Skip to content

Commit

Permalink
- clean up vectorization for trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and OpenModelica-Hudson committed Oct 1, 2015
1 parent 21d79d8 commit 18a82cf
Show file tree
Hide file tree
Showing 12 changed files with 603 additions and 1,842 deletions.
33 changes: 4 additions & 29 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -289,38 +289,13 @@ public uniontype EquationAttributes
record EQUATION_ATTRIBUTES
Boolean differentiated "true if the equation was differentiated, and should not differentiated again to avoid equal equations";
EquationKind kind;
LoopInfo loopInfo;
end EQUATION_ATTRIBUTES;
end EquationAttributes;

public constant EquationAttributes EQ_ATTR_DEFAULT_DYNAMIC = EQUATION_ATTRIBUTES(false, DYNAMIC_EQUATION(), NO_LOOP());
public constant EquationAttributes EQ_ATTR_DEFAULT_BINDING = EQUATION_ATTRIBUTES(false, BINDING_EQUATION(), NO_LOOP());
public constant EquationAttributes EQ_ATTR_DEFAULT_INITIAL = EQUATION_ATTRIBUTES(false, INITIAL_EQUATION(), NO_LOOP());
public constant EquationAttributes EQ_ATTR_DEFAULT_UNKNOWN = EQUATION_ATTRIBUTES(false, UNKNOWN_EQUATION_KIND(), NO_LOOP());

public uniontype LoopInfo "is this equation part of a for-loop"
record NO_LOOP
end NO_LOOP;

record LOOP
Integer loopId;
//Integer pos; // position in the loop, 1=start, endIt=last, needed to get the matching afterwards
.DAE.Exp startIt;
.DAE.Exp endIt;
list<IterCref> crefs;
end LOOP;
end LoopInfo;

public uniontype IterCref "which crefs occur in the for-loop and what are their iterated indexes"
record ITER_CREF
.DAE.ComponentRef cref;
.DAE.Exp iterator;
end ITER_CREF;
record ACCUM_ITER_CREF
.DAE.ComponentRef cref;
.DAE.Operator op; // the operator e.g. add
end ACCUM_ITER_CREF;
end IterCref;
public constant EquationAttributes EQ_ATTR_DEFAULT_DYNAMIC = EQUATION_ATTRIBUTES(false, DYNAMIC_EQUATION());
public constant EquationAttributes EQ_ATTR_DEFAULT_BINDING = EQUATION_ATTRIBUTES(false, BINDING_EQUATION());
public constant EquationAttributes EQ_ATTR_DEFAULT_INITIAL = EQUATION_ATTRIBUTES(false, INITIAL_EQUATION());
public constant EquationAttributes EQ_ATTR_DEFAULT_UNKNOWN = EQUATION_ATTRIBUTES(false, UNKNOWN_EQUATION_KIND());

public
uniontype Equation
Expand Down
19 changes: 10 additions & 9 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -123,7 +123,8 @@ algorithm
extVars := BackendVariable.listVar(extvarlst);
aliasVars := BackendVariable.emptyVars();
if Flags.isSet(Flags.VECTORIZE) then
(vars,eqns) := Vectorization.buildForLoops(vars,eqns);
(varlst,eqns) := Vectorization.collectForLoops(varlst,eqns);
vars := BackendVariable.listVar(varlst);
end if;
// handle alias equations
(vars, knvars, extVars, aliasVars, eqns, reqns, ieqns) := handleAliasEquations(aliaseqns, vars, knvars, extVars, aliasVars, eqns, reqns, ieqns);
Expand Down Expand Up @@ -543,7 +544,7 @@ algorithm
outVars := lowerDynamicVar(inElement, inFunctions) :: outVars;
(e2, src) := Inline.inlineExp(e2, (SOME(inFunctions), {DAE.NORM_INLINE()}), src);
e1 := Expression.crefExp(cr);
attr := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.BINDING_EQUATION(), BackendDAE.NO_LOOP());
attr := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.BINDING_EQUATION());
outEqns := BackendDAE.EQUATION(e1, e2, src, attr) :: outEqns;
then
();
Expand Down Expand Up @@ -1560,7 +1561,7 @@ algorithm
true = DAEUtil.expTypeComplex(tp);
size = Expression.sizeOf(tp);
then
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))::inEqns;
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::inEqns;

