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

Commit e8bea85

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve simplification of functions.
- Evaluate constants and simplify functions during collection, to make sure all collected functions are processed correctly. Belonging to [master]: - #2777
1 parent 52bf402 commit e8bea85

File tree

5 files changed

+7
-13
lines changed

5 files changed

+7
-13
lines changed

Compiler/NFFrontEnd/NFEvalConstants.mo

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ algorithm
167167
algorithm
168168
(outExp, outChanged) := Expression.mapFoldShallow(exp,
169169
function evaluateExpTraverser(isExternalArg = Call.isExternal(exp.call)), false);
170-
evaluateFunction(Call.typedFunction(exp.call));
171170
then
172171
outExp;
173172

@@ -443,12 +442,6 @@ algorithm
443442
then
444443
outExp;
445444

446-
case Expression.CALL()
447-
algorithm
448-
evaluateFunction(Call.typedFunction(e.call));
449-
then
450-
e;
451-
452445
else if outChanged then Expression.retype(e) else e;
453446
end match;
454447

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import Ceval = NFCeval;
8686
import NFTyping.ExpOrigin;
8787
import SimplifyExp = NFSimplifyExp;
8888
import Restriction = NFRestriction;
89+
import EvalConstants = NFEvalConstants;
90+
import SimplifyModel = NFSimplifyModel;
8991

9092
public
9193
type FunctionTree = FunctionTreeImpl.Tree;
@@ -1505,6 +1507,8 @@ function flattenFunction
15051507
input output FunctionTree funcs;
15061508
algorithm
15071509
if not Function.isCollected(fn) then
1510+
EvalConstants.evaluateFunction(fn);
1511+
SimplifyModel.simplifyFunction(fn);
15081512
Function.collect(fn);
15091513

15101514
if not InstNode.isPartial(fn.node) then

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ uniontype Function
491491
input Function fn;
492492
algorithm
493493
if Pointer.access(fn.status) <> FunctionStatus.BUILTIN then
494-
Pointer.update(fn.status, FunctionStatus.COLLECTED);
494+
Pointer.update(fn.status, FunctionStatus.SIMPLIFIED);
495495
end if;
496496
end markSimplified;
497497

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ algorithm
157157
flat_model := EvalConstants.evaluate(flat_model);
158158
flat_model := SimplifyModel.simplify(flat_model);
159159
funcs := Flatten.collectFunctions(flat_model, name);
160-
funcs := FunctionTree.map(funcs, SimplifyModel.simplifyFunction);
161-
execStat("SimplifyModel.simplifyFunction");
162160

163161
// Collect package constants that couldn't be substituted with their values
164162
// (e.g. because they where used with non-constant subscripts), and add them

Compiler/NFFrontEnd/NFSimplifyModel.mo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ algorithm
450450
end simplifyIfStmtBranches;
451451

452452
function simplifyFunction
453-
input Absyn.Path name;
454-
input output Function func;
453+
input Function func;
455454
protected
456455
Class cls;
457456
Algorithm fn_body;
@@ -485,7 +484,7 @@ algorithm
485484

486485
for fn_der in func.derivatives loop
487486
for der_fn in Function.getCachedFuncs(fn_der.derivativeFn) loop
488-
simplifyFunction(Function.name(der_fn), der_fn);
487+
simplifyFunction(der_fn);
489488
end for;
490489
end for;
491490
end if;

0 commit comments

Comments
 (0)