Skip to content

Commit

Permalink
Added code to make separate compilation use dummy .stamp files instea…
Browse files Browse the repository at this point in the history
…d of updating C-code.

By comparing the generated code to the old, we only re-compile files that actually changed.
Added new debug-flag to be able to turn off function inlining (made separate compilation non-deterministic).


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16893 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 22, 2013
1 parent 291270c commit 18e300f
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 111 deletions.
14 changes: 14 additions & 0 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,19 @@ algorithm
end matchcontinue;
end getCalledFunctionReferences;

protected function orderRecordDecls
input SimCode.RecordDeclaration decl1;
input SimCode.RecordDeclaration decl2;
output Boolean b;
algorithm
b := match (decl1,decl2)
local
Absyn.Path path1,path2;
case (SimCode.RECORD_DECL_DEF(path=path1),SimCode.RECORD_DECL_DEF(path=path2)) then Absyn.pathGe(path1,path2);
else true;
end match;
end orderRecordDecls;

public function elaborateFunctions
input Absyn.Program program;
input list<DAE.Function> daeElements;
Expand All @@ -608,6 +621,7 @@ algorithm
(extraRecordDecls, outRecordTypes) := elaborateRecordDeclarationsForMetarecords(literals, {}, {});
(functions, outRecordTypes, extraRecordDecls, outIncludes, includeDirs, libs) := elaborateFunctions2(program, daeElements, {}, outRecordTypes, extraRecordDecls, includes, {}, {});
(extraRecordDecls, _) := elaborateRecordDeclarationsFromTypes(metarecordTypes, extraRecordDecls, outRecordTypes);
extraRecordDecls := List.sort(extraRecordDecls, orderRecordDecls);
end elaborateFunctions;

protected function elaborateFunctions2
Expand Down
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ public uniontype InlineType
record NORM_INLINE "Normal inline, inline as soon as possible"
end NORM_INLINE;

record BUILTIN_EARLY_INLINE "Inline even if inlining is globally disabled by flags."
end BUILTIN_EARLY_INLINE;

record EARLY_INLINE "Inline even earlier than NORM_INLINE. This will display the inlined code in the flattened model and also works for functions calling other functions that should be inlined."
end EARLY_INLINE;

Expand Down
13 changes: 7 additions & 6 deletions Compiler/FrontEnd/DAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4602,12 +4602,13 @@ Function for converting a InlineType to a bool.
Whether the inline takes place before or after index reduction does not mather.
Any kind of inline will result in true.
"
input DAE.InlineType it;
output Boolean b;
algorithm b := matchcontinue(it)
case(DAE.NO_INLINE()) then false;
case(_) then true;
end matchcontinue;
input DAE.InlineType it;
output Boolean b;
algorithm
b := match (it)
case DAE.NO_INLINE() then false;
else true;
end match;
end convertInlineTypeToBool;

public function daeElements "Retrieve the elements from a DAEList"
Expand Down
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/Inline.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,13 @@ algorithm
Boolean generateEvents;
Option<SCode.Comment> comment;

/* If we disable inlining by use of flags, we still inline builtin functions */
case ((DAE.CALL(attr=DAE.CALL_ATTR(inlineType=inlineType)),_))
equation
false = Flags.isSet(Flags.INLINE_FUNCTIONS);
failure(DAE.BUILTIN_EARLY_INLINE() = inlineType);
then inTuple;

case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_)))
equation
true = Config.acceptMetaModelicaGrammar();
Expand Down Expand Up @@ -2057,6 +2064,7 @@ algorithm
case(DAE.NO_INLINE()) then "No inline";
case(DAE.AFTER_INDEX_RED_INLINE()) then "Inline after index reduction";
case(DAE.EARLY_INLINE()) then "Inline as soon as possible";
case(DAE.BUILTIN_EARLY_INLINE()) then "Inline as soon as possible, even if inlining is globally disabled";
case(DAE.NORM_INLINE()) then "Inline before index reduction";
end matchcontinue;
end printInlineTypeStr;
Expand Down
89 changes: 19 additions & 70 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected import Global;
protected import Graph;
protected import HashTable;
protected import HashTable5;
protected import Inline;
protected import InstSection;
protected import InstExtends;
protected import NFInstUtil;
Expand Down Expand Up @@ -2782,7 +2783,7 @@ algorithm
print(intString(dimension));
print("\n");*/
// adrpo: get the inline type of the function
inlineType = isInlineFunc2(el);
inlineType = isInlineFunc(el);
then
SOME((path, dimension, inlineType));

Expand Down Expand Up @@ -11643,7 +11644,7 @@ algorithm

// set the source of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), NONE(), NONE());
inlineType = isInlineFunc2(c);
inlineType = isInlineFunc(c);
partialPrefixBool = SCode.partialBool(partialPrefix);

