calyx icon indicating copy to clipboard operation
calyx copied to clipboard

Hoist redundant parallel actions

Open anshumanmohan opened this issue 1 year ago • 2 comments

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

anshumanmohan avatar Aug 15 '23 14:08 anshumanmohan

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.

rachitnigam avatar Aug 16 '23 03:08 rachitnigam

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.

rachitnigam avatar Dec 26 '23 23:12 rachitnigam