| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ASSERT(!is_bound()); | 135 ASSERT(!is_bound()); |
| 136 | 136 |
| 137 // Live non-frame registers are not allowed at the start of a basic | 137 // Live non-frame registers are not allowed at the start of a basic |
| 138 // block. | 138 // block. |
| 139 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); | 139 ASSERT(!cgen_->has_valid_frame() || cgen_->HasValidEntryRegisters()); |
| 140 | 140 |
| 141 // Compute the frame to use for entry to the block. | 141 // Compute the frame to use for entry to the block. |
| 142 ComputeEntryFrame(mergable_elements); | 142 ComputeEntryFrame(mergable_elements); |
| 143 | 143 |
| 144 if (is_linked()) { | 144 if (is_linked()) { |
| 145 // There were forward jumps. All the reaching frames, beginning | 145 // There were forward jumps. Handle merging the reaching frames |
| 146 // with the current frame if any, are merged to the expected one. | 146 // and possible fall through to the entry frame. |
| 147 int start_index = 0; | |
| 148 if (!cgen_->has_valid_frame()) { | |
| 149 // Pick up the first reaching frame as the code generator's | |
| 150 // current frame. | |
| 151 RegisterFile reserved_registers = RegisterAllocator::Reserved(); | |
| 152 cgen_->SetFrame(reaching_frames_[0], &reserved_registers); | |
| 153 __ bind(&merge_labels_[0]); | |
| 154 start_index = 1; | |
| 155 } | |
| 156 | 147 |
| 157 cgen_->frame()->MergeTo(entry_frame_); | 148 // If there is a fall through to the jump target and it needs |
| 149 // merge code, process it first. |
| 150 if (cgen_->has_valid_frame() && !cgen_->frame()->Equals(entry_frame_)) { |
| 151 // Loop over all the reaching frames, looking for any that can |
| 152 // share merge code with this one. |
| 153 for (int i = 0; i < reaching_frames_.length(); i++) { |
| 154 if (cgen_->frame()->Equals(reaching_frames_[i])) { |
| 155 // Set the reaching frames element to null to avoid |
| 156 // processing it later, and then bind its entry label. |
| 157 delete reaching_frames_[i]; |
| 158 reaching_frames_[i] = NULL; |
| 159 __ bind(&merge_labels_[i]); |
| 160 } |
| 161 } |
| 158 | 162 |
| 159 for (int i = start_index; i < reaching_frames_.length(); i++) { | 163 // Emit the merge code. |
| 160 // Delete the current frame and jump to the block entry. | |
| 161 cgen_->DeleteFrame(); | |
| 162 __ jmp(&entry_label_); | |
| 163 | |
| 164 // Pick up the next reaching frame as the code generator's | |
| 165 // current frame. | |
| 166 RegisterFile reserved_registers = RegisterAllocator::Reserved(); | |
| 167 cgen_->SetFrame(reaching_frames_[i], &reserved_registers); | |
| 168 __ bind(&merge_labels_[i]); | |
| 169 | |
| 170 cgen_->frame()->MergeTo(entry_frame_); | 164 cgen_->frame()->MergeTo(entry_frame_); |
| 171 } | 165 } |
| 172 | 166 |
| 167 // Loop over the (non-null) reaching frames and process any that |
| 168 // need merge code. |
| 169 for (int i = 0; i < reaching_frames_.length(); i++) { |
| 170 VirtualFrame* frame = reaching_frames_[i]; |
| 171 if (frame != NULL && !frame->Equals(entry_frame_)) { |
| 172 // Set the reaching frames element to null to avoid processing |
| 173 // it later. Do not delete it as it is needed for merging. |
| 174 reaching_frames_[i] = NULL; |
| 175 |
| 176 // If the code generator has a current frame (a fall-through |
| 177 // or a previously merged frame), insert a jump around the |
| 178 // merge code we are about to generate. |
| 179 if (cgen_->has_valid_frame()) { |
| 180 cgen_->DeleteFrame(); |
| 181 __ jmp(&entry_label_); |
| 182 } |
| 183 |
| 184 // Set the frame to merge as the code generator's current |
| 185 // frame and bind its merge label. |
| 186 RegisterFile reserved_registers = RegisterAllocator::Reserved(); |
| 187 cgen_->SetFrame(frame, &reserved_registers); |
| 188 __ bind(&merge_labels_[i]); |
| 189 |
| 190 // Loop over the remaining (non-null) reaching frames, looking |
| 191 // for any that can share merge code with this one. |
| 192 for (int j = i + 1; j < reaching_frames_.length(); j++) { |
| 193 VirtualFrame* other = reaching_frames_[j]; |
| 194 if (other != NULL && frame->Equals(other)) { |
| 195 delete other; |
| 196 reaching_frames_[j] = NULL; |
| 197 __ bind(&merge_labels_[j]); |
| 198 } |
| 199 } |
| 200 |
| 201 // Emit the merge code. |
| 202 cgen_->frame()->MergeTo(entry_frame_); |
| 203 } |
| 204 } |
| 205 |
| 206 // The code generator may not have a current frame if there was no |
| 207 // fall through and none of the reaching frames needed merging. |
| 208 // In that case, clone the entry frame as the current frame. |
| 209 if (!cgen_->has_valid_frame()) { |
| 210 RegisterFile reserved_registers = RegisterAllocator::Reserved(); |
| 211 cgen_->SetFrame(new VirtualFrame(entry_frame_), &reserved_registers); |
| 212 } |
| 213 |
| 214 // There is certainly a current frame equal to the entry frame. |
| 215 // Bind the entry frame label. |
| 173 __ bind(&entry_label_); | 216 __ bind(&entry_label_); |
| 174 | 217 |
| 175 // All but the last reaching virtual frame have been deleted, and | 218 // There may be unprocessed reaching frames that did not need |
| 176 // the last one is the current frame. | 219 // merge code. Bind their merge labels to be the same as the |
| 220 // entry label. |
| 221 for (int i = 0; i < reaching_frames_.length(); i++) { |
| 222 if (reaching_frames_[i] != NULL) { |
| 223 delete reaching_frames_[i]; |
| 224 __ bind(&merge_labels_[i]); |
| 225 } |
| 226 } |
| 227 |
| 228 // All the reaching frames except the one that is the current |
| 229 // frame (if it is one of the reaching frames) have been deleted. |
| 177 reaching_frames_.Clear(); | 230 reaching_frames_.Clear(); |
| 178 merge_labels_.Clear(); | 231 merge_labels_.Clear(); |
| 232 |
| 179 } else { | 233 } else { |
| 180 // There were no forward jumps. The current frame is merged to | 234 // There were no forward jumps. The current frame is merged to |
| 181 // the entry frame. | 235 // the entry frame. |
| 182 cgen_->frame()->MergeTo(entry_frame_); | 236 cgen_->frame()->MergeTo(entry_frame_); |
| 183 __ bind(&entry_label_); | 237 __ bind(&entry_label_); |
| 184 } | 238 } |
| 185 | 239 |
| 186 is_linked_ = false; | 240 is_linked_ = false; |
| 187 is_bound_ = true; | 241 is_bound_ = true; |
| 188 } | 242 } |
| 189 | 243 |
| 190 #undef __ | 244 #undef __ |
| 191 | 245 |
| 192 | 246 |
| 193 } } // namespace v8::internal | 247 } } // namespace v8::internal |
| OLD | NEW |