Skip to content

Commit

Permalink
- fixed bug in last commit
Browse files Browse the repository at this point in the history
 - added AliasEquations testcase


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8438 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Mar 31, 2011
1 parent 5995f48 commit c0ccd69
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
10 changes: 7 additions & 3 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -420,7 +420,8 @@ algorithm
({v},_) = BackendVariable.getVar(cr1,vars);
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);
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Simple Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(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 @@ -439,6 +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");
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 @@ -457,7 +459,8 @@ algorithm
({v},_) = BackendVariable.getVar(cr1,vars);
failure(_ = BackendVariable.varStartValueFail(v));
failure(_ = BackendDAEUtil.treeGet(outputs, cr1)) "cr1 not output of algorithm";
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Alias Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(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 @@ -477,7 +480,8 @@ algorithm
({v},_) = BackendVariable.getVar(cr1,vars);
failure( _ = BackendVariable.varStartValueFail(v));
failure(_ = BackendDAEUtil.treeGet(outputs, cr1)) "cr1 not output of algorithm";
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
(extlst,_,replc_1) = removeSimpleEquations3(inExtendLst,replc,cr1,NONE(),e2,t);
Debug.fcall("debugAlias",print,"Alias Equation " +& ComponentReference.printComponentRefStr(cr1) +& " = " +& ExpressionDump.printExpStr(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
17 changes: 8 additions & 9 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);
//print("++++ added Alias eqn : " +& ComponentReference.printComponentRefStr(cr) +& " = " +& ExpressionDump.printExpStr(exp) +& "\n");
Debug.fcall("debugAlias",print,"++++ added Alias eqn : " +& ComponentReference.printComponentRefStr(cr) +& " = " +& ExpressionDump.printExpStr(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 @@ -1338,7 +1338,7 @@ algorithm
equation
exp1 = Expression.crefExp(inCref);
cr1 = BaseHashTable.get(exp1,aliasMappingsExp);
//print("update ComponentRef : " +& ComponentReference.printComponentRefStr(inCref) +& " with Exp : " +& ExpressionDump.printExpStr(inExp) +& "\n");
Debug.fcall("debugAlias",print,"update ComponentRef : " +& ComponentReference.printComponentRefStr(inCref) +& " with Exp : " +& ExpressionDump.printExpStr(inExp) +& "\n");

tableList = BaseHashTable.hashTableList(aliasMappingsExp);
Aliases = updateAliasVars(tableList,exp1,inExp,Aliases);
Expand All @@ -1355,7 +1355,7 @@ algorithm
exp1 = Expression.crefExp(inCref);
ty = Expression.typeof(exp1);
cr1 = BaseHashTable.get(DAE.UNARY(DAE.UMINUS(ty),exp1),aliasMappingsExp);
//print("update ComponentRef : " +& ComponentReference.printComponentRefStr(inCref) +& " with -" +& ExpressionDump.printExpStr(inExp) +& "\n");
Debug.fcall("debugAlias",print,"update ComponentRef : " +& ComponentReference.printComponentRefStr(inCref) +& " with -" +& ExpressionDump.printExpStr(inExp) +& "\n");

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

case (Aliases as BackendDAE.ALIASVARS( varMappingsExp = aliasMappingsExp, aliasVars = aliasVariables),inCref,inExp,inVars)
equation
//print(" Search for " +& ComponentReference.printComponentRefStr(inCref) +& " with binding : " +& ExpressionDump.printExpStr(inExp) +& "failed.\n");
Debug.fcall("debugAlias",print," Search for " +& ComponentReference.printComponentRefStr(inCref) +& " with binding : " +& ExpressionDump.printExpStr(inExp) +& "failed.\n");
exp1 = Expression.crefExp(inCref);
failure(_ = BaseHashTable.get(exp1,aliasMappingsExp));
({v},_) = BackendVariable.getVar(inCref,inVars);
Expand Down Expand Up @@ -1410,23 +1410,22 @@ algorithm
case ({},_,_,inAliases) then inAliases;
case (((exp,cref))::rest,inExp1,inExp2,inAliases as BackendDAE.ALIASVARS(aliasVars=aliasvars))
equation
//print("Exp : " +& ExpressionDump.printExpStr(exp) +& " - " +& ExpressionDump.printExpStr(inExp1) +& "\n");
ty = Expression.typeof(inExp2);
(true,b,exp2) = compareExpAlias(exp,inExp1);
//print("*** got : " +& ComponentReference.printComponentRefStr(cref) +& " = Exp : " +& ExpressionDump.printExpStr(exp2) +& "\n" +& "ListLength: " +& intString(listLength(rest)) +& "\n");
Debug.fcall("debugAlias",print,"*** got : " +& ComponentReference.printComponentRefStr(cref) +& " = Exp : " +& ExpressionDump.printExpStr(exp2) +& "\n");
({v},_) = BackendVariable.getVar(cref,aliasvars);
exp = BackendVariable.varBindExp(v);
//print("*** replace : " +& ExpressionDump.printExpStr(exp) +& " = " +& ExpressionDump.printExpStr(exp2) +& "\n");
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");
v = BackendVariable.setBindExp(v,exp2);
aliasVariables = addAliasVariables({v},inAliases);
//print("RES *** ComponentRef : " +& ComponentReference.printComponentRefStr(cref) +& " = Exp : " +& ExpressionDump.printExpStr(exp2) +& "\n");
Debug.fcall("debugAlias",print,"RES *** ComponentRef : " +& ComponentReference.printComponentRefStr(cref) +& " = Exp : " +& ExpressionDump.printExpStr(exp2) +& "\n");
aliasVariables = updateAliasVars(rest,inExp1,inExp2,aliasVariables);
then aliasVariables;
case (((exp,cref))::rest,inExp1,inExp2,aliasVariables)
equation
//print("*** let " +& ExpressionDump.printExpStr(exp) +& " with binding Exp : " +& ComponentReference.printComponentRefStr(cref) +& "\n" +& "ListLength: " +& intString(listLength(rest)) +& "\n");
Debug.fcall("debugAlias",print,"*** let " +& ExpressionDump.printExpStr(exp) +& " with binding Exp : " +& ComponentReference.printComponentRefStr(cref) +& "\n");
aliasVariables = updateAliasVars(rest,inExp1,inExp2,aliasVariables);
then aliasVariables;
end matchcontinue;
Expand Down
12 changes: 10 additions & 2 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1155,7 +1155,6 @@ algorithm
varKind = kind,
varDirection = dir,
varType = tp,
bindExp = NONE(),
bindValue = v,
arryDim = dim,
index = i,
Expand Down Expand Up @@ -2406,7 +2405,16 @@ algorithm
end match;
end daeKnVars;


public function daeAliasVars
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.Variables vars;
algorithm
vars := match (inBackendDAE)
local BackendDAE.Variables vars;
case (BackendDAE.DAE(aliasVars = BackendDAE.ALIASVARS(aliasVars = vars)))
then vars;
end match;
end daeAliasVars;

public function varsSize "function: varsSize
author: PA
Expand Down

0 comments on commit c0ccd69

Please sign in to comment.