Skip to content

Commit

Permalink
Don't remove functions that are passed through CREF in the backend (p…
Browse files Browse the repository at this point in the history
…artially evaluated functions use it)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21318 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 28, 2014
1 parent 2168702 commit aadb80d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 57 deletions.
22 changes: 17 additions & 5 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1578,8 +1578,7 @@ algorithm
case ((e as DAE.CALL(path = path),(func,usefuncs)))
equation
_ = DAEUtil.avlTreeGet(usefuncs, path);
then
((e, (func,usefuncs)));
then inTuple;

// add it
case ((e as DAE.CALL(path = path),(func,usefuncs)))
Expand All @@ -1591,12 +1590,25 @@ algorithm
then
((e, (func,usefuncs2)));

case ((e as DAE.CREF(ty = DAE.T_FUNCTION_REFERENCE_FUNC(functionType=DAE.T_FUNCTION(source={path}))),(func,usefuncs)))
equation
_ = DAEUtil.avlTreeGet(usefuncs, path);
then inTuple;

case ((e as DAE.CREF(ty = DAE.T_FUNCTION_REFERENCE_FUNC(functionType=DAE.T_FUNCTION(source={path}))),(func,usefuncs)))
equation
(f,body) = getFunctionAndBody(path,func);
usefuncs1 = DAEUtil.avlTreeAdd(usefuncs, path, f);
// print("add function " +& Absyn.pathStringNoQual(path) +& "\n");
(_,(_,usefuncs2)) = DAEUtil.traverseDAE2(body,checkUnusedFunctions,(func,usefuncs1));
then
((e, (func,usefuncs2)));

// already there
case ((e as DAE.PARTEVALFUNCTION(path = path),(func,usefuncs)))
equation
_ = DAEUtil.avlTreeGet(usefuncs, path);
then
((e, (func,usefuncs)));
then inTuple;

// add it
case ((e as DAE.PARTEVALFUNCTION(path = path),(func,usefuncs)))
Expand All @@ -1607,7 +1619,7 @@ algorithm
then
((e, (func,usefuncs1)));

case _ then inTuple;
else inTuple;
end matchcontinue;
end checkUnusedFunctionsExp;

Expand Down
53 changes: 1 addition & 52 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -520,31 +520,6 @@ algorithm
end matchcontinue;
end createFunctions;

public function getCalledFunctionReferences
"Goes through the BackendDAE structure, finds all function references calls,
and returns them in a list. Removes duplicates."
input DAE.DAElist dae;
input BackendDAE.BackendDAE dlow;
output list<Absyn.Path> res;
protected
list<DAE.Exp> explist, fcallexps;
list<Absyn.Path> calledfuncs;
algorithm
res := matchcontinue(dae, dlow)
case (_, _)
equation
false = Config.acceptMetaModelicaGrammar();
then {};
case (_, _)
equation
true = Config.acceptMetaModelicaGrammar();
fcallexps = BackendDAEUtil.traverseBackendDAEExps(dlow, matchFnRefs, {});
calledfuncs = List.map(fcallexps, getCallPath);
res = removeDuplicatePaths(calledfuncs);
then res;
end matchcontinue;
end getCalledFunctionReferences;

protected function orderRecordDecls
input SimCode.RecordDeclaration decl1;
input SimCode.RecordDeclaration decl2;
Expand Down Expand Up @@ -8411,7 +8386,7 @@ algorithm
els = DAEUtil.getFunctionElements(funcelem);
// SimCode.Function reference variables are filtered out
varfuncs = List.fold(els, DAEUtil.collectFunctionRefVarPaths, {});
(_, (_, varfuncs)) = DAEUtil.traverseDAE2(Util.if_(Config.acceptMetaModelicaGrammar(), els, {}), Expression.traverseSubexpressionsHelper, (DAEUtil.collectValueblockFunctionRefVars, varfuncs));
(_, (_, varfuncs)) = DAEUtil.traverseDAE2(els, Expression.traverseSubexpressionsHelper, (DAEUtil.collectValueblockFunctionRefVars, varfuncs));
(_, (_, (calledfuncs, _))) = DAEUtil.traverseDAE2(els, Expression.traverseSubexpressionsHelper, (matchNonBuiltinCallsAndFnRefPaths, ({}, varfuncs)));
ht = BaseHashTable.add((pathstr, path), ht);
ht = addDestructor(funcelem, ht);
Expand Down Expand Up @@ -9292,32 +9267,6 @@ algorithm
end matchcontinue;
end generateExtFunctionDynamicLoad;

protected function matchFnRefs "Used together with getMatchingExps"
input tuple<DAE.Exp, list<DAE.Exp>> itpl;
output tuple<DAE.Exp, list<DAE.Exp>> otpl;
algorithm
otpl := matchcontinue itpl
local
DAE.Exp e, e2;
list<DAE.Exp> acc;
DAE.ComponentRef cref;
Absyn.Path p;
DAE.Type ty;

case ((e as DAE.CREF(ty = DAE.T_FUNCTION_REFERENCE_FUNC(builtin = false)), acc)) then ((e, e::acc));

case ((e as DAE.PARTEVALFUNCTION(ty = ty as DAE.T_FUNCTION_REFERENCE_VAR(source = _), path=p), acc))
equation
cref = ComponentReference.pathToCref(p);
e2 = Expression.makeCrefExp(cref, ty);
then
((e, e2::acc));

else itpl;

end matchcontinue;
end matchFnRefs;

public function getImplicitRecordConstructors
"If a record instance is sent to a function we need to generate code for the
record constructor even if it's not explicitly called, because the constructor
Expand Down

0 comments on commit aadb80d

Please sign in to comment.