Skip to content

Commit

Permalink
- remove some never matched cases from simplifyBinaryConst, fix bug f…
Browse files Browse the repository at this point in the history
…or GREATEREQ, move true=positiveZero(e1)=negativeZero(e2) to simplifyBinary

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12677 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Aug 25, 2012
1 parent 83ea71a commit a85bb41
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 52 deletions.
30 changes: 20 additions & 10 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3127,20 +3127,13 @@ algorithm
case ((v as BackendDAE.VAR(varName=cr,bindExp=SOME(e),values=attr),(repl,numrepl)))
equation
(e1,true) = BackendVarTransform.replaceExp(e, repl, NONE());
(e1,_) = ExpressionSimplify.simplify(e1);
v1 = BackendVariable.setBindExp(v,e1);
true = Expression.isConst(e1);
repl_1 = BackendVarTransform.addReplacement(repl, cr, e1,NONE());
repl_1 = addConstExpReplacement(e1,cr,repl);
(attr,repl_1) = BackendDAEUtil.traverseBackendDAEVarAttr(attr,traverseExpVisitorWrapper,repl_1);
v1 = BackendVariable.setVarAttributes(v1,attr);
then ((v1,(repl_1,numrepl+1)));
case ((v as BackendDAE.VAR(bindExp=SOME(e),values=attr),(repl,numrepl)))
equation
(e1,true) = BackendVarTransform.replaceExp(e, repl, NONE());
v1 = BackendVariable.setBindExp(v,e1);
(new_attr,repl) = BackendDAEUtil.traverseBackendDAEVarAttr(attr,traverseExpVisitorWrapper,repl);
v1 = BackendVariable.setVarAttributes(v1,new_attr);
then ((v1,(repl,numrepl)));


case ((v as BackendDAE.VAR(values=attr),(repl,numrepl)))
equation
(new_attr,repl) = BackendDAEUtil.traverseBackendDAEVarAttr(attr,traverseExpVisitorWrapper,repl);
Expand All @@ -3149,6 +3142,23 @@ algorithm
end matchcontinue;
end replaceFinalVarTraverser;

protected function addConstExpReplacement
input DAE.Exp inExp;
input DAE.ComponentRef cr;
input BackendVarTransform.VariableReplacements inRepl;
output BackendVarTransform.VariableReplacements outRepl;
algorithm
outRepl := matchcontinue(inExp,cr,inRepl)
case (_,_,_)
equation
true = Expression.isConst(inExp);
then
BackendVarTransform.addReplacement(inRepl, cr, inExp,NONE());
else
inRepl;
end matchcontinue;
end addConstExpReplacement;

protected function traverseExpVisitorWrapper "help function to replaceFinalVarTraverser"
input tuple<DAE.Exp,BackendVarTransform.VariableReplacements> inTpl;
output tuple<DAE.Exp,BackendVarTransform.VariableReplacements> outTpl;
Expand Down
48 changes: 6 additions & 42 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3240,12 +3240,6 @@ algorithm
b = v1 <. v2;
then
DAE.BCONST(b);

case(DAE.LESS(ty=_),DAE.ENUM_LITERAL(index=i1),DAE.ENUM_LITERAL(index=i2))
equation
b = i1 < i2;
then
DAE.BCONST(b);

case(DAE.LESSEQ(ty=_),DAE.BCONST(true),DAE.BCONST(false))
then DAE.BCONST(false);
Expand All @@ -3261,12 +3255,6 @@ algorithm
then
DAE.BCONST(b);

case(DAE.LESSEQ(ty=_),DAE.ENUM_LITERAL(index=i1),DAE.ENUM_LITERAL(index=i2))
equation
b = i1 <= i2;
then
DAE.BCONST(b);

case(DAE.GREATER(ty=_),DAE.BCONST(true),DAE.BCONST(false))
then DAE.BCONST(true);

Expand All @@ -3280,25 +3268,13 @@ algorithm
b = v1 >. v2;
then
DAE.BCONST(b);

case(DAE.GREATER(ty=_),DAE.ENUM_LITERAL(index=i1),DAE.ENUM_LITERAL(index=i2))
equation
b = i1 > i2;
then
DAE.BCONST(b);

case(DAE.GREATEREQ(ty=_),DAE.BCONST(false),DAE.BCONST(true))
then DAE.BCONST(false);

case(DAE.GREATEREQ(ty=_),DAE.BCONST(_),DAE.BCONST(_))
then DAE.BCONST(true);

case(DAE.GREATEREQ(ty=_),exp1,exp2)
equation
true = Expression.isPositiveOrZero(exp1);
true = Expression.isNegativeOrZero(exp2);
then DAE.BCONST(true);

case(DAE.GREATEREQ(ty=_),exp1,exp2)
equation
v1 = Expression.getRealConst(exp1);
Expand All @@ -3307,12 +3283,6 @@ algorithm
then
DAE.BCONST(b);

case(DAE.GREATEREQ(ty=_),DAE.ENUM_LITERAL(index=i1),DAE.ENUM_LITERAL(index=i2))
equation
b = i1 >= i2;
then
DAE.BCONST(b);

case(DAE.EQUAL(ty=_),DAE.BCONST(b1),DAE.BCONST(b2))
equation
b = boolEq(b1,b2);
Expand All @@ -3333,12 +3303,6 @@ algorithm
then
DAE.BCONST(b);

case(DAE.EQUAL(ty=_),DAE.ENUM_LITERAL(index=i1),DAE.ENUM_LITERAL(index=i2))
equation
b = i1 == i2;
then
DAE.BCONST(b);

case(DAE.NEQUAL(ty=_),DAE.BCONST(b1),DAE.BCONST(b2))
equation
b = not boolEq(b1,b2);
Expand All @@ -3359,12 +3323,6 @@ algorithm
then
DAE.BCONST(b);

case(DAE.NEQUAL(ty=_),DAE.ENUM_LITERAL(index=i1),DAE.ENUM_LITERAL(index=i2))
equation
b = i1 <> i2;
then
DAE.BCONST(b);

case(DAE.AND(DAE.T_BOOL(varLst = _)),exp1,exp2)
equation
b1 = Expression.getBoolConst(exp1);
Expand Down Expand Up @@ -3983,6 +3941,12 @@ algorithm
then
DAE.RANGE(ty,e1,oexp,e2);

case(DAE.GREATEREQ(ty=_),_,_)
equation
true = Expression.isPositiveOrZero(inExp3);
true = Expression.isNegativeOrZero(inExp4);
then DAE.BCONST(true);

end matchcontinue;
end simplifyBinary;

Expand Down

0 comments on commit a85bb41

Please sign in to comment.