daeElts = optimizeFunctionCheckForLocals(fpath,daeElts,NONE(),{},{},{});
Expand Down Expand Up @@ -12135,83 +12136,33 @@ algorithm
end matchcontinue;
end setFullyQualifiedTypename;

public function isInlineFunc "
Author: stefan
function: isInlineFunc
looks up a function and returns whether or not it is an inline function"
input Absyn.Path inPath;
input Env.Cache inCache;
input Env.Env inEnv;
output DAE.InlineType outBoolean;
algorithm
outBoolean := matchcontinue(inPath,inCache,inEnv)
local
Absyn.Path p;
Env.Cache c;
Env.Env env;
SCode.Element cl;
case(p,c,env)
equation
(c,cl,env) = Lookup.lookupClass(c,env,p,true);
then
isInlineFunc2(cl);
case(_,_,_) then DAE.NO_INLINE();
end matchcontinue;
end isInlineFunc;

public function isInlineFunc2 "
Author: bjozac 2009-12
helper function to isInlineFunc"
protected function isInlineFunc
input SCode.Element inClass;
output DAE.InlineType outInlineType;
algorithm
outInlineType := matchcontinue(inClass)
local
SCode.Annotation ann;

case SCode.CLASS(cmt=SCode.COMMENT(annotation_=SOME(ann)))
then isInlineFunc3(ann);

else DAE.NO_INLINE();
end matchcontinue;
end isInlineFunc2;

protected function isInlineFunc3 "
Author Stefan
helper function to isInlineFunc2"
input SCode.Annotation ann;
output DAE.InlineType outBoolean;
algorithm
outBoolean := matchcontinue(ann)
local
list<SCode.Annotation> cdr;
list<SCode.SubMod> smlst;
DAE.InlineType res;

case (SCode.ANNOTATION(SCode.MOD(subModLst = smlst)))
equation
res = isInlineFunc4(smlst);
true = DAEUtil.convertInlineTypeToBool(res);
then res;
case SCode.CLASS(cmt=SCode.COMMENT(annotation_=SOME(SCode.ANNOTATION(SCode.MOD(subModLst = smlst)))))
then isInlineFunc2(smlst);

else DAE.NO_INLINE();
end matchcontinue;
end isInlineFunc3;
end isInlineFunc;

protected function isInlineFunc4 "
Author: stefan
function: isInlineFunc4
helper function to isInlineFunc3"
protected function isInlineFunc2
input list<SCode.SubMod> inSubModList;
output DAE.InlineType res;
algorithm
res := matchcontinue(inSubModList)
res := match (inSubModList)
local
list<SCode.SubMod> cdr;
case ({}) then DAE.NO_INLINE();

case (SCode.NAMEMOD("Inline",SCode.MOD(binding = SOME((Absyn.BOOL(true),_)))) :: cdr)
equation
failure(DAE.AFTER_INDEX_RED_INLINE() = isInlineFunc4(cdr));
failure(DAE.AFTER_INDEX_RED_INLINE() = isInlineFunc2(cdr));
then DAE.NORM_INLINE();

case(SCode.NAMEMOD("LateInline",SCode.MOD(binding = SOME((Absyn.BOOL(true),_)))) :: _)
Expand All @@ -12227,13 +12178,11 @@ algorithm
then DAE.AFTER_INDEX_RED_INLINE();

case (SCode.NAMEMOD("__OpenModelica_EarlyInline",SCode.MOD(binding = SOME((Absyn.BOOL(true),_)))) :: cdr)
equation
DAE.NO_INLINE() = isInlineFunc4(cdr);
then DAE.EARLY_INLINE();

case(_ :: cdr) then isInlineFunc4(cdr);
end matchcontinue;
end isInlineFunc4;
case(_ :: cdr) then isInlineFunc2(cdr);
end match;
end isInlineFunc2;

protected function stripFuncOutputsMod "strips the assignment modification of the component declared as output"
input SCode.Element elem;
Expand Down Expand Up @@ -17485,7 +17434,7 @@ algorithm
inVars = List.filter(vl,Types.isInputVar);
outVars = List.filter(vl,Types.isOutputVar);
name = SCode.isBuiltinFunction(cl,List.map(inVars,Types.varName),List.map(outVars,Types.varName));
inlineType = isInlineFunc2(cl);
inlineType = isInlineFunc(cl);
isOpenModelicaPure = not SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_Impure");
then (DAE.FUNCTION_ATTRIBUTES(inlineType,isOpenModelicaPure,isImpure,DAE.FUNCTION_BUILTIN(SOME(name)),DAE.FP_NON_PARALLEL()));

