5 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ 6 #define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ 8 #include "src/interpreter/bytecode-register.h" 9 #include "src/interpreter/bytecodes.h" 10 #include "src/zone/zone-containers.h" 14 namespace interpreter {
23 virtual void RegisterAllocateEvent(
Register reg) = 0;
24 virtual void RegisterListAllocateEvent(
RegisterList reg_list) = 0;
25 virtual void RegisterListFreeEvent(
RegisterList reg_list) = 0;
29 : next_register_index_(start_index),
30 max_register_count_(start_index),
36 Register reg(next_register_index_++);
37 max_register_count_ = std::max(next_register_index_, max_register_count_);
39 observer_->RegisterAllocateEvent(reg);
45 RegisterList NewRegisterList(
int count) {
46 RegisterList reg_list(next_register_index_, count);
47 next_register_index_ += count;
48 max_register_count_ = std::max(next_register_index_, max_register_count_);
50 observer_->RegisterListAllocateEvent(reg_list);
56 RegisterList NewGrowableRegisterList() {
57 RegisterList reg_list(next_register_index_, 0);
66 Register GrowRegisterList(RegisterList* reg_list) {
67 Register reg(NewRegister());
68 reg_list->IncrementRegisterCount();
72 CHECK_EQ(reg.index(), reg_list->last_register().index());
77 void ReleaseRegisters(
int register_index) {
78 int count = next_register_index_ - register_index;
79 next_register_index_ = register_index;
81 observer_->RegisterListFreeEvent(RegisterList(register_index, count));
86 bool RegisterIsLive(Register reg)
const {
87 return reg.index() < next_register_index_;
91 RegisterList AllLiveRegisters()
const {
92 return RegisterList(0, next_register_index());
95 void set_observer(Observer* observer) { observer_ = observer; }
97 int next_register_index()
const {
return next_register_index_; }
98 int maximum_register_count()
const {
return max_register_count_; }
101 int next_register_index_;
102 int max_register_count_;
105 DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterAllocator);
113 #endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_