Skip to content

Commit

Permalink
- becauase edge and change uses a and pre(a) do not ignore them
Browse files Browse the repository at this point in the history
- continue redesign of remove simple equation

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13885 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 13, 2012
1 parent a802fd2 commit d753a1a
Show file tree
Hide file tree
Showing 8 changed files with 1,015 additions and 106 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2584,8 +2584,8 @@ algorithm
replaceableAlias(v1);
replaceableAlias(v2);
// calc wights
w1 = BackendVariable.calcAliasKey(cr1,v1);
w2 = BackendVariable.calcAliasKey(cr2,v2);
w1 = BackendVariable.calcAliasKey(v1);
w2 = BackendVariable.calcAliasKey(v2);
b = intGt(w2,w1);
// select alias
((acr,avar,aindx,ae,cr,var,e)) = Util.if_(b,(cr2,v2,index2,e2,cr1,v1,e1),(cr1,v1,index1,e1,cr2,v2,e2));
Expand Down
791 changes: 771 additions & 20 deletions Compiler/BackEnd/BackendDAEOptimize.mo

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6843,12 +6843,6 @@ algorithm
case ((e as DAE.CALL(path = Absyn.IDENT(name = "pre")),(vars,b)))
then
((e,false,(vars,b)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "change")),(vars,b)))
then
((e,false,(vars,b)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "edge")),(vars,b)))
then
((e,false,(vars,b)));
case ((e as DAE.CALL(expLst=expLst),(vars,b)))
equation
// check if vars not in condition
Expand Down Expand Up @@ -7087,12 +7081,6 @@ algorithm
case((e as DAE.CALL(path=Absyn.IDENT(name = "pre")),(vars,b)))
then
((e,false,(vars,b)));
case((e as DAE.CALL(path=Absyn.IDENT(name = "change")),(vars,b)))
then
((e,false,(vars,b)));
case((e as DAE.CALL(path=Absyn.IDENT(name = "edge")),(vars,b)))
then
((e,false,(vars,b)));
case ((e,(vars,b))) then ((e,not b,(vars,b)));
end matchcontinue;
end traverserjacobianNonlinearExp;
Expand Down Expand Up @@ -7178,12 +7166,6 @@ algorithm
case ((e as DAE.CALL(path = Absyn.IDENT(name = "pre")),(repl,vars,funcs,b)))
then
((e,false,(repl,vars,funcs,b)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "change")),(repl,vars,funcs,b)))
then
((e,false,(repl,vars,funcs,b)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "edge")),(repl,vars,funcs,b)))
then
((e,false,(repl,vars,funcs,b)));
case ((e as DAE.CALL(expLst=expLst),(repl,vars,funcs,b)))
equation
// check if vars not in condition
Expand Down Expand Up @@ -7240,13 +7222,6 @@ algorithm
case ((e as DAE.CALL(path = Absyn.IDENT(name = "pre")),(vars,b)))
then
((e,false,(vars,b)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "change")),(vars,b)))
then
((e,false,(vars,b)));
case ((e as DAE.CALL(path = Absyn.IDENT(name = "edge")),(vars,b)))
then
((e,false,(vars,b)));

