Skip to content

Commit

Permalink
Added cache to almost all functions that has something to do with loo…
Browse files Browse the repository at this point in the history
…kup and instantiation. Packages with constants now translates much faster.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2417 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jun 7, 2006
1 parent 5eb8e60 commit 66be264
Show file tree
Hide file tree
Showing 13 changed files with 5,520 additions and 4,422 deletions.
913 changes: 464 additions & 449 deletions Compiler/Builtin.mo

Large diffs are not rendered by default.

2,238 changes: 1,219 additions & 1,019 deletions Compiler/Ceval.mo

Large diffs are not rendered by default.

41 changes: 24 additions & 17 deletions Compiler/Connect.mo
Expand Up @@ -651,20 +651,23 @@ public function unconnectedFlowEquations "Unconnected flow variables.
these are connected or not. This is only known in the preceding recursive
call. However, the top call must generate for both inner and outer
connectors, hence the last argument, true for top call"
input Env.Cache inCache;
input Sets inSets;
input list<DAE.Element> inDAEElementLst;
input Env.Env inEnv;
input Boolean inBoolean;
output Env.Cache outCache;
output list<DAE.Element> outDAEElementLst;
algorithm
outDAEElementLst:=
matchcontinue (inSets,inDAEElementLst,inEnv,inBoolean)
(outCache,outDAEElementLst) :=
matchcontinue (inCache,inSets,inDAEElementLst,inEnv,inBoolean)
local
list<Exp.ComponentRef> v1,v2,vars,vars2,unconnectedvars;
list<DAE.Element> dae_1,dae;
Sets csets;
list<Env.Frame> env;
case (csets,dae,env,true)
Env.Cache cache;
case (cache,csets,dae,env,true)
equation
v1 = Env.localOutsideConnectorFlowvars(env) "if outermost call look at both inner and outer unconnected connectors" ;
v2 = Env.localInsideConnectorFlowvars(env);
Expand All @@ -673,10 +676,11 @@ algorithm
// last array subscripts are not present in vars, therefor removed from vars2 too.
vars2 = Util.listMap(vars2,Exp.crefStripLastSubs);
unconnectedvars = removeVariables(vars, vars2);
dae_1 = generateZeroflowEquations(unconnectedvars,env);
(cache,dae_1) = generateZeroflowEquations(cache,unconnectedvars,env);
then
dae_1;
case (csets,dae,env,_) /* Debug.fprint(\"failtrace\",\"-unconnected_flow_equations failed\\n\") */ then {};
(cache,dae_1);
case (cache,csets,dae,env,_) /* Debug.fprint(\"failtrace\",\"-unconnected_flow_equations failed\\n\") */
then (cache,{});
end matchcontinue;
end unconnectedFlowEquations;

Expand Down Expand Up @@ -735,12 +739,14 @@ protected function generateZeroflowEquations "function: generateZeroflowEquation
Unconnected flow variables should be set to zero. This function
generates equations setting each variable in the list to zero.
"
input Env.Cache inCache;
input list<Exp.ComponentRef> inExpComponentRefLst;
input Env.Env inEnv;
output Env.Cache outCache;
output list<DAE.Element> outDAEElementLst;
algorithm
outDAEElementLst:=
matchcontinue (inExpComponentRefLst,inEnv)
(outCache,outDAEElementLst) :=
matchcontinue (inCache,inExpComponentRefLst,inEnv)
local
list<DAE.Element> res;
Exp.ComponentRef cr;
Expand All @@ -749,24 +755,25 @@ algorithm
list<Exp.ComponentRef> xs;
list<int> dimSizes;
list<Exp.Exp> dimExps;
case ({},_) then {};
case ((cr :: xs),env)
Env.Cache cache;
case (cache,{},_) then (cache,{});
case (cache,(cr :: xs),env)
equation
(_,tp,_) = Lookup.lookupVar(env,cr);
(cache,_,tp,_) = Lookup.lookupVar(cache,env,cr);
true = Types.isArray(tp); // For variables that are arrays, generate cr = fill(0,dims);
dimSizes = Types.getDimensionSizes(tp);
dimExps = Util.listMap(dimSizes,Exp.makeIntegerExp);
res = generateZeroflowEquations(xs,env);
(cache,res) = generateZeroflowEquations(cache,xs,env);
then
(DAE.EQUATION(Exp.CREF(cr,Exp.REAL()),Exp.CALL(Absyn.IDENT("fill"),Exp.RCONST(0.0)::dimExps,false,true)) :: res);
(cache,DAE.EQUATION(Exp.CREF(cr,Exp.REAL()),Exp.CALL(Absyn.IDENT("fill"),Exp.RCONST(0.0)::dimExps,false,true)) :: res);

