Skip to content

Commit

Permalink
try to reduce memory usage
Browse files Browse the repository at this point in the history
- use listReverseInPlace where possible
- remove some recursions and matchcontinue
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Mar 4, 2016
1 parent cc074b4 commit 8abe1ff
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 282 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -102,7 +102,7 @@ algorithm
else eq::removedEqsList;
end match;
end for;
shared.removedEqs := BackendEquation.listEquation(listReverse(removedEqsList));
shared.removedEqs := BackendEquation.listEquation(MetaModelica.Dangerous.listReverseInPlace(removedEqsList));
outDAE.shared := shared;
end simplifyAllExpressions;

Expand Down Expand Up @@ -4291,7 +4291,7 @@ algorithm
end if;
expLst := e :: expLst;
end for; // lhs
left := DAE.TUPLE(listReverse(expLst));
left := DAE.TUPLE(MetaModelica.Dangerous.listReverseInPlace(expLst));
eqn := BackendDAE.COMPLEX_EQUATION(size, left, right, source, attr);
eqns := BackendEquation.setAtIndex(eqns, i, eqn);
end if; // lhs <-> rhs
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -161,7 +161,7 @@ algorithm
outComps := acomp :: outComps;
end for;

outComps := listReverse(outComps);
outComps := MetaModelica.Dangerous.listReverseInPlace(outComps);
end analyseStrongComponentsScalar;

protected function analyseStrongComponentScalar "author: Frenkel TUD 2011-05"
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -597,7 +597,7 @@ algorithm
outEquations := eq::outEquations;
end for;

outEquations := listReverse(outEquations);
outEquations := MetaModelica.Dangerous.listReverseInPlace(outEquations);
end traverseExpsOfEquationList;

public function traverseExpsOfEquationList_WithStop "author: Frenkel TUD 2012-09
Expand Down Expand Up @@ -1095,7 +1095,7 @@ algorithm
outExpl := e :: outExpl;
end for;

outExpl := listReverse(outExpl);
outExpl := MetaModelica.Dangerous.listReverseInPlace(outExpl);
end traverseExpsOfExpList;

protected function traverseExpsOfExpList_WithStop<T> "author Frenkel TUD
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/CommonSubExpression.mo
Expand Up @@ -111,7 +111,7 @@ algorithm

eqs := syst::eqs;
end for;
eqs := listReverse(eqs);
eqs := MetaModelica.Dangerous.listReverseInPlace(eqs);

System.tmpTickSetIndex(index, Global.backendDAE_cseIndex);
outDAE := BackendDAE.DAE(eqs, shared);
Expand Down
13 changes: 6 additions & 7 deletions Compiler/BackEnd/Differentiate.mo
Expand Up @@ -2595,17 +2595,16 @@ algorithm
tp = DAEUtil.getFunctionType(func);
dtp = Types.extendsFunctionTypeArgs(tp, inputVarsDer, outputVarsDer, blst);

inputVars = listAppend(inputVars, inputVarsDer);
protectedVars = listAppend(protectedVars, protectedVarsDer);
funcbodyDer = listAppend(inputVars, outputVarsDer);
funcbodyDer = listAppend(funcbodyDer, protectedVars);

//change output vars to protected vars and direction bidir
newProtectedVars = List.map1(outputVars, DAEUtil.setElementVarVisibility, DAE.PROTECTED());
newProtectedVars = List.map1(newProtectedVars, DAEUtil.setElementVarDirection, DAE.BIDIR());
funcbodyDer = listAppend(funcbodyDer, newProtectedVars);

funcbodyDer = listAppend(funcbodyDer, {DAE.ALGORITHM(DAE.ALGORITHM_STMTS(derbodyStmts), DAE.emptyElementSource)});
funcbodyDer = listAppend(newProtectedVars, {DAE.ALGORITHM(DAE.ALGORITHM_STMTS(derbodyStmts), DAE.emptyElementSource)});
funcbodyDer = listAppend(protectedVarsDer, funcbodyDer);
funcbodyDer = listAppend(protectedVars, funcbodyDer);
funcbodyDer = listAppend(outputVarsDer, funcbodyDer);
funcbodyDer = listAppend(inputVarsDer, funcbodyDer);
funcbodyDer = listAppend(inputVars, funcbodyDer);

isImpure = DAEUtil.getFunctionImpureAttribute(func);
dinl = DAEUtil.getFunctionInlineType(func);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/EvaluateFunctions.mo
Expand Up @@ -1053,7 +1053,7 @@ algorithm
//print("scalars to check\n"+stringDelimitList(List.map(scalars,ComponentReference.printComponentRefStr),"\n")+"\n");

false = listEmpty(scalars);
(constVars,_,_) = List.intersection1OnTrue(scalars,constCrefs,ComponentReference.crefEqual);
constVars = List.intersectionOnTrue(scalars,constCrefs,ComponentReference.crefEqual);
//print("constVars\n"+stringDelimitList(List.map(constVars,ComponentReference.printComponentRefStr),"\n")+"\n");

const = intEq(listLength(scalars),listLength(constVars));
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/EvaluateParameter.mo
Expand Up @@ -1210,7 +1210,7 @@ algorithm
sys.removedEqs := remEqsSys;
systs2 := sys::systs2;
end for;
systs2 := listReverse(systs2);
systs2 := MetaModelica.Dangerous.listReverseInPlace(systs2);
// replace all init eqs, removed eqs, external var-bindings and alias var bindings, event-infos
initEqs := shared.initialEqs;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -1297,7 +1297,7 @@ algorithm
osysts := syst :: osysts;
end if;
end for;
osysts := listReverse(osysts);
osysts := MetaModelica.Dangerous.listReverseInPlace(osysts);
end mapdynamicStateSelection;

protected function dynamicStateSelectionWork
Expand Down

0 comments on commit 8abe1ff

Please sign in to comment.