calyx
calyx copied to clipboard
Hoist redundant parallel actions
When working on the new slew of queues (FIFO, PIFO, PIFO Tree), I found myself doing the following refactoring by hand:
par (
(
if_case_1:
action;
additional_action_for_cases_1_and_2
),
(
if_case_2:
action;
additional_action_for_cases_1_and_2
),
(
if_case_3:
action;
)
) # par ends
turned into:
action;
if_case_1_or_2: additional_action_for_cases_1_and_2
And I think that's simpler.
Basically the action
was the same in all the parallel branches, so I lifted it. Then the additional_action_for_cases_1_and_2
is run after that. These cannot themselves be run in parallel: the latter step depends on some state change triggered by the former.
Just making a quick issue in case Calyx would like to perform such hoisting automatically.
Originally posted by @anshumanmohan in https://github.com/cucapra/calyx/pull/1657#discussion_r1294609470
Thanks for creating this issue! One can imagine a similar pass that hoists groups out of a while
loops but that would be more complicated because you'd be implementing loop invariant code motion.
An obvious but important property of this rewrite should be that action
cannot affect the value of the conditions if_case_*
. If it does, we cannot move it outside the if
.