| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ASSERT(cgen_ != NULL); | 65 ASSERT(cgen_ != NULL); |
| 66 | 66 |
| 67 VirtualFrame* current_frame = cgen_->frame(); | 67 VirtualFrame* current_frame = cgen_->frame(); |
| 68 ASSERT(current_frame != NULL); | 68 ASSERT(current_frame != NULL); |
| 69 ASSERT(cgen_->HasValidEntryRegisters()); | 69 ASSERT(cgen_->HasValidEntryRegisters()); |
| 70 | 70 |
| 71 if (expected_frame_ == NULL) { | 71 if (expected_frame_ == NULL) { |
| 72 current_frame->MakeMergable(); | 72 current_frame->MakeMergable(); |
| 73 expected_frame_ = current_frame; | 73 expected_frame_ = current_frame; |
| 74 ASSERT(cgen_->HasValidEntryRegisters()); | 74 ASSERT(cgen_->HasValidEntryRegisters()); |
| 75 cgen_->SetFrame(NULL); | 75 RegisterFile ignored; |
| 76 cgen_->SetFrame(NULL, &ignored); |
| 76 } else { | 77 } else { |
| 77 current_frame->MergeTo(expected_frame_); | 78 current_frame->MergeTo(expected_frame_); |
| 78 ASSERT(cgen_->HasValidEntryRegisters()); | 79 ASSERT(cgen_->HasValidEntryRegisters()); |
| 79 cgen_->DeleteFrame(); | 80 cgen_->DeleteFrame(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 __ jmp(&label_); | 83 __ jmp(&label_); |
| 83 // Postcondition: there is no current frame but there is an expected frame | 84 // Postcondition: there is no current frame but there is an expected frame |
| 84 // at the label. | 85 // at the label. |
| 85 } | 86 } |
| 86 | 87 |
| 87 | 88 |
| 88 void JumpTarget::Jump(Result* arg) { | 89 void JumpTarget::Jump(Result* arg) { |
| 89 ASSERT(cgen_ != NULL); | 90 ASSERT(cgen_ != NULL); |
| 90 ASSERT(cgen_->has_valid_frame()); | 91 ASSERT(cgen_->has_valid_frame()); |
| 91 | 92 |
| 92 cgen_->frame()->Push(arg); | 93 cgen_->frame()->Push(arg); |
| 93 Jump(); | 94 Jump(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 | 97 |
| 97 void JumpTarget::Branch(Condition cc, Hint hint) { | 98 void JumpTarget::Branch(Condition cc, Hint hint) { |
| 98 // Precondition: there is a current frame. There may or may not be an | 99 // Precondition: there is a current frame. There may or may not be an |
| 99 // expected frame at the label. | 100 // expected frame at the label. |
| 100 ASSERT(cgen_ != NULL); | 101 ASSERT(cgen_ != NULL); |
| 101 ASSERT(masm_ != NULL); | 102 ASSERT(masm_ != NULL); |
| 102 | 103 |
| 103 VirtualFrame* current_frame = cgen_->frame(); | 104 VirtualFrame* current_frame = cgen_->frame(); |
| 104 ASSERT(current_frame != NULL); | 105 ASSERT(current_frame != NULL); |
| 105 ASSERT(cgen_->HasValidEntryRegisters()); | |
| 106 | 106 |
| 107 if (expected_frame_ == NULL) { | 107 if (expected_frame_ == NULL) { |
| 108 expected_frame_ = new VirtualFrame(current_frame); | 108 expected_frame_ = new VirtualFrame(current_frame); |
| 109 // For a branch, the frame at the fall-through basic block (not labeled) | 109 // For a branch, the frame at the fall-through basic block (not labeled) |
| 110 // does not need to be mergable, but only the other (labeled) one. That | 110 // does not need to be mergable, but only the other (labeled) one. That |
| 111 // is achieved by reversing the condition and emitting the make mergable | 111 // is achieved by reversing the condition and emitting the make mergable |
| 112 // code as the actual fall-through block. This is necessary only when | 112 // code as the actual fall-through block. This is necessary only when |
| 113 // MakeMergable will generate code. | 113 // MakeMergable will generate code. |
| 114 if (expected_frame_->RequiresMergeCode()) { | 114 if (expected_frame_->RequiresMergeCode()) { |
| 115 Label original_fall_through; | 115 Label original_fall_through; |
| 116 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); | 116 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); |
| 117 expected_frame_->MakeMergable(); | 117 expected_frame_->MakeMergable(); |
| 118 __ jmp(&label_); | 118 __ jmp(&label_); |
| 119 __ bind(&original_fall_through); | 119 __ bind(&original_fall_through); |
| 120 } else { | 120 } else { |
| 121 expected_frame_->MakeMergable(); | 121 expected_frame_->MakeMergable(); |
| 122 ASSERT(cgen_->HasValidEntryRegisters()); | 122 ASSERT(cgen_->HasValidEntryRegisters()); |
| 123 __ j(cc, &label_, hint); | 123 __ j(cc, &label_, hint); |
| 124 } | 124 } |
| 125 } else { | 125 } else { |
| 126 // We negate the condition and emit the code to merge to the expected | 126 // We negate the condition and emit the code to merge to the expected |
| 127 // frame immediately. | 127 // frame immediately. |
| 128 // | 128 // |
| 129 // TODO(): This should be replaced with a solution that emits the | 129 // TODO(): This should be replaced with a solution that emits the |
| 130 // merge code for forward CFG edges at the appropriate entry to the | 130 // merge code for forward CFG edges at the appropriate entry to the |
| 131 // target block. | 131 // target block. |
| 132 Label original_fall_through; | 132 Label original_fall_through; |
| 133 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); | 133 __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint)); |
| 134 VirtualFrame* working_frame = new VirtualFrame(current_frame); | 134 VirtualFrame* working_frame = new VirtualFrame(current_frame); |
| 135 cgen_->SetFrame(working_frame); | 135 |
| 136 // Switch to the working frame for the merge code with only the reserved |
| 137 // registers referenced outside the frame. Explicitly setting |
| 138 // references here is ugly, but temporary. |
| 139 RegisterFile non_frame_registers; |
| 140 non_frame_registers.Use(esi); |
| 141 non_frame_registers.Use(ebp); |
| 142 non_frame_registers.Use(esp); |
| 143 cgen_->SetFrame(working_frame, &non_frame_registers); |
| 144 |
| 136 working_frame->MergeTo(expected_frame_); | 145 working_frame->MergeTo(expected_frame_); |
| 137 ASSERT(cgen_->HasValidEntryRegisters()); | 146 ASSERT(cgen_->HasValidEntryRegisters()); |
| 138 __ jmp(&label_); | 147 __ jmp(&label_); |
| 139 cgen_->SetFrame(current_frame); | 148 |
| 149 // Restore the current frame and its associated non-frame registers. |
| 150 cgen_->SetFrame(current_frame, &non_frame_registers); |
| 140 delete working_frame; | 151 delete working_frame; |
| 141 __ bind(&original_fall_through); | 152 __ bind(&original_fall_through); |
| 142 } | 153 } |
| 143 // Postcondition: there is both a current frame and an expected frame at | 154 // Postcondition: there is both a current frame and an expected frame at |
| 144 // the label and they match. | 155 // the label and they match. |
| 145 } | 156 } |
| 146 | 157 |
| 147 | 158 |
| 148 void JumpTarget::Branch(Condition cc, Result* arg, Hint hint) { | 159 void JumpTarget::Branch(Condition cc, Result* arg, Hint hint) { |
| 149 ASSERT(cgen_ != NULL); | 160 ASSERT(cgen_ != NULL); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 ASSERT(!label_.is_bound()); | 238 ASSERT(!label_.is_bound()); |
| 228 | 239 |
| 229 if (expected_frame_ == NULL) { | 240 if (expected_frame_ == NULL) { |
| 230 ASSERT(cgen_->HasValidEntryRegisters()); | 241 ASSERT(cgen_->HasValidEntryRegisters()); |
| 231 // When a label is bound the current frame becomes the expected frame at | 242 // When a label is bound the current frame becomes the expected frame at |
| 232 // the label. This requires the current frame to be mergable. | 243 // the label. This requires the current frame to be mergable. |
| 233 current_frame->MakeMergable(); | 244 current_frame->MakeMergable(); |
| 234 ASSERT(cgen_->HasValidEntryRegisters()); | 245 ASSERT(cgen_->HasValidEntryRegisters()); |
| 235 expected_frame_ = new VirtualFrame(current_frame); | 246 expected_frame_ = new VirtualFrame(current_frame); |
| 236 } else if (current_frame == NULL) { | 247 } else if (current_frame == NULL) { |
| 237 cgen_->SetFrame(new VirtualFrame(expected_frame_)); | 248 // Pick up the frame from the label. No merge code is necessary. |
| 249 // Manually setting the reserved register reference counts is clumsy but |
| 250 // temporary. |
| 251 RegisterFile non_frame_registers; |
| 252 non_frame_registers.Use(esi); |
| 253 non_frame_registers.Use(ebp); |
| 254 non_frame_registers.Use(esp); |
| 255 cgen_->SetFrame(new VirtualFrame(expected_frame_), &non_frame_registers); |
| 238 ASSERT(cgen_->HasValidEntryRegisters()); | 256 ASSERT(cgen_->HasValidEntryRegisters()); |
| 239 } else { | 257 } else { |
| 240 ASSERT(cgen_->HasValidEntryRegisters()); | 258 ASSERT(cgen_->HasValidEntryRegisters()); |
| 241 current_frame->MergeTo(expected_frame_); | 259 current_frame->MergeTo(expected_frame_); |
| 242 ASSERT(cgen_->HasValidEntryRegisters()); | 260 ASSERT(cgen_->HasValidEntryRegisters()); |
| 243 } | 261 } |
| 244 | 262 |
| 245 __ bind(&label_); | 263 __ bind(&label_); |
| 246 // Postcondition: there is both a current frame and an expected frame at | 264 // Postcondition: there is both a current frame and an expected frame at |
| 247 // the label and they match. The label is bound. | 265 // the label and they match. The label is bound. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 364 |
| 347 #ifdef DEBUG | 365 #ifdef DEBUG |
| 348 is_shadowing_ = false; | 366 is_shadowing_ = false; |
| 349 #endif | 367 #endif |
| 350 } | 368 } |
| 351 | 369 |
| 352 #undef __ | 370 #undef __ |
| 353 | 371 |
| 354 | 372 |
| 355 } } // namespace v8::internal | 373 } } // namespace v8::internal |
| OLD | NEW |