Skip to content

Commit

Permalink
- CevalScript.mo, Main.mo, SimCode.mo
Browse files Browse the repository at this point in the history
  - do late inlining earlier to avoid generade code for unused functions
- Exp.mo
  - bugfix expStriplastSubs
  - isZero for UNARY_ARR
  - getTermsContainingX also for arrays

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5734 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 27, 2010
1 parent 6230303 commit 89eca8e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 17 deletions.
13 changes: 11 additions & 2 deletions Compiler/CevalScript.mo
Expand Up @@ -58,6 +58,7 @@ public import Env;
public import Interactive;
public import Dependency;
public import Values;
public import Inline;

protected import SimCode;
protected import AbsynDep;
Expand Down Expand Up @@ -3595,6 +3596,7 @@ algorithm
list<list<Integer>> comps;
list<Absyn.Path> funcpaths;
list<DAE.Element> funcelems;
DAE.FunctionTree funcs;
equation
//asInSimulationCode==true => it's necessary to do all the translation's steps before dumping with xml
_ = Error.getMessagesStr() "Clear messages";
Expand All @@ -3610,7 +3612,10 @@ algorithm
dlow = DAELow.lower(dae, true, true);
m = DAELow.incidenceMatrix(dlow);
mT = DAELow.transposeMatrix(m);
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),DAEUtil.daeFunctionTree(dae));
funcs = DAEUtil.daeFunctionTree(dae);
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),funcs);
// late Inline
dlow_1 = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = DAELow.translateDae(dlow_1,NONE());
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
Expand Down Expand Up @@ -3638,6 +3643,7 @@ algorithm
list<SCode.Class> p_1,sp;
list<Absyn.Path> funcpaths;
list<DAE.Element> funcelems;
DAE.FunctionTree funcs;
equation
//asInSimulationCode==false => it's NOT necessary to do all the translation's steps before dumping with xml
_ = Error.getMessagesStr() "Clear messages";
Expand All @@ -3653,7 +3659,10 @@ algorithm
dlow = DAELow.lower(dae, true, true);
m = DAELow.incidenceMatrix(dlow);
mT = DAELow.transposeMatrix(m);
(_,_,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),DAEUtil.daeFunctionTree(dae));
funcs = DAEUtil.daeFunctionTree(dae);
(_,_,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),funcs);
// late Inline
dlow_1 = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
xml_filename = Util.stringAppendList({filenameprefix,".xml"});
funcpaths = SimCode.getCalledFunctions(dae, dlow_1);
funcelems = SimCode.generateFunctions2(p_1, funcpaths);
Expand Down
37 changes: 34 additions & 3 deletions Compiler/Exp.mo
Expand Up @@ -633,14 +633,14 @@ algorithm
then DAE.CREF(cr_1,ty);
case (DAE.UNARY(operator=op,exp=e))
equation
ty = typeof(e);
e_1 = expStripLastSubs(e);
ty = typeof(e_1);
true = DAEUtil.expTypeArray(ty);
then DAE.UNARY(DAE.UMINUS_ARR(ty),e_1);
case (DAE.UNARY(operator=op,exp=e))
equation
ty = typeof(e);
e_1 = expStripLastSubs(e);
ty = typeof(e_1);
false = DAEUtil.expTypeArray(ty);
then DAE.UNARY(DAE.UMINUS(ty),e_1);
end matchcontinue;
Expand Down Expand Up @@ -886,6 +886,7 @@ algorithm
res = Util.boolAndList(ab);
then
res;
case(DAE.UNARY(DAE.UMINUS_ARR(_),e)) then isZero(e);
case (_) then false;
end matchcontinue;
end isZero;
Expand Down Expand Up @@ -921,7 +922,7 @@ algorithm
res = isConst(e);
then
res;
case (DAE.BINARY(e1,op,e2))
case (DAE.BINARY(e1,op,e2))
equation
b1 = isConst(e1);
b2 = isConst(e2);
Expand Down Expand Up @@ -9647,6 +9648,36 @@ algorithm
nonxt = DAE.UNARY(DAE.UMINUS(ty),nonxt1);
then
(xt,nonxt);
case (DAE.BINARY(exp1 = e1,operator = DAE.ADD_ARR(ty = ty),exp2 = e2),(cr as DAE.CREF(componentRef = _)))
equation
(xt1,nonxt1) = getTermsContainingX(e1, cr);
(xt2,nonxt2) = getTermsContainingX(e2, cr);
xt = DAE.BINARY(xt1,DAE.ADD_ARR(ty),xt2);
nonxt = DAE.BINARY(nonxt1,DAE.ADD_ARR(ty),nonxt2);
then
(xt,nonxt);
case (DAE.BINARY(exp1 = e1,operator = DAE.SUB_ARR(ty = ty),exp2 = e2),(cr as DAE.CREF(componentRef = _)))
equation
(xt1,nonxt1) = getTermsContainingX(e1, cr);
(xt2,nonxt2) = getTermsContainingX(e2, cr);
xt = DAE.BINARY(xt1,DAE.SUB_ARR(ty),xt2);
nonxt = DAE.BINARY(nonxt1,DAE.SUB_ARR(ty),nonxt2);
then
(xt,nonxt);
case (DAE.UNARY(operator = DAE.UPLUS_ARR(ty = ty),exp = e),(cr as DAE.CREF(componentRef = _)))
equation
(xt1,nonxt1) = getTermsContainingX(e, cr);
xt = DAE.UNARY(DAE.UPLUS_ARR(ty),xt1);
nonxt = DAE.UNARY(DAE.UPLUS_ARR(ty),nonxt1);
then
(xt,nonxt);
case (DAE.UNARY(operator = DAE.UMINUS_ARR(ty = ty),exp = e),(cr as DAE.CREF(componentRef = _)))
equation
(xt1,nonxt1) = getTermsContainingX(e, cr);
xt = DAE.UNARY(DAE.UMINUS_ARR(ty),xt1);
nonxt = DAE.UNARY(DAE.UMINUS_ARR(ty),nonxt1);
then
(xt,nonxt);
case (e,(cr as DAE.CREF(componentRef = _)))
equation
res = expContains(e, cr);
Expand Down
7 changes: 6 additions & 1 deletion Compiler/Main.mo
Expand Up @@ -73,6 +73,7 @@ protected import InnerOuter;
protected import ClassLoader;
protected import TplMain;
protected import DAEDump;
protected import Inline;

