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

Commit

Permalink
wrapFunctionCalls is activated and add configFlag --wfcAdvanced to sk…
Browse files Browse the repository at this point in the history
…ip more than default cases
  • Loading branch information
jhag authored and OpenModelica-Hudson committed Jan 9, 2017
1 parent e7c76f7 commit e3ba94b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
41 changes: 31 additions & 10 deletions Compiler/BackEnd/CommonSubExpression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -462,29 +462,29 @@ algorithm
(HT, exarray, cseIndex, index, functionTree) := inTuple;

_ := match(inEq)
case BackendDAE.COMPLEX_EQUATION(left=lhs, right=rhs) equation
case BackendDAE.COMPLEX_EQUATION(left=lhs, right=rhs) algorithm
if debug then
BackendDump.dumpEquationList({inEq}, "wrapFunctionCalls_analysis (COMPLEX_EQUATION)");
end if;

// TUPLE = CALL
if isCallAndTuple(lhs, rhs) then
(cref, call) = getTheRightPattern(lhs, rhs);
(cref, call) := getTheRightPattern(lhs, rhs);
if BaseHashTable.hasKey(call, HT) then
exIndex = BaseHashTable.get(call, HT);
cseEquation = ExpandableArray.get(exIndex, exarray);
exIndex := BaseHashTable.get(call, HT);
cseEquation := ExpandableArray.get(exIndex, exarray);
//print("cref1: " + ExpressionDump.printExpStr(cseEquation.cse) + "\n");
//print("cref2: " + ExpressionDump.printExpStr(cref) + "\n");
cseEquation.cse = mergeCSETuples(cseEquation.cse, cref);
exarray = ExpandableArray.update(exIndex, cseEquation, exarray);
cseEquation.cse := mergeCSETuples(cseEquation.cse, cref);
exarray := ExpandableArray.update(exIndex, cseEquation, exarray);
elseif not isSkipCase(call, functionTree) then
index = index + 1;
HT = BaseHashTable.add((call, index), HT);
exarray = ExpandableArray.set(index, CSE_EQUATION(cref, call, {}), exarray);
index := index + 1;
HT := BaseHashTable.add((call, index), HT);
exarray := ExpandableArray.set(index, CSE_EQUATION(cref, call, {}), exarray);
end if;
end if;

(_, (HT, exarray, cseIndex, index, functionTree)) = BackendEquation.traverseExpsOfEquation(inEq, wrapFunctionCalls_analysis2, (HT, exarray, cseIndex, index, functionTree));
(_, (HT, exarray, cseIndex, index, functionTree)) := BackendEquation.traverseExpsOfEquation(inEq, wrapFunctionCalls_analysis2, (HT, exarray, cseIndex, index, functionTree));
then ();

case BackendDAE.EQUATION(exp=lhs, scalar=rhs) algorithm
Expand Down Expand Up @@ -868,10 +868,31 @@ algorithm
case DAE.CALL(path=Absyn.IDENT("noClock")) then true;
case DAE.CALL(path=Absyn.IDENT("sign")) then true;
case DAE.CALL() guard(Expression.isImpureCall(inCall) or isCallRecordConstructor(inCall, functionTree)) then true;
case DAE.CALL() guard(Flags.getConfigBool(Flags.WFC_ADVANCED)) then isSkipCase_advanced(inCall);
else false;
end match;
end isSkipCase;

protected function isSkipCase_advanced
input DAE.Exp inCall;
output Boolean outB;
algorithm
outB := match(inCall)
local
Absyn.Path path;
case DAE.CALL(path=Absyn.IDENT("abs")) then true;
case DAE.CALL(path=Absyn.IDENT("sin")) then true;
case DAE.CALL(path=Absyn.IDENT("cos")) then true;
case DAE.CALL(path=Absyn.IDENT("log")) then true;
case DAE.CALL(path=Absyn.IDENT("exp")) then true;
case DAE.CALL(path=Absyn.IDENT("tan")) then true;
case DAE.CALL(path=Absyn.IDENT("sinh")) then true;
case DAE.CALL(path=Absyn.IDENT("cosh")) then true;
case DAE.CALL(path=Absyn.IDENT("tanh")) then true;
else false;
end match;
end isSkipCase_advanced;

protected function isCallRecordConstructor
//DAEUtil.funcIsRecord(DAEUtil.getNamedFunction(path, functionTree))
input DAE.Exp inExp;
Expand Down
7 changes: 6 additions & 1 deletion Compiler/Util/Flags.mo
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ constant ConfigFlag INDEX_REDUCTION_METHOD = CONFIG_FLAG(15, "indexReductionMeth
constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
NONE(), EXTERNAL(), STRING_LIST_FLAG({
"lateInlineFunction",
"wrapFunctionCalls",
"inlineArrayEqn",
"constantLinearSystem",
"simplifysemiLinear",
Expand Down Expand Up @@ -1333,6 +1334,9 @@ constant ConfigFlag REPLACE_EVALUATED_PARAMS = CONFIG_FLAG(109, "replaceEvaluate
constant ConfigFlag CONDENSE_ARRAYS = CONFIG_FLAG(110, "condenseArrays",
NONE(), EXTERNAL(), BOOL_FLAG(true), NONE(),
Util.gettext("Sets whether array expressions containing function calls are condensed or not."));
constant ConfigFlag WFC_ADVANCED = CONFIG_FLAG(111, "wfcAdvanced",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("wrapFunctionCalls ignores more then default cases, e.g. exp, sin, cos, log, (experimental flag)"));

protected
// This is a list of all configuration flags. A flag can not be used unless it's
Expand Down Expand Up @@ -1448,7 +1452,8 @@ constant list<ConfigFlag> allConfigFlags = {
EVALUATE_FINAL_PARAMS,
EVALUATE_PROTECTED_PARAMS,
REPLACE_EVALUATED_PARAMS,
CONDENSE_ARRAYS
CONDENSE_ARRAYS,
WFC_ADVANCED
};

public function new
Expand Down

0 comments on commit e3ba94b

Please sign in to comment.