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

Commit 8b4871a

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve function vectorization.
- Handle dimensions defined by an expression when vectorizing calls. Belonging to [master]: - #2420
1 parent c844742 commit 8b4871a

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,12 @@ uniontype Call
690690
i := 1;
691691

692692
for dim in vect_dims loop
693-
Error.assertion(Dimension.isKnown(dim), getInstanceName() +
693+
Error.assertion(Dimension.isKnown(dim, allowExp = true), getInstanceName() +
694694
" got unknown dimension for vectorized call", info);
695695

696696
// Create the range on which we will iterate to vectorize.
697697
ty := Type.ARRAY(Type.INTEGER(), {dim});
698-
exp := Expression.RANGE(ty, Expression.INTEGER(1), NONE(), Expression.INTEGER(Dimension.size(dim)));
698+
exp := Expression.RANGE(ty, Expression.INTEGER(1), NONE(), Dimension.sizeExp(dim));
699699

700700
// Create the iterator.
701701
iter := InstNode.fromComponent("$i" + intString(i),

Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,14 @@ public
209209

210210
function isKnown
211211
input Dimension dim;
212+
input Boolean allowExp = false;
212213
output Boolean known;
213214
algorithm
214215
known := match dim
215216
case INTEGER() then true;
216217
case BOOLEAN() then true;
217218
case ENUM() then true;
219+
case EXP() then allowExp;
218220
else false;
219221
end match;
220222
end isKnown;
@@ -256,8 +258,8 @@ public
256258
algorithm
257259
end toStringList;
258260

259-
function sizeExp
260-
"Returns the size of a dimension as an expression."
261+
function endExp
262+
"Returns an expression for the last index in a dimension."
261263
input Dimension dim;
262264
input ComponentRef cref;
263265
input Integer index;
@@ -276,6 +278,23 @@ public
276278
then Expression.SIZE(Expression.CREF(Type.INTEGER(), ComponentRef.stripSubscripts(cref)),
277279
SOME(Expression.INTEGER(index)));
278280
end match;
281+
end endExp;
282+
283+
function sizeExp
284+
"Returns the size of a dimension as an Expression."
285+
input Dimension dim;
286+
output Expression sizeExp;
287+
algorithm
288+
sizeExp := match dim
289+
local
290+
Type ty;
291+
292+
case INTEGER() then Expression.INTEGER(dim.size);
293+
case BOOLEAN() then Expression.INTEGER(2);
294+
case ENUM(enumType = ty as Type.ENUMERATION())
295+
then Expression.INTEGER(listLength(ty.literals));
296+
case EXP() then dim.exp;
297+
end match;
279298
end sizeExp;
280299

281300
function variability

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ function evaluateEnd
17881788
Type ty;
17891789
ComponentRef cr;
17901790

1791-
case Expression.END() then Dimension.sizeExp(dim, cref, index);
1791+
case Expression.END() then Dimension.endExp(dim, cref, index);
17921792

17931793
case Expression.CREF()
17941794
algorithm

0 commit comments

Comments
 (0)