| 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 19 matching lines...) Expand all Loading... |
| 30 #include "codegen.h" | 30 #include "codegen.h" |
| 31 #include "jump-target.h" | 31 #include "jump-target.h" |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 // ------------------------------------------------------------------------- | 35 // ------------------------------------------------------------------------- |
| 36 // JumpTarget implementation. | 36 // JumpTarget implementation. |
| 37 | 37 |
| 38 #define __ masm_-> | 38 #define __ masm_-> |
| 39 | 39 |
| 40 JumpTarget::JumpTarget(CodeGenerator* cgen) | 40 JumpTarget::JumpTarget(CodeGenerator* cgen, Directionality direction) |
| 41 : cgen_(cgen), | 41 : cgen_(cgen), |
| 42 direction_(direction), |
| 42 reaching_frames_(0), | 43 reaching_frames_(0), |
| 43 merge_labels_(0), | 44 merge_labels_(0), |
| 44 expected_frame_(NULL) { | 45 expected_frame_(NULL) { |
| 45 ASSERT(cgen_ != NULL); | 46 ASSERT(cgen_ != NULL); |
| 46 masm_ = cgen_->masm(); | 47 masm_ = cgen_->masm(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 | 50 |
| 50 JumpTarget::JumpTarget() | 51 JumpTarget::JumpTarget() |
| 51 : cgen_(NULL), | 52 : cgen_(NULL), |
| 52 masm_(NULL), | 53 masm_(NULL), |
| 54 direction_(FORWARD_ONLY), |
| 53 reaching_frames_(0), | 55 reaching_frames_(0), |
| 54 merge_labels_(0), | 56 merge_labels_(0), |
| 55 expected_frame_(NULL) { | 57 expected_frame_(NULL) { |
| 56 } | 58 } |
| 57 | 59 |
| 58 | 60 |
| 59 void JumpTarget::set_code_generator(CodeGenerator* cgen) { | 61 void JumpTarget::Initialize(CodeGenerator* cgen, Directionality direction) { |
| 60 ASSERT(cgen != NULL); | 62 ASSERT(cgen != NULL); |
| 61 ASSERT(cgen_ == NULL); | 63 ASSERT(cgen_ == NULL); |
| 62 cgen_ = cgen; | 64 cgen_ = cgen; |
| 63 masm_ = cgen->masm(); | 65 masm_ = cgen->masm(); |
| 66 direction_ = direction; |
| 64 } | 67 } |
| 65 | 68 |
| 66 | 69 |
| 67 void JumpTarget::Jump() { | 70 void JumpTarget::Jump() { |
| 68 ASSERT(cgen_ != NULL); | 71 ASSERT(cgen_ != NULL); |
| 69 ASSERT(cgen_->has_valid_frame()); | 72 ASSERT(cgen_->has_valid_frame()); |
| 70 // Live non-frame registers are not allowed at unconditional jumps | 73 // Live non-frame registers are not allowed at unconditional jumps |
| 71 // because we have no way of invalidating the corresponding results | 74 // because we have no way of invalidating the corresponding results |
| 72 // which are still live in the C++ code. | 75 // which are still live in the C++ code. |
| 73 ASSERT(cgen_->HasValidEntryRegisters()); | 76 ASSERT(cgen_->HasValidEntryRegisters()); |
| 74 | 77 |
| 75 if (is_bound()) { | 78 if (is_bound()) { |
| 76 // Backward jump. There is an expected frame to merge to. | 79 // Backward jump. There is an expected frame to merge to. |
| 80 ASSERT(direction_ == BIDIRECTIONAL); |
| 77 cgen_->frame()->MergeTo(expected_frame_); | 81 cgen_->frame()->MergeTo(expected_frame_); |
| 78 cgen_->DeleteFrame(); | 82 cgen_->DeleteFrame(); |
| 79 __ jmp(&entry_label_); | 83 __ jmp(&entry_label_); |
| 80 } else { | 84 } else { |
| 81 // Forward jump. The current frame is added to the end of the list | 85 // Forward jump. The current frame is added to the end of the list |
| 82 // of frames reaching the target block and a jump to the merge code | 86 // of frames reaching the target block and a jump to the merge code |
| 83 // is emitted. | 87 // is emitted. |
| 84 AddReachingFrame(cgen_->frame()); | 88 AddReachingFrame(cgen_->frame()); |
| 85 RegisterFile empty; | 89 RegisterFile empty; |
| 86 cgen_->SetFrame(NULL, &empty); | 90 cgen_->SetFrame(NULL, &empty); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 113 ASSERT(cgen_->has_valid_frame()); | 117 ASSERT(cgen_->has_valid_frame()); |
| 114 | 118 |
| 115 if (is_bound()) { | 119 if (is_bound()) { |
| 116 // Backward branch. We have an expected frame to merge to on the | 120 // Backward branch. We have an expected frame to merge to on the |
| 117 // backward edge. We negate the condition and emit the merge code | 121 // backward edge. We negate the condition and emit the merge code |
| 118 // here. | 122 // here. |
| 119 // | 123 // |
| 120 // TODO(): we should try to avoid negating the condition in the case | 124 // TODO(): we should try to avoid negating the condition in the case |
| 121 // where there is no merge code to emit. Otherwise, we emit a | 125 // where there is no merge code to emit. Otherwise, we emit a |
| 122 // branch around an unconditional jump. | 126 // branch around an unconditional jump. |
| 127 ASSERT(direction_ == BIDIRECTIONAL); |
| 123 Label original_fall_through; | 128 Label original_fall_through; |
| 124 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); | 129 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); |
| 125 // Swap the current frame for a copy of it, saving non-frame | 130 // Swap the current frame for a copy of it, saving non-frame |
| 126 // register reference counts and invalidating all non-frame register | 131 // register reference counts and invalidating all non-frame register |
| 127 // references except the reserved ones on the backward edge. | 132 // references except the reserved ones on the backward edge. |
| 128 VirtualFrame* original_frame = cgen_->frame(); | 133 VirtualFrame* original_frame = cgen_->frame(); |
| 129 VirtualFrame* working_frame = new VirtualFrame(original_frame); | 134 VirtualFrame* working_frame = new VirtualFrame(original_frame); |
| 130 RegisterFile non_frame_registers = RegisterAllocator::Reserved(); | 135 RegisterFile non_frame_registers = RegisterAllocator::Reserved(); |
| 131 cgen_->SetFrame(working_frame, &non_frame_registers); | 136 cgen_->SetFrame(working_frame, &non_frame_registers); |
| 132 | 137 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 Bind(); | 303 Bind(); |
| 299 *arg1 = cgen_->frame()->Pop(); | 304 *arg1 = cgen_->frame()->Pop(); |
| 300 *arg0 = cgen_->frame()->Pop(); | 305 *arg0 = cgen_->frame()->Pop(); |
| 301 } | 306 } |
| 302 | 307 |
| 303 | 308 |
| 304 void JumpTarget::CopyTo(JumpTarget* destination) { | 309 void JumpTarget::CopyTo(JumpTarget* destination) { |
| 305 ASSERT(destination != NULL); | 310 ASSERT(destination != NULL); |
| 306 destination->cgen_ = cgen_; | 311 destination->cgen_ = cgen_; |
| 307 destination->masm_ = masm_; | 312 destination->masm_ = masm_; |
| 308 | 313 destination->direction_ = direction_; |
| 309 destination->reaching_frames_.Clear(); | 314 destination->reaching_frames_.Clear(); |
| 310 destination->merge_labels_.Clear(); | 315 destination->merge_labels_.Clear(); |
| 311 ASSERT(reaching_frames_.length() == merge_labels_.length()); | 316 ASSERT(reaching_frames_.length() == merge_labels_.length()); |
| 312 for (int i = 0; i < reaching_frames_.length(); i++) { | 317 for (int i = 0; i < reaching_frames_.length(); i++) { |
| 313 destination->reaching_frames_.Add(reaching_frames_[i]); | 318 destination->reaching_frames_.Add(reaching_frames_[i]); |
| 314 destination->merge_labels_.Add(merge_labels_[i]); | 319 destination->merge_labels_.Add(merge_labels_[i]); |
| 315 } | 320 } |
| 316 destination->expected_frame_ = expected_frame_; | 321 destination->expected_frame_ = expected_frame_; |
| 317 destination->entry_label_ = entry_label_; | 322 destination->entry_label_ = entry_label_; |
| 318 } | 323 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 347 // The original's state is reset. We do not Unuse it because that | 352 // The original's state is reset. We do not Unuse it because that |
| 348 // would delete the expected frame and assert that the target is not | 353 // would delete the expected frame and assert that the target is not |
| 349 // linked. | 354 // linked. |
| 350 shadowed->Reset(); | 355 shadowed->Reset(); |
| 351 } | 356 } |
| 352 | 357 |
| 353 | 358 |
| 354 void ShadowTarget::StopShadowing() { | 359 void ShadowTarget::StopShadowing() { |
| 355 ASSERT(is_shadowing_); | 360 ASSERT(is_shadowing_); |
| 356 | 361 |
| 362 // This target does not have a valid code generator yet. |
| 363 cgen_ = other_target_->code_generator(); |
| 364 ASSERT(cgen_ != NULL); |
| 365 masm_ = cgen_->masm(); |
| 366 |
| 357 // The states of this target, which was shadowed, and the original | 367 // The states of this target, which was shadowed, and the original |
| 358 // target, which was shadowing, are swapped. | 368 // target, which was shadowing, are swapped. |
| 359 JumpTarget temp; | 369 JumpTarget temp; |
| 360 | |
| 361 other_target_->CopyTo(&temp); | 370 other_target_->CopyTo(&temp); |
| 362 CopyTo(other_target_); | 371 CopyTo(other_target_); |
| 363 temp.CopyTo(this); | 372 temp.CopyTo(this); |
| 364 temp.Reset(); // So the destructor does not deallocate virtual frames. | 373 temp.Reset(); // So the destructor does not deallocate virtual frames. |
| 365 | 374 |
| 366 // The shadowing target does not have a valid code generator yet. | |
| 367 other_target_->set_code_generator(cgen_); | |
| 368 #ifdef DEBUG | 375 #ifdef DEBUG |
| 369 is_shadowing_ = false; | 376 is_shadowing_ = false; |
| 370 #endif | 377 #endif |
| 371 } | 378 } |
| 372 | 379 |
| 373 #undef __ | 380 #undef __ |
| 374 | 381 |
| 375 | 382 |
| 376 } } // namespace v8::internal | 383 } } // namespace v8::internal |
| OLD | NEW |