Skip to content

Commit

Permalink
some minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel committed Jul 1, 2016
1 parent 3fd8767 commit dec4b30
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
9 changes: 3 additions & 6 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -999,7 +999,7 @@ algorithm
// BackendDump.debugStrExpStrExpStr(("Found ",ecr," = ",exp,"\n"));
expvars = BackendDAEUtil.incidenceRowExp(exp,vars,{},NONE(),BackendDAE.NORMAL());
// print("expvars "); BackendDump.debuglst((expvars,intString," ","\n"));
(expvars1::expvarseqns) = List.map1(expvars,varEqns,(pos,mT));
(expvars1::expvarseqns) = List.map2(expvars,varEqns,pos,mT);
// print("expvars1 "); BackendDump.debuglst((expvars1,intString," ","\n"));;
controleqns = getControlEqns(expvars1,expvarseqns);
// print("controleqns "); BackendDump.debuglst((controleqns,intString," ","\n"));
Expand Down Expand Up @@ -1059,15 +1059,12 @@ end functionCallEqn;
protected function varEqns
"author Frenkel TUD 2011-04"
input Integer v;
input tuple<Integer,BackendDAE.IncidenceMatrixT> inTpl;
input Integer pos;
input BackendDAE.IncidenceMatrixT mT;
output list<Integer> outVarEqns;
protected
Integer pos;
list<Integer> vareqns,vareqns1;
BackendDAE.IncidenceMatrix mT;
algorithm
pos := Util.tuple21(inTpl);
mT := Util.tuple22(inTpl);
vareqns := mT[intAbs(v)];
vareqns1 := List.map(vareqns, intAbs);
outVarEqns := List.removeOnTrue(intAbs(pos),intEq,vareqns1);
Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -1608,7 +1608,7 @@ protected function generateStateSets
protected
tuple<Integer,Integer,Integer,Integer,list<BackendDAE.Var>,list<BackendDAE.Equation>,list<BackendDAE.Var>,list<BackendDAE.Equation>> tpl;
list<BackendDAE.Var> setVars,aVars,varJ,otherVars,stateCandidates;
list<DAE.ComponentRef> crstates,crset;
list<DAE.ComponentRef> crset;
DAE.ComponentRef crA,set,crJ;
DAE.Type tp, tyExpCrStates;
Integer rang,nStates,nStateCandidates,nUnassignedEquations,setIndex,level;
Expand All @@ -1633,8 +1633,7 @@ algorithm
// add Equations
// set.x = set.A*set.statecandidates
// der(set.x) = set.A*der(set.candidates)
crstates := List.map(stateCandidates,BackendVariable.varCref);
expcrstates := List.map(crstates,Expression.crefExp);
expcrstates := List.map(stateCandidates,BackendVariable.varExp);
expcrstatesstart := List.map(expcrstates,makeStartExp);
expcrdstates := List.map(expcrstates,makeder);
expcrset := List.map(crset,Expression.crefExp);
Expand Down
38 changes: 17 additions & 21 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -694,21 +694,20 @@ a *(b+c) => a*b + a*c"
input DAE.Exp e;
output DAE.Exp outE;
algorithm
outE := matchcontinue(e)
outE := match(e)
local
DAE.Type tp;
DAE.Operator op;
DAE.Exp e1,e2,e21,e22;

case(DAE.BINARY(e1,DAE.MUL(tp),e2))
case(DAE.BINARY(e1,DAE.MUL(tp),e2 as DAE.BINARY(e21,op,e22))) guard isAddOrSub(op)
equation
DAE.BINARY(e21,op,e22) = expand(e2);
true = isAddOrSub(op);
then
DAE.BINARY(DAE.BINARY(e1,DAE.MUL(tp),e21),op,DAE.BINARY(e1,DAE.MUL(tp),e22));

else e;
end matchcontinue;
end match;
end expand;

public function expDer
Expand Down Expand Up @@ -802,7 +801,7 @@ algorithm
end addNoEventToRelationExp;

public function addNoEventToRelationsAndConds
"Function that adds a noEvent() call to all relations in an expression"
"Function that adds a noEvent() call to all relations in an expression"
input DAE.Exp e;
output DAE.Exp outE;
algorithm
Expand All @@ -817,14 +816,14 @@ algorithm
outExp := match e
local
DAE.Exp e1,e2,e3;
case DAE.RELATION() then makeNoEvent(e);
case DAE.RELATION() then makeNoEvent(e);
case DAE.IFEXP(e1,e2,e3) then DAE.IFEXP(makeNoEvent(e1),e2,e3);
else e;
end match;
end addNoEventToRelationandCondExp;

public function addNoEventToEventTriggeringFunctions
" Function that adds a noEvent() call to all event triggering functions in an expression"
" Function that adds a noEvent() call to all event triggering functions in an expression"
input DAE.Exp e;
output DAE.Exp outE;
algorithm
Expand Down Expand Up @@ -1311,6 +1310,7 @@ algorithm
case DAE.SUB_SCALAR_ARRAY() then true;
case DAE.DIV_SCALAR_ARRAY() then true;
case DAE.POW_SCALAR_ARRAY() then true;
else false;
end match;
end isScalarArrayOp;

