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

Commit a72f165

Browse files
hkielOpenModelica-Hudson
authored andcommitted
some small optimizations
avoid matchcontinue Belonging to [master]: - #1949
1 parent 978d276 commit a72f165

File tree

10 files changed

+112
-151
lines changed

10 files changed

+112
-151
lines changed

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -174,87 +174,52 @@ algorithm
174174
BackendDAE.Var var;
175175
DAE.CallAttributes attr;
176176
Boolean negate;
177+
String idn;
177178

178179
case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (globalKnownVars, aliasvars, _)) equation
179180
(var, _) = BackendVariable.getVarSingle(cr, globalKnownVars);
180181
false = BackendVariable.isVarOnTopLevelAndInput(var);
181182
(zero, _) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
182183
then (zero, (globalKnownVars, aliasvars, true));
183184

184-
case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={e as DAE.CREF(componentRef=cr)}), (globalKnownVars, aliasvars, _)) equation
185+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={e as DAE.CREF(componentRef=cr)}), (globalKnownVars, aliasvars, _)) guard idn=="pre" or idn=="previous" equation
185186
(_, _) = BackendVariable.getVarSingle(cr, globalKnownVars);
186187
then(e, (globalKnownVars, aliasvars, true));
187188

188-
case (DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={e as DAE.CREF(componentRef=cr)}), (globalKnownVars, aliasvars, _)) equation
189-
(_, _) = BackendVariable.getVarSingle(cr, globalKnownVars);
190-
then(e, (globalKnownVars, aliasvars, true));
191-
192-
case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={e as DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (globalKnownVars, aliasvars, _))
193-
then (e, (globalKnownVars, aliasvars, true));
194-
195-
case (DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={e as DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (globalKnownVars, aliasvars, _))
196-
then (e, (globalKnownVars, aliasvars, true));
197-
198-
case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={e as DAE.UNARY(DAE.UMINUS(_), DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time")))}), (globalKnownVars, aliasvars, _))
189+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={e as DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (globalKnownVars, aliasvars, _)) guard idn=="pre" or idn=="previous"
199190
then (e, (globalKnownVars, aliasvars, true));
200191

201-
case (DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={e as DAE.UNARY(DAE.UMINUS(_), DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time")))}), (globalKnownVars, aliasvars, _))
202-
then (e, (globalKnownVars, aliasvars, true));
203-
204-
case (DAE.CALL(path=Absyn.IDENT(name="pre"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (globalKnownVars, aliasvars, _)) equation
205-
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
206-
(cr, negate) = BackendVariable.getAlias(var);
207-
e = DAE.CREF(cr, tp);
208-
e = if negate then Expression.negate(e) else e;
209-
(e, _) = ExpressionSimplify.simplify(DAE.CALL(Absyn.IDENT("pre"), {e}, attr));
210-
(e, _) = Expression.traverseExpBottomUp(e, traverserExpsimplifyTimeIndepFuncCalls, (globalKnownVars, aliasvars, false));
192+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={e as DAE.UNARY(DAE.UMINUS(_), DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time")))}), (globalKnownVars, aliasvars, _)) guard idn=="pre" or idn=="previous"
211193
then (e, (globalKnownVars, aliasvars, true));
212194

213-
case (DAE.CALL(path=Absyn.IDENT(name="previous"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (globalKnownVars, aliasvars, _)) equation
195+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (globalKnownVars, aliasvars, _)) guard idn=="pre" or idn=="previous" equation
214196
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
215197
(cr, negate) = BackendVariable.getAlias(var);
216198
e = DAE.CREF(cr, tp);
217199
e = if negate then Expression.negate(e) else e;
218-
(e, _) = ExpressionSimplify.simplify(DAE.CALL(Absyn.IDENT("previous"), {e}, attr));
200+
(e, _) = ExpressionSimplify.simplify(DAE.CALL(Absyn.IDENT(idn), {e}, attr));
219201
(e, _) = Expression.traverseExpBottomUp(e, traverserExpsimplifyTimeIndepFuncCalls, (globalKnownVars, aliasvars, false));
220202
then (e, (globalKnownVars, aliasvars, true));
221203

222-
case (DAE.CALL(path=Absyn.IDENT(name="change"), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (globalKnownVars, aliasvars, _)) equation
204+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (globalKnownVars, aliasvars, _)) guard idn=="change" or idn=="edge" equation
223205
(_::_, _) = BackendVariable.getVar(cr, globalKnownVars);
224206
zero = Expression.arrayFill(Expression.arrayDimension(tp), DAE.BCONST(false));
225207
then (zero, (globalKnownVars, aliasvars, true));
226208

227-
case (DAE.CALL(path=Absyn.IDENT(name="change"), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (globalKnownVars, aliasvars, _)) equation
209+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (globalKnownVars, aliasvars, _)) guard idn=="change" or idn=="edge" equation
228210
(_::_, _) = BackendVariable.getVar(cr, aliasvars);
229211
zero = Expression.arrayFill(Expression.arrayDimension(tp), DAE.BCONST(false));
230212
then (zero, (globalKnownVars, aliasvars, true));
231213

232-
case (DAE.CALL(path=Absyn.IDENT(name="change"), expLst={DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (globalKnownVars, aliasvars, _))
233-
then (DAE.BCONST(false), (globalKnownVars, aliasvars, true));
234-
235-
case (DAE.CALL(path=Absyn.IDENT(name="change"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (globalKnownVars, aliasvars, _)) equation
236-
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
237-
(cr, negate) = BackendVariable.getAlias(var);
238-
e = DAE.CREF(cr, tp);
239-
e = if negate then Expression.negate(e) else e;
240-
(e, _) = ExpressionSimplify.simplify(DAE.CALL(Absyn.IDENT("change"), {e}, attr));
241-
(e, _) = Expression.traverseExpBottomUp(e, traverserExpsimplifyTimeIndepFuncCalls, (globalKnownVars, aliasvars, false));
242-
then (e, (globalKnownVars, aliasvars, true));
243-
244-
case (DAE.CALL(path=Absyn.IDENT(name="edge"), expLst={DAE.CREF(componentRef=cr, ty=tp)}), (globalKnownVars, aliasvars, _)) equation
245-
(_, _) = BackendVariable.getVarSingle(cr, globalKnownVars);
246-
zero = Expression.arrayFill(Expression.arrayDimension(tp), DAE.BCONST(false));
247-
then (zero, (globalKnownVars, aliasvars, true));
248-
249-
case (DAE.CALL(path=Absyn.IDENT(name="edge"), expLst={DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (globalKnownVars, aliasvars, _))
214+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))}), (globalKnownVars, aliasvars, _)) guard idn=="change" or idn=="edge"
250215
then (DAE.BCONST(false), (globalKnownVars, aliasvars, true));
251216

252-
case (DAE.CALL(path=Absyn.IDENT(name="edge"), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (globalKnownVars, aliasvars, _)) equation
217+
case (DAE.CALL(path=Absyn.IDENT(name=idn), expLst={DAE.CREF(componentRef=cr, ty=tp)}, attr=attr), (globalKnownVars, aliasvars, _)) guard idn=="change" or idn=="edge" equation
253218
(var, _) = BackendVariable.getVarSingle(cr, aliasvars);
254219
(cr, negate) = BackendVariable.getAlias(var);
255220
e = DAE.CREF(cr, tp);
256221
e = if negate then Expression.negate(e) else e;
257-
(e, _) = ExpressionSimplify.simplify(DAE.CALL(Absyn.IDENT("edge"), {e}, attr));
222+
(e, _) = ExpressionSimplify.simplify(DAE.CALL(Absyn.IDENT(idn), {e}, attr));
258223
(e, _) = Expression.traverseExpBottomUp(e, traverserExpsimplifyTimeIndepFuncCalls, (globalKnownVars, aliasvars, false));
259224
then (e, (globalKnownVars, aliasvars, true));
260225

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,7 @@ algorithm
26882688
Integer diffindx;
26892689
list<DAE.Subscript> subs;
26902690
AvlSetPath.Tree visitedPaths;
2691+
String idn;
26912692

26922693
case (DAE.LBINARY(), tpl)
26932694
then (inExp, false, tpl);
@@ -2753,11 +2754,8 @@ algorithm
27532754
then (inExp, false,(vars, pa, visitedPaths, ofunctionTree));
27542755

27552756
/* pre(v) is considered a known variable */
2756-
case (DAE.CALL(path=Absyn.IDENT(name="pre")), tpl)
2757-
then (inExp, false, tpl);
2758-
27592757
/* previous(v) is considered a known variable */
2760-
case (DAE.CALL(path=Absyn.IDENT(name="previous")), tpl)
2758+
case (DAE.CALL(path=Absyn.IDENT(name=idn)), tpl) guard idn=="pre" or idn=="previous"
27612759
then (inExp, false, tpl);
27622760

27632761
/* delay(...) can be used to break algebraic loops given some solver options */

Compiler/BackEnd/BackendEquation.mo

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,11 @@ public function checkEquationsVarsExpTopDown
406406
input output AvlSetInt.Tree tree;
407407
input BackendDAE.Variables vars;
408408
algorithm
409-
(cont,tree) := matchcontinue exp
409+
(cont,tree) := match exp
410410
local
411411
DAE.ComponentRef cr;
412412
list<Integer> ilst;
413+
String idn;
413414

414415
// special case for time, it is never part of the equation system
415416
case DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time"))
@@ -419,23 +420,22 @@ algorithm
419420
case DAE.CREF(ty=DAE.T_FUNCTION_REFERENCE_FUNC())
420421
then (true, tree);
421422

422-
// case for pre vars
423-
case DAE.CALL(path = Absyn.IDENT(name = "pre"))
424-
then (false, tree);
425-
426-
// case for previous vars
427-
case DAE.CALL(path = Absyn.IDENT(name = "previous"))
423+
// case for pre and previous vars
424+
case DAE.CALL(path = Absyn.IDENT(name = idn)) guard idn=="pre" or idn=="previous"
428425
then (false, tree);
429426

430427
// add it
431428
case DAE.CREF(componentRef = cr)
432429
algorithm
430+
try
433431
(_, ilst) := BackendVariable.getVar(cr, vars);
434432
tree := AvlSetInt.addList(tree, ilst);
433+
else
434+
end try;
435435
then (true, tree);
436436

437437
else (true, tree);
438-
end matchcontinue;
438+
end match;
439439
end checkEquationsVarsExpTopDown;
440440

441441
public function assertWithCondTrue "author: Frenkel TUD 2012-12"

Compiler/BackEnd/BackendVarTransform.mo

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,8 +1508,9 @@ public function skipPreOperator "The variable/exp in the pre operator should not
15081508
output Boolean outBoolean;
15091509
algorithm
15101510
outBoolean := match (inExp)
1511-
case (DAE.CALL(path = Absyn.IDENT(name = "pre"))) then false;
1512-
case (DAE.CALL(path = Absyn.IDENT(name = "previous"))) then false;
1511+
local String idn;
1512+
case (DAE.CALL(path = Absyn.IDENT(name = idn)))
1513+
guard idn=="pre" or idn=="previous" then false;
15131514
else true;
15141515
end match;
15151516
end skipPreOperator;
@@ -1522,14 +1523,11 @@ algorithm
15221523
outBoolean := match (inExp)
15231524
local
15241525
DAE.ComponentRef cr;
1525-
case DAE.CALL(path = Absyn.IDENT(name = "pre"),expLst = {DAE.CREF(componentRef=cr)}) then selfGeneratedVar(cr);
1526-
case DAE.CALL(path = Absyn.IDENT(name = "previous"),expLst = {DAE.CREF(componentRef=cr)}) then selfGeneratedVar(cr);
1527-
case DAE.CALL(path = Absyn.IDENT(name = "change"),expLst = {DAE.CREF(componentRef=cr)}) then selfGeneratedVar(cr);
1528-
case DAE.CALL(path = Absyn.IDENT(name = "edge"),expLst = {DAE.CREF(componentRef=cr)}) then selfGeneratedVar(cr);
1529-
case DAE.CALL(path = Absyn.IDENT(name = "pre")) then false;
1530-
case DAE.CALL(path = Absyn.IDENT(name = "previous")) then false;
1531-
case DAE.CALL(path = Absyn.IDENT(name = "change")) then false;
1532-
case DAE.CALL(path = Absyn.IDENT(name = "edge")) then false;
1526+
String idn;
1527+
case DAE.CALL(path = Absyn.IDENT(name = idn),expLst = {DAE.CREF(componentRef=cr)})
1528+
guard idn=="pre" or idn=="previous" or idn=="change" or idn=="edge" then selfGeneratedVar(cr);
1529+
case DAE.CALL(path = Absyn.IDENT(name = idn))
1530+
guard idn=="pre" or idn=="previous" or idn=="change" or idn=="edge" then false;
15331531
else true;
15341532
end match;
15351533
end skipPreChangeEdgeOperator;
@@ -1539,9 +1537,8 @@ protected function selfGeneratedVar
15391537
output Boolean b;
15401538
algorithm
15411539
b := match(inCref)
1542-
case DAE.CREF_QUAL(ident = "$ZERO") then true;
1543-
case DAE.CREF_QUAL(ident = "$_DER") then true;
1544-
case DAE.CREF_QUAL(ident = "$pDER") then true;
1540+
local String idn;
1541+
case DAE.CREF_QUAL(ident = idn) guard idn=="$ZERO" or idn=="$_DER" or idn=="$pDER" then true;
15451542
// keep same a while untill we know which are needed
15461543
//case DAE.CREF_QUAL(ident = "$DER") then true;
15471544
else false;

Compiler/FrontEnd/ExpressionDump.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ Returns a string if SOME otherwise ''"
429429
algorithm
430430
str := match(oexp)
431431
local DAE.Exp e;
432-
case(NONE()) then "";
433432
case(SOME(e)) then printExpStr(e);
433+
else "";
434434
end match;
435435
end printOptExpStr;
436436

Compiler/FrontEnd/InstUtil.mo

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ public function prefixEqualUnlessBasicType
622622
algorithm
623623
_ := matchcontinue (pre1, pre2, cls)
624624
local
625+
String idn;
625626
// adrpo: TODO! FIXME!, I think here we should have pre1 = Prefix.CLASSPRE(variability1) == pre2 = Prefix.CLASSPRE(variability2)
626627

627628
// don't care about prefix for:
@@ -639,10 +640,7 @@ algorithm
639640
case (_, _, SCode.CLASS(restriction = SCode.R_PREDEFINED_CLOCK())) then ();
640641
// don't care about prefix for:
641642
// - Real, String, Integer, Boolean
642-
case (_, _, SCode.CLASS(name = "Real")) then ();
643-
case (_, _, SCode.CLASS(name = "Integer")) then ();
644-
case (_, _, SCode.CLASS(name = "String")) then ();
645-
case (_, _, SCode.CLASS(name = "Boolean")) then ();
643+
case (_, _, SCode.CLASS(name = idn)) guard idn=="Real" or idn== "Integer" or idn=="String" or idn=="Boolean" then ();
646644
// BTH
647645
case (_, _, SCode.CLASS(name = "Clock"))
648646
equation
@@ -3303,10 +3301,7 @@ algorithm
33033301
list<SCode.Element> els;
33043302
SCode.Path path;
33053303

3306-
case (cache, _, _, _, cl as SCode.CLASS(name = "Real"), _, _) then (cache,{},cl,DAE.NOMOD());
3307-
case (cache, _, _, _, cl as SCode.CLASS(name = "Integer"), _, _) then (cache,{},cl,DAE.NOMOD());
3308-
case (cache, _, _, _, cl as SCode.CLASS(name = "String"), _, _) then (cache,{},cl,DAE.NOMOD());
3309-
case (cache, _, _, _, cl as SCode.CLASS(name = "Boolean"), _, _) then (cache,{},cl,DAE.NOMOD());
3304+
case (cache, _, _, _, cl as SCode.CLASS(name = id), _, _) guard id=="Real" or id=="Integer" or id=="String" or id=="Boolean" then (cache,{},cl,DAE.NOMOD());
33103305
// BTH
33113306
case (cache, _, _, _, cl as SCode.CLASS(name = "Clock"), _, _)
33123307
equation
@@ -8344,8 +8339,8 @@ function isSubModDomainOrStart
83448339
output Boolean isNotDomain;
83458340
algorithm
83468341
isNotDomain := match subMod
8347-
case SCode.NAMEMOD(ident="domain") then true;
8348-
case SCode.NAMEMOD(ident="start") then true;
8342+
local String idn;
8343+
case SCode.NAMEMOD(ident=idn) guard idn=="domain" or idn=="start" then true;
83498344
else false;
83508345
end match;
83518346
end isSubModDomainOrStart;

0 commit comments

Comments
 (0)