Skip to content

Commit

Permalink
- calculate the max range of addressed indexes in a for-loop if the i…
Browse files Browse the repository at this point in the history
…ndex is a computable expression

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21552 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Jul 17, 2014
1 parent 97b0c59 commit ecc780a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -3633,7 +3633,7 @@ algorithm
local
DAE.Exp sub_exp;
list<DAE.Subscript> rest,res;
Boolean b,const;
Boolean b,const,calcRange;

case ({}, _) then (inSubscript,iPerformed);
case (DAE.WHOLEDIM()::rest, _)
Expand All @@ -3651,12 +3651,12 @@ algorithm

case (DAE.INDEX(exp = sub_exp)::rest, _)
equation
(sub_exp,calcRange) = computeRangeExps(sub_exp); // the fact that if it can be calculated, we can take the wholedim is a bit weird, anyway, the whole function is weird
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
const = Expression.isConst(sub_exp);
res = Util.if_(const,DAE.INDEX(sub_exp)::rest,DAE.WHOLEDIM()::rest);
then
(res, b or not const);

(res, b or not const or calcRange);
case (DAE.WHOLE_NONEXP(exp = sub_exp)::rest, _)
equation
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
Expand All @@ -3667,6 +3667,26 @@ algorithm
end match;
end replaceVarWithWholeDimSubs;

protected function computeRangeExps"computes the maximal range expression for calculated ranges like [i1+i2]."
input DAE.Exp inExp;
output DAE.Exp outExp;
output Boolean isCalculated;
algorithm
(outExp,isCalculated) := matchcontinue(inExp)
local
Integer stop1,stop2;
DAE.Exp exp;
DAE.Type ty;
case(DAE.BINARY(exp1=DAE.RANGE(ty=ty,start=DAE.ICONST(integer=1),stop=DAE.ICONST(integer=stop1)), operator=DAE.ADD(ty=_), exp2=DAE.RANGE(start=DAE.ICONST(integer=1),stop=DAE.ICONST(integer=stop2))))
equation
stop2= stop1+stop2;
exp = DAE.RANGE(ty,DAE.ICONST(1),NONE(),DAE.ICONST(stop2));
then (exp,true);
else
then (inExp,false);
end matchcontinue;
end computeRangeExps;

public function getVarLst
input list<DAE.ComponentRef> inComponentRefLst;
input BackendDAE.Variables inVariables;
Expand Down

0 comments on commit ecc780a

Please sign in to comment.