Skip to content

Commit

Permalink
- Rewrote crefPrefixOf, crefEqualNoStringCompare and setsEqual using …
Browse files Browse the repository at this point in the history
…match instead of matchcontinue (~20% speedup of checkEngineV6_analytic for bootstrapped OMC)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7699 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 15, 2011
1 parent 21a4faf commit e3e57c7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 73 deletions.
78 changes: 39 additions & 39 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -740,7 +740,7 @@ public function crefPrefixOf
input DAE.ComponentRef fullCref;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (prefixCref,fullCref)
outBoolean := match (prefixCref,fullCref)
local
DAE.ComponentRef cr1,cr2;
Boolean res;
Expand All @@ -754,46 +754,38 @@ algorithm
case (DAE.CREF_QUAL(ident = id1, subscriptLst = ss1,componentRef = cr1),
DAE.CREF_QUAL(ident = id2, subscriptLst = ss2,componentRef = cr2))
equation
true = stringEq(id1, id2);
true = Expression.subscriptEqual(ss1, ss2);
res = crefPrefixOf(cr1, cr2);
res = stringEq(id1, id2);
res = Debug.bcallret2(res, Expression.subscriptEqual, ss1, ss2, false);
res = Debug.bcallret2(res, crefPrefixOf, cr1, cr2, false);
then
res;

// adrpo: 2010-10-07: first is an ID, second is qualified, see if one is prefix of the other
// even if the first one DOESN'T HAVE SUBSCRIPTS!
case (DAE.CREF_IDENT(ident = id1,subscriptLst = {}),
DAE.CREF_QUAL(ident = id2,subscriptLst = ss2))
equation
true = stringEq(id1, id2);
then
true;
then stringEq(id1, id2);

// first is an ID, second is qualified, see if one is prefix of the other
case (DAE.CREF_IDENT(ident = id1,subscriptLst = ss1),
DAE.CREF_QUAL(ident = id2,subscriptLst = ss2))
equation
true = stringEq(id1, id2);
res = Expression.subscriptEqual(ss1, ss2);
res = Debug.bcallret2(stringEq(id1, id2), Expression.subscriptEqual, ss1, ss2, false);
then
res;

// adrpo: 2010-10-07: first is an ID, second is an ID, see if one is prefix of the other
// even if the first one DOESN'T HAVE SUBSCRIPTS!
case (DAE.CREF_IDENT(ident = id1,subscriptLst = {}),
DAE.CREF_IDENT(ident = id2,subscriptLst = ss2))
equation
true = stringEq(id1, id2);
then
true;
then stringEq(id1, id2);

case (DAE.CREF_IDENT(ident = id1,subscriptLst = ss1),
DAE.CREF_IDENT(ident = id2,subscriptLst = ss2))
equation
true = stringEq(id1, id2);
res = Expression.subscriptEqual(ss1, ss2);
res = Debug.bcallret2(stringEq(id1, id2), Expression.subscriptEqual, ss1, ss2, false);
then
res;
res;

