Skip to content

Commit

Permalink
some minor list optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Jul 7, 2016
1 parent 3405204 commit 1464a0d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
11 changes: 5 additions & 6 deletions Compiler/BackEnd/BackendInline.mo
Expand Up @@ -724,7 +724,7 @@ algorithm
if Flags.getConfigEnum(Flags.INLINE_METHOD) == 1 then
eqs := List.map1(eqs, BackendInline.inlineEquationSystem, tpl);
elseif Flags.getConfigEnum(Flags.INLINE_METHOD) == 2 then
eqs := List.map1(eqs, inlineEquationSystemAppend, (tpl,shared));
eqs := List.map2(eqs, inlineEquationSystemAppend, tpl, shared);
end if;
if Flags.isSet(Flags.DUMPBACKENDINLINE) then
BackendDump.dumpEqSystems(eqs, "Result DAE after Inline.");
Expand All @@ -750,22 +750,21 @@ end inlineCallsBDAE;

protected function inlineEquationSystemAppend
input BackendDAE.EqSystem eqs;
input tuple<Inline.Functiontuple,BackendDAE.Shared> tpl_shard;
input Inline.Functiontuple tpl;
input BackendDAE.Shared ishared;
output BackendDAE.EqSystem oeqs = eqs;
protected
BackendDAE.Shared shared = ishared;
BackendDAE.EqSystem new;
Boolean inlined=true;
BackendDAE.EquationArray eqnsArray;
BackendDAE.Shared shared;
Inline.Functiontuple tpl;
algorithm
(tpl, shared) := tpl_shard;
//inlineVariables(oeqs.orderedVars, tpl);
(eqnsArray, new, inlined, shared) := inlineEquationArrayAppend(oeqs.orderedEqs, tpl, shared);
//inlineEquationArray(oeqs.removedEqs, tpl);
if inlined then
oeqs.orderedEqs := eqnsArray;
new := inlineEquationSystemAppend(new, (tpl, shared));
new := inlineEquationSystemAppend(new, tpl, shared);
oeqs := BackendDAEUtil.mergeEqSystems(new, oeqs);
end if;
end inlineEquationSystemAppend;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/FindZeroCrossings.mo
Expand Up @@ -396,7 +396,7 @@ algorithm
(conditions, initialCall) = BackendDAEUtil.getConditionList(condition);
DoubleEndedList.push_list_front(vars, vars1);

if listEmpty(CheckModel.algorithmStatementListOutputs({DAE.STMT_WHEN(condition, conditions, initialCall, stmts1, NONE(), source)}, DAE.EXPAND())) then
if listEmpty(CheckModel.algorithmStatementListOutputs(stmts1, DAE.EXPAND())) then
// without outputs
(stmts, preStmts2, index) = encapsulateWhenConditions_Algorithms(rest, vars, index);
preStmts = listAppend(preStmts, preStmts2);
Expand Down
11 changes: 2 additions & 9 deletions Compiler/BackEnd/Matching.mo
Expand Up @@ -5734,12 +5734,9 @@ public function reachableEquations "author: lochel
output list<Integer> outEqNodes;
protected
Integer var;
list<Integer> reachable;
algorithm
var := ass2[eqn] "get the variable that is solved in given equation";
reachable := if var > 0 then mT[var] else {} "get the equations that depend on that variable";
reachable := List.select(reachable, Util.intGreaterZero) "just keep positive integers";
outEqNodes := List.removeOnTrue(eqn, intEq, reachable);
outEqNodes := if var > 0 then list(e for e guard(e > 0 and e <> eqn) in mT[var]) else {} "get the equations that depend on that variable";
end reachableEquations;

public function incomingEquations "author: lochel
Expand All @@ -5749,12 +5746,8 @@ public function incomingEquations "author: lochel
input BackendDAE.IncidenceMatrix m;
input array<Integer> ass1 "eqn := ass1[var]";
output list<Integer> outEqNodes;
protected
list<Integer> vars;
algorithm
vars := List.select(m[eqn], Util.intGreaterZero) "just keep positive integers";
outEqNodes := list(ass1[var] for var guard(ass1[var] > 0) in vars);
outEqNodes := List.removeOnTrue(eqn, intEq, outEqNodes);
outEqNodes := list(ass1[var] for var guard(var > 0 and ass1[var] <> eqn and ass1[var] > 0) in m[eqn]);
end incomingEquations;

