Search in sources :

Example 1 with LoopEx

use of org.graalvm.compiler.nodes.loop.LoopEx in project graal by oracle.

the class CountedLoopMaxTripCountPiTest method checkGraph.

/**
 * In the high and mid tiers, make sure that all max trip count nodes are the unique pi node in
 * the graph (i.e., exactly the one proved by the guard). We don't check the low tier because pi
 * nodes are eliminated by FixReads.
 */
void checkGraph(StructuredGraph graph, LoopsData loops) {
    loops.detectedCountedLoops();
    for (LoopEx loop : loops.loops()) {
        Assert.assertTrue("expect all loops to be counted", loop.isCounted());
        ValueNode maxTripCountNode = loop.counted().maxTripCountNode();
        Assert.assertTrue("expect a PiNode for the guarded maxTripCount, got: " + maxTripCountNode, maxTripCountNode instanceof PiNode);
    }
    PiNode[] pis = graph.getNodes().filter(PiNode.class).snapshot().toArray(new PiNode[0]);
    Assert.assertEquals("number of PiNodes in the graph", 1, pis.length);
}
Also used : LoopEx(org.graalvm.compiler.nodes.loop.LoopEx) ValueNode(org.graalvm.compiler.nodes.ValueNode) PiNode(org.graalvm.compiler.nodes.PiNode)

Example 2 with LoopEx

use of org.graalvm.compiler.nodes.loop.LoopEx in project graal by oracle.

the class ReferenceGetLoopTest method checkMidTierGraph.

@Override
protected void checkMidTierGraph(StructuredGraph graph) {
    final LoopsData loops = getDefaultMidTierContext().getLoopsDataProvider().getLoopsData(graph);
    boolean found = false;
    for (LoopEx loop : loops.loops()) {
        for (Node node : loop.inside().nodes()) {
            if (node instanceof MemoryAccess) {
                MemoryAccess access = (MemoryAccess) node;
                LocationIdentity location = access.getLocationIdentity();
                if (location instanceof FieldLocationIdentity) {
                    ResolvedJavaField field = ((FieldLocationIdentity) location).getField();
                    if (field.getName().equals("referent") && field.getDeclaringClass().equals(getMetaAccess().lookupJavaType(Reference.class))) {
                        found = true;
                    }
                }
            }
        }
    }
    if (!found) {
        assertTrue(false, "Reference.referent not found in loop: " + getCanonicalGraphString(graph, true, false));
    }
}
Also used : FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LoopsData(org.graalvm.compiler.nodes.loop.LoopsData) LoopEx(org.graalvm.compiler.nodes.loop.LoopEx) Node(org.graalvm.compiler.graph.Node) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LocationIdentity(org.graalvm.word.LocationIdentity) MemoryAccess(org.graalvm.compiler.nodes.memory.MemoryAccess) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 3 with LoopEx

use of org.graalvm.compiler.nodes.loop.LoopEx in project graal by oracle.

the class LoopsDataTest method testouterFirst.

@Test
public void testouterFirst() {
    LoopsData loops = getLoopsData();
    Set<LoopEx> seen = new HashSet<>();
    for (LoopEx loop : loops.outerFirst()) {
        assertFalse(seen.contains(loop), "%s has already been seen", loop);
        if (loop.parent() != null) {
            assertTrue(seen.contains(loop.parent()), "%s's parent (%s) should have already been seen", loop, loop.parent());
        }
        seen.add(loop);
    }
}
Also used : LoopsData(org.graalvm.compiler.nodes.loop.LoopsData) LoopEx(org.graalvm.compiler.nodes.loop.LoopEx) HashSet(java.util.HashSet) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 4 with LoopEx

use of org.graalvm.compiler.nodes.loop.LoopEx in project graal by oracle.

the class LoopFullUnrollPhase method run.

@Override
protected void run(StructuredGraph graph, CoreProviders context) {
    if (GraalOptions.FullUnroll.getValue(graph.getOptions())) {
        DebugContext debug = graph.getDebug();
        if (graph.hasLoops()) {
            boolean peeled;
            int applications = 0;
            do {
                peeled = false;
                final LoopsData dataCounted = context.getLoopsDataProvider().getLoopsData(graph);
                dataCounted.detectedCountedLoops();
                List<LoopEx> countedLoops = dataCounted.countedLoops();
                countedLoops.sort(LOOP_COMPARATOR);
                for (LoopEx loop : 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();
                applications++;
            } while (peeled && applications < Options.FullUnrollMaxApplication.getValue(graph.getOptions()));
        }
    }
}
Also used : LoopsData(org.graalvm.compiler.nodes.loop.LoopsData) LoopEx(org.graalvm.compiler.nodes.loop.LoopEx) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 5 with LoopEx

use of org.graalvm.compiler.nodes.loop.LoopEx in project graal by oracle.

the class LoopPeelingPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, CoreProviders context) {
    DebugContext debug = graph.getDebug();
    if (graph.hasLoops()) {
        LoopsData data = context.getLoopsDataProvider().getLoopsData(graph);
        try (DebugContext.Scope s = debug.scope("peeling", data.getCFG())) {
            for (LoopEx loop : data.outerFirst()) {
                if (canPeel(loop)) {
                    if (LoopPolicies.Options.PeelALot.getValue(graph.getOptions()) || getPolicies().shouldPeel(loop, data.getCFG(), context)) {
                        debug.log("Peeling %s", loop);
                        PEELED.increment(debug);
                        LoopTransformations.peel(loop);
                        debug.dump(DebugContext.DETAILED_LEVEL, graph, "Peeling %s", loop);
                    }
                }
            }
            data.deleteUnusedNodes();
        } catch (Throwable t) {
            throw debug.handle(t);
        }
    }
}
Also used : LoopsData(org.graalvm.compiler.nodes.loop.LoopsData) LoopEx(org.graalvm.compiler.nodes.loop.LoopEx) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

LoopEx (org.graalvm.compiler.nodes.loop.LoopEx)21 LoopsData (org.graalvm.compiler.nodes.loop.LoopsData)19 DebugContext (org.graalvm.compiler.debug.DebugContext)8 Node (org.graalvm.compiler.graph.Node)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 Block (org.graalvm.compiler.nodes.cfg.Block)4 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 HashSet (java.util.HashSet)2 SpeculationLog (jdk.vm.ci.meta.SpeculationLog)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 FrameState (org.graalvm.compiler.nodes.FrameState)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)2 PiNode (org.graalvm.compiler.nodes.PiNode)2 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)2 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)2 Test (org.junit.Test)2 BytecodePosition (jdk.vm.ci.code.BytecodePosition)1