use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopFullUnrollPhase method run.
@Override
protected void run(StructuredGraph graph, PhaseContext context) {
DebugContext debug = graph.getDebug();
if (graph.hasLoops()) {
boolean peeled;
do {
peeled = false;
final LoopsData dataCounted = new LoopsData(graph);
dataCounted.detectedCountedLoops();
for (LoopEx loop : dataCounted.countedLoops()) {
if (getPolicies().shouldFullUnroll(loop)) {
debug.log("FullUnroll %s", loop);
LoopTransformations.fullUnroll(loop, context, canonicalizer);
FULLY_UNROLLED_LOOPS.increment(debug);
debug.dump(DebugContext.DETAILED_LEVEL, graph, "FullUnroll %s", loop);
peeled = true;
break;
}
}
dataCounted.deleteUnusedNodes();
} while (peeled);
}
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopPartialUnrollPhase method checkCounted.
private static boolean checkCounted(StructuredGraph graph, Graph.Mark mark) {
LoopsData dataCounted;
dataCounted = new LoopsData(graph);
dataCounted.detectedCountedLoops();
for (LoopEx anyLoop : dataCounted.loops()) {
if (graph.isNew(mark, anyLoop.loopBegin())) {
assert anyLoop.isCounted() : "pre/post transformation loses counted loop " + anyLoop.loopBegin();
}
}
return true;
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopPartialUnrollPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, PhaseContext context) {
if (graph.hasLoops()) {
HashSetNodeEventListener listener = new HashSetNodeEventListener();
boolean changed = true;
while (changed) {
changed = false;
try (Graph.NodeEventScope nes = graph.trackNodeEvents(listener)) {
LoopsData dataCounted = new LoopsData(graph);
dataCounted.detectedCountedLoops();
Graph.Mark mark = graph.getMark();
boolean prePostInserted = false;
for (LoopEx loop : dataCounted.countedLoops()) {
if (!LoopTransformations.isUnrollableLoop(loop)) {
continue;
}
if (getPolicies().shouldPartiallyUnroll(loop)) {
if (loop.loopBegin().isSimpleLoop()) {
// First perform the pre/post transformation and do the partial
// unroll when we come around again.
LoopTransformations.insertPrePostLoops(loop);
prePostInserted = true;
} else {
LoopTransformations.partialUnroll(loop);
}
changed = true;
}
}
dataCounted.deleteUnusedNodes();
if (!listener.getNodes().isEmpty()) {
canonicalizer.applyIncremental(graph, context, listener.getNodes());
listener.getNodes().clear();
}
assert !prePostInserted || checkCounted(graph, mark);
}
}
}
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopPeelingPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, PhaseContext context) {
DebugContext debug = graph.getDebug();
if (graph.hasLoops()) {
LoopsData data = new LoopsData(graph);
try (DebugContext.Scope s = debug.scope("peeling", data.getCFG())) {
for (LoopEx loop : data.outerFirst()) {
if (getPolicies().shouldPeel(loop, data.getCFG(), context.getMetaAccess())) {
debug.log("Peeling %s", loop);
LoopTransformations.peel(loop);
debug.dump(DebugContext.DETAILED_LEVEL, graph, "Peeling %s", loop);
}
}
data.deleteUnusedNodes();
} catch (Throwable t) {
throw debug.handle(t);
}
}
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopSafepointEliminationPhase method run.
@Override
protected void run(StructuredGraph graph, MidTierContext context) {
LoopsData loops = new LoopsData(graph);
if (context.getOptimisticOptimizations().useLoopLimitChecks(graph.getOptions()) && graph.getGuardsStage().allowsFloatingGuards()) {
loops.detectedCountedLoops();
for (LoopEx loop : loops.countedLoops()) {
if (loop.loop().getChildren().isEmpty() && loop.counted().getStamp().getBits() <= 32) {
boolean hasSafepoint = false;
for (LoopEndNode loopEnd : loop.loopBegin().loopEnds()) {
hasSafepoint |= loopEnd.canSafepoint();
}
if (hasSafepoint) {
loop.counted().createOverFlowGuard();
loop.loopBegin().disableSafepoint();
}
}
}
}
for (LoopEx loop : loops.loops()) {
for (LoopEndNode loopEnd : loop.loopBegin().loopEnds()) {
Block b = loops.getCFG().blockFor(loopEnd);
blocks: while (b != loop.loop().getHeader()) {
assert b != null;
for (FixedNode node : b.getNodes()) {
if (node instanceof Invoke || (node instanceof ForeignCallNode && ((ForeignCallNode) node).isGuaranteedSafepoint())) {
loopEnd.disableSafepoint();
break blocks;
}
}
b = b.getDominator();
}
}
}
loops.deleteUnusedNodes();
}
Aggregations