Skip to content

Commit

Permalink
- Fixed vectorization of crefs so that enumeration dimensions are pre…
Browse files Browse the repository at this point in the history
…served.

- Added test case mofiles/EnumDimSum.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6037 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 7, 2010
1 parent 05084f4 commit 9216698
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 48 deletions.
13 changes: 13 additions & 0 deletions Compiler/Exp.mo
Expand Up @@ -13445,5 +13445,18 @@ algorithm
end matchcontinue;
end arrayDimensionSetFirst;

public function isValidSubscript
"Checks if an expression is a valid subscript, i.e. an integer or enumeration
literal."
input DAE.Exp inSub;
output Boolean isValid;
algorithm
isValid := matchcontinue(inSub)
case DAE.ICONST(integer = _) then true;
case DAE.ENUM_LITERAL(index = _) then true;
case _ then false;
end matchcontinue;
end isValidSubscript;

end Exp;

90 changes: 70 additions & 20 deletions Compiler/Lookup.mo
Expand Up @@ -2517,7 +2517,7 @@ algorithm
equation
(cache,DAE.TYPES_VAR(name,DAE.ATTR(f,streamPrefix,acc,vt,di,io),_,ty,bind,cnstForRange),_,_,componentEnv) = lookupVar2(cache,ht, id);
ty_1 = checkSubscripts(ty, ss);
ss = addArrayDimensions(ty,ty_1,ss);
ss = addArrayDimensions(ty,ss);
tty = Types.elabType(ty);
ty2_2 = Types.elabType(ty);
splicedExp = DAE.CREF(DAE.CREF_IDENT(id,ty2_2, ss),tty);
Expand All @@ -2538,7 +2538,7 @@ algorithm
(tCref::ltCref) = elabComponentRecursive((texp));
ty1 = checkSubscripts(ty2, ss);
ty = sliceDimensionType(ty1,ty);
ss = addArrayDimensions(ty2,ty2,ss);
ss = addArrayDimensions(ty2,ss);
ty2_2 = Types.elabType(ty2);
xCref = DAE.CREF_QUAL(id,ty2_2,ss,tCref);
eType = Types.elabType(ty);
Expand Down Expand Up @@ -2582,32 +2582,82 @@ protected function addArrayDimensions " function addArrayDimensions
This is the function where we add arrays representing the dimension of the type.
In type {array 2[array 3 ]] Will generate 2 arrays. {1,2} and {1,2,3}"
input DAE.Type tySub;
input DAE.Type tyExpr;
input list<DAE.Subscript> ss;
output list<DAE.Subscript> outType;

algorithm
outType :=
matchcontinue (tySub, tyExpr,ss)
matchcontinue (tySub, ss)
local
DAE.Type ty1,ty2,ty3;
list<DAE.Subscript> subs1,subs2,subs3;
list<Integer> dim1,dim2;
Integer sslLength,expandLength;
case( ty2, ty3, subs1) // add ss
equation
true = Types.isArray(ty2);
dim2 = Types.getDimensionSizes(ty2);
sslLength = listLength(ss);
subs2 = makeExpIntegerArray(dim2);
subs2 = expandWholeDimSubScript(subs1,subs2);
then subs2;
case(_,_,subs1) // non array, return
equation
then (subs1);
list<DAE.Subscript> subs;
list<DAE.Dimension> dims;
case(_, _)
equation
true = Types.isArray(tySub);
dims = Types.getDimensions(tySub);
subs = Util.listMap(dims, makeDimensionSubscript);
subs = expandWholeDimSubScript(ss,subs);
then subs;
case(_,_) // non array, return
equation then ss;
end matchcontinue;
end addArrayDimensions;

