Skip to content

Commit

Permalink
don't inline inside solveSimpleEquation (performance issues after inl…
Browse files Browse the repository at this point in the history
…ine)
  • Loading branch information
vruge authored and OpenModelica-Hudson committed Mar 28, 2016
1 parent 50ebc1f commit 9a6f2aa
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -132,7 +132,7 @@ algorithm
cr := ComponentReference.crefPrefixDer(cr);
end if;

(e1, e2) := preprocessingSolve(e1, e2, varexp, SOME(shared.functionTree), NONE(), 0);
(e1, e2) := preprocessingSolve(e1, e2, varexp, SOME(shared.functionTree), NONE(), 0, false);

try
e := solve2(e1, e2, varexp, SOME(shared.functionTree), NONE());
Expand Down Expand Up @@ -209,7 +209,7 @@ algorithm
(outExp,outAsserts,dummy1, dummy2, dummyI) := matchcontinue inExp1
case _ then solveSimple(inExp1, inExp2, inExp3, 0);
case _ then solveSimple(inExp2, inExp1, inExp3, 0);
case _ then solveWork(inExp1, inExp2, inExp3, NONE(), NONE(), 0);
case _ then solveWork(inExp1, inExp2, inExp3, NONE(), NONE(), 0, false);
else equation
if Flags.isSet(Flags.FAILTRACE) then
Error.addInternalError("Failed to solve \"" + ExpressionDump.printExpStr(inExp1) + " = " + ExpressionDump.printExpStr(inExp2) + "\" w.r.t. \"" + ExpressionDump.printExpStr(inExp3) + "\"", sourceInfo());
Expand All @@ -231,6 +231,7 @@ public function solve2
input DAE.Exp inExp3 "DAE.CREF or 'der(DAE.CREF())'";
input Option<DAE.FunctionTree> functions "need for solve modelica functions";
input Option<Integer> uniqueEqIndex "offset for tmp vars";
input Boolean doInline = true;
output DAE.Exp outExp;
output list<DAE.Statement> outAsserts;
output list<BackendDAE.Equation> eqnForNewVars "eqn for tmp vars";
Expand All @@ -247,7 +248,7 @@ algorithm
(outExp,outAsserts,eqnForNewVars,newVarsCrefs,dummyI) := matchcontinue inExp1
case _ then solveSimple(inExp1, inExp2, inExp3, 0);
case _ then solveSimple(inExp2, inExp1, inExp3, 0);
case _ then solveWork(inExp1, inExp2, inExp3, functions, uniqueEqIndex, 0);
case _ then solveWork(inExp1, inExp2, inExp3, functions, uniqueEqIndex, 0, doInline);
else equation
if Flags.isSet(Flags.FAILTRACE) then
Error.addInternalError("Failed to solve \"" + ExpressionDump.printExpStr(inExp1) + " = " + ExpressionDump.printExpStr(inExp2) + "\" w.r.t. \"" + ExpressionDump.printExpStr(inExp3) + "\"", sourceInfo());
Expand All @@ -267,6 +268,7 @@ protected function solveWork
input Option<DAE.FunctionTree> functions;
input Option<Integer> uniqueEqIndex "offset for tmp vars";
input Integer idepth;
input Boolean doInline;
output DAE.Exp outExp;
output list<DAE.Statement> outAsserts;
output list<BackendDAE.Equation> eqnForNewVars "eqn for tmp vars";
Expand All @@ -280,7 +282,7 @@ protected
list<DAE.ComponentRef> newVarsCrefs1;
algorithm
(e1, e2, eqnForNewVars, newVarsCrefs, depth) := matchcontinue inExp1
case _ then preprocessingSolve(inExp1, inExp2, inExp3, functions, uniqueEqIndex, idepth);
case _ then preprocessingSolve(inExp1, inExp2, inExp3, functions, uniqueEqIndex, idepth, doInline);
else
equation
if Flags.isSet(Flags.FAILTRACE) then
Expand All @@ -292,7 +294,7 @@ algorithm
end matchcontinue;

(outExp, outAsserts, eqnForNewVars1, newVarsCrefs1, depth) := matchcontinue e1
case _ then solveIfExp(e1, e2, inExp3, functions, uniqueEqIndex, depth);
case _ then solveIfExp(e1, e2, inExp3, functions, uniqueEqIndex, depth, doInline);
case _ then solveSimple(e1, e2, inExp3, depth);
case _ then solveLinearSystem(e1, e2, inExp3, functions, depth);
else fail();
Expand Down Expand Up @@ -468,6 +470,7 @@ preprocessing for solve1,
input Option<DAE.FunctionTree> functions;
input Option<Integer> uniqueEqIndex "offset for tmp vars";
input Integer idepth;
input Boolean doInline;
output DAE.Exp x;
output DAE.Exp y;
output list<BackendDAE.Equation> eqnForNewVars = {} "eqn for tmp vars";
Expand Down Expand Up @@ -542,7 +545,7 @@ preprocessing for solve1,
(rhsX, rhsY) := preprocessingSolve5(y, inExp3, false);
x := Expression.expSub(lhsX, rhsX);
y := Expression.expSub(rhsY, lhsY);
elseif inlineFun then
elseif doInline and inlineFun then
iter := iter + 50;
if inlineFun then
(x,con) := solveFunCalls(x, inExp3, functions);
Expand Down Expand Up @@ -1710,6 +1713,7 @@ protected function solveIfExp
input Option<DAE.FunctionTree> functions;
input Option<Integer> uniqueEqIndex "offset for tmp vars";
input Integer idepth;
input Boolean doInline;
output DAE.Exp outExp;
output list<DAE.Statement> outAsserts;
output list<BackendDAE.Equation> eqnForNewVars "eqn for tmp vars";
Expand All @@ -1733,8 +1737,8 @@ algorithm
equation
false = expHasCref(e1, inExp3);

(lhs, asserts1, eqns, var, depth) = solveWork(e2, inExp2, inExp3, functions, uniqueEqIndex, idepth);
(rhs,_, eqns1, var1, depth) = solveWork(e3, inExp2, inExp3, functions, uniqueEqIndex, depth);
(lhs, asserts1, eqns, var, depth) = solveWork(e2, inExp2, inExp3, functions, uniqueEqIndex, idepth, doInline);
(rhs,_, eqns1, var1, depth) = solveWork(e3, inExp2, inExp3, functions, uniqueEqIndex, depth, doInline);

res = DAE.IFEXP(e1,lhs,rhs);
asserts = listAppend(asserts1,asserts1);
Expand Down

0 comments on commit 9a6f2aa

Please sign in to comment.