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

Commit ba58857

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve function vectorization.
- Merged Function.matchArgs and matchArgsVectorize, to avoid having to match functions twice when doing vectorization. - Handle vectorization over unknown dimensions by generating the appropriate size expressions. Belonging to [master]: - #2951 - OpenModelica/OpenModelica-testsuite#1129
1 parent 46fdf1a commit ba58857

File tree

4 files changed

+187
-184
lines changed

4 files changed

+187
-184
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,21 +1211,6 @@ protected
12111211
Type.toDAE(InstNode.getType(iter_node)));
12121212
end iteratorToDAE;
12131213

1214-
function matchFunction
1215-
input Function func;
1216-
input list<TypedArg> args;
1217-
input list<TypedNamedArg> named_args;
1218-
input SourceInfo info;
1219-
output list<TypedArg> out_args;
1220-
output Boolean matched;
1221-
output FunctionMatchKind matchKind;
1222-
algorithm
1223-
(out_args, matched) := Function.fillArgs(args, named_args, func, info);
1224-
if matched then
1225-
(out_args, matched, matchKind) := Function.matchArgs(func, out_args, info);
1226-
end if;
1227-
end matchFunction;
1228-
12291214
function vectorizeCall
12301215
input Call base_call;
12311216
input FunctionMatchKind mk;
@@ -1237,21 +1222,19 @@ protected
12371222
Expression exp;
12381223
list<tuple<InstNode, Expression>> iters;
12391224
InstNode iter;
1240-
Integer i;
1241-
list<Dimension> vect_dims;
1242-
list<Boolean> arg_is_vected, b_list;
1225+
Integer i, vect_idx;
12431226
Boolean b;
1244-
list<Expression> vect_args;
1227+
list<Expression> call_args, vect_args;
12451228
Subscript sub;
1229+
list<Integer> vect_idxs;
12461230
algorithm
1247-
vectorized_call := match base_call
1248-
case TYPED_CALL()
1231+
vectorized_call := match (base_call, mk)
1232+
case (TYPED_CALL(arguments = call_args), FunctionMatchKind.VECTORIZED())
12491233
algorithm
1250-
FunctionMatchKind.VECTORIZED(vect_dims, arg_is_vected) := mk;
12511234
iters := {};
12521235
i := 1;
12531236

1254-
for dim in vect_dims loop
1237+
for dim in mk.vectDims loop
12551238
Error.assertion(Dimension.isKnown(dim, allowExp = true), getInstanceName() +
12561239
" got unknown dimension for vectorized call", info);
12571240

@@ -1270,22 +1253,23 @@ protected
12701253
exp := Expression.CREF(Type.INTEGER(), ComponentRef.makeIterator(iter, Type.INTEGER()));
12711254
sub := Subscript.INDEX(exp);
12721255

1273-
vect_args := {};
1274-
b_list := arg_is_vected;
1275-
for arg in base_call.arguments loop
1276-
// If the argument is supposed to be vectorized
1277-
b :: b_list := b_list;
1278-
vect_args := (if b then Expression.applySubscript(sub, arg) else arg) :: vect_args;
1279-
end for;
1256+
call_args := List.mapIndices(call_args, mk.vectorizedArgs,
1257+
function Expression.applySubscript(subscript = sub, restSubscripts = {}));
12801258

1281-
base_call.arguments := listReverse(vect_args);
12821259
i := i + 1;
12831260
end for;
12841261

1285-
vect_ty := Type.liftArrayLeftList(base_call.ty, vect_dims);
1262+
vect_ty := Type.liftArrayLeftList(base_call.ty, mk.vectDims);
1263+
base_call.arguments := call_args;
12861264
then
12871265
TYPED_ARRAY_CONSTRUCTOR(vect_ty, base_call.var, Expression.CALL(base_call), iters);
12881266

1267+
else
1268+
algorithm
1269+
Error.addInternalError(getInstanceName() + " got unknown call", info);
1270+
then
1271+
fail();
1272+
12891273
end match;
12901274
end vectorizeCall;
12911275

Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ public
212212
end match;
213213
end isKnown;
214214

215+
function isUnknown
216+
input Dimension dim;
217+
output Boolean isUnknown;
218+
algorithm
219+
isUnknown := match dim
220+
case UNKNOWN() then true;
221+
else false;
222+
end match;
223+
end isUnknown;
224+
215225
function isZero
216226
input Dimension dim;
217227
output Boolean isZero;

0 commit comments

Comments
 (0)