Skip to content

Commit

Permalink
Handle deprecated pre-optimization flags
Browse files Browse the repository at this point in the history
* make "evalFunc" default pre-optimization module
* display a warning for deprecated pre-optimization flags
  • Loading branch information
lochel committed Dec 14, 2015
1 parent 8759c84 commit 6c8bc92
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 97 deletions.
15 changes: 2 additions & 13 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -4038,13 +4038,6 @@ end addedScaledVarsWork;
// =============================================================================

public function sortEqnsVars
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
outDAE := if Flags.isSet(Flags.SORT_EQNS_AND_VARS) then sortEqnsVarsWork(inDAE) else inDAE;
end sortEqnsVars;

protected function sortEqnsVarsWork
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
protected
Expand Down Expand Up @@ -4110,7 +4103,7 @@ algorithm

outDAE:= BackendDAE.DAE(new_systlst, shared);
//BackendDump.bltdump("ENDE:", outDAE);
end sortEqnsVarsWork;
end sortEqnsVars;

protected function sortEqnsVarsWorkTpl
input list<tuple<Integer,Integer>> tplIndexWeight;
Expand Down Expand Up @@ -5007,11 +5000,7 @@ public function introduceDerAlias
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
if Flags.isSet(Flags.ADD_DER_ALIASES) then
outDAE := BackendDAEUtil.mapEqSystem(inDAE, introduceDerAliasWork);
else
outDAE := inDAE;
end if;
outDAE := BackendDAEUtil.mapEqSystem(inDAE, introduceDerAliasWork);
end introduceDerAlias;

protected function introduceDerAliasWork
Expand Down
48 changes: 22 additions & 26 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7161,6 +7161,19 @@ algorithm
strPreOptModules := Config.getPreOptModules();
end getPreOptModulesString;

protected function deprecatedDebugFlag
input Flags.DebugFlag inFlag;
input list<String> inModuleList;
input String inModule;
input String inPhase;
output list<String> outModuleList = inModuleList;
algorithm
if Flags.isSet(inFlag) then
outModuleList := inModule::inModuleList;
Error.addCompilerWarning("Deprecated debug flag --d=" + Flags.debugFlagName(inFlag) + " detected. Use --" + inPhase + "=" + inModule + " instead.");
end if;
end deprecatedDebugFlag;

protected function getPreOptModules
input Option<list<String>> inPreOptModules;
output list<tuple<BackendDAEFunc.optimizationModule, String>> outPreOptModules;
Expand All @@ -7174,42 +7187,25 @@ algorithm

if Flags.getConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING) then
// handle special flags, which enable modules
if Flags.isSet(Flags.SORT_EQNS_AND_VARS) then
enabledModules := "sortEqnsVars"::enabledModules;
end if;

enabledModules := deprecatedDebugFlag(Flags.SORT_EQNS_AND_VARS, enabledModules, "sortEqnsVars", "preOptModules+");
enabledModules := deprecatedDebugFlag(Flags.RESOLVE_LOOPS, enabledModules, "resolveLoops", "preOptModules+");
enabledModules := deprecatedDebugFlag(Flags.EVAL_ALL_PARAMS, enabledModules, "evaluateAllParameters", "preOptModules+");
enabledModules := deprecatedDebugFlag(Flags.ADD_DER_ALIASES, enabledModules, "introduceDerAlias", "preOptModules+");
if Config.acceptOptimicaGrammar() or Flags.getConfigBool(Flags.GENERATE_DYN_OPTIMIZATION_PROBLEM) then
enabledModules := "inputDerivativesForDynOpt"::enabledModules;
end if;

if Flags.isSet(Flags.RESOLVE_LOOPS) then
enabledModules := "resolveLoops"::enabledModules;
end if;

if Flags.isSet(Flags.EVALUATE_CONST_FUNCTIONS) then
enabledModules := "evalFunc"::enabledModules;
end if;

if Flags.isSet(Flags.EVAL_ALL_PARAMS) then
enabledModules := "evaluateAllParameters"::enabledModules;
end if;

if Flags.isSet(Flags.ADD_DER_ALIASES) then
enabledModules := "introduceDerAlias"::enabledModules;
end if;

// handle special flags, which disable modules
if Flags.isSet(Flags.NO_PARTITIONING) then
disabledModules := "clockPartitioning"::disabledModules;
end if;

