Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' (reverted from commit b1…
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and sjoelund committed May 26, 2015
1 parent 9991681 commit 29b89ac
Show file tree
Hide file tree
Showing 23 changed files with 317 additions and 414 deletions.
63 changes: 12 additions & 51 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -5143,18 +5143,18 @@ author:Waurich TUD 2014-04"
input BackendDAE.Variables knVars;
output BackendDAE.Shared sharedOut;
protected
BackendDAE.Variables knownVars,externalObjects,aliasVars;
BackendDAE.EquationArray initialEqs,removedEqs;
list<DAE.Constraint> constraints;
list<DAE.ClassAttributes> classAttrs;
FCore.Cache cache;
FCore.Graph graph;
DAE.FunctionTree functionTree;
BackendDAE.EventInfo eventInfo;
BackendDAE.ExternalObjectClasses extObjClasses;
BackendDAE.BackendDAEType backendDAEType;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.ExtraInfo info;
BackendDAE.Variables knownVars,externalObjects,aliasVars;
BackendDAE.EquationArray initialEqs,removedEqs;
list<DAE.Constraint> constraints;
list<DAE.ClassAttributes> classAttrs;
FCore.Cache cache;
FCore.Graph graph;
DAE.FunctionTree functionTree;
BackendDAE.EventInfo eventInfo;
BackendDAE.ExternalObjectClasses extObjClasses;
BackendDAE.BackendDAEType backendDAEType;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.ExtraInfo info;
algorithm
BackendDAE.SHARED(knownVars=knownVars,externalObjects=externalObjects,aliasVars=aliasVars,initialEqs=initialEqs,removedEqs=removedEqs,
constraints=constraints,classAttrs=classAttrs,cache=cache,graph=graph,functionTree=functionTree,eventInfo=eventInfo,extObjClasses=extObjClasses,
Expand Down Expand Up @@ -8268,45 +8268,6 @@ algorithm
comp := BackendDAE.SINGLEEQUATION(eqIdx,varIdx);
end makeSingleEquationComp;

public function getAliasVars
input BackendDAE.BackendDAE inDAE;
output BackendDAE.Variables outAliasVars;
algorithm
BackendDAE.DAE(shared=BackendDAE.SHARED(aliasVars=outAliasVars)) := inDAE;
end getAliasVars;

public function getKnownVars
input BackendDAE.BackendDAE inDAE;
output BackendDAE.Variables outKnownVars;
algorithm
BackendDAE.DAE(shared=BackendDAE.SHARED(knownVars=outKnownVars)) := inDAE;
end getKnownVars;

public function setAliasVars
input BackendDAE.BackendDAE inDAE;
input BackendDAE.Variables inAliasVars;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;
algorithm
BackendDAE.DAE(eqs, shared) := inDAE;
shared := replaceAliasVarsInShared(shared, inAliasVars);
outDAE := BackendDAE.DAE(eqs, shared);
end setAliasVars;

public function setKnownVars
input BackendDAE.BackendDAE inDAE;
input BackendDAE.Variables inKnownVars;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;
algorithm
BackendDAE.DAE(eqs, shared) := inDAE;
shared := replaceKnownVarsInShared(shared, inKnownVars);
outDAE := BackendDAE.DAE(eqs, shared);
end setKnownVars;

annotation(__OpenModelica_Interface="backend");
end BackendDAEUtil;
31 changes: 1 addition & 30 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -158,7 +158,7 @@ public function removeSimpleEquations "author: Frenkel TUD 2012-12
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
Boolean b;
Boolean b;
algorithm
b := BackendDAEUtil.hasDAEMatching(inDAE);
outDAE := match(Flags.getConfigString(Flags.REMOVE_SIMPLE_EQUATIONS))
Expand All @@ -169,37 +169,8 @@ algorithm
case "new" then performAliasEliminationBB(inDAE);
else inDAE;
end match;

outDAE := fixAliasVars(outDAE) "workaround for #3323";
end removeSimpleEquations;

protected function fixAliasVars "author: lochel
This is a workaround for #3323
TODO: Remove this once removeSimpleEquations is implemented properly.

This module traverses all alias variables and double-checks if they are alias or known variables."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.Variables aliasVars;
list<BackendDAE.Var> aliasVarList = {};
list<BackendDAE.Var> knownVarList;
DAE.Exp binding;
algorithm
aliasVars := BackendDAEUtil.getAliasVars(inDAE);
knownVarList := BackendVariable.varList(BackendDAEUtil.getKnownVars(inDAE));
for var in BackendVariable.varList(aliasVars) loop
binding := BackendVariable.varBindExp(var);
if Expression.isConst(binding) then
knownVarList := var::knownVarList;
else
aliasVarList := var::aliasVarList;
end if;
end for;
outDAE := BackendDAEUtil.setAliasVars(inDAE, BackendVariable.listVar(aliasVarList));
outDAE := BackendDAEUtil.setKnownVars(outDAE, BackendVariable.listVar(knownVarList));
end fixAliasVars;


// =============================================================================
// section for fastAcausal
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Algorithm.mo
Expand Up @@ -630,7 +630,7 @@ algorithm

case (i, e, DAE.PROP(type_ = DAE.T_ARRAY(ty = t, dims = dims)), stmts, _)
equation
isArray = Types.isNonscalarArray(t, dims);
isArray = Types.isArray(t, dims);
then DAE.STMT_FOR(t, isArray, i, -1, e, stmts, source);

case (i, e, DAE.PROP(type_ = DAE.T_METALIST(ty = t)), stmts, _)
Expand Down Expand Up @@ -675,7 +675,7 @@ algorithm

case (i, e, DAE.PROP(type_ = DAE.T_ARRAY(ty = t, dims = dims)), stmts, _, _)
equation
isArray = Types.isNonscalarArray(t, dims);
isArray = Types.isArray(t, dims);
_ = Types.simplifyType(t);
then
DAE.STMT_PARFOR(t, isArray, i, -1, e, stmts, inLoopPrlVars, source);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/CevalFunction.mo
Expand Up @@ -565,7 +565,7 @@ algorithm
case (_, Values.ARRAY(valueLst = vals as Values.ARRAY() :: _, dimLst = dim :: _), _)
equation
(DAE.T_ARRAY(ty = ty, dims = dims), _) = getVariableTypeAndBinding(inCref, inEnv);
false = Types.isNonscalarArray(ty, dims);
false = Types.isArray(ty, dims);
vals = List.map(vals, ValuesUtil.arrayScalar);
then
Values.ARRAY(vals, {dim});
Expand Down
40 changes: 21 additions & 19 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -104,7 +104,22 @@ end intSubscripts;
protected function subscriptInt
"Tries to convert a subscript to an integer index."
input DAE.Subscript inSubscript;
output Integer outInteger = expArrayIndex(subscriptIndexExp(inSubscript));
output Integer outInteger;
algorithm
outInteger := match(inSubscript)
local
Integer x;
Boolean b;
case DAE.INDEX(exp = DAE.ICONST(integer = x)) then x;
case DAE.INDEX(exp = DAE.ENUM_LITERAL(index = x)) then x;
case DAE.INDEX(exp = DAE.BCONST(bool = b)) then if b then 1 else 0;
/*
else
equation
Error.addInternalError("subscriptInt failed: " + ExpressionDump.printSubscriptStr(inSubscript), sourceInfo());
then fail();
*/
end match;
end subscriptInt;

public function subscriptsInt
Expand Down Expand Up @@ -1522,25 +1537,12 @@ public function expInt "returns the int value if expression is constant Integer"
input DAE.Exp exp;
output Integer i;
algorithm
i := match exp
case DAE.ICONST() then exp.integer;
case DAE.ENUM_LITERAL() then exp.index;
case DAE.BCONST() then if exp.bool then 1 else 0;
i := match(exp) local Integer i2;
case (DAE.ICONST(integer = i2)) then i2;
case (DAE.ENUM_LITERAL(index = i2)) then i2;
end match;
end expInt;

public function expArrayIndex
"Returns the array index that an expression represents as an integer."
input DAE.Exp inExp;
output Integer outIndex;
algorithm
outIndex := match inExp
case DAE.ICONST() then inExp.integer;
case DAE.ENUM_LITERAL() then inExp.index;
case DAE.BCONST() then if inExp.bool then 2 else 1;
end match;
end expArrayIndex;

public function varName "Returns the name of a Var"
input DAE.Var v;
output String name;
Expand Down Expand Up @@ -1867,7 +1869,7 @@ algorithm

case DAE.BINARY(operator=op, exp1=e1, exp2=e2) equation
ty = typeofOp(op);
true = Types.isArray(ty);
true = Types.isArray(ty, {});
e_1 = nthArrayExp(e1, inInteger);
e_2 = nthArrayExp(e2, inInteger);
then DAE.BINARY(e_1, op, e_2);
Expand Down Expand Up @@ -10264,7 +10266,7 @@ algorithm
tys = makePromotedTypes(dims, ty, {});

// Use the constructed types to promote the expression.
is_array_ty = Types.isArray(inType);
is_array_ty = Types.isArray(inType, {});
exp = promoteExp2(inExp, is_array_ty, dims_to_add, tys);
then
(exp, res_ty);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1241,7 +1241,7 @@ algorithm
simplifySymmetric(marr, arrayLength(marr)-1, arrayLength(marr));
mexpl = List.map(arrayList(marr), arrayList);
tp1 = Types.unliftArray(tp);
es = List.map2(mexpl, Expression.makeArray, tp1, not Types.isArray(tp1));
es = List.map2(mexpl, Expression.makeArray, tp1, not Types.isArray(tp1,{}));
e = Expression.makeArray(es, tp, false);
then e;
end match;
Expand All @@ -1254,7 +1254,7 @@ algorithm

case DAE.CALL(path=Absyn.IDENT("vector"),expLst=es as (e::_),attr=DAE.CALL_ATTR(ty=DAE.T_ARRAY(tp,_,source)))
equation
false = Types.isArray(Expression.typeof(e));
false = Types.isArray(Expression.typeof(e),{});
i = listLength(es);
tp = DAE.T_ARRAY(tp,{DAE.DIM_INTEGER(i)},source);
then DAE.ARRAY(tp,true,es);
Expand Down Expand Up @@ -2937,7 +2937,7 @@ algorithm
// name subscript
case(DAE.CREF(c,t), _, _)
equation
true = Types.isArray(t);
true = Types.isArray(t,{});
t = Expression.unliftArray(t);
c_1 = simplifyAsubCref(c, inSubExp);
exp = Expression.makeCrefExp(c_1, t);
Expand Down Expand Up @@ -5295,7 +5295,7 @@ algorithm
aty = Types.unliftArray(Types.expTypetoTypesType(ty));
length = listLength(inExps);
ty2 = Types.liftArray(aty, DAE.DIM_INTEGER(length)); // The size can be unknown before the reduction...
exp = Expression.makeArray(inExps, ty2, not Types.isArray(aty));
exp = Expression.makeArray(inExps, ty2, not Types.isArray(aty,{}));
then exp;

case (_,_,_,_,_,{},SOME(val)) then ValuesUtil.valueExp(val);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/InstBinding.mo
Expand Up @@ -215,7 +215,7 @@ algorithm
Option<Values.Value> optVal;
case (mod,etype,(index :: {}),_,_) /* Only one element in the index-list */
equation
mod2 = Mod.lookupIdxModification(mod, DAE.ICONST(index));
mod2 = Mod.lookupIdxModification(mod, index);
SOME(DAE.TYPED(e,optVal,DAE.PROP(ty2,_),_,_)) = Mod.modEquation(mod2);
(e_1,_) = Types.matchType(e, ty2, etype, true);
e_1 = InstUtil.checkUseConstValue(useConstValue,e_1,optVal);
Expand All @@ -226,7 +226,7 @@ algorithm
result = matchcontinue()
case ()
equation
mod2 = Mod.lookupIdxModification(mod, DAE.ICONST(index));
mod2 = Mod.lookupIdxModification(mod, index);
result = instBinding2(mod2, etype, res, bind_name,useConstValue);
then result;
else NONE();
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -6184,7 +6184,7 @@ algorithm

case (_,ci,_,SOME(tp),_)
equation
true = Types.isArray(tp);
true = Types.isArray(tp, {});
failure(ClassInf.isConnector(ci));
then
tp;
Expand Down Expand Up @@ -6377,7 +6377,7 @@ algorithm

else
equation
false = Types.isArray(inType);
false = Types.isArray(inType, {});
then
(inExp, inValue);
end matchcontinue;
Expand Down

0 comments on commit 29b89ac

Please sign in to comment.