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

Commit e76f577

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Do not create a new cse variable for record=call
1 parent b1a493a commit e76f577

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

Compiler/BackEnd/CommonSubExpression.mo

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,30 @@ algorithm
467467
if BaseHashTable.hasKey(call, HT) then
468468
exIndex := BaseHashTable.get(call, HT);
469469
cseEquation := ExpandableArray.get(exIndex, exarray);
470-
//print("cref1: " + ExpressionDump.printExpStr(cseEquation.cse) + "\n");
471-
//print("cref2: " + ExpressionDump.printExpStr(cref) + "\n");
470+
//print("cref1: " + ExpressionDump.printExpStr(cseEquation.cse) + "\n");
471+
//print("cref2: " + ExpressionDump.printExpStr(cref) + "\n");
472472
cseEquation.cse := mergeCSETuples(cseEquation.cse, cref);
473473
exarray := ExpandableArray.update(exIndex, cseEquation, exarray);
474474
elseif not isSkipCase(call, functionTree) then
475475
index := index + 1;
476476
HT := BaseHashTable.add((call, index), HT);
477477
exarray := ExpandableArray.set(index, CSE_EQUATION(cref, call, {}), exarray);
478478
end if;
479+
480+
elseif isCallAndRecord(lhs, rhs) then
481+
(cref, call) := getTheRightPattern(lhs, rhs);
482+
if BaseHashTable.hasKey(call, HT) then
483+
exIndex := BaseHashTable.get(call, HT);
484+
cseEquation := ExpandableArray.get(exIndex, exarray);
485+
//print("cref old: " + ExpressionDump.printExpStr(cseEquation.cse) + "\n");
486+
//print("cref new: " + ExpressionDump.printExpStr(cref) + "\n");
487+
cseEquation.cse := cref;
488+
exarray := ExpandableArray.update(exIndex, cseEquation, exarray);
489+
elseif not isSkipCase(call, functionTree) then
490+
index := index + 1;
491+
HT := BaseHashTable.add((call, index), HT);
492+
exarray := ExpandableArray.set(index, CSE_EQUATION(cref, call, {}), exarray);
493+
end if;
479494
end if;
480495

481496
(_, (HT, exarray, cseIndex, index, functionTree)) := BackendEquation.traverseExpsOfEquation(inEq, wrapFunctionCalls_analysis2, (HT, exarray, cseIndex, index, functionTree));
@@ -665,6 +680,9 @@ algorithm
665680
case BackendDAE.COMPLEX_EQUATION(left=DAE.TUPLE(lhs), right=DAE.TUPLE(rhs)) guard (listLength(lhs) == listLength(rhs))
666681
then isEquationRedundant2(lhs, rhs);
667682

683+
case BackendDAE.COMPLEX_EQUATION(left = exp1 as DAE.CREF(ty = DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_))), right = exp2 as DAE.CREF(ty = DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_))))
684+
then Expression.expEqual(exp1, exp2);
685+
668686
else false;
669687
end match;
670688
end isEquationRedundant;
@@ -743,6 +761,18 @@ algorithm
743761
end match;
744762
end isCallAndTuple;
745763

764+
protected function isCallAndRecord
765+
input DAE.Exp inExp;
766+
input DAE.Exp inExp2;
767+
output Boolean outBoolean;
768+
algorithm
769+
outBoolean := match(inExp, inExp2)
770+
case (DAE.CREF(ty = DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_))), DAE.CALL()) then true;
771+
case (DAE.CALL(), DAE.CREF(ty = DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_)))) then true;
772+
else false;
773+
end match;
774+
end isCallAndRecord;
775+
746776
protected function mergeCSETuples
747777
input DAE.Exp inCref1;
748778
input DAE.Exp inCref2;

0 commit comments

Comments
 (0)