Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/ir/If.java @ 2602:0c6564c254af
new node layout: BlockBegin, BlockEnd
-Dc1x.dot=regex for pdf output
escape dot graph labels (<, >, &)
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 06 May 2011 10:25:37 +0200 |
parents | 4a36a0bd6d18 |
children | 3558ca7088c0 |
comparison
equal
deleted
inserted
replaced
2601:224e8b4007bd | 2602:0c6564c254af |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.sun.c1x.ir; | 23 package com.sun.c1x.ir; |
24 | 24 |
25 import com.oracle.graal.graph.*; | |
25 import com.sun.c1x.debug.*; | 26 import com.sun.c1x.debug.*; |
26 import com.sun.c1x.util.*; | 27 import com.sun.c1x.util.*; |
27 import com.sun.c1x.value.*; | 28 import com.sun.c1x.value.*; |
28 import com.sun.cri.ci.*; | 29 import com.sun.cri.ci.*; |
29 | 30 |
30 /** | 31 /** |
31 * The {@code If} instruction represents a branch that can go one of two directions | 32 * The {@code If} instruction represents a branch that can go one of two directions |
32 * depending on the outcome of a comparison. | 33 * depending on the outcome of a comparison. |
33 * | |
34 * @author Ben L. Titzer | |
35 */ | 34 */ |
36 public final class If extends BlockEnd { | 35 public final class If extends BlockEnd { |
37 | 36 |
38 Value x; | 37 private static final int INPUT_COUNT = 2; |
39 Value y; | 38 private static final int INPUT_X = 0; |
39 private static final int INPUT_Y = 1; | |
40 | |
41 private static final int SUCCESSOR_COUNT = 0; | |
42 | |
43 @Override | |
44 protected int inputCount() { | |
45 return super.inputCount() + INPUT_COUNT; | |
46 } | |
47 | |
48 @Override | |
49 protected int successorCount() { | |
50 return super.successorCount() + SUCCESSOR_COUNT; | |
51 } | |
52 | |
53 /** | |
54 * The instruction that produces the first input to this comparison. | |
55 */ | |
56 public Value x() { | |
57 return (Value) inputs().get(super.inputCount() + INPUT_X); | |
58 } | |
59 | |
60 public Value setX(Value n) { | |
61 return (Value) inputs().set(super.inputCount() + INPUT_X, n); | |
62 } | |
63 | |
64 /** | |
65 * The instruction that produces the second input to this comparison. | |
66 */ | |
67 public Value y() { | |
68 return (Value) inputs().get(super.inputCount() + INPUT_Y); | |
69 } | |
70 | |
71 public Value setY(Value n) { | |
72 return (Value) inputs().set(super.inputCount() + INPUT_Y, n); | |
73 } | |
74 | |
40 Condition condition; | 75 Condition condition; |
41 boolean unorderedIsTrue; | 76 boolean unorderedIsTrue; |
42 | 77 |
43 /** | 78 /** |
44 * Constructs a new If instruction. | 79 * Constructs a new If instruction. |
45 * @param x the instruction producing the first input to the instruction | 80 * @param x the instruction producing the first input to the instruction |
46 * @param cond the condition (comparison operation) | 81 * @param cond the condition (comparison operation) |
47 * @param unorderedIsTrue {@code true} if unordered is treated as true (floating point operations) | |
48 * @param y the instruction that produces the second input to this instruction | 82 * @param y the instruction that produces the second input to this instruction |
49 * @param trueSucc the block representing the true successor | 83 * @param trueSucc the block representing the true successor |
50 * @param falseSucc the block representing the false successor | 84 * @param falseSucc the block representing the false successor |
51 * @param stateAfter the state before the branch but after the input values have been popped | 85 * @param stateAfter the state before the branch but after the input values have been popped |
52 * @param isSafepoint {@code true} if this branch should be considered a safepoint | 86 * @param isSafepoint {@code true} if this branch should be considered a safepoint |
87 * @param graph | |
53 */ | 88 */ |
54 public If(Value x, Condition cond, Value y, | 89 public If(Value x, Condition cond, Value y, |
55 BlockBegin trueSucc, BlockBegin falseSucc, FrameState stateAfter, boolean isSafepoint) { | 90 BlockBegin trueSucc, BlockBegin falseSucc, FrameState stateAfter, boolean isSafepoint, Graph graph) { |
56 super(CiKind.Illegal, stateAfter, isSafepoint); | 91 super(CiKind.Illegal, stateAfter, isSafepoint, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); |
57 this.x = x; | 92 assert Util.archKindsEqual(x, y); |
58 this.y = y; | |
59 condition = cond; | 93 condition = cond; |
60 assert Util.archKindsEqual(x, y); | 94 setX(x); |
61 successors.add(trueSucc); | 95 setY(y); |
62 successors.add(falseSucc); | 96 setBlockSuccessor(0, trueSucc); |
63 } | 97 setBlockSuccessor(1, falseSucc); |
64 | |
65 /** | |
66 * Gets the instruction that produces the first input to this comparison. | |
67 * @return the instruction producing the first input | |
68 */ | |
69 public Value x() { | |
70 return x; | |
71 } | |
72 | |
73 /** | |
74 * Gets the instruction that produces the second input to this comparison. | |
75 * @return the instruction producing the second input | |
76 */ | |
77 public Value y() { | |
78 return y; | |
79 } | 98 } |
80 | 99 |
81 /** | 100 /** |
82 * Gets the condition (comparison operation) for this instruction. | 101 * Gets the condition (comparison operation) for this instruction. |
83 * @return the condition | 102 * @return the condition |
97 /** | 116 /** |
98 * Gets the block corresponding to the true successor. | 117 * Gets the block corresponding to the true successor. |
99 * @return the true successor | 118 * @return the true successor |
100 */ | 119 */ |
101 public BlockBegin trueSuccessor() { | 120 public BlockBegin trueSuccessor() { |
102 return successors.get(0); | 121 return blockSuccessor(0); |
103 } | 122 } |
104 | 123 |
105 /** | 124 /** |
106 * Gets the block corresponding to the false successor. | 125 * Gets the block corresponding to the false successor. |
107 * @return the false successor | 126 * @return the false successor |
108 */ | 127 */ |
109 public BlockBegin falseSuccessor() { | 128 public BlockBegin falseSuccessor() { |
110 return successors.get(1); | 129 return blockSuccessor(1); |
111 } | 130 } |
112 | 131 |
113 /** | 132 /** |
114 * Gets the block corresponding to the specified outcome of the branch. | 133 * Gets the block corresponding to the specified outcome of the branch. |
115 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise | 134 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise |
116 * @return the corresponding successor | 135 * @return the corresponding successor |
117 */ | 136 */ |
118 public BlockBegin successor(boolean istrue) { | 137 public BlockBegin successor(boolean istrue) { |
119 return successors.get(istrue ? 0 : 1); | 138 return blockSuccessor(istrue ? 0 : 1); |
120 } | 139 } |
121 | 140 |
122 /** | 141 /** |
123 * Gets the successor of this instruction for the unordered case. | 142 * Gets the successor of this instruction for the unordered case. |
124 * @return the successor for unordered inputs | 143 * @return the successor for unordered inputs |
131 * Swaps the operands to this if and reverses the condition (e.g. > goes to <=). | 150 * Swaps the operands to this if and reverses the condition (e.g. > goes to <=). |
132 * @see Condition#mirror() | 151 * @see Condition#mirror() |
133 */ | 152 */ |
134 public void swapOperands() { | 153 public void swapOperands() { |
135 condition = condition.mirror(); | 154 condition = condition.mirror(); |
136 Value t = x; | 155 Value t = x(); |
137 x = y; | 156 setX(y()); |
138 y = t; | 157 setY(t); |
139 } | 158 } |
140 | 159 |
141 /** | 160 /** |
142 * Swaps the successor blocks to this if and negates the condition (e.g. == goes to !=) | 161 * Swaps the successor blocks to this if and negates the condition (e.g. == goes to !=) |
143 * @see Condition#negate() | 162 * @see Condition#negate() |
144 */ | 163 */ |
145 public void swapSuccessors() { | 164 public void swapSuccessors() { |
146 unorderedIsTrue = !unorderedIsTrue; | 165 unorderedIsTrue = !unorderedIsTrue; |
147 condition = condition.negate(); | 166 condition = condition.negate(); |
148 BlockBegin t = successors.get(0); | 167 BlockBegin t = blockSuccessor(0); |
149 BlockBegin f = successors.get(1); | 168 BlockBegin f = blockSuccessor(1); |
150 successors.set(0, f); | 169 setBlockSuccessor(0, f); |
151 successors.set(1, t); | 170 setBlockSuccessor(1, t); |
152 } | |
153 | |
154 @Override | |
155 public void inputValuesDo(ValueClosure closure) { | |
156 x = closure.apply(x); | |
157 y = closure.apply(y); | |
158 } | 171 } |
159 | 172 |
160 @Override | 173 @Override |
161 public void accept(ValueVisitor v) { | 174 public void accept(ValueVisitor v) { |
162 v.visitIf(this); | 175 v.visitIf(this); |