Skip to content

Commit

Permalink
Reactivate removeEqualFunctionCalls
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Jul 19, 2019
1 parent 981f8ab commit a6beda5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
16 changes: 8 additions & 8 deletions OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -906,9 +906,9 @@ end protectedParametersFinder;
// remove equal function calls equations stuff
//
// =============================================================================
public function removeEqualFunctionCalls "author: Frenkel TUD 2011-04
This function detects equal function calls of the form a=f(b) and c=f(b) in
BackendDAE.BackendDAE to get speed up."
public function removeEqualRHS "author: Frenkel TUD 2011-04
Detects equal expressions of the form a=<exp> and b=<exp> and substitutes
them to get speed up."
input BackendDAE.BackendDAE dae;
output BackendDAE.BackendDAE odae;
algorithm
Expand All @@ -918,7 +918,7 @@ algorithm
else
odae := BackendDAEUtil.mapEqSystem(dae,removeEqualFunctionCallsWork);
end if;
end removeEqualFunctionCalls;
end removeEqualRHS;

protected function removeEqualFunctionCallsWork "author: Frenkel TUD 2011-04
This function detects equal function calls of the form a=f(b) and c=f(b) in
Expand Down Expand Up @@ -1018,22 +1018,22 @@ algorithm
then fail();
case (DAE.UNARY(operator=DAE.UMINUS(),exp=DAE.CREF()),DAE.CREF(),_)
then fail();
// a = -f(...);
// a = -<exp>
case (e1 as DAE.CREF(componentRef = cr),DAE.UNARY(operator=op as DAE.UMINUS(),exp=e2),_)
equation
((_::_),(_::_)) = BackendVariable.getVar(cr,inVars);
then (DAE.UNARY(op,e1),e2);
// a = f(...);
// a = <exp>;
case (e1 as DAE.CREF(componentRef = cr),e2,_)
equation
((_::_),(_::_)) = BackendVariable.getVar(cr,inVars);
then (e1,e2);
// a = -f(...);
// -<exp> = a
case (DAE.UNARY(operator=op as DAE.UMINUS(),exp=e1),e2 as DAE.CREF(componentRef = cr),_)
equation
((_::_),(_::_)) = BackendVariable.getVar(cr,inVars);
then (DAE.UNARY(op,e2),e1);
// f(...)=a;
// <exp> = a
case (e1,e2 as DAE.CREF(componentRef = cr),_)
equation
((_::_),(_::_)) = BackendVariable.getVar(cr,inVars);
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7736,7 +7736,6 @@ public function allPreOptimizationModules
(RemoveSimpleEquations.removeVerySimpleEquations, "removeVerySimpleEquations"),
(BackendDAEOptimize.simplifyIfEquations, "simplifyIfEquations"),
(BackendDAEOptimize.expandDerOperator, "expandDerOperator"),
(BackendDAEOptimize.removeEqualFunctionCalls, "removeEqualFunctionCalls"),
(BackendDAEOptimize.removeLocalKnownVars, "removeLocalKnownVars"),
(CommonSubExpression.wrapFunctionCalls, "wrapFunctionCalls"),
(SynchronousFeatures.clockPartitioning, "clockPartitioning"),
Expand All @@ -7746,6 +7745,7 @@ public function allPreOptimizationModules
(BackendDAEOptimize.replaceEdgeChange, "replaceEdgeChange"),
(InlineArrayEquations.inlineArrayEqn, "inlineArrayEqn"),
(BackendDAEOptimize.sortEqnsVars, "sortEqnsVars"),
(BackendDAEOptimize.removeEqualRHS, "removeEqualRHS"),
(RemoveSimpleEquations.removeSimpleEquations, "removeSimpleEquations"),
(CommonSubExpression.commonSubExpressionReplacement, "comSubExp"),
(ResolveLoops.resolveLoops, "resolveLoops"),
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/SymbolicImplicitSolver.mo
Expand Up @@ -136,7 +136,7 @@ algorithm
end if;