// found ?
case ((e as DAE.CREF(componentRef = cr),(vars,_)))
equation
Expand Down
182 changes: 142 additions & 40 deletions Compiler/BackEnd/BackendEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,7 @@ algorithm
list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> tpls;
list<DAE.Var> varLst1,varLst2;
Absyn.Path patha,patha1,pathb,pathb1;
DAE.Dimensions dims;
// a = b;
case (DAE.CREF(componentRef = cr1),DAE.CREF(componentRef = cr2),_)
then (cr1,cr2,lhs,rhs,false)::inTpls;
Expand All @@ -1972,8 +1973,6 @@ algorithm
then (cr1,cr2,DAE.LUNARY(DAE.NOT(ty),lhs),rhs,true)::inTpls;
// not a = b;
case (DAE.LUNARY(DAE.NOT(ty),DAE.CREF(componentRef = cr1)),DAE.CREF(componentRef = cr2),_)
equation
ne = Expression.negate(rhs);
then (cr1,cr2,lhs,DAE.LUNARY(DAE.NOT(ty),rhs),true)::inTpls;
// not a = not b;
case (DAE.LUNARY(DAE.NOT(_),e1 as DAE.CREF(componentRef = cr1)),DAE.LUNARY(DAE.NOT(_),e2 as DAE.CREF(componentRef = cr2)),_)
Expand All @@ -1982,71 +1981,174 @@ algorithm
case (DAE.ARRAY(array = elst1),DAE.ARRAY(array = elst2),_)
then List.threadFold(elst1,elst2,aliasEquation1,inTpls);
// a = {b1,b2,b3,..}
//case (DAE.CREF(componentRef = cr1),DAE.ARRAY(array = elst2),_)
//case (DAE.CREF(componentRef = cr1),DAE.ARRAY(array = elst2,dims=dims),_)
// then
// aliasArray(cr1,false,elst2,dims,inTpls);
// -a = {b1,b2,b3,..}
//case (DAE.UNARY(DAE.UMINUS_ARR(_),e1 as DAE.CREF(componentRef = cr1)),DAE.ARRAY(array = elst2),_)
//case (DAE.UNARY(DAE.UMINUS_ARR(_),e1 as DAE.CREF(componentRef = cr1)),DAE.ARRAY(array = elst2,dims=dims),_)
// then
// aliasArray(cr1,true,elst2,dims,inTpls);
// a = -{b1,b2,b3,..}
//case (DAE.CREF(componentRef = cr1),DAE.UNARY(DAE.UMINUS_ARR(_),DAE.ARRAY(array = elst2)),_)
//case (DAE.CREF(componentRef = cr1),DAE.UNARY(DAE.UMINUS_ARR(_),DAE.ARRAY(array = elst2,ty=ty)),_)
// -a = -{b1,b2,b3,..}
//case (DAE.UNARY(DAE.UMINUS_ARR(_),e1 as DAE.CREF(componentRef = cr1)),DAE.UNARY(DAE.UMINUS_ARR(_),DAE.ARRAY(array = elst2)),_)
//case (DAE.UNARY(DAE.UMINUS_ARR(_),e1 as DAE.CREF(componentRef = cr1)),DAE.UNARY(DAE.UMINUS_ARR(_),DAE.ARRAY(array = elst2,ty=ty)),_)
// {a1,a2,a3,..} = b
//case (DAE.ARRAY(array = elst1),DAE.CREF(componentRef = cr2),_)
// -{a1,a2,a3,..} = b
//case (DAE.UNARY(DAE.UMINUS_ARR(_),DAE.ARRAY(array = elst1)),DAE.CREF(componentRef = cr2),_)
//case (DAE.UNARY(DAE.UMINUS_ARR(_),DAE.ARRAY(array = elst1,ty=ty)),DAE.CREF(componentRef = cr2),_)
// {a1,a2,a3,..} = -b
//case (DAE.ARRAY(array = elst1),DAE.UNARY(DAE.UMINUS_ARR(_),e2 as DAE.CREF(componentRef = cr2)),_)
// -{a1,a2,a3,..} = -b
//case (DAE.UNARY(DAE.UMINUS_ARR(_)DAE.ARRAY(array = elst1)),DAE.UNARY(DAE.UMINUS_ARR(_),e2 as DAE.CREF(componentRef = cr2)),_)
//case (DAE.UNARY(DAE.UMINUS_ARR(_)DAE.ARRAY(array = elst1,ty=ty)),DAE.UNARY(DAE.UMINUS_ARR(_),e2 as DAE.CREF(componentRef = cr2)),_)
// not a = {b1,b2,b3,..}
//case (DAE.LUNARY(DAE.NOT(_),e1 as DAE.CREF(componentRef = cr1)),DAE.ARRAY(array = elst2),_)
//case (DAE.LUNARY(DAE.NOT(_),e1 as DAE.CREF(componentRef = cr1)),DAE.ARRAY(array = elst2,ty=ty),_)
// a = not {b1,b2,b3,..}
//case (DAE.CREF(componentRef = cr1),DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst2)),_)
//case (DAE.CREF(componentRef = cr1),DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst2,ty=ty)),_)
// not a = not {b1,b2,b3,..}
//case (DAE.LUNARY(DAE.NOT(_),e1 as DAE.CREF(componentRef = cr1)),DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst2)),_)
//case (DAE.LUNARY(DAE.NOT(_),e1 as DAE.CREF(componentRef = cr1)),DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst2,ty=ty)),_)
// {a1,a2,a3,..} = not b
//case (DAE.ARRAY(array = elst1),DAE.LUNARY(DAE.NOT(_),e2 as DAE.CREF(componentRef = cr2)),_)
//case (DAE.ARRAY(array = elst1,ty=ty),DAE.LUNARY(DAE.NOT(_),e2 as DAE.CREF(componentRef = cr2)),_)
// not {a1,a2,a3,..} = b
//case (DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst1)),DAE.CREF(componentRef = cr2),_)
//case (DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst1,ty=ty)),DAE.CREF(componentRef = cr2),_)
// not {a1,a2,a3,..} = not b
//case (DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst1)),DAE.LUNARY(DAE.NOT(_),e2 as DAE.CREF(componentRef = cr2)),_)
//case (DAE.LUNARY(DAE.NOT(_),DAE.ARRAY(array = elst1,ty=ty)),DAE.LUNARY(DAE.NOT(_),e2 as DAE.CREF(componentRef = cr2)),_)
// a = Record(b1,b2,b3,..)
//case (DAE.CREF(componentRef = cr1),DAE.CALL(path=pathb,expLst=elst2,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(varLst=varLst2,complexClassType=ClassInf.RECORD(pathb1)))),_)
//equation
// true = Absyn.pathEqual(pathb,pathb1);
case (DAE.CREF(componentRef = cr1),DAE.CALL(path=pathb,expLst=elst2,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(varLst=varLst2,complexClassType=ClassInf.RECORD(pathb1)))),_)
equation
true = Absyn.pathEqual(pathb,pathb1);
then
aliasRecord(cr1,varLst2,elst2,inTpls);
// Record(a1,a2,a3,..) = b
//case (DAE.CALL(path=patha,expLst=elst1,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(varLst=varLst1,complexClassType=ClassInf.RECORD(patha1)))),DAE.CREF(componentRef = cr2),_)
//equation
// true = Absyn.pathEqual(patha,patha1);
case (DAE.CALL(path=patha,expLst=elst1,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(varLst=varLst1,complexClassType=ClassInf.RECORD(patha1)))),DAE.CREF(componentRef = cr2),_)
equation
true = Absyn.pathEqual(patha,patha1);
then
aliasRecord(cr2,varLst1,elst1,inTpls);
// Record(a1,a2,a3,..) = Record(b1,b2,b3,..)
case (DAE.CALL(path=patha,expLst=elst1,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(patha1)))),
DAE.CALL(path=pathb,expLst=elst2,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(pathb1)))),_)
equation
true = Absyn.pathEqual(patha,patha1);
true = Absyn.pathEqual(pathb,pathb1);
then List.threadFold(elst1,elst2,aliasEquation1,inTpls);
// {a1+b1,a2+b2,a3+b3,..} = 0;
case (DAE.ARRAY(array = elst1),_,_)
equation
true = Expression.isZero(rhs);
then List.fold(elst1,aliasExpression,inTpls);
// 0 = {a1+b1,a2+b2,a3+b3,..};
case (_,DAE.ARRAY(array = elst2),_)
equation
true = Expression.isZero(lhs);
then List.fold(elst2,aliasExpression,inTpls);
// lhs = 0
case (_,_,_)
equation
true = Expression.isZero(rhs);
then aliasExpression(lhs,inTpls);
// 0 = rhs
case (_,_,_)
equation
true = Expression.isZero(lhs);
then aliasExpression(rhs,inTpls);
// matchcontinue part
else
then aliasEquation2(lhs,rhs,inTpls);
end match;
end aliasEquation1;

