Skip to content

Commit

Permalink
[NF] Ignore some funcs in Expression.hasArrayCall.
Browse files Browse the repository at this point in the history
- 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]:
  - OpenModelica/OMCompiler#2614
  • Loading branch information
perost authored and OpenModelica-Hudson committed Aug 22, 2018
1 parent 6a4d8d1 commit 4e5b4c7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -651,6 +651,26 @@ uniontype Call
end match;
end toDAE;

function isVectorizeable
input Call call;
output Boolean isVect;
algorithm
isVect := match call
local
String name;

case TYPED_CALL(fn = Function.FUNCTION(path = Absyn.IDENT(name = name)))
then match name
case "der" then false;
case "pre" then false;
case "previous" then false;
else true;
end match;

else true;
end match;
end isVectorizeable;

protected
function instNormalCall
input Absyn.ComponentRef functionName;
Expand Down
45 changes: 45 additions & 0 deletions Compiler/NFFrontEnd/NFExpandExp.mo
Expand Up @@ -45,6 +45,7 @@ protected
import Ceval = NFCeval;
import NFInstNode.InstNode;
import SimplifyExp = NFSimplifyExp;
import NFPrefixes.Variability;
import MetaModelica.Dangerous.*;

public
Expand Down Expand Up @@ -245,6 +246,9 @@ public
(outExp, expanded) := match Absyn.pathFirstIdent(fn_path)
case "cat" then expandBuiltinCat(args, call);
case "promote" then expandBuiltinPromote(args);
case "der" then expandBuiltinGeneric(call);
case "pre" then expandBuiltinGeneric(call);
case "previous" then expandBuiltinGeneric(call);
end match;
end expandBuiltinCall;

Expand Down Expand Up @@ -282,6 +286,47 @@ public
exp := Expression.promote(eexp, Expression.typeOf(eexp), n);
end expandBuiltinPromote;

function expandBuiltinGeneric
input Call call;
output Expression outExp;
output Boolean expanded = true;
protected
Function fn;
Type ty;
Variability var;
NFCall.CallAttributes attr;
Expression arg;
list<Expression> args, expl;
algorithm
Call.TYPED_CALL(fn, ty, var, {arg}, attr) := call;
ty := Type.arrayElementType(ty);
attr.ty := ty;

(arg, true) := expand(arg);
outExp := expandBuiltinGeneric2(arg, fn, ty, var, attr);
end expandBuiltinGeneric;

function expandBuiltinGeneric2
input output Expression exp;
input Function fn;
input Type ty;
input Variability var;
input NFCall.CallAttributes attr;
algorithm
exp := match exp
local
list<Expression> expl;

case Expression.ARRAY()
algorithm
expl := list(expandBuiltinGeneric2(e, fn, ty, var, attr) for e in exp.elements);
then
Expression.ARRAY(Type.setArrayElementType(exp.ty, ty), expl);

else Expression.CALL(Call.TYPED_CALL(fn, ty, var, {exp}, attr));
end match;
end expandBuiltinGeneric2;

function expandReduction
input Expression exp;
input Type ty;
Expand Down
3 changes: 2 additions & 1 deletion Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -3042,7 +3042,8 @@ public
input output Boolean hasArrayCall;
algorithm
hasArrayCall := match exp
case CALL() then Type.isArray(Call.typeOf(exp.call));
case CALL() then hasArrayCall or
(Type.isArray(Call.typeOf(exp.call)) and Call.isVectorizeable(exp.call));
else hasArrayCall;
end match;
end hasArrayCall2;
Expand Down

0 comments on commit 4e5b4c7

Please sign in to comment.