Search in sources :

Example 31 with ReturnNode

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

the class MemoryScheduleTest method assertReadWithinAllReturnBlocks.

private void assertReadWithinAllReturnBlocks(ScheduleResult schedule, boolean withinReturnBlock) {
    StructuredGraph graph = schedule.getCFG().graph;
    assertTrue(graph.getNodes(ReturnNode.TYPE).isNotEmpty());
    int withRead = 0;
    int returnBlocks = 0;
    for (ReturnNode returnNode : graph.getNodes(ReturnNode.TYPE)) {
        Block block = schedule.getCFG().getNodeToBlock().get(returnNode);
        for (Node node : schedule.getBlockToNodesMap().get(block)) {
            if (node instanceof FloatingReadNode) {
                withRead++;
                break;
            }
        }
        returnBlocks++;
    }
    assertDeepEquals(withRead == returnBlocks, withinReturnBlock);
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) StartNode(org.graalvm.compiler.nodes.StartNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) Node(org.graalvm.compiler.graph.Node) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 32 with ReturnNode

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

the class MemoryScheduleTest method testLoop9.

@Test
public void testLoop9() {
    ScheduleResult schedule = getFinalSchedule("testLoop9Snippet", TestMode.WITHOUT_FRAMESTATES);
    StructuredGraph graph = schedule.getCFG().getStartBlock().getBeginNode().graph();
    assertThat(graph.getNodes(ReturnNode.TYPE), hasCount(1));
    ReturnNode ret = graph.getNodes(ReturnNode.TYPE).first();
    assertThat(ret.result(), instanceOf(FloatingReadNode.class));
    Block readBlock = schedule.getNodeToBlockMap().get(ret.result());
    Assert.assertEquals(0, readBlock.getLoopDepth());
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) Block(org.graalvm.compiler.nodes.cfg.Block) Test(org.junit.Test)

Example 33 with ReturnNode

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

the class FindUniqueDefaultMethodTest method testConstantReturn.

private void testConstantReturn(String name, Object value) {
    StructuredGraph result = buildGraph(name);
    ReturnNode ret = result.getNodes(ReturnNode.TYPE).first();
    assertDeepEquals(1, result.getNodes(ReturnNode.TYPE).count());
    assertDeepEquals(true, ret.result().isConstant());
    assertDeepEquals(value, ret.result().asJavaConstant().asBoxedPrimitive());
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Example 34 with ReturnNode

use of org.graalvm.compiler.nodes.ReturnNode 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);
    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));
                }
            }
        }
    }
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new LoweringPhase(new CanonicalizerPhase(), 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);
    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) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) 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) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) 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 35 with ReturnNode

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

the class FoldTest method checkHighTierGraph.

@Override
protected boolean checkHighTierGraph(StructuredGraph graph) {
    // check that folding happened correctly
    StartNode start = graph.start();
    assert start.next() instanceof ReturnNode : "expected ReturnNode, got " + start.next();
    ReturnNode ret = (ReturnNode) start.next();
    assert ret.result().isConstant() : "expected ConstantNode, got " + ret.result();
    return true;
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode)

Aggregations

ReturnNode (org.graalvm.compiler.nodes.ReturnNode)40 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)22 ValueNode (org.graalvm.compiler.nodes.ValueNode)12 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)11 DebugContext (org.graalvm.compiler.debug.DebugContext)10 Node (org.graalvm.compiler.graph.Node)10 FixedNode (org.graalvm.compiler.nodes.FixedNode)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 Test (org.junit.Test)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)7 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 MergeNode (org.graalvm.compiler.nodes.MergeNode)7 StartNode (org.graalvm.compiler.nodes.StartNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 PhiNode (org.graalvm.compiler.nodes.PhiNode)6 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)5 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)4 BeginNode (org.graalvm.compiler.nodes.BeginNode)4