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-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 // If there is a free register < start_index | 1148 // If there is a free register < start_index |
1149 index--; | 1149 index--; |
1150 } | 1150 } |
1151 | 1151 |
1152 int retval = *index; | 1152 int retval = *index; |
1153 free_temporaries_.erase(index); | 1153 free_temporaries_.erase(index); |
1154 return retval; | 1154 return retval; |
1155 } | 1155 } |
1156 | 1156 |
1157 | 1157 |
1158 int BytecodeArrayBuilder::AllocateAndBorrowTemporaryRegister() { | |
1159 temporary_register_count_ += 1; | |
1160 return last_temporary_register().index(); | |
1161 } | |
1162 | |
1163 | |
1164 void BytecodeArrayBuilder::BorrowConsecutiveTemporaryRegister(int reg_index) { | 1158 void BytecodeArrayBuilder::BorrowConsecutiveTemporaryRegister(int reg_index) { |
1165 DCHECK(free_temporaries_.find(reg_index) != free_temporaries_.end()); | 1159 DCHECK(free_temporaries_.find(reg_index) != free_temporaries_.end()); |
1166 free_temporaries_.erase(reg_index); | 1160 free_temporaries_.erase(reg_index); |
1167 } | 1161 } |
1168 | 1162 |
1169 | 1163 |
1170 void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) { | 1164 void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) { |
1171 DCHECK(free_temporaries_.find(reg_index) == free_temporaries_.end()); | 1165 DCHECK(free_temporaries_.find(reg_index) == free_temporaries_.end()); |
1172 free_temporaries_.insert(reg_index); | 1166 free_temporaries_.insert(reg_index); |
1173 } | 1167 } |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 } else { | 1626 } else { |
1633 allocated = builder_->BorrowTemporaryRegisterNotInRange( | 1627 allocated = builder_->BorrowTemporaryRegisterNotInRange( |
1634 next_consecutive_register_, | 1628 next_consecutive_register_, |
1635 next_consecutive_register_ + next_consecutive_count_ - 1); | 1629 next_consecutive_register_ + next_consecutive_count_ - 1); |
1636 } | 1630 } |
1637 allocated_.push_back(allocated); | 1631 allocated_.push_back(allocated); |
1638 return Register(allocated); | 1632 return Register(allocated); |
1639 } | 1633 } |
1640 | 1634 |
1641 | 1635 |
1642 Register TemporaryRegisterScope::AllocateNewRegister() { | |
1643 int allocated = builder_->AllocateAndBorrowTemporaryRegister(); | |
1644 allocated_.push_back(allocated); | |
1645 return Register(allocated); | |
1646 } | |
1647 | |
1648 | |
1649 bool TemporaryRegisterScope::RegisterIsAllocatedInThisScope( | 1636 bool TemporaryRegisterScope::RegisterIsAllocatedInThisScope( |
1650 Register reg) const { | 1637 Register reg) const { |
1651 for (auto i = allocated_.begin(); i != allocated_.end(); i++) { | 1638 for (auto i = allocated_.begin(); i != allocated_.end(); i++) { |
1652 if (*i == reg.index()) return true; | 1639 if (*i == reg.index()) return true; |
1653 } | 1640 } |
1654 return false; | 1641 return false; |
1655 } | 1642 } |
1656 | 1643 |
1657 | 1644 |
1658 void TemporaryRegisterScope::PrepareForConsecutiveAllocations(size_t count) { | 1645 void TemporaryRegisterScope::PrepareForConsecutiveAllocations(size_t count) { |
(...skipping 10 matching lines...) Expand all Loading... |
1669 DCHECK_GT(next_consecutive_count_, 0); | 1656 DCHECK_GT(next_consecutive_count_, 0); |
1670 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | 1657 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); |
1671 allocated_.push_back(next_consecutive_register_); | 1658 allocated_.push_back(next_consecutive_register_); |
1672 next_consecutive_count_--; | 1659 next_consecutive_count_--; |
1673 return Register(next_consecutive_register_++); | 1660 return Register(next_consecutive_register_++); |
1674 } | 1661 } |
1675 | 1662 |
1676 } // namespace interpreter | 1663 } // namespace interpreter |
1677 } // namespace internal | 1664 } // namespace internal |
1678 } // namespace v8 | 1665 } // namespace v8 |
OLD | NEW |