protected function makeDimensionSubscript
"Creates a slice with all indices of the dimension."
input DAE.Dimension inDim;
output DAE.Subscript outSub;
algorithm
outSubs := matchcontinue(inDim)
local
Integer sz;
list<DAE.Exp> expl;
// Special case when addressing array[0].
case DAE.DIM_INTEGER(integer = 0)
then
DAE.SLICE(DAE.ARRAY(DAE.ET_INT, true, {DAE.ICONST(0)}));
// Array with integer dimension.
case DAE.DIM_INTEGER(integer = sz)
equation
expl = Util.listMap(Util.listIntRange(sz), Exp.makeIntegerExp);
then
DAE.SLICE(DAE.ARRAY(DAE.ET_INT, true, expl));
// Array with enumeration dimension.
case DAE.DIM_ENUM(enumTypeName = enum_name, literals = l, size = sz)
local
Absyn.Path enum_name;
list<String> l;
equation
expl = makeEnumLiteralIndices(enum_name, l, 1);
then
DAE.SLICE(DAE.ARRAY(DAE.ET_ENUMERATION(NONE, enum_name, l, {}), true, expl));
end matchcontinue;
end makeDimensionSubscript;

protected function makeEnumLiteralIndices
"Creates a list of enumeration literal expressions from an enumeration."
input Absyn.Path enumTypeName;
input list<String> enumLiterals;
input Integer enumIndex;
output list<DAE.Exp> enumIndices;
algorithm
enumIndices := matchcontinue(enumTypeName, enumLiterals, enumIndex)
case (_, {}, _) then {};
case (_, l :: ls, _)
local
String l;
list<String> ls;
DAE.Exp e;
list<DAE.Exp> expl;
Absyn.Path enum_type_name;
equation
enum_type_name = Absyn.joinPaths(enumTypeName, Absyn.IDENT(l));
e = DAE.ENUM_LITERAL(enum_type_name, enumIndex);
expl = makeEnumLiteralIndices(enumTypeName, ls, enumIndex + 1);
then
e :: expl;
end matchcontinue;
end makeEnumLiteralIndices;

protected function expandWholeDimSubScript " Function expandWholeDimSubScript
This function replaces Wholedim(if possible) with the expanded dimension.
If there exist a subscript, the subscript is used instead of the expanded dimension.
Expand Down
59 changes: 31 additions & 28 deletions Compiler/Static.mo
Expand Up @@ -10889,55 +10889,52 @@ public function crefVectorize
algorithm
outExp := matchcontinue (performVectorization,inExp,inType,splicedExp,crefIdType,applyLimits)
local
Boolean b1,b2,doVect;
DAE.ExpType elt_tp,exptp,t2;
DAE.Exp e,exp1,exp2;
DAE.ComponentRef cr,cr_2;
Integer ds,ds2;
list<DAE.Subscript> ssl;
tuple<DAE.TType, Option<Absyn.Path>> t;//,tOrg;
DAE.Type tOrg;
DAE.ExpType ety;
DAE.Type tttt;
list<DAE.ComponentRef> crefl1;
DAE.ComponentRef testCREF;
Boolean b1,b2;
DAE.ExpType exptp;
DAE.Exp e;
DAE.ComponentRef cr;
DAE.Type t;
DAE.Dimension d1, d2;

// no vectorization
case(false, e, _, _,_,_) then e;

// types extending basictype
case (doVect,e,(DAE.T_COMPLEX(_,_,SOME(t),_),_),_,crefIdType,applyLimits)
case (_,e,(DAE.T_COMPLEX(_,_,SOME(t),_),_),_,crefIdType,applyLimits)
equation
e = crefVectorize(doVect,e,t,NONE,crefIdType,applyLimits);
e = crefVectorize(true,e,t,NONE,crefIdType,applyLimits);
then e;

// component reference and an array type with dimensions less than vectorization limit
case (_,DAE.CREF(componentRef = cr_2,ty = t2),
(tOrg as (DAE.T_ARRAY(arrayDim = DAE.DIM_INTEGER(integer = ds),arrayType =
(t as (DAE.T_ARRAY(arrayDim = DAE.DIM_INTEGER(integer = ds2)),_))),_)),
SOME(exp1 as DAE.CREF(componentRef = cr,ty = exptp)),crefIdType,applyLimits)
case (_, _, (DAE.T_ARRAY(arrayDim = d1, arrayType = (DAE.T_ARRAY(arrayDim = d2), _)), _),
SOME(DAE.CREF(componentRef = cr)), crefIdType, applyLimits)
equation
b1 = (ds < RTOpts.vectorizationLimit());
b2 = (ds2 < RTOpts.vectorizationLimit());
b1 = (Exp.dimensionSize(d1) < RTOpts.vectorizationLimit());
b2 = (Exp.dimensionSize(d2) < RTOpts.vectorizationLimit());
true = boolAnd(b1, b2) or not applyLimits;
e = elabCrefSlice(cr,crefIdType);
e = tryToConvertArrayToMatrix(e);
then
e;

