Skip to content

Commit

Permalink
New optimization module to wrap function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Nov 30, 2015
1 parent 150aaf3 commit f81f8c6
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -637,7 +637,7 @@ algorithm
dae_var_attr = DAEUtil.setProtectedAttr(dae_var_attr, b);
dae_var_attr = setMinMaxFromEnumeration(t, dae_var_attr);
(dae_var_attr, source, _) = Inline.inlineStartAttribute(dae_var_attr, source, (SOME(functionTree), {DAE.NORM_INLINE()}));
ts = BackendDAEUtil.setTearingSelectAttribute(comment);
ts = BackendDAEUtil.setTearingSelectAttribute(comment);
then
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, comment, ct, DAEUtil.toDAEInnerOuter(io), false));
end match;
Expand Down
12 changes: 8 additions & 4 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7067,7 +7067,7 @@ protected function allPreOptimizationModules
(BackendDAEOptimize.expandDerOperator, "expandDerOperator"),
(BackendDAEOptimize.removeEqualFunctionCalls, "removeEqualFunctionCalls"),
(SynchronousFeatures.clockPartitioning, "clockPartitioning"),
(CommonSubExpression.CSE_EachCall, "CSE_EachCall"),
(CommonSubExpression.wrapFunctionCalls, "wrapFunctionCalls"),
(IndexReduction.findStateOrder, "findStateOrder"),
(BackendDAEOptimize.introduceDerAlias, "introduceDerAlias"),
(DynamicOptimization.inputDerivativesForDynOpt, "inputDerivativesForDynOpt"), // only for dyn. opt.
Expand Down Expand Up @@ -7101,6 +7101,7 @@ protected function allPostOptimizationModules
output list<tuple<BackendDAEFunc.optimizationModule, String>> allPostOptimizationModules = {
(BackendInline.lateInlineFunction, "lateInlineFunction"),
(DynamicOptimization.simplifyConstraints, "simplifyConstraints"),
(CommonSubExpression.wrapFunctionCalls, "wrapFunctionCalls"),
(CommonSubExpression.CSE, "CSE"),
(OnRelaxation.relaxSystem, "relaxSystem"),
(InlineArrayEquations.inlineArrayEqn, "inlineArrayEqn"),
Expand Down Expand Up @@ -7256,12 +7257,15 @@ algorithm
enabledModules := "extendDynamicOptimization"::enabledModules;
end if;

if Flags.getConfigBool(Flags.CSE_CALL) or
Flags.getConfigBool(Flags.CSE_EACHCALL) or
Flags.getConfigBool(Flags.CSE_BINARY) then
if Flags.getConfigBool(Flags.CSE_BINARY) then
enabledModules := "CSE"::enabledModules;
end if;

if Flags.getConfigBool(Flags.CSE_CALL) or
Flags.getConfigBool(Flags.CSE_EACHCALL) then
enabledModules := "wrapFunctionCalls"::enabledModules;
end if;

if Flags.isSet(Flags.ON_RELAXATION) then
enabledModules := "relaxSystem"::enabledModules;
end if;
Expand Down
20 changes: 20 additions & 0 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -1286,6 +1286,25 @@ algorithm
end match;
end traverseOptEquation_WithStop;

public function calculateOptArrEqnSizeProperly "author: lochel"
input array<Option<BackendDAE.Equation>> inEquOptArr;
output Integer outSize = 0;
algorithm
for optEq in inEquOptArr loop
outSize := match optEq
local
Integer size;
BackendDAE.Equation eq;

case SOME(eq) equation
size = BackendEquation.equationSize(eq);
then outSize+size;

else outSize;
end match;
end for;
end calculateOptArrEqnSizeProperly;

public function traverseEquationArray_WithUpdate<T> "author: Frenkel TUD
Traverses all equations of a BackendDAE.EquationArray."
input BackendDAE.EquationArray inEquationArray;
Expand All @@ -1304,6 +1323,7 @@ protected
array<Option<BackendDAE.Equation>> equOptArr;
algorithm
(equOptArr, outTypeA) := BackendDAEUtil.traverseArrayNoCopyWithUpdate(inEquationArray.equOptArr, inFuncWithUpdate, traverseOptEquation_WithUpdate, inTypeA);
outEquationArray.size := calculateOptArrEqnSizeProperly(equOptArr);
outEquationArray.equOptArr := equOptArr;
end traverseEquationArray_WithUpdate;

Expand Down
36 changes: 32 additions & 4 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1514,7 +1514,7 @@ algorithm
end createVar;

public function createCSEVar "Creates a cse variable with the name of inCref.
TODO: discrete real varaibales are not treated correctly"
TODO: discrete real variables are not treated correctly"
input DAE.ComponentRef inCref;
input DAE.Type inType;
output BackendDAE.Var outVar;
Expand All @@ -1530,16 +1530,44 @@ algorithm
DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path), source=typeLst) = inType;
source = DAE.SOURCE(Absyn.dummyInfo, {}, NONE(), {}, path::typeLst, {}, {});
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), {}, source, NONE(), SOME(BackendDAE.AVOID()), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), {}, source, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;

case (_) equation
else equation
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), SOME(BackendDAE.AVOID()), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false);
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;
end match;
end createCSEVar;

public function createCSEArrayVar "Creates a cse array variable with the name of inCref.
TODO: discrete real variables are not treated correctly"
input DAE.ComponentRef inCref;
input DAE.Type inType;
input DAE.InstDims inArryDim;
output BackendDAE.Var outVar;
algorithm
outVar := match (inCref)
local
DAE.ElementSource source;
list<Absyn.Path> typeLst;
Absyn.Path path;
BackendDAE.VarKind varKind;

case (_) guard(ComponentReference.traverseCref(inCref, ComponentReference.crefIsRec, false)) equation
DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path), source=typeLst) = inType;
source = DAE.SOURCE(Absyn.dummyInfo, {}, NONE(), {}, path::typeLst, {}, {});
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), inArryDim, source, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;

else equation
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), inArryDim, DAE.emptyElementSource, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;
end match;
end createCSEArrayVar;

public function copyVarNewName "author: Frenkel TUD 2012-5
Create variable with new name as cref from other var."
input DAE.ComponentRef cr;
Expand Down

0 comments on commit f81f8c6

Please sign in to comment.