Expand All @@ -17495,14 +17444,14 @@ algorithm
inVars = List.filter(vl,Types.isInputVar);
outVars = List.filter(vl,Types.isOutputVar);
name = SCode.isBuiltinFunction(cl,List.map(inVars,Types.varName),List.map(outVars,Types.varName));
inlineType = isInlineFunc2(cl);
inlineType = isInlineFunc(cl);
isOpenModelicaPure = not SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_Impure");
then (DAE.FUNCTION_ATTRIBUTES(inlineType,isOpenModelicaPure,false,DAE.FUNCTION_BUILTIN(SOME(name)),DAE.FP_PARALLEL_FUNCTION()));

//parallel functions: non-builtin
case (SCode.CLASS(restriction=SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION())),_)
equation
inlineType = isInlineFunc2(cl);
inlineType = isInlineFunc(cl);
isBuiltin = Util.if_(SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_BuiltinPtr"), DAE.FUNCTION_BUILTIN_PTR(), DAE.FUNCTION_NOT_BUILTIN());
isOpenModelicaPure = not SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_Impure");
then DAE.FUNCTION_ATTRIBUTES(inlineType,isOpenModelicaPure,false,isBuiltin,DAE.FP_PARALLEL_FUNCTION());
Expand All @@ -17511,9 +17460,9 @@ algorithm
case (SCode.CLASS(restriction=SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION())),_)
then DAE.FUNCTION_ATTRIBUTES(DAE.NO_INLINE(),true,false,DAE.FUNCTION_NOT_BUILTIN(),DAE.FP_KERNEL_FUNCTION());

case (SCode.CLASS(restriction=restriction),_)
case (SCode.CLASS(name=name,restriction=restriction),_)
equation
inlineType = isInlineFunc2(cl);
inlineType = isInlineFunc(cl);
isBuiltin = Util.if_(SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_BuiltinPtr"), DAE.FUNCTION_BUILTIN_PTR(), DAE.FUNCTION_NOT_BUILTIN());
isOpenModelicaPure = not SCode.hasBooleanNamedAnnotationInClass(cl,"__OpenModelica_Impure");
isImpure = SCode.isRestrictionImpure(restriction);
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1000,13 +1000,15 @@ end generateHeader;

function generateSeparateCode
input TypeName className[:] := fill($TypeName(AllLoadedClasses),0);
input String stampSuffix := "" "Suffix to add to dependencies (usually .stamp)";
output Boolean success;
external "builtin";
annotation(Documentation(info="<html><p>Under construction.</p>
</html>"),preferredView="text");
end generateSeparateCode;

function generateSeparateCodeDependencies
input String stampSuffix := ".c" "Suffix to add to dependencies (often .c.stamp)";
output String [:] dependencies;
external "builtin";
annotation(Documentation(info="<html><p>Under construction.</p>
Expand Down
15 changes: 14 additions & 1 deletion Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7488,6 +7488,7 @@ algorithm
(fn_1,functype) := deoverloadFuncname(fn, functype);
tuple_ := isTuple(restype);
(isBuiltin,builtin,fn_1) := isBuiltinFunc(fn_1,functype);
inlineType := inlineBuiltin(isBuiltin,inlineType);

//check the env to see if a call to a parallel or kernle function is a valid one.
true := isValidWRTParallelScope(fn,builtin,funcParal,inEnv,info);
Expand Down Expand Up @@ -7519,14 +7520,26 @@ algorithm
/* Instantiate any implicit record constructors needed and add them to the dae function tree */
cache := instantiateImplicitRecordConstructors(cache, inEnv, args_1, st);
functionTree := Env.getFunctionTree(cache);
((call_exp,(_,didInline))) := Inline.inlineCall((call_exp,((SOME(functionTree),{DAE.EARLY_INLINE()}),false)));
((call_exp,(_,didInline))) := Inline.inlineCall((call_exp,((SOME(functionTree),{DAE.BUILTIN_EARLY_INLINE(),DAE.EARLY_INLINE()}),false)));
(call_exp,_) := ExpressionSimplify.condsimplify(didInline,call_exp);
didInline := didInline and (not Config.acceptMetaModelicaGrammar() /* Some weird errors when inlining. Becomes boxed even if it shouldn't... */);
prop_1 := Debug.bcallret2(didInline, Types.setTypeInProps, restype, prop_1, prop_1);
expProps := Util.if_(Util.isSuccess(status),SOME((call_exp,prop_1)),NONE());
outCache := cache;
end elabCallArgs3;

protected function inlineBuiltin
input DAE.FunctionBuiltin isBuiltin;
input DAE.InlineType inlineType;
output DAE.InlineType outInlineType;
algorithm
outInlineType := match (isBuiltin,inlineType)
case (DAE.FUNCTION_BUILTIN_PTR(),_)
then DAE.BUILTIN_EARLY_INLINE();
else inlineType;
end match;
end inlineBuiltin;

protected function isValidWRTParallelScope
input Absyn.Path inFn;
input Boolean isBuiltin;
Expand Down

0 comments on commit 18e300f

Please sign in to comment.