case(_, exp2 as (DAE.CREF(componentRef = cr_2,ty = t2)),
(tOrg as (DAE.T_ARRAY(arrayDim = DAE.DIM_INTEGER(integer = ds),arrayType = t),_)),
SOME(exp1 as DAE.CREF(componentRef = cr,ty = exptp)),crefIdType,applyLimits)
case (_, _, (DAE.T_ARRAY(arrayDim = d1, arrayType = t), _),
SOME(DAE.CREF(componentRef = cr)), crefIdType, applyLimits)
equation
false = Types.isArray(t);
true = (ds < RTOpts.vectorizationLimit()) or not applyLimits;
true = (Exp.dimensionSize(d1) < RTOpts.vectorizationLimit()) or not applyLimits;
e = elabCrefSlice(cr,crefIdType);
then
e;

/* matrix sizes > vectorization limit is not vectorized */
case (_,DAE.CREF(componentRef = cr,ty = exptp),(DAE.T_ARRAY(arrayDim = DAE.DIM_INTEGER(integer = ds),arrayType = (t as (DAE.T_ARRAY(arrayDim = DAE.DIM_INTEGER(integer = ds2)),_))),_),_,crefIdType,applyLimits)
case (_, DAE.CREF(componentRef = cr, ty = exptp),
(DAE.T_ARRAY(arrayDim = d1, arrayType = t as (DAE.T_ARRAY(arrayDim = d2), _)), _),
_, crefIdType, applyLimits)
local
Integer ds, ds2;
equation
ds = Exp.dimensionSize(d1);
ds2 = Exp.dimensionSize(d2);
b1 = (ds < RTOpts.vectorizationLimit());
b2 = (ds2 < RTOpts.vectorizationLimit());
true = boolAnd(b1, b2) or not applyLimits;
Expand All @@ -10946,9 +10943,13 @@ algorithm
e;

/* vectorsizes > vectorization limit is not vectorized */
case (_,DAE.CREF(componentRef = cr,ty = exptp),(DAE.T_ARRAY(arrayDim = DAE.DIM_INTEGER(integer = ds),arrayType = t),_),_,crefIdType,applyLimits)
case (_,DAE.CREF(componentRef = cr,ty = exptp),
(DAE.T_ARRAY(arrayDim = d1,arrayType = t),_),_,crefIdType,applyLimits)
local
Integer ds;
equation
false = Types.isArray(t);
ds = Exp.dimensionSize(d1);
true = (ds < RTOpts.vectorizationLimit()) or not applyLimits;
e = createCrefArray(cr, 1, ds, exptp, t,crefIdType);
then
Expand Down Expand Up @@ -11293,14 +11294,16 @@ algorithm
exp1 = DAE.ARRAY(DAE.ET_ARRAY( ety,{DAE.DIM_INTEGER(0)}),true,{});
then exp1;

case(exp1 as DAE.ICONST(integer=_),DAE.ARRAY(_,_,{}),id ,ety)
case(exp1,DAE.ARRAY(_,_,{}),id ,ety)
equation
true = Exp.isValidSubscript(exp1);
crty = Exp.unliftArray(ety) "only subscripting one dimension, unlifting once ";
exp1 = DAE.CREF(DAE.CREF_IDENT(id,ety,{DAE.INDEX(exp1)}),crty);
then exp1;

case(exp1 as DAE.ICONST(integer=_), (exp2), id ,ety)
case(exp1, exp2, id ,ety)
equation
true = Exp.isValidSubscript(exp1);
exp1 = applySubscript2(exp1, exp2,ety);
then exp1;
end matchcontinue;
Expand Down

0 comments on commit 9216698

Please sign in to comment.