Skip to content

Commit

Permalink
- fix binary statistics of cse module
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24763 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Feb 25, 2015
1 parent 6e920f8 commit e96b610
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions Compiler/BackEnd/CommonSubExpression.mo
Expand Up @@ -93,21 +93,22 @@ algorithm
HashTableExpToIndex.HashTable HT2, HT3;

case BackendDAE.EQSYSTEM(orderedVars, orderedEqs, _, _, _, stateSets, partitionKind) equation
// BackendDump.dumpEquationList(eqList, "############## Equation-Liste: ###########");
// BackendDump.dumpVarList(varList, "############## Variablen-Liste: ###########");
// TODO: merge HT and HT2
//if Flags.isSet(Flags.DUMP_CSE) then
// BackendDump.dumpVariables(orderedVars, "########### Updated Variable List ###########");
// BackendDump.dumpEquationArray(orderedEqs, "########### Updated Equation List ###########");
//end if;
HT = HashTableExpToExp.emptyHashTableSized(49999); //2053 4013 25343 536870879
HT2 = HashTableExpToIndex.emptyHashTableSized(49999);
HT3 = HashTableExpToIndex.emptyHashTableSized(49999);
(HT, HT2, outStartIndex) = BackendEquation.traverseEquationArray(orderedEqs, foldEq, (HT, HT2, inStartIndex));
// BaseHashTable.dumpHashTable(HT);
// BaseHashTable.dumpHashTable(HT2);
//BaseHashTable.dumpHashTable(HT);
//BaseHashTable.dumpHashTable(HT2);
(orderedEqs, (HT, HT2, _, eqList, varList)) = BackendEquation.traverseEquationArray_WithUpdate(orderedEqs, foldEq2, (HT, HT2, HT3, {}, {}));
orderedEqs = BackendEquation.addEquations(eqList, orderedEqs);
orderedVars = BackendVariable.addVars(varList, orderedVars);
if Flags.isSet(Flags.DUMP_CSE) then
BackendDump.dumpEquationArray(orderedEqs, "########### Updated Equation List: #########");
BackendDump.dumpVariables(orderedVars, "########### Updated Variable List: #########");
BackendDump.dumpEquationArray(orderedEqs, "########### Updated Equation List ###########");
BackendDump.dumpVariables(orderedVars, "########### Updated Variable List ###########");
end if;
then BackendDAE.EQSYSTEM(orderedVars, orderedEqs, NONE(), NONE(), BackendDAE.NO_MATCHING(), stateSets, partitionKind);

Expand Down Expand Up @@ -272,8 +273,7 @@ algorithm

else equation
if Flags.isSet(Flags.DUMP_CSE_VERBOSE) then
print("\n");
BackendDump.printEquation(inEq);
print("traverse " + BackendDump.equationString(inEq) + "\n");
end if;
(eq, tpl) = BackendEquation.traverseExpsOfEquation(inEq, traverseExpsEquation_1, inTuple);
then (eq, tpl);
Expand Down Expand Up @@ -306,7 +306,7 @@ algorithm
HashTableExpToIndex.HashTable HT2;
list<BackendDAE.Equation> eqList;
list<BackendDAE.Var> varList;
Integer i, value2;
Integer i, counter;
String str;
DAE.ComponentRef cr;
BackendDAE.Var var;
Expand All @@ -318,12 +318,17 @@ algorithm
if checkOp(op) then
if BaseHashTable.hasKey(inExp, HT) then
value = BaseHashTable.get(inExp, HT);
value2 = BaseHashTable.get(value, HT2);
HT2 = BaseHashTable.update((value, value2 + 1), HT2);
counter = BaseHashTable.get(value, HT2);
HT2 = BaseHashTable.update((value, counter + 1), HT2);

if commutativeBinaryExp(op) then
value = BaseHashTable.get(DAE.BINARY(exp2, op, exp1), HT);
HT2 = BaseHashTable.update((value, counter + 1), HT2);
end if;
else
str = "$cse" + intString(i);
cr = DAE.CREF_IDENT(str, DAE.T_REAL_DEFAULT, {});
value = DAE.CREF(cr, DAE.T_REAL_DEFAULT);
cr = DAE.CREF_IDENT(str, Expression.typeof(inExp), {});
value = DAE.CREF(cr, Expression.typeof(inExp));
HT = BaseHashTable.add((inExp, value), HT);
HT2 = BaseHashTable.add((value, 1), HT2);
if commutativeBinaryExp(op) then
Expand All @@ -334,9 +339,9 @@ algorithm
end if;
then (inExp, true, (HT, HT2, i));

// skip some kinds of expressions
case (DAE.IFEXP(), _)
then (inExp, false, inTuple);

case (DAE.CALL(path=Absyn.IDENT("der")), _)
then (inExp, false, inTuple);
case (DAE.CALL(path=Absyn.IDENT("smooth")), _)
Expand All @@ -350,10 +355,10 @@ algorithm
true = Flags.getConfigBool(Flags.CSE_CALL) or Flags.getConfigBool(Flags.CSE_EACHCALL);
if BaseHashTable.hasKey(inExp, HT) then
value = BaseHashTable.get(inExp, HT);
value2 = BaseHashTable.get(value, HT2) + 1;
HT2 = BaseHashTable.update((value, value2), HT2);
counter = BaseHashTable.get(value, HT2) + 1;
HT2 = BaseHashTable.update((value, counter), HT2);
if Flags.isSet(Flags.DUMP_CSE_VERBOSE) then
print("Found CSE Expression (count: " + intString(value2) + "): " + ExpressionDump.printExpStr(inExp) + " \n");
print("Found CSE Expression (count: " + intString(counter) + "): " + ExpressionDump.printExpStr(inExp) + " \n");
end if;
else
(value, i) = createReturnExp(tp, i);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/Flags.mo
Expand Up @@ -634,7 +634,7 @@ constant ConfigFlag PRE_OPT_MODULES = CONFIG_FLAG(12, "preOptModules",
"evalFunc"
}),
SOME(STRING_DESC_OPTION({
//("CSE", Util.gettext("Common SubExpression Elimination")),
("CSE", Util.gettext("Common Subexpression Elimination")),
("unitChecking", Util.gettext("advanced unit checking: 1. calculation of unspecified unit information for variables; 2. unit consistency check for equations")),
("removeSimpleEquations", removeSimpleEquationDesc),
("removeAllSimpleEquations", removeSimpleEquationDesc),
Expand Down Expand Up @@ -762,7 +762,7 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("calculateStateSetsJacobians", Util.gettext("Generates analytical jacobian for dynamic state selection sets.")),
("addInitialStmtsToAlgorithms", Util.gettext("Expands all algorithms with initial statements for outputs.")),
("reshufflePost", Util.gettext("Reshuffles algebraic loops.")),
("CSE", Util.gettext("Common SubExpression Elimination"))
("CSE", Util.gettext("Common Subexpression Elimination"))
})),
Util.gettext("Sets the post optimization modules to use in the back end. See --help=optmodules for more info."));

Expand Down

0 comments on commit e96b610

Please sign in to comment.