Search in sources :

Example 1 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class CompareCanonicalizerTest3 method assertCanonicallyEqual.

protected void assertCanonicallyEqual(String snippet, String reference) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    CoreProviders context = getProviders();
    CanonicalizerPhase canonicalizer = this.createCanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new GuardLoweringPhase().apply(graph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
    new FrameStateAssignmentPhase().apply(graph);
    canonicalizer.apply(graph, context);
    StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
    canonicalizer.apply(referenceGraph, context);
    new GuardLoweringPhase().apply(referenceGraph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
    new FrameStateAssignmentPhase().apply(referenceGraph);
    canonicalizer.apply(referenceGraph, context);
    canonicalizer.apply(referenceGraph, context);
    assertEquals(referenceGraph, graph, true, true);
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase)

Example 2 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class ConditionalEliminationTest14 method test1.

@Test
public void test1() {
    StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
    CoreProviders context = getProviders();
    /* Convert the LoadIndexNode to ReadNode with floating guards. */
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    /* Convert the ReadNode to FloatingReadNode. */
    new FloatingReadPhase().apply(graph);
    /* Apply the phase that we want to test. */
    new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
    Assert.assertEquals("All guards must be floating", 0, graph.getNodes(FixedGuardNode.TYPE).count());
    Assert.assertEquals("All array accesses must have been lowered", 0, graph.getNodes().filter(LoadIndexedNode.class).count());
    Assert.assertEquals("All reads must be floating", 0, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals("Must have floating reads (3 array accesses, 1 array length)", 4, graph.getNodes().filter(FloatingReadNode.class).count());
    NodeIterable<GuardNode> boundsChecks = graph.getNodes(GuardNode.TYPE).filter(n -> ((GuardNode) n).getReason() == DeoptimizationReason.BoundsCheckException);
    Assert.assertEquals("Must have only 1 bounds check remaining", 1, boundsChecks.count());
    LogicNode condition = boundsChecks.first().getCondition();
    Assert.assertTrue("Bounds check must check for array length 8", condition instanceof IntegerBelowNode && ((IntegerBelowNode) condition).getY().valueEquals(ConstantNode.forInt(8)));
}
Also used : IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) LogicNode(org.graalvm.compiler.nodes.LogicNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) Test(org.junit.Test)

Example 3 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class ConditionalEliminationTest2 method testRedundantCompares.

@Test
public void testRedundantCompares() {
    StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
    CoreProviders context = getProviders();
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new FloatingReadPhase().apply(graph);
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    assertDeepEquals(1, graph.getNodes().filter(GuardNode.class).count());
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) Test(org.junit.Test)

Example 4 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class LoopFullUnrollTest method test.

@SuppressWarnings("try")
private void test(String snippet, int loopCount) {
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope(getClass().getSimpleName(), new DebugDumpScope(snippet))) {
        final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
        CoreProviders context = getProviders();
        new LoopFullUnrollPhase(createCanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context);
        assertTrue(graph.getNodes().filter(LoopBeginNode.class).count() == loopCount);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) LoopFullUnrollPhase(org.graalvm.compiler.loop.phases.LoopFullUnrollPhase) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DefaultLoopPolicies(org.graalvm.compiler.nodes.loop.DefaultLoopPolicies) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 5 with CoreProviders

use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.

the class GraphEncoderTest method testStringMethods.

public void testStringMethods(boolean canonicalize) {
    /* Encode and decode all methods of java.lang.String. */
    List<StructuredGraph> originalGraphs = new ArrayList<>();
    for (Method method : String.class.getDeclaredMethods()) {
        ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
        if (javaMethod.hasBytecodes()) {
            StructuredGraph originalGraph = parseEager(javaMethod, AllowAssumptions.YES);
            if (canonicalize) {
                CoreProviders context = getProviders();
                createCanonicalizerPhase().apply(originalGraph, context);
            }
            originalGraphs.add(originalGraph);
        }
    }
    GraphEncoder encoder = new GraphEncoder(getTarget().arch);
    for (StructuredGraph originalGraph : originalGraphs) {
        encoder.prepare(originalGraph);
    }
    encoder.finishPrepare();
    Map<StructuredGraph, Integer> startOffsets = new HashMap<>();
    for (StructuredGraph originalGraph : originalGraphs) {
        startOffsets.put(originalGraph, encoder.encode(originalGraph));
    }
    for (StructuredGraph originalGraph : originalGraphs) {
        EncodedGraph encodedGraph = new EncodedGraph(encoder.getEncoding(), startOffsets.get(originalGraph), encoder.getObjects(), encoder.getNodeClasses(), originalGraph);
        encoder.verifyEncoding(originalGraph, encodedGraph);
    }
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HashMap(java.util.HashMap) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

CoreProviders (org.graalvm.compiler.nodes.spi.CoreProviders)30 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)25 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)16 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)15 DebugContext (org.graalvm.compiler.debug.DebugContext)9 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)7 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)7 Test (org.junit.Test)6 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 IterativeConditionalEliminationPhase (org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase)5 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)4 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)4 Node (org.graalvm.compiler.graph.Node)3 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)3 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)3 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 FrameState (org.graalvm.compiler.nodes.FrameState)2