Search in sources :

Example 26 with CoreProviders

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

the class ConditionalEliminationTest10 method test.

private void test(String snippet, int guardCount) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    CoreProviders context = getProviders();
    new LoweringPhase(createCanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new ConditionalEliminationPhase(true).apply(graph, context);
    Assert.assertEquals(guardCount, 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)

Example 27 with CoreProviders

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

the class PEGraphDecoderTest method test.

@SuppressWarnings("try")
private StructuredGraph test(String methodName, EconomicMap<ResolvedJavaMethod, EncodedGraph> graphCache) {
    ResolvedJavaMethod testMethod = getResolvedJavaMethod(methodName);
    StructuredGraph targetGraph = null;
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
        GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
        graphBuilderConfig = editGraphBuilderConfiguration(graphBuilderConfig);
        registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
        targetGraph = new StructuredGraph.Builder(debug.getOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
        CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES, null, null, new InlineInvokePlugin[] { new InlineAll() }, null, null, null, null, null, graphCache, false);
        decoder.decode(testMethod, false, false);
        debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
        targetGraph.verify();
        CoreProviders context = getProviders();
        createCanonicalizerPhase().apply(targetGraph, context);
        targetGraph.verify();
        return targetGraph;
    } catch (Throwable ex) {
        if (targetGraph != null) {
            debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString());
        }
        throw debug.handle(ex);
    }
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) CachingPEGraphDecoder(org.graalvm.compiler.replacements.CachingPEGraphDecoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 28 with CoreProviders

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

the class UnsafeReadEliminationTest method testEarlyReadElimination.

public void testEarlyReadElimination(StructuredGraph graph, int reads, int writes) {
    CoreProviders context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new ReadEliminationPhase(canonicalizer).apply(graph, context);
    Assert.assertEquals(3, graph.getNodes().filter(UnsafeAccessNode.class).count());
    // after lowering the same applies for reads and writes
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new ReadEliminationPhase(canonicalizer).apply(graph, context);
    Assert.assertEquals(reads, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals(writes, graph.getNodes().filter(WriteNode.class).count());
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ReadEliminationPhase(org.graalvm.compiler.virtual.phases.ea.ReadEliminationPhase)

Example 29 with CoreProviders

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

the class SchedulingTest2 method testValueProxyInputs.

@Test
public void testValueProxyInputs() {
    StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
    BeginNode beginNode = graph.add(new BeginNode());
    returnNode.replaceAtPredecessor(beginNode);
    beginNode.setNext(returnNode);
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
    schedulePhase.apply(graph, getDefaultHighTierContext());
    ScheduleResult schedule = graph.getLastSchedule();
    BlockMap<List<Node>> blockToNodesMap = schedule.getBlockToNodesMap();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    assertDeepEquals(2, schedule.getCFG().getBlocks().length);
    for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
        if (node instanceof AddNode) {
            assertTrue(node.toString() + " expected: " + nodeToBlock.get(beginNode) + " but was: " + nodeToBlock.get(node), nodeToBlock.get(node) != nodeToBlock.get(beginNode));
        }
    }
    for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
        Block block = nodeToBlock.get(fs);
        assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
        for (Node usage : fs.usages()) {
            if (usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) {
                assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
                if (usage != block.getBeginNode()) {
                    List<Node> map = blockToNodesMap.get(block);
                    assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
                }
            }
        }
    }
    CoreProviders context = getProviders();
    new LoweringPhase(createCanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new LoweringPhase(createCanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
    MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
    new GuardLoweringPhase().apply(graph, midContext);
    FrameStateAssignmentPhase phase = new FrameStateAssignmentPhase();
    phase.apply(graph);
    schedulePhase.apply(graph, midContext);
    schedule = graph.getLastSchedule();
    blockToNodesMap = schedule.getBlockToNodesMap();
    nodeToBlock = schedule.getNodeToBlockMap();
    for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
        Block block = nodeToBlock.get(fs);
        assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
        for (Node usage : fs.usages()) {
            if ((usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) || (usage instanceof DeoptDuring && ((DeoptDuring) usage).stateDuring() == fs)) {
                assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
                if (usage != block.getBeginNode()) {
                    List<Node> map = blockToNodesMap.get(block);
                    assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
                }
            }
        }
    }
}
Also used : FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) AddNode(org.graalvm.compiler.nodes.calc.AddNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) Node(org.graalvm.compiler.graph.Node) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptDuring(org.graalvm.compiler.nodes.DeoptimizingNode.DeoptDuring) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) StateSplit(org.graalvm.compiler.nodes.StateSplit) Test(org.junit.Test)

Example 30 with CoreProviders

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

the class PushNodesThroughPiTest method compileTestSnippet.

private StructuredGraph compileTestSnippet(final String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    CoreProviders context = getProviders();
    CanonicalizerPhase canonicalizer = this.createCanonicalizerPhase();
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    canonicalizer.apply(graph, context);
    return graph;
}
Also used : CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

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