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

Commit b8a0777

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Add flag to expand binary operations.
- Add new debug flag nfExpandOperations that expands the operators of binary operations, to mimic the old frontend behaviour. This flag is on by default. - Fixed some small issues with ExpandExp so that it doesn't fail on basic arithmetic operations involving scalars. Belonging to [master]: - #2632 - OpenModelica/OpenModelica-testsuite#1022
1 parent 8522167 commit b8a0777

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

Compiler/NFFrontEnd/NFExpandExp.mo

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,22 @@ public
456456
Operator op;
457457
algorithm
458458
Expression.BINARY(exp1 = exp1, operator = op, exp2 = exp2) := exp;
459-
(exp1, expanded) := expand(exp1);
460459

461-
if expanded then
462-
(exp2, expanded) := expand(exp2);
463-
end if;
460+
if Type.isArray(Operator.typeOf(op)) then
461+
(exp1, expanded) := expand(exp1);
464462

465-
if expanded then
466-
outExp := expandBinaryElementWise2(exp1, op, exp2, makeBinaryOp);
463+
if expanded then
464+
(exp2, expanded) := expand(exp2);
465+
end if;
466+
467+
if expanded then
468+
outExp := expandBinaryElementWise2(exp1, op, exp2, makeBinaryOp);
469+
else
470+
outExp := exp;
471+
end if;
467472
else
468473
outExp := exp;
474+
expanded := true;
469475
end if;
470476
end expandBinaryElementWise;
471477

Compiler/NFFrontEnd/NFOperator.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ public
201201
op.ty := Type.arrayElementType(op.ty);
202202
end scalarize;
203203

204+
function unlift
205+
input output Operator op;
206+
algorithm
207+
op.ty := Type.unliftArray(op.ty);
208+
end unlift;
209+
204210
function symbol
205211
input Operator op;
206212
input String spacing = " ";

Compiler/NFFrontEnd/NFSimplifyExp.mo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Operator = NFOperator;
3636
import Type = NFType;
3737
import NFCall.Call;
3838
import Subscript = NFSubscript;
39+
import NFOperator.Op;
3940

4041
protected
4142

@@ -273,7 +274,9 @@ algorithm
273274
se1 := simplify(e1);
274275
se2 := simplify(e2);
275276

276-
if Expression.isLiteral(se1) and Expression.isLiteral(se2) then
277+
if Flags.isSet(Flags.NF_EXPAND_OPERATIONS) then
278+
binaryExp := ExpandExp.expand(ExpandExp.makeBinaryOp(se1, op, se2));
279+
elseif Expression.isLiteral(se1) and Expression.isLiteral(se2) then
277280
binaryExp := Ceval.evalBinaryOp(se1, op, se2);
278281
elseif not (referenceEq(e1, se1) and referenceEq(e2, se2)) then
279282
binaryExp := Expression.BINARY(se1, op, se2);

Compiler/Util/Flags.mo

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ constant DebugFlag DEBUG_DAEMODE = DEBUG_FLAG(178, "debugDAEmode", false,
532532
Util.gettext("Dump debug output for the DAEmode."));
533533
constant DebugFlag NF_SCALARIZE = DEBUG_FLAG(179, "nfScalarize", true,
534534
Util.gettext("Run scalarization in NF, default true."));
535+
constant DebugFlag NF_EVAL_CONST_ARG_FUNCS = DEBUG_FLAG(180, "nfEvalConstArgFuncs", false,
536+
Util.gettext("Evaluate all functions with constant arguments in the new frontend."));
537+
constant DebugFlag NF_EXPAND_OPERATIONS = DEBUG_FLAG(181, "nfExpandOperations", true,
538+
Util.gettext("Expand all unary/binary operations to scalar expressions in the new frontend."));
535539

536540
// This is a list of all debug flags, to keep track of which flags are used. A
537541
// flag can not be used unless it's in this list, and the list is checked at
@@ -717,7 +721,9 @@ constant list<DebugFlag> allDebugFlags = {
717721
OLD_FE_UNITCHECK,
718722
EXEC_STAT_EXTRA_GC,
719723
DEBUG_DAEMODE,
720-
NF_SCALARIZE
724+
NF_SCALARIZE,
725+
NF_EVAL_CONST_ARG_FUNCS,
726+
NF_EXPAND_OPERATIONS
721727
};
722728

723729
public
@@ -1413,31 +1419,31 @@ constant ConfigFlag IGNORE_REPLACEABLE = CONFIG_FLAG(117, "ignoreReplaceable",
14131419
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
14141420
Util.gettext("Sets whether to ignore replaceability or not when redeclaring."));
14151421