inlineBDAE := BackendDAEUtil.getSolvedSystemforJacobians(inlineBDAE,
{"removeEqualFunctionCalls",
{"removeEqualRHS",
"removeSimpleEquations",
"evalFunc"},
NONE(),
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -2095,7 +2095,7 @@ algorithm
end if;

backendDAE2 = BackendDAEUtil.getSolvedSystemforJacobians(backendDAE,
{"removeEqualFunctionCalls",
{"removeEqualRHS",
"removeSimpleEquations",
"evalFunc"},
NONE(),
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/BackEnd/Uncertainties.mo
Expand Up @@ -148,9 +148,9 @@ algorithm
description = DAEUtil.daeDescription(dae);
//print("- Flatten ok\n");
dlow = BackendDAECreate.lower(dae,cache,graph,BackendDAE.EXTRA_INFO(description,outputFile));
//(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(dlow, funcs,SOME({"removeSimpleEquations","removeFinalParameters", "removeEqualFunctionCalls", "expandDerOperator"}), NONE(), NONE(),NONE());
//(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(dlow, funcs,SOME({"removeSimpleEquations","removeFinalParameters", "removeEqualRHS", "expandDerOperator"}), NONE(), NONE(),NONE());
Flags.setConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING, false);
(dlow_1) = BackendDAEUtil.getSolvedSystem(dlow, "", SOME({"removeSimpleEquations","removeUnusedVariables","removeEqualFunctionCalls","expandDerOperator"}), NONE(), NONE(), SOME({}));
(dlow_1) = BackendDAEUtil.getSolvedSystem(dlow, "", SOME({"removeSimpleEquations","removeUnusedVariables","removeEqualRHS","expandDerOperator"}), NONE(), NONE(), SOME({}));
Flags.setConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING, forceOrdering);
//print("* Lowered Ok \n");

Expand Down
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/Util/Flags.mo
Expand Up @@ -805,6 +805,7 @@ constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules",
"findStateOrder",
"replaceEdgeChange",
"inlineArrayEqn",
"removeEqualRHS",
"removeSimpleEquations",
"comSubExp",
"resolveLoops",
Expand All @@ -827,7 +828,7 @@ constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules",
("normalInlineFunction", Util.gettext("Perform function inlining for function with annotation Inline=true.")),
("inputDerivativesForDynOpt", Util.gettext("Allowed derivatives of inputs in dyn. optimization.")),
("introduceDerAlias", Util.notrans("Adds for every der-call an alias equation e.g. dx = der(x).")),
("removeEqualFunctionCalls", Util.notrans("Detects equal function calls of the form a=f(b) and c=f(b) and substitutes them to get speed up.")),
("removeEqualRHS", Util.notrans("Detects equal expressions of the form a=<exp> and b=<exp> and substitutes them to get speed up.")),
("removeProtectedParameters", Util.gettext("Replace all parameters with protected=true in the system.")),
("removeSimpleEquations", removeSimpleEquationDesc),
("removeUnusedParameter", Util.gettext("Strips all parameter not present in the equations from the system.")),
Expand Down Expand Up @@ -932,7 +933,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("reduceDynamicOptimization", Util.notrans("Removes equations which are not needed for the calculations of cost and constraints. This module requires -d=reduceDynOpt.")),
("relaxSystem", Util.notrans("relaxation from gausian elemination")),
("removeConstants", Util.gettext("Remove all constants in the system.")),
("removeEqualFunctionCalls", Util.notrans("Detects equal function calls of the form a=f(b) and c=f(b) and substitutes them to get speed up.")),
("removeEqualRHS", Util.notrans("Detects equal function calls of the form a=f(b) and c=f(b) and substitutes them to get speed up.")),
("removeSimpleEquations", removeSimpleEquationDesc),
("removeUnusedParameter", Util.gettext("Strips all parameter not present in the equations from the system to get speed up for compilation of target code.")),
("removeUnusedVariables", Util.notrans("Strips all variables not present in the equations from the system to get speed up for compilation of target code.")),
Expand Down

0 comments on commit a6beda5

Please sign in to comment.