Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Replace ASUB/CREF subscripts in BackendVarTransform
- Do not perform empty backend variable replacements


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8874 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 8, 2011
1 parent 351d553 commit 034ee89
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -1178,7 +1178,7 @@ algorithm
values = va, comment = c, flowPrefix = fp, streamPrefix = sp), cache, env, _)
equation
((e2, _)) = Expression.traverseExp(e, replaceCrefsWithValues, vars);
(_, v, _) = Ceval.ceval(cache, env, e2, false,NONE(), NONE(), Ceval.MSG());
(_, v, _) = Ceval.ceval(cache, env, e2, false,NONE(), NONE(), Ceval.NO_MSG());
then
BackendDAE.VAR(cr, vk, vd, ty, SOME(e), SOME(v), dims, idx, src, va, c, fp, sp);
else inVar;
Expand Down
110 changes: 107 additions & 3 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -591,6 +591,7 @@ algorithm
case ((e as DAE.CREF(componentRef = cr,ty = t)),repl,cond)
equation
true = replaceExpCond(cond, e);
(cr,_) = replaceCrefSubs(cr,repl,cond);
e1 = getExtendReplacement(repl, cr);
((e2,(_,true))) = BackendDAEUtil.extendArrExp((e,(NONE(),false)));
(e3,_) = replaceExp(e2,repl,cond);
Expand All @@ -599,10 +600,16 @@ algorithm
case ((e as DAE.CREF(componentRef = cr,ty = t)),repl,cond)
equation
true = replaceExpCond(cond, e);
(cr,_) = replaceCrefSubs(cr,repl,cond);
e1 = getReplacement(repl, cr);
e2 = avoidDoubleHashLookup(e1,t);
then
(e2,true);
case ((e as DAE.CREF(componentRef = cr,ty = t)),repl,cond)
equation
true = replaceExpCond(cond, e);
(cr,true) = replaceCrefSubs(cr,repl,cond);
then (DAE.CREF(cr,t),true);
case ((e as DAE.BINARY(exp1 = e1,operator = op,exp2 = e2)),repl,cond)
equation
true = replaceExpCond(cond, e);
Expand Down Expand Up @@ -704,7 +711,8 @@ algorithm
case ((e as DAE.ASUB(exp = e1,sub = expl)),repl,cond)
equation
true = replaceExpCond(cond, e);
(e1_1,true) = replaceExp(e1, repl, cond);
(e1_1,c1) = replaceExp(e1, repl, cond);
(expl,true) = replaceExpList(expl, repl, cond, {}, c1);
then
(Expression.makeASUB(e1_1,expl),true);
case ((e as DAE.SIZE(exp = e1,sz = NONE())),repl,cond)
Expand Down Expand Up @@ -737,6 +745,91 @@ algorithm
end matchcontinue;
end replaceExp;

protected function replaceCrefSubs
input DAE.ComponentRef inCref;
input VariableReplacements repl;
input Option<FuncTypeExp_ExpToBoolean> cond;
output DAE.ComponentRef outCr;
output Boolean replacementPerformed;
partial function FuncTypeExp_ExpToBoolean
input DAE.Exp inExp;
output Boolean outBoolean;
end FuncTypeExp_ExpToBoolean;
algorithm
(outCr,replacementPerformed) := match (inCref,repl,cond)
local
String name;
DAE.ComponentRef cr,cr_1;
DAE.ExpType ty;
list<DAE.Subscript> subs,subs_1;
Boolean c1,c2;

case (inCref as DAE.CREF_QUAL(ident = name, identType = ty, subscriptLst = subs, componentRef = cr), repl, cond)
equation
(subs_1, c1) = replaceCrefSubs2(subs, repl, cond);
(cr_1, c2) = replaceCrefSubs(cr, repl, cond);
subs = Util.if_(c1,subs_1,subs);
cr = Util.if_(c2,cr_1,cr);
cr = Util.if_(c1 or c2,DAE.CREF_QUAL(name, ty, subs, cr),inCref);
then
(cr, c1 or c2);

case (inCref as DAE.CREF_IDENT(ident = name, identType = ty, subscriptLst = subs), repl, cond)
equation
(subs, c1) = replaceCrefSubs2(subs, repl, cond);
cr = Util.if_(c1,DAE.CREF_IDENT(name, ty, subs),inCref);
then
(cr, c1);

else (inCref,false);
end match;
end replaceCrefSubs;

protected function replaceCrefSubs2
input list<DAE.Subscript> subs;
input VariableReplacements repl;
input Option<FuncTypeExp_ExpToBoolean> cond;
output list<DAE.Subscript> outSubs;
output Boolean replacementPerformed;
partial function FuncTypeExp_ExpToBoolean
input DAE.Exp inExp;
output Boolean outBoolean;
end FuncTypeExp_ExpToBoolean;
algorithm
(outSubs,replacementPerformed) := match (subs,repl,cond)
local
DAE.Exp exp;
Boolean c1,c2;
case ({}, repl, cond) then ({},false);
case (DAE.WHOLEDIM()::subs, repl, cond)
equation
(subs,c1) = replaceCrefSubs2(subs,repl,cond);
then (DAE.WHOLEDIM()::subs, c1);

case (DAE.SLICE(exp = exp)::subs, repl, cond)
equation
(exp,c2) = replaceExp(exp, repl, cond);
(subs,c1) = replaceCrefSubs2(subs,repl,cond);
then
(DAE.SLICE(exp)::subs, c1 or c2);

case (DAE.INDEX(exp = exp)::subs, repl, cond)
equation
(exp,c2) = replaceExp(exp, repl, cond);
(subs,c1) = replaceCrefSubs2(subs,repl,cond);
then
(DAE.INDEX(exp)::subs, c1 or c2);

