OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "codegen-inl.h" | 30 #include "codegen-inl.h" |
| 31 #include "jump-target-inl.h" |
31 #include "register-allocator-inl.h" | 32 #include "register-allocator-inl.h" |
32 | 33 |
33 namespace v8 { namespace internal { | 34 namespace v8 { namespace internal { |
34 | 35 |
35 // ------------------------------------------------------------------------- | 36 // ------------------------------------------------------------------------- |
36 // JumpTarget implementation. | 37 // JumpTarget implementation. |
37 | 38 |
38 #define __ ACCESS_MASM(masm_) | 39 #define __ ACCESS_MASM(cgen()->masm()) |
39 | 40 |
40 void JumpTarget::DoJump() { | 41 void JumpTarget::DoJump() { |
41 ASSERT(cgen_ != NULL); | 42 ASSERT(cgen()->has_valid_frame()); |
42 ASSERT(cgen_->has_valid_frame()); | |
43 // Live non-frame registers are not allowed at unconditional jumps | 43 // Live non-frame registers are not allowed at unconditional jumps |
44 // because we have no way of invalidating the corresponding results | 44 // because we have no way of invalidating the corresponding results |
45 // which are still live in the C++ code. | 45 // which are still live in the C++ code. |
46 ASSERT(cgen_->HasValidEntryRegisters()); | 46 ASSERT(cgen()->HasValidEntryRegisters()); |
47 | 47 |
48 if (is_bound()) { | 48 if (is_bound()) { |
49 // Backward jump. There is an expected frame to merge to. | 49 // Backward jump. There is an expected frame to merge to. |
50 ASSERT(direction_ == BIDIRECTIONAL); | 50 ASSERT(direction_ == BIDIRECTIONAL); |
51 cgen_->frame()->MergeTo(entry_frame_); | 51 cgen()->frame()->MergeTo(entry_frame_); |
52 cgen_->DeleteFrame(); | 52 cgen()->DeleteFrame(); |
53 __ jmp(&entry_label_); | 53 __ jmp(&entry_label_); |
54 } else if (entry_frame_ != NULL) { | 54 } else if (entry_frame_ != NULL) { |
55 // Forward jump with a preconfigured entry frame. Assert the | 55 // Forward jump with a preconfigured entry frame. Assert the |
56 // current frame matches the expected one and jump to the block. | 56 // current frame matches the expected one and jump to the block. |
57 ASSERT(cgen_->frame()->Equals(entry_frame_)); | 57 ASSERT(cgen()->frame()->Equals(entry_frame_)); |
58 cgen_->DeleteFrame(); | 58 cgen()->DeleteFrame(); |
59 __ jmp(&entry_label_); | 59 __ jmp(&entry_label_); |
60 } else { | 60 } else { |
61 // Forward jump. Remember the current frame and emit a jump to | 61 // Forward jump. Remember the current frame and emit a jump to |
62 // its merge code. | 62 // its merge code. |
63 AddReachingFrame(cgen_->frame()); | 63 AddReachingFrame(cgen()->frame()); |
64 RegisterFile empty; | 64 RegisterFile empty; |
65 cgen_->SetFrame(NULL, &empty); | 65 cgen()->SetFrame(NULL, &empty); |
66 __ jmp(&merge_labels_.last()); | 66 __ jmp(&merge_labels_.last()); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 void JumpTarget::DoBranch(Condition cc, Hint hint) { | 71 void JumpTarget::DoBranch(Condition cc, Hint hint) { |
72 ASSERT(cgen_ != NULL); | 72 ASSERT(cgen() != NULL); |
73 ASSERT(cgen_->has_valid_frame()); | 73 ASSERT(cgen()->has_valid_frame()); |
74 | 74 |
75 if (is_bound()) { | 75 if (is_bound()) { |
76 ASSERT(direction_ == BIDIRECTIONAL); | 76 ASSERT(direction_ == BIDIRECTIONAL); |
77 // Backward branch. We have an expected frame to merge to on the | 77 // Backward branch. We have an expected frame to merge to on the |
78 // backward edge. | 78 // backward edge. |
79 | 79 |
80 // Swap the current frame for a copy (we do the swapping to get | 80 // Swap the current frame for a copy (we do the swapping to get |
81 // the off-frame registers off the fall through) to use for the | 81 // the off-frame registers off the fall through) to use for the |
82 // branch. | 82 // branch. |
83 VirtualFrame* fall_through_frame = cgen_->frame(); | 83 VirtualFrame* fall_through_frame = cgen()->frame(); |
84 VirtualFrame* branch_frame = new VirtualFrame(fall_through_frame); | 84 VirtualFrame* branch_frame = new VirtualFrame(fall_through_frame); |
85 RegisterFile non_frame_registers = RegisterAllocator::Reserved(); | 85 RegisterFile non_frame_registers = RegisterAllocator::Reserved(); |
86 cgen_->SetFrame(branch_frame, &non_frame_registers); | 86 cgen()->SetFrame(branch_frame, &non_frame_registers); |
87 | 87 |
88 // Check if we can avoid merge code. | 88 // Check if we can avoid merge code. |
89 cgen_->frame()->PrepareMergeTo(entry_frame_); | 89 cgen()->frame()->PrepareMergeTo(entry_frame_); |
90 if (cgen_->frame()->Equals(entry_frame_)) { | 90 if (cgen()->frame()->Equals(entry_frame_)) { |
91 // Branch right in to the block. | 91 // Branch right in to the block. |
92 cgen_->DeleteFrame(); | 92 cgen()->DeleteFrame(); |
93 __ j(cc, &entry_label_, hint); | 93 __ j(cc, &entry_label_, hint); |
94 cgen_->SetFrame(fall_through_frame, &non_frame_registers); | 94 cgen()->SetFrame(fall_through_frame, &non_frame_registers); |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 // Check if we can reuse existing merge code. | 98 // Check if we can reuse existing merge code. |
99 for (int i = 0; i < reaching_frames_.length(); i++) { | 99 for (int i = 0; i < reaching_frames_.length(); i++) { |
100 if (reaching_frames_[i] != NULL && | 100 if (reaching_frames_[i] != NULL && |
101 cgen_->frame()->Equals(reaching_frames_[i])) { | 101 cgen()->frame()->Equals(reaching_frames_[i])) { |
102 // Branch to the merge code. | 102 // Branch to the merge code. |
103 cgen_->DeleteFrame(); | 103 cgen()->DeleteFrame(); |
104 __ j(cc, &merge_labels_[i], hint); | 104 __ j(cc, &merge_labels_[i], hint); |
105 cgen_->SetFrame(fall_through_frame, &non_frame_registers); | 105 cgen()->SetFrame(fall_through_frame, &non_frame_registers); |
106 return; | 106 return; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 // To emit the merge code here, we negate the condition and branch | 110 // To emit the merge code here, we negate the condition and branch |
111 // around the merge code on the fall through path. | 111 // around the merge code on the fall through path. |
112 Label original_fall_through; | 112 Label original_fall_through; |
113 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); | 113 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); |
114 cgen_->frame()->MergeTo(entry_frame_); | 114 cgen()->frame()->MergeTo(entry_frame_); |
115 cgen_->DeleteFrame(); | 115 cgen()->DeleteFrame(); |
116 __ jmp(&entry_label_); | 116 __ jmp(&entry_label_); |
117 cgen_->SetFrame(fall_through_frame, &non_frame_registers); | 117 cgen()->SetFrame(fall_through_frame, &non_frame_registers); |
118 __ bind(&original_fall_through); | 118 __ bind(&original_fall_through); |
119 | 119 |
120 } else if (entry_frame_ != NULL) { | 120 } else if (entry_frame_ != NULL) { |
121 // Forward branch with a preconfigured entry frame. Assert the | 121 // Forward branch with a preconfigured entry frame. Assert the |
122 // current frame matches the expected one and branch to the block. | 122 // current frame matches the expected one and branch to the block. |
123 ASSERT(cgen_->frame()->Equals(entry_frame_)); | 123 ASSERT(cgen()->frame()->Equals(entry_frame_)); |
124 // Explicitly use the macro assembler instead of __ as forward | 124 // Explicitly use the macro assembler instead of __ as forward |
125 // branches are expected to be a fixed size (no inserted | 125 // branches are expected to be a fixed size (no inserted |
126 // coverage-checking instructions please). This is used in | 126 // coverage-checking instructions please). This is used in |
127 // Reference::GetValue. | 127 // Reference::GetValue. |
128 masm_->j(cc, &entry_label_, hint); | 128 cgen()->masm()->j(cc, &entry_label_, hint); |
129 | 129 |
130 } else { | 130 } else { |
131 // Forward branch. A copy of the current frame is remembered and | 131 // Forward branch. A copy of the current frame is remembered and |
132 // a branch to the merge code is emitted. Explicitly use the | 132 // a branch to the merge code is emitted. Explicitly use the |
133 // macro assembler instead of __ as forward branches are expected | 133 // macro assembler instead of __ as forward branches are expected |
134 // to be a fixed size (no inserted coverage-checking instructions | 134 // to be a fixed size (no inserted coverage-checking instructions |
135 // please). This is used in Reference::GetValue. | 135 // please). This is used in Reference::GetValue. |
136 AddReachingFrame(new VirtualFrame(cgen_->frame())); | 136 AddReachingFrame(new VirtualFrame(cgen()->frame())); |
137 masm_->j(cc, &merge_labels_.last(), hint); | 137 cgen()->masm()->j(cc, &merge_labels_.last(), hint); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 | 141 |
142 void JumpTarget::Call() { | 142 void JumpTarget::Call() { |
143 // Call is used to push the address of the catch block on the stack as | 143 // Call is used to push the address of the catch block on the stack as |
144 // a return address when compiling try/catch and try/finally. We | 144 // a return address when compiling try/catch and try/finally. We |
145 // fully spill the frame before making the call. The expected frame | 145 // fully spill the frame before making the call. The expected frame |
146 // at the label (which should be the only one) is the spilled current | 146 // at the label (which should be the only one) is the spilled current |
147 // frame plus an in-memory return address. The "fall-through" frame | 147 // frame plus an in-memory return address. The "fall-through" frame |
148 // at the return site is the spilled current frame. | 148 // at the return site is the spilled current frame. |
149 ASSERT(cgen_ != NULL); | 149 ASSERT(cgen() != NULL); |
150 ASSERT(cgen_->has_valid_frame()); | 150 ASSERT(cgen()->has_valid_frame()); |
151 // There are no non-frame references across the call. | 151 // There are no non-frame references across the call. |
152 ASSERT(cgen_->HasValidEntryRegisters()); | 152 ASSERT(cgen()->HasValidEntryRegisters()); |
153 ASSERT(!is_linked()); | 153 ASSERT(!is_linked()); |
154 | 154 |
155 cgen_->frame()->SpillAll(); | 155 cgen()->frame()->SpillAll(); |
156 VirtualFrame* target_frame = new VirtualFrame(cgen_->frame()); | 156 VirtualFrame* target_frame = new VirtualFrame(cgen()->frame()); |
157 target_frame->Adjust(1); | 157 target_frame->Adjust(1); |
158 // We do not expect a call with a preconfigured entry frame. | 158 // We do not expect a call with a preconfigured entry frame. |
159 ASSERT(entry_frame_ == NULL); | 159 ASSERT(entry_frame_ == NULL); |
160 AddReachingFrame(target_frame); | 160 AddReachingFrame(target_frame); |
161 __ call(&merge_labels_.last()); | 161 __ call(&merge_labels_.last()); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 void JumpTarget::DoBind(int mergable_elements) { | 165 void JumpTarget::DoBind(int mergable_elements) { |
166 ASSERT(cgen_ != NULL); | 166 ASSERT(cgen() != NULL); |
167 ASSERT(!is_bound()); | 167 ASSERT(!is_bound()); |
168 | 168 |
169 // Live non-frame registers are not allowed at the start of a basic | 169 // Live non-frame registers are not allowed at the start of a basic |
170 // block. | 170 // block. |
171 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); | 171 ASSERT(!cgen()->has_valid_frame() || cgen()->HasValidEntryRegisters()); |
172 | 172 |
173 // Fast case: the jump target was manually configured with an entry | 173 // Fast case: the jump target was manually configured with an entry |
174 // frame to use. | 174 // frame to use. |
175 if (entry_frame_ != NULL) { | 175 if (entry_frame_ != NULL) { |
176 // Assert no reaching frames to deal with. | 176 // Assert no reaching frames to deal with. |
177 ASSERT(reaching_frames_.is_empty()); | 177 ASSERT(reaching_frames_.is_empty()); |
178 ASSERT(!cgen_->has_valid_frame()); | 178 ASSERT(!cgen()->has_valid_frame()); |
179 | 179 |
180 RegisterFile reserved = RegisterAllocator::Reserved(); | 180 RegisterFile reserved = RegisterAllocator::Reserved(); |
181 if (direction_ == BIDIRECTIONAL) { | 181 if (direction_ == BIDIRECTIONAL) { |
182 // Copy the entry frame so the original can be used for a | 182 // Copy the entry frame so the original can be used for a |
183 // possible backward jump. | 183 // possible backward jump. |
184 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved); | 184 cgen()->SetFrame(new VirtualFrame(entry_frame_), &reserved); |
185 } else { | 185 } else { |
186 // Take ownership of the entry frame. | 186 // Take ownership of the entry frame. |
187 cgen_->SetFrame(entry_frame_, &reserved); | 187 cgen()->SetFrame(entry_frame_, &reserved); |
188 entry_frame_ = NULL; | 188 entry_frame_ = NULL; |
189 } | 189 } |
190 __ bind(&entry_label_); | 190 __ bind(&entry_label_); |
191 return; | 191 return; |
192 } | 192 } |
193 | 193 |
194 if (!is_linked()) { | 194 if (!is_linked()) { |
195 ASSERT(cgen_->has_valid_frame()); | 195 ASSERT(cgen()->has_valid_frame()); |
196 if (direction_ == FORWARD_ONLY) { | 196 if (direction_ == FORWARD_ONLY) { |
197 // Fast case: no forward jumps and no possible backward jumps. | 197 // Fast case: no forward jumps and no possible backward jumps. |
198 // The stack pointer can be floating above the top of the | 198 // The stack pointer can be floating above the top of the |
199 // virtual frame before the bind. Afterward, it should not. | 199 // virtual frame before the bind. Afterward, it should not. |
200 VirtualFrame* frame = cgen_->frame(); | 200 VirtualFrame* frame = cgen()->frame(); |
201 int difference = | 201 int difference = |
202 frame->stack_pointer_ - (frame->elements_.length() - 1); | 202 frame->stack_pointer_ - (frame->elements_.length() - 1); |
203 if (difference > 0) { | 203 if (difference > 0) { |
204 frame->stack_pointer_ -= difference; | 204 frame->stack_pointer_ -= difference; |
205 __ add(Operand(esp), Immediate(difference * kPointerSize)); | 205 __ add(Operand(esp), Immediate(difference * kPointerSize)); |
206 } | 206 } |
207 } else { | 207 } else { |
208 ASSERT(direction_ == BIDIRECTIONAL); | 208 ASSERT(direction_ == BIDIRECTIONAL); |
209 // Fast case: no forward jumps, possible backward ones. Remove | 209 // Fast case: no forward jumps, possible backward ones. Remove |
210 // constants and copies above the watermark on the fall-through | 210 // constants and copies above the watermark on the fall-through |
211 // frame and use it as the entry frame. | 211 // frame and use it as the entry frame. |
212 cgen_->frame()->MakeMergable(mergable_elements); | 212 cgen()->frame()->MakeMergable(mergable_elements); |
213 entry_frame_ = new VirtualFrame(cgen_->frame()); | 213 entry_frame_ = new VirtualFrame(cgen()->frame()); |
214 } | 214 } |
215 __ bind(&entry_label_); | 215 __ bind(&entry_label_); |
216 return; | 216 return; |
217 } | 217 } |
218 | 218 |
219 if (direction_ == FORWARD_ONLY && | 219 if (direction_ == FORWARD_ONLY && |
220 !cgen_->has_valid_frame() && | 220 !cgen()->has_valid_frame() && |
221 reaching_frames_.length() == 1) { | 221 reaching_frames_.length() == 1) { |
222 // Fast case: no fall-through, a single forward jump, and no | 222 // Fast case: no fall-through, a single forward jump, and no |
223 // possible backward jumps. Pick up the only reaching frame, take | 223 // possible backward jumps. Pick up the only reaching frame, take |
224 // ownership of it, and use it for the block about to be emitted. | 224 // ownership of it, and use it for the block about to be emitted. |
225 VirtualFrame* frame = reaching_frames_[0]; | 225 VirtualFrame* frame = reaching_frames_[0]; |
226 RegisterFile reserved = RegisterAllocator::Reserved(); | 226 RegisterFile reserved = RegisterAllocator::Reserved(); |
227 cgen_->SetFrame(frame, &reserved); | 227 cgen()->SetFrame(frame, &reserved); |
228 reaching_frames_[0] = NULL; | 228 reaching_frames_[0] = NULL; |
229 __ bind(&merge_labels_[0]); | 229 __ bind(&merge_labels_[0]); |
230 | 230 |
231 // The stack pointer can be floating above the top of the | 231 // The stack pointer can be floating above the top of the |
232 // virtual frame before the bind. Afterward, it should not. | 232 // virtual frame before the bind. Afterward, it should not. |
233 int difference = | 233 int difference = |
234 frame->stack_pointer_ - (frame->elements_.length() - 1); | 234 frame->stack_pointer_ - (frame->elements_.length() - 1); |
235 if (difference > 0) { | 235 if (difference > 0) { |
236 frame->stack_pointer_ -= difference; | 236 frame->stack_pointer_ -= difference; |
237 __ add(Operand(esp), Immediate(difference * kPointerSize)); | 237 __ add(Operand(esp), Immediate(difference * kPointerSize)); |
238 } | 238 } |
239 | 239 |
240 __ bind(&entry_label_); | 240 __ bind(&entry_label_); |
241 return; | 241 return; |
242 } | 242 } |
243 | 243 |
244 // If there is a current frame, record it as the fall-through. It | 244 // If there is a current frame, record it as the fall-through. It |
245 // is owned by the reaching frames for now. | 245 // is owned by the reaching frames for now. |
246 bool had_fall_through = false; | 246 bool had_fall_through = false; |
247 if (cgen_->has_valid_frame()) { | 247 if (cgen()->has_valid_frame()) { |
248 had_fall_through = true; | 248 had_fall_through = true; |
249 AddReachingFrame(cgen_->frame()); // Return value ignored. | 249 AddReachingFrame(cgen()->frame()); // Return value ignored. |
250 RegisterFile empty; | 250 RegisterFile empty; |
251 cgen_->SetFrame(NULL, &empty); | 251 cgen()->SetFrame(NULL, &empty); |
252 } | 252 } |
253 | 253 |
254 // Compute the frame to use for entry to the block. | 254 // Compute the frame to use for entry to the block. |
255 ComputeEntryFrame(mergable_elements); | 255 ComputeEntryFrame(mergable_elements); |
256 | 256 |
257 // Some moves required to merge to an expected frame require purely | 257 // Some moves required to merge to an expected frame require purely |
258 // frame state changes, and do not require any code generation. | 258 // frame state changes, and do not require any code generation. |
259 // Perform those first to increase the possibility of finding equal | 259 // Perform those first to increase the possibility of finding equal |
260 // frames below. | 260 // frames below. |
261 for (int i = 0; i < reaching_frames_.length(); i++) { | 261 for (int i = 0; i < reaching_frames_.length(); i++) { |
(...skipping 14 matching lines...) Expand all Loading... |
276 for (int i = reaching_frames_.length() - 1; i >= 0; i--) { | 276 for (int i = reaching_frames_.length() - 1; i >= 0; i--) { |
277 VirtualFrame* frame = reaching_frames_[i]; | 277 VirtualFrame* frame = reaching_frames_[i]; |
278 | 278 |
279 if (frame != NULL) { | 279 if (frame != NULL) { |
280 // Does the frame (probably) need merge code? | 280 // Does the frame (probably) need merge code? |
281 if (!frame->Equals(entry_frame_)) { | 281 if (!frame->Equals(entry_frame_)) { |
282 // We could have a valid frame as the fall through to the | 282 // We could have a valid frame as the fall through to the |
283 // binding site or as the fall through from a previous merge | 283 // binding site or as the fall through from a previous merge |
284 // code block. Jump around the code we are about to | 284 // code block. Jump around the code we are about to |
285 // generate. | 285 // generate. |
286 if (cgen_->has_valid_frame()) { | 286 if (cgen()->has_valid_frame()) { |
287 cgen_->DeleteFrame(); | 287 cgen()->DeleteFrame(); |
288 __ jmp(&entry_label_); | 288 __ jmp(&entry_label_); |
289 } | 289 } |
290 // Pick up the frame for this block. Assume ownership if | 290 // Pick up the frame for this block. Assume ownership if |
291 // there cannot be backward jumps. | 291 // there cannot be backward jumps. |
292 RegisterFile reserved = RegisterAllocator::Reserved(); | 292 RegisterFile reserved = RegisterAllocator::Reserved(); |
293 if (direction_ == BIDIRECTIONAL) { | 293 if (direction_ == BIDIRECTIONAL) { |
294 cgen_->SetFrame(new VirtualFrame(frame), &reserved); | 294 cgen()->SetFrame(new VirtualFrame(frame), &reserved); |
295 } else { | 295 } else { |
296 cgen_->SetFrame(frame, &reserved); | 296 cgen()->SetFrame(frame, &reserved); |
297 reaching_frames_[i] = NULL; | 297 reaching_frames_[i] = NULL; |
298 } | 298 } |
299 __ bind(&merge_labels_[i]); | 299 __ bind(&merge_labels_[i]); |
300 | 300 |
301 // Loop over the remaining (non-null) reaching frames, | 301 // Loop over the remaining (non-null) reaching frames, |
302 // looking for any that can share merge code with this one. | 302 // looking for any that can share merge code with this one. |
303 for (int j = 0; j < i; j++) { | 303 for (int j = 0; j < i; j++) { |
304 VirtualFrame* other = reaching_frames_[j]; | 304 VirtualFrame* other = reaching_frames_[j]; |
305 if (other != NULL && other->Equals(cgen_->frame())) { | 305 if (other != NULL && other->Equals(cgen()->frame())) { |
306 // Set the reaching frame element to null to avoid | 306 // Set the reaching frame element to null to avoid |
307 // processing it later, and then bind its entry label. | 307 // processing it later, and then bind its entry label. |
308 reaching_frames_[j] = NULL; | 308 reaching_frames_[j] = NULL; |
309 __ bind(&merge_labels_[j]); | 309 __ bind(&merge_labels_[j]); |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
313 // Emit the merge code. | 313 // Emit the merge code. |
314 cgen_->frame()->MergeTo(entry_frame_); | 314 cgen()->frame()->MergeTo(entry_frame_); |
315 } else if (i == reaching_frames_.length() - 1 && had_fall_through) { | 315 } else if (i == reaching_frames_.length() - 1 && had_fall_through) { |
316 // If this is the fall through frame, and it didn't need | 316 // If this is the fall through frame, and it didn't need |
317 // merge code, we need to pick up the frame so we can jump | 317 // merge code, we need to pick up the frame so we can jump |
318 // around subsequent merge blocks if necessary. | 318 // around subsequent merge blocks if necessary. |
319 RegisterFile reserved = RegisterAllocator::Reserved(); | 319 RegisterFile reserved = RegisterAllocator::Reserved(); |
320 cgen_->SetFrame(frame, &reserved); | 320 cgen()->SetFrame(frame, &reserved); |
321 reaching_frames_[i] = NULL; | 321 reaching_frames_[i] = NULL; |
322 } | 322 } |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 // The code generator may not have a current frame if there was no | 326 // The code generator may not have a current frame if there was no |
327 // fall through and none of the reaching frames needed merging. | 327 // fall through and none of the reaching frames needed merging. |
328 // In that case, clone the entry frame as the current frame. | 328 // In that case, clone the entry frame as the current frame. |
329 if (!cgen_->has_valid_frame()) { | 329 if (!cgen()->has_valid_frame()) { |
330 RegisterFile reserved_registers = RegisterAllocator::Reserved(); | 330 RegisterFile reserved_registers = RegisterAllocator::Reserved(); |
331 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved_registers); | 331 cgen()->SetFrame(new VirtualFrame(entry_frame_), &reserved_registers); |
332 } | 332 } |
333 | 333 |
334 // There may be unprocessed reaching frames that did not need | 334 // There may be unprocessed reaching frames that did not need |
335 // merge code. They will have unbound merge labels. Bind their | 335 // merge code. They will have unbound merge labels. Bind their |
336 // merge labels to be the same as the entry label and deallocate | 336 // merge labels to be the same as the entry label and deallocate |
337 // them. | 337 // them. |
338 for (int i = 0; i < reaching_frames_.length(); i++) { | 338 for (int i = 0; i < reaching_frames_.length(); i++) { |
339 if (!merge_labels_[i].is_bound()) { | 339 if (!merge_labels_[i].is_bound()) { |
340 reaching_frames_[i] = NULL; | 340 reaching_frames_[i] = NULL; |
341 __ bind(&merge_labels_[i]); | 341 __ bind(&merge_labels_[i]); |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 // There are non-NULL reaching frames with bound labels for each | 345 // There are non-NULL reaching frames with bound labels for each |
346 // merge block, but only on backward targets. | 346 // merge block, but only on backward targets. |
347 } else { | 347 } else { |
348 // There were no forward jumps. There must be a current frame and | 348 // There were no forward jumps. There must be a current frame and |
349 // this must be a bidirectional target. | 349 // this must be a bidirectional target. |
350 ASSERT(reaching_frames_.length() == 1); | 350 ASSERT(reaching_frames_.length() == 1); |
351 ASSERT(reaching_frames_[0] != NULL); | 351 ASSERT(reaching_frames_[0] != NULL); |
352 ASSERT(direction_ == BIDIRECTIONAL); | 352 ASSERT(direction_ == BIDIRECTIONAL); |
353 | 353 |
354 // Use a copy of the reaching frame so the original can be saved | 354 // Use a copy of the reaching frame so the original can be saved |
355 // for possible reuse as a backward merge block. | 355 // for possible reuse as a backward merge block. |
356 RegisterFile reserved = RegisterAllocator::Reserved(); | 356 RegisterFile reserved = RegisterAllocator::Reserved(); |
357 cgen_->SetFrame(new VirtualFrame(reaching_frames_[0]), &reserved); | 357 cgen()->SetFrame(new VirtualFrame(reaching_frames_[0]), &reserved); |
358 __ bind(&merge_labels_[0]); | 358 __ bind(&merge_labels_[0]); |
359 cgen_->frame()->MergeTo(entry_frame_); | 359 cgen()->frame()->MergeTo(entry_frame_); |
360 } | 360 } |
361 | 361 |
362 __ bind(&entry_label_); | 362 __ bind(&entry_label_); |
363 } | 363 } |
364 | 364 |
365 #undef __ | 365 #undef __ |
366 | 366 |
367 | 367 |
368 } } // namespace v8::internal | 368 } } // namespace v8::internal |
OLD | NEW |