protected function serverLoop
"function: serverLoop
Expand Down Expand Up @@ -756,6 +757,7 @@ algorithm
Env.Cache cache;
Env.Env env;
list<Integer> reseqn,tearvar;
DAE.FunctionTree funcs;
case (cache,env,p,ap,dae,daeimpl,classname)
local String str,strtearing;
equation
Expand All @@ -768,7 +770,10 @@ algorithm
Debug.fcall("bltdump", DAELow.dumpIncidenceMatrix, m);
Debug.fcall("bltdump", DAELow.dumpIncidenceMatrixT, mT);
Debug.fcall("execstat",print, "*** Main -> To run matching at time: " +& realString(clock()) +& "\n" );
(v1,v2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(), DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),DAEUtil.daeFunctionTree(dae));
funcs = DAEUtil.daeFunctionTree(dae);
(v1,v2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(), DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),funcs);
// late Inline
dlow_1 = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
Debug.fcall("bltdump", DAELow.dumpIncidenceMatrix, m);
Debug.fcall("bltdump", DAELow.dumpIncidenceMatrixT, mT);
Debug.fcall("bltdump", DAELow.dump, dlow_1);
Expand Down
43 changes: 32 additions & 11 deletions Compiler/SimCode.mo
Expand Up @@ -571,6 +571,7 @@ algorithm
Ceval.Msg msg;
Exp.Exp fileprefix;
Env.Cache cache;
DAE.FunctionTree funcs;
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),msg,fileprefix,addDummy)
equation
/* calculate stuff that we need to create SimCode data structure */
Expand All @@ -584,7 +585,10 @@ algorithm
Debug.fcall("bltdump", DAELow.dump, dlow);
m = DAELow.incidenceMatrix(dlow);
mT = DAELow.transposeMatrix(m);
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(),DAELow.REMOVE_SIMPLE_EQN()),DAEUtil.daeFunctionTree(dae));
funcs = DAEUtil.daeFunctionTree(dae);
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(),DAELow.REMOVE_SIMPLE_EQN()),funcs);
// late Inline
dlow_1 = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = DAELow.translateDae(dlow_1,NONE);
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
Expand Down Expand Up @@ -1151,15 +1155,10 @@ algorithm
list<tuple<Integer, DAE.Exp>> delayedExps;
list<DAE.Exp> divLst;
list<DAE.Statement> allDivStmts;
DAE.FunctionTree funcs;

