5 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_OPTIMIZER_H_ 6 #define V8_INTERPRETER_BYTECODE_REGISTER_OPTIMIZER_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/globals.h" 10 #include "src/interpreter/bytecode-register-allocator.h" 14 namespace interpreter {
21 :
public NON_EXPORTED_BASE(BytecodeRegisterAllocator::Observer),
22 public NON_EXPORTED_BASE(ZoneObject) {
30 virtual void EmitLdar(
Register input) = 0;
31 virtual void EmitStar(
Register output) = 0;
40 int fixed_registers_count,
int parameter_count,
49 RegisterTransfer(input_info, accumulator_info_);
52 RegisterInfo* output_info = GetRegisterInfo(output);
53 RegisterTransfer(accumulator_info_, output_info);
56 RegisterInfo* input_info = GetRegisterInfo(input);
57 RegisterInfo* output_info = GetRegisterInfo(output);
58 RegisterTransfer(input_info, output_info);
65 template <Bytecode bytecode, AccumulatorUse accumulator_use>
66 V8_INLINE
void PrepareForBytecode() {
67 if (Bytecodes::IsJump(bytecode) || Bytecodes::IsSwitch(bytecode) ||
68 bytecode == Bytecode::kDebugger ||
69 bytecode == Bytecode::kSuspendGenerator ||
70 bytecode == Bytecode::kResumeGenerator) {
85 if (BytecodeOperands::ReadsAccumulator(accumulator_use)) {
86 Materialize(accumulator_info_);
91 if (BytecodeOperands::WritesAccumulator(accumulator_use)) {
92 PrepareOutputRegister(accumulator_);
97 void PrepareOutputRegister(Register reg);
100 void PrepareOutputRegisterList(RegisterList reg_list);
103 Register GetInputRegister(Register reg);
107 RegisterList GetInputRegisterList(RegisterList reg_list);
109 int maxiumum_register_index()
const {
return max_register_index_; }
112 static const uint32_t kInvalidEquivalenceId;
117 void RegisterAllocateEvent(Register reg)
override;
118 void RegisterListAllocateEvent(RegisterList reg_list)
override;
119 void RegisterListFreeEvent(RegisterList reg)
override;
122 void RegisterTransfer(RegisterInfo* input, RegisterInfo* output);
125 void OutputRegisterTransfer(RegisterInfo* input, RegisterInfo* output);
127 void CreateMaterializedEquivalent(RegisterInfo* info);
128 RegisterInfo* GetMaterializedEquivalent(RegisterInfo* info);
129 RegisterInfo* GetMaterializedEquivalentNotAccumulator(RegisterInfo* info);
130 void Materialize(RegisterInfo* info);
131 void AddToEquivalenceSet(RegisterInfo* set_member,
132 RegisterInfo* non_set_member);
134 void PushToRegistersNeedingFlush(RegisterInfo* reg);
135 bool EnsureAllRegistersAreFlushed()
const;
138 RegisterInfo* GetRegisterInfo(Register reg) {
139 size_t index = GetRegisterInfoTableIndex(reg);
140 DCHECK_LT(index, register_info_table_.size());
141 return register_info_table_[index];
143 RegisterInfo* GetOrCreateRegisterInfo(Register reg) {
144 size_t index = GetRegisterInfoTableIndex(reg);
145 return index < register_info_table_.size() ? register_info_table_[index]
146 : NewRegisterInfo(reg);
148 RegisterInfo* NewRegisterInfo(Register reg) {
149 size_t index = GetRegisterInfoTableIndex(reg);
150 DCHECK_GE(index, register_info_table_.size());
151 GrowRegisterMap(reg);
152 return register_info_table_[index];
155 void GrowRegisterMap(Register reg);
157 bool RegisterIsTemporary(Register reg)
const {
158 return reg >= temporary_base_;
161 bool RegisterIsObservable(Register reg)
const {
162 return reg != accumulator_ && !RegisterIsTemporary(reg);
165 static Register OperandToRegister(
uint32_t operand) {
166 return Register::FromOperand(static_cast<int32_t>(operand));
169 size_t GetRegisterInfoTableIndex(Register reg)
const {
170 return static_cast<size_t>(reg.index() + register_info_table_offset_);
173 Register RegisterFromRegisterInfoTableIndex(
size_t index)
const {
174 return Register(static_cast<int>(index) - register_info_table_offset_);
180 CHECK_NE(static_cast<size_t>(equivalence_id_), kInvalidEquivalenceId);
181 return equivalence_id_;
184 void AllocateRegister(RegisterInfo* info);
186 Zone* zone() {
return zone_; }
188 const Register accumulator_;
189 RegisterInfo* accumulator_info_;
190 const Register temporary_base_;
191 int max_register_index_;
194 ZoneVector<RegisterInfo*> register_info_table_;
195 int register_info_table_offset_;
197 ZoneDeque<RegisterInfo*> registers_needing_flushed_;
202 BytecodeWriter* bytecode_writer_;
203 bool flush_required_;
206 DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterOptimizer);
213 #endif // V8_INTERPRETER_BYTECODE_REGISTER_OPTIMIZER_H_