Open casella opened 1 year 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.
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.