Skip to content

Commit

Permalink
- Made sure all arguments of a METARECORDCALL are boxed
Browse files Browse the repository at this point in the history
- Started sharing metarecord literals (30000 more constants shared for Main.main, up from 10000)
  - Some functions using large constants (such as Error.lookupMessage) now have 500 less malloc calls, which should result in a performance improvement


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7556 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 23, 2010
1 parent 809f69e commit 3f9e83c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
20 changes: 11 additions & 9 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -795,7 +795,7 @@ public function generateModelCodeFMU
algorithm
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
(libs, includes, recordDecls, functions, outIndexedBackendDAE, dae2) :=
createFunctions(program, dae, indexedBackendDAE, functionTree, className);
createFunctions(dae, indexedBackendDAE, functionTree, className);
simCode := createSimCode(functionTree, outIndexedBackendDAE, equationIndices,
variableIndices, incidenceMatrix, incidenceMatrixT, strongComponents,
className, filenamePrefix, fileDir, functions, includes, libs, simSettingsOpt, recordDecls);
Expand Down Expand Up @@ -933,7 +933,7 @@ public function generateModelCode
algorithm
System.realtimeTick(CevalScript.RT_CLOCK_BUILD_MODEL);
(libs, includes, recordDecls, functions, outIndexedBackendDAE, _) :=
createFunctions(program, dae, indexedBackendDAE, functionTree, className);
createFunctions(dae, indexedBackendDAE, functionTree, className);
simCode := createSimCode(functionTree, outIndexedBackendDAE, equationIndices,
variableIndices, incidenceMatrix, incidenceMatrixT, strongComponents,
className, filenamePrefix, fileDir, functions, includes, libs, simSettingsOpt, recordDecls);
Expand Down Expand Up @@ -1067,7 +1067,7 @@ algorithm
// Create FunctionCode
(daeElements,(_,(_,_,literals))) = DAEUtil.traverseDAEFunctions(daeMainFunction::daeElements,Expression.traverseSubexpressionsHelper,(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(24971),{})));
literals = listReverse(literals);
(mainFunction::fns, extraRecordDecls, includes, libs) = elaborateFunctions(daeElements, metarecordTypes);
(mainFunction::fns, extraRecordDecls, includes, libs) = elaborateFunctions(daeElements, metarecordTypes, literals);
checkValidMainFunction(name, mainFunction);
makefileParams = createMakefileParams(libs);
fnCode = FUNCTIONCODE(name, mainFunction, fns, literals, includes, makefileParams, extraRecordDecls);
Expand Down Expand Up @@ -1219,6 +1219,7 @@ algorithm
case DAE.CONS(car = e1, cdr = e2) equation isLiteralExp(e1); isLiteralExp(e2); then ();
case DAE.LIST(valList = expl) equation Util.listMap0(expl,isLiteralExp); then ();
case DAE.META_TUPLE(expl) equation Util.listMap0(expl,isLiteralExp); then ();
case DAE.METARECORDCALL(args=expl) equation Util.listMap0(expl,isLiteralExp); then ();
case DAE.SHARED_LITERAL(index=_) then ();
else fail();
end match;
Expand Down Expand Up @@ -1266,7 +1267,6 @@ end isFunctionPtr;
/* Finds the called functions in BackendDAE and transforms them to a list of
libraries and a list of Function uniontypes. */
public function createFunctions
input SCode.Program inProgram;
input DAE.DAElist inDAElist;
input BackendDAE.BackendDAE inBackendDAE;
input DAE.FunctionTree functionTree;
Expand All @@ -1279,7 +1279,7 @@ public function createFunctions
output DAE.DAElist outDAE;
algorithm
(libs, includes, recordDecls, functions, outBackendDAE, outDAE) :=
matchcontinue (inProgram,inDAElist,inBackendDAE,functionTree,inPath)
matchcontinue (inDAElist,inBackendDAE,functionTree,inPath)
local
list<Absyn.Path> funcPaths, funcRefPaths, funcNormalPaths;
list<String> debugpathstrs,libs1,libs2,includes1,includes2;
Expand All @@ -1293,7 +1293,7 @@ algorithm
SimCode sc;
DAE.FunctionTree funcs;

