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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 bool BytecodeArrayBuilder::FitsInReg8Operand(Register value) { | 1596 bool BytecodeArrayBuilder::FitsInReg8Operand(Register value) { |
1597 return kMinInt8 <= value.index() && value.index() <= kMaxInt8; | 1597 return kMinInt8 <= value.index() && value.index() <= kMaxInt8; |
1598 } | 1598 } |
1599 | 1599 |
1600 | 1600 |
1601 // static | 1601 // static |
1602 bool BytecodeArrayBuilder::FitsInReg16Operand(Register value) { | 1602 bool BytecodeArrayBuilder::FitsInReg16Operand(Register value) { |
1603 return kMinInt16 <= value.index() && value.index() <= kMaxInt16; | 1603 return kMinInt16 <= value.index() && value.index() <= kMaxInt16; |
1604 } | 1604 } |
1605 | 1605 |
1606 | |
1607 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) | |
1608 : builder_(builder), | |
1609 allocated_(builder->zone()), | |
1610 next_consecutive_register_(-1), | |
1611 next_consecutive_count_(-1) {} | |
1612 | |
1613 | |
1614 TemporaryRegisterScope::~TemporaryRegisterScope() { | |
1615 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) { | |
1616 builder_->ReturnTemporaryRegister(*i); | |
1617 } | |
1618 allocated_.clear(); | |
1619 } | |
1620 | |
1621 | |
1622 Register TemporaryRegisterScope::NewRegister() { | |
1623 int allocated = -1; | |
1624 if (next_consecutive_count_ <= 0) { | |
1625 allocated = builder_->BorrowTemporaryRegister(); | |
1626 } else { | |
1627 allocated = builder_->BorrowTemporaryRegisterNotInRange( | |
1628 next_consecutive_register_, | |
1629 next_consecutive_register_ + next_consecutive_count_ - 1); | |
1630 } | |
1631 allocated_.push_back(allocated); | |
1632 return Register(allocated); | |
1633 } | |
1634 | |
1635 | |
1636 bool TemporaryRegisterScope::RegisterIsAllocatedInThisScope( | |
1637 Register reg) const { | |
1638 for (auto i = allocated_.begin(); i != allocated_.end(); i++) { | |
1639 if (*i == reg.index()) return true; | |
1640 } | |
1641 return false; | |
1642 } | |
1643 | |
1644 | |
1645 void TemporaryRegisterScope::PrepareForConsecutiveAllocations(size_t count) { | |
1646 if (static_cast<int>(count) > next_consecutive_count_) { | |
1647 next_consecutive_register_ = | |
1648 builder_->PrepareForConsecutiveTemporaryRegisters(count); | |
1649 next_consecutive_count_ = static_cast<int>(count); | |
1650 } | |
1651 } | |
1652 | |
1653 | |
1654 Register TemporaryRegisterScope::NextConsecutiveRegister() { | |
1655 DCHECK_GE(next_consecutive_register_, 0); | |
1656 DCHECK_GT(next_consecutive_count_, 0); | |
1657 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | |
1658 allocated_.push_back(next_consecutive_register_); | |
1659 next_consecutive_count_--; | |
1660 return Register(next_consecutive_register_++); | |
1661 } | |
1662 | |
1663 } // namespace interpreter | 1606 } // namespace interpreter |
1664 } // namespace internal | 1607 } // namespace internal |
1665 } // namespace v8 | 1608 } // namespace v8 |
OLD | NEW |