Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Remove unused and superfluous BackendDAE.VAR.bindValue
Browse files Browse the repository at this point in the history
see ticket:3682
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Jan 11, 2017
1 parent ed61035 commit 4d49ee5
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 403 deletions.
1 change: 0 additions & 1 deletion Compiler/BackEnd/BackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ uniontype Var "variables"
.DAE.VarParallelism varParallelism "parallelism of the variable. parglobal, parlocal or non-parallel";
Type varType "built-in type or enumeration";
Option< .DAE.Exp> bindExp "Binding expression e.g. for parameters";
Option<Values.Value> bindValue "binding value for parameters";
.DAE.InstDims arryDim "array dimensions of non-expanded var";
.DAE.ElementSource source "origin of variable";
Option< .DAE.VariableAttributes> values "values on built-in attributes";
Expand Down
8 changes: 4 additions & 4 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ algorithm
ts = BackendDAEUtil.setTearingSelectAttribute(comment);
hideResult = BackendDAEUtil.setHideResultAttribute(comment, b, name);
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false));
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false));
end match;
end lowerDynamicVar;

Expand Down Expand Up @@ -833,7 +833,7 @@ algorithm
ts = NONE();
hideResult = BackendDAEUtil.setHideResultAttribute(comment, b, name);
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false), iInlineHT, eqLst);
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false), iInlineHT, eqLst);

else
equation
Expand Down Expand Up @@ -1152,7 +1152,7 @@ algorithm
ts = NONE();
hideResult = DAE.BCONST(false);
then
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false);
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false);
end match;
end lowerExtObjVar;

Expand Down Expand Up @@ -1814,7 +1814,7 @@ algorithm
varName = cr, varKind = BackendDAE.VARIABLE(),
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
varType = DAE.T_CLOCK_DEFAULT, bindExp = NONE(),
bindValue = NONE(), arryDim = {}, source = DAE.emptyElementSource,
arryDim = {}, source = DAE.emptyElementSource,
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()), hideResult = DAE.BCONST(false),
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true ) :: inVars;
Expand Down
18 changes: 2 additions & 16 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -701,20 +701,13 @@ algorithm
DAE.ComponentRef varName;
Option< .DAE.VariableAttributes> values;
DAE.Exp exp,exp1;
Values.Value bindValue;

case (v as BackendDAE.VAR(varName=varName,varKind=BackendDAE.PARAM(),bindExp=SOME(exp)),(repl,vars))
equation
(exp1, _) = Expression.traverseExpBottomUp(exp, BackendDAEUtil.replaceCrefsWithValues, (vars, varName));
repl_1 = BackendVarTransform.addReplacement(repl, varName, exp1,NONE());
then (v,(repl_1,vars));

case (v as BackendDAE.VAR(varName=varName,varKind=BackendDAE.PARAM(),bindValue=SOME(bindValue)),(repl,vars))
equation
exp = ValuesUtil.valueExp(bindValue);
repl_1 = BackendVarTransform.addReplacement(repl, varName, exp,NONE());
then (v,(repl_1,vars));

else (inVar,inTpl);
end matchcontinue;
end removeParametersFinder;
Expand Down Expand Up @@ -886,19 +879,12 @@ algorithm
DAE.ComponentRef varName;
Option< .DAE.VariableAttributes> values;
DAE.Exp exp;
Values.Value bindValue;
case (v as BackendDAE.VAR(varName=varName,varKind=BackendDAE.PARAM(),bindExp=SOME(exp),values=values),repl)
equation
true = DAEUtil.getProtectedAttr(values);
repl_1 = BackendVarTransform.addReplacement(repl, varName, exp,NONE());
then (v,repl_1);
case (v as BackendDAE.VAR(varName=varName,varKind=BackendDAE.PARAM(),bindValue=SOME(bindValue),values=values),repl)
equation
true = DAEUtil.getProtectedAttr(values);
true = BackendVariable.varFixed(v);
exp = ValuesUtil.valueExp(bindValue);
repl_1 = BackendVarTransform.addReplacement(repl, varName, exp,NONE());
then (v,repl_1);