// array types to array equations
case (_, _, _, _, _, _)
Expand All @@ -1578,7 +1579,7 @@ algorithm
true = Types.isTuple(tp);
size = Expression.sizeOf(tp);
then
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))::inEqns;
BackendDAE.COMPLEX_EQUATION(size, inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::inEqns;

// other types
case (_, _, _, _, _, _)
Expand All @@ -1590,7 +1591,7 @@ algorithm
false = b1 or b2 or b3;
//Error.assertionOrAddSourceMessage(not b1, Error.INTERNAL_ERROR, {str}, Absyn.dummyInfo);
then
BackendDAE.EQUATION(inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))::inEqns;
BackendDAE.EQUATION(inExp1, inExp2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::inEqns;
else
equation
// show only on failtrace!
Expand Down Expand Up @@ -1636,12 +1637,12 @@ algorithm
ds = List.map1(ds, intMul, i);
//For COMPLEX_EQUATION
//i = List.fold(ds, intMul, 1);
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))::iAcc;
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::iAcc;

case (_, _, _, _, _, _)
equation
ds = Expression.dimensionsSizes(dims);
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))::iAcc;
then BackendDAE.ARRAY_EQUATION(ds, e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::iAcc;
end matchcontinue;
end lowerArrayEqn;

Expand All @@ -1659,7 +1660,7 @@ algorithm
list<DAE.Exp> e1lst, e2lst;
case ({}, {}, _, _, _) then iAcc;
case (e1::e1lst, e2::e2lst, _, _, _)
then generateEquations(e1lst, e2lst, source, inEqKind, BackendDAE.EQUATION(e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))::iAcc);
then generateEquations(e1lst, e2lst, source, inEqKind, BackendDAE.EQUATION(e1, e2, source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))::iAcc);
end match;
end generateEquations;

Expand Down Expand Up @@ -1689,7 +1690,7 @@ algorithm
outEqs := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
scalar = e, source = DAE.emptyElementSource,
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: inEqs;
outEqAttrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt), BackendDAE.NO_LOOP());
outEqAttrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt));
end createWhenClock;


Expand Down
54 changes: 1 addition & 53 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -1451,8 +1451,7 @@ algorithm
equation
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
s3 = printEqAtts(attr);
res = stringAppendList({s1," = ",s2," ",s3});
res = stringAppendList({s1," = ",s2});
then
res;
case (BackendDAE.COMPLEX_EQUATION(left = e1,right = e2))
Expand Down Expand Up @@ -3591,56 +3590,5 @@ algorithm
end matchcontinue;
end printCompInfo;

protected function printEqAtts
input BackendDAE.EquationAttributes atts;
output String s;
protected
BackendDAE.LoopInfo li;
algorithm
BackendDAE.EQUATION_ATTRIBUTES(loopInfo=li) := atts;
s := printLoopInfoStr(li);
end printEqAtts;

public function printLoopInfoStr"outputs a string representation of a loopInfo"
input BackendDAE.LoopInfo loopInfoIn;
output String s;
algorithm
s := match(loopInfoIn)
local
String s1,s2,s3;
String loopId;
Integer id;
DAE.Exp startIt;
DAE.Exp endIt;
list<BackendDAE.IterCref> crefs;
case(BackendDAE.LOOP(loopId=id, startIt=startIt, endIt=endIt, crefs=crefs))
equation
s1 = "LOOP"+intString(id)+":";
s2 = "[ "+ExpressionDump.printExpStr(startIt)+"->"+ExpressionDump.printExpStr(endIt)+" ] ";
s3 = stringDelimitList(List.map(crefs,printIterCrefStr),"| ");
then s1+s2+s3;
case(_)
then "";
end match;
end printLoopInfoStr;

public function printIterCrefStr"outputs a string representation of a IterCref"
input BackendDAE.IterCref itCref;
output String s;
algorithm
s := match(itCref)
local
DAE.ComponentRef cref;
DAE.Exp it;
DAE.Operator op;
case(BackendDAE.ITER_CREF(cref=cref, iterator=it))
equation
then "{"+ComponentReference.printComponentRefStr(cref)+" :iter["+ExpressionDump.printExpStr(it)+"]}";
case(BackendDAE.ACCUM_ITER_CREF(cref=cref, op=op))
equation
then "ACCUM{"+ComponentReference.printComponentRefStr(cref)+" :op["+DAEDump.dumpOperatorString(op)+"]}";
end match;
end printIterCrefStr;

annotation(__OpenModelica_Interface="backend");
end BackendDump;
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -2170,7 +2170,7 @@ public function generateEQUATION "author: Frenkel TUD 2010-05"
input BackendDAE.EquationKind inEqKind;
output BackendDAE.Equation outEqn;
algorithm
outEqn := BackendDAE.EQUATION(iLhs, iRhs, Source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()));
outEqn := BackendDAE.EQUATION(iLhs, iRhs, Source, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind));
end generateEQUATION;

