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

Commit deeabde

Browse files
hkielOpenModelica-Hudson
authored andcommitted
Fix initial size of HashSet
reduces execution time of inlineWhenForInitialization from O(n^3) to O(n^2) (see ScalableTestSuite)
1 parent 398f563 commit deeabde

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

Compiler/BackEnd/Initialization.mo

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ protected function inlineWhenForInitialization "author: lochel
324324
output BackendDAE.BackendDAE outDAE = inDAE;
325325
protected
326326
list<BackendDAE.Equation> eqnlst;
327-
HashSet.HashSet leftCrs = HashSet.emptyHashSetSized(50) "dummy hash set - should always be empty";
327+
HashSet.HashSet leftCrs = HashSet.emptyHashSet() "dummy hash set - should always be empty";
328328
algorithm
329329
outDAE.eqs := List.map(inDAE.eqs, inlineWhenForInitializationSystem);
330330
(eqnlst, _) := BackendEquation.traverseEquationArray(inDAE.shared.removedEqs, inlineWhenForInitializationEquation, ({}, leftCrs));
@@ -336,7 +336,7 @@ protected function inlineWhenForInitializationSystem "author: lochel"
336336
output BackendDAE.EqSystem outEqSystem;
337337
protected
338338
list<BackendDAE.Equation> eqnlst;
339-
HashSet.HashSet leftCrs = HashSet.emptyHashSetSized(50) "hack for #3209";
339+
HashSet.HashSet leftCrs = HashSet.emptyHashSet() "hack for #3209";
340340
list<DAE.ComponentRef> crefLst;
341341
algorithm
342342
(eqnlst, leftCrs) := BackendEquation.traverseEquationArray(inEqSystem.orderedEqs, inlineWhenForInitializationEquation, ({}, leftCrs));
@@ -455,7 +455,7 @@ protected function inlineWhenForInitializationWhenAlgorithm "author: lochel
455455
output list< DAE.Statement> outStmts;
456456
output HashSet.HashSet outLeftCrs;
457457
algorithm
458-
(outStmts, outLeftCrs) := matchcontinue(inStmts)
458+
(outStmts, outLeftCrs) := match(inStmts)
459459
local
460460
DAE.Statement stmt;
461461
list<DAE.Statement> stmts, rest;
@@ -476,7 +476,7 @@ algorithm
476476
case stmt::rest equation
477477
(stmts, leftCrs) = inlineWhenForInitializationWhenAlgorithm(rest, stmt::inAcc, inLeftCrs);
478478
then (stmts, leftCrs);
479-
end matchcontinue;
479+
end match;
480480
end inlineWhenForInitializationWhenAlgorithm;
481481

482482
protected function inlineWhenForInitializationWhenStmt "author: lochel
@@ -487,7 +487,7 @@ protected function inlineWhenForInitializationWhenStmt "author: lochel
487487
output list< DAE.Statement> outStmts;
488488
output HashSet.HashSet outLeftCrs;
489489
algorithm
490-
(outStmts, outLeftCrs) := matchcontinue(inWhenStatement)
490+
(outStmts, outLeftCrs) := match(inWhenStatement)
491491
local
492492
DAE.Exp condition;
493493
list<DAE.ComponentRef> crefLst;
@@ -496,21 +496,20 @@ algorithm
496496
HashSet.HashSet leftCrs;
497497

498498
// active when equation during initialization
499-
case DAE.STMT_WHEN(exp=condition, statementLst=stmts) equation
500-
true = Expression.containsInitialCall(condition, false);
499+
case DAE.STMT_WHEN(exp=condition, statementLst=stmts) guard
500+
Expression.containsInitialCall(condition, false)
501+
equation
501502
stmts = List.foldr(stmts, List.consr, inAcc);
502503
then (stmts, inLeftCrs);
503504

504505
// inactive when equation during initialization
505506
case DAE.STMT_WHEN(exp=condition, statementLst=stmts, elseWhen=NONE()) equation
506-
false = Expression.containsInitialCall(condition, false);
507507
crefLst = CheckModel.algorithmStatementListOutputs(stmts, DAE.EXPAND()); // expand as we're in an algorithm
508508
leftCrs = List.fold(crefLst, BaseHashSet.add, inLeftCrs);
509509
then (inAcc, leftCrs);
510510

511511
// inactive when equation during initialization with elsewhen part
512512
case DAE.STMT_WHEN(exp=condition, statementLst=stmts, elseWhen=SOME(stmt)) equation
513-
false = Expression.containsInitialCall(condition, false);
514513
crefLst = CheckModel.algorithmStatementListOutputs(stmts, DAE.EXPAND()); // expand as we're in an algorithm
515514
leftCrs = List.fold(crefLst, BaseHashSet.add, inLeftCrs);
516515
(stmts, leftCrs) = inlineWhenForInitializationWhenStmt(stmt, leftCrs, inAcc);
@@ -519,7 +518,7 @@ algorithm
519518
else equation
520519
Error.addInternalError("function inlineWhenForInitializationWhenStmt failed", sourceInfo());
521520
then fail();
522-
end matchcontinue;
521+
end match;
523522
end inlineWhenForInitializationWhenStmt;
524523

525524
protected function generateInactiveWhenEquationForInitialization "author: lochel"

0 commit comments

Comments
 (0)