Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit c0d2c57

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve Ceval.evalArrayConstructor.
- Improve the performance of evalArrayConstructor by precomputing the types of the created arrays. Belonging to [master]: - #2874
1 parent 973bab3 commit c0d2c57

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ algorithm
15221522
evalNormalCall(call.fn, args);
15231523

15241524
case Call.TYPED_ARRAY_CONSTRUCTOR()
1525-
then evalArrayConstructor(call.exp, call.ty, call.iters);
1525+
then evalArrayConstructor(call.exp, call.iters);
15261526

15271527
case Call.TYPED_REDUCTION()
15281528
then evalReduction(call.fn, call.exp, call.ty, call.iters);
@@ -2697,17 +2697,26 @@ end evalSolverClock;
26972697

26982698
function evalArrayConstructor
26992699
input Expression exp;
2700-
input Type ty;
27012700
input list<tuple<InstNode, Expression>> iterators;
27022701
output Expression result;
27032702
protected
27042703
Expression e;
27052704
list<Expression> ranges;
27062705
list<Mutable<Expression>> iters;
2706+
list<Type> types = {};
2707+
Type ty;
27072708
algorithm
27082709
e := evalExpPartial(exp);
27092710
(e, ranges, iters) := createIterationRanges(e, iterators);
2710-
result := evalArrayConstructor2(e, ranges, iters);
2711+
2712+
// Precompute all the types we're going to need for the arrays created.
2713+
ty := Expression.typeOf(e);
2714+
for r in ranges loop
2715+
ty := Type.liftArrayLeftList(ty, Type.arrayDims(Expression.typeOf(r)));
2716+
types := ty :: types;
2717+
end for;
2718+
2719+
result := evalArrayConstructor2(e, ranges, iters, types);
27112720
end evalArrayConstructor;
27122721

27132722
function createIterationRanges
@@ -2733,6 +2742,7 @@ function evalArrayConstructor2
27332742
input Expression exp;
27342743
input list<Expression> ranges;
27352744
input list<Mutable<Expression>> iterators;
2745+
input list<Type> types;
27362746
output Expression result;
27372747
protected
27382748
Expression range, e;
@@ -2742,27 +2752,22 @@ protected
27422752
ExpressionIterator range_iter;
27432753
Expression value;
27442754
Type ty;
2755+
list<Type> rest_ty;
27452756
algorithm
27462757
if listEmpty(ranges) then
27472758
result := evalExp(exp);
27482759
else
27492760
range :: ranges_rest := ranges;
27502761
iter :: iters_rest := iterators;
2762+
ty :: rest_ty := types;
27512763
range_iter := ExpressionIterator.fromExp(range);
27522764

27532765
while ExpressionIterator.hasNext(range_iter) loop
27542766
(range_iter, value) := ExpressionIterator.next(range_iter);
27552767
Mutable.update(iter, value);
2756-
expl := evalArrayConstructor2(exp, ranges_rest, iters_rest) :: expl;
2768+
expl := evalArrayConstructor2(exp, ranges_rest, iters_rest, rest_ty) :: expl;
27572769
end while;
27582770

2759-
if listEmpty(expl) then
2760-
ty := Type.unliftArray(Expression.typeOf(exp));
2761-
else
2762-
ty := Expression.typeOf(listHead(expl));
2763-
end if;
2764-
2765-
ty := Type.liftArrayLeft(ty, Dimension.fromInteger(listLength(expl)));
27662771
result := Expression.makeArray(ty, listReverseInPlace(expl), literal = true);
27672772
end if;
27682773
end evalArrayConstructor2;

0 commit comments

Comments
 (0)