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

Commit 0283b33

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve DAE conversion of reductions.
- 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]: - #2706
1 parent c7d9e16 commit 0283b33

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ uniontype Call
702702
Function.name(call.fn),
703703
Absyn.COMBINE(),
704704
Type.toDAE(call.ty),
705-
NONE(),
705+
SOME(Expression.toDAEValue(reductionDefaultValue(call))),
706706
String(Util.getTempVariableIndex()),
707707
String(Util.getTempVariableIndex()),
708708
NONE()),
@@ -717,6 +717,23 @@ uniontype Call
717717
end match;
718718
end toDAE;
719719

720+
function reductionDefaultValue
721+
input Call call;
722+
output Expression defaultValue;
723+
protected
724+
Function fn;
725+
Type ty;
726+
algorithm
727+
TYPED_REDUCTION(fn = fn, ty = ty) := call;
728+
729+
defaultValue := match Absyn.pathFirstIdent(Function.name(fn))
730+
case "sum" then Expression.makeZero(ty);
731+
case "product" then Expression.makeOne(ty);
732+
case "min" then Expression.makeMaxValue(ty);
733+
case "max" then Expression.makeMinValue(ty);
734+
end match;
735+
end reductionDefaultValue;
736+
720737
function isVectorizeable
721738
input Call call;
722739
output Boolean isVect;
@@ -1094,7 +1111,7 @@ protected
10941111
algorithm
10951112
(iter_node, iter_range) := iter;
10961113
diter := DAE.REDUCTIONITER(InstNode.name(iter_node), Expression.toDAE(iter_range), NONE(),
1097-
Type.toDAE(Expression.typeOf(iter_range)));
1114+
Type.toDAE(InstNode.getType(iter_node)));
10981115
end iteratorToDAE;
10991116

11001117
function matchFunction

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected
4646
import ComplexType = NFComplexType;
4747
import ExpandExp = NFExpandExp;
4848
import TypeCheck = NFTypeCheck;
49+
import ValuesUtil;
4950
import MetaModelica.Dangerous.listReverseInPlace;
5051

5152
public
@@ -65,6 +66,7 @@ public
6566
import NFComponentRef.Origin;
6667
import NFTyping.ExpOrigin;
6768
import ExpressionSimplify;
69+
import Values;
6870

6971
uniontype ClockKind
7072
record INFERRED_CLOCK
@@ -1507,13 +1509,38 @@ public
15071509
fail();
15081510

15091511
end match;
1510-
1511-
//(dexp, changed) := ExpressionSimplify.simplify(dexp);
1512-
//if changed then
1513-
// (dexp, changed) := ExpressionSimplify.simplify(dexp);
1514-
//end if;
15151512
end toDAE;
15161513

1514+
function toDAEValue
1515+
input Expression exp;
1516+
output Values.Value value;
1517+
algorithm
1518+
value := match exp
1519+
local
1520+
Type ty;
1521+
list<Values.Value> vals;
1522+
1523+
case INTEGER() then Values.INTEGER(exp.value);
1524+
case REAL() then Values.REAL(exp.value);
1525+
case STRING() then Values.STRING(exp.value);
1526+
case BOOLEAN() then Values.BOOL(exp.value);
1527+
case ENUM_LITERAL(ty = ty as Type.ENUMERATION())
1528+
then Values.ENUM_LITERAL(Absyn.suffixPath(ty.typePath, exp.name), exp.index);
1529+
1530+
case ARRAY()
1531+
algorithm
1532+
vals := list(toDAEValue(e) for e in exp.elements);
1533+
then
1534+
ValuesUtil.makeArray(vals);
1535+
1536+
else
1537+
algorithm
1538+
Error.assertion(false, getInstanceName() + " got unhandled expression " + toString(exp), sourceInfo());
1539+
then
1540+
fail();
1541+
end match;
1542+
end toDAEValue;
1543+
15171544
function dimensionCount
15181545
input Expression exp;
15191546
output Integer dimCount;

0 commit comments

Comments
 (0)