public function isAssigned
Expand Down
14 changes: 7 additions & 7 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -5336,11 +5336,11 @@ The extra argument is a tuple of the actul function to call on each subexpressio
end FuncExpType;
protected
FuncExpType rel;
Type_a ext_arg;
Type_a ext_arg, ext_arg2;
algorithm
(rel,ext_arg) := itpl;
(outExp,ext_arg) := traverseExpBottomUp(inExp,rel,ext_arg);
otpl := (rel,ext_arg);
(outExp,ext_arg2) := traverseExpBottomUp(inExp,rel,ext_arg);
otpl := if referenceEq(ext_arg, ext_arg2) then itpl else (rel,ext_arg2);
end traverseSubexpressionsHelper;

public function traverseSubexpressionsDummyHelper
Expand Down Expand Up @@ -5377,11 +5377,11 @@ The extra argument is a tuple of the actual function to call on each subexpressi
end FuncExpType2;
protected
FuncExpType2 rel;
Type_a ext_arg;
Type_a ext_arg, ext_arg2;
algorithm
(rel,ext_arg) := itpl;
(outExp,ext_arg) := traverseExpTopDown(inExp,rel,ext_arg);
otpl := (rel,ext_arg);
(outExp,ext_arg2) := traverseExpTopDown(inExp,rel,ext_arg);
otpl := if referenceEq(ext_arg, ext_arg2) then itpl else (rel,ext_arg2);
end traverseSubexpressionsTopDownHelper;

protected function traverseExpMatrix
Expand Down Expand Up @@ -6706,7 +6706,7 @@ algorithm
case (DAE.CREF(cr,_),(func,arg))
equation
arg1 = func(cr,arg);
then (inExp, (func,arg1));
then (inExp, if referenceEq(arg, arg1) then inTpl else (func,arg1));

else (inExp,inTpl);

Expand Down
17 changes: 6 additions & 11 deletions Compiler/Script/Interactive.mo
Expand Up @@ -3944,7 +3944,7 @@ algorithm
matchcontinue (path,inProgram)
local
Absyn.Class cdef;
list<Absyn.Element> comps,comps_1;
list<Absyn.Element> comps;
list<list<Absyn.ComponentItem>> compelts;
list<Absyn.ComponentItem> compelts_1;
list<String> names;
Expand All @@ -3953,8 +3953,7 @@ algorithm
equation
cdef = getPathedClassInProgram(path, p);
comps = getComponentsInClass(cdef);
comps_1 = List.select(comps, isParameterElement);
compelts = List.map(comps_1, getComponentitemsInElement);
compelts = list(getComponentitemsInElement(c) for c guard isParameterElement(c) in comps);
compelts_1 = List.flatten(compelts);
names = List.map(compelts_1, getComponentitemName);
then
Expand Down Expand Up @@ -6285,22 +6284,18 @@ algorithm
case ((Absyn.MODIFICATION(path = p,modification = SOME(Absyn.CLASSMOD(args,Absyn.EQMOD()))) :: rest))
equation
name = Absyn.pathString(p);
names2 = getModificationNames(args);
names2_1 = List.map1r(names2, stringAppend, ".");
names2_2 = List.map1r(names2_1, stringAppend, name);
names2 = list(stringAppend(stringAppend(name, "."), n) for n in getModificationNames(args));
names = getModificationNames(rest);
res = listAppend(names2_2, names);
res = listAppend(names2, names);
then
name::res;
// modifier with submodifiers, e.g. m(...)
case ((Absyn.MODIFICATION(path = p,modification = SOME(Absyn.CLASSMOD(args,_))) :: rest))
equation
name = Absyn.pathString(p);
names2 = getModificationNames(args);
names2_1 = List.map1r(names2, stringAppend, ".");
names2_2 = List.map1r(names2_1, stringAppend, name);
names2 = list(stringAppend(stringAppend(name, "."), n) for n in getModificationNames(args));
names = getModificationNames(rest);
res = listAppend(names2_2, names);
res = listAppend(names2, names);
then
res;
case ((_ :: rest))
Expand Down

0 comments on commit 1464a0d

Please sign in to comment.