disabledModules := deprecatedDebugFlag(Flags.NO_PARTITIONING, disabledModules, "clockPartitioning", "preOptModules-");
disabledModules := deprecatedDebugFlag(Flags.DISABLE_COMSUBEXP, disabledModules, "comSubExp", "preOptModules-");
if Flags.getConfigString(Flags.REMOVE_SIMPLE_EQUATIONS) == "causal" or
Flags.getConfigString(Flags.REMOVE_SIMPLE_EQUATIONS) == "none" then
disabledModules := "removeSimpleEquations"::disabledModules;
end if;

if Flags.isSet(Flags.DISABLE_COMSUBEXP) then
disabledModules := "comSubExp"::disabledModules;
if not Flags.isSet(Flags.EVALUATE_CONST_FUNCTIONS) then
disabledModules := "evalFunc"::disabledModules;
Error.addCompilerWarning("Deprecated debug flag --d=evalConstFuncs=false detected. Use --preOptModules-=evalFunc instead.");
end if;
end if;

Expand Down
17 changes: 5 additions & 12 deletions Compiler/BackEnd/CommonSubExpression.mo
Expand Up @@ -997,19 +997,12 @@ REMARK: this is just a basic prototype. feel free to extend.
author:Waurich TUD 2014-11"
input BackendDAE.BackendDAE daeIn;
output BackendDAE.BackendDAE daeOut;
protected
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;
algorithm
//print("SYSTEM IN\n");
//BackendDump.printBackendDAE(daeIn);
if Flags.isSet(Flags.DISABLE_COMSUBEXP) then
daeOut := daeIn;
else
daeOut := BackendDAEUtil.mapEqSystem(daeIn, commonSubExpression);
end if;
//print("SYSTEM OUT\n");
//BackendDump.printBackendDAE(daeOut);
//print("SYSTEM IN\n");
//BackendDump.printBackendDAE(daeIn);
daeOut := BackendDAEUtil.mapEqSystem(daeIn, commonSubExpression);
//print("SYSTEM OUT\n");
//BackendDump.printBackendDAE(daeOut);
end commonSubExpressionReplacement;

protected function commonSubExpression
Expand Down
36 changes: 15 additions & 21 deletions Compiler/BackEnd/EvaluateFunctions.mo
Expand Up @@ -89,30 +89,24 @@ partial constant outputs are added as extra equations. Therefore removeSimpleEqu
author:Waurich TUD 2014-04"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
Boolean changed;
BackendDAE.EqSystems eqSysts;
BackendDAE.Shared shared;
algorithm
outDAE := matchcontinue(inDAE)
local
Boolean changed;
BackendDAE.EqSystems eqSysts;
BackendDAE.Shared shared;
case(_)
equation
true = Flags.isSet(Flags.EVALUATE_CONST_FUNCTIONS);
BackendDAE.DAE(eqs = eqSysts,shared = shared) = inDAE;
(eqSysts,(shared,_,changed)) = List.mapFold(eqSysts,evalFunctions_main,(shared,1,false));
//shared = evaluateShared(shared);
try
BackendDAE.DAE(eqs=eqSysts, shared=shared) := inDAE;
(eqSysts, (shared, _, changed)) := List.mapFold(eqSysts, evalFunctions_main, (shared, 1, false));
//shared = evaluateShared(shared);

if changed then
outDAE = updateVarKinds(RemoveSimpleEquations.fastAcausal(BackendDAE.DAE(eqSysts,shared)));
else
outDAE = inDAE;
end if;
then
outDAE;
if changed then
outDAE := updateVarKinds(RemoveSimpleEquations.fastAcausal(BackendDAE.DAE(eqSysts, shared)));
else
then
inDAE;
end matchcontinue;
outDAE := inDAE;
end if;
else
outDAE := inDAE;
end try;
end evalFunctions;