case (DAE.WHOLE_NONEXP(exp = exp)::subs, repl, cond)
equation
(exp,c2) = replaceExp(exp, repl, cond);
(subs,c1) = replaceCrefSubs2(subs,repl,cond);
then
(DAE.WHOLE_NONEXP(exp)::subs, c1 or c2);

end match;
end replaceCrefSubs2;

public function replaceExpList
input list<DAE.Exp> expl;
input VariableReplacements repl;
Expand Down Expand Up @@ -901,12 +994,23 @@ algorithm
end match;
end replaceExpMatrix2;


public function replaceEquations
"function: replaceEquations
This function takes a list of equations ana a set of variable
replacements and applies the replacements on all equations.
The function returns the updated list of equations"
input list<BackendDAE.Equation> inDAE;
input VariableReplacements repl;
output list<BackendDAE.Equation> outDAE;
protected
HashTable2.HashTable ht;
algorithm
REPLACEMENTS(hashTable = ht) := repl;
// Do not do empty replacements; it just takes time ;)
outDAE := Debug.bcallret2(BaseHashTable.hashTableCurrentSize(ht)>0,replaceEquations2,inDAE,repl,inDAE);
end replaceEquations;

protected function replaceEquations2
input list<BackendDAE.Equation> inBackendDAEEquationLst;
input VariableReplacements inVariableReplacements;
output list<BackendDAE.Equation> outBackendDAEEquationLst;
Expand Down Expand Up @@ -994,7 +1098,7 @@ algorithm
then
(a :: es_1);
end matchcontinue;
end replaceEquations;
end replaceEquations2;

protected function replaceWhenEquation "Replaces variables in a when equation"
input BackendDAE.WhenEquation whenEqn;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -11427,7 +11427,7 @@ algorithm
cr = ComponentReference.crefPrependIdent(prefixCr,n,{},ty2);
(cache,_,t,_,_,_,_,_,_) = Lookup.lookupVar(cache,env, cr);
sl = Types.getDimensionSizes(t);
(cache,ss_1) = Ceval.cevalSubscripts(cache,env, ss, sl, impl, Ceval.MSG());
(cache,ss_1) = Ceval.cevalSubscripts(cache,env, ss, sl, impl, Ceval.NO_MSG());
then
(cache,ComponentReference.makeCrefIdent(n,ty2,ss_1));
end matchcontinue;
Expand Down Expand Up @@ -11468,7 +11468,7 @@ algorithm
equation
(cache,_,t,_,_,_,_,_,_) = Lookup.lookupVar(cache, env, ComponentReference.makeCrefIdent(n,DAE.ET_OTHER(),{}));
sl = Types.getDimensionSizes(t);
(cache,ss_1) = Ceval.cevalSubscripts(cache, env, ss, sl, impl, Ceval.MSG());
(cache,ss_1) = Ceval.cevalSubscripts(cache, env, ss, sl, impl, Ceval.NO_MSG());
ty2 = Types.elabType(t);
then
(cache,ComponentReference.makeCrefIdent(n,ty2,ss_1));
Expand All @@ -11479,7 +11479,7 @@ algorithm
(cache,_,t,_,_,_,_,componentEnv,_) = Lookup.lookupVar(cache, env, ComponentReference.makeCrefIdent(n,DAE.ET_OTHER(),{}));
ty2 = Types.elabType(t);
sl = Types.getDimensionSizes(t);
(cache,ss_1) = Ceval.cevalSubscripts(cache, env, ss, sl, impl, Ceval.MSG());
(cache,ss_1) = Ceval.cevalSubscripts(cache, env, ss, sl, impl, Ceval.NO_MSG());
//(cache,c_1) = canonCref2(cache, env, c, ComponentReference.makeCrefIdent(n,ty2,ss), impl);
(cache, c_1) = canonCref(cache, componentEnv, c, impl);
then
Expand Down
28 changes: 24 additions & 4 deletions Compiler/Util/BaseHashTable.mo
Expand Up @@ -544,18 +544,38 @@ algorithm
end matchcontinue;
end valueArrayList2;

public function hashTableCurrentSize
"Returns the number of elements inserted into the table"
input HashTable hashTable;
output Integer sz;

replaceable type Key subtypeof Any;
replaceable type Value subtypeof Any;
type HashTable = tuple<HashVector, ValueArray, Integer, Integer, FuncsTuple>;
type HashVector = array<list<tuple<Key,Integer>>>;
type ValueArray = tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>;
type FuncsTuple = tuple<FuncHash,FuncEq,FuncKeyString,FuncValString>;
partial function FuncHash input Key key; input Integer mod; output Integer hash; end FuncHash;
partial function FuncEq input Key key1; input Key key2; output Boolean b; end FuncEq;
partial function FuncKeyString input Key key; output String str; end FuncKeyString;
partial function FuncValString input Value val; output String str; end FuncValString;
protected
ValueArray va;
algorithm
(_,va,_,_,_) := hashTable;
sz := valueArrayLength(va);
end hashTableCurrentSize;

public function valueArrayLength
"Returns the number of elements in the ValueArray"
input ValueArray valueArray;
output Integer size;
output Integer sz;

replaceable type Key subtypeof Any;
replaceable type Value subtypeof Any;
type ValueArray = tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>;
algorithm
size := match valueArray
case ((size,_,_)) then size;
end match;
(sz,_,_) := valueArray;
end valueArrayLength;

public function valueArrayAdd
Expand Down

0 comments on commit 034ee89

Please sign in to comment.