diff options
Diffstat (limited to 'deps/v8/test/unittests/interpreter/bytecode-register-allocator-unittest.cc')
-rw-r--r-- | deps/v8/test/unittests/interpreter/bytecode-register-allocator-unittest.cc | 254 |
1 files changed, 69 insertions, 185 deletions
diff --git a/deps/v8/test/unittests/interpreter/bytecode-register-allocator-unittest.cc b/deps/v8/test/unittests/interpreter/bytecode-register-allocator-unittest.cc index d4dc111d69..f06e454cc9 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-register-allocator-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecode-register-allocator-unittest.cc @@ -12,199 +12,83 @@ namespace v8 { namespace internal { namespace interpreter { -class TemporaryRegisterAllocatorTest : public TestWithIsolateAndZone { - public: - TemporaryRegisterAllocatorTest() : allocator_(zone(), 0) {} - ~TemporaryRegisterAllocatorTest() override {} - TemporaryRegisterAllocator* allocator() { return &allocator_; } - - private: - TemporaryRegisterAllocator allocator_; -}; - -TEST_F(TemporaryRegisterAllocatorTest, FirstAllocation) { - CHECK_EQ(allocator()->allocation_count(), 0); - int reg0_index = allocator()->BorrowTemporaryRegister(); - CHECK_EQ(reg0_index, 0); - CHECK_EQ(allocator()->allocation_count(), 1); - CHECK(allocator()->RegisterIsLive(Register(reg0_index))); - allocator()->ReturnTemporaryRegister(reg0_index); - CHECK(!allocator()->RegisterIsLive(Register(reg0_index))); - CHECK_EQ(allocator()->allocation_count(), 1); - CHECK(allocator()->first_temporary_register() == Register(0)); - CHECK(allocator()->last_temporary_register() == Register(0)); -} - -TEST_F(TemporaryRegisterAllocatorTest, SimpleAllocations) { - for (int i = 0; i < 13; i++) { - int reg_index = allocator()->BorrowTemporaryRegister(); - CHECK_EQ(reg_index, i); - CHECK_EQ(allocator()->allocation_count(), i + 1); - } - for (int i = 0; i < 13; i++) { - CHECK(allocator()->RegisterIsLive(Register(i))); - allocator()->ReturnTemporaryRegister(i); - CHECK(!allocator()->RegisterIsLive(Register(i))); - int reg_index = allocator()->BorrowTemporaryRegister(); - CHECK_EQ(reg_index, i); - CHECK_EQ(allocator()->allocation_count(), 13); - } - for (int i = 0; i < 13; i++) { - CHECK(allocator()->RegisterIsLive(Register(i))); - allocator()->ReturnTemporaryRegister(i); - CHECK(!allocator()->RegisterIsLive(Register(i))); - } -} - -TEST_F(TemporaryRegisterAllocatorTest, SimpleRangeAllocation) { - static const int kRunLength = 7; - int start = allocator()->PrepareForConsecutiveTemporaryRegisters(kRunLength); - CHECK(!allocator()->RegisterIsLive(Register(start))); - for (int i = 0; i < kRunLength; i++) { - CHECK(!allocator()->RegisterIsLive(Register(start + i))); - allocator()->BorrowConsecutiveTemporaryRegister(start + i); - CHECK(allocator()->RegisterIsLive(Register(start + i))); - } -} - -TEST_F(TemporaryRegisterAllocatorTest, RangeAllocationAbuttingFree) { - static const int kFreeCount = 3; - static const int kRunLength = 6; - - for (int i = 0; i < kFreeCount; i++) { - int to_free = allocator()->BorrowTemporaryRegister(); - CHECK_EQ(to_free, i); - } - for (int i = 0; i < kFreeCount; i++) { - allocator()->ReturnTemporaryRegister(i); - } - - int start = allocator()->PrepareForConsecutiveTemporaryRegisters(kRunLength); - CHECK(!allocator()->RegisterIsLive(Register(start))); - for (int i = 0; i < kRunLength; i++) { - CHECK(!allocator()->RegisterIsLive(Register(start + i))); - allocator()->BorrowConsecutiveTemporaryRegister(start + i); - CHECK(allocator()->RegisterIsLive(Register(start + i))); - } -} - -TEST_F(TemporaryRegisterAllocatorTest, RangeAllocationAbuttingHole) { - static const int kPreAllocatedCount = 7; - static const int kPreAllocatedFreeCount = 6; - static const int kRunLength = 8; - - for (int i = 0; i < kPreAllocatedCount; i++) { - int to_free = allocator()->BorrowTemporaryRegister(); - CHECK_EQ(to_free, i); - } - for (int i = 0; i < kPreAllocatedFreeCount; i++) { - allocator()->ReturnTemporaryRegister(i); - } - int start = allocator()->PrepareForConsecutiveTemporaryRegisters(kRunLength); - CHECK(!allocator()->RegisterIsLive(Register(start))); - CHECK_EQ(start, kPreAllocatedCount); - for (int i = 0; i < kRunLength; i++) { - CHECK(!allocator()->RegisterIsLive(Register(start + i))); - allocator()->BorrowConsecutiveTemporaryRegister(start + i); - CHECK(allocator()->RegisterIsLive(Register(start + i))); - } -} - -TEST_F(TemporaryRegisterAllocatorTest, RangeAllocationAvailableInTemporaries) { - static const int kNotRunLength = 13; - static const int kRunLength = 8; - - // Allocate big batch - for (int i = 0; i < kNotRunLength * 2 + kRunLength; i++) { - int allocated = allocator()->BorrowTemporaryRegister(); - CHECK_EQ(allocated, i); - } - // Free every other register either side of target. - for (int i = 0; i < kNotRunLength; i++) { - if ((i & 2) == 1) { - allocator()->ReturnTemporaryRegister(i); - allocator()->ReturnTemporaryRegister(kNotRunLength + kRunLength + i); - } - } - // Free all registers for target. - for (int i = kNotRunLength; i < kNotRunLength + kRunLength; i++) { - allocator()->ReturnTemporaryRegister(i); - } - - int start = allocator()->PrepareForConsecutiveTemporaryRegisters(kRunLength); - CHECK_EQ(start, kNotRunLength); - for (int i = 0; i < kRunLength; i++) { - CHECK(!allocator()->RegisterIsLive(Register(start + i))); - allocator()->BorrowConsecutiveTemporaryRegister(start + i); - CHECK(allocator()->RegisterIsLive(Register(start + i))); - } -} - -TEST_F(TemporaryRegisterAllocatorTest, NotInRange) { - for (int i = 0; i < 10; i++) { - int reg = allocator()->BorrowTemporaryRegisterNotInRange(2, 5); - CHECK(reg == i || (reg > 2 && reg == i + 4)); - } - for (int i = 0; i < 10; i++) { - if (i < 2) { - allocator()->ReturnTemporaryRegister(i); - } else { - allocator()->ReturnTemporaryRegister(i + 4); - } - } - int reg0 = allocator()->BorrowTemporaryRegisterNotInRange(0, 3); - CHECK_EQ(reg0, 4); - int reg1 = allocator()->BorrowTemporaryRegisterNotInRange(3, 10); - CHECK_EQ(reg1, 2); - int reg2 = allocator()->BorrowTemporaryRegisterNotInRange(2, 6); - CHECK_EQ(reg2, 1); - allocator()->ReturnTemporaryRegister(reg0); - allocator()->ReturnTemporaryRegister(reg1); - allocator()->ReturnTemporaryRegister(reg2); -} - class BytecodeRegisterAllocatorTest : public TestWithIsolateAndZone { public: - BytecodeRegisterAllocatorTest() {} + BytecodeRegisterAllocatorTest() : allocator_(0) {} ~BytecodeRegisterAllocatorTest() override {} -}; - -TEST_F(BytecodeRegisterAllocatorTest, TemporariesRecycled) { - BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); - int first; - { - BytecodeRegisterAllocator allocator(zone(), - builder.temporary_register_allocator()); - first = allocator.NewRegister().index(); - allocator.NewRegister(); - allocator.NewRegister(); - allocator.NewRegister(); - } + BytecodeRegisterAllocator* allocator() { return &allocator_; } - int second; - { - BytecodeRegisterAllocator allocator(zone(), - builder.temporary_register_allocator()); - second = allocator.NewRegister().index(); - } + private: + BytecodeRegisterAllocator allocator_; +}; - CHECK_EQ(first, second); +TEST_F(BytecodeRegisterAllocatorTest, SimpleAllocations) { + CHECK_EQ(allocator()->maximum_register_count(), 0); + Register reg0 = allocator()->NewRegister(); + CHECK_EQ(reg0.index(), 0); + CHECK_EQ(allocator()->maximum_register_count(), 1); + CHECK_EQ(allocator()->next_register_index(), 1); + CHECK(allocator()->RegisterIsLive(reg0)); + + allocator()->ReleaseRegisters(0); + CHECK(!allocator()->RegisterIsLive(reg0)); + CHECK_EQ(allocator()->maximum_register_count(), 1); + CHECK_EQ(allocator()->next_register_index(), 0); + + reg0 = allocator()->NewRegister(); + Register reg1 = allocator()->NewRegister(); + CHECK_EQ(reg0.index(), 0); + CHECK_EQ(reg1.index(), 1); + CHECK(allocator()->RegisterIsLive(reg0)); + CHECK(allocator()->RegisterIsLive(reg1)); + CHECK_EQ(allocator()->maximum_register_count(), 2); + CHECK_EQ(allocator()->next_register_index(), 2); + + allocator()->ReleaseRegisters(1); + CHECK(allocator()->RegisterIsLive(reg0)); + CHECK(!allocator()->RegisterIsLive(reg1)); + CHECK_EQ(allocator()->maximum_register_count(), 2); + CHECK_EQ(allocator()->next_register_index(), 1); } -TEST_F(BytecodeRegisterAllocatorTest, ConsecutiveRegisters) { - BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); - BytecodeRegisterAllocator allocator(zone(), - builder.temporary_register_allocator()); - allocator.PrepareForConsecutiveAllocations(4); - Register reg0 = allocator.NextConsecutiveRegister(); - Register other = allocator.NewRegister(); - Register reg1 = allocator.NextConsecutiveRegister(); - Register reg2 = allocator.NextConsecutiveRegister(); - Register reg3 = allocator.NextConsecutiveRegister(); - USE(other); - - CHECK(Register::AreContiguous(reg0, reg1, reg2, reg3)); +TEST_F(BytecodeRegisterAllocatorTest, RegisterListAllocations) { + CHECK_EQ(allocator()->maximum_register_count(), 0); + RegisterList reg_list = allocator()->NewRegisterList(3); + CHECK_EQ(reg_list.first_register().index(), 0); + CHECK_EQ(reg_list.register_count(), 3); + CHECK_EQ(reg_list[0].index(), 0); + CHECK_EQ(reg_list[1].index(), 1); + CHECK_EQ(reg_list[2].index(), 2); + CHECK_EQ(allocator()->maximum_register_count(), 3); + CHECK_EQ(allocator()->next_register_index(), 3); + CHECK(allocator()->RegisterIsLive(reg_list[2])); + + Register reg = allocator()->NewRegister(); + RegisterList reg_list_2 = allocator()->NewRegisterList(2); + CHECK_EQ(reg.index(), 3); + CHECK_EQ(reg_list_2.first_register().index(), 4); + CHECK_EQ(reg_list_2.register_count(), 2); + CHECK_EQ(reg_list_2[0].index(), 4); + CHECK_EQ(reg_list_2[1].index(), 5); + CHECK_EQ(allocator()->maximum_register_count(), 6); + CHECK_EQ(allocator()->next_register_index(), 6); + CHECK(allocator()->RegisterIsLive(reg)); + CHECK(allocator()->RegisterIsLive(reg_list_2[1])); + + allocator()->ReleaseRegisters(reg.index()); + CHECK(!allocator()->RegisterIsLive(reg)); + CHECK(!allocator()->RegisterIsLive(reg_list_2[0])); + CHECK(!allocator()->RegisterIsLive(reg_list_2[1])); + CHECK(allocator()->RegisterIsLive(reg_list[2])); + CHECK_EQ(allocator()->maximum_register_count(), 6); + CHECK_EQ(allocator()->next_register_index(), 3); + + RegisterList empty_reg_list = allocator()->NewRegisterList(0); + CHECK_EQ(empty_reg_list.first_register().index(), 0); + CHECK_EQ(empty_reg_list.register_count(), 0); + CHECK_EQ(allocator()->maximum_register_count(), 6); + CHECK_EQ(allocator()->next_register_index(), 3); } } // namespace interpreter |