| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/interpreter/bytecode-register-allocator.h" | 5 #include "src/interpreter/bytecode-register-allocator.h" |
| 6 | 6 |
| 7 #include "src/interpreter/bytecode-array-builder.h" | 7 #include "src/interpreter/bytecode-array-builder.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 // Search within existing temporaries for a run. | 89 // Search within existing temporaries for a run. |
| 90 auto start = free_temporaries_.begin(); | 90 auto start = free_temporaries_.begin(); |
| 91 size_t run_length = 0; | 91 size_t run_length = 0; |
| 92 for (auto run_end = start; run_end != free_temporaries_.end(); run_end++) { | 92 for (auto run_end = start; run_end != free_temporaries_.end(); run_end++) { |
| 93 int expected = *start + static_cast<int>(run_length); | 93 int expected = *start + static_cast<int>(run_length); |
| 94 if (*run_end != expected) { | 94 if (*run_end != expected) { |
| 95 start = run_end; | 95 start = run_end; |
| 96 run_length = 0; | 96 run_length = 0; |
| 97 } | 97 } |
| 98 Register reg_start(*start); | |
| 99 Register reg_expected(expected); | |
| 100 if (RegisterTranslator::DistanceToTranslationWindow(reg_start) > 0 && | |
| 101 RegisterTranslator::DistanceToTranslationWindow(reg_expected) <= 0) { | |
| 102 // Run straddles the lower edge of the translation window. Registers | |
| 103 // after the start of this boundary are displaced by the register | |
| 104 // translator to provide a hole for translation. Runs either side | |
| 105 // of the boundary are fine. | |
| 106 start = run_end; | |
| 107 run_length = 0; | |
| 108 } | |
| 109 if (++run_length == count) { | 98 if (++run_length == count) { |
| 110 return *start; | 99 return *start; |
| 111 } | 100 } |
| 112 } | 101 } |
| 113 | 102 |
| 114 // Continue run if possible across existing last temporary. | 103 // Continue run if possible across existing last temporary. |
| 115 if (allocation_count_ > 0 && (start == free_temporaries_.end() || | 104 if (allocation_count_ > 0 && (start == free_temporaries_.end() || |
| 116 *start + static_cast<int>(run_length) != | 105 *start + static_cast<int>(run_length) != |
| 117 last_temporary_register().index() + 1)) { | 106 last_temporary_register().index() + 1)) { |
| 118 run_length = 0; | 107 run_length = 0; |
| 119 } | 108 } |
| 120 | 109 |
| 121 // Pad temporaries if extended run would cross translation boundary. | 110 // Pad temporaries if extended run would cross translation boundary. |
| 122 Register reg_first(*start); | 111 Register reg_first(*start); |
| 123 Register reg_last(*start + static_cast<int>(count) - 1); | 112 Register reg_last(*start + static_cast<int>(count) - 1); |
| 124 DCHECK_GT(RegisterTranslator::DistanceToTranslationWindow(reg_first), | |
| 125 RegisterTranslator::DistanceToTranslationWindow(reg_last)); | |
| 126 while (RegisterTranslator::DistanceToTranslationWindow(reg_first) > 0 && | |
| 127 RegisterTranslator::DistanceToTranslationWindow(reg_last) <= 0) { | |
| 128 auto pos_insert_pair = | |
| 129 free_temporaries_.insert(AllocateTemporaryRegister()); | |
| 130 reg_first = Register(*pos_insert_pair.first); | |
| 131 reg_last = Register(reg_first.index() + static_cast<int>(count) - 1); | |
| 132 run_length = 0; | |
| 133 } | |
| 134 | 113 |
| 135 // Ensure enough registers for run. | 114 // Ensure enough registers for run. |
| 136 while (run_length++ < count) { | 115 while (run_length++ < count) { |
| 137 free_temporaries_.insert(AllocateTemporaryRegister()); | 116 free_temporaries_.insert(AllocateTemporaryRegister()); |
| 138 } | 117 } |
| 139 | 118 |
| 140 int run_start = | 119 int run_start = |
| 141 last_temporary_register().index() - static_cast<int>(count) + 1; | 120 last_temporary_register().index() - static_cast<int>(count) + 1; |
| 142 DCHECK(RegisterTranslator::DistanceToTranslationWindow(Register(run_start)) <= | |
| 143 0 || | |
| 144 RegisterTranslator::DistanceToTranslationWindow( | |
| 145 Register(run_start + static_cast<int>(count) - 1)) > 0); | |
| 146 return run_start; | 121 return run_start; |
| 147 } | 122 } |
| 148 | 123 |
| 149 bool TemporaryRegisterAllocator::RegisterIsLive(Register reg) const { | 124 bool TemporaryRegisterAllocator::RegisterIsLive(Register reg) const { |
| 150 if (allocation_count_ > 0) { | 125 if (allocation_count_ > 0) { |
| 151 DCHECK(reg >= first_temporary_register() && | 126 DCHECK(reg >= first_temporary_register() && |
| 152 reg <= last_temporary_register()); | 127 reg <= last_temporary_register()); |
| 153 return free_temporaries_.find(reg.index()) == free_temporaries_.end(); | 128 return free_temporaries_.find(reg.index()) == free_temporaries_.end(); |
| 154 } else { | 129 } else { |
| 155 return false; | 130 return false; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 base_allocator()->BorrowConsecutiveTemporaryRegister( | 195 base_allocator()->BorrowConsecutiveTemporaryRegister( |
| 221 next_consecutive_register_); | 196 next_consecutive_register_); |
| 222 allocated_.push_back(next_consecutive_register_); | 197 allocated_.push_back(next_consecutive_register_); |
| 223 next_consecutive_count_--; | 198 next_consecutive_count_--; |
| 224 return Register(next_consecutive_register_++); | 199 return Register(next_consecutive_register_++); |
| 225 } | 200 } |
| 226 | 201 |
| 227 } // namespace interpreter | 202 } // namespace interpreter |
| 228 } // namespace internal | 203 } // namespace internal |
| 229 } // namespace v8 | 204 } // namespace v8 |
| OLD | NEW |