Expand Down Expand Up @@ -2054,7 +2054,7 @@ public function subscriptDimension
input DAE.Subscript inSubscript;
output DAE.Dimension outDimension;
algorithm
outDimension := matchcontinue(inSubscript)
outDimension := match(inSubscript)
local
Integer x;
DAE.Exp e;
Expand All @@ -2066,14 +2066,12 @@ algorithm

// Special cases for non-expanded arrays
case DAE.WHOLE_NONEXP(exp = DAE.ICONST(x))
equation
false = Config.splitArrays();
guard not Config.splitArrays()
then
DAE.DIM_INTEGER(x);

case DAE.WHOLE_NONEXP(exp=e)
equation
false = Config.splitArrays();
guard not Config.splitArrays()
then
DAE.DIM_EXP(e);

Expand All @@ -2085,7 +2083,7 @@ algorithm
then
fail();

end matchcontinue;
end match;
end subscriptDimension;

public function arrayEltType
Expand Down Expand Up @@ -2131,8 +2129,7 @@ algorithm

case DAE.T_TUPLE(types=typs)
equation
lstInt = List.map(typs,sizeOf);
nr = List.reduce(lstInt, intAdd);
nr = List.applyAndFold(typs, intAdd, sizeOf, 0);
then
nr;
/* Size of Enumeration is 1 like a Integer
Expand Down Expand Up @@ -2398,7 +2395,7 @@ public function getRelations
input DAE.Exp inExp;
output list<DAE.Exp> outExpLst;
algorithm
outExpLst := matchcontinue (inExp)
outExpLst := match (inExp)
local
DAE.Exp e,e1,e2,cond,tb,fb;
list<DAE.Exp> rellst1,rellst2,rellst,rellst3,rellst4,xs;
Expand Down Expand Up @@ -2460,7 +2457,7 @@ algorithm
rellst;

else {};
end matchcontinue;
end match;
end getRelations;

public function getAllCrefs "author: lochel
Expand Down Expand Up @@ -2494,7 +2491,7 @@ public function allTerms
input DAE.Exp inExp;
output list<DAE.Exp> outExpLst;
algorithm
outExpLst := matchcontinue (inExp)
outExpLst := match (inExp)
local
list<DAE.Exp> f1,f2,res,f2_1;
DAE.Exp e1,e2,e;
Expand Down Expand Up @@ -2677,7 +2674,7 @@ algorithm
case (e as DAE.REDUCTION()) then {e};
*/
else {inExp};
end matchcontinue;
end match;
end allTerms;

public function allTermsForCref
Expand Down Expand Up @@ -4550,8 +4547,7 @@ algorithm
case DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(path)) equation
cr = DAE.CREF_IDENT("$TMP", inType, {});
crefs = ComponentReference.expandCref(cr, true);
expLst = List.map(crefs, crefExp);
typeLst = List.map(expLst, typeof);
typeLst = List.mapMap(crefs, crefExp, typeof);
expLst = List.map(typeLst, createZeroExpression);
varNames = List.map(varLst, varName);
e = DAE.RECORD(path, expLst, varNames, inType);
Expand Down
15 changes: 5 additions & 10 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1194,8 +1194,7 @@ algorithm

case Values.META_TUPLE(valueLst = vs)
equation
ts = List.map(vs, typeOfValue);
ts = List.map(ts, boxIfUnboxedType);
ts = List.mapMap(vs, typeOfValue, boxIfUnboxedType);
then
DAE.T_METATUPLE(ts,DAE.emptyTypeSource);

Expand Down Expand Up @@ -5497,8 +5496,7 @@ algorithm

case DAE.T_FUNCTION(funcArg = fargs,funcResultType = ty)
equation
tys = List.map(fargs, funcArgType);
explists = List.map(tys, getAllExps);
explists = List.mapMap(fargs, funcArgType, getAllExps);
tyexps = getAllExps(ty);
exps = List.flatten((tyexps :: explists));
then
Expand Down Expand Up @@ -5669,8 +5667,7 @@ algorithm

case DAE.T_METATUPLE()
equation
tys = List.map(ity.types, unboxedType);
tys = List.map(tys, boxIfUnboxedType);
tys = List.mapMap(ity.types, unboxedType, boxIfUnboxedType);
then
DAE.T_METATUPLE(tys,DAE.emptyTypeSource);

Expand Down Expand Up @@ -7308,8 +7305,7 @@ algorithm

case (true,DAE.T_METATUPLE(tys,_))
equation
tys = List.map(tys, unboxedType);
tys = List.map(tys, boxIfUnboxedType);
tys = List.mapMap(tys, unboxedType, boxIfUnboxedType);
tys = List.map(tys, unboxedType); // Yes. Crazy
then (DAE.T_TUPLE(tys,NONE(),DAE.emptyTypeSource));

Expand Down Expand Up @@ -7346,8 +7342,7 @@ algorithm

case (DAE.T_FUNCTION(args1,ty1,functionAttributes,ts))
equation
tys1 = List.map(args1, funcArgType);
tys1 = List.map(tys1, unboxedType);
tys1 = List.mapMap(args1, funcArgType, unboxedType);
ty1 = unboxedType(ty1);
args1 = List.threadMap(args1,tys1,setFuncArgType);
then (DAE.T_FUNCTION(args1,ty1,functionAttributes,ts));
Expand Down

0 comments on commit dec4b30

Please sign in to comment.