Skip to content

Commit

Permalink
- Recommit r22962.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23489 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 20, 2014
1 parent 3667844 commit 20ffbea
Showing 1 changed file with 21 additions and 45 deletions.
66 changes: 21 additions & 45 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1443,9 +1443,9 @@ protected

partial function FuncType
input DAE.Exp inExp;
input tuple<DAE.FunctionTree, DAE.FunctionTree> inTuple;
input DAE.FunctionTree inUnsedFunctions;
output DAE.Exp outExp;
output tuple<DAE.FunctionTree, DAE.FunctionTree> outTuple;
output DAE.FunctionTree outUsedFunctions;
end FuncType;

FuncType func;
Expand All @@ -1457,15 +1457,15 @@ algorithm

usedfuncs := copyRecordConstructorAndExternalObjConstructorDestructor(funcs);

func := checkUnusedFunctionsTupleWrapper;
(_, usedfuncs) := List.fold1(eqs, BackendDAEUtil.traverseBackendDAEExpsEqSystem, func, (funcs, usedfuncs));
(_, usedfuncs) := List.fold1(eqs, BackendDAEUtil.traverseBackendDAEExpsEqSystemJacobians, func, (funcs, usedfuncs));
(_, usedfuncs) := BackendDAEUtil.traverseBackendDAEExpsVars(knvars, func, (funcs, usedfuncs));
(_, usedfuncs) := BackendDAEUtil.traverseBackendDAEExpsVars(exobj, func, (funcs, usedfuncs));
(_, usedfuncs) := BackendDAEUtil.traverseBackendDAEExpsVars(aliasVars, func, (funcs, usedfuncs));
(_, usedfuncs) := BackendDAEUtil.traverseBackendDAEExpsEqns(remeqns, func, (funcs, usedfuncs));
(_, usedfuncs) := BackendDAEUtil.traverseBackendDAEExpsEqns(inieqns, func, (funcs, usedfuncs));
(_, (_, usedfuncs)) := BackendDAETransform.traverseBackendDAEExpsWhenClauseLst(whenClauseLst, func, (funcs, usedfuncs));
func := function checkUnusedFunctions(inFunctions = funcs);
usedfuncs := List.fold1(eqs, BackendDAEUtil.traverseBackendDAEExpsEqSystem, func, usedfuncs);
usedfuncs := List.fold1(eqs, BackendDAEUtil.traverseBackendDAEExpsEqSystemJacobians, func, usedfuncs);
usedfuncs := BackendDAEUtil.traverseBackendDAEExpsVars(knvars, func, usedfuncs);
usedfuncs := BackendDAEUtil.traverseBackendDAEExpsVars(exobj, func, usedfuncs);
usedfuncs := BackendDAEUtil.traverseBackendDAEExpsVars(aliasVars, func, usedfuncs);
usedfuncs := BackendDAEUtil.traverseBackendDAEExpsEqns(remeqns, func, usedfuncs);
usedfuncs := BackendDAEUtil.traverseBackendDAEExpsEqns(inieqns, func, usedfuncs);
(_, usedfuncs) := BackendDAETransform.traverseBackendDAEExpsWhenClauseLst(whenClauseLst, func, usedfuncs);

//traverse Symbolic jacobians
usedfuncs := removeUnusedFunctionsSymJacs(symjacs, funcs, usedfuncs);
Expand Down Expand Up @@ -1541,43 +1541,17 @@ algorithm
end for;
end removeUnusedFunctionsSymJacs;

protected function checkUnusedFunctionsTupleWrapper
input DAE.Exp inExp;
input tuple<DAE.FunctionTree, DAE.FunctionTree> inTuple;
output DAE.Exp outExp;
output tuple<DAE.FunctionTree, DAE.FunctionTree> outTuple;
protected
DAE.FunctionTree funcs, used_funcs;
algorithm
(funcs, used_funcs) := inTuple;
(outExp, used_funcs) := checkUnusedFunctions(inExp, funcs, used_funcs);
outTuple := (funcs, used_funcs);
end checkUnusedFunctionsTupleWrapper;

protected function checkUnusedFunctions
input DAE.Exp inExp;
input DAE.FunctionTree inFunctions;
input DAE.FunctionTree inUsedFunctions;
output DAE.Exp outExp;
output DAE.FunctionTree outUsedFunctions;
algorithm
(outExp, (_, outUsedFunctions)) := Expression.traverseExp(inExp,
checkUnusedFunctionsExpTupleWrapper, (inFunctions, inUsedFunctions));
(outExp, outUsedFunctions) := Expression.traverseExp(inExp,
function checkUnusedFunctionsExp(inFunctions = inFunctions), inUsedFunctions);
end checkUnusedFunctions;

protected function checkUnusedFunctionsExpTupleWrapper
input DAE.Exp inExp;
input tuple<DAE.FunctionTree, DAE.FunctionTree> inTuple;
output DAE.Exp outExp;
output tuple<DAE.FunctionTree, DAE.FunctionTree> outTuple;
protected
DAE.FunctionTree funcs, used_funcs;
algorithm
(funcs, used_funcs) := inTuple;
(outExp, used_funcs) := checkUnusedFunctionsExp(inExp, funcs, used_funcs);
outTuple := (funcs, used_funcs);
end checkUnusedFunctionsExpTupleWrapper;

protected function checkUnusedFunctionsExp
input DAE.Exp inExp;
input DAE.FunctionTree inFunctions;
Expand Down Expand Up @@ -1605,8 +1579,8 @@ algorithm
// If it's a cref, check the cref's dimensions for function calls.
case DAE.CREF(componentRef = cr)
algorithm
(_, (_, usedfuncs)) := Expression.traverseExpCrefDims(cr,
checkUnusedFunctionsTupleWrapper, (inFunctions, inUsedFunctions));
(_, usedfuncs) := Expression.traverseExpCrefDims(cr,
function checkUnusedFunctions(inFunctions = inFunctions), inUsedFunctions);
then
usedfuncs;

Expand All @@ -1628,10 +1602,12 @@ algorithm
_ := DAEUtil.avlTreeGet(inUsedFunctions, inPath);
else // Otherwise, try to add it.
(f, body) := getFunctionAndBody(inPath, inFunctions);
if isNone(f) then return; end if; // Return if the function couldn't be found.
outUsedFunctions := DAEUtil.avlTreeAdd(outUsedFunctions, inPath, f);
(_, (_, outUsedFunctions)) := DAEUtil.traverseDAE2(body,
checkUnusedFunctionsTupleWrapper, (inFunctions, outUsedFunctions));

if isSome(f) then
outUsedFunctions := DAEUtil.avlTreeAdd(outUsedFunctions, inPath, f);
(_, outUsedFunctions) := DAEUtil.traverseDAE2(body,
function checkUnusedFunctions(inFunctions = inFunctions), outUsedFunctions);
end if;
end try;
end addUnusedFunction;

Expand Down

0 comments on commit 20ffbea

Please sign in to comment.