Skip to content

Commit 9002e08

Browse files
committed
- Removed Array.append (since we have arrayAppend now).
- Optimized some Array functions. - Some random cleanups. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23147 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d51b7bf commit 9002e08

File tree

8 files changed

+249
-343
lines changed

8 files changed

+249
-343
lines changed

Compiler/BackEnd/EvaluateFunctions.mo

Lines changed: 86 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,12 +2243,11 @@ algorithm
22432243
equation
22442244
names = List.map(varLst,DAEUtil.typeVarIdent);
22452245
//print("the names for the scalar complex crefs: "+stringDelimitList(names,"\n;")+"\n");
2246-
types = List.map(varLst,DAEUtil.VarType);
2246+
types = List.map(varLst,DAEUtil.varType);
22472247
crefs = List.map1(names,ComponentReference.appendStringCref,cref);
2248-
crefs = setTypesForScalarCrefs(crefs,types,{});
2248+
crefs = setTypesForScalarCrefs(crefs,types);
22492249
crefLst = List.map1(crefs,ComponentReference.expandCref,true);
22502250
crefs = List.flatten(crefLst);
2251-
crefs = listReverse(crefs);
22522251
then
22532252
crefs;
22542253
case(DAE.VAR(componentRef=cref,ty=DAE.T_REAL(varLst=_, source=_), dims=dims ))
@@ -2302,86 +2301,39 @@ algorithm
23022301
local
23032302
list<Integer> dimints;
23042303
list<DAE.Dimension> dims;
2305-
case(DAE.VAR(componentRef = _,ty=DAE.T_COMPLEX(varLst = _)))
2306-
then
2307-
false;
2308-
case(DAE.VAR(componentRef=_,ty=DAE.T_REAL(varLst=_, source=_), dims=dims ))
2304+
2305+
case (DAE.VAR(ty=DAE.T_COMPLEX(_))) then false;
2306+
2307+
case (DAE.VAR(ty=DAE.T_REAL(_), dims=dims))
23092308
equation
23102309
dimints = List.map(dims, Expression.dimensionSize);
2311-
true = intNe(List.first(dimints),0);
2310+
true = List.first(dimints) <> 0;
23122311
then
23132312
false;
2314-
case(DAE.VAR(componentRef=_,ty=DAE.T_ARRAY(ty=_, dims=_, source=_), dims=dims ))
2315-
equation
2316-
then
2317-
false;
2318-
else
2319-
equation
2320-
then
2321-
true;
2313+
2314+
case (DAE.VAR(ty=DAE.T_ARRAY(_))) then false;
2315+
else true;
23222316
end matchcontinue;
23232317
end isNotComplexVar;
23242318

23252319
protected function setTypesForScalarCrefs
23262320
input list<DAE.ComponentRef> allCrefs;
23272321
input list<DAE.Type> types;
2328-
input list<DAE.ComponentRef> crefsIn;
23292322
output list<DAE.ComponentRef> crefsOut;
23302323
algorithm
2331-
crefsOut := match(allCrefs,types,crefsIn)
2332-
local
2333-
Integer idx;
2334-
DAE.ComponentRef cr1,cr2;
2335-
DAE.Ident id;
2336-
DAE.Type t1,t2;
2337-
list<DAE.ComponentRef> crest,crs;
2338-
list<DAE.Subscript> sl;
2339-
list<DAE.Type> trest;
2340-
case({},{},_)
2341-
equation
2342-
then crefsIn;
2343-
case(DAE.CREF_QUAL(ident=_,identType=_,subscriptLst=_,componentRef=_)::crest, t1::trest, _)
2344-
equation
2345-
cr1 = List.first(allCrefs);
2346-
cr1 = ComponentReference.crefSetLastType(cr1,t1);
2347-
crs = setTypesForScalarCrefs(crest,trest,cr1::crefsIn);
2348-
then
2349-
crs;
2350-
case(DAE.CREF_IDENT(ident=id,identType=_,subscriptLst=sl)::crest, t1::trest, _)
2351-
equation
2352-
cr1 = List.first(allCrefs);
2353-
cr1 = DAE.CREF_IDENT(id,t1,sl);
2354-
crs = setTypesForScalarCrefs(crest,trest,cr1::crefsIn);
2355-
then
2356-
crs;
2357-
case(DAE.CREF_ITER(ident=id,index=idx,identType=_,subscriptLst=sl)::crest, t1::trest, _)
2358-
equation
2359-
cr1 = List.first(allCrefs);
2360-
cr1 = DAE.CREF_ITER(id,idx,t1,sl);
2361-
crs = setTypesForScalarCrefs(crest,trest,cr1::crefsIn);
2362-
then
2363-
crs;
2364-
else
2365-
then
2366-
fail();
2367-
end match;
2324+
crefsOut := list(ComponentReference.crefSetLastType(cr, ty)
2325+
threaded for cr in allCrefs, ty in types);
23682326
end setTypesForScalarCrefs;
23692327

