Search in sources :

Example 1 with LoopEx

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

the class AMD64HotSpotAddressLowering method preProcess.

@Override
public void preProcess(StructuredGraph graph) {
    if (graph.hasLoops()) {
        LoopsData loopsData = new LoopsData(graph);
        loopsData.detectedCountedLoops();
        for (LoopEx loop : loopsData.countedLoops()) {
            for (OffsetAddressNode offsetAdressNode : loop.whole().nodes().filter(OffsetAddressNode.class)) {
                tryOptimize(offsetAdressNode, loop);
            }
        }
    }
}
Also used : LoopsData(org.graalvm.compiler.loop.LoopsData) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) LoopEx(org.graalvm.compiler.loop.LoopEx)

Example 2 with LoopEx

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

the class SnippetTemplate method explodeLoops.

public static void explodeLoops(final StructuredGraph snippetCopy, PhaseContext phaseContext) {
    // Do any required loop explosion
    boolean exploded = false;
    do {
        exploded = false;
        ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
        if (explodeLoop != null) {
            // Earlier canonicalization may have removed the loop
            // altogether
            LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
            if (loopBegin != null) {
                LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
                Mark mark = snippetCopy.getMark();
                LoopTransformations.fullUnroll(loop, phaseContext, new CanonicalizerPhase());
                new CanonicalizerPhase().applyIncremental(snippetCopy, phaseContext, mark);
                loop.deleteUnusedNodes();
            }
            GraphUtil.removeFixedWithUnusedInputs(explodeLoop);
            exploded = true;
        }
    } while (exploded);
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopsData(org.graalvm.compiler.loop.LoopsData) LoopEx(org.graalvm.compiler.loop.LoopEx) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) Mark(org.graalvm.compiler.graph.Graph.Mark) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 3 with LoopEx

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

the class ReferenceGetLoopTest method checkMidTierGraph.

@Override
protected boolean checkMidTierGraph(StructuredGraph graph) {
    final LoopsData loops = new LoopsData(graph);
    boolean found = false;
    for (LoopEx loop : loops.loops()) {
        for (Node node : loop.inside().nodes()) {
            if (node instanceof Access) {
                Access access = (Access) 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));
    }
    return true;
}
Also used : FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LoopsData(org.graalvm.compiler.loop.LoopsData) LoopEx(org.graalvm.compiler.loop.LoopEx) Node(org.graalvm.compiler.graph.Node) Access(org.graalvm.compiler.nodes.memory.Access) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LocationIdentity(org.graalvm.word.LocationIdentity) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 4 with LoopEx

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

the class ReassociateInvariantPhase method run.

@SuppressWarnings("try")
@Override
protected void run(StructuredGraph graph) {
    int iterations = 0;
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope s = debug.scope("ReassociateInvariants")) {
        boolean changed = true;
        while (changed) {
            changed = false;
            final LoopsData dataReassociate = new LoopsData(graph);
            for (LoopEx loop : dataReassociate.loops()) {
                changed |= loop.reassociateInvariants();
            }
            dataReassociate.deleteUnusedNodes();
            iterations++;
            debug.dump(DebugContext.VERBOSE_LEVEL, graph, "after iteration %d", iterations);
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : LoopsData(org.graalvm.compiler.loop.LoopsData) LoopEx(org.graalvm.compiler.loop.LoopEx) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 5 with LoopEx

use of org.graalvm.compiler.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.loop.LoopsData) LoopEx(org.graalvm.compiler.loop.LoopEx) HashSet(java.util.HashSet) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Aggregations

LoopEx (org.graalvm.compiler.loop.LoopEx)14 LoopsData (org.graalvm.compiler.loop.LoopsData)14 DebugContext (org.graalvm.compiler.debug.DebugContext)5 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 Graph (org.graalvm.compiler.graph.Graph)1 Mark (org.graalvm.compiler.graph.Graph.Mark)1 Node (org.graalvm.compiler.graph.Node)1 LoopFragmentInside (org.graalvm.compiler.loop.LoopFragmentInside)1 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1