public function getEquationAttributes
Expand Down Expand Up @@ -2335,7 +2335,7 @@ algorithm
DAE.Exp rhs;

case (_, SOME(rhs), _, _)
then {BackendDAE.SOLVED_EQUATION(inLhs, rhs, inSource, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind, BackendDAE.NO_LOOP()))};
then {BackendDAE.SOLVED_EQUATION(inLhs, rhs, inSource, BackendDAE.EQUATION_ATTRIBUTES(false, inEqKind))};

else {};
end match;
Expand Down
77 changes: 0 additions & 77 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -1753,7 +1753,6 @@ algorithm
true = b1 or b2;
source = DAEUtil.addSymbolicTransformationSubstitution(b1,source,e1,e1_1);
source = DAEUtil.addSymbolicTransformationSubstitution(b2,source,e2,e2_1);
eqAttr = replaceEquationAttributes(eqAttr,repl);
(DAE.EQUALITY_EXPS(e1_2,e2_2),source) = ExpressionSimplify.simplifyAddSymbolicOperation(DAE.EQUALITY_EXPS(e1_1,e2_1),source);
then
(BackendDAE.EQUATION(e1_2,e2_2,source,eqAttr)::inAcc,true);
Expand All @@ -1772,7 +1771,6 @@ algorithm
(e_1,true) = replaceExp(e, repl,inFuncTypeExpExpToBooleanOption);
(e_2,_) = ExpressionSimplify.simplify(e_1);
source = DAEUtil.addSymbolicTransformationSubstitution(true,source,e,e_2);
eqAttr = replaceEquationAttributes(eqAttr,repl);
then
(BackendDAE.SOLVED_EQUATION(cr,e_2,source,eqAttr)::inAcc,true);

Expand Down Expand Up @@ -2722,81 +2720,6 @@ algorithm
end match;
end replaceVariableAttributesInVar;

protected function replaceEquationAttributes"replaces iterCrefs in the LoopInfo.
author:Waurich TUD 05-2015"
input BackendDAE.EquationAttributes eqAttrIn;
input VariableReplacements repl;
output BackendDAE.EquationAttributes eqAttrOut;
algorithm
eqAttrOut := matchcontinue(eqAttrIn,repl)
local
Boolean differentiated;
BackendDAE.EquationKind kind;
Integer id;
BackendDAE.LoopInfo loopInfo;
DAE.Exp startIt, endIt;
list<BackendDAE.IterCref> crefs;
case(BackendDAE.EQUATION_ATTRIBUTES(differentiated=differentiated, kind=kind, loopInfo=BackendDAE.LOOP(loopId=id,startIt=startIt,endIt=endIt,crefs=crefs)),_)
equation
crefs = replaceIterationCrefs(crefs,repl,{});
if listEmpty(crefs) then loopInfo = BackendDAE.NO_LOOP();
else loopInfo = BackendDAE.LOOP(id,startIt,endIt,crefs);
end if;
then BackendDAE.EQUATION_ATTRIBUTES(differentiated, kind, loopInfo);
else
then eqAttrIn;
end matchcontinue;
end replaceEquationAttributes;

protected function replaceIterationCrefs"replaces iterated crefs in the equation attributes"
input list<BackendDAE.IterCref> iterCrefsIn;
input VariableReplacements repl;
input list<BackendDAE.IterCref> foldIn;
output list<BackendDAE.IterCref> iterCrefsOut;
algorithm
(iterCrefsOut) := matchcontinue(iterCrefsIn,repl,foldIn)
local
BackendDAE.IterCref itCref;
list<BackendDAE.IterCref> rest,itCrefLst;
DAE.ComponentRef cref;
DAE.Exp iterator, crefExp;
DAE.Operator op;
case({},_,_)
then foldIn;
case(BackendDAE.ITER_CREF(cref = cref, iterator=iterator)::rest,_,_)
algorithm
(crefExp,_) := replaceCref(cref,repl);
try
{cref} := Expression.extractCrefsFromExp(crefExp);
itCref := BackendDAE.ITER_CREF(cref, iterator);
itCrefLst := itCref::foldIn;
else
itCrefLst := foldIn;
end try;
itCrefLst := replaceIterationCrefs(rest,repl,itCrefLst);
then itCrefLst;
case(BackendDAE.ACCUM_ITER_CREF(cref = cref, op=op)::rest,_,_)
algorithm
(crefExp,_) := replaceCref(cref,repl);
if Expression.isNegativeUnary(crefExp) then
op := negateOperator(op);
end if;
try
{cref} := Expression.extractCrefsFromExp(crefExp);
itCref := BackendDAE.ACCUM_ITER_CREF(cref, op);
itCrefLst := itCref::foldIn;
else
itCrefLst := foldIn;
end try;
itCrefLst := replaceIterationCrefs(rest,repl,itCrefLst);
then itCrefLst;
case(_::rest,_,_)
algorithm
itCrefLst := replaceIterationCrefs(rest,repl,foldIn);
then itCrefLst;
end matchcontinue;
end replaceIterationCrefs;

