use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopUnswitchingPhase method run.
@Override
protected void run(StructuredGraph graph) {
DebugContext debug = graph.getDebug();
if (graph.hasLoops()) {
boolean unswitched;
do {
unswitched = false;
final LoopsData dataUnswitch = new LoopsData(graph);
for (LoopEx loop : dataUnswitch.outerFirst()) {
if (getPolicies().shouldTryUnswitch(loop)) {
List<ControlSplitNode> controlSplits = LoopTransformations.findUnswitchable(loop);
if (controlSplits != null) {
UNSWITCH_CANDIDATES.increment(debug);
if (getPolicies().shouldUnswitch(loop, controlSplits)) {
if (debug.isLogEnabled()) {
logUnswitch(loop, controlSplits);
}
LoopTransformations.unswitch(loop, controlSplits);
debug.dump(DebugContext.DETAILED_LEVEL, graph, "After unswitch %s", controlSplits);
UNSWITCHED.increment(debug);
unswitched = true;
break;
}
}
} else {
UNSWITCH_EARLY_REJECTS.increment(debug);
}
}
} while (unswitched);
}
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopPartialUnrollTest method buildGraph.
@SuppressWarnings("try")
public StructuredGraph buildGraph(String name, boolean partialUnroll) {
CompilationIdentifier id = new CompilationIdentifier() {
@Override
public String toString(Verbosity verbosity) {
return name;
}
};
ResolvedJavaMethod method = getResolvedJavaMethod(name);
OptionValues options = new OptionValues(getInitialOptions(), DefaultLoopPolicies.Options.UnrollMaxIterations, 2);
StructuredGraph graph = parse(builder(method, StructuredGraph.AllowAssumptions.YES, id, options), getEagerGraphBuilderSuite());
try (DebugContext.Scope buildScope = graph.getDebug().scope(name, method, graph)) {
MidTierContext context = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, null);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
canonicalizer.apply(graph, context);
new RemoveValueProxyPhase().apply(graph);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
new DeadCodeEliminationPhase().apply(graph);
new ConditionalEliminationPhase(true).apply(graph, context);
ComputeLoopFrequenciesClosure.compute(graph);
new GuardLoweringPhase().apply(graph, context);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
new FrameStateAssignmentPhase().apply(graph);
new DeoptimizationGroupingPhase().apply(graph, context);
canonicalizer.apply(graph, context);
new ConditionalEliminationPhase(true).apply(graph, context);
if (partialUnroll) {
LoopsData dataCounted = new LoopsData(graph);
dataCounted.detectedCountedLoops();
for (LoopEx loop : dataCounted.countedLoops()) {
LoopFragmentInside newSegment = loop.inside().duplicate();
newSegment.insertWithinAfter(loop, false);
}
canonicalizer.apply(graph, getDefaultMidTierContext());
}
new DeadCodeEliminationPhase().apply(graph);
canonicalizer.apply(graph, context);
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "before compare");
return graph;
} catch (Throwable e) {
throw getDebugContext().handle(e);
}
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopsDataTest method testInnerFirst.
@Test
public void testInnerFirst() {
LoopsData loops = getLoopsData();
Set<LoopEx> seen = new HashSet<>();
for (LoopEx loop : reversed(loops.outerFirst())) {
assertFalse(seen.contains(loop), "%s has already been seen", loop);
if (loop.parent() != null) {
assertFalse(seen.contains(loop.parent()), "%s's parent (%s) should not have already been seen", loop, loop.parent());
}
seen.add(loop);
}
}
use of org.graalvm.compiler.loop.LoopEx in project graal by oracle.
the class LoopsDataTest method sanityTests.
@Test
public void sanityTests() {
LoopsData loops = getLoopsData();
Assert.assertEquals(8, loops.outerFirst().size());
Assert.assertEquals(1, loops.outerFirst().get(0).loop().getDepth());
Assert.assertEquals(1, loops.outerFirst().get(1).loop().getDepth());
Assert.assertEquals(2, loops.outerFirst().get(2).loop().getDepth());
Assert.assertEquals(3, loops.outerFirst().get(3).loop().getDepth());
Assert.assertEquals(2, loops.outerFirst().get(4).loop().getDepth());
Assert.assertEquals(2, loops.outerFirst().get(5).loop().getDepth());
Assert.assertEquals(3, loops.outerFirst().get(6).loop().getDepth());
Assert.assertEquals(4, loops.outerFirst().get(7).loop().getDepth());
for (LoopEx loop : loops.loops()) {
if (loop.parent() != null) {
Assert.assertEquals(loop.parent().loop().getDepth() + 1, loop.loop().getDepth());
}
}
}
Aggregations