23702328
public function getRecordScalars"gets all crefs from a record"
23712329
input DAE.ComponentRef crefIn;
23722330
output list<DAE.ComponentRef> crefsOut;
23732331
algorithm
2374-
crefsOut := matchcontinue(crefIn)
2375-
local
2376-
case(_)
2377-
equation
2378-
crefsOut = ComponentReference.expandCref(crefIn,true);
2379-
then
2380-
crefsOut;
2332+
try
2333+
crefsOut := ComponentReference.expandCref(crefIn, true);
23812334
else
2382-
then
2383-
{};
2384-
end matchcontinue;
2335+
crefsOut := {};
2336+
end try;
23852337
end getRecordScalars;
23862338

23872339
protected function getScalarExpSize "gets the number of scalars of an expression.
@@ -2393,51 +2345,48 @@ algorithm
23932345
local
23942346
Boolean b;
23952347
DAE.ComponentRef cref;
2396-
list<Integer> sizes;
2397-
list<DAE.ComponentRef> crefs;
23982348
list<DAE.Exp> exps;
23992349
list<DAE.Var> vl;
24002350
list<DAE.Type> tyl;
2401-
list<list<DAE.Var>> vlLst;
2402-
DAE.Type ty;
2403-
case(DAE.TUPLE(exps))
2404-
equation
2405-
// tuple
2406-
exps = List.filterOnTrue(exps,Expression.isNotWild);
2407-
sizes = List.map(exps,getScalarExpSize);//check if the expressions are records or something
2408-
size = List.fold(sizes,intAdd,0);
2409-
size = intMax(size,listLength(exps));
2410-
then
2411-
size;
2412-
case(DAE.CREF(componentRef=_,ty=DAE.T_COMPLEX(varLst=vl)))
2413-
equation
2414-
// record cref
2415-
sizes = List.map(vl,getScalarVarSize);
2416-
size = List.fold(sizes,intAdd,0);
2417-
then
2418-
size;
2419-
case(DAE.CREF(componentRef=cref,ty=_))
2420-
equation
2421-
// array cref
2422-
b = ComponentReference.isArrayElement(cref);
2423-
crefs = if b then ComponentReference.expandCref(cref,true) else {cref};
2424-
size = listLength(crefs);
2425-
then
2426-
size;
2427-
case(DAE.CALL(path=_,expLst=_,attr=DAE.CALL_ATTR(ty=DAE.T_COMPLEX(varLst=vl),tuple_=_,builtin=_,isImpure=_,inlineType=_,tailCall=_)))
2428-
equation
2429-
sizes = List.map(vl,getScalarVarSize);
2430-
size = List.fold(sizes,intAdd,0);
2431-
then size;
2432-
case(DAE.CALL(path=_,expLst=exps,attr=DAE.CALL_ATTR(ty=DAE.T_TUPLE(tupleType=tyl,source=_),tuple_=_,builtin=_,isImpure=_,inlineType=_,tailCall=_)))
2433-
equation
2434-
vlLst = List.map(tyl,getVarLstFromType);
2435-
vl = List.flatten(vlLst);
2436-
sizes = List.map(vl,getScalarVarSize);
2437-
size = List.fold(sizes,intAdd,0);
2438-
then size;
2439-
else
2440-
then 0;
2351+
Integer exps_len;
2352+
2353+
// tuple
2354+
case DAE.TUPLE(exps as _ :: _)
2355+
algorithm
2356+
exps_len := intAdd(1 for exp guard(Expression.isNotWild(exp)) in exps);
2357+
size := intAdd(getScalarExpSize(exp) for exp in exps);
2358+
then
2359+
max(size, exps_len);
2360+
2361+
// record cref
2362+
case DAE.CREF(ty = DAE.T_COMPLEX(varLst = vl as _ :: _))
2363+
then intAdd(getScalarVarSize(v) for v in vl);
2364+
2365+
// array cref
2366+
case DAE.CREF(componentRef = cref)
2367+
algorithm
2368+
size := if ComponentReference.isArrayElement(cref) then
2369+
listLength(ComponentReference.expandCref(cref, true)) else 1;
2370+
then
2371+
size;
2372+
2373+
case DAE.CALL(attr = DAE.CALL_ATTR(ty = DAE.T_COMPLEX(varLst = vl as _ :: _)))
2374+
then intAdd(getScalarVarSize(v) for v in vl);
2375+
2376+
case DAE.CALL(expLst=exps, attr = DAE.CALL_ATTR(ty = DAE.T_TUPLE(tupleType = tyl as _ :: _)))
2377+
algorithm
2378+
size := 0;
2379+
for ty in tyl loop
2380+
vl := getVarLstFromType(ty);
2381+
2382+
if not listEmpty(vl) then
2383+
size := size + intAdd(getScalarVarSize(v) for v in vl);
2384+
end if;
2385+
end for;
2386+
then
2387+
size;
2388+
2389+
else 0;
24412390
end match;
24422391
end getScalarExpSize;
24432392

