Skip to content

Commit ecc780a

Browse files
author
Volker Waurich
committed
- calculate the max range of addressed indexes in a for-loop if the index is a computable expression
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21552 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 97b0c59 commit ecc780a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Compiler/BackEnd/BackendVariable.mo

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,7 +3633,7 @@ algorithm
36333633
local
36343634
DAE.Exp sub_exp;
36353635
list<DAE.Subscript> rest,res;
3636-
Boolean b,const;
3636+
Boolean b,const,calcRange;
36373637

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

36523652
case (DAE.INDEX(exp = sub_exp)::rest, _)
36533653
equation
3654+
(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
36543655
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
36553656
const = Expression.isConst(sub_exp);
36563657
res = Util.if_(const,DAE.INDEX(sub_exp)::rest,DAE.WHOLEDIM()::rest);
36573658
then
3658-
(res, b or not const);
3659-
3659+
(res, b or not const or calcRange);
36603660
case (DAE.WHOLE_NONEXP(exp = sub_exp)::rest, _)
36613661
equation
36623662
(res,b) = replaceVarWithWholeDimSubs(rest,iPerformed);
@@ -3667,6 +3667,26 @@ algorithm
36673667
end match;
36683668
end replaceVarWithWholeDimSubs;
36693669

3670+
protected function computeRangeExps"computes the maximal range expression for calculated ranges like [i1+i2]."
3671+
input DAE.Exp inExp;
3672+
output DAE.Exp outExp;
3673+
output Boolean isCalculated;
3674+
algorithm
3675+
(outExp,isCalculated) := matchcontinue(inExp)
3676+
local
3677+
Integer stop1,stop2;
3678+
DAE.Exp exp;
3679+
DAE.Type ty;
3680+
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))))
3681+
equation
3682+
stop2= stop1+stop2;
3683+
exp = DAE.RANGE(ty,DAE.ICONST(1),NONE(),DAE.ICONST(stop2));
3684+
then (exp,true);
3685+
else
3686+
then (inExp,false);
3687+
end matchcontinue;
3688+
end computeRangeExps;
3689+
36703690
public function getVarLst
36713691
input list<DAE.ComponentRef> inComponentRefLst;
36723692
input BackendDAE.Variables inVariables;

0 commit comments

Comments
 (0)