public static boolean tryKillUnused(Node node) { if (node.isAlive() && isFloatingNode().apply(node) && node.usages().isEmpty()) { killWithUnusedFloatingInputs(node); return true; } return false; }
public static void killWithUnusedFloatingInputs(Node node) { List<Node> floatingInputs = node.inputs().filter(isFloatingNode()).snapshot(); node.safeDelete(); for (Node in : floatingInputs) { if (in.isAlive() && in.usages().isEmpty()) { killWithUnusedFloatingInputs(in); } } }
public static void propagateKill(Node node) { if (node != null && node.isAlive()) { List<Node> usagesSnapshot = node.usages().filter(isFloatingNode()).snapshot(); // null out remaining usages node.replaceAtUsages(null); node.replaceAtPredecessor(null); killWithUnusedFloatingInputs(node); for (Node usage : usagesSnapshot) { if (!usage.isDeleted()) { if (usage instanceof PhiNode) { usage.replaceFirstInput(node, null); } else { propagateKill(usage); } } } } }