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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
| 55 // Forward jump with a preconfigured entry frame. Assert the |
| 56 // current frame matches the expected one and jump to the block. |
| 57 ASSERT(cgen_->frame()->Equals(entry_frame_)); |
| 58 cgen_->DeleteFrame(); |
| 59 __ jmp(&entry_label_); |
54 } else { | 60 } else { |
55 // Forward jump. The current frame is added to the end of the list | 61 // Forward jump. Remember the current frame and emit a jump to |
56 // of frames reaching the target block and a jump to the merge code | 62 // its merge code. |
57 // is emitted. | |
58 AddReachingFrame(cgen_->frame()); | 63 AddReachingFrame(cgen_->frame()); |
59 RegisterFile empty; | 64 RegisterFile empty; |
60 cgen_->SetFrame(NULL, &empty); | 65 cgen_->SetFrame(NULL, &empty); |
61 __ jmp(&merge_labels_.last()); | 66 __ jmp(&merge_labels_.last()); |
62 } | 67 } |
63 | 68 |
64 is_linked_ = !is_bound_; | 69 is_linked_ = !is_bound_; |
65 } | 70 } |
66 | 71 |
67 | 72 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // To emit the merge code here, we negate the condition and branch | 112 // To emit the merge code here, we negate the condition and branch |
108 // around the merge code on the fall through path. | 113 // around the merge code on the fall through path. |
109 Label original_fall_through; | 114 Label original_fall_through; |
110 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); | 115 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); |
111 cgen_->frame()->MergeTo(entry_frame_); | 116 cgen_->frame()->MergeTo(entry_frame_); |
112 cgen_->DeleteFrame(); | 117 cgen_->DeleteFrame(); |
113 __ jmp(&entry_label_); | 118 __ jmp(&entry_label_); |
114 cgen_->SetFrame(fall_through_frame, &non_frame_registers); | 119 cgen_->SetFrame(fall_through_frame, &non_frame_registers); |
115 __ bind(&original_fall_through); | 120 __ bind(&original_fall_through); |
116 | 121 |
| 122 } else if (entry_frame_ != NULL) { |
| 123 // Forward branch with a preconfigured entry frame. Assert the |
| 124 // current frame matches the expected one and branch to the block. |
| 125 ASSERT(cgen_->frame()->Equals(entry_frame_)); |
| 126 // Use masm_-> instead of __ as forward branches are expected to |
| 127 // be a fixed size (no inserted coverage-checking instructions |
| 128 // please). This is used in Reference::GetValue. |
| 129 masm_->j(cc, &entry_label_, hint); |
| 130 is_linked_ = true; |
| 131 |
117 } else { | 132 } else { |
118 // Forward branch. A copy of the current frame is added to the end of the | 133 // Forward branch. A copy of the current frame is remembered and |
119 // list of frames reaching the target block and a branch to the merge code | 134 // a branch to the merge code is emitted. |
120 // is emitted. Use masm_-> instead of __ as forward branches are expected | |
121 // to be a fixed size (no inserted coverage-checking instructions please). | |
122 // This is used in Reference::GetValue. | |
123 AddReachingFrame(new VirtualFrame(cgen_->frame())); | 135 AddReachingFrame(new VirtualFrame(cgen_->frame())); |
124 masm_->j(cc, &merge_labels_.last(), hint); | 136 masm_->j(cc, &merge_labels_.last(), hint); |
125 is_linked_ = true; | 137 is_linked_ = true; |
126 } | 138 } |
127 } | 139 } |
128 | 140 |
129 | 141 |
130 void JumpTarget::Call() { | 142 void JumpTarget::Call() { |
131 // 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 |
132 // a return address when compiling try/catch and try/finally. We | 144 // a return address when compiling try/catch and try/finally. We |
133 // fully spill the frame before making the call. The expected frame | 145 // fully spill the frame before making the call. The expected frame |
134 // 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 |
135 // frame plus an in-memory return address. The "fall-through" frame | 147 // frame plus an in-memory return address. The "fall-through" frame |
136 // at the return site is the spilled current frame. | 148 // at the return site is the spilled current frame. |
137 ASSERT(cgen_ != NULL); | 149 ASSERT(cgen_ != NULL); |
138 ASSERT(cgen_->has_valid_frame()); | 150 ASSERT(cgen_->has_valid_frame()); |
139 // There are no non-frame references across the call. | 151 // There are no non-frame references across the call. |
140 ASSERT(cgen_->HasValidEntryRegisters()); | 152 ASSERT(cgen_->HasValidEntryRegisters()); |
141 ASSERT(!is_linked()); | 153 ASSERT(!is_linked()); |
142 | 154 |
143 cgen_->frame()->SpillAll(); | 155 cgen_->frame()->SpillAll(); |
144 VirtualFrame* target_frame = new VirtualFrame(cgen_->frame()); | 156 VirtualFrame* target_frame = new VirtualFrame(cgen_->frame()); |
145 target_frame->Adjust(1); | 157 target_frame->Adjust(1); |
| 158 // We do not expect a call with a preconfigured entry frame. |
| 159 ASSERT(entry_frame_ == NULL); |
146 AddReachingFrame(target_frame); | 160 AddReachingFrame(target_frame); |
147 __ call(&merge_labels_.last()); | 161 __ call(&merge_labels_.last()); |
148 | 162 |
149 is_linked_ = !is_bound_; | 163 is_linked_ = !is_bound_; |
150 } | 164 } |
151 | 165 |
152 | 166 |
153 void JumpTarget::DoBind(int mergable_elements) { | 167 void JumpTarget::DoBind(int mergable_elements) { |
154 ASSERT(cgen_ != NULL); | 168 ASSERT(cgen_ != NULL); |
155 ASSERT(!is_bound()); | 169 ASSERT(!is_bound()); |
156 | 170 |
157 // Live non-frame registers are not allowed at the start of a basic | 171 // Live non-frame registers are not allowed at the start of a basic |
158 // block. | 172 // block. |
159 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); | 173 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); |
160 | 174 |
| 175 // Fast case: the jump target was manually configured with an entry |
| 176 // frame to use. |
| 177 if (entry_frame_ != NULL) { |
| 178 // Assert no reaching frames to deal with. |
| 179 ASSERT(reaching_frames_.is_empty()); |
| 180 ASSERT(!cgen_->has_valid_frame()); |
| 181 |
| 182 RegisterFile reserved = RegisterAllocator::Reserved(); |
| 183 if (direction_ == BIDIRECTIONAL) { |
| 184 // Copy the entry frame so the original can be used for a |
| 185 // possible backward jump. |
| 186 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved); |
| 187 } else { |
| 188 // Take ownership of the entry frame. |
| 189 cgen_->SetFrame(entry_frame_, &reserved); |
| 190 entry_frame_ = NULL; |
| 191 } |
| 192 __ bind(&entry_label_); |
| 193 is_linked_ = false; |
| 194 is_bound_ = true; |
| 195 return; |
| 196 } |
| 197 |
161 if (direction_ == FORWARD_ONLY) { | 198 if (direction_ == FORWARD_ONLY) { |
162 // A simple case: no forward jumps and no possible backward jumps. | 199 // A simple case: no forward jumps and no possible backward jumps. |
163 if (!is_linked()) { | 200 if (!is_linked()) { |
164 // The stack pointer can be floating above the top of the | 201 // The stack pointer can be floating above the top of the |
165 // virtual frame before the bind. Afterward, it should not. | 202 // virtual frame before the bind. Afterward, it should not. |
166 ASSERT(cgen_->has_valid_frame()); | 203 ASSERT(cgen_->has_valid_frame()); |
167 VirtualFrame* frame = cgen_->frame(); | 204 VirtualFrame* frame = cgen_->frame(); |
168 int difference = | 205 int difference = |
169 frame->stack_pointer_ - (frame->elements_.length() - 1); | 206 frame->stack_pointer_ - (frame->elements_.length() - 1); |
170 if (difference > 0) { | 207 if (difference > 0) { |
(...skipping 29 matching lines...) Expand all Loading... |
200 is_bound_ = true; | 237 is_bound_ = true; |
201 return; | 238 return; |
202 } | 239 } |
203 } | 240 } |
204 | 241 |
205 // If there is a current frame, record it as the fall-through. It | 242 // If there is a current frame, record it as the fall-through. It |
206 // is owned by the reaching frames for now. | 243 // is owned by the reaching frames for now. |
207 bool had_fall_through = false; | 244 bool had_fall_through = false; |
208 if (cgen_->has_valid_frame()) { | 245 if (cgen_->has_valid_frame()) { |
209 had_fall_through = true; | 246 had_fall_through = true; |
210 AddReachingFrame(cgen_->frame()); | 247 AddReachingFrame(cgen_->frame()); // Return value ignored. |
211 RegisterFile empty; | 248 RegisterFile empty; |
212 cgen_->SetFrame(NULL, &empty); | 249 cgen_->SetFrame(NULL, &empty); |
213 } | 250 } |
214 | 251 |
215 // Compute the frame to use for entry to the block. | 252 // Compute the frame to use for entry to the block. |
216 ComputeEntryFrame(mergable_elements); | 253 if (entry_frame_ == NULL) { |
| 254 ComputeEntryFrame(mergable_elements); |
| 255 } |
217 | 256 |
218 // Some moves required to merge to an expected frame require purely | 257 // Some moves required to merge to an expected frame require purely |
219 // frame state changes, and do not require any code generation. | 258 // frame state changes, and do not require any code generation. |
220 // Perform those first to increase the possibility of finding equal | 259 // Perform those first to increase the possibility of finding equal |
221 // frames below. | 260 // frames below. |
222 for (int i = 0; i < reaching_frames_.length(); i++) { | 261 for (int i = 0; i < reaching_frames_.length(); i++) { |
223 if (reaching_frames_[i] != NULL) { | 262 if (reaching_frames_[i] != NULL) { |
224 reaching_frames_[i]->PrepareMergeTo(entry_frame_); | 263 reaching_frames_[i]->PrepareMergeTo(entry_frame_); |
225 } | 264 } |
226 } | 265 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 367 } |
329 | 368 |
330 is_linked_ = false; | 369 is_linked_ = false; |
331 is_bound_ = true; | 370 is_bound_ = true; |
332 } | 371 } |
333 | 372 |
334 #undef __ | 373 #undef __ |
335 | 374 |
336 | 375 |
337 } } // namespace v8::internal | 376 } } // namespace v8::internal |
OLD | NEW |