marco-compiler / marco

Modelica Advanced Research COmpiler
GNU Lesser General Public License v3.0
20 stars 5 forks source link

CSE to avoid repeated pure function calls with the same argument #4

Open casella opened 1 year ago

casella commented 1 year ago

If the same pure function call with the same argument is present in multiple places in the Modelica source code, Common Subexpression Elimination should be applied to avoid useless repeated function calls, which are guaranteed to give the same output.

One way to implement this feature is the method employed in OpenModelica: for each function call, an equation $cseXX = function_call() is generated and an auxiliary variable $cseXX is added to the problem. Then, all function calls are replaced by the $cseXX variable. Matching and sorting then ensures that the function is called in the proper order.

mscuttari commented 1 month ago

@arrangabriel The function-cse branch contains a starting point for the work. There is already a first implementation of expressions equivalence checks, and a scheleton for the transformation pass. You can keep working on that feature branch.