protected function negateOperator
"makes an add out of a sub and a sub out of an add."
input DAE.Operator inOp;
Expand Down
16 changes: 8 additions & 8 deletions Compiler/BackEnd/Differentiate.mo
Expand Up @@ -308,7 +308,7 @@ algorithm
op2 = DAE.OP_DIFFERENTIATE(inDiffwrtCref, e2, e2_1);
source = List.foldr({op1, op2}, DAEUtil.addSymbolicTransformation, source);
then
(BackendDAE.EQUATION(e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.EQUATION(e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

// solved equations
case BackendDAE.SOLVED_EQUATION(componentRef=cref, exp=e2, source=source, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
Expand All @@ -325,7 +325,7 @@ algorithm
op2 = DAE.OP_DIFFERENTIATE(inDiffwrtCref, e2, e2_1);
source = List.foldr({op1, op2}, DAEUtil.addSymbolicTransformation, source);
then
(BackendDAE.EQUATION(e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.EQUATION(e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

// RESIDUAL_EQUATION
case BackendDAE.RESIDUAL_EQUATION(exp=e1, source=source, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
Expand All @@ -338,7 +338,7 @@ algorithm
source = List.foldr({op1}, DAEUtil.addSymbolicTransformation, source);

then
(BackendDAE.RESIDUAL_EQUATION(e1_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.RESIDUAL_EQUATION(e1_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

// complex equations
case BackendDAE.COMPLEX_EQUATION(size=size, left=e1, right=e2, source=source, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
Expand All @@ -353,7 +353,7 @@ algorithm
op2 = DAE.OP_DIFFERENTIATE(inDiffwrtCref, e2, e2_1);
source = List.foldr({op1, op2}, DAEUtil.addSymbolicTransformation, source);
then
(BackendDAE.COMPLEX_EQUATION(size, e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.COMPLEX_EQUATION(size, e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

// Array Equations
case BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left=e1, right=e2, source=source, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
Expand All @@ -368,7 +368,7 @@ algorithm
op2 = DAE.OP_DIFFERENTIATE(inDiffwrtCref, e2, e2_1);
source = List.foldr({op1, op2}, DAEUtil.addSymbolicTransformation, source);
then
(BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.ARRAY_EQUATION(dimSize, e1_1, e2_1, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

// differentiate algorithm
case BackendDAE.ALGORITHM(size=size, alg=DAE.ALGORITHM_STMTS(statementLst=statementLst), source=source, expand=expand, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
Expand All @@ -381,21 +381,21 @@ algorithm
//op1 = DAE.OP_DIFFERENTIATE(inDiffwrtCref, e1, e2);
//source = DAEUtil.addSymbolicTransformation(source, op1);
then
(BackendDAE.ALGORITHM(size, alg, source, expand, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.ALGORITHM(size, alg, source, expand, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

// if-equations
case BackendDAE.IF_EQUATION(conditions=expExpLst, eqnstrue=eqnslst, eqnsfalse=eqns, source=source, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
equation
(eqnslst, funcs) = differentiateEquationsLst(eqnslst, inDiffwrtCref, inInputData, inDiffType, {}, inFunctionTree);
(eqns, funcs) = differentiateEquations(eqns, inDiffwrtCref, inInputData, inDiffType, {}, funcs);
then
(BackendDAE.IF_EQUATION(expExpLst, eqnslst, eqns, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.IF_EQUATION(expExpLst, eqnslst, eqns, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

case BackendDAE.WHEN_EQUATION(size=size, whenEquation=whenEqn, source=source, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))
equation
(whenEqn, funcs) = differentiateWhenEquations(whenEqn, inDiffwrtCref, inInputData, inDiffType, inFunctionTree);
then
(BackendDAE.WHEN_EQUATION(size, whenEqn, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind, BackendDAE.NO_LOOP())), funcs);
(BackendDAE.WHEN_EQUATION(size, whenEqn, source, BackendDAE.EQUATION_ATTRIBUTES(false, eqKind)), funcs);

else
equation
Expand Down

0 comments on commit 18a82cf

Please sign in to comment.