Skip to content

Commit

Permalink
- update array only if element is updated
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8896 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed May 9, 2011
1 parent 9d7562d commit 1f9a798
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
23 changes: 20 additions & 3 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5481,20 +5481,37 @@ algorithm
(outArray,outTypeB) := matchcontinue(inArray,func,arrayfunc,pos,len,inTypeB)
local
array<Type_a> array;
Type_a new_a;
Type_a a,new_a;
Type_b ext_arg_1,ext_arg_2;
case(array,_,_,pos,len,inTypeB) equation
true = pos > len;
then (array,inTypeB);

case(array,func,arrayfunc,pos,len,inTypeB) equation
(new_a,ext_arg_1) = arrayfunc(array[pos],func,inTypeB);
array = arrayUpdate(array,pos,new_a);
a = array[pos];
(new_a,ext_arg_1) = arrayfunc(a,func,inTypeB);
array = arrayUpdateCond(referenceEq(a,new_a),array,pos,new_a);
(array,ext_arg_2) = traverseBackendDAEArrayNoCopyWithUpdate(array,func,arrayfunc,pos+1,len,ext_arg_1);
then (array,ext_arg_2);
end matchcontinue;
end traverseBackendDAEArrayNoCopyWithUpdate;

protected function arrayUpdateCond
input Boolean b;
input array<Type_a> inArray;
input Integer pos;
input Type_a a;
output array<Type_a> outArray;
replaceable type Type_a subtypeof Any;
algorithm
outArray := match(b,inArray,pos,a)
case(true,inArray,_,_) // equation print("equal\n");
then inArray;
case(false,inArray,pos,a) // equation print("not equal\n");
then arrayUpdate(inArray,pos,a);
end match;
end arrayUpdateCond;

protected function traverseBackendDAEExpsVar "function: traverseBackendDAEExpsVar
author: Frenkel TUD
Helper traverseBackendDAEExpsVar. Get all exps from a Var.
Expand Down
24 changes: 15 additions & 9 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -778,14 +778,16 @@ protected function traverseBackendDAEOptEqnWithUpdate "function: traverseBackend
algorithm
(outEquation,outTypeA):= matchcontinue (inEquation,func,inTypeA)
local
Option<BackendDAE.Equation> oeqn;
BackendDAE.Equation eqn,eqn1;
Type_a ext_arg;
case (NONE(),func,inTypeA) then (NONE(),inTypeA);
case (SOME(eqn),func,inTypeA)
case (oeqn as NONE(),func,inTypeA) then (oeqn,inTypeA);
case (oeqn as SOME(eqn),func,inTypeA)
equation
((eqn1,ext_arg)) = func((eqn,inTypeA));
oeqn = Util.if_(referenceEq(eqn,eqn1),oeqn,SOME(eqn1));
then
(SOME(eqn1),ext_arg);
(oeqn,ext_arg);
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendEquation.traverseBackendDAEOptEqnWithUpdate failed");
Expand Down Expand Up @@ -813,16 +815,18 @@ algorithm
(outMultiDimEquation,outTypeA):=
match (inMultiDimEquation,func,inTypeA)
local
BackendDAE.MultiDimEquation meqn;
DAE.Exp e1,e2,e1_1,e2_1;
list<Integer> dims;
DAE.ElementSource source;
Type_a ext_arg_1,ext_arg_2;
case (BackendDAE.MULTIDIM_EQUATION(dims,e1,e2,source),func,inTypeA)
case (meqn as BackendDAE.MULTIDIM_EQUATION(dims,e1,e2,source),func,inTypeA)
equation
((e1_1,ext_arg_1)) = func((e1,inTypeA));
((e2_1,ext_arg_2)) = func((e2,ext_arg_1));
meqn = Util.if_(referenceEq(e1,e1_1) and referenceEq(e2,e2_1),meqn,BackendDAE.MULTIDIM_EQUATION(dims,e1_1,e2_1,source));
then
(BackendDAE.MULTIDIM_EQUATION(dims,e1_1,e2_1,source),ext_arg_2);
(meqn,ext_arg_2);
end match;
end traverseBackendDAEExpsArrayEqnWithUpdate;

Expand All @@ -845,13 +849,15 @@ algorithm
(outAlg,outTypeA):=
match (inAlg,func,inTypeA)
local
list<DAE.Statement> stmts;
DAE.Algorithm alg;
list<DAE.Statement> stmts,stmts1;
Type_a ext_arg_1;
case (DAE.ALGORITHM_STMTS(stmts),func,inTypeA)
case (alg as DAE.ALGORITHM_STMTS(stmts),func,inTypeA)
equation
(stmts,ext_arg_1) = DAEUtil.traverseDAEEquationsStmts(stmts,func,inTypeA);
(stmts1,ext_arg_1) = DAEUtil.traverseDAEEquationsStmts(stmts,func,inTypeA);
alg = Util.if_(referenceEq(stmts,stmts1),alg,DAE.ALGORITHM_STMTS(stmts));
then
(DAE.ALGORITHM_STMTS(stmts),ext_arg_1);
(alg,ext_arg_1);
end match;
end traverseBackendDAEExpsAlgortihmWithUpdate;

Expand Down
8 changes: 5 additions & 3 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -3578,14 +3578,16 @@ algorithm
(outVar,outTypeA):=
matchcontinue (inVar,func,inTypeA)
local
Option<BackendDAE.Var> ovar;
BackendDAE.Var v,v1;
Type_a ext_arg;
case (NONE(),func,inTypeA) then (NONE(),inTypeA);
case (SOME(v),func,inTypeA)
case (ovar as NONE(),func,inTypeA) then (ovar,inTypeA);
case (ovar as SOME(v),func,inTypeA)
equation
((v1,ext_arg)) = func((v,inTypeA));
ovar = Util.if_(referenceEq(v,v1),ovar,SOME(v1));
then
(SOME(v1),ext_arg);
(ovar,ext_arg);
case (_,_,_)
equation
Debug.fprintln("failtrace", "- BackendVariable.traverseBackendDAEVar failed");
Expand Down

0 comments on commit 1f9a798

Please sign in to comment.