protected function evaluateShared "evaluate objects in the shared structure that could be dependent of a function. i.e. parameters
Expand Down
14 changes: 5 additions & 9 deletions Compiler/BackEnd/EvaluateParameter.mo
Expand Up @@ -197,15 +197,11 @@ Evaluates all parameters and replaces them with their value, if possible."
protected
BackendVarTransform.VariableReplacements repl;
algorithm
if Flags.isSet(Flags.EVAL_ALL_PARAMS) then
(outDAE,repl) := evaluateParameters(inDAE,BackendVariable.isParam);
if not BackendVarTransform.isReplacementEmpty(repl) then
//BackendVarTransform.dumpReplacements(repl);
outDAE := replaceEvaluatedParametersEqns(outDAE, repl);
end if;
else
outDAE := inDAE;
end if;
(outDAE, repl) := evaluateParameters(inDAE, BackendVariable.isParam);
if not BackendVarTransform.isReplacementEmpty(repl) then
//BackendVarTransform.dumpReplacements(repl);
outDAE := replaceEvaluatedParametersEqns(outDAE, repl);
end if;
end evaluateAllParameters;

/*
Expand Down
8 changes: 2 additions & 6 deletions Compiler/BackEnd/ResolveLoops.mo
Expand Up @@ -69,12 +69,8 @@ protected
BackendDAE.EqSystems eqSysts;
BackendDAE.Shared shared;
algorithm
if Flags.isSet(Flags.RESOLVE_LOOPS) then
(eqSysts, shared, _) := List.mapFold2(inDAE.eqs, resolveLoops_main, inDAE.shared, 1);
outDAE := BackendDAE.DAE(eqSysts, shared);
else
outDAE := inDAE;
end if;
(eqSysts, shared, _) := List.mapFold2(inDAE.eqs, resolveLoops_main, inDAE.shared, 1);
outDAE := BackendDAE.DAE(eqSysts, shared);
end resolveLoops;

protected function resolveLoops_main "author: Waurich TUD 2014-01
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/SynchronousFeatures.mo
Expand Up @@ -75,13 +75,13 @@ algorithm
list<BackendDAE.EqSystem> systs;
BackendDAE.Shared shared;

case (BackendDAE.DAE({syst}, shared)) guard(not Flags.isSet(Flags.NO_PARTITIONING))
case (BackendDAE.DAE({syst}, shared))
then clockPartitioning1(syst, shared);

// TODO: Improve support for partitioned systems of equations
case _ guard(not Flags.isSet(Flags.NO_PARTITIONING)) equation
else equation
BackendDAE.DAE({syst}, shared) = BackendDAEOptimize.collapseIndependentBlocks(inDAE);
then clockPartitioning1(syst, shared);
else inDAE;
end match;
end clockPartitioning;

Expand Down
16 changes: 9 additions & 7 deletions Compiler/Util/Flags.mo
Expand Up @@ -359,15 +359,15 @@ constant DebugFlag INFO_XML_OPERATIONS = DEBUG_FLAG(96, "infoXmlOperations", fal
constant DebugFlag HPCOM_DUMP = DEBUG_FLAG(97, "hpcomDump", false,
Util.gettext("Dumps additional information on the parallel execution with hpcom."));
constant DebugFlag RESOLVE_LOOPS = DEBUG_FLAG(98, "resolveLoops", false,
Util.gettext("Activates the resolveLoops module."));
Util.gettext("Activates the resolveLoops module.\nDeprecated flag: Use --preOptModules+=resolveLoops instead."));
constant DebugFlag DISABLE_WINDOWS_PATH_CHECK_WARNING = DEBUG_FLAG(99, "disableWindowsPathCheckWarning", false,
Util.gettext("Disables warnings on Windows if OPENMODELICAHOME/MinGW is missing."));
constant DebugFlag DISABLE_RECORD_CONSTRUCTOR_OUTPUT = DEBUG_FLAG(100, "disableRecordConstructorOutput", false,
Util.gettext("Disables output of record constructors in the flat code."));
constant DebugFlag DUMP_TRANSFORMED_MODELICA_MODEL = DEBUG_FLAG(101, "dumpTransformedModelica", false,
Util.gettext("Dumps the back-end DAE to a Modelica-like model after all symbolic transformations are applied."));
constant DebugFlag EVALUATE_CONST_FUNCTIONS = DEBUG_FLAG(102, "evalConstFuncs", true,
Util.gettext("Evaluates functions complete and partially and checks for constant output."));
Util.gettext("Evaluates functions complete and partially and checks for constant output.\nDeprecated flag: Use --preOptModules+=evalFunc instead."));
constant DebugFlag IMPL_ODE = DEBUG_FLAG(103, "implOde", false,
Util.gettext("activates implicit codegen"));
constant DebugFlag EVAL_FUNC_DUMP = DEBUG_FLAG(104, "evalFuncDump", false,
Expand Down Expand Up @@ -415,13 +415,14 @@ constant DebugFlag DUMP_CSE_VERBOSE = DEBUG_FLAG(124, "dumpCSE_verbose", false,
constant DebugFlag ADD_DER_ALIASES = DEBUG_FLAG(125, "addDerAliases", false,
Util.gettext("Adds for every der-call an alias equation e.g. dx = der(x). It's a work-a-round flag,
which helps im some cases to simulate the models e.g.
Modelica.Fluid.Examples.HeatExchanger.HeatExchangerSimulation."));
Modelica.Fluid.Examples.HeatExchanger.HeatExchangerSimulation.
Deprecated flag: Use --preOptModules+=introduceDerAlias instead."));
constant DebugFlag DISABLE_COMSUBEXP = DEBUG_FLAG(126, "disableComSubExp", false,
Util.gettext("Deactivates module 'comSubExp'"));
Util.gettext("Deactivates module 'comSubExp'\nDeprecated flag: Use --preOptModules-=comSubExp instead."));
constant DebugFlag NO_START_CALC = DEBUG_FLAG(127, "disableStartCalc", false,
Util.gettext("Deactivates the pre-calculation of start values during compile-time."));
constant DebugFlag NO_PARTITIONING = DEBUG_FLAG(128, "disablePartitioning", false,
Util.gettext("Deactivates partitioning of entire equation system."));
Util.gettext("Deactivates partitioning of entire equation system.\nDeprecated flag: Use --preOptModules-=clockPartitioning instead."));
constant DebugFlag ADVANCE_TEARING = DEBUG_FLAG(129, "advanceTearing", false,
Util.gettext("Using ExpressionSolve in adjacencyRowEnhanced"));
constant DebugFlag CONSTJAC = DEBUG_FLAG(130, "constjac", false,
Expand All @@ -443,7 +444,7 @@ constant DebugFlag RUNTIME_STATIC_LINKING = DEBUG_FLAG(137, "runtimeStaticLinkin
constant DebugFlag DYNAMIC_TEARING_INFO = DEBUG_FLAG(138, "dynamicTearingInfo", false,
Util.gettext("Dumps information about the strict and casual sets of the tearing system."));
constant DebugFlag SORT_EQNS_AND_VARS = DEBUG_FLAG(139, "sortEqnsAndVars", false,
Util.gettext("Heuristic sorting for equations and variables. Influenced: removeSimpleEquations and tearing."));
Util.gettext("Heuristic sorting for equations and variables. Influenced: removeSimpleEquations and tearing.\nDeprecated flag: Use --preOptModules+=sortEqnsVars instead."));
constant DebugFlag DUMP_SIMPLIFY_LOOPS = DEBUG_FLAG(140, "dumpSimplifyLoops", false,
Util.gettext("Dump between steps of simplifyLoops"));
constant DebugFlag DUMP_RTEARING = DEBUG_FLAG(141, "dumpRecursiveTearing", false,
Expand All @@ -453,7 +454,7 @@ constant DebugFlag DIS_SIMP_FUN = DEBUG_FLAG(142, "disableSimplifyComplexFunctio
constant DebugFlag DIS_SYMJAC_FMI20 = DEBUG_FLAG(143, "disableSymbolicLinearization", false,
Util.gettext("For FMI 2.0 only dependecy analysis will be perform."));
constant DebugFlag EVAL_ALL_PARAMS = DEBUG_FLAG(144, "evalAllParams", false,
Util.gettext("Evaluates all parameters in order to increase simulation speed."));
Util.gettext("Evaluates all parameters in order to increase simulation speed.\nDeprecated flag: Use --preOptModules+=evaluateAllParameters instead."));
constant DebugFlag EVAL_OUTPUT_ONLY = DEBUG_FLAG(145, "evalOutputOnly", false,
Util.gettext("Generates equations to calculate outputs only."));
constant DebugFlag HARDCODED_START_VALUES = DEBUG_FLAG(146, "hardcodedStartValues", false,
Expand Down Expand Up @@ -689,6 +690,7 @@ constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules",
"inlineArrayEqn",
"removeSimpleEquations",
"comSubExp",
"evalFunc",
"encapsulateWhenConditions"
}),
SOME(STRING_DESC_OPTION({
Expand Down

0 comments on commit 6c8bc92

Please sign in to comment.