case (dae,dlow,ass1,ass2,m,mt,comps,class_,fileDir,functions,libs)
equation
cname = Absyn.pathString(class_);

// late Inline
funcs = DAEUtil.daeFunctionTree(dae);
dlow = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow);
Debug.fcall("lateInline", DAELow.dump, dlow);

(blt_states, blt_no_states) = DAELow.generateStatePartition(comps, dlow, ass1, ass2, m, mt);

Expand Down Expand Up @@ -5243,16 +5242,38 @@ protected function solveTrivialArrayEquation
algorithm
(outE1,outE2) := matchcontinue(v,e1,e2)
local
Exp.Exp e12,e22,vTerm,res,rhs;
list<Exp.Exp> terms;
Exp.Exp e12,e22,vTerm,res,rhs,f;
list<Exp.Exp> terms,exps,exps_1,expl_1;
Exp.Type tp;

Boolean b;
list<Boolean> bls;
DAE.ComponentRef c;
case (v,DAE.ARRAY( tp, b,exps as ((DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef=c)) :: _))),e2)
equation
(f::exps_1) = Util.listMap(exps, Exp.expStripLastSubs); //Strip last subscripts
bls = Util.listMap1(exps_1, Exp.expEqual,f);
true = Util.boolAndList(bls);
c = Exp.crefStripLastSubs(c);
(e12,e22) = solveTrivialArrayEquation(v,DAE.CREF(c,tp),DAE.UNARY(DAE.UMINUS_ARR(tp),e2));
then
(e12,e22);
case (v,e2,DAE.ARRAY( tp, b,exps as ((DAE.UNARY(DAE.UMINUS(_),DAE.CREF(componentRef=c)) :: _))))
equation
(f::exps_1) = Util.listMap(exps, Exp.expStripLastSubs); //Strip last subscripts
bls = Util.listMap1(exps_1, Exp.expEqual,f);
true = Util.boolAndList(bls);
c = Exp.crefStripLastSubs(c);
(e12,e22) = solveTrivialArrayEquation(v,DAE.UNARY(DAE.UMINUS_ARR(tp),e2),DAE.CREF(c,tp));
then
(e12,e22);
// Solve simple linear equations.
case(v,e1,e2)
equation
tp = Exp.typeof(e1);
res = Exp.simplify(DAE.BINARY(e1,DAE.SUB_ARR(tp),e2));
(vTerm as DAE.CREF(_,_),rhs) = Exp.getTermsContainingX(res,DAE.CREF(v,DAE.ET_OTHER()));
(f,rhs) = Exp.getTermsContainingX(res,DAE.CREF(v,DAE.ET_OTHER()));
(vTerm as DAE.CREF(_,_)) = Exp.simplify(f);
rhs = Exp.simplify(rhs);
then (vTerm,rhs);

// not succeded to solve, return unsolved equation., catched later.
Expand Down

0 comments on commit 89eca8e

Please sign in to comment.