Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ |
| 6 | #define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ |
| 7 | |
| 8 | #include "src/zone-containers.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | namespace interpreter { |
| 13 | |
| 14 | class BytecodeArrayBuilder; |
| 15 | class Register; |
| 16 | |
| 17 | // A class than allows the instantiator to allocate temporary registers that are |
| 18 | // cleaned up when scope is closed. |
| 19 | class BytecodeRegisterAllocator { |
| 20 | public: |
| 21 | explicit BytecodeRegisterAllocator(BytecodeArrayBuilder* builder); |
| 22 | ~BytecodeRegisterAllocator(); |
| 23 | Register NewRegister(); |
| 24 | |
| 25 | void PrepareForConsecutiveAllocations(size_t count); |
| 26 | Register NextConsecutiveRegister(); |
| 27 | |
| 28 | bool RegisterIsAllocatedInThisScope(Register reg) const; |
| 29 | |
| 30 | bool HasConsecutiveAllocations() const { return next_consecutive_count_ > 0; } |
| 31 | |
| 32 | private: |
| 33 | void* operator new(size_t size); |
| 34 | void operator delete(void* p); |
| 35 | |
| 36 | BytecodeArrayBuilder* builder_; |
| 37 | ZoneVector<int> allocated_; |
| 38 | int next_consecutive_register_; |
| 39 | int next_consecutive_count_; |
| 40 | |
| 41 | DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterAllocator); |
| 42 | }; |
| 43 | |
| 44 | } // namespace interpreter |
| 45 | } // namespace internal |
| 46 | } // namespace v8 |
| 47 | |
| 48 | |
| 49 | #endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ |