Skip to content

Commit

Permalink
[BE] Consider complex as impure for removeSimpleEquations
Browse files Browse the repository at this point in the history
  • Loading branch information
kabdelhak authored and OpenModelica-Hudson committed Mar 15, 2019
1 parent f440207 commit f63f7ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -1943,13 +1943,10 @@ algorithm

case (_, _, _, _, _, (vars, shared as BackendDAE.SHARED(functionTree=functions), eqns, seqns, index, mT, _))
guard
not Expression.isImpure(exp) // lochel: this is at least needed for impure functions
not Expression.isImpure(exp) and not Expression.containsComplexCall(exp) // lochel: this is at least needed for impure functions
equation
//exp2 = Ceval.cevalSimpleWithFunctionTreeReturnExp(exp, functions);
exp2 = EvaluateFunctions.evaluateConstantFunctionCallExp(exp, functions, false);
if not Expression.isConst(exp2) then
exp2 = exp;
end if;
if Flags.isSet(Flags.DEBUG_ALIAS) then
BackendDump.debugStrCrefStrExpStr("Const Equation (through Ceval, case 1) ", cr, " = ", exp, " found.\n");
end if;
Expand All @@ -1961,7 +1958,7 @@ algorithm
// TODO: Remove or fix this case. We do not want to add function calls here as they are inlined in a very bad way sometimes.
case (_, _, _, _, _, (vars, shared, eqns, seqns, index, mT, _))
guard
not Expression.isImpure(exp) // lochel: this is at least needed for impure functions
not Expression.isImpure(exp) and not Expression.containsComplexCall(exp) // lochel: this is at least needed for impure functions
equation
if Flags.isSet(Flags.DEBUG_ALIAS) then
BackendDump.debugStrCrefStrExpStr("Const Equation (through Ceval, case 2) ", cr, " = ", exp, " found.\n");
Expand Down
45 changes: 45 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -7857,6 +7857,51 @@ algorithm
end match;
end isImpureWork;

public function containsComplexCall "author: kabdelhak
Returns true if an expression contains a complex constructor call."
input DAE.Exp inExp;
output Boolean isCC;
algorithm
(_, isCC) := traverseExpTopDown(inExp, containsComplexCallWork, false);
end containsComplexCall;

function containsComplexCallWork "author: kabdelhak"
input DAE.Exp inExp;
input Boolean inCC;
output DAE.Exp outExp;
output Boolean cont;
output Boolean outCC;
algorithm
(outExp,cont,outCC) := match (inExp,inCC)
local
Absyn.Path path;
Boolean isCC;
case (_, true) then (inExp,true,true);
case (DAE.CALL(path = Absyn.FULLYQUALIFIED(path = path)), _)
equation
true = isComplexCall(path);
then (inExp,false,true);
else (inExp,true,false);
end match;
end containsComplexCallWork;

function isComplexCall "author: kabdelhak"
input Absyn.Path path;
output Boolean isCC;
algorithm
isCC := match path
local
Absyn.Path innerPath;
case (Absyn.FULLYQUALIFIED(path = innerPath))
then isComplexCall(innerPath);
case (Absyn.QUALIFIED(name=".Complex"))
then true;
case (Absyn.IDENT(name=".Complex"))
then true;
else false;
end match;
end isComplexCall;

public function isConst
"Returns true if an expression is constant"
input DAE.Exp inExp;
Expand Down

0 comments on commit f63f7ac

Please sign in to comment.