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

Commit 4e5b4c7

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Ignore some funcs in Expression.hasArrayCall.
- Ignore der/pre/previous when checking whether an equation contains function calls that shouldn't be scalarized, like the old frontend does. Belonging to [master]: - #2614
1 parent 6a4d8d1 commit 4e5b4c7

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,26 @@ uniontype Call
651651
end match;
652652
end toDAE;
653653

654+
function isVectorizeable
655+
input Call call;
656+
output Boolean isVect;
657+
algorithm
658+
isVect := match call
659+
local
660+
String name;
661+
662+
case TYPED_CALL(fn = Function.FUNCTION(path = Absyn.IDENT(name = name)))
663+
then match name
664+
case "der" then false;
665+
case "pre" then false;
666+
case "previous" then false;
667+
else true;
668+
end match;
669+
670+
else true;
671+
end match;
672+
end isVectorizeable;
673+
654674
protected
655675
function instNormalCall
656676
input Absyn.ComponentRef functionName;

Compiler/NFFrontEnd/NFExpandExp.mo

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected
4545
import Ceval = NFCeval;
4646
import NFInstNode.InstNode;
4747
import SimplifyExp = NFSimplifyExp;
48+
import NFPrefixes.Variability;
4849
import MetaModelica.Dangerous.*;
4950

5051
public
@@ -245,6 +246,9 @@ public
245246
(outExp, expanded) := match Absyn.pathFirstIdent(fn_path)
246247
case "cat" then expandBuiltinCat(args, call);
247248
case "promote" then expandBuiltinPromote(args);
249+
case "der" then expandBuiltinGeneric(call);
250+
case "pre" then expandBuiltinGeneric(call);
251+
case "previous" then expandBuiltinGeneric(call);
248252
end match;
249253
end expandBuiltinCall;
250254

@@ -282,6 +286,47 @@ public
282286
exp := Expression.promote(eexp, Expression.typeOf(eexp), n);
283287
end expandBuiltinPromote;
284288

289+
function expandBuiltinGeneric
290+
input Call call;
291+
output Expression outExp;
292+
output Boolean expanded = true;
293+
protected
294+
Function fn;
295+
Type ty;
296+
Variability var;
297+
NFCall.CallAttributes attr;
298+
Expression arg;
299+
list<Expression> args, expl;
300+
algorithm
301+
Call.TYPED_CALL(fn, ty, var, {arg}, attr) := call;
302+
ty := Type.arrayElementType(ty);
303+
attr.ty := ty;
304+
305+
(arg, true) := expand(arg);
306+
outExp := expandBuiltinGeneric2(arg, fn, ty, var, attr);
307+
end expandBuiltinGeneric;
308+
309+
function expandBuiltinGeneric2
310+
input output Expression exp;
311+
input Function fn;
312+
input Type ty;
313+
input Variability var;
314+
input NFCall.CallAttributes attr;
315+
algorithm
316+
exp := match exp
317+
local
318+
list<Expression> expl;
319+
320+
case Expression.ARRAY()
321+
algorithm
322+
expl := list(expandBuiltinGeneric2(e, fn, ty, var, attr) for e in exp.elements);
323+
then
324+
Expression.ARRAY(Type.setArrayElementType(exp.ty, ty), expl);
325+
326+
else Expression.CALL(Call.TYPED_CALL(fn, ty, var, {exp}, attr));
327+
end match;
328+
end expandBuiltinGeneric2;
329+
285330
function expandReduction
286331
input Expression exp;
287332
input Type ty;

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,7 +3042,8 @@ public
30423042
input output Boolean hasArrayCall;
30433043
algorithm
30443044
hasArrayCall := match exp
3045-
case CALL() then Type.isArray(Call.typeOf(exp.call));
3045+
case CALL() then hasArrayCall or
3046+
(Type.isArray(Call.typeOf(exp.call)) and Call.isVectorizeable(exp.call));
30463047
else hasArrayCall;
30473048
end match;
30483049
end hasArrayCall2;

0 commit comments

Comments
 (0)