Skip to content

Commit

Permalink
- replace Debug.fcall("..",print, .. crefStr(..) .. expStr(..) by add…
Browse files Browse the repository at this point in the history
…ing print functions, this is a speedup because the unused string generation from crefs and exp are avoided

- Bugfixes removeSimpleEquationsX

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8463 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Apr 2, 2011
1 parent dcc8c76 commit 56f8459
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 66 deletions.
36 changes: 19 additions & 17 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -48,10 +48,10 @@ public import Absyn;
public import BackendDAE;
public import DAE;

protected import BackendDump;
protected import BackendDAECreate;
protected import BackendDAETransform;
protected import BackendDAEUtil;
protected import BackendDump;
protected import BackendEquation;
protected import BackendVarTransform;
protected import BackendVariable;
Expand Down Expand Up @@ -421,7 +421,7 @@ algorithm
false = BackendVariable.isTopLevelInputOrOutput(cr1,vars,knvars);
failure(_ = BackendDAEUtil.treeGet(outputs, cr1)) "cr1 not output of algorithm";
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Simple Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(e2) +& " found.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("Simple Equation ",cr1," = ",e2," found.\n"));
repl_1 = VarTransform.addReplacement(repl, cr1, e2);
mvars_1 = BackendDAEUtil.treeAdd(mvars, cr1, 0);
(eqns_1,seqns_1,mvars, mvars1, repl_2,extlst1,replc_2,varsAliases) = removeSimpleEquations2(eqns, funcSimpleEquation, vars, knvars, mvars_1, mvars1, outputs, repl_1, extlst,replc_1,varsAliases);
Expand All @@ -440,7 +440,7 @@ algorithm
false = BackendVariable.isTopLevelInputOrOutput(cr1,vars,knvars);
failure(_ = BackendDAEUtil.treeGet(outputs, cr1)) "cr1 not output of algorithm";
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Simple Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(e2) +& " found.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("Simple Equation ",cr1," = ",e2," found.\n"));
repl_1 = VarTransform.addReplacement(repl, cr1, e2);
mvars_1 = BackendDAEUtil.treeAdd(mvars, cr1, 0);
(eqns_1,seqns_1,mvars,mvars1,repl_2,extlst1,replc_2,varsAliases) = removeSimpleEquations2(eqns, funcSimpleEquation, vars, knvars, mvars_1, mvars1,outputs, repl_1, extlst,replc_1,varsAliases);
Expand All @@ -460,7 +460,7 @@ algorithm
failure(_ = BackendVariable.varStartValueFail(v));
failure(_ = BackendDAEUtil.treeGet(outputs, cr1)) "cr1 not output of algorithm";
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Alias Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(e2) +& " found.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("Alias Equation ",cr1," = ",e2," found.\n"));
repl_1 = VarTransform.addReplacement(repl, cr1, e2);
mvars_1 = BackendDAEUtil.treeAdd(mvars1, cr1, 0);
varsAliases = BackendDAEUtil.updateAliasVariables(varsAliases, cr1, e2,vars);
Expand All @@ -481,7 +481,7 @@ algorithm
failure( _ = BackendVariable.varStartValueFail(v));
failure(_ = BackendDAEUtil.treeGet(outputs, cr1)) "cr1 not output of algorithm";
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Alias Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(e2) +& " found.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("Alias Equation ",cr1," = ",e2," found.\n"));
repl_1 = VarTransform.addReplacement(repl, cr1, e2);
mvars_1 = BackendDAEUtil.treeAdd(mvars1, cr1, 0);
varsAliases = BackendDAEUtil.updateAliasVariables(varsAliases, cr1, e2,vars);
Expand Down Expand Up @@ -1732,36 +1732,38 @@ algorithm
BackendDAE.Var var;
BackendDAE.VarKind kind;
BackendDAE.BackendDAE dae1;
BackendDAE.Variables vars,knvars;
BackendDAE.Variables vars;
case (cr1,i,cr2,j,e1,e2,dae,mavars)
equation
true = intGt(i,0) "cr1 not state";
vars = BackendVariable.daeVars(dae);
var = BackendVariable.getVarAt(vars,intAbs(i));
// no State
false = BackendVariable.isState(cr1, vars) "cr1 not state";
false = BackendVariable.isStateVar(var) "cr1 not state";
kind = BackendVariable.varKind(var);
BackendVariable.isVarKindVariable(kind) "cr1 not constant";
knvars = BackendVariable.daeKnVars(dae);
false = BackendVariable.isTopLevelInputOrOutput(cr1,vars,knvars);
false = BackendVariable.isVarOnTopLevelAndOutput(var);
false = BackendVariable.isVarOnTopLevelAndInput(var);
failure( _ = BackendVariable.varStartValueFail(var));
Debug.fcall("debugAlias",print,"Alias Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(e2) +& " found.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("Alias Equation ",cr1," = ",e2," found.\n"));
// store changed var
newvars = BackendDAEUtil.treeAdd(mavars, cr1, 0);
dae1 = BackendDAEUtil.updateAliasVariablesDAE(cr1,e2,dae);
then
(cr1,e2,dae1,newvars);
case (cr1,i,cr2,j,e1,e2,dae,mavars)
equation
true = intGt(j,0) "cr1 not state";
vars = BackendVariable.daeVars(dae);
var = BackendVariable.getVarAt(vars,intAbs(i));
// no State
false = BackendVariable.isState(cr2, vars) "cr1 not state";
false = BackendVariable.isStateVar(var) "cr1 not state";
kind = BackendVariable.varKind(var);
BackendVariable.isVarKindVariable(kind) "cr1 not constant";
knvars = BackendVariable.daeKnVars(dae);
false = BackendVariable.isTopLevelInputOrOutput(cr2,vars,knvars);
false = BackendVariable.isVarOnTopLevelAndOutput(var);
false = BackendVariable.isVarOnTopLevelAndInput(var);
failure( _ = BackendVariable.varStartValueFail(var));
Debug.fcall("debugAlias",print,"Alias Equation " +& ComponentReference.printComponentRefStr(cr2) +& " = " +& ExpressionDump.printExpStr(e1) +& " found.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("Alias Equation ",cr2," = ",e1," found.\n"));
// store changed var
newvars = BackendDAEUtil.treeAdd(mavars, cr2, 0);
dae1 = BackendDAEUtil.updateAliasVariablesDAE(cr2,e1,dae);
Expand Down Expand Up @@ -4427,16 +4429,16 @@ algorithm
case (curr as BackendDAE.VAR(varName=currCREF),(currVar,currInd)::restTuple,bt) equation
true = ComponentReference.crefEqual(currCREF, currVar) ;
changedVar = BackendVariable.setVarIndex(curr,currInd);
Debug.fcall("varIndex2",print, ComponentReference.printComponentRefStr(currVar) +& " " +& intString(currInd)+&"\n");
Debug.fcall("varIndex2",BackendDump.debugCrefStrIntStr,(currVar," ",currInd,"\n"));
bt = BackendDAEUtil.treeAddList(bt,{currCREF});
then (changedVar,bt);
case (curr as BackendDAE.VAR(varName=currCREF),{},bt) equation
changedVar = BackendVariable.setVarIndex(curr,-1);
Debug.fcall("varIndex2",print, ComponentReference.printComponentRefStr(currCREF) +& " -1\n");
Debug.fcall("varIndex2",BackendDump.debugCrefStr, (currCREF," -1\n"));
then (changedVar,bt);
case (curr as BackendDAE.VAR(varName=currCREF),(currVar,currInd)::restTuple,bt) equation
changedVar = BackendVariable.setVarIndex(curr,-1);
Debug.fcall("varIndex2",print, ComponentReference.printComponentRefStr(currCREF) +& " -1\n");
Debug.fcall("varIndex2",BackendDump.debugCrefStr,(currCREF," -1\n"));
(changedVar,bt) = changeIndices2(changedVar,restTuple,bt);
then (changedVar,bt);
case (_,_,_) equation
Expand Down
22 changes: 11 additions & 11 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -1297,7 +1297,7 @@ algorithm
aliasVariables = BackendVariable.addVar(v,aliasVariables);
exp = BackendVariable.varBindExp(v);
cr = BackendVariable.varCref(v);
Debug.fcall("debugAlias",print,"++++ added Alias eqn : " +& ComponentReference.printComponentRefStr(cr) +& " = " +& ExpressionDump.printExpStr(exp) +& "\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("++++ added Alias eqn : ",cr," = ",exp,"\n"));
aliasMappingsCref1 = BaseHashTable.addNoUpdCheck((cr,exp),aliasMappingsCref);
aliasMappingsExp1 = BaseHashTable.addNoUpdCheck((exp,cr),aliasMappingsExp);
Aliases = addAliasVariables(rest,BackendDAE.ALIASVARS(aliasMappingsCref1,aliasMappingsExp1,aliasVariables));
Expand Down Expand Up @@ -1358,13 +1358,12 @@ algorithm
DAE.ComponentRef cr1;
list<tuple<HashTable4.Key,HashTable4.Value>> tableList;
list<String> str;
DAE.ExpType ty;

case (Aliases as BackendDAE.ALIASVARS( varMappingsExp = aliasMappingsExp, aliasVars = aliasVariables),inCref,inExp,inVars)
equation
exp1 = Expression.crefExp(inCref);
cr1 = BaseHashTable.get(exp1,aliasMappingsExp);
Debug.fcall("debugAlias",print,"update ComponentRef : " +& ComponentReference.printComponentRefStr(inCref) +& " with Exp : " +& ExpressionDump.printExpStr(inExp) +& "\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("update ComponentRef : ",inCref," with Exp : ",inExp,"\n"));

tableList = BaseHashTable.hashTableList(aliasMappingsExp);
Aliases = updateAliasVars(tableList,exp1,inExp,Aliases);
Expand All @@ -1379,9 +1378,9 @@ algorithm
case (Aliases as BackendDAE.ALIASVARS( varMappingsExp = aliasMappingsExp, aliasVars = aliasVariables),inCref,inExp,inVars)
equation
exp1 = Expression.crefExp(inCref);
ty = Expression.typeof(exp1);
cr1 = BaseHashTable.get(DAE.UNARY(DAE.UMINUS(ty),exp1),aliasMappingsExp);
Debug.fcall("debugAlias",print,"update ComponentRef : " +& ComponentReference.printComponentRefStr(inCref) +& " with -" +& ExpressionDump.printExpStr(inExp) +& "\n");
exp1 = Expression.negate(exp1);
cr1 = BaseHashTable.get(exp1,aliasMappingsExp);
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("update ComponentRef : ",inCref," with -",inExp,"\n"));

tableList = BaseHashTable.hashTableList(aliasMappingsExp);
Aliases = updateAliasVars(tableList,exp1,inExp,Aliases);
Expand All @@ -1395,7 +1394,7 @@ algorithm

case (Aliases as BackendDAE.ALIASVARS( varMappingsExp = aliasMappingsExp, aliasVars = aliasVariables),inCref,inExp,inVars)
equation
Debug.fcall("debugAlias",print," Search for " +& ComponentReference.printComponentRefStr(inCref) +& " with binding : " +& ExpressionDump.printExpStr(inExp) +& "failed.\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,(" Search for ",inCref," with binding : ",inExp,"failed.\n"));
exp1 = Expression.crefExp(inCref);
failure(_ = BaseHashTable.get(exp1,aliasMappingsExp));
({v},_) = BackendVariable.getVar(inCref,inVars);
Expand Down Expand Up @@ -1438,20 +1437,20 @@ algorithm
equation
ty = Expression.typeof(inExp2);
(true,b,exp2) = compareExpAlias(exp,inExp1);
Debug.fcall("debugAlias",print,"*** got : " +& ComponentReference.printComponentRefStr(cref) +& " = Exp : " +& ExpressionDump.printExpStr(exp2) +& "\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("*** got : ",cref," = Exp : ",exp2,"\n"));
({v},_) = BackendVariable.getVar(cref,aliasvars);
exp = BackendVariable.varBindExp(v);
exp2 = Util.if_(b,DAE.UNARY(DAE.UMINUS(ty),inExp2),inExp2);
exp2 = ExpressionSimplify.simplify1(exp2);
Debug.fcall("debugAlias",print,"*** replace : " +& ExpressionDump.printExpStr(exp) +& " = " +& ExpressionDump.printExpStr(exp2) +& "\n");
Debug.fcall("debugAlias",BackendDump.debugStrExpStrExpStr,("*** replace : ",exp," = ",exp2,"\n"));
v = BackendVariable.setBindExp(v,exp2);
aliasVariables = addAliasVariables({v},inAliases);
Debug.fcall("debugAlias",print,"RES *** ComponentRef : " +& ComponentReference.printComponentRefStr(cref) +& " = Exp : " +& ExpressionDump.printExpStr(exp2) +& "\n");
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("RES *** ComponentRef : ",cref," = Exp : ",exp2,"\n"));
aliasVariables = updateAliasVars(rest,inExp1,inExp2,aliasVariables);
then aliasVariables;
case (((exp,cref))::rest,inExp1,inExp2,aliasVariables)
equation
Debug.fcall("debugAlias",print,"*** let " +& ExpressionDump.printExpStr(exp) +& " with binding Exp : " +& ComponentReference.printComponentRefStr(cref) +& "\n");
Debug.fcall("debugAlias",BackendDump.debugStrExpStrCrefStr,("*** let ",exp," with binding Exp : ",cref,"\n"));
aliasVariables = updateAliasVars(rest,inExp1,inExp2,aliasVariables);
then aliasVariables;
end matchcontinue;
Expand Down Expand Up @@ -5902,6 +5901,7 @@ protected
list<String> strPreOptModules;
algorithm
allPreOptModules := {(BackendDAEOptimize.removeSimpleEquations,"removeSimpleEquations"),
(BackendDAEOptimize.removeSimpleEquationsX,"removeSimpleEquationsX"),
(BackendDAEOptimize.removeParameterEqns,"removeParameterEqns"),
(BackendDAEOptimize.removeAliasEquations,"removeAliasEquations"),
(BackendDAEOptimize.inlineArrayEqn,"inlineArrayEqn"),
Expand Down
110 changes: 108 additions & 2 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -47,14 +47,12 @@ protected import BackendDAEUtil;
protected import BackendVariable;
protected import BackendEquation;
protected import ComponentReference;
protected import BackendDAEEXT;
protected import DAEDump;
protected import DAEUtil;
protected import Debug;
protected import Error;
protected import Expression;
protected import ExpressionDump;
protected import HashTable4;
protected import IOStream;
protected import SCode;
protected import Util;
Expand Down Expand Up @@ -1685,4 +1683,112 @@ algorithm
end match;
end dumpComponentsAdvanced3;

/*******************************************/
/* Debug dump functions */
/*******************************************/

public function debugCrefStr
input tuple<DAE.ComponentRef,String> inTpl;
protected
DAE.ComponentRef a;
String b;
algorithm
(a,b) := inTpl;
print(ComponentReference.printComponentRefStr(a) +& b);
end debugCrefStr;

public function debugCrefStrIntStr
input tuple<DAE.ComponentRef,String,Integer,String> inTpl;
protected
DAE.ComponentRef a;
String b,d;
Integer c;
algorithm
(a,b,c,d) := inTpl;
print(ComponentReference.printComponentRefStr(a) +& b +& intString(c) +& d);
end debugCrefStrIntStr;

public function debugStrCrefStr
input tuple<String,DAE.ComponentRef,String> inTpl;
protected
String a,c;
DAE.ComponentRef b;
algorithm
(a,b,c) := inTpl;
print(a +&ComponentReference.printComponentRefStr(b) +& c);
end debugStrCrefStr;

public function debugStrCrefStrIntStr
input tuple<String,DAE.ComponentRef,String,Integer,String> inTpl;
protected
String a,c,e;
DAE.ComponentRef b;
Integer d;
algorithm
(a,b,c,d,e) := inTpl;
print(a +& ComponentReference.printComponentRefStr(b) +& c +& intString(d) +& e);
end debugStrCrefStrIntStr;

public function debugStrCrefStrExpStr
input tuple<String,DAE.ComponentRef,String,DAE.Exp,String> inTpl;
protected
String a,c,e;
DAE.ComponentRef b;
DAE.Exp d;
algorithm
(a,b,c,d,e) := inTpl;
print(a +& ComponentReference.printComponentRefStr(b) +& c +& ExpressionDump.printExpStr(d) +& e);
end debugStrCrefStrExpStr;

public function debugStrCrefStrCrefStr
input tuple<String,DAE.ComponentRef,String,DAE.ComponentRef,String> inTpl;
protected
String a,c,e;
DAE.ComponentRef b,d;
algorithm
(a,b,c,d,e) := inTpl;
print(a +& ComponentReference.printComponentRefStr(b) +& c +& ComponentReference.printComponentRefStr(d) +& e);
end debugStrCrefStrCrefStr;

public function debugStrExpStrCrefStr
input tuple<String,DAE.Exp,String,DAE.ComponentRef,String> inTpl;
protected
String a,c,e;
DAE.Exp b;
DAE.ComponentRef d;
algorithm
(a,b,c,d,e) := inTpl;
print(a +& ExpressionDump.printExpStr(b) +& c +& ComponentReference.printComponentRefStr(d) +& e);
end debugStrExpStrCrefStr;

public function debugStrExpStrExpStr
input tuple<String,DAE.Exp,String,DAE.Exp,String> inTpl;
protected
String a,c,e;
DAE.Exp b,d;
algorithm
(a,b,c,d,e) := inTpl;
print(a +& ExpressionDump.printExpStr(b) +& c +& ExpressionDump.printExpStr(d) +& e);
end debugStrExpStrExpStr;

public function debugExpStrExpStrExpStr
input tuple<DAE.Exp,String,DAE.Exp,String,DAE.Exp,String> inTpl;
protected
DAE.Exp a,c,e;
String b,d,f;
algorithm
(a,b,c,d,e,f) := inTpl;
print(ExpressionDump.printExpStr(a) +& b +& ExpressionDump.printExpStr(c) +& d +& ExpressionDump.printExpStr(e) +& f);
end debugExpStrExpStrExpStr;

public function debugStrExpStrExpStrExpStr
input tuple<String,DAE.Exp,String,DAE.Exp,String,DAE.Exp,String> inTpl;
protected
String a,c,e,g;
DAE.Exp b,d,f;
algorithm
(a,b,c,d,e,f,g) := inTpl;
print(a +& ExpressionDump.printExpStr(b) +& c +& ExpressionDump.printExpStr(d) +& e +& ExpressionDump.printExpStr(f) +& g);
end debugStrExpStrExpStrExpStr;

end BackendDump;

0 comments on commit 56f8459

Please sign in to comment.