protected function aliasEquation2
"function aliasEquation1
autor Frenkel TUD 2011-04
helper for aliasEquation"
input DAE.Exp lhs;
input DAE.Exp rhs;
input list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> inTpls "(cr1,cr2,cr1=e2,cr2=e1,true if negated alias)";
output list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> outTpls "(cr1,cr2,cr1=e2,cr2=e1,true if negated alias)";
algorithm
outTpls := matchcontinue (lhs,rhs,inTpls)
local
list<DAE.Exp> elst1,elst2;
// {a1+b1,a2+b2,a3+b3,..} = 0;
case (DAE.ARRAY(array = elst1),_,_)
equation
true = Expression.isZero(rhs);
then List.fold(elst1,aliasExpression,inTpls);
// 0 = {a1+b1,a2+b2,a3+b3,..};
case (_,DAE.ARRAY(array = elst2),_)
equation
true = Expression.isZero(lhs);
then List.fold(elst2,aliasExpression,inTpls);
// lhs = 0
case (_,_,_)
equation
true = Expression.isZero(rhs);
then aliasExpression(lhs,inTpls);
// 0 = rhs
case (_,_,_)
equation
true = Expression.isZero(lhs);
then aliasExpression(rhs,inTpls);
end matchcontinue;
end aliasEquation2;

protected function aliasArray
"function aliasArray
autor Frenkel TUD 2011-04
helper for aliasEquation"
input DAE.ComponentRef cr;
input Boolean negate;
input list<DAE.Exp> explst;
input DAE.Type iTy;
input list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> inTpls "(cr1,cr2,cr1=e2,cr2=e1,true if negated alias)";
output list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> outTpls "(cr1,cr2,cr1=e2,cr2=e1,true if negated alias)";
algorithm
outTpls := match (cr,negate,explst,iTy,inTpls)
local
DAE.ComponentRef cr1,cr2;
DAE.Exp e1,e2;
DAE.Type ty,ty1;
list<DAE.Exp> elst;
case (_,_,{},_,_) then inTpls;
// a = b
case (_,_,(e2 as DAE.CREF(componentRef = cr2))::elst,_,_)
equation
then
aliasArray(cr,negate,elst,iTy,inTpls);
// a = -b
// a = not b
end match;
end aliasArray;

