Changeset c0d2c572 in OpenModelica


Ignore:
Timestamp:
2019-01-15T11:22:22+01:00 (5 years ago)
Author:
hudson <openmodelica@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, master, omlib-staging
Children:
158a345
Parents:
973bab3
git-author:
Per Östlund <per.ostlund@…> (01/15/19 11:22:21)
git-committer:
hudson <openmodelica@…> (01/15/19 11:22:22)
Message:

[NF] Improve Ceval.evalArrayConstructor.

  • Improve the performance of evalArrayConstructor by precomputing the types of the created arrays.

Belonging to [master]:

  • OpenModelica/OMCompiler#2874
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Compiler/NFFrontEnd/NFCeval.mo

    r8481cc5 rc0d2c572  
    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()
     
    26982698function evalArrayConstructor
    26992699  input Expression exp;
    2700   input Type ty;
    27012700  input list<tuple<InstNode, Expression>> iterators;
    27022701  output Expression result;
     
    27052704  list<Expression> ranges;
    27062705  list<Mutable<Expression>> iters;
     2706  list<Type> types = {};
     2707  Type ty;
    27072708algorithm
    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);
    27112720end evalArrayConstructor;
    27122721
     
    27342743  input list<Expression> ranges;
    27352744  input list<Mutable<Expression>> iterators;
     2745  input list<Type> types;
    27362746  output Expression result;
    27372747protected
     
    27432753  Expression value;
    27442754  Type ty;
     2755  list<Type> rest_ty;
    27452756algorithm
    27462757  if listEmpty(ranges) then
     
    27492760    range :: ranges_rest := ranges;
    27502761    iter :: iters_rest := iterators;
     2762    ty :: rest_ty := types;
    27512763    range_iter := ExpressionIterator.fromExp(range);
    27522764
     
    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;
Note: See TracChangeset for help on using the changeset viewer.