Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Optimize if-statements a bit when traversing the DAE


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9629 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 10, 2011
1 parent dede75f commit 9be4ddf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions Compiler/FrontEnd/Algorithm.mo
Expand Up @@ -481,6 +481,23 @@ algorithm
end matchcontinue;
end makeIf;

public function optimizeIf
"Every time we re-create/walk an if-statement, we optimize a bit :)"
input DAE.Exp cond;
input list<Statement> stmts;
input DAE.Else _else;
input DAE.ElementSource source;
output list<Statement> ostmts "can be empty or selected branch";
algorithm
ostmts := match (cond,stmts,_else,source)
case (DAE.BCONST(true),stmts,_else,source) then stmts;
case (DAE.BCONST(false),stmts,DAE.NOELSE(),source) then {};
case (DAE.BCONST(false),_,DAE.ELSE(stmts),source) then stmts;
case (DAE.BCONST(false),_,DAE.ELSEIF(cond,stmts,_else),source) then optimizeIf(cond,stmts,_else,source);
else DAE.STMT_IF(cond,stmts,_else,source)::{};
end match;
end optimizeIf;

protected function makeElse "function: makeElse
This function creates the ELSE part of the DAE.STMT_IF and checks if is correct."
input list<tuple<DAE.Exp, DAE.Properties, list<Statement>>> inTplExpExpTypesPropertiesStatementLstLst;
Expand Down
7 changes: 4 additions & 3 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -3932,9 +3932,9 @@ algorithm
DAE.Exp e_1,e_2,e,e2;
list<DAE.Exp> expl1,expl2;
DAE.ComponentRef cr_1,cr;
list<DAE.Statement> xs_1,xs,stmts,stmts2;
list<DAE.Statement> xs_1,xs,stmts,stmts1,stmts2;
DAE.ExpType tp;
DAE.Statement x,ew,ew_1;
DAE.Statement x,ew,ew_1,res;
Boolean b1;
String id1,str;
list<Integer> li;
Expand Down Expand Up @@ -3982,7 +3982,8 @@ algorithm
(stmts2,extraArg) = traverseDAEEquationsStmts(stmts,func,extraArg);
((e_1,extraArg)) = func((e, extraArg));
(xs_1,extraArg) = traverseDAEEquationsStmts(xs, func, extraArg);
then (DAE.STMT_IF(e_1,stmts2,algElse,source) :: xs_1,extraArg);
stmts1 = Algorithm.optimizeIf(e_1,stmts2,algElse,source);
then (listAppend(stmts1, xs_1),extraArg);

case (((x as DAE.STMT_FOR(type_=tp,iterIsArray=b1,iter=id1,range=e,statementLst=stmts, source = source)) :: xs),func,extraArg)
equation
Expand Down

0 comments on commit 9be4ddf

Please sign in to comment.