| 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 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ | 6 #define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ |
| 7 | 7 |
| 8 #include "src/interpreter/bytecode-register.h" | 8 #include "src/interpreter/bytecode-register.h" |
| 9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
| 10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 namespace interpreter { | 14 namespace interpreter { |
| 15 | 15 |
| 16 class RegisterList { | |
| 17 public: | |
| 18 RegisterList() : first_reg_index_(Register().index()), register_count_(0) {} | |
| 19 RegisterList(int first_reg_index, int register_count) | |
| 20 : first_reg_index_(first_reg_index), register_count_(register_count) {} | |
| 21 | |
| 22 // Returns a new RegisterList which is a truncated version of this list, with | |
| 23 // |count| registers. | |
| 24 const RegisterList Truncate(int new_count) { | |
| 25 DCHECK_GE(new_count, 0); | |
| 26 DCHECK_LT(new_count, register_count_); | |
| 27 return RegisterList(first_reg_index_, new_count); | |
| 28 } | |
| 29 | |
| 30 const Register operator[](size_t i) const { | |
| 31 DCHECK_LT(static_cast<int>(i), register_count_); | |
| 32 return Register(first_reg_index_ + static_cast<int>(i)); | |
| 33 } | |
| 34 | |
| 35 const Register first_register() const { | |
| 36 return (register_count() == 0) ? Register(0) : (*this)[0]; | |
| 37 } | |
| 38 | |
| 39 int register_count() const { return register_count_; } | |
| 40 | |
| 41 private: | |
| 42 int first_reg_index_; | |
| 43 int register_count_; | |
| 44 }; | |
| 45 | |
| 46 // A class that allows the allocation of contiguous temporary registers. | 16 // A class that allows the allocation of contiguous temporary registers. |
| 47 class BytecodeRegisterAllocator final { | 17 class BytecodeRegisterAllocator final { |
| 48 public: | 18 public: |
| 49 // Enables observation of register allocation and free events. | 19 // Enables observation of register allocation and free events. |
| 50 class Observer { | 20 class Observer { |
| 51 public: | 21 public: |
| 52 virtual ~Observer() {} | 22 virtual ~Observer() {} |
| 53 virtual void RegisterAllocateEvent(Register reg) = 0; | 23 virtual void RegisterAllocateEvent(Register reg) = 0; |
| 54 virtual void RegisterListAllocateEvent(RegisterList reg_list) = 0; | 24 virtual void RegisterListAllocateEvent(RegisterList reg_list) = 0; |
| 55 virtual void RegisterListFreeEvent(RegisterList reg_list) = 0; | 25 virtual void RegisterListFreeEvent(RegisterList reg_list) = 0; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 78 |
| 109 DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterAllocator); | 79 DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterAllocator); |
| 110 }; | 80 }; |
| 111 | 81 |
| 112 } // namespace interpreter | 82 } // namespace interpreter |
| 113 } // namespace internal | 83 } // namespace internal |
| 114 } // namespace v8 | 84 } // namespace v8 |
| 115 | 85 |
| 116 | 86 |
| 117 #endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ | 87 #endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |