Skip to content

Commit

Permalink
[NF] Improve DAE conversion of reductions.
Browse files Browse the repository at this point in the history
- Use the type of the iterator and not the iteration range when
  converting iterators.
- Fill in the default value in the created DAE.REDUCTIONINFO record.

Belonging to [master]:
  - OpenModelica/OMCompiler#2706
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 9, 2018
1 parent c7d9e16 commit 0283b33
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
21 changes: 19 additions & 2 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -702,7 +702,7 @@ uniontype Call
Function.name(call.fn),
Absyn.COMBINE(),
Type.toDAE(call.ty),
NONE(),
SOME(Expression.toDAEValue(reductionDefaultValue(call))),
String(Util.getTempVariableIndex()),
String(Util.getTempVariableIndex()),
NONE()),
Expand All @@ -717,6 +717,23 @@ uniontype Call
end match;
end toDAE;

function reductionDefaultValue
input Call call;
output Expression defaultValue;
protected
Function fn;
Type ty;
algorithm
TYPED_REDUCTION(fn = fn, ty = ty) := call;

defaultValue := match Absyn.pathFirstIdent(Function.name(fn))
case "sum" then Expression.makeZero(ty);
case "product" then Expression.makeOne(ty);
case "min" then Expression.makeMaxValue(ty);
case "max" then Expression.makeMinValue(ty);
end match;
end reductionDefaultValue;

function isVectorizeable
input Call call;
output Boolean isVect;
Expand Down Expand Up @@ -1094,7 +1111,7 @@ protected
algorithm
(iter_node, iter_range) := iter;
diter := DAE.REDUCTIONITER(InstNode.name(iter_node), Expression.toDAE(iter_range), NONE(),
Type.toDAE(Expression.typeOf(iter_range)));
Type.toDAE(InstNode.getType(iter_node)));
end iteratorToDAE;

function matchFunction
Expand Down
37 changes: 32 additions & 5 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -46,6 +46,7 @@ protected
import ComplexType = NFComplexType;
import ExpandExp = NFExpandExp;
import TypeCheck = NFTypeCheck;
import ValuesUtil;
import MetaModelica.Dangerous.listReverseInPlace;

public
Expand All @@ -65,6 +66,7 @@ public
import NFComponentRef.Origin;
import NFTyping.ExpOrigin;
import ExpressionSimplify;
import Values;

uniontype ClockKind
record INFERRED_CLOCK
Expand Down Expand Up @@ -1507,13 +1509,38 @@ public
fail();

end match;

//(dexp, changed) := ExpressionSimplify.simplify(dexp);
//if changed then
// (dexp, changed) := ExpressionSimplify.simplify(dexp);
//end if;
end toDAE;

function toDAEValue
input Expression exp;
output Values.Value value;
algorithm
value := match exp
local
Type ty;
list<Values.Value> vals;

case INTEGER() then Values.INTEGER(exp.value);
case REAL() then Values.REAL(exp.value);
case STRING() then Values.STRING(exp.value);
case BOOLEAN() then Values.BOOL(exp.value);
case ENUM_LITERAL(ty = ty as Type.ENUMERATION())
then Values.ENUM_LITERAL(Absyn.suffixPath(ty.typePath, exp.name), exp.index);

case ARRAY()
algorithm
vals := list(toDAEValue(e) for e in exp.elements);
then
ValuesUtil.makeArray(vals);

else
algorithm
Error.assertion(false, getInstanceName() + " got unhandled expression " + toString(exp), sourceInfo());
then
fail();
end match;
end toDAEValue;

function dimensionCount
input Expression exp;
output Integer dimCount;
Expand Down

0 comments on commit 0283b33

Please sign in to comment.