/* adrpo: 2010-10-07. already handled by the cases above!
they might be equal, a.b.c is a prefix of a.b.c
Expand All @@ -808,7 +800,7 @@ algorithm
equation
// print("Expression.crefPrefixOf: " +& printComponentRefStr(cr1) +& " NOT PREFIX OF " +& printComponentRefStr(cr2) +& "\n");
then false;
end matchcontinue;
end match;
end crefPrefixOf;

public function crefNotPrefixOf "negation of crefPrefixOf"
Expand Down Expand Up @@ -945,42 +937,50 @@ public function crefEqualNoStringCompare
IMPORTANT! do not use this function if you have
stringified components, meaning this function will
return false for: cref1: QUAL(x, IDENT(x)) != cref2: IDENT(x.y)"
input DAE.ComponentRef cr1;
input DAE.ComponentRef cr2;
output Boolean res;
algorithm
res := crefEqualNoStringCompare2(referenceEq(cr1,cr2),cr1,cr2);
end crefEqualNoStringCompare;

protected function crefEqualNoStringCompare2
"function: crefEqualNoStringCompare
Returns true if two component references are equal!
IMPORTANT! do not use this function if you have
stringified components, meaning this function will
return false for: cref1: QUAL(x, IDENT(x)) != cref2: IDENT(x.y)"
input Boolean refEq;
input DAE.ComponentRef inComponentRef1;
input DAE.ComponentRef inComponentRef2;
output Boolean outBoolean;
output Boolean res;
algorithm
outBoolean := matchcontinue (inComponentRef1,inComponentRef2)
res := match (refEq,inComponentRef1,inComponentRef2)
local
DAE.Ident n1,n2;
list<DAE.Subscript> idx1,idx2;
DAE.ComponentRef cr1,cr2;

// check for pointer equality first, if they point to the same thing, they are equal
case (inComponentRef1,inComponentRef2)
equation
true = referenceEq(inComponentRef1,inComponentRef2);
then
true;
case (true,_,_) then true;

// simple identifiers
case (DAE.CREF_IDENT(ident = n1,subscriptLst = idx1),DAE.CREF_IDENT(ident = n2,subscriptLst = idx2))
case (_,DAE.CREF_IDENT(ident = n1,subscriptLst = idx1),DAE.CREF_IDENT(ident = n2,subscriptLst = idx2))
equation
true = stringEq(n1, n2);
true = Expression.subscriptEqual(idx1, idx2);
then
true;
res = stringEq(n1, n2);
res = Debug.bcallret2(res, Expression.subscriptEqual, idx1, idx2, false);
then res;
// qualified crefs
case (DAE.CREF_QUAL(ident = n1,subscriptLst = idx1,componentRef = cr1),DAE.CREF_QUAL(ident = n2,subscriptLst = idx2,componentRef = cr2))
case (_,DAE.CREF_QUAL(ident = n1,subscriptLst = idx1,componentRef = cr1),DAE.CREF_QUAL(ident = n2,subscriptLst = idx2,componentRef = cr2))
equation
true = stringEq(n1, n2);
true = crefEqualNoStringCompare(cr1, cr2);
true = Expression.subscriptEqual(idx1, idx2);
then
true;
res = stringEq(n1, n2);
res = Debug.bcallret3(res, crefEqualNoStringCompare2, referenceEq(cr1,cr2), cr1, cr2, false);
res = Debug.bcallret2(res, Expression.subscriptEqual, idx1, idx2, false);
then res;
// the crefs are not equal!
case (_,_) then false;
end matchcontinue;
end crefEqualNoStringCompare;
else false;
end match;
end crefEqualNoStringCompare2;

public function crefEqualReturn
"function: crefEqualReturn
Expand Down
66 changes: 32 additions & 34 deletions Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -1816,57 +1816,55 @@ protected function setsEqual
input Connect.Set inSet2;
output Boolean equalSets;
algorithm
equalSets := matchcontinue(inSet1,inSet2)
equalSets := setsEqual2(referenceEq(inSet1,inSet2),inSet1,inSet2);
end setsEqual;

protected function setsEqual2
input Boolean refEqual;
input Connect.Set inSet1;
input Connect.Set inSet2;
output Boolean equalSets;
algorithm
equalSets := match (refEqual,inSet1,inSet2)
local
DAE.ComponentRef cr1,cr2;
list<Connect.EquSetElement> equRest1,equRest2;
list<Connect.FlowSetElement> flowRest1,flowRest2;
list<Connect.StreamSetElement> streamRest1,streamRest2;
Connect.Face face1,face2;

// pointer equality testing first.
case (inSet1, inSet2)
equation
true = referenceEq(inSet1, inSet2);
then true;

case (true,_,_) then true;
// deal with empty case
case (Connect.EQU({}), Connect.EQU({})) then true;
case (Connect.FLOW({}), Connect.FLOW({})) then true;
case (Connect.STREAM({}), Connect.STREAM({})) then true;
case (_,Connect.EQU({}), Connect.EQU({})) then true;
case (_,Connect.FLOW({}), Connect.FLOW({})) then true;
case (_,Connect.STREAM({}), Connect.STREAM({})) then true;

// deal with non empty Connect.EQU
case (Connect.EQU((cr1,face1,_)::equRest1),
Connect.EQU((cr2,face2,_)::equRest2))
case (_,Connect.EQU((cr1,face1,_)::equRest1),Connect.EQU((cr2,face2,_)::equRest2))
equation
true = faceEqual(face1, face2);
true = ComponentReference.crefEqualNoStringCompare(cr1, cr2);
true = setsEqual(Connect.EQU(equRest1),Connect.EQU(equRest2));
then
true;
equalSets = faceEqual(face1, face2);
equalSets = Debug.bcallret2(equalSets, ComponentReference.crefEqualNoStringCompare, cr1, cr2, false);
equalSets = Debug.bcallret3(equalSets, setsEqual2, false, Connect.EQU(equRest1), Connect.EQU(equRest2), false);
then equalSets;

// deal with non empty Connect.FLOW
case (Connect.FLOW((cr1,face1,_)::flowRest1),
Connect.FLOW((cr2,face2,_)::flowRest2))
case (_,Connect.FLOW((cr1,face1,_)::flowRest1),Connect.FLOW((cr2,face2,_)::flowRest2))
equation
true = faceEqual(face1, face2);
true = ComponentReference.crefEqualNoStringCompare(cr1, cr2);
true = setsEqual(Connect.FLOW(flowRest1),Connect.FLOW(flowRest2));
then
true;
equalSets = faceEqual(face1, face2);
equalSets = Debug.bcallret2(equalSets, ComponentReference.crefEqualNoStringCompare, cr1, cr2, false);
equalSets = Debug.bcallret3(equalSets, setsEqual2, false, Connect.FLOW(flowRest1),Connect.FLOW(flowRest2), false);
then equalSets;

// deal with non empty Connect.STREAM
case (Connect.STREAM((cr1,_,face1,_)::streamRest1),
Connect.STREAM((cr2,_,face2,_)::streamRest2))
case (_,Connect.STREAM((cr1,_,face1,_)::streamRest1),Connect.STREAM((cr2,_,face2,_)::streamRest2))
equation
true = faceEqual(face1, face2);
true = ComponentReference.crefEqualNoStringCompare(cr1, cr2);
true = setsEqual(Connect.STREAM(streamRest1),Connect.STREAM(streamRest2));
then
true;
case (_, _) then false;
end matchcontinue;
end setsEqual;
equalSets = faceEqual(face1, face2);
equalSets = Debug.bcallret2(equalSets, ComponentReference.crefEqualNoStringCompare, cr1, cr2, false);
equalSets = Debug.bcallret3(equalSets, setsEqual2, false, Connect.STREAM(streamRest1),Connect.STREAM(streamRest2), false);
then equalSets;
else false;
end match;
end setsEqual2;

//- Merging

Expand Down

0 comments on commit e3e57c7

Please sign in to comment.