From f63f7ac403200666de28c0332ab9ba938f3e64b1 Mon Sep 17 00:00:00 2001 From: kabdelhak Date: Fri, 15 Mar 2019 17:48:30 +0100 Subject: [PATCH] [BE] Consider complex as impure for removeSimpleEquations Belonging to [master]: - OpenModelica/OMCompiler#2982 - OpenModelica/OpenModelica-testsuite#1141 --- Compiler/BackEnd/RemoveSimpleEquations.mo | 7 +--- Compiler/FrontEnd/Expression.mo | 45 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Compiler/BackEnd/RemoveSimpleEquations.mo b/Compiler/BackEnd/RemoveSimpleEquations.mo index a92b5d8eff5..5687b6ec618 100644 --- a/Compiler/BackEnd/RemoveSimpleEquations.mo +++ b/Compiler/BackEnd/RemoveSimpleEquations.mo @@ -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; @@ -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"); diff --git a/Compiler/FrontEnd/Expression.mo b/Compiler/FrontEnd/Expression.mo index c04cee6082c..70d3cf727e2 100644 --- a/Compiler/FrontEnd/Expression.mo +++ b/Compiler/FrontEnd/Expression.mo @@ -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;