Search in sources :

Example 6 with GuardNode

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

the class GuardPrioritiesTest method growingTest.

@Test
public void growingTest() {
    assumeTrue("GuardPriorities must be turned one", GraalOptions.GuardPriorities.getValue(getInitialOptions()));
    StructuredGraph graph = prepareGraph("growing");
    NodeIterable<GuardNode> guards = graph.getNodes(GuardNode.TYPE).filter(n -> n.inputs().filter(i -> i instanceof IntegerLowerThanNode).isNotEmpty());
    assertThat(guards, isNotEmpty());
    assumeThat(guards, hasCount(2));
    Iterator<GuardNode> iterator = guards.iterator();
    GuardNode g1 = iterator.next();
    GuardNode g2 = iterator.next();
    assertTrue("There should be one guard with speculation, the other one without", g1.getSpeculation().isNull() ^ g2.getSpeculation().isNull());
    GuardNode withSpeculation = g1.getSpeculation().isNull() ? g2 : g1;
    GuardNode withoutSpeculation = g1.getSpeculation().isNull() ? g1 : g2;
    assertOrderedAfterSchedule(graph, SchedulePhase.SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER, withSpeculation, withoutSpeculation);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerLowerThanNode(org.graalvm.compiler.nodes.calc.IntegerLowerThanNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) Test(org.junit.Test)

Example 7 with GuardNode

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

the class ConditionalEliminationTest14 method test1.

@Test
public void test1() {
    StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(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 : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) 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 8 with GuardNode

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

the class GraphUtil method killWithUnusedFloatingInputs.

public static void killWithUnusedFloatingInputs(Node node, boolean mayKillGuard) {
    assert checkKill(node, mayKillGuard);
    node.markDeleted();
    outer: for (Node in : node.inputs()) {
        if (in.isAlive()) {
            in.removeUsage(node);
            if (in.hasNoUsages()) {
                node.maybeNotifyZeroUsages(in);
            }
            if (isFloatingNode(in)) {
                if (in.hasNoUsages()) {
                    if (in instanceof GuardNode) {
                    // Guard nodes are only killed if their anchor dies.
                    } else {
                        killWithUnusedFloatingInputs(in);
                    }
                } else if (in instanceof PhiNode) {
                    for (Node use : in.usages()) {
                        if (use != in) {
                            continue outer;
                        }
                    }
                    in.replaceAtUsages(null);
                    killWithUnusedFloatingInputs(in);
                }
            }
        }
    }
}
Also used : PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) GuardNode(org.graalvm.compiler.nodes.GuardNode)

Example 9 with GuardNode

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

the class GraphUtil method killCFG.

@SuppressWarnings("try")
public static void killCFG(FixedNode node) {
    DebugContext debug = node.getDebug();
    try (DebugContext.Scope scope = debug.scope("KillCFG", node)) {
        EconomicSet<Node> unusedNodes = null;
        EconomicSet<Node> unsafeNodes = null;
        Graph.NodeEventScope nodeEventScope = null;
        OptionValues options = node.getOptions();
        if (Graph.Options.VerifyGraalGraphEdges.getValue(options)) {
            unsafeNodes = collectUnsafeNodes(node.graph());
        }
        if (GraphUtil.Options.VerifyKillCFGUnusedNodes.getValue(options)) {
            EconomicSet<Node> collectedUnusedNodes = unusedNodes = EconomicSet.create(Equivalence.IDENTITY);
            nodeEventScope = node.graph().trackNodeEvents(new Graph.NodeEventListener() {

                @Override
                public void changed(Graph.NodeEvent e, Node n) {
                    if (e == Graph.NodeEvent.ZERO_USAGES && isFloatingNode(n) && !(n instanceof GuardNode)) {
                        collectedUnusedNodes.add(n);
                    }
                }
            });
        }
        debug.dump(DebugContext.VERY_DETAILED_LEVEL, node.graph(), "Before killCFG %s", node);
        killCFGInner(node);
        debug.dump(DebugContext.VERY_DETAILED_LEVEL, node.graph(), "After killCFG %s", node);
        if (Graph.Options.VerifyGraalGraphEdges.getValue(options)) {
            EconomicSet<Node> newUnsafeNodes = collectUnsafeNodes(node.graph());
            newUnsafeNodes.removeAll(unsafeNodes);
            assert newUnsafeNodes.isEmpty() : "New unsafe nodes: " + newUnsafeNodes;
        }
        if (GraphUtil.Options.VerifyKillCFGUnusedNodes.getValue(options)) {
            nodeEventScope.close();
            Iterator<Node> iterator = unusedNodes.iterator();
            while (iterator.hasNext()) {
                Node curNode = iterator.next();
                if (curNode.isDeleted()) {
                    iterator.remove();
                }
            }
            assert unusedNodes.isEmpty() : "New unused nodes: " + unusedNodes;
        }
    } catch (Throwable t) {
        throw debug.handle(t);
    }
}
Also used : Graph(org.graalvm.compiler.graph.Graph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OptionValues(org.graalvm.compiler.options.OptionValues) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

GuardNode (org.graalvm.compiler.nodes.GuardNode)9 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 Node (org.graalvm.compiler.graph.Node)3 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)3 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)3 PhiNode (org.graalvm.compiler.nodes.PhiNode)3 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)3 Test (org.junit.Test)3 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)2 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)2 PiNode (org.graalvm.compiler.nodes.PiNode)2