case ((cr :: xs),env) // For scalars.
case (cache,(cr :: xs),env) // For scalars.
equation
(_,tp,_) = Lookup.lookupVar(env,cr);
(cache,_,tp,_) = Lookup.lookupVar(cache,env,cr);
false = Types.isArray(tp); // scalar
res = generateZeroflowEquations(xs,env);
(cache,res) = generateZeroflowEquations(cache,xs,env);
then
(DAE.EQUATION(Exp.CREF(cr,Exp.REAL()),Exp.RCONST(0.0)) :: res);
(cache,DAE.EQUATION(Exp.CREF(cr,Exp.REAL()),Exp.RCONST(0.0)) :: res);
end matchcontinue;
end generateZeroflowEquations;

Expand Down
4 changes: 3 additions & 1 deletion Compiler/DAE.mo
Expand Up @@ -357,6 +357,8 @@ protected import OpenModelica.Compiler.Error;

protected import OpenModelica.Compiler.SCode;

protected import OpenModelica.Compiler.Env;

public function dump "function: dump
This function prints the DAE in the standard output format.
Expand Down Expand Up @@ -3138,7 +3140,7 @@ algorithm
case (cname,{},_) then Values.RECORD(cname,{},{}); /* impl */
case (cname,(EQUATION(exp = Exp.CREF(componentRef = cr),scalar = rhs) :: rest),impl)
equation
(value,_) = Ceval.ceval({}, rhs, impl, NONE, NONE, Ceval.MSG());
(_,value,_) = Ceval.ceval(Env.emptyCache,{}, rhs, impl, NONE, NONE, Ceval.MSG());
Values.RECORD(cname,vals,names) = daeToRecordValue(cname, rest, impl);
cr_str = Exp.printComponentRefStr(cr);
then
Expand Down
6 changes: 3 additions & 3 deletions Compiler/DAELow.mo
Expand Up @@ -10251,7 +10251,7 @@ algorithm
case (DAELOW(orderedVars = vars,knownVars = knvars,externalObjects=extVars,orderedEqs = eqns,
removedEqs = seqns,initialEqs = ie,arrayEqs = ae,algorithms = al,eventInfo = wc,extObjClasses=extObjCls))
equation
env = Builtin.initialEnv();
(_,env) = Builtin.initialEnv(Env.emptyCache);
knvarlst = varList(knvars);
env_1 = addVariablesToEnv(knvarlst, env);
knvarlst_1 = updateVariables(knvarlst, env_1);
Expand Down Expand Up @@ -10356,15 +10356,15 @@ algorithm
case ((VAR(varName = cr,varKind = a,varDirection = b,varType = c,bindExp = SOME(e),arryDim = d,startValue = f,index = g,origVarName = h,className = i,values = dae_var_attr,comment = comment,flow_ = flow_) :: rest),env)
equation
rest_1 = updateVariables(rest, env);
(v,_) = Ceval.ceval(env, e, false, NONE, NONE, Ceval.MSG());
(_,v,_) = Ceval.ceval(Env.emptyCache,env, e, false, NONE, NONE, Ceval.MSG());
then
(VAR(cr,a,b,c,SOME(e),SOME(v),d,f,g,h,i,dae_var_attr,comment,
flow_) :: rest_1);
case ((VAR(varName = cr,varKind = a,varDirection = b,varType = c,bindExp = SOME(e),bindValue = v,arryDim = d,startValue = f,index = g,origVarName = h,className = i,values = dae_var_attr,comment = comment,flow_ = flow_) :: rest),env)
local Option<Values.Value> v;
equation
rest_1 = updateVariables(rest, env);
failure((_,_) = Ceval.ceval(env, e, false, NONE, NONE, Ceval.NO_MSG()));
failure((_,_,_) = Ceval.ceval(Env.emptyCache,env, e, false, NONE, NONE, Ceval.NO_MSG()));
Print.printBuf("Warning, ceval failed for parameter: ");
Exp.printComponentRef(cr);
Print.printBuf("\n");
Expand Down

0 comments on commit 66be264

Please sign in to comment.