Skip to content

Commit

Permalink
[BE] fix computation of array record sizes
Browse files Browse the repository at this point in the history
  - ticket 4611
  • Loading branch information
kabdelhak authored and adrpo committed Jul 10, 2019
1 parent 8eee160 commit c496614
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 243 deletions.
1 change: 1 addition & 0 deletions OMCompiler/Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -362,6 +362,7 @@ uniontype Equation
.DAE.Exp right "rhs";
.DAE.ElementSource source "origin of equation";
EquationAttributes attr;
Option<Integer> recordSize "NONE() if not a record";
end ARRAY_EQUATION;

record SOLVED_EQUATION
Expand Down
66 changes: 30 additions & 36 deletions OMCompiler/Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -701,9 +701,11 @@ algorithm
DAE.ElementSource src;
DAE.Exp e1, e2;
DAE.Dimensions dims;
DAE.Type tp;
BackendDAE.EquationAttributes attr;
BackendDAE.Var var;
list<BackendDAE.Equation> assert_eqs;
Option<Integer> recordSize;

// external object variables
case DAE.VAR(ty = DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ()))
Expand All @@ -719,11 +721,17 @@ algorithm
outVars := lowerDynamicVar(inElement, inFunctions) :: outVars;
e1 := Expression.crefExp(cr);
attr := BackendDAE.EQ_ATTR_DEFAULT_BINDING;
(_, dims) := ComponentReference.crefTypeFull2(cr);
(tp, dims) := ComponentReference.crefTypeFull2(cr);
tp := DAEUtil.expTypeElementType(tp);
if DAEUtil.expTypeComplex(tp) then
recordSize := SOME(Expression.sizeOf(tp));
else
recordSize := NONE();
end if;
if listEmpty(dims) then
outEqns := BackendDAE.EQUATION(e1, e2, src, attr) :: outEqns;
else
outEqns := BackendDAE.ARRAY_EQUATION(Expression.dimensionsSizes(dims), e1, e2, src, attr) :: outEqns;
outEqns := BackendDAE.ARRAY_EQUATION(Expression.dimensionsSizes(dims), e1, e2, src, attr, recordSize) :: outEqns;
end if;
then
();
Expand Down Expand Up @@ -1840,40 +1848,26 @@ protected function lowerArrayEqn "author: Frenkel TUD 2012-06"
input BackendDAE.EquationAttributes inEqAttributes;
input list<BackendDAE.Equation> iAcc;
output list<BackendDAE.Equation> outEqsLst;
algorithm
outEqsLst := matchcontinue (dims, e1, e2, source, inEqAttributes, iAcc)
local
list<DAE.Exp> ea1, ea2;
list<Integer> ds;
DAE.Type tp;
Integer i;

// array type with record
case (_, _, _, _, _, _)
equation
tp = Expression.typeof(e1);
tp = DAEUtil.expTypeElementType(tp);
true = DAEUtil.expTypeComplex(tp);
i = Expression.sizeOf(tp);
ds = Expression.dimensionsSizes(dims);
ds = List.map1(ds, intMul, i);
//For COMPLEX_EQUATION
//i = List.fold(ds, intMul, 1);
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, inEqAttributes)::iAcc;

case (_, _, _, _, _, _)
equation
true = Expression.isArray(e1) or Expression.isMatrix(e1);
true = Expression.isArray(e2) or Expression.isMatrix(e2);
ea1 = Expression.flattenArrayExpToList(e1);
ea2 = Expression.flattenArrayExpToList(e2);
then generateEquations(ea1, ea2, source, inEqAttributes, iAcc);

case (_, _, _, _, _, _)
equation
ds = Expression.dimensionsSizes(dims);
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, inEqAttributes)::iAcc;
end matchcontinue;
protected
list<Integer> dimensions;
list<DAE.Exp> ea1,ea2;
DAE.Type tp;
Integer recordSize;
algorithm
tp := Expression.typeof(e1);
tp := DAEUtil.expTypeElementType(tp);
if DAEUtil.expTypeComplex(tp) then
recordSize := Expression.sizeOf(tp);
dimensions := Expression.dimensionsSizes(dims);
outEqsLst := BackendDAE.ARRAY_EQUATION(dimensions, e1, e2, source, inEqAttributes,SOME(recordSize))::iAcc;
elseif (Expression.isArray(e1) or Expression.isMatrix(e1)) and (Expression.isArray(e2) or Expression.isMatrix(e2)) then
ea1 := Expression.flattenArrayExpToList(e1);
ea2 := Expression.flattenArrayExpToList(e2);
outEqsLst := generateEquations(ea1, ea2, source, inEqAttributes, iAcc);
else
dimensions := Expression.dimensionsSizes(dims);
outEqsLst := BackendDAE.ARRAY_EQUATION(dimensions, e1, e2, source, inEqAttributes, NONE())::iAcc;
end if;
end lowerArrayEqn;

protected function generateEquations "author: Frenkel TUD 2012-06"
Expand Down
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -568,6 +568,7 @@ algorithm
DAE.Exp iter, start, stop;
DAE.ComponentRef cr, cr1;
Integer size;
Option<Integer> recordSize;
list<DAE.Exp> expl;
BackendDAE.Equation eqn;
BackendDAE.WhenEquation elsepartRes;
Expand All @@ -591,11 +592,11 @@ algorithm
then (BackendDAE.EQUATION(e1_1, e2_1, source, eqAttr), ext_arg_2);

// Array equation
case BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left = e1, right = e2, source = source, attr=eqAttr) equation
case BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left = e1, right = e2, source = source, attr=eqAttr, recordSize=recordSize) equation
(e1_1, (ops, ext_arg_1)) = func(e1, ({}, inTypeA));
(e2_1, (ops, ext_arg_2)) = func(e2, (ops, ext_arg_1));
source = List.foldr(ops, ElementSource.addSymbolicTransformation, source);
then (BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, eqAttr), ext_arg_2);
then (BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, eqAttr, recordSize), ext_arg_2);

case BackendDAE.FOR_EQUATION(iter = iter, start = start, stop = stop, body = eqn, source = source, attr = eqAttr) equation
(eqn, outTypeA) = traverseBackendDAEExpsEqnWithSymbolicOperation(eqn, func, inTypeA);
Expand Down

0 comments on commit c496614

Please sign in to comment.