# HG changeset patch # User Doug Simon # Date 1366106790 -7200 # Node ID d0aab82a60462865c25f1b09be9149acf047c495 # Parent 703228415b74a49627c797d765411adf353635cf removed unused code in lowering of instanceof in the context of an IfNode diff -r 703228415b74 -r d0aab82a6046 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java Tue Apr 16 11:33:20 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java Tue Apr 16 12:06:30 2013 +0200 @@ -91,11 +91,14 @@ /** * Gets the specific replacer object used to replace the usage of an instanceof node with the * result of an instantiated instanceof snippet. + * + * @param nUsages + * @param tool */ protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, LoweringTool tool, int nUsages, Instantiation instantiation, Node usage, final StructuredGraph graph) { InstanceOfUsageReplacer replacer; if (usage instanceof IfNode) { - replacer = new IfUsageReplacer(instantiation, ConstantNode.forInt(1, graph), ConstantNode.forInt(0, graph), instanceOf, (IfNode) usage, nUsages == 1, tool); + replacer = new IfUsageReplacer(instantiation, ConstantNode.forInt(1, graph), ConstantNode.forInt(0, graph), instanceOf, (IfNode) usage); } else { assert usage instanceof ConditionalNode : "unexpected usage of " + instanceOf + ": " + usage; ConditionalNode c = (ConditionalNode) usage; @@ -190,14 +193,10 @@ */ public static class IfUsageReplacer extends InstanceOfUsageReplacer { - private final boolean solitaryUsage; private final IfNode usage; - private final boolean sameBlock; - public IfUsageReplacer(Instantiation instantiation, ValueNode trueValue, ValueNode falseValue, FloatingNode instanceOf, IfNode usage, boolean solitaryUsage, LoweringTool tool) { + public IfUsageReplacer(Instantiation instantiation, ValueNode trueValue, ValueNode falseValue, FloatingNode instanceOf, IfNode usage) { super(instantiation, instanceOf, trueValue, falseValue); - this.sameBlock = tool.getBlockFor(usage) == tool.getBlockFor(instanceOf); - this.solitaryUsage = solitaryUsage; this.usage = usage; } @@ -206,84 +205,13 @@ usage.replaceFirstInput(instanceOf, instantiation.asCondition(trueValue)); } - private boolean usageFollowsInstantiation() { - return instantiation.result != null && instantiation.result.merge().next() == usage; - } - @Override public void replace(ValueNode oldNode, ValueNode newNode) { assert newNode instanceof PhiNode; assert oldNode == instanceOf; - if (sameBlock && solitaryUsage && usageFollowsInstantiation()) { - removeIntermediateMaterialization(newNode); - } else { - newNode.inferStamp(); - instantiation.initialize((PhiNode) newNode, trueValue, falseValue); - usage.replaceFirstInput(oldNode, instantiation.asCondition(trueValue)); - } - } - - /** - * Directly wires the incoming edges of the merge at the end of the snippet to the outgoing - * edges of the IfNode that uses the materialized result. - */ - private void removeIntermediateMaterialization(ValueNode newNode) { - IfNode ifNode = usage; - PhiNode phi = (PhiNode) newNode; - MergeNode merge = phi.merge(); - assert merge.stateAfter() == null; - - List mergePredecessors = merge.cfgPredecessors().snapshot(); - assert phi.valueCount() == mergePredecessors.size(); - - List falseEnds = new ArrayList<>(mergePredecessors.size()); - List trueEnds = new ArrayList<>(mergePredecessors.size()); - - int endIndex = 0; - for (EndNode end : mergePredecessors) { - ValueNode endValue = phi.valueAt(endIndex++); - if (endValue == trueValue) { - trueEnds.add(end); - } else { - assert endValue == falseValue; - falseEnds.add(end); - } - } - - BeginNode trueSuccessor = ifNode.trueSuccessor(); - BeginNode falseSuccessor = ifNode.falseSuccessor(); - ifNode.setTrueSuccessor(null); - ifNode.setFalseSuccessor(null); - - connectEnds(merge, trueEnds, trueSuccessor); - connectEnds(merge, falseEnds, falseSuccessor); - - GraphUtil.killCFG(merge); - GraphUtil.killCFG(ifNode); - - assert !merge.isAlive() : merge; - assert !phi.isAlive() : phi; - } - - private static void connectEnds(MergeNode merge, List ends, BeginNode successor) { - if (ends.size() == 0) { - // InstanceOf has been lowered to always true or always false - this successor is - // therefore unreachable. - GraphUtil.killCFG(successor); - } else if (ends.size() == 1) { - EndNode end = ends.get(0); - ((FixedWithNextNode) end.predecessor()).setNext(successor); - merge.removeEnd(end); - GraphUtil.killCFG(end); - } else { - assert ends.size() > 1; - MergeNode newMerge = merge.graph().add(new MergeNode()); - - for (EndNode end : ends) { - newMerge.addForwardEnd(end); - } - newMerge.setNext(successor); - } + newNode.inferStamp(); + instantiation.initialize((PhiNode) newNode, trueValue, falseValue); + usage.replaceFirstInput(oldNode, instantiation.asCondition(trueValue)); } }