Skip to content

Commit e8f161b

Browse files
author
Sebastian Schulze
committed
[GR-72043] BBLS: Fix Phase Plan Fuzzing
PullRequest: graal/22911
2 parents c91ec90 + 8449261 commit e8f161b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/schedule/SchedulePhase.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.TreeSet;
4141
import java.util.function.Function;
4242

43+
import jdk.graal.compiler.phases.PhaseSuite;
4344
import org.graalvm.collections.EconomicSet;
4445
import org.graalvm.word.LocationIdentity;
4546

@@ -233,9 +234,28 @@ public SchedulePhase(SchedulingStrategy strategy, boolean immutableGraph, boolea
233234
/**
234235
* Last schedule to be run in any phase plan in the compiler. After this no further
235236
* optimizations or transformations must happen that would require a re-scheduling of the graph.
237+
*
238+
* Optionally, a post-processing phase can be provided via the constructor to perform low-tier
239+
* cleanups that rely on a stable schedule. Such a phase must be schedule-preserving and must
240+
* not introduce changes that require another scheduling pass. This is typically used to run
241+
* local transformations (e.g., {@link SchedulingStrategy#BASIC_BLOCK_LOCAL_SCHEDULING}) as part
242+
* of a {@link PhaseSuite} plan.
236243
*/
237244
public static class FinalSchedulePhase extends BasePhase<LowTierContext> {
238245

246+
private final BasePhase<LowTierContext> postProcessingPhase;
247+
248+
/**
249+
* Creates a FinalSchedulePhase without any post-processing.
250+
*/
251+
public FinalSchedulePhase() {
252+
this(null);
253+
}
254+
255+
public FinalSchedulePhase(final BasePhase<LowTierContext> postProcessingPhase) {
256+
this.postProcessingPhase = postProcessingPhase;
257+
}
258+
239259
@Override
240260
public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
241261
return NotApplicable.ifAny(
@@ -246,7 +266,11 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
246266
@Override
247267
protected void run(StructuredGraph graph, LowTierContext context) {
248268
new SchedulePhase(SchedulePhase.SchedulingStrategy.LATEST_OUT_OF_LOOPS).apply(graph, context);
249-
269+
// Apply the optional, schedule-preserving post-processing phase. This must not perform
270+
// transformations that would invalidate or require recomputing the final schedule.
271+
if (postProcessingPhase != null) {
272+
postProcessingPhase.apply(graph, context);
273+
}
250274
}
251275

252276
@Override

0 commit comments

Comments
 (0)