comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java @ 18993:480bd3b1adcd

Rename BeginNode => AbstractBeginNode.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 28 Jan 2015 00:50:31 +0100
parents 14496953435e
children 8b4ef818169c
comparison
equal deleted inserted replaced
18992:b1c03c2bfa40 18993:480bd3b1adcd
49 @NodeInfo 49 @NodeInfo
50 public class IfNode extends ControlSplitNode implements Simplifiable, LIRLowerable { 50 public class IfNode extends ControlSplitNode implements Simplifiable, LIRLowerable {
51 51
52 private static final DebugMetric CORRECTED_PROBABILITIES = Debug.metric("CorrectedProbabilities"); 52 private static final DebugMetric CORRECTED_PROBABILITIES = Debug.metric("CorrectedProbabilities");
53 53
54 @Successor BeginNode trueSuccessor; 54 @Successor AbstractBeginNode trueSuccessor;
55 @Successor BeginNode falseSuccessor; 55 @Successor AbstractBeginNode falseSuccessor;
56 @Input(InputType.Condition) LogicNode condition; 56 @Input(InputType.Condition) LogicNode condition;
57 protected double trueSuccessorProbability; 57 protected double trueSuccessorProbability;
58 58
59 public LogicNode condition() { 59 public LogicNode condition() {
60 return condition; 60 return condition;
64 updateUsages(condition, x); 64 updateUsages(condition, x);
65 condition = x; 65 condition = x;
66 } 66 }
67 67
68 public IfNode(LogicNode condition, FixedNode trueSuccessor, FixedNode falseSuccessor, double trueSuccessorProbability) { 68 public IfNode(LogicNode condition, FixedNode trueSuccessor, FixedNode falseSuccessor, double trueSuccessorProbability) {
69 this(condition, BeginNode.begin(trueSuccessor), BeginNode.begin(falseSuccessor), trueSuccessorProbability); 69 this(condition, AbstractBeginNode.begin(trueSuccessor), AbstractBeginNode.begin(falseSuccessor), trueSuccessorProbability);
70 } 70 }
71 71
72 public IfNode(LogicNode condition, BeginNode trueSuccessor, BeginNode falseSuccessor, double trueSuccessorProbability) { 72 public IfNode(LogicNode condition, AbstractBeginNode trueSuccessor, AbstractBeginNode falseSuccessor, double trueSuccessorProbability) {
73 super(StampFactory.forVoid()); 73 super(StampFactory.forVoid());
74 this.condition = condition; 74 this.condition = condition;
75 this.falseSuccessor = falseSuccessor; 75 this.falseSuccessor = falseSuccessor;
76 this.trueSuccessor = trueSuccessor; 76 this.trueSuccessor = trueSuccessor;
77 setTrueSuccessorProbability(trueSuccessorProbability); 77 setTrueSuccessorProbability(trueSuccessorProbability);
80 /** 80 /**
81 * Gets the true successor. 81 * Gets the true successor.
82 * 82 *
83 * @return the true successor 83 * @return the true successor
84 */ 84 */
85 public BeginNode trueSuccessor() { 85 public AbstractBeginNode trueSuccessor() {
86 return trueSuccessor; 86 return trueSuccessor;
87 } 87 }
88 88
89 /** 89 /**
90 * Gets the false successor. 90 * Gets the false successor.
91 * 91 *
92 * @return the false successor 92 * @return the false successor
93 */ 93 */
94 public BeginNode falseSuccessor() { 94 public AbstractBeginNode falseSuccessor() {
95 return falseSuccessor; 95 return falseSuccessor;
96 } 96 }
97 97
98 public void setTrueSuccessor(BeginNode node) { 98 public void setTrueSuccessor(AbstractBeginNode node) {
99 updatePredecessor(trueSuccessor, node); 99 updatePredecessor(trueSuccessor, node);
100 trueSuccessor = node; 100 trueSuccessor = node;
101 } 101 }
102 102
103 public void setFalseSuccessor(BeginNode node) { 103 public void setFalseSuccessor(AbstractBeginNode node) {
104 updatePredecessor(falseSuccessor, node); 104 updatePredecessor(falseSuccessor, node);
105 falseSuccessor = node; 105 falseSuccessor = node;
106 } 106 }
107 107
108 /** 108 /**
109 * Gets the node corresponding to the specified outcome of the branch. 109 * Gets the node corresponding to the specified outcome of the branch.
110 * 110 *
111 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise 111 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise
112 * @return the corresponding successor 112 * @return the corresponding successor
113 */ 113 */
114 public BeginNode successor(boolean istrue) { 114 public AbstractBeginNode successor(boolean istrue) {
115 return istrue ? trueSuccessor : falseSuccessor; 115 return istrue ? trueSuccessor : falseSuccessor;
116 } 116 }
117 117
118 public void setTrueSuccessorProbability(double prob) { 118 public void setTrueSuccessorProbability(double prob) {
119 assert prob >= -0.000000001 && prob <= 1.000000001 : "Probability out of bounds: " + prob; 119 assert prob >= -0.000000001 && prob <= 1.000000001 : "Probability out of bounds: " + prob;
120 trueSuccessorProbability = Math.min(1.0, Math.max(0.0, prob)); 120 trueSuccessorProbability = Math.min(1.0, Math.max(0.0, prob));
121 } 121 }
122 122
123 @Override 123 @Override
124 public double probability(BeginNode successor) { 124 public double probability(AbstractBeginNode successor) {
125 return successor == trueSuccessor ? trueSuccessorProbability : 1 - trueSuccessorProbability; 125 return successor == trueSuccessor ? trueSuccessorProbability : 1 - trueSuccessorProbability;
126 } 126 }
127 127
128 @Override 128 @Override
129 public void generate(NodeLIRBuilderTool gen) { 129 public void generate(NodeLIRBuilderTool gen) {
151 trueSuccessorProbability = 1; 151 trueSuccessorProbability = 1;
152 } 152 }
153 } 153 }
154 154
155 if (condition() instanceof LogicNegationNode) { 155 if (condition() instanceof LogicNegationNode) {
156 BeginNode trueSucc = trueSuccessor(); 156 AbstractBeginNode trueSucc = trueSuccessor();
157 BeginNode falseSucc = falseSuccessor(); 157 AbstractBeginNode falseSucc = falseSuccessor();
158 setTrueSuccessor(null); 158 setTrueSuccessor(null);
159 setFalseSuccessor(null); 159 setFalseSuccessor(null);
160 LogicNegationNode negation = (LogicNegationNode) condition(); 160 LogicNegationNode negation = (LogicNegationNode) condition();
161 IfNode newIfNode = graph().add(new IfNode(negation.getValue(), falseSucc, trueSucc, 1 - trueSuccessorProbability)); 161 IfNode newIfNode = graph().add(new IfNode(negation.getValue(), falseSucc, trueSucc, 1 - trueSuccessorProbability));
162 predecessor().replaceFirstSuccessor(this, newIfNode); 162 predecessor().replaceFirstSuccessor(this, newIfNode);
188 if (removeIntermediateMaterialization(tool)) { 188 if (removeIntermediateMaterialization(tool)) {
189 return; 189 return;
190 } 190 }
191 191
192 if (falseSuccessor().hasNoUsages() && (!(falseSuccessor() instanceof LoopExitNode)) && falseSuccessor().next() instanceof IfNode) { 192 if (falseSuccessor().hasNoUsages() && (!(falseSuccessor() instanceof LoopExitNode)) && falseSuccessor().next() instanceof IfNode) {
193 BeginNode intermediateBegin = falseSuccessor(); 193 AbstractBeginNode intermediateBegin = falseSuccessor();
194 IfNode nextIf = (IfNode) intermediateBegin.next(); 194 IfNode nextIf = (IfNode) intermediateBegin.next();
195 double probabilityB = (1.0 - this.trueSuccessorProbability) * nextIf.trueSuccessorProbability; 195 double probabilityB = (1.0 - this.trueSuccessorProbability) * nextIf.trueSuccessorProbability;
196 if (this.trueSuccessorProbability < probabilityB) { 196 if (this.trueSuccessorProbability < probabilityB) {
197 // Reordering of those two if statements is beneficial from the point of view of 197 // Reordering of those two if statements is beneficial from the point of view of
198 // their probabilities. 198 // their probabilities.
199 if (prepareForSwap(tool.getConstantReflection(), condition(), nextIf.condition(), this.trueSuccessorProbability, probabilityB)) { 199 if (prepareForSwap(tool.getConstantReflection(), condition(), nextIf.condition(), this.trueSuccessorProbability, probabilityB)) {
200 // Reordering is allowed from (if1 => begin => if2) to (if2 => begin => if1). 200 // Reordering is allowed from (if1 => begin => if2) to (if2 => begin => if1).
201 assert intermediateBegin.next() == nextIf; 201 assert intermediateBegin.next() == nextIf;
202 BeginNode bothFalseBegin = nextIf.falseSuccessor(); 202 AbstractBeginNode bothFalseBegin = nextIf.falseSuccessor();
203 nextIf.setFalseSuccessor(null); 203 nextIf.setFalseSuccessor(null);
204 intermediateBegin.setNext(null); 204 intermediateBegin.setNext(null);
205 this.setFalseSuccessor(null); 205 this.setFalseSuccessor(null);
206 206
207 this.replaceAtPredecessor(nextIf); 207 this.replaceAtPredecessor(nextIf);
223 223
224 private void pushNodesThroughIf(SimplifierTool tool) { 224 private void pushNodesThroughIf(SimplifierTool tool) {
225 assert trueSuccessor().hasNoUsages() && falseSuccessor().hasNoUsages(); 225 assert trueSuccessor().hasNoUsages() && falseSuccessor().hasNoUsages();
226 // push similar nodes upwards through the if, thereby deduplicating them 226 // push similar nodes upwards through the if, thereby deduplicating them
227 do { 227 do {
228 BeginNode trueSucc = trueSuccessor(); 228 AbstractBeginNode trueSucc = trueSuccessor();
229 BeginNode falseSucc = falseSuccessor(); 229 AbstractBeginNode falseSucc = falseSuccessor();
230 if (trueSucc.getClass() == BeginNode.class && falseSucc.getClass() == BeginNode.class && trueSucc.next() instanceof FixedWithNextNode && falseSucc.next() instanceof FixedWithNextNode) { 230 if (trueSucc.getClass() == AbstractBeginNode.class && falseSucc.getClass() == AbstractBeginNode.class && trueSucc.next() instanceof FixedWithNextNode && falseSucc.next() instanceof FixedWithNextNode) {
231 FixedWithNextNode trueNext = (FixedWithNextNode) trueSucc.next(); 231 FixedWithNextNode trueNext = (FixedWithNextNode) trueSucc.next();
232 FixedWithNextNode falseNext = (FixedWithNextNode) falseSucc.next(); 232 FixedWithNextNode falseNext = (FixedWithNextNode) falseSucc.next();
233 NodeClass nodeClass = trueNext.getNodeClass(); 233 NodeClass nodeClass = trueNext.getNodeClass();
234 if (trueNext.getClass() == falseNext.getClass()) { 234 if (trueNext.getClass() == falseNext.getClass()) {
235 if (nodeClass.getEdges(Inputs).areEqualIn(trueNext, falseNext) && trueNext.valueEquals(falseNext)) { 235 if (nodeClass.getEdges(Inputs).areEqualIn(trueNext, falseNext) && trueNext.valueEquals(falseNext)) {
273 Constant y = lessThan.getY().stamp().asConstant(); 273 Constant y = lessThan.getY().stamp().asConstant();
274 if (y instanceof PrimitiveConstant && ((PrimitiveConstant) y).asLong() == 0 && falseSuccessor().next() instanceof IfNode) { 274 if (y instanceof PrimitiveConstant && ((PrimitiveConstant) y).asLong() == 0 && falseSuccessor().next() instanceof IfNode) {
275 IfNode ifNode2 = (IfNode) falseSuccessor().next(); 275 IfNode ifNode2 = (IfNode) falseSuccessor().next();
276 if (ifNode2.condition() instanceof IntegerLessThanNode) { 276 if (ifNode2.condition() instanceof IntegerLessThanNode) {
277 IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition(); 277 IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition();
278 BeginNode falseSucc = ifNode2.falseSuccessor(); 278 AbstractBeginNode falseSucc = ifNode2.falseSuccessor();
279 BeginNode trueSucc = ifNode2.trueSuccessor(); 279 AbstractBeginNode trueSucc = ifNode2.trueSuccessor();
280 IntegerBelowNode below = null; 280 IntegerBelowNode below = null;
281 /* 281 /*
282 * Convert x >= 0 && x < positive which is represented as !(x < 0) && x < 282 * Convert x >= 0 && x < positive which is represented as !(x < 0) && x <
283 * <positive> into an unsigned compare. 283 * <positive> into an unsigned compare.
284 */ 284 */
285 if (lessThan2.getX() == lessThan.getX() && lessThan2.getY().stamp() instanceof IntegerStamp && ((IntegerStamp) lessThan2.getY().stamp()).isPositive() && 285 if (lessThan2.getX() == lessThan.getX() && lessThan2.getY().stamp() instanceof IntegerStamp && ((IntegerStamp) lessThan2.getY().stamp()).isPositive() &&
286 sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) { 286 sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) {
287 below = graph().unique(new IntegerBelowNode(lessThan2.getX(), lessThan2.getY())); 287 below = graph().unique(new IntegerBelowNode(lessThan2.getX(), lessThan2.getY()));
288 // swap direction 288 // swap direction
289 BeginNode tmp = falseSucc; 289 AbstractBeginNode tmp = falseSucc;
290 falseSucc = trueSucc; 290 falseSucc = trueSucc;
291 trueSucc = tmp; 291 trueSucc = tmp;
292 } else if (lessThan2.getY() == lessThan.getX() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) { 292 } else if (lessThan2.getY() == lessThan.getX() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) {
293 /* 293 /*
294 * Convert x >= 0 && x <= positive which is represented as !(x < 0) && 294 * Convert x >= 0 && x <= positive which is represented as !(x < 0) &&
324 324
325 /** 325 /**
326 * Check it these two blocks end up at the same place. Meeting at the same merge, or 326 * Check it these two blocks end up at the same place. Meeting at the same merge, or
327 * deoptimizing in the same way. 327 * deoptimizing in the same way.
328 */ 328 */
329 private static boolean sameDestination(BeginNode succ1, BeginNode succ2) { 329 private static boolean sameDestination(AbstractBeginNode succ1, AbstractBeginNode succ2) {
330 Node next1 = succ1.next(); 330 Node next1 = succ1.next();
331 Node next2 = succ2.next(); 331 Node next2 = succ2.next();
332 if (next1 instanceof EndNode && next2 instanceof EndNode) { 332 if (next1 instanceof EndNode && next2 instanceof EndNode) {
333 EndNode end1 = (EndNode) next1; 333 EndNode end1 = (EndNode) next1;
334 EndNode end2 = (EndNode) next2; 334 EndNode end2 = (EndNode) next2;
550 } 550 }
551 return false; 551 return false;
552 } 552 }
553 553
554 protected void removeThroughFalseBranch(SimplifierTool tool) { 554 protected void removeThroughFalseBranch(SimplifierTool tool) {
555 BeginNode trueBegin = trueSuccessor(); 555 AbstractBeginNode trueBegin = trueSuccessor();
556 graph().removeSplitPropagate(this, trueBegin, tool); 556 graph().removeSplitPropagate(this, trueBegin, tool);
557 tool.addToWorkList(trueBegin); 557 tool.addToWorkList(trueBegin);
558 } 558 }
559 559
560 private ConditionalNode canonicalizeConditionalCascade(ValueNode trueValue, ValueNode falseValue) { 560 private ConditionalNode canonicalizeConditionalCascade(ValueNode trueValue, ValueNode falseValue) {
700 700
701 List<AbstractEndNode> falseEnds = new ArrayList<>(mergePredecessors.size()); 701 List<AbstractEndNode> falseEnds = new ArrayList<>(mergePredecessors.size());
702 List<AbstractEndNode> trueEnds = new ArrayList<>(mergePredecessors.size()); 702 List<AbstractEndNode> trueEnds = new ArrayList<>(mergePredecessors.size());
703 Map<AbstractEndNode, ValueNode> phiValues = CollectionsFactory.newMap(mergePredecessors.size()); 703 Map<AbstractEndNode, ValueNode> phiValues = CollectionsFactory.newMap(mergePredecessors.size());
704 704
705 BeginNode oldFalseSuccessor = falseSuccessor(); 705 AbstractBeginNode oldFalseSuccessor = falseSuccessor();
706 BeginNode oldTrueSuccessor = trueSuccessor(); 706 AbstractBeginNode oldTrueSuccessor = trueSuccessor();
707 707
708 setFalseSuccessor(null); 708 setFalseSuccessor(null);
709 setTrueSuccessor(null); 709 setTrueSuccessor(null);
710 710
711 Iterator<AbstractEndNode> ends = mergePredecessors.iterator(); 711 Iterator<AbstractEndNode> ends = mergePredecessors.iterator();
838 * {@linkplain SimplifierTool#addToWorkList(com.oracle.graal.graph.Node) work list}. 838 * {@linkplain SimplifierTool#addToWorkList(com.oracle.graal.graph.Node) work list}.
839 * 839 *
840 * @param oldMerge the merge being removed 840 * @param oldMerge the merge being removed
841 * @param phiValues the values of the phi at the merge, keyed by the merge ends 841 * @param phiValues the values of the phi at the merge, keyed by the merge ends
842 */ 842 */
843 private void connectEnds(List<AbstractEndNode> ends, Map<AbstractEndNode, ValueNode> phiValues, BeginNode successor, MergeNode oldMerge, SimplifierTool tool) { 843 private void connectEnds(List<AbstractEndNode> ends, Map<AbstractEndNode, ValueNode> phiValues, AbstractBeginNode successor, MergeNode oldMerge, SimplifierTool tool) {
844 if (!ends.isEmpty()) { 844 if (!ends.isEmpty()) {
845 if (ends.size() == 1) { 845 if (ends.size() == 1) {
846 AbstractEndNode end = ends.get(0); 846 AbstractEndNode end = ends.get(0);
847 ((FixedWithNextNode) end.predecessor()).setNext(successor); 847 ((FixedWithNextNode) end.predecessor()).setNext(successor);
848 oldMerge.removeEnd(end); 848 oldMerge.removeEnd(end);