Skip to content

Commit

Permalink
[GR-59001][GR-59002][GR-61452] Safepoint changes.
Browse files Browse the repository at this point in the history
PullRequest: graal/19135
  • Loading branch information
davleopo committed Jan 20, 2025
2 parents bbdf41b + 23bcab5 commit 15c39e8
Show file tree
Hide file tree
Showing 17 changed files with 435 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int ascendingSnippet(int start, int limit) {
for (int i = start; GraalDirectives.injectIterationCount(101, i < limit); i++) {
GraalDirectives.sideEffect(i);
sum += i;
GraalDirectives.neverStripMine();
}
return sum + maxTripCount;
}
Expand All @@ -64,6 +65,7 @@ int descendingSnippet(int start, int limit) {
for (int i = start; GraalDirectives.injectIterationCount(102, i >= limit); i--) {
GraalDirectives.sideEffect(i);
sum += i;
GraalDirectives.neverStripMine();
}
return sum + maxTripCount;
}
Expand All @@ -76,9 +78,12 @@ int descendingSnippet(int start, int limit) {
void checkGraph(StructuredGraph graph, LoopsData loops) {
loops.detectCountedLoops();
for (Loop loop : loops.loops()) {
if (loop.loopBegin().isStripMinedOuter()) {
continue;
}
// max trip count can only be used if a loop does not overflow
loop.counted().createOverFlowGuard();
Assert.assertTrue("expect all loops to be counted", loop.isCounted());
loop.counted().createOverFlowGuard();
ValueNode maxTripCountNode = loop.counted().maxTripCountNode();
Assert.assertTrue("expect a PiNode for the guarded maxTripCount, got: " + maxTripCountNode, maxTripCountNode instanceof PiNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
@Override
protected void run(StructuredGraph graph, HighTierContext context) {
for (LoopBeginNode lb : graph.getNodes(LoopBeginNode.TYPE)) {
lb.disableSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
lb.disableGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
lb.setLoopEndSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
lb.setGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static LoopBeginNode findFirstLoop(StructuredGraph graph) {
*/
private static void removeLoopSafepoint(StructuredGraph graph) {
LoopBeginNode loopBegin = findFirstLoop(graph);
loopBegin.disableSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
loopBegin.setLoopEndSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ protected void checkMidTierGraph(StructuredGraph graph) {
}
NodeIterable<LoopBeginNode> loops = graph.getNodes().filter(LoopBeginNode.class);
// Loops might be optimizable after partial unrolling
if (!loops.isEmpty()) {
for (LoopBeginNode loop : loops) {
if (loop.isMainLoop()) {
return;
}
boolean seenLoop = false;
for (LoopBeginNode loop : loops) {
if (loop.isStripMinedOuter()) {
continue;
}
seenLoop = true;
if (loop.isMainLoop()) {
return;
}
}
if (seenLoop) {
fail("expected a main loop");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3910,9 +3910,9 @@ private LoopBeginNode appendLoopBegin(FixedWithNextNode fixedWithNext, int start
EndNode preLoopEnd = graph.add(new EndNode());
LoopBeginNode loopBegin = graph.add(new LoopBeginNode());
if (disableLoopSafepoint()) {
loopBegin.disableSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
loopBegin.disableGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
loopBegin.disableLoopExitSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
loopBegin.setLoopEndSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
loopBegin.setGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
loopBegin.setLoopExitSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
}
fixedWithNext.setNext(preLoopEnd);
// Add the single non-loop predecessor of the loop header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.graph.Graph;
import jdk.graal.compiler.graph.NodeBitMap;
import jdk.graal.compiler.loop.phases.LoopTransformations.PreMainPostResult;
import jdk.graal.compiler.nodes.GraphState;
import jdk.graal.compiler.nodes.GraphState.StageFlag;
import jdk.graal.compiler.nodes.LoopBeginNode;
Expand All @@ -56,7 +58,8 @@ private void unroll(StructuredGraph graph, CoreProviders context) {
EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener();
boolean changed = true;
EconomicMap<LoopBeginNode, OpaqueNode> opaqueUnrolledStrides = null;
boolean prePostInserted = false;
NodeBitMap newMainLoops = null;

while (changed) {
changed = false;
try (Graph.NodeEventScope nes = graph.trackNodeEvents(listener)) {
Expand All @@ -72,10 +75,13 @@ private void unroll(StructuredGraph graph, CoreProviders context) {
// First perform the pre/post transformation and do the partial
// unroll when we come around again.
LoopUtility.preserveCounterStampsForDivAfterUnroll(loop);
LoopTransformations.insertPrePostLoops(loop);
prePostInserted = true;
PreMainPostResult res = LoopTransformations.insertPrePostLoops(loop);
if (newMainLoops == null) {
newMainLoops = graph.createNodeBitMap();
}
newMainLoops.markAndGrow(res.getMainLoop());
changed = true;
} else if (prePostInserted) {
} else if (newMainLoops != null && newMainLoops.isMarkedAndGrow(loop.loopBegin())) {
if (opaqueUnrolledStrides == null) {
opaqueUnrolledStrides = EconomicMap.create(Equivalence.IDENTITY);
}
Expand All @@ -94,7 +100,7 @@ private void unroll(StructuredGraph graph, CoreProviders context) {
listener.getNodes().clear();
}

assert !prePostInserted || checkCounted(graph, context.getLoopsDataProvider(), mark);
assert newMainLoops == null || checkCounted(graph, context.getLoopsDataProvider(), mark);
}
}
if (opaqueUnrolledStrides != null) {
Expand Down
Loading

0 comments on commit 15c39e8

Please sign in to comment.