OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "src/interpreter/bytecode-array-builder.h" |
| 8 #include "src/interpreter/bytecode-register-allocator.h" |
| 9 #include "test/unittests/test-utils.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace interpreter { |
| 14 |
| 15 class BytecodeRegisterAllocatorTest : public TestWithIsolateAndZone { |
| 16 public: |
| 17 BytecodeRegisterAllocatorTest() {} |
| 18 ~BytecodeRegisterAllocatorTest() override {} |
| 19 }; |
| 20 |
| 21 |
| 22 TEST_F(BytecodeRegisterAllocatorTest, TemporariesRecycled) { |
| 23 BytecodeArrayBuilder builder(isolate(), zone()); |
| 24 builder.set_parameter_count(0); |
| 25 builder.set_locals_count(0); |
| 26 builder.set_context_count(0); |
| 27 |
| 28 int first; |
| 29 { |
| 30 BytecodeRegisterAllocator temporaries(&builder); |
| 31 first = temporaries.NewRegister().index(); |
| 32 temporaries.NewRegister(); |
| 33 temporaries.NewRegister(); |
| 34 temporaries.NewRegister(); |
| 35 } |
| 36 |
| 37 int second; |
| 38 { |
| 39 BytecodeRegisterAllocator temporaries(&builder); |
| 40 second = temporaries.NewRegister().index(); |
| 41 } |
| 42 |
| 43 CHECK_EQ(first, second); |
| 44 } |
| 45 |
| 46 |
| 47 TEST_F(BytecodeRegisterAllocatorTest, ConsecutiveRegisters) { |
| 48 BytecodeArrayBuilder builder(isolate(), zone()); |
| 49 builder.set_parameter_count(0); |
| 50 builder.set_locals_count(0); |
| 51 builder.set_context_count(0); |
| 52 |
| 53 BytecodeRegisterAllocator temporaries(&builder); |
| 54 temporaries.PrepareForConsecutiveAllocations(4); |
| 55 Register reg0 = temporaries.NextConsecutiveRegister(); |
| 56 Register other = temporaries.NewRegister(); |
| 57 Register reg1 = temporaries.NextConsecutiveRegister(); |
| 58 Register reg2 = temporaries.NextConsecutiveRegister(); |
| 59 Register reg3 = temporaries.NextConsecutiveRegister(); |
| 60 USE(other); |
| 61 |
| 62 CHECK(Register::AreContiguous(reg0, reg1, reg2, reg3)); |
| 63 } |
| 64 |
| 65 } // namespace interpreter |
| 66 } // namespace internal |
| 67 } // namespace v8 |
OLD | NEW |