| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | |
| 69 is_linked_ = !is_bound_; | |
| 70 } | 68 } |
| 71 | 69 |
| 72 | 70 |
| 73 void JumpTarget::DoBranch(Condition cc, Hint hint) { | 71 void JumpTarget::DoBranch(Condition cc, Hint hint) { |
| 74 ASSERT(cgen_ != NULL); | 72 ASSERT(cgen_ != NULL); |
| 75 ASSERT(cgen_->has_valid_frame()); | 73 ASSERT(cgen_->has_valid_frame()); |
| 76 | 74 |
| 77 if (is_bound()) { | 75 if (is_bound()) { |
| 78 ASSERT(direction_ == BIDIRECTIONAL); | 76 ASSERT(direction_ == BIDIRECTIONAL); |
| 79 // 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 cgen_->frame()->MergeTo(entry_frame_); | 114 cgen_->frame()->MergeTo(entry_frame_); |
| 117 cgen_->DeleteFrame(); | 115 cgen_->DeleteFrame(); |
| 118 __ jmp(&entry_label_); | 116 __ jmp(&entry_label_); |
| 119 cgen_->SetFrame(fall_through_frame, &non_frame_registers); | 117 cgen_->SetFrame(fall_through_frame, &non_frame_registers); |
| 120 __ bind(&original_fall_through); | 118 __ bind(&original_fall_through); |
| 121 | 119 |
| 122 } else if (entry_frame_ != NULL) { | 120 } else if (entry_frame_ != NULL) { |
| 123 // Forward branch with a preconfigured entry frame. Assert the | 121 // Forward branch with a preconfigured entry frame. Assert the |
| 124 // current frame matches the expected one and branch to the block. | 122 // current frame matches the expected one and branch to the block. |
| 125 ASSERT(cgen_->frame()->Equals(entry_frame_)); | 123 ASSERT(cgen_->frame()->Equals(entry_frame_)); |
| 126 // Use masm_-> instead of __ as forward branches are expected to | 124 // Explicitly use the macro assembler instead of __ as forward |
| 127 // be a fixed size (no inserted coverage-checking instructions | 125 // branches are expected to be a fixed size (no inserted |
| 128 // please). This is used in Reference::GetValue. | 126 // coverage-checking instructions please). This is used in |
| 127 // Reference::GetValue. |
| 129 masm_->j(cc, &entry_label_, hint); | 128 masm_->j(cc, &entry_label_, hint); |
| 130 is_linked_ = true; | |
| 131 | 129 |
| 132 } else { | 130 } else { |
| 133 // Forward branch. A copy of the current frame is remembered and | 131 // Forward branch. A copy of the current frame is remembered and |
| 134 // a branch to the merge code is emitted. | 132 // a branch to the merge code is emitted. Explicitly use the |
| 133 // macro assembler instead of __ as forward branches are expected |
| 134 // to be a fixed size (no inserted coverage-checking instructions |
| 135 // please). This is used in Reference::GetValue. |
| 135 AddReachingFrame(new VirtualFrame(cgen_->frame())); | 136 AddReachingFrame(new VirtualFrame(cgen_->frame())); |
| 136 masm_->j(cc, &merge_labels_.last(), hint); | 137 masm_->j(cc, &merge_labels_.last(), hint); |
| 137 is_linked_ = true; | |
| 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 | |
| 163 is_linked_ = !is_bound_; | |
| 164 } | 162 } |
| 165 | 163 |
| 166 | 164 |
| 167 void JumpTarget::DoBind(int mergable_elements) { | 165 void JumpTarget::DoBind(int mergable_elements) { |
| 168 ASSERT(cgen_ != NULL); | 166 ASSERT(cgen_ != NULL); |
| 169 ASSERT(!is_bound()); | 167 ASSERT(!is_bound()); |
| 170 | 168 |
| 171 // 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 |
| 172 // block. | 170 // block. |
| 173 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); | 171 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); |
| 174 | 172 |
| 175 // Fast case: the jump target was manually configured with an entry | 173 // Fast case: the jump target was manually configured with an entry |
| 176 // frame to use. | 174 // frame to use. |
| 177 if (entry_frame_ != NULL) { | 175 if (entry_frame_ != NULL) { |
| 178 // Assert no reaching frames to deal with. | 176 // Assert no reaching frames to deal with. |
| 179 ASSERT(reaching_frames_.is_empty()); | 177 ASSERT(reaching_frames_.is_empty()); |
| 180 ASSERT(!cgen_->has_valid_frame()); | 178 ASSERT(!cgen_->has_valid_frame()); |
| 181 | 179 |
| 182 RegisterFile reserved = RegisterAllocator::Reserved(); | 180 RegisterFile reserved = RegisterAllocator::Reserved(); |
| 183 if (direction_ == BIDIRECTIONAL) { | 181 if (direction_ == BIDIRECTIONAL) { |
| 184 // 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 |
| 185 // possible backward jump. | 183 // possible backward jump. |
| 186 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved); | 184 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved); |
| 187 } else { | 185 } else { |
| 188 // Take ownership of the entry frame. | 186 // Take ownership of the entry frame. |
| 189 cgen_->SetFrame(entry_frame_, &reserved); | 187 cgen_->SetFrame(entry_frame_, &reserved); |
| 190 entry_frame_ = NULL; | 188 entry_frame_ = NULL; |
| 191 } | 189 } |
| 192 __ bind(&entry_label_); | 190 __ bind(&entry_label_); |
| 193 is_linked_ = false; | |
| 194 is_bound_ = true; | |
| 195 return; | 191 return; |
| 196 } | 192 } |
| 197 | 193 |
| 198 if (!is_linked()) { | 194 if (!is_linked()) { |
| 199 ASSERT(cgen_->has_valid_frame()); | 195 ASSERT(cgen_->has_valid_frame()); |
| 200 if (direction_ == FORWARD_ONLY) { | 196 if (direction_ == FORWARD_ONLY) { |
| 201 // Fast case: no forward jumps and no possible backward jumps. | 197 // Fast case: no forward jumps and no possible backward jumps. |
| 202 // The stack pointer can be floating above the top of the | 198 // The stack pointer can be floating above the top of the |
| 203 // virtual frame before the bind. Afterward, it should not. | 199 // virtual frame before the bind. Afterward, it should not. |
| 204 VirtualFrame* frame = cgen_->frame(); | 200 VirtualFrame* frame = cgen_->frame(); |
| 205 int difference = | 201 int difference = |
| 206 frame->stack_pointer_ - (frame->elements_.length() - 1); | 202 frame->stack_pointer_ - (frame->elements_.length() - 1); |
| 207 if (difference > 0) { | 203 if (difference > 0) { |
| 208 frame->stack_pointer_ -= difference; | 204 frame->stack_pointer_ -= difference; |
| 209 __ add(Operand(esp), Immediate(difference * kPointerSize)); | 205 __ add(Operand(esp), Immediate(difference * kPointerSize)); |
| 210 } | 206 } |
| 211 | |
| 212 } else { | 207 } else { |
| 213 ASSERT(direction_ == BIDIRECTIONAL); | 208 ASSERT(direction_ == BIDIRECTIONAL); |
| 214 // Fast case: no forward jumps, possible backward ones. Remove | 209 // Fast case: no forward jumps, possible backward ones. Remove |
| 215 // constants and copies above the watermark on the fall-through | 210 // constants and copies above the watermark on the fall-through |
| 216 // frame and use it as the entry frame. | 211 // frame and use it as the entry frame. |
| 217 cgen_->frame()->MakeMergable(mergable_elements); | 212 cgen_->frame()->MakeMergable(mergable_elements); |
| 218 entry_frame_ = new VirtualFrame(cgen_->frame()); | 213 entry_frame_ = new VirtualFrame(cgen_->frame()); |
| 219 __ bind(&entry_label_); | |
| 220 } | 214 } |
| 221 is_bound_ = true; | 215 __ bind(&entry_label_); |
| 222 return; | 216 return; |
| 223 } | 217 } |
| 224 | 218 |
| 225 if (direction_ == FORWARD_ONLY && | 219 if (direction_ == FORWARD_ONLY && |
| 226 !cgen_->has_valid_frame() && | 220 !cgen_->has_valid_frame() && |
| 227 reaching_frames_.length() == 1) { | 221 reaching_frames_.length() == 1) { |
| 228 // Fast case: no fall-through, a single forward jump, and no | 222 // Fast case: no fall-through, a single forward jump, and no |
| 229 // possible backward jumps. Pick up the only reaching frame, take | 223 // possible backward jumps. Pick up the only reaching frame, take |
| 230 // 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. |
| 231 VirtualFrame* frame = reaching_frames_[0]; | 225 VirtualFrame* frame = reaching_frames_[0]; |
| 232 RegisterFile reserved = RegisterAllocator::Reserved(); | 226 RegisterFile reserved = RegisterAllocator::Reserved(); |
| 233 cgen_->SetFrame(frame, &reserved); | 227 cgen_->SetFrame(frame, &reserved); |
| 234 reaching_frames_[0] = NULL; | 228 reaching_frames_[0] = NULL; |
| 235 __ bind(&merge_labels_[0]); | 229 __ bind(&merge_labels_[0]); |
| 236 | 230 |
| 237 // The stack pointer can be floating above the top of the | 231 // The stack pointer can be floating above the top of the |
| 238 // virtual frame before the bind. Afterward, it should not. | 232 // virtual frame before the bind. Afterward, it should not. |
| 239 int difference = | 233 int difference = |
| 240 frame->stack_pointer_ - (frame->elements_.length() - 1); | 234 frame->stack_pointer_ - (frame->elements_.length() - 1); |
| 241 if (difference > 0) { | 235 if (difference > 0) { |
| 242 frame->stack_pointer_ -= difference; | 236 frame->stack_pointer_ -= difference; |
| 243 __ add(Operand(esp), Immediate(difference * kPointerSize)); | 237 __ add(Operand(esp), Immediate(difference * kPointerSize)); |
| 244 } | 238 } |
| 245 | 239 |
| 246 is_linked_ = false; | 240 __ bind(&entry_label_); |
| 247 is_bound_ = true; | |
| 248 return; | 241 return; |
| 249 } | 242 } |
| 250 | 243 |
| 251 // 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 |
| 252 // is owned by the reaching frames for now. | 245 // is owned by the reaching frames for now. |
| 253 bool had_fall_through = false; | 246 bool had_fall_through = false; |
| 254 if (cgen_->has_valid_frame()) { | 247 if (cgen_->has_valid_frame()) { |
| 255 had_fall_through = true; | 248 had_fall_through = true; |
| 256 AddReachingFrame(cgen_->frame()); // Return value ignored. | 249 AddReachingFrame(cgen_->frame()); // Return value ignored. |
| 257 RegisterFile empty; | 250 RegisterFile empty; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 324 } |
| 332 | 325 |
| 333 // 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 |
| 334 // fall through and none of the reaching frames needed merging. | 327 // fall through and none of the reaching frames needed merging. |
| 335 // In that case, clone the entry frame as the current frame. | 328 // In that case, clone the entry frame as the current frame. |
| 336 if (!cgen_->has_valid_frame()) { | 329 if (!cgen_->has_valid_frame()) { |
| 337 RegisterFile reserved_registers = RegisterAllocator::Reserved(); | 330 RegisterFile reserved_registers = RegisterAllocator::Reserved(); |
| 338 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved_registers); | 331 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved_registers); |
| 339 } | 332 } |
| 340 | 333 |
| 341 // There is certainly a current frame equal to the entry frame. | |
| 342 // Bind the entry frame label. | |
| 343 __ bind(&entry_label_); | |
| 344 | |
| 345 // There may be unprocessed reaching frames that did not need | 334 // There may be unprocessed reaching frames that did not need |
| 346 // merge code. They will have unbound merge labels. Bind their | 335 // merge code. They will have unbound merge labels. Bind their |
| 347 // 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 |
| 348 // them. | 337 // them. |
| 349 for (int i = 0; i < reaching_frames_.length(); i++) { | 338 for (int i = 0; i < reaching_frames_.length(); i++) { |
| 350 if (!merge_labels_[i].is_bound()) { | 339 if (!merge_labels_[i].is_bound()) { |
| 351 reaching_frames_[i] = NULL; | 340 reaching_frames_[i] = NULL; |
| 352 __ bind(&merge_labels_[i]); | 341 __ bind(&merge_labels_[i]); |
| 353 } | 342 } |
| 354 } | 343 } |
| 355 | 344 |
| 356 // There are non-NULL reaching frames with bound labels for each | 345 // There are non-NULL reaching frames with bound labels for each |
| 357 // merge block, but only on backward targets. | 346 // merge block, but only on backward targets. |
| 358 } else { | 347 } else { |
| 359 // 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 |
| 360 // this must be a bidirectional target. | 349 // this must be a bidirectional target. |
| 361 ASSERT(reaching_frames_.length() == 1); | 350 ASSERT(reaching_frames_.length() == 1); |
| 362 ASSERT(reaching_frames_[0] != NULL); | 351 ASSERT(reaching_frames_[0] != NULL); |
| 363 ASSERT(direction_ == BIDIRECTIONAL); | 352 ASSERT(direction_ == BIDIRECTIONAL); |
| 364 | 353 |
| 365 // 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 |
| 366 // for possible reuse as a backward merge block. | 355 // for possible reuse as a backward merge block. |
| 367 RegisterFile reserved = RegisterAllocator::Reserved(); | 356 RegisterFile reserved = RegisterAllocator::Reserved(); |
| 368 cgen_->SetFrame(new VirtualFrame(reaching_frames_[0]), &reserved); | 357 cgen_->SetFrame(new VirtualFrame(reaching_frames_[0]), &reserved); |
| 369 __ bind(&merge_labels_[0]); | 358 __ bind(&merge_labels_[0]); |
| 370 cgen_->frame()->MergeTo(entry_frame_); | 359 cgen_->frame()->MergeTo(entry_frame_); |
| 371 __ bind(&entry_label_); | |
| 372 } | 360 } |
| 373 | 361 |
| 374 is_linked_ = false; | 362 __ bind(&entry_label_); |
| 375 is_bound_ = true; | |
| 376 } | 363 } |
| 377 | 364 |
| 378 #undef __ | 365 #undef __ |
| 379 | 366 |
| 380 | 367 |
| 381 } } // namespace v8::internal | 368 } } // namespace v8::internal |
| OLD | NEW |