Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java @ 2764:99912abb3ff7
Phi clean up. Phis no longer save their local/stack index.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Mon, 23 May 2011 15:07:01 +0200 |
parents | 5e8a69041cd7 |
children | 43ffa0e47a46 |
comparison
equal
deleted
inserted
replaced
2763:5e8a69041cd7 | 2764:99912abb3ff7 |
---|---|
31 * The {@code Phi} instruction represents the merging of dataflow | 31 * The {@code Phi} instruction represents the merging of dataflow |
32 * in the instruction graph. It refers to a join block and a variable. | 32 * in the instruction graph. It refers to a join block and a variable. |
33 */ | 33 */ |
34 public final class Phi extends Value { | 34 public final class Phi extends Value { |
35 | 35 |
36 private static final int DEFAULT_MAX_VALUES = 2; | |
37 | |
36 private static final int INPUT_COUNT = 1; | 38 private static final int INPUT_COUNT = 1; |
37 private static final int INPUT_BLOCK = 0; | 39 private static final int INPUT_BLOCK = 0; |
38 | 40 |
39 private static final int SUCCESSOR_COUNT = 0; | 41 private static final int SUCCESSOR_COUNT = 0; |
40 | 42 |
41 @Override | 43 private int usedInputCount; |
42 protected int inputCount() { | |
43 return super.inputCount() + INPUT_COUNT + maxValues; | |
44 } | |
45 | 44 |
46 @Override | 45 @Override |
47 protected int successorCount() { | 46 protected int successorCount() { |
48 return super.successorCount() + SUCCESSOR_COUNT; | 47 return super.successorCount() + SUCCESSOR_COUNT; |
49 } | 48 } |
58 | 57 |
59 public Value setBlock(Value n) { | 58 public Value setBlock(Value n) { |
60 return (BlockBegin) inputs().set(super.inputCount() + INPUT_BLOCK, n); | 59 return (BlockBegin) inputs().set(super.inputCount() + INPUT_BLOCK, n); |
61 } | 60 } |
62 | 61 |
63 private final int index; | |
64 private final int maxValues; | |
65 private int usedInputCount; | |
66 | |
67 /** | 62 /** |
68 * Create a new Phi for the specified join block and local variable (or operand stack) slot. | 63 * Create a new Phi for the specified join block and local variable (or operand stack) slot. |
69 * @param kind the type of the variable | 64 * @param kind the type of the variable |
70 * @param block the join point | 65 * @param block the join point |
71 * @param index the index into the stack (if < 0) or local variables | 66 * @param index the index into the stack (if < 0) or local variables |
72 * @param graph | 67 * @param graph |
73 */ | 68 */ |
74 public Phi(CiKind kind, BlockBegin block, int index, Graph graph) { | 69 public Phi(CiKind kind, BlockBegin block, Graph graph) { |
75 this(kind, block, index, 2, graph); | 70 this(kind, block, DEFAULT_MAX_VALUES, graph); |
76 } | 71 } |
77 | 72 |
78 public Phi(CiKind kind, BlockBegin block, int index, int maxValues, Graph graph) { | 73 public Phi(CiKind kind, BlockBegin block, int maxValues, Graph graph) { |
79 super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph); | 74 super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph); |
80 usedInputCount = 1; | 75 usedInputCount = 1; |
81 this.maxValues = maxValues; | |
82 this.index = index; | |
83 setBlock(block); | 76 setBlock(block); |
84 } | |
85 | |
86 /** | |
87 * Check whether this phi corresponds to a local variable. | |
88 * @return {@code true} if this phi refers to a local variable | |
89 */ | |
90 public boolean isLocal() { | |
91 return index >= 0; | |
92 } | |
93 | |
94 /** | |
95 * Check whether this phi corresponds to a stack location. | |
96 * @return {@code true} if this phi refers to a stack location | |
97 */ | |
98 public boolean isOnStack() { | |
99 return index < 0; | |
100 } | |
101 | |
102 /** | |
103 * Get the local index of this phi. | |
104 * @return the local index | |
105 */ | |
106 public int localIndex() { | |
107 assert isLocal(); | |
108 return index; | |
109 } | |
110 | |
111 /** | |
112 * Get the stack index of this phi. | |
113 * @return the stack index of this phi | |
114 */ | |
115 public int stackIndex() { | |
116 assert isOnStack(); | |
117 return -(index + 1); | |
118 } | 77 } |
119 | 78 |
120 /** | 79 /** |
121 * Get the instruction that produces the value associated with the i'th predecessor | 80 * Get the instruction that produces the value associated with the i'th predecessor |
122 * of the join block. | 81 * of the join block. |
123 * @param i the index of the predecessor | 82 * @param i the index of the predecessor |
124 * @return the instruction that produced the value in the i'th predecessor | 83 * @return the instruction that produced the value in the i'th predecessor |
125 */ | 84 */ |
126 public Value inputAt(int i) { | 85 public Value valueAt(int i) { |
127 return (Value) inputs().get(i + INPUT_COUNT); | 86 return (Value) inputs().get(i + INPUT_COUNT); |
128 } | |
129 | |
130 /** | |
131 * Gets the instruction that produces the value for this phi in the specified state. | |
132 * @param state the state to access | |
133 * @return the instruction producing the value | |
134 */ | |
135 public Value inputIn(FrameState state) { | |
136 if (isLocal()) { | |
137 return state.localAt(localIndex()); | |
138 } else { | |
139 return state.stackAt(stackIndex()); | |
140 } | |
141 } | 87 } |
142 | 88 |
143 /** | 89 /** |
144 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block). | 90 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block). |
145 * @return the number of inputs in this phi | 91 * @return the number of inputs in this phi |
146 */ | 92 */ |
147 public int phiInputCount() { | 93 public int valueCount() { |
148 return usedInputCount - 1; | 94 return usedInputCount - 1; |
149 } | 95 } |
150 | 96 |
151 @Override | 97 @Override |
152 public void accept(ValueVisitor v) { | 98 public void accept(ValueVisitor v) { |
166 out.print("phi function"); | 112 out.print("phi function"); |
167 } | 113 } |
168 | 114 |
169 @Override | 115 @Override |
170 public String shortName() { | 116 public String shortName() { |
171 return "Phi: " + index + " (" + phiInputCount() + ")"; | 117 return "Phi: (" + valueCount() + ")"; |
172 } | 118 } |
173 | 119 |
174 public Phi addInput(Value y) { | 120 public Phi addInput(Node y) { |
175 assert !this.isDeleted() && !y.isDeleted(); | 121 assert !this.isDeleted() && !y.isDeleted(); |
176 Phi phi = this; | 122 Phi phi = this; |
177 if (usedInputCount == inputs().size()) { | 123 if (usedInputCount == inputs().size()) { |
178 phi = new Phi(kind, block(), index, maxValues * 2, graph()); | 124 phi = new Phi(kind, block(), usedInputCount * 2, graph()); |
179 for (int i = 0; i < phiInputCount(); ++i) { | 125 for (int i = 0; i < valueCount(); ++i) { |
180 phi.addInput(inputAt(i)); | 126 phi.addInput(valueAt(i)); |
181 } | 127 } |
182 phi.addInput(y); | 128 phi.addInput(y); |
183 this.replace(phi); | 129 this.replace(phi); |
184 } else { | 130 } else { |
185 phi.inputs().set(usedInputCount++, y); | 131 phi.inputs().set(usedInputCount++, y); |
186 } | 132 } |
187 return phi; | 133 return phi; |
188 } | 134 } |
189 | |
190 | |
191 } | 135 } |