@@ -2449,25 +2398,14 @@ algorithm
24492398
varsOut := match(tyIn)
24502399
local
24512400
list<DAE.Var> varLst;
2452-
list<list<DAE.Var>> varLst2;
24532401
list<DAE.Type> tyLst;
2454-
case(DAE.T_TUPLE(tupleType=tyLst,source=_))
2455-
equation
2456-
varLst2 = List.map(tyLst,getVarLstFromType);
2457-
varLst = List.flatten(varLst2);
2458-
then
2459-
varLst;
2460-
case(DAE.T_COMPLEX(varLst = varLst))
2461-
equation
2462-
then
2463-
varLst;
2464-
case(DAE.T_SUBTYPE_BASIC(varLst = varLst))
2465-
equation
2466-
then
2467-
varLst;
2468-
else
2469-
then
2470-
{};
2402+
2403+
case DAE.T_TUPLE(tupleType = tyLst as _ :: _)
2404+
then listAppend(getVarLstFromType(ty) for ty in tyLst);
2405+
2406+
case DAE.T_COMPLEX(varLst = varLst) then varLst;
2407+
case DAE.T_SUBTYPE_BASIC(varLst = varLst) then varLst;
2408+
else {};
24712409
end match;
24722410
end getVarLstFromType;
24732411

@@ -2476,30 +2414,19 @@ author:Waurich TUD 2014-04"
24762414
input DAE.Var inVar;
24772415
output Integer size;
24782416
algorithm
2479-
size := matchcontinue(inVar)
2417+
size := match(inVar)
24802418
local
24812419
DAE.Type ty;
2482-
list<Integer> sizes;
2483-
list<DAE.Exp> exps;
24842420
list<DAE.Var> vl;
2485-
case(DAE.TYPES_VAR(name=_,attributes=_,ty=DAE.T_COMPLEX(complexClassType=_,varLst=vl,equalityConstraint=_,source=_),binding=_,constOfForIteratorRange=_))
2486-
equation
2487-
sizes = List.map(vl,getScalarVarSize);
2488-
size = List.fold(sizes,intAdd,0);
2489-
then
2490-
size;
2491-
case(DAE.TYPES_VAR(name=_,attributes=_,ty=DAE.T_ARRAY(ty=_,dims=_,source=_),binding=_,constOfForIteratorRange=_))
2492-
equation
2493-
ty = DAEUtil.VarType(inVar);
2494-
sizes = DAEUtil.expTypeArrayDimensions(ty);
2495-
size = List.fold(sizes,intAdd,0);
2496-
then
2497-
size;
2498-
else
2499-
equation
2500-
then
2501-
1;
2502-
end matchcontinue;
2421+
2422+
case DAE.TYPES_VAR(ty = DAE.T_COMPLEX(varLst = vl as _ :: _))
2423+
then intAdd(getScalarVarSize(v) for v in vl);
2424+
2425+
case DAE.TYPES_VAR(ty = ty as DAE.T_ARRAY(_))
2426+
then intMul(sz for sz in DAEUtil.expTypeArrayDimensions(ty));
2427+
2428+
else 1;
2429+
end match;
25032430
end getScalarVarSize;
25042431

25052432

@@ -2921,51 +2848,30 @@ protected function convertTupleEquations "author:Waurich TUD 2014-04
29212848
output BackendDAE.Equation eqOut;
29222849
output list<BackendDAE.Equation> addEqsOut;
29232850
algorithm
2924-
(eqOut, addEqsOut) := matchcontinue (eqIn, addEqsIn)
2851+
(eqOut, addEqsOut) := match(eqIn)
29252852
local
2926-
BackendDAE.Equation eq;
29272853
DAE.Exp lhsExp, rhsExp;
29282854
list<DAE.Exp> lhs, rhs;
2855+
BackendDAE.Equation eq;
29292856
list<BackendDAE.Equation> eqs;
29302857

