v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bytecode-register-allocator.h
Go to the documentation of this file.
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
9
10namespace v8 {
11namespace internal {
12namespace interpreter {
13
14// A class that allows the allocation of contiguous temporary registers.
16 public:
17 // Enables observation of register allocation and free events.
18 class Observer {
19 public:
20 virtual ~Observer() = default;
22 virtual void RegisterListAllocateEvent(RegisterList reg_list) = 0;
23 virtual void RegisterListFreeEvent(RegisterList reg_list) = 0;
24 virtual void RegisterFreeEvent(Register reg_list) = 0;
25 };
26
27 explicit BytecodeRegisterAllocator(int start_index)
28 : next_register_index_(start_index),
29 max_register_count_(start_index),
30 observer_(nullptr) {}
34 delete;
35
36 // Returns a new register.
45
46 // Returns a consecutive list of |count| new registers.
56
57 // Returns a growable register list.
60 return reg_list;
61 }
62
63 // Appends a new register to |reg_list| increasing it's count by one and
64 // returning the register added.
65 //
66 // Note: no other new registers must be currently allocated since the register
67 // list was originally allocated.
70 reg_list->IncrementRegisterCount();
71 // If the following CHECK fails then a register was allocated (and not
72 // freed) between the creation of the RegisterList and this call to add a
73 // Register.
74 CHECK_EQ(reg.index(), reg_list->last_register().index());
75 return reg;
76 }
77
78 // Release all registers above |register_index|.
79 void ReleaseRegisters(int register_index) {
80 int count = next_register_index_ - register_index;
81 next_register_index_ = register_index;
82 if (observer_) {
84 }
85 }
86
87 // Release last allocated register
95
96 // Returns true if the register |reg| is a live register.
98 return reg.index() < next_register_index_;
99 }
100
101 // Returns a register list for all currently live registers.
105
106 void set_observer(Observer* observer) { observer_ = observer; }
107
110
111 private:
115};
116
117} // namespace interpreter
118} // namespace internal
119} // namespace v8
120
121
122#endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_
virtual void RegisterListFreeEvent(RegisterList reg_list)=0
virtual void RegisterListAllocateEvent(RegisterList reg_list)=0
BytecodeRegisterAllocator(const BytecodeRegisterAllocator &)=delete
BytecodeRegisterAllocator & operator=(const BytecodeRegisterAllocator &)=delete
uint32_t count
LiftoffRegister reg
#define CHECK_EQ(lhs, rhs)
#define DCHECK_EQ(v1, v2)
Definition logging.h:485