Skip to content

Commit c496614

Browse files
kabdelhakadrpo
authored andcommitted
[BE] fix computation of array record sizes
- ticket 4611
1 parent 8eee160 commit c496614

13 files changed

+256
-243
lines changed

OMCompiler/Compiler/BackEnd/BackendDAE.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ uniontype Equation
362362
.DAE.Exp right "rhs";
363363
.DAE.ElementSource source "origin of equation";
364364
EquationAttributes attr;
365+
Option<Integer> recordSize "NONE() if not a record";
365366
end ARRAY_EQUATION;
366367

367368
record SOLVED_EQUATION

OMCompiler/Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,11 @@ algorithm
701701
DAE.ElementSource src;
702702
DAE.Exp e1, e2;
703703
DAE.Dimensions dims;
704+
DAE.Type tp;
704705
BackendDAE.EquationAttributes attr;
705706
BackendDAE.Var var;
706707
list<BackendDAE.Equation> assert_eqs;
708+
Option<Integer> recordSize;
707709

708710
// external object variables
709711
case DAE.VAR(ty = DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ()))
@@ -719,11 +721,17 @@ algorithm
719721
outVars := lowerDynamicVar(inElement, inFunctions) :: outVars;
720722
e1 := Expression.crefExp(cr);
721723
attr := BackendDAE.EQ_ATTR_DEFAULT_BINDING;
722-
(_, dims) := ComponentReference.crefTypeFull2(cr);
724+
(tp, dims) := ComponentReference.crefTypeFull2(cr);
725+
tp := DAEUtil.expTypeElementType(tp);
726+
if DAEUtil.expTypeComplex(tp) then
727+
recordSize := SOME(Expression.sizeOf(tp));
728+
else
729+
recordSize := NONE();
730+
end if;
723731
if listEmpty(dims) then
724732
outEqns := BackendDAE.EQUATION(e1, e2, src, attr) :: outEqns;
725733
else
726-
outEqns := BackendDAE.ARRAY_EQUATION(Expression.dimensionsSizes(dims), e1, e2, src, attr) :: outEqns;
734+
outEqns := BackendDAE.ARRAY_EQUATION(Expression.dimensionsSizes(dims), e1, e2, src, attr, recordSize) :: outEqns;
727735
end if;
728736
then
729737
();
@@ -1840,40 +1848,26 @@ protected function lowerArrayEqn "author: Frenkel TUD 2012-06"
18401848
input BackendDAE.EquationAttributes inEqAttributes;
18411849
input list<BackendDAE.Equation> iAcc;
18421850
output list<BackendDAE.Equation> outEqsLst;
1843-
algorithm
1844-
outEqsLst := matchcontinue (dims, e1, e2, source, inEqAttributes, iAcc)
1845-
local
1846-
list<DAE.Exp> ea1, ea2;
1847-
list<Integer> ds;
1848-
DAE.Type tp;
1849-
Integer i;
1850-
1851-
// array type with record
1852-
case (_, _, _, _, _, _)
1853-
equation
1854-
tp = Expression.typeof(e1);
1855-
tp = DAEUtil.expTypeElementType(tp);
1856-
true = DAEUtil.expTypeComplex(tp);
1857-
i = Expression.sizeOf(tp);
1858-
ds = Expression.dimensionsSizes(dims);
1859-
ds = List.map1(ds, intMul, i);
1860-
//For COMPLEX_EQUATION
1861-
//i = List.fold(ds, intMul, 1);
1862-
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, inEqAttributes)::iAcc;
1863-
1864-
case (_, _, _, _, _, _)
1865-
equation
1866-
true = Expression.isArray(e1) or Expression.isMatrix(e1);
1867-
true = Expression.isArray(e2) or Expression.isMatrix(e2);
1868-
ea1 = Expression.flattenArrayExpToList(e1);
1869-
ea2 = Expression.flattenArrayExpToList(e2);
1870-
then generateEquations(ea1, ea2, source, inEqAttributes, iAcc);
1871-
1872-
case (_, _, _, _, _, _)
1873-
equation
1874-
ds = Expression.dimensionsSizes(dims);
1875-
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, inEqAttributes)::iAcc;
1876-
end matchcontinue;
1851+
protected
1852+
list<Integer> dimensions;
1853+
list<DAE.Exp> ea1,ea2;
1854+
DAE.Type tp;
1855+
Integer recordSize;
1856+
algorithm
1857+
tp := Expression.typeof(e1);
1858+
tp := DAEUtil.expTypeElementType(tp);
1859+
if DAEUtil.expTypeComplex(tp) then
1860+
recordSize := Expression.sizeOf(tp);
1861+
dimensions := Expression.dimensionsSizes(dims);
1862+
outEqsLst := BackendDAE.ARRAY_EQUATION(dimensions, e1, e2, source, inEqAttributes,SOME(recordSize))::iAcc;
1863+
elseif (Expression.isArray(e1) or Expression.isMatrix(e1)) and (Expression.isArray(e2) or Expression.isMatrix(e2)) then
1864+
ea1 := Expression.flattenArrayExpToList(e1);
1865+
ea2 := Expression.flattenArrayExpToList(e2);
1866+
outEqsLst := generateEquations(ea1, ea2, source, inEqAttributes, iAcc);
1867+
else
1868+
dimensions := Expression.dimensionsSizes(dims);
1869+
outEqsLst := BackendDAE.ARRAY_EQUATION(dimensions, e1, e2, source, inEqAttributes, NONE())::iAcc;
1870+
end if;
18771871
end lowerArrayEqn;
18781872

18791873
protected function generateEquations "author: Frenkel TUD 2012-06"

OMCompiler/Compiler/BackEnd/BackendDAETransform.mo

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ algorithm
568568
DAE.Exp iter, start, stop;
569569
DAE.ComponentRef cr, cr1;
570570
Integer size;
571+
Option<Integer> recordSize;
571572
list<DAE.Exp> expl;
572573
BackendDAE.Equation eqn;
573574
BackendDAE.WhenEquation elsepartRes;
@@ -591,11 +592,11 @@ algorithm
591592
then (BackendDAE.EQUATION(e1_1, e2_1, source, eqAttr), ext_arg_2);
592593

593594
// Array equation
594-
case BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left = e1, right = e2, source = source, attr=eqAttr) equation
595+
case BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left = e1, right = e2, source = source, attr=eqAttr, recordSize=recordSize) equation
595596
(e1_1, (ops, ext_arg_1)) = func(e1, ({}, inTypeA));
596597
(e2_1, (ops, ext_arg_2)) = func(e2, (ops, ext_arg_1));
597598
source = List.foldr(ops, ElementSource.addSymbolicTransformation, source);
598-
then (BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, eqAttr), ext_arg_2);
599+
then (BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, eqAttr, recordSize), ext_arg_2);
599600

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

0 commit comments

Comments
 (0)