Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit c8a95fd

Browse files
kabdelhakOpenModelica-Hudson
authored andcommitted
[BE] Avoid records in remove simple equations
- #4793 Belonging to [master]: - OpenModelica/OpenModelica#167 - #3077
1 parent 80f6ed2 commit c8a95fd

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

Compiler/BackEnd/RemoveSimpleEquations.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ algorithm
19431943

19441944
case (_, _, _, _, _, (vars, shared as BackendDAE.SHARED(functionTree=functions), eqns, seqns, index, mT, _))
19451945
guard
1946-
not Expression.isImpure(exp) and not Expression.containsComplexCall(exp) // lochel: this is at least needed for impure functions
1946+
not Expression.isImpure(exp) and not Expression.containsRecordType(exp) // lochel: this is at least needed for impure functions
19471947
equation
19481948
//exp2 = Ceval.cevalSimpleWithFunctionTreeReturnExp(exp, functions);
19491949
exp2 = EvaluateFunctions.evaluateConstantFunctionCallExp(exp, functions, false);
@@ -1958,7 +1958,7 @@ algorithm
19581958
// 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.
19591959
case (_, _, _, _, _, (vars, shared, eqns, seqns, index, mT, _))
19601960
guard
1961-
not Expression.isImpure(exp) and not Expression.containsComplexCall(exp) // lochel: this is at least needed for impure functions
1961+
not Expression.isImpure(exp) and not Expression.containsRecordType(exp) // lochel: this is at least needed for impure functions
19621962
equation
19631963
if Flags.isSet(Flags.DEBUG_ALIAS) then
19641964
BackendDump.debugStrCrefStrExpStr("Const Equation (through Ceval, case 2) ", cr, " = ", exp, " found.\n");

Compiler/FrontEnd/DAEDump.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,18 +3356,18 @@ public function dumpCallAttr
33563356
"dumps the DAE.CallAttributes"
33573357
input DAE.CallAttributes ca;
33583358
protected
3359-
Boolean tpl,bi,impure_;
3359+
Boolean tpl,bi,impure_,isFunc;
33603360
DAE.InlineType iType;
33613361
DAE.Type ty;
33623362
DAE.TailCall tailCall;
33633363
String s1,s2;
33643364
algorithm
3365-
DAE.CALL_ATTR(ty=ty,tuple_=tpl,builtin=bi,isImpure=impure_,inlineType=iType,tailCall=tailCall) := ca;
3365+
DAE.CALL_ATTR(ty=ty,tuple_=tpl,builtin=bi,isImpure=impure_,isFunctionPointerCall=isFunc,inlineType=iType,tailCall=tailCall) := ca;
33663366
print("Call attributes: \n----------------------\n");
33673367
(s1,s2) := printTypeStr(ty);
33683368
print("DAE-type: "+s1+"\n");
33693369
print("DAE-type attributes :"+s2+"\n");
3370-
print("tuple_: "+boolString(tpl)+" builtin: "+boolString(bi)+" impure: "+boolString(impure_)+"\n\n");
3370+
print("tuple_: "+boolString(tpl)+" builtin: "+boolString(bi)+" impure: "+boolString(impure_)+" isFunctionPointerCall: "+boolString(isFunc)+"\n\n");
33713371
end dumpCallAttr;
33723372

33733373
public function dumpVarBindingStr

Compiler/FrontEnd/Expression.mo

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ encapsulated package Expression
4949
// public imports
5050
public import Absyn;
5151
public import DAE;
52+
public import DAEDump;
5253

5354
protected
5455
type ComponentRef = DAE.ComponentRef;
@@ -7857,50 +7858,48 @@ algorithm
78577858
end match;
78587859
end isImpureWork;
78597860

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

7868-
function containsComplexCallWork "author: kabdelhak"
7862+
public function containsRecordType
7863+
" Returns true if an expression contains a record type."
78697864
input DAE.Exp inExp;
7870-
input Boolean inCC;
7871-
output DAE.Exp outExp;
7872-
output Boolean cont;
7873-
output Boolean outCC;
7865+
output Boolean isRec;
78747866
algorithm
7875-
(outExp,cont,outCC) := match (inExp,inCC)
7876-
local
7877-
Absyn.Path path;
7878-
Boolean isCC;
7879-
case (_, true) then (inExp,true,true);
7880-
case (DAE.CALL(path = Absyn.FULLYQUALIFIED(path = path)), _)
7881-
equation
7882-
true = isComplexCall(path);
7883-
then (inExp,false,true);
7884-
else (inExp,true,false);
7885-
end match;
7886-
end containsComplexCallWork;
7867+
(_, isRec) := traverseExpTopDown(inExp, containsRecordTypeWork, false);
7868+
end containsRecordType;
78877869

7888-
function isComplexCall "author: kabdelhak"
7889-
input Absyn.Path path;
7890-
output Boolean isCC;
7870+
protected function containsRecordTypeWork
7871+
input DAE.Exp inExp;
7872+
input Boolean inRec;
7873+
output DAE.Exp outExp = inExp;
7874+
output Boolean cont = false;
7875+
output Boolean outRec = inRec;
78917876
algorithm
7892-
isCC := match path
7893-
local
7894-
Absyn.Path innerPath;
7895-
case (Absyn.FULLYQUALIFIED(path = innerPath))
7896-
then isComplexCall(innerPath);
7897-
case (Absyn.QUALIFIED(name=".Complex"))
7898-
then true;
7899-
case (Absyn.IDENT(name=".Complex"))
7900-
then true;
7901-
else false;
7902-
end match;
7903-
end isComplexCall;
7877+
if not inRec then
7878+
(outExp,cont,outRec) := matchcontinue inExp
7879+
local
7880+
DAE.Type ty;
7881+
list<DAE.Exp> expLst;
7882+
Boolean subRec;
7883+
DAE.ComponentRef cr;
7884+
case DAE.RECORD()
7885+
algorithm
7886+
then (inExp,false,true);
7887+
case DAE.CALL(expLst=expLst, attr=DAE.CALL_ATTR(ty=ty))
7888+
algorithm
7889+
subRec := isRecordType(ty);
7890+
if not subRec then
7891+
for exp in expLst loop
7892+
subRec := containsRecordType(exp);
7893+
if subRec then
7894+
break;
7895+
end if;
7896+
end for;
7897+
end if;
7898+
then (inExp,not subRec,subRec);
7899+
else (inExp,true,false);
7900+
end matchcontinue;
7901+
end if;
7902+
end containsRecordTypeWork;
79047903

79057904
public function isConst
79067905
"Returns true if an expression is constant"

0 commit comments

Comments
 (0)