case (p,dae,dlow,functionTree,path)
case (dae,dlow,functionTree,path)
equation
// get all the used functions from the function tree
funcelems = DAEUtil.getFunctionList(functionTree);
Expand All @@ -1306,10 +1306,10 @@ algorithm
funcelems = Inline.inlineCallsInFunctions(funcelems,(NONE(),{DAE.NORM_INLINE(), DAE.AFTER_INDEX_RED_INLINE()}));
//Debug.fprintln("info", "Generating functions, call Codegen.\n") "debug" ;
(includes1, libs1) = generateExternalObjectIncludes(dlow);
(fns, recordDecls, includes2, libs2) = elaborateFunctions(funcelems, {}); // Do we need metarecords here as well?
(fns, recordDecls, includes2, libs2) = elaborateFunctions(funcelems, {}, {}); // Do we need metarecords here as well?
then
(Util.listUnion(libs1,libs2), Util.listUnion(includes1,includes2), recordDecls, fns, dlow, dae);
case (_,_,_,_,_)
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"Creation of Modelica functions failed. "});
then
Expand Down Expand Up @@ -1386,6 +1386,7 @@ end generateExternalObjectInclude;
protected function elaborateFunctions
input list<DAE.Function> daeElements;
input list<DAE.Type> metarecordTypes;
input list<DAE.Exp> literals;
output list<Function> functions;
output list<RecordDeclaration> extraRecordDecls;
output list<String> includes;
Expand All @@ -1394,7 +1395,8 @@ protected function elaborateFunctions
list<Function> fns;
list<String> outRecordTypes;
algorithm
(functions, outRecordTypes, extraRecordDecls, includes, libs) := elaborateFunctions2(daeElements,{},{},{},{},{});
(extraRecordDecls, outRecordTypes) := elaborateRecordDeclarationsForMetarecords(literals,{},{});
(functions, outRecordTypes, extraRecordDecls, includes, libs) := elaborateFunctions2(daeElements,{},outRecordTypes,extraRecordDecls,{},{});
(extraRecordDecls,_) := elaborateRecordDeclarationsFromTypes(metarecordTypes, extraRecordDecls, outRecordTypes);
end elaborateFunctions;

Expand Down
6 changes: 4 additions & 2 deletions Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -1012,8 +1012,10 @@ algorithm
case (Values.RECORD(path,vallist,namelst,ix))
equation
true = ix >= 0;
expl=Util.listMap(vallist,valueExp);
then DAE.METARECORDCALL(path,expl,namelst,ix);
explist = Util.listMap(vallist, valueExp);
typelist = Util.listMap(vallist, Types.typeOfValue);
(explist,_) = Types.matchTypeTuple(explist, typelist, Util.listMap(typelist, Types.boxIfUnboxedType), true);
then DAE.METARECORDCALL(path,explist,namelst,ix);

case (Values.META_FAIL())
then DAE.CALL(Absyn.IDENT("fail"),{},false,false,DAE.ET_OTHER(),DAE.NO_INLINE());
Expand Down
10 changes: 8 additions & 2 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -5540,7 +5540,7 @@ match exp
case exp as BOX(__) then
let ty = expTypeFromExpShort(exp.exp)
let res = daeExp(exp.exp,context,&preExp,&varDecls)
'mmc_mk_<%ty%>(<%res%>) /* <%printExpStr(exp)%> */'
'mmc_mk_<%ty%>(<%res%>)'
end daeExpBox;

template daeExpUnbox(Exp exp, Context context, Text &preExp /*BUFP*/, Text &varDecls /*BUFP*/)
Expand Down Expand Up @@ -6111,7 +6111,7 @@ template literalExpConst(Exp lit, Integer index) "These should all be declared s
<<
#define <%name%>_data "<%escstr%>"
static const size_t <%name%>_strlen = <%stringLength(escstr)%>;
static const char <%name%>[<%stringLength(string)%>+1] = <%name%>_data;
static const char <%name%>[<%intAdd(1,stringLength(string))%>] = <%name%>_data;
static const MMC_DEFSTRINGLIT(<%tmp%>,<%name%>_strlen,<%name%>_data);
<%meta%>_mmc = MMC_REFSTRINGLIT(<%tmp%>);
>>
Expand Down Expand Up @@ -6156,6 +6156,12 @@ template literalExpConst(Exp lit, Integer index) "These should all be declared s
static const MMC_DEFSTRUCTLIT(<%tmp%>,1,1) {<%literalExpConstBoxedVal(exp)%>}};
<%meta%> = MMC_REFSTRUCTLIT(<%tmp%>);
>>
case METARECORDCALL(__) then
let newIndex = intAdd(index, 3)
<<
static const MMC_DEFSTRUCTLIT(<%tmp%>,<%intAdd(1,listLength(args))%>,<%newIndex%>) {&<%underscorePath(path)%>__desc,<%args |> exp => literalExpConstBoxedVal(exp); separator=","%>}};
<%meta%> = MMC_REFSTRUCTLIT(<%tmp%>);
>>
else '<%\n%>#error "literalExpConst failed: <%printExpStr(lit)%>"<%\n%>'
end literalExpConst;

Expand Down

0 comments on commit 3f9e83c

Please sign in to comment.