1416-
constant ConfigFlag LABELED_REDUCTION = CONFIG_FLAG(118,
1422+
constant ConfigFlag LABELED_REDUCTION = CONFIG_FLAG(118,
14171423
"labeledReduction", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
14181424
Util.gettext("Turns on labeling and reduce terms to do whole process of reduction."));
14191425

1420-
constant ConfigFlag DISABLE_EXTRA_LABELING = CONFIG_FLAG(119,
1426+
constant ConfigFlag DISABLE_EXTRA_LABELING = CONFIG_FLAG(119,
14211427
"disableExtraLabeling", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
14221428
Util.gettext("Disable adding extra label into the whole experssion with more than one term and +,- operations."));
14231429

1424-
constant ConfigFlag LOAD_MSL_MODEL = CONFIG_FLAG(120,
1430+
constant ConfigFlag LOAD_MSL_MODEL = CONFIG_FLAG(120,
14251431
"loadMSLModel", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
14261432
Util.gettext("Used to know loadFile doesn't need to be called in cpp-runtime (for labeled model reduction)."));
14271433

1428-
constant ConfigFlag Load_PACKAGE_FILE = CONFIG_FLAG(121,
1434+
constant ConfigFlag Load_PACKAGE_FILE = CONFIG_FLAG(121,
14291435
"loadPackageFile", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
14301436
Util.gettext("used when the outside name is different with the inside name of the packge, in cpp-runtime (for labeled model reduction)."));
14311437

1432-
constant ConfigFlag BUILDING_FMU = CONFIG_FLAG(122,
1438+
constant ConfigFlag BUILDING_FMU = CONFIG_FLAG(122,
14331439
"", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
14341440
Util.gettext("Is true when building an FMU (so the compiler can look for URIs to package as FMI resources)."));
14351441

1436-
constant ConfigFlag BUILDING_MODEL = CONFIG_FLAG(123,
1442+
constant ConfigFlag BUILDING_MODEL = CONFIG_FLAG(123,
14371443
"", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
14381444
Util.gettext("Is true when building a model (as opposed to running a Modelica script)."));
14391445

1440-
constant ConfigFlag POST_OPT_MODULES_DAE = CONFIG_FLAG(124, "postOptModulesDAE",
1446+
constant ConfigFlag POST_OPT_MODULES_DAE = CONFIG_FLAG(124, "postOptModulesDAE",
14411447
NONE(), EXTERNAL(), STRING_LIST_FLAG({
14421448
"lateInlineFunction",
14431449
"wrapFunctionCalls",
@@ -1454,15 +1460,15 @@ constant ConfigFlag IGNORE_REPLACEABLE = CONFIG_FLAG(117, "ignoreReplaceable",
14541460
}),NONE(),
14551461
Util.gettext("Sets the optimization modules for the DAEmode in the back end. See --help=optmodules for more info."));
14561462

1457-
constant ConfigFlag EVAL_LOOP_LIMIT = CONFIG_FLAG(125,
1458-
"evalLoopLimit", NONE(), EXTERNAL(), INT_FLAG(100000), NONE(),
1459-
Util.gettext("The loop iteration limit used when evaluating constant function calls."));
1463+
constant ConfigFlag EVAL_LOOP_LIMIT = CONFIG_FLAG(125,
1464+
"evalLoopLimit", NONE(), EXTERNAL(), INT_FLAG(100000), NONE(),
1465+
Util.gettext("The loop iteration limit used when evaluating constant function calls."));
14601466

1461-
constant ConfigFlag EVAL_RECURSION_LIMIT = CONFIG_FLAG(126,
1462-
"evalRecursionLimit", NONE(), EXTERNAL(), INT_FLAG(256), NONE(),
1463-
Util.gettext("The recursion limit used when evaluating constant function calls."));
1467+
constant ConfigFlag EVAL_RECURSION_LIMIT = CONFIG_FLAG(126,
1468+
"evalRecursionLimit", NONE(), EXTERNAL(), INT_FLAG(256), NONE(),
1469+
Util.gettext("The recursion limit used when evaluating constant function calls."));
14641470

1465-
constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER = CONFIG_FLAG(127, "singleInstanceAglSolver",
1471+
constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER = CONFIG_FLAG(127, "singleInstanceAglSolver",
14661472
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
14671473
Util.gettext("Sets to instantiate only one algebraic loop solver all algebraic loops"));
14681474

0 commit comments

Comments
 (0)