# HG changeset patch # User Gilles Duboscq # Date 1415786017 -3600 # Node ID 1cd104505b611d9adf75a68f5c0b0eb4d900df9d # Parent 973c6551dfd8335bb7a16112e01cce511825f8ab ConditionalElimination: use GuardingNode interface where possible diff -r 973c6551dfd8 -r 1cd104505b61 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Mon Sep 22 10:27:52 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Nov 12 10:53:37 2014 +0100 @@ -104,8 +104,8 @@ private Map knownTypes; private Set knownNonNull; private Set knownNull; - private Map trueConditions; - private Map falseConditions; + private Map trueConditions; + private Map falseConditions; private Map valueConstraints; public State() { @@ -129,8 +129,8 @@ @Override public boolean merge(MergeNode merge, List withStates) { Map newKnownTypes = Node.newIdentityMap(); - Map newTrueConditions = Node.newIdentityMap(); - Map newFalseConditions = Node.newIdentityMap(); + Map newTrueConditions = Node.newIdentityMap(); + Map newFalseConditions = Node.newIdentityMap(); Map newValueConstraints = Node.newIdentityMap(); Set newKnownNull = Node.newSet(knownNull); @@ -156,12 +156,12 @@ } } - for (Map.Entry entry : trueConditions.entrySet()) { + for (Map.Entry entry : trueConditions.entrySet()) { LogicNode check = entry.getKey(); - ValueNode guard = entry.getValue(); + GuardingNode guard = entry.getValue(); for (State other : withStates) { - ValueNode otherGuard = other.trueConditions.get(check); + GuardingNode otherGuard = other.trueConditions.get(check); if (otherGuard == null) { guard = null; break; @@ -174,12 +174,12 @@ newTrueConditions.put(check, guard); } } - for (Map.Entry entry : falseConditions.entrySet()) { + for (Map.Entry entry : falseConditions.entrySet()) { LogicNode check = entry.getKey(); - ValueNode guard = entry.getValue(); + GuardingNode guard = entry.getValue(); for (State other : withStates) { - ValueNode otherGuard = other.falseConditions.get(check); + GuardingNode otherGuard = other.falseConditions.get(check); if (otherGuard == null) { guard = null; break; @@ -254,7 +254,7 @@ * Adds information about a condition. If isTrue is true then the condition is known to * hold, otherwise the condition is known not to hold. */ - public void addCondition(boolean isTrue, LogicNode condition, ValueNode anchor) { + public void addCondition(boolean isTrue, LogicNode condition, GuardingNode anchor) { if (isTrue) { if (!trueConditions.containsKey(condition)) { trueConditions.put(condition, anchor); @@ -352,7 +352,7 @@ super.finished(); } - private void registerCondition(boolean isTrue, LogicNode condition, ValueNode anchor) { + private void registerCondition(boolean isTrue, LogicNode condition, GuardingNode anchor) { if (!isTrue && condition instanceof ShortCircuitOrNode) { /* * We can only do this for fixed nodes, because floating guards will be registered @@ -476,7 +476,7 @@ if (testExistingGuard(guard)) { return true; } else { - ValueNode anchor = state.trueConditions.get(condition); + GuardingNode anchor = state.trueConditions.get(condition); if (anchor != null) { if (!guard.negated()) { eliminateGuard(guard, anchor); @@ -503,8 +503,8 @@ * @param guard The guard to eliminate. * @param anchor Node to replace the guard. */ - private void eliminateGuard(GuardNode guard, ValueNode anchor) { - guard.replaceAtUsages(anchor); + private void eliminateGuard(GuardNode guard, GuardingNode anchor) { + guard.replaceAtUsages(anchor.asNode()); metricGuardsRemoved.increment(); GraphUtil.killWithUnusedFloatingInputs(guard); } @@ -574,7 +574,7 @@ } private boolean testExistingGuard(GuardNode guard) { - ValueNode existingGuard = guard.negated() ? state.falseConditions.get(guard.condition()) : state.trueConditions.get(guard.condition()); + GuardingNode existingGuard = guard.negated() ? state.falseConditions.get(guard.condition()) : state.trueConditions.get(guard.condition()); if (existingGuard != null && existingGuard != guard) { eliminateGuard(guard, existingGuard); return true; @@ -694,9 +694,9 @@ } } else if (node instanceof FixedGuardNode) { FixedGuardNode guard = (FixedGuardNode) node; - ValueNode existingGuard = guard.isNegated() ? state.falseConditions.get(guard.condition()) : state.trueConditions.get(guard.condition()); + GuardingNode existingGuard = guard.isNegated() ? state.falseConditions.get(guard.condition()) : state.trueConditions.get(guard.condition()); if (existingGuard != null && existingGuard instanceof FixedGuardNode) { - guard.replaceAtUsages(existingGuard); + guard.replaceAtUsages(existingGuard.asNode()); guard.graph().removeFixed(guard); } else { registerCondition(!guard.isNegated(), guard.condition(), guard); @@ -729,7 +729,7 @@ } else if (node instanceof ConditionAnchorNode) { ConditionAnchorNode conditionAnchorNode = (ConditionAnchorNode) node; LogicNode condition = conditionAnchorNode.condition(); - ValueNode replacementAnchor = null; + GuardingNode replacementAnchor = null; if (conditionAnchorNode.isNegated()) { if (state.falseConditions.containsKey(condition)) { replacementAnchor = state.falseConditions.get(condition); @@ -740,7 +740,7 @@ } } if (replacementAnchor != null) { - conditionAnchorNode.replaceAtUsages(replacementAnchor); + conditionAnchorNode.replaceAtUsages(replacementAnchor.asNode()); conditionAnchorNode.graph().removeFixed(conditionAnchorNode); } } else if (node instanceof IfNode) { @@ -748,7 +748,7 @@ LogicNode compare = ifNode.condition(); LogicNode replacement = null; - ValueNode replacementAnchor = null; + GuardingNode replacementAnchor = null; BeginNode survivingSuccessor = null; if (state.trueConditions.containsKey(compare)) { replacement = trueConstant; @@ -772,7 +772,7 @@ if (replacement != null) { if (replacementAnchor != null && !(replacementAnchor instanceof BeginNode)) { - ValueAnchorNode anchor = graph.add(ValueAnchorNode.create(replacementAnchor)); + ValueAnchorNode anchor = graph.add(ValueAnchorNode.create(replacementAnchor.asNode())); graph.addBeforeFixed(ifNode, anchor); } for (Node n : survivingSuccessor.usages().snapshot()) { @@ -784,7 +784,7 @@ return; } // Rewire to the replacement anchor. - n.replaceFirstInput(survivingSuccessor, replacementAnchor); + n.replaceFirstInput(survivingSuccessor, replacementAnchor.asNode()); } } @@ -838,9 +838,9 @@ if (n instanceof InstanceOfNode) { InstanceOfNode instanceOfNode = (InstanceOfNode) n; if (instanceOfNode.type().equals(type) && state.trueConditions.containsKey(instanceOfNode)) { - ValueNode v = state.trueConditions.get(instanceOfNode); - if (v instanceof GuardingNode) { - return (GuardingNode) v; + GuardingNode v = state.trueConditions.get(instanceOfNode); + if (v != null) { + return v; } } }