diff --git a/Compiler/BackEnd/BackendDAEOptimize.mo b/Compiler/BackEnd/BackendDAEOptimize.mo index 955ef97b2eb..ebf4c2517f5 100644 --- a/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/Compiler/BackEnd/BackendDAEOptimize.mo @@ -5690,7 +5690,7 @@ algorithm //print("eq: "+BackendDump.equationString(eq)+"\n"); crefs := BackendEquation.equationCrefs(eq); crefs := List.filter1OnTrue(crefs,BackendVariable.isState,vars); - (states,stateIndxs) := BackendVariable.getVarLst(crefs,vars,{},{}); + (states,stateIndxs) := BackendVariable.getVarLst(crefs,vars); (stateIndxs,states) := List.filter1OnTrueSync(stateIndxs,stateVarIsNotVisited,varVisited,states);//not yet visited if not listEmpty(stateIndxs) then //print("states "+stringDelimitList(List.map(states,BackendDump.varString),"\n ")+"\n"); diff --git a/Compiler/BackEnd/BackendDAEUtil.mo b/Compiler/BackEnd/BackendDAEUtil.mo index 94d37cf8efb..87cf3a4b1ab 100644 --- a/Compiler/BackEnd/BackendDAEUtil.mo +++ b/Compiler/BackEnd/BackendDAEUtil.mo @@ -2685,7 +2685,7 @@ algorithm {e1 as DAE.RANGE()} := ExpressionSimplify.simplifyList(explst, {}); subs := list(DAE.INDEX(e) for e in extendRange(e1, vars)); crlst := list(ComponentReference.subscriptCref(cr, {s}) for s in subs); - (varslst, p) := BackendVariable.getVarLst(crlst, vars,{},{}); + (varslst, p) := BackendVariable.getVarLst(crlst, vars); pa := incidenceRowExp1(varslst, p, pa, 0); then (inExp, false, (vars, pa, ofunctionTree)); @@ -6243,10 +6243,10 @@ protected function traverseBackendDAEExpsVarWithUpdate "author: Frenkel TUD algorithm (ovar, outTypeA) := matchcontinue(inVar) local - DAE.Exp e1; + DAE.Exp e1, e1_; DAE.ComponentRef cref; list instdims; - Option attr; + Option attr, attr_; Option ts; Type_a ext_arg_1, ext_arg_2; BackendDAE.VarKind varKind; @@ -6260,18 +6260,29 @@ algorithm DAE.VarInnerOuter io; Boolean unreplaceable; String name; + Option v; case NONE() then (NONE(), inTypeA); case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)) equation - (e1, ext_arg_1) = func(e1, inTypeA); - (attr, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, ext_arg_1); - then (SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)), ext_arg_2); + (e1_, ext_arg_1) = func(e1, inTypeA); + (attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, ext_arg_1); + if referenceEq(e1,e1_) and referenceEq(attr,attr_) then + v = inVar; + else + v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), bindValue, instdims, source, attr_, ts, comment, ct, io, unreplaceable)); + end if; + then (v, ext_arg_2); case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)) equation - (attr, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, inTypeA); - then (SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr, ts, comment, ct, io, unreplaceable)), ext_arg_2); + (attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, inTypeA); + if referenceEq(attr,attr_) then + v = inVar; + else + v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), bindValue, instdims, source, attr_, ts, comment, ct, io, unreplaceable)); + end if; + then (v, ext_arg_2); else equation true = Flags.isSet(Flags.FAILTRACE); @@ -6301,57 +6312,86 @@ algorithm (outAttr,outExtraArg) := match(attr,func,extraArg) local Option q,u,du,min,max,i,f,n,eqbound,startOrigin; + Option q_,u_,du_,min_,max_,i_,f_,n_,eqbound_; Option ss; Option unc; - Option dist; + Option dist, dist_; Option p,fin; + Option a; case(NONE(),_,_) then (NONE(),extraArg); case(SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,i,f,n,ss,unc,dist,eqbound,p,fin,startOrigin)),_,_) equation - (q,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); - (u,outExtraArg) = Expression.traverseExpOpt(u,func,outExtraArg); - (du,outExtraArg) = Expression.traverseExpOpt(du,func,outExtraArg); - (min,outExtraArg) = Expression.traverseExpOpt(min,func,outExtraArg); - (max,outExtraArg) = Expression.traverseExpOpt(max,func,outExtraArg); - (i,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); - (f,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); - (n,outExtraArg) = Expression.traverseExpOpt(n,func,outExtraArg); - (eqbound,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); - (dist,outExtraArg) = traverseBackendDAEAttrDistribution(dist,func,outExtraArg); - then (SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,i,f,n,ss,unc,dist,eqbound,p,fin,startOrigin)),outExtraArg); + (q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); + (u_,outExtraArg) = Expression.traverseExpOpt(u,func,outExtraArg); + (du_,outExtraArg) = Expression.traverseExpOpt(du,func,outExtraArg); + (min_,outExtraArg) = Expression.traverseExpOpt(min,func,outExtraArg); + (max_,outExtraArg) = Expression.traverseExpOpt(max,func,outExtraArg); + (i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); + (f_,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); + (n_,outExtraArg) = Expression.traverseExpOpt(n,func,outExtraArg); + (eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); + (dist_,outExtraArg) = traverseBackendDAEAttrDistribution(dist,func,outExtraArg); + if referenceEq(q,q_) and referenceEq(u,u_) and referenceEq(du,du_) and referenceEq(min,min_) and referenceEq(max,max_) and referenceEq(i,i_) and referenceEq(f,f_) and referenceEq(n,n_) + and referenceEq(eqbound,eqbound_) and referenceEq(dist,dist_) then + a = attr; + else + a = SOME(DAE.VAR_ATTR_REAL(q_,u_,du_,min_,max_,i_,f_,n_,ss,unc,dist_,eqbound_,p,fin,startOrigin)); + end if; + then (a,outExtraArg); case(SOME(DAE.VAR_ATTR_INT(q,min,max,i,f,unc,dist,eqbound,p,fin,startOrigin)),_,_) equation - (q,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); - (min,outExtraArg) = Expression.traverseExpOpt(min,func,outExtraArg); - (max,outExtraArg) = Expression.traverseExpOpt(max,func,outExtraArg); - (i,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); - (f,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); - (eqbound,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); - (dist,outExtraArg) = traverseBackendDAEAttrDistribution(dist,func,outExtraArg); - then (SOME(DAE.VAR_ATTR_INT(q,min,max,i,f,unc,dist,eqbound,p,fin,startOrigin)),outExtraArg); + (q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); + (min_,outExtraArg) = Expression.traverseExpOpt(min,func,outExtraArg); + (max_,outExtraArg) = Expression.traverseExpOpt(max,func,outExtraArg); + (i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); + (f_,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); + (eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); + (dist_,outExtraArg) = traverseBackendDAEAttrDistribution(dist,func,outExtraArg); + if referenceEq(q,q_) and referenceEq(min,min_) and referenceEq(max,max_) and referenceEq(i,i_) and referenceEq(f,f_) + and referenceEq(eqbound,eqbound_) and referenceEq(dist,dist_) then + a = attr; + else + a = SOME(DAE.VAR_ATTR_INT(q_,min_,max_,i_,f_,unc,dist_,eqbound_,p,fin,startOrigin)); + end if; + then (a,outExtraArg); case(SOME(DAE.VAR_ATTR_BOOL(q,i,f,eqbound,p,fin,startOrigin)),_,_) equation - (q,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); - (i,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); - (f,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); - (eqbound,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); - then (SOME(DAE.VAR_ATTR_BOOL(q,i,f,eqbound,p,fin,startOrigin)),outExtraArg); + (q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); + (i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); + (f_,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); + (eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); + if referenceEq(q,q_) and referenceEq(i,i_) and referenceEq(f,f_) and referenceEq(eqbound,eqbound_) then + a = attr; + else + a = SOME(DAE.VAR_ATTR_BOOL(q_,i_,f_,eqbound_,p,fin,startOrigin)); + end if; + then (a,outExtraArg); case(SOME(DAE.VAR_ATTR_STRING(q,i,eqbound,p,fin,startOrigin)),_,_) equation - (q,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); - (i,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); - (eqbound,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); - then (SOME(DAE.VAR_ATTR_STRING(q,i,eqbound,p,fin,startOrigin)),outExtraArg); + (q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); + (i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); + (eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); + if referenceEq(q,q_) and referenceEq(i,i_) and referenceEq(eqbound,eqbound_) then + a = attr; + else + a = SOME(DAE.VAR_ATTR_STRING(q_,i_,eqbound_,p,fin,startOrigin)); + end if; + then (a,outExtraArg); case(SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,i,f,eqbound,p,fin,startOrigin)),_,_) equation - (q,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); - (min,outExtraArg) = Expression.traverseExpOpt(min,func,outExtraArg); - (max,outExtraArg) = Expression.traverseExpOpt(max,func,outExtraArg); - (i,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); - (f,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); - (eqbound,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); - then (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,i,f,eqbound,p,fin,startOrigin)),outExtraArg); + (q_,outExtraArg) = Expression.traverseExpOpt(q,func,extraArg); + (min_,outExtraArg) = Expression.traverseExpOpt(min,func,outExtraArg); + (max_,outExtraArg) = Expression.traverseExpOpt(max,func,outExtraArg); + (i_,outExtraArg) = Expression.traverseExpOpt(i,func,outExtraArg); + (f_,outExtraArg) = Expression.traverseExpOpt(f,func,outExtraArg); + (eqbound_,outExtraArg) = Expression.traverseExpOpt(eqbound,func,outExtraArg); + if referenceEq(q,q_) and referenceEq(min,min_) and referenceEq(max,max_) and referenceEq(i,i_) and referenceEq(f,f_) and referenceEq(eqbound,eqbound_) then + a = attr; + else + a = SOME(DAE.VAR_ATTR_ENUMERATION(q_,min_,max_,i_,f_,eqbound_,p,fin,startOrigin)); + end if; + then (a,outExtraArg); case(SOME(DAE.VAR_ATTR_CLOCK(p, fin)),_,_) - then (SOME(DAE.VAR_ATTR_CLOCK(p,fin)),extraArg); + then (attr,extraArg); end match; end traverseBackendDAEVarAttr; @@ -6376,16 +6416,23 @@ algorithm (outDistOpt,outExtraArg) := match(distOpt,func,extraArg) local DAE.Exp name,arr,sarr; + DAE.Exp name_,arr_,sarr_; + Option d; case(NONE(),_,outExtraArg) then (NONE(),outExtraArg); case(SOME(DAE.DISTRIBUTION(name,arr,sarr)),_,_) equation - (arr,_) = Expression.extendArrExp(arr,false); - (sarr,_) = Expression.extendArrExp(sarr,false); - (name,outExtraArg) = Expression.traverseExpBottomUp(name,func,extraArg); - (arr,outExtraArg) = Expression.traverseExpBottomUp(arr,func,outExtraArg); - (sarr,outExtraArg) = Expression.traverseExpBottomUp(sarr,func,outExtraArg); - then (SOME(DAE.DISTRIBUTION(name,arr,sarr)),outExtraArg); + (arr_,_) = Expression.extendArrExp(arr,false); + (sarr_,_) = Expression.extendArrExp(sarr,false); + (name_,outExtraArg) = Expression.traverseExpBottomUp(name,func,extraArg); + (arr_,outExtraArg) = Expression.traverseExpBottomUp(arr_,func,outExtraArg); + (sarr_,outExtraArg) = Expression.traverseExpBottomUp(sarr_,func,outExtraArg); + if referenceEq(name, name_) and referenceEq(arr, arr_) and referenceEq(sarr, sarr_) then + d = distOpt; + else + d = SOME(DAE.DISTRIBUTION(name_,arr_,sarr_)); + end if; + then (d,outExtraArg); end match; end traverseBackendDAEAttrDistribution; diff --git a/Compiler/BackEnd/BackendVariable.mo b/Compiler/BackEnd/BackendVariable.mo index e0d3d5ea3ef..ceac805ac6a 100644 --- a/Compiler/BackEnd/BackendVariable.mo +++ b/Compiler/BackEnd/BackendVariable.mo @@ -2747,7 +2747,7 @@ algorithm case (_,_) /* check if array or record */ equation crlst = ComponentReference.expandCref(cr,true); - (vLst as _::_,indxs) = getVarLst(crlst,inVariables,{},{}); + (vLst as _::_,indxs) = getVarLst(crlst,inVariables); then (vLst,indxs); // try again check if variable indexes used @@ -2756,7 +2756,7 @@ algorithm // replace variables with WHOLEDIM() (cr1,true) = replaceVarWithWholeDim(cr, false); crlst = ComponentReference.expandCref(cr1,true); - (vLst as _::_,indxs) = getVarLst(crlst,inVariables,{},{}); + (vLst as _::_,indxs) = getVarLst(crlst,inVariables); then (vLst,indxs); /* failure @@ -2876,32 +2876,21 @@ end computeRangeExps; public function getVarLst input list inComponentRefLst; input BackendDAE.Variables inVariables; - input list inVarLst; - input list iIntegerLst; - output list outVarLst; - output list outIntegerLst; + output list outVarLst = {}; + output list outIntegerLst = {}; +protected + BackendDAE.Var v; + Integer indx; algorithm - (outVarLst,outIntegerLst) := matchcontinue(inComponentRefLst,inVariables,inVarLst,iIntegerLst) - local - list crlst; - DAE.ComponentRef cr; - list varlst; - list ilst; - BackendDAE.Var v; - Integer indx; - case ({},_,_,_) then (inVarLst,iIntegerLst); - case (cr::crlst,_,_,_) - equation - (v,indx) = getVar2(cr, inVariables); - (varlst,ilst) = getVarLst(crlst,inVariables,v::inVarLst,indx::iIntegerLst); - then - (varlst,ilst); - case (_::crlst,_,_,_) - equation - (varlst,ilst) = getVarLst(crlst,inVariables,inVarLst,iIntegerLst); - then - (varlst,ilst); - end matchcontinue; + for cr in inComponentRefLst loop + try + (v,indx) := getVar2(cr, inVariables); + outVarLst := v::outVarLst; + outIntegerLst := indx::outIntegerLst; + else + // skip this element + end try; + end for; end getVarLst; public function getVar2 diff --git a/Compiler/BackEnd/Differentiate.mo b/Compiler/BackEnd/Differentiate.mo index a2450d9b3c9..b6eb60f3f76 100644 --- a/Compiler/BackEnd/Differentiate.mo +++ b/Compiler/BackEnd/Differentiate.mo @@ -2689,7 +2689,7 @@ algorithm case((var as DAE.VAR(binding=SOME(binding)))::rest, _, BackendDAE.DIFFINPUTDATA(independenentVars=SOME(timevars)), _, _, _, _, _) equation // check if bindung depends on independentVars crefLst = Expression.extractCrefsFromExp(binding); - ({},{}) = BackendVariable.getVarLst(crefLst, timevars, {}, {}); + ({},{}) = BackendVariable.getVarLst(crefLst, timevars); vars = var::inElementsNoDer; blst = false::inBooleanLst; diff --git a/Compiler/BackEnd/Matching.mo b/Compiler/BackEnd/Matching.mo index 249513174f8..f73054e3513 100644 --- a/Compiler/BackEnd/Matching.mo +++ b/Compiler/BackEnd/Matching.mo @@ -5658,7 +5658,7 @@ algorithm for eq in BackendEquation.equationList(eqs) loop (hasNoDerAnno,noDerInputs) := BackendDAEUtil.isFuncCallWithNoDerAnnotation(eq,functionTree); if hasNoDerAnno then - (_,varIdxs) := BackendVariable.getVarLst(noDerInputs,vars,{},{}); + (_,varIdxs) := BackendVariable.getVarLst(noDerInputs,vars); //print("remove edges between eq: "+intString(idx)+" and vars "+stringDelimitList(List.map(varIdxs,intString),", ")+"\n"); //update m row := m[idx]; diff --git a/Compiler/BackEnd/OnRelaxation.mo b/Compiler/BackEnd/OnRelaxation.mo index 002e46c2274..41ed08fbb54 100644 --- a/Compiler/BackEnd/OnRelaxation.mo +++ b/Compiler/BackEnd/OnRelaxation.mo @@ -3319,7 +3319,7 @@ algorithm set = addCrefandParentsToSet(crnosubs, set, NONE()); set = List.fold(crlst, BaseHashSet.add, set); (_, (_, false)) = Expression.traverseExpTopDown(e2, expHasCreftraverser, (set, false)); - (_, ilst) = BackendVariable.getVarLst(crlst, vars, {}, {}); + (_, ilst) = BackendVariable.getVarLst(crlst, vars); // unassgned unassignedLst(ilst, vec1); // assign @@ -3343,7 +3343,7 @@ algorithm set = addCrefandParentsToSet(crnosubs, set, NONE()); set = List.fold(crlst, BaseHashSet.add, set); (_, (_, false)) = Expression.traverseExpTopDown(e1, expHasCreftraverser, (set, false)); - (_, ilst) = BackendVariable.getVarLst(crlst, vars, {}, {}); + (_, ilst) = BackendVariable.getVarLst(crlst, vars); // unassgned unassignedLst(ilst, vec1); // assign diff --git a/Compiler/BackEnd/ResolveLoops.mo b/Compiler/BackEnd/ResolveLoops.mo index 861d50a6623..9cd16ab123c 100644 --- a/Compiler/BackEnd/ResolveLoops.mo +++ b/Compiler/BackEnd/ResolveLoops.mo @@ -117,7 +117,7 @@ algorithm eqMapping = List.map1(simpEqLst,List.position,eqLst); simpEqs = BackendEquation.listEquation(simpEqLst); crefs = BackendEquation.getAllCrefFromEquations(simpEqs); - (simpVarLst,varMapping) = BackendVariable.getVarLst(crefs,vars,{},{}); + (simpVarLst,varMapping) = BackendVariable.getVarLst(crefs,vars); simpVars = BackendVariable.listVar1(simpVarLst); // build the incidence matrix for the linear equations diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index 125878b68c1..01492a75bf1 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -5913,20 +5913,24 @@ algorithm local Option o1; Option o2; - DAE.Exp startValue; - DAE.VariableAttributes attr; + DAE.Exp startValue, startValue_; + DAE.VariableAttributes attr, attr_; case(BackendDAE.VAR(bindExp = o1, values = o2), _) equation if isSome(o1) then startValue = Util.getOption(o1); - startValue = EvaluateFunctions.evaluateConstantFunctionCallExp(startValue,funcTreeIn); - inVar.bindExp = SOME(startValue); + startValue_ = EvaluateFunctions.evaluateConstantFunctionCallExp(startValue,funcTreeIn); + if not referenceEq(startValue, startValue_) then + inVar.bindExp = SOME(startValue_); + end if; end if; if isSome(o2) then attr = Util.getOption(o2); - attr = evaluateVariableAttributes(attr,funcTreeIn); - inVar.values = SOME(attr); + attr_ = evaluateVariableAttributes(attr,funcTreeIn); + if not referenceEq(attr, attr_) then + inVar.values = SOME(attr_); + end if; end if; then (inVar,funcTreeIn); @@ -5942,11 +5946,13 @@ protected function evaluateVariableAttributes"evaluates functions in the start v algorithm attrOut := matchcontinue(attrIn, funcTree) local - DAE.Exp exp; + DAE.Exp exp, exp_; case(DAE.VAR_ATTR_REAL(start=SOME(exp)),_) equation - exp = EvaluateFunctions.evaluateConstantFunctionCallExp(exp,funcTree); - attrIn.start = SOME(exp); + exp_ = EvaluateFunctions.evaluateConstantFunctionCallExp(exp,funcTree); + if not referenceEq(exp, exp_) then + attrIn.start = SOME(exp); + end if; then attrIn; else then attrIn; @@ -6113,7 +6119,7 @@ algorithm Option> optionExpisASUB; BackendDAE.Var var; DAE.ComponentRef cref; - DAE.Exp exp, exp1, exp2, exp3, startTime; + DAE.Exp exp, exp1, exp2, exp3, startTime, exp1_, exp2_, exp3_; DAE.Operator op; list expLst; @@ -6151,15 +6157,25 @@ algorithm case(DAE.BINARY(exp1=exp1,operator=op,exp2=exp2),_) equation - exp1 = replaceCrefWithStartValue(exp1,varsIn); - exp2 = replaceCrefWithStartValue(exp2,varsIn); - then (DAE.BINARY(exp1,op,exp2),varsIn); + exp1_ = replaceCrefWithStartValue(exp1,varsIn); + exp2_ = replaceCrefWithStartValue(exp2,varsIn); + if referenceEq(exp1, exp1_) and referenceEq(exp2,exp2_) then + exp = expIn; + else + exp = DAE.BINARY(exp1_,op,exp2_); + end if; + then (exp,varsIn); case(DAE.LBINARY(exp1=exp1,operator=op,exp2=exp2),_) equation - exp1 = replaceCrefWithStartValue(exp1,varsIn); - exp2 = replaceCrefWithStartValue(exp2,varsIn); - then (DAE.LBINARY(exp1,op,exp2),varsIn); + exp1_ = replaceCrefWithStartValue(exp1,varsIn); + exp2_ = replaceCrefWithStartValue(exp2,varsIn); + if referenceEq(exp1, exp1_) and referenceEq(exp2,exp2_) then + exp = expIn; + else + exp = DAE.LBINARY(exp1_,op,exp2_); + end if; + then (exp,varsIn); // time > -1.0 or similar case(DAE.RELATION(exp1=DAE.CREF(componentRef=DAE.CREF_IDENT(ident="time")),operator=DAE.GREATER(),exp2=DAE.RCONST(real=r),index=idx,optionExpisASUB=optionExpisASUB),_) @@ -6187,17 +6203,27 @@ algorithm case(DAE.RELATION(exp1=exp1,operator=op,exp2=exp2,index=idx,optionExpisASUB=optionExpisASUB),_) equation - exp1 = replaceCrefWithStartValue(exp1,varsIn); - exp2 = replaceCrefWithStartValue(exp2,varsIn); - then (DAE.RELATION(exp1,op,exp2,idx,optionExpisASUB),varsIn); + exp1_ = replaceCrefWithStartValue(exp1,varsIn); + exp2_ = replaceCrefWithStartValue(exp2,varsIn); + if referenceEq(exp1, exp1_) and referenceEq(exp2,exp2_) then + exp = expIn; + else + exp = DAE.RELATION(exp1_,op,exp2_,idx,optionExpisASUB); + end if; + then (exp,varsIn); case(DAE.IFEXP(expCond=exp1,expThen=exp2,expElse=exp3),_) equation //print("IFEXP: "+ExpressionDump.dumpExpStr(expIn,0)+"\n"); - exp1 = replaceCrefWithStartValue(exp1,varsIn); - exp2 = replaceCrefWithStartValue(exp2,varsIn); - exp3 = replaceCrefWithStartValue(exp3,varsIn); - then (DAE.IFEXP(exp1,exp2,exp3),varsIn); + exp1_ = replaceCrefWithStartValue(exp1,varsIn); + exp2_ = replaceCrefWithStartValue(exp2,varsIn); + exp3_ = replaceCrefWithStartValue(exp3,varsIn); + if referenceEq(exp1, exp1_) and referenceEq(exp2,exp2_) and referenceEq(exp3,exp3_) then + exp = expIn; + else + exp = DAE.IFEXP(exp1_,exp2_,exp3_); + end if; + then (exp,varsIn); else equation @@ -6517,8 +6543,8 @@ algorithm // figure out in which lists to put it isAlg := BackendVariable.isVarAlg(dlowVar); - isParam := BackendVariable.BackendVariable.isParam(dlowVar); - isConst := BackendVariable.BackendVariable.isConst(dlowVar); + isParam := BackendVariable.isParam(dlowVar); + isConst := BackendVariable.isConst(dlowVar); // for inputs and outputs we have additional lists if BackendVariable.isVarOnTopLevelAndInputNoDerInput(dlowVar) then @@ -9888,7 +9914,8 @@ algorithm Boolean partOfMixed; DAE.ComponentRef cr, left; DAE.ElementSource source; - DAE.Exp exp, right, leftexp; + DAE.Exp exp, exp_, right, leftexp; + SimCode.SimEqSystem eq_; Integer index, indexSys; Option symJac; Option alternativeTearingL; @@ -9910,12 +9937,22 @@ algorithm list whenStmtLst; case (SimCode.SES_RESIDUAL(index, exp, source), _, a) equation - (exp, a) = func(exp, a); - then (SimCode.SES_RESIDUAL(index, exp, source), a); + (exp_, a) = func(exp, a); + if referenceEq(exp,exp_) then + eq_ = eq; + else + eq_ = SimCode.SES_RESIDUAL(index, exp_, source); + end if; + then (eq_, a); case (SimCode.SES_SIMPLE_ASSIGN(index, cr, exp, source), _, a) equation - (exp, a) = func(exp, a); - then (SimCode.SES_SIMPLE_ASSIGN(index, cr, exp, source), a); + (exp_, a) = func(exp, a); + if referenceEq(exp,exp_) then + eq_ = eq; + else + eq_ = SimCode.SES_SIMPLE_ASSIGN(index, cr, exp_, source); + end if; + then (eq_, a); case (SimCode.SES_ARRAY_CALL_ASSIGN(index, leftexp, exp, source), _, a) equation (leftexp, a) = func(leftexp, a); @@ -9924,31 +9961,31 @@ algorithm case (SimCode.SES_IFEQUATION(index, ifbranches, elsebranch, source), _, a) /* TODO: Me */ - then (SimCode.SES_IFEQUATION(index, ifbranches, elsebranch, source), a); + then (eq, a); case (SimCode.SES_ALGORITHM(index, stmts), _, a) /* TODO: Me */ - then (SimCode.SES_ALGORITHM(index, stmts), a); + then (eq, a); case (SimCode.SES_INVERSE_ALGORITHM(index, stmts, crefs), _, a) /* TODO: Me */ - then (SimCode.SES_INVERSE_ALGORITHM(index, stmts, crefs), a); + then (eq, a); case (SimCode.SES_LINEAR(lSystem, alternativeTearingL), _, a) /* TODO: Me */ - then (SimCode.SES_LINEAR(lSystem, alternativeTearingL), a); + then (eq, a); case (SimCode.SES_NONLINEAR(nlSystem, alternativeTearingNl), _, a) /* TODO: Me */ - then (SimCode.SES_NONLINEAR(nlSystem, alternativeTearingNl), a); + then (eq, a); case (SimCode.SES_MIXED(index, cont, discVars, discEqs, indexSys), _, a) /* TODO: Me */ - then (SimCode.SES_MIXED(index, cont, discVars, discEqs, indexSys), a); + then (eq, a); case (SimCode.SES_WHEN(index, conditions, initialCall, whenStmtLst, elseWhen, source), _, a) /* TODO: Me */ - then (SimCode.SES_WHEN(index, conditions, initialCall, whenStmtLst, elseWhen, source), a); + then (eq, a); case (SimCode.SES_FOR_LOOP(), _, a) /* TODO: Me */