protected function aliasRecord
"function aliasRecord
autor Frenkel TUD 2011-04
helper for aliasEquation"
input DAE.ComponentRef cr;
input list<DAE.Var> varLst;
input list<DAE.Exp> explst;
input list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> inTpls "(cr1,cr2,cr1=e2,cr2=e1,true if negated alias)";
output list<tuple<DAE.ComponentRef,DAE.ComponentRef,DAE.Exp,DAE.Exp,Boolean>> outTpls "(cr1,cr2,cr1=e2,cr2=e1,true if negated alias)";
algorithm
outTpls := match (cr,varLst,explst,inTpls)
local
DAE.ComponentRef cr1,cr2;
DAE.Exp e1,e2;
DAE.Type ty,ty1;
list<DAE.Exp> elst;
list<DAE.Var> vlst;
DAE.Ident ident;
case (_,{},{},_) then inTpls;
// a = b
case (_,DAE.TYPES_VAR(name=ident,ty=ty)::vlst,(e2 as DAE.CREF(componentRef = cr2))::elst,_)
equation
cr1 = ComponentReference.crefPrependIdent(cr,ident,{},ty);
e1 = DAE.CREF(cr1,ty);
then
aliasRecord(cr,vlst,elst,(cr1,cr2,e1,e2,false)::inTpls);
// a = -b
case (_,DAE.TYPES_VAR(name=ident,ty=ty)::vlst,(e2 as DAE.UNARY(DAE.UMINUS(ty1),DAE.CREF(componentRef = cr2)))::elst,_)
equation
cr1 = ComponentReference.crefPrependIdent(cr,ident,{},ty);
e1 = DAE.UNARY(DAE.UMINUS(ty1),DAE.CREF(cr1,ty));
then
aliasRecord(cr,vlst,elst,(cr1,cr2,e1,e2,true)::inTpls);
case (_,DAE.TYPES_VAR(name=ident,ty=ty)::vlst,(e2 as DAE.UNARY(DAE.UMINUS_ARR(ty1),DAE.CREF(componentRef = cr2)))::elst,_)
equation
cr1 = ComponentReference.crefPrependIdent(cr,ident,{},ty);
e1 = DAE.UNARY(DAE.UMINUS_ARR(ty1),DAE.CREF(cr1,ty));
then
aliasRecord(cr,vlst,elst,(cr1,cr2,e1,e2,true)::inTpls);
// a = not b
case (_,DAE.TYPES_VAR(name=ident,ty=ty)::vlst,(e2 as DAE.LUNARY(DAE.NOT(ty1),DAE.CREF(componentRef = cr2)))::elst,_)
equation
cr1 = ComponentReference.crefPrependIdent(cr,ident,{},ty);
e1 = DAE.LUNARY(DAE.NOT(ty1),DAE.CREF(cr1,ty));
then
aliasRecord(cr,vlst,elst,(cr1,cr2,e1,e2,true)::inTpls);
end match;
end aliasRecord;

protected function aliasExpression
"function aliasExpression
autor Frenkel TUD 2011-11
Expand Down
14 changes: 13 additions & 1 deletion Compiler/BackEnd/BackendVarTransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1200,14 +1200,26 @@ public function skipPreOperator "function: skipPreOperator
This function is passed to replace_exp to ensure this."
input DAE.Exp inExp;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inExp)
case (DAE.CALL(path = Absyn.IDENT(name = "pre"))) then false;
case (_) then true;
end matchcontinue;
end skipPreOperator;

public function skipPreChangeEdgeOperator "function: skipPreChangeEdgeOperator
The variable/exp in the pre/change/edge operator should not be replaced.
This function is passed to replace_exp to ensure this."
input DAE.Exp inExp;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inExp)
case (DAE.CALL(path = Absyn.IDENT(name = "pre"))) then false;
case (DAE.CALL(path = Absyn.IDENT(name = "change"))) then false;
case (DAE.CALL(path = Absyn.IDENT(name = "edge"))) then false;
case (_) then true;
end matchcontinue;
end skipPreOperator;
end skipPreChangeEdgeOperator;

/*********************************************************/
/* replace Equations */
Expand Down

0 comments on commit d753a1a

Please sign in to comment.