2931-
case (BackendDAE.COMPLEX_EQUATION(left=lhsExp, right=rhsExp), _) equation
2932-
DAE.TUPLE(lhs) = lhsExp;
2933-
DAE.TUPLE(rhs) = rhsExp;
2934-
eqs = makeBackendEquation(lhs, rhs, {});
2935-
eq::eqs = eqs;
2936-
eqs = listAppend(eqs, addEqsIn);
2937-
then (eq, eqs);
2858+
case BackendDAE.COMPLEX_EQUATION(left = DAE.TUPLE(lhs), right = DAE.TUPLE(rhs))
2859+
algorithm
2860+
eq :: eqs := list(makeBackendEquation(lh, rh) threaded for lh in lhs, rh in rhs);
2861+
then
2862+
(eq, listAppend(eqs, addEqsIn));
29382863

2939-
else
2940-
then (eqIn, addEqsIn);
2941-
end matchcontinue;
2864+
else (eqIn, addEqsIn);
2865+
end match;
29422866
end convertTupleEquations;
29432867

29442868
protected function makeBackendEquation "author:Waurich TUD 2014-04
2945-
builds backendEquations for the list of lhs-exps and rhs-exps"
2946-
input list<DAE.Exp> ls;
2947-
input list<DAE.Exp> rs;
2948-
input list<BackendDAE.Equation> eqLstIn;
2949-
output list<BackendDAE.Equation> eqLstOut;
2869+
builds a backendEquation for the lhs-exp and rhs-exp"
2870+
input DAE.Exp ls;
2871+
input DAE.Exp rs;
2872+
output BackendDAE.Equation eq;
29502873
algorithm
2951-
eqLstOut := match(ls, rs, eqLstIn)
2952-
local
2953-
list<DAE.Exp> lrest;
2954-
list<DAE.Exp> rrest;
2955-
BackendDAE.Equation eq;
2956-
list<BackendDAE.Equation> eqLst;
2957-
DAE.Exp l;
2958-
DAE.Exp r;
2959-
2960-
case ({}, {}, _)
2961-
then eqLstIn;
2962-
2963-
case (l::lrest, r::rrest, _) equation
2964-
eq = BackendDAE.EQUATION(r, l, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
2965-
eqLst = eq::eqLstIn;
2966-
eqLst = makeBackendEquation(lrest, rrest, eqLst);
2967-
then eqLst;
2968-
end match;
2874+
eq := BackendDAE.EQUATION(rs, ls, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
29692875
end makeBackendEquation;
29702876

29712877
annotation(__OpenModelica_Interface="backend");

Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,14 +2923,14 @@ algorithm
29232923
simCode = TDS_updateModelInfo(simCode,idcs);
29242924
numDupl = List.fold(List.map(duplComps,listLength),intAdd,0);
29252925
procAss = Array.map(procAss,listReverse);
2926-
sccSimEqMap = Array.append(iSccSimEqMapping,listArray(listReverse(duplSccSimEqMap)));
2927-
comps = Array.append(inComps,listArray(listReverse(duplComps)));
2928-
varCompMapping = Array.append(varCompMapping,arrayCreate(numDupl,(0,0,0)));
2929-
eqCompMapping = Array.append(eqCompMapping,arrayCreate(numDupl,(0,0,0)));
2930-
nodeNames = Array.append(nodeNames,arrayCreate(numDupl,"duplicated"));
2931-
nodeDescs = Array.append(nodeDescs,arrayCreate(numDupl,"duplicated"));
2932-
exeCosts = Array.append(exeCosts,arrayCreate(numDupl,(1,1.0)));
2933-
nodeMark = Array.append(nodeMark,arrayCreate(numDupl,-1));
2926+
sccSimEqMap = arrayAppend(iSccSimEqMapping,listArray(listReverse(duplSccSimEqMap)));
2927+
comps = arrayAppend(inComps,listArray(listReverse(duplComps)));
2928+
varCompMapping = arrayAppend(varCompMapping,arrayCreate(numDupl,(0,0,0)));
2929+
eqCompMapping = arrayAppend(eqCompMapping,arrayCreate(numDupl,(0,0,0)));
2930+
nodeNames = arrayAppend(nodeNames,arrayCreate(numDupl,"duplicated"));
2931+
nodeDescs = arrayAppend(nodeDescs,arrayCreate(numDupl,"duplicated"));
2932+
exeCosts = arrayAppend(exeCosts,arrayCreate(numDupl,(1,1.0)));
2933+
nodeMark = arrayAppend(nodeMark,arrayCreate(numDupl,-1));
29342934
meta = HpcOmTaskGraph.TASKGRAPHMETA(comps,varCompMapping,eqCompMapping,rootNodes,nodeNames,nodeDescs,exeCosts,commCosts,nodeMark);
29352935
//assign new simEqSysIndexes
29362936
newIdxAss = arrayCreate(SimCodeUtil.getMaxSimEqSystemIndex(simCode),-1);

0 commit comments

Comments
 (0)