Search in sources :

Example 61 with FrameState

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

the class GraphUtil method removeFixedWithUnusedInputs.

public static void removeFixedWithUnusedInputs(FixedWithNextNode fixed) {
    if (fixed instanceof StateSplit) {
        FrameState stateAfter = ((StateSplit) fixed).stateAfter();
        if (stateAfter != null) {
            ((StateSplit) fixed).setStateAfter(null);
            if (stateAfter.hasNoUsages()) {
                killWithUnusedFloatingInputs(stateAfter);
            }
        }
    }
    unlinkFixedNode(fixed);
    killWithUnusedFloatingInputs(fixed);
}
Also used : FrameState(org.graalvm.compiler.nodes.FrameState) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 62 with FrameState

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

the class SchedulingTest method testValueProxyInputs.

@Test
public void testValueProxyInputs() {
    StructuredGraph graph = parseEager("testValueProxyInputsSnippet", AllowAssumptions.YES);
    for (FrameState fs : graph.getNodes().filter(FrameState.class).snapshot()) {
        fs.replaceAtUsages(null);
        GraphUtil.killWithUnusedFloatingInputs(fs);
    }
    SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST);
    schedulePhase.apply(graph);
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getCFG().getNodeToBlock();
    assertTrue(graph.getNodes().filter(LoopExitNode.class).count() == 1);
    LoopExitNode loopExit = graph.getNodes().filter(LoopExitNode.class).first();
    List<Node> list = schedule.nodesFor(nodeToBlock.get(loopExit));
    for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
        if (!(node instanceof AddNode)) {
            assertTrue(node.toString(), nodeToBlock.get(node) == nodeToBlock.get(loopExit));
            assertTrue(list.indexOf(node) + " < " + list.indexOf(loopExit) + ", " + node + ", " + loopExit, list.indexOf(node) < list.indexOf(loopExit));
        }
    }
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) Node(org.graalvm.compiler.graph.Node) Block(org.graalvm.compiler.nodes.cfg.Block) FrameState(org.graalvm.compiler.nodes.FrameState) AddNode(org.graalvm.compiler.nodes.calc.AddNode) Test(org.junit.Test)

Example 63 with FrameState

use of org.graalvm.compiler.nodes.FrameState 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 64 with FrameState

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

the class IfCanonicalizerTest method test.

private void test(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
    ConstantNode constant = ConstantNode.forInt(0, graph);
    for (Node n : param.usages().snapshot()) {
        if (!(n instanceof FrameState)) {
            n.replaceFirstInput(param, constant);
        }
    }
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
        fs.replaceFirstInput(param, null);
        param.safeDelete();
    }
    StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IfNode(org.graalvm.compiler.nodes.IfNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 65 with FrameState

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

the class IntegerEqualsCanonicalizerTest method getCanonicalizedGraph.

private StructuredGraph getCanonicalizedGraph(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    for (FrameState state : graph.getNodes(FrameState.TYPE).snapshot()) {
        state.replaceAtUsages(null);
        state.safeDelete();
    }
    return graph;
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FrameState(org.graalvm.compiler.nodes.FrameState)

Aggregations

FrameState (org.graalvm.compiler.nodes.FrameState)73 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 Node (org.graalvm.compiler.graph.Node)27 FixedNode (org.graalvm.compiler.nodes.FixedNode)21 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)19 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)16 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)16 PhiNode (org.graalvm.compiler.nodes.PhiNode)16 EndNode (org.graalvm.compiler.nodes.EndNode)15 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)15 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)14 MergeNode (org.graalvm.compiler.nodes.MergeNode)14 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)13 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)12 StateSplit (org.graalvm.compiler.nodes.StateSplit)12 MonitorIdNode (org.graalvm.compiler.nodes.java.MonitorIdNode)12 DebugContext (org.graalvm.compiler.debug.DebugContext)11 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)11 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)11