else (inVar,inRepl);
end matchcontinue;
end protectedParametersFinder;
Expand Down Expand Up @@ -5690,7 +5676,7 @@ protected
algorithm
(BackendDAE.DAE(eqs, shared), _) := BackendDAEUtil.mapEqSystemAndFold(inDAE, addTimeAsState1, 0);
orderedVars := BackendVariable.emptyVars();
var := BackendDAE.VAR(DAE.crefTimeState, BackendDAE.STATE(1, NONE()), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
var := BackendDAE.VAR(DAE.crefTimeState, BackendDAE.STATE(1, NONE()), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
var := BackendVariable.setVarFixed(var, true);
var := BackendVariable.setVarStartValue(var, DAE.CREF(DAE.crefTime, DAE.T_REAL_DEFAULT));
orderedVars := BackendVariable.addVar(var, orderedVars);
Expand Down
104 changes: 6 additions & 98 deletions Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected
algorithm
name := Expression.reductionIterName(iter);
cr := ComponentReference.makeCrefIdent(name,DAE.T_INTEGER_DEFAULT,{});
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
end makeIterVariable;

protected function checkEquationSize"author: Frenkel TUD 2010-12
Expand Down Expand Up @@ -629,94 +629,6 @@ algorithm
end match;
end countDiscreteVars3;

protected function calculateValues "author: PA
This function calculates the values from the parameter binding expressions.
modefication: wbraun
Use really only parameter bindungs for evaluation."
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
algorithm
outBackendDAE := match inBackendDAE
local
BackendDAE.Variables globalKnownVars;
FCore.Cache cache;
FCore.Graph graph;
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;

case BackendDAE.DAE(eqs, shared as BackendDAE.SHARED(globalKnownVars=globalKnownVars, cache=cache, graph=graph))
algorithm
globalKnownVars := BackendVariable.traverseBackendDAEVarsWithUpdate (
globalKnownVars, function calculateValueTraverser(inEnv = graph), cache );
// Reverse the order of the known vars in the hashtable. This is stupid,
// but things break otherwise.
shared.globalKnownVars := BackendVariable.listVar(BackendVariable.varList(globalKnownVars));
then
BackendDAE.DAE(eqs, shared);
end match;
end calculateValues;

protected function calculateValueTraverser
input BackendDAE.Var inVar;
input FCore.Cache inCache;
input FCore.Graph inEnv;
output BackendDAE.Var outVar;
output FCore.Cache outCache = inCache;
algorithm
if BackendVariable.isParam(inVar) then
outVar := calculateValue(inVar, inCache, inEnv);
else
outVar := inVar;
end if;
end calculateValueTraverser;

protected function calculateValue
input BackendDAE.Var inVar;
input FCore.Cache cache;
input FCore.Graph graph;
output BackendDAE.Var outVar;
algorithm
outVar := matchcontinue(inVar)
local
BackendDAE.Var var;
DAE.ComponentRef cr;
BackendDAE.VarKind vk;
DAE.VarDirection vd;
DAE.VarParallelism prl;
BackendDAE.Type ty;
DAE.Exp e;
DAE.InstDims dims;
DAE.ElementSource src;
Option<DAE.VariableAttributes> va;
Option<BackendDAE.TearingSelect> ts;
DAE.Exp hideResult;
Option<SCode.Comment> c;
DAE.ConnectorType ct;
Values.Value v;
DAE.VarInnerOuter io;
case BackendDAE.VAR(bindValue = SOME(_))
equation
print("*** Not Ceval.eval var: ");
BackendDump.printVar(inVar);
print("\n");
then
inVar;
case BackendDAE.VAR(varName = cr, varKind = vk, varDirection = vd, varParallelism = prl,
varType = ty, bindExp = SOME(e), arryDim = dims, source = src,
values = va, tearingSelectOption = ts, hideResult = hideResult, comment = c, connectorType = ct, innerOuter = io)
equation
// wbraun: Evaluate parameter expressions only if they are
// constant at compile time otherwise we solve them
// much faster at runtime.
//((e, _)) = Expression.traverseExpBottomUp(e, replaceCrefsWithValues, (vars, cr_orign));
true = Expression.isConst(e);
(_, v, _) = Ceval.ceval(cache, graph, e, false, NONE(), Absyn.NO_MSG(),0);
then
BackendDAE.VAR(cr, vk, vd, prl, ty, SOME(e), SOME(v), dims, src, va, ts, hideResult, c, ct, io, false);
else inVar;
end matchcontinue;
end calculateValue;

public function replaceCrefsWithValues
input DAE.Exp inExp;
input tuple<BackendDAE.Variables, DAE.ComponentRef> inTuple;
Expand Down Expand Up @@ -6427,7 +6339,6 @@ algorithm
DAE.VarDirection varDirection;
DAE.VarParallelism varParallelism;
BackendDAE.Type varType;
Option<Values.Value> bindValue;
DAE.ElementSource source;
Option<SCode.Comment> comment;
DAE.ConnectorType ct;
Expand All @@ -6439,22 +6350,22 @@ algorithm
case NONE()
then (NONE(), inTypeA);

case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
(e1_, ext_arg_1) = func(e1, inTypeA);
(attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, ext_arg_1);
if referenceEq(e1,e1_) and referenceEq(attr,attr_) then
v = inVar;
else
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), bindValue, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
end if;
then (v, ext_arg_2);

case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
(attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, inTypeA);
if referenceEq(attr,attr_) then
v = inVar;
else
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
end if;
then (v, ext_arg_2);

Expand Down Expand Up @@ -6918,10 +6829,7 @@ algorithm
simDAE := Initialization.removeInitializationStuff(simDAE);

// post-optimization phase
simDAE := postOptimizeDAE(simDAE, postOptModules, matchingAlgorithm, daeHandler);

outSimDAE := calculateValues(simDAE);
execStat("calculateValue");
outSimDAE := postOptimizeDAE(simDAE, postOptModules, matchingAlgorithm, daeHandler);

if Flags.isSet(Flags.DUMP_INDX_DAE) then
BackendDump.dumpBackendDAE(outSimDAE, "dumpindxdae");
Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.LESS(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e1,e2);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2312,7 +2312,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.LESSEQ(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e1,e2);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2322,7 +2322,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.GREATER(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify1(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2332,7 +2332,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.GREATEREQ(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2342,7 +2342,7 @@ algorithm

case (_, DAE.RELATION(e1, DAE.EQUAL(_), e2, _, _)) equation
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
rhs = Expression.expSub(e2,e1);
(rhs, _) = ExpressionSimplify.simplify(rhs);
expNull = DAE.RCONST(0.0);
Expand All @@ -2357,7 +2357,7 @@ algorithm
end try;

lhs := ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.BCONST(false), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
dummyVar := BackendVariable.mergeAliasVars(dummyVar, v, false, knvars);
eqn := BackendDAE.SOLVED_EQUATION(lhs, e1, Source, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN);

Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/BackendInline.mo
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ algorithm
DAE.VarDirection varDirection;
DAE.VarParallelism varParallelism;
BackendDAE.Type varType;
Option<Values.Value> bindValue;
DAE.InstDims arrayDim;
Option<DAE.VariableAttributes> values,values1;
Option<BackendDAE.TearingSelect> ts;
Expand All @@ -525,10 +524,10 @@ algorithm
DAE.VarInnerOuter io;
Boolean unreplaceable;

case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values,ts,hideResult,comment,ct,io,unreplaceable) equation
case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,arrayDim,source,values,ts,hideResult,comment,ct,io,unreplaceable) equation
(bind,source,b1) = Inline.inlineExpOpt(bind,inElementList,source);
(values1,source,b2) = Inline.inlineStartAttribute(values,source,inElementList);
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,bindValue,arrayDim,source,values1,ts,hideResult,comment,ct,io,unreplaceable), b1 or b2);
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,arrayDim,source,values1,ts,hideResult,comment,ct,io,unreplaceable), b1 or b2);

else (inVar, false);
end match;
Expand Down

0 comments on commit 4d49ee5

Please sign in to comment.