Skip to content

Commit d79307d

Browse files
committed
Use two bounded optimizer sweeps
1 parent 9b8f232 commit d79307d

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imoptimizer/ImOptimizer.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public class ImOptimizer {
3939
localPasses.add(new GlobalsInliner());
4040
localPasses.add(new DispatchCheckDeduplicator());
4141
localPasses.add(new SimpleRewrites());
42-
localPasses.add(new LocalMerger());
43-
localPasses.add(new DispatchCheckDeduplicator());
4442
}
4543

4644
private final TimeTaker timeTaker;
@@ -78,6 +76,23 @@ public void localOptimizations() {
7876

7977
removeGarbage();
8078

79+
int optCount = runLocalOptimizationSweep();
80+
if (optCount > 0) {
81+
removeGarbage();
82+
trans.getImProg().flatten(trans);
83+
}
84+
85+
int cleanupCount = runLocalOptimizationSweep();
86+
if (cleanupCount > 0) {
87+
removeGarbage();
88+
trans.getImProg().flatten(trans);
89+
}
90+
91+
WLogger.info("=== Local optimization passes done! Opts: " + (optCount + cleanupCount) + " ===");
92+
totalCount.forEach((k, v) -> WLogger.info("== " + k + ": " + v));
93+
}
94+
95+
private int runLocalOptimizationSweep() {
8196
int optCount = 0;
8297
LocalPlayerContextAnalyzer localPlayerContextAnalyzer = null;
8398
for (OptimizerPass pass : localPasses) {
@@ -101,14 +116,7 @@ public void localOptimizations() {
101116
optCount += count;
102117
totalCount.put(pass.getName(), totalCount.getOrDefault(pass.getName(), 0) + count);
103118
}
104-
105-
if (optCount > 0) {
106-
removeGarbage();
107-
trans.getImProg().flatten(trans);
108-
}
109-
110-
WLogger.info("=== Local optimization pass done! Opts: " + optCount + " ===");
111-
totalCount.forEach((k, v) -> WLogger.info("== " + k + ": " + v));
119+
return optCount;
112120
}
113121

114122
public void doNullsetting() {

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/OptimizerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ public void repeatedLocalOptimizationStartsANewIteration() {
15981598
}
15991599

16001600
@Test
1601-
public void localOptimizationRunsOneSweepPerInvocation() {
1601+
public void localOptimizationRunsTwoBoundedSweepsPerInvocation() {
16021602
class CountingTimeTaker extends TimeTaker.Default {
16031603
int measurements;
16041604

@@ -1632,8 +1632,8 @@ public <T> T measure(String name, java.util.function.Supplier<T> f) {
16321632

16331633
new ImOptimizer(timeTaker, translator).localOptimizations();
16341634

1635-
assertEquals(timeTaker.measurements, 10,
1636-
"the optimizer should run each configured local pass exactly once per invocation");
1635+
assertEquals(timeTaker.measurements, 16,
1636+
"the optimizer should run two fixed sweeps rather than iterating to convergence");
16371637
}
16381638

16391639
@Test

0 commit comments

Comments
 (0)