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);
}
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;
}
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);
}
}
}
}
Aggregations