Search in sources :

Example 1 with NodeFlood

use of org.graalvm.compiler.graph.NodeFlood in project graal by oracle.

the class DeadCodeEliminationPhase method run.

@Override
public void run(StructuredGraph graph) {
    if (optional && Options.ReduceDCE.getValue(graph.getOptions())) {
        return;
    }
    NodeFlood flood = graph.createNodeFlood();
    int totalNodeCount = graph.getNodeCount();
    flood.add(graph.start());
    iterateSuccessorsAndInputs(flood);
    boolean changed = false;
    for (GuardNode guard : graph.getNodes(GuardNode.TYPE)) {
        if (flood.isMarked(guard.getAnchor().asNode())) {
            flood.add(guard);
            changed = true;
        }
    }
    if (changed) {
        iterateSuccessorsAndInputs(flood);
    }
    int totalMarkedCount = flood.getTotalMarkedCount();
    if (totalNodeCount == totalMarkedCount) {
        // All nodes are live => nothing more to do.
        return;
    } else {
        // Some nodes are not marked alive and therefore dead => proceed.
        assert totalNodeCount > totalMarkedCount;
    }
    deleteNodes(flood, graph);
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) NodeFlood(org.graalvm.compiler.graph.NodeFlood)

Example 2 with NodeFlood

use of org.graalvm.compiler.graph.NodeFlood in project graal by oracle.

the class VirtualUtil method assertNonReachable.

public static boolean assertNonReachable(StructuredGraph graph, List<Node> obsoleteNodes) {
    // Helper code that determines the paths that keep obsolete nodes alive.
    // Nodes with support for GVN can be kept alive by GVN and are therefore not part of the
    // assertion.
    DebugContext debug = graph.getDebug();
    NodeFlood flood = graph.createNodeFlood();
    EconomicMap<Node, Node> path = EconomicMap.create(Equivalence.IDENTITY);
    flood.add(graph.start());
    for (Node current : flood) {
        if (current instanceof AbstractEndNode) {
            AbstractEndNode end = (AbstractEndNode) current;
            flood.add(end.merge());
            if (!path.containsKey(end.merge())) {
                path.put(end.merge(), end);
            }
        } else {
            for (Node successor : current.successors()) {
                flood.add(successor);
                if (!path.containsKey(successor)) {
                    path.put(successor, current);
                }
            }
        }
    }
    for (Node node : obsoleteNodes) {
        if (node instanceof FixedNode && !node.isDeleted()) {
            assert !flood.isMarked(node) : node;
        }
    }
    for (Node node : graph.getNodes()) {
        if (flood.isMarked(node)) {
            for (Node input : node.inputs()) {
                flood.add(input);
                if (!path.containsKey(input)) {
                    path.put(input, node);
                }
            }
        }
    }
    for (Node current : flood) {
        for (Node input : current.inputs()) {
            flood.add(input);
            if (!path.containsKey(input)) {
                path.put(input, current);
            }
        }
    }
    boolean success = true;
    for (Node node : obsoleteNodes) {
        if (!node.isDeleted() && flood.isMarked(node) && !node.getNodeClass().valueNumberable()) {
            TTY.println("offending node path:");
            Node current = node;
            TTY.print(current.toString());
            while (true) {
                current = path.get(current);
                if (current != null) {
                    TTY.print(" -> " + current.toString());
                    if (current instanceof FixedNode && !obsoleteNodes.contains(current)) {
                        break;
                    }
                }
            }
            success = false;
        }
    }
    if (!success) {
        TTY.println();
        debug.forceDump(graph, "assertNonReachable");
    }
    return success;
}
Also used : FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) Node(org.graalvm.compiler.graph.Node) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) NodeFlood(org.graalvm.compiler.graph.NodeFlood)

Example 3 with NodeFlood

use of org.graalvm.compiler.graph.NodeFlood in project graal by oracle.

the class WriteBarrierVerificationPhase method validateWrite.

private void validateWrite(Node write) {
    /*
         * The currently validated write is checked in order to discover if it has an appropriate
         * attached write barrier.
         */
    if (hasAttachedBarrier((FixedWithNextNode) write)) {
        return;
    }
    NodeFlood frontier = write.graph().createNodeFlood();
    expandFrontier(frontier, write);
    Iterator<Node> iterator = frontier.iterator();
    while (iterator.hasNext()) {
        Node currentNode = iterator.next();
        if (isSafepoint(currentNode)) {
            throw new AssertionError("Write barrier must be present " + write.toString(Verbosity.All) + " / " + write.inputs());
        }
        if (useG1GC()) {
            if (!(currentNode instanceof G1PostWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode))) {
                expandFrontier(frontier, currentNode);
            }
        } else {
            if (!(currentNode instanceof SerialWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode)) || ((currentNode instanceof SerialWriteBarrier) && !validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode))) {
                expandFrontier(frontier, currentNode);
            }
        }
    }
}
Also used : FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) ObjectWriteBarrier(org.graalvm.compiler.hotspot.nodes.ObjectWriteBarrier) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) NodeFlood(org.graalvm.compiler.graph.NodeFlood)

Aggregations

NodeFlood (org.graalvm.compiler.graph.NodeFlood)3 Node (org.graalvm.compiler.graph.Node)2 DebugContext (org.graalvm.compiler.debug.DebugContext)1 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)1 ObjectWriteBarrier (org.graalvm.compiler.hotspot.nodes.ObjectWriteBarrier)1 SerialWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier)1 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)1 DeoptimizingNode (org.graalvm.compiler.nodes.DeoptimizingNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 GuardNode (org.graalvm.compiler.nodes.GuardNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 LogicCompareAndSwapNode (org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode)1 LoweredAtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)1 FixedAccessNode (org.graalvm.compiler.nodes.memory.FixedAccessNode)1 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)1 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)1 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)1