v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
bytecode-node.h
Go to the documentation of this file.
1// Copyright 2017 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_NODE_H_
6#define V8_INTERPRETER_BYTECODE_NODE_H_
7
8#include <algorithm>
9
12
13namespace v8 {
14namespace internal {
15namespace interpreter {
16
17// A container for a generated bytecode, it's operands, and source information.
19 public:
22 : bytecode_(bytecode),
23 operand_count_(0),
24 operand_scale_(OperandScale::kSingle),
25 source_info_(source_info) {
26 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
27 }
28
29 V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0,
31 : bytecode_(bytecode),
32 operand_count_(1),
33 operand_scale_(OperandScale::kSingle),
34 source_info_(source_info) {
35 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
36 SetOperand(0, operand0);
37 }
38
39 V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0,
40 uint32_t operand1,
42 : bytecode_(bytecode),
43 operand_count_(2),
44 operand_scale_(OperandScale::kSingle),
45 source_info_(source_info) {
46 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
47 SetOperand(0, operand0);
48 SetOperand(1, operand1);
49 }
50
51 V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0,
52 uint32_t operand1, uint32_t operand2,
54 : bytecode_(bytecode),
55 operand_count_(3),
56 operand_scale_(OperandScale::kSingle),
57 source_info_(source_info) {
58 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
59 SetOperand(0, operand0);
60 SetOperand(1, operand1);
61 SetOperand(2, operand2);
62 }
63
64 V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0,
65 uint32_t operand1, uint32_t operand2,
66 uint32_t operand3,
68 : bytecode_(bytecode),
69 operand_count_(4),
70 operand_scale_(OperandScale::kSingle),
71 source_info_(source_info) {
72 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
73 SetOperand(0, operand0);
74 SetOperand(1, operand1);
75 SetOperand(2, operand2);
76 SetOperand(3, operand3);
77 }
78
79 V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0,
80 uint32_t operand1, uint32_t operand2,
81 uint32_t operand3, uint32_t operand4,
83 : bytecode_(bytecode),
84 operand_count_(5),
85 operand_scale_(OperandScale::kSingle),
86 source_info_(source_info) {
87 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
88 SetOperand(0, operand0);
89 SetOperand(1, operand1);
90 SetOperand(2, operand2);
91 SetOperand(3, operand3);
92 SetOperand(4, operand4);
93 }
94
95#define DEFINE_BYTECODE_NODE_CREATOR(Name, ...) \
96 template <typename... Operands> \
97 V8_INLINE static BytecodeNode Name(BytecodeSourceInfo source_info, \
98 Operands... operands) { \
99 return Create<Bytecode::k##Name, __VA_ARGS__>(source_info, operands...); \
100 }
102#undef DEFINE_BYTECODE_NODE_CREATOR
103
104 // Print to stream |os|.
105 void Print(std::ostream& os) const;
106
107 Bytecode bytecode() const { return bytecode_; }
108
109 uint32_t operand(int i) const {
110 DCHECK_LT(i, operand_count());
111 return operands_[i];
112 }
113 const uint32_t* operands() const { return operands_; }
114
115 void update_operand0(uint32_t operand0) { SetOperand(0, operand0); }
116
117 int operand_count() const { return operand_count_; }
118 OperandScale operand_scale() const { return operand_scale_; }
119
120 const BytecodeSourceInfo& source_info() const { return source_info_; }
122 source_info_ = source_info;
123 }
124
125 bool operator==(const BytecodeNode& other) const;
126 bool operator!=(const BytecodeNode& other) const { return !(*this == other); }
127
128 private:
129 template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use,
130 OperandType... operand_types>
132
133 V8_INLINE BytecodeNode(Bytecode bytecode, int operand_count,
134 OperandScale operand_scale,
135 BytecodeSourceInfo source_info, uint32_t operand0 = 0,
136 uint32_t operand1 = 0, uint32_t operand2 = 0,
137 uint32_t operand3 = 0, uint32_t operand4 = 0)
138 : bytecode_(bytecode),
139 operand_count_(operand_count),
140 operand_scale_(operand_scale),
141 source_info_(source_info) {
142 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count);
143 operands_[0] = operand0;
144 operands_[1] = operand1;
145 operands_[2] = operand2;
146 operands_[3] = operand3;
147 operands_[4] = operand4;
148 }
149
150 template <Bytecode bytecode, ImplicitRegisterUse accum_use>
152 return BytecodeNode(bytecode, 0, OperandScale::kSingle, source_info);
153 }
154
155 template <Bytecode bytecode, ImplicitRegisterUse accum_use,
156 OperandType operand0_type>
158 uint32_t operand0) {
159 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type);
160 OperandScale scale = OperandScale::kSingle;
161 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
162 return BytecodeNode(bytecode, 1, scale, source_info, operand0);
163 }
164
165 template <Bytecode bytecode, ImplicitRegisterUse accum_use,
166 OperandType operand0_type, OperandType operand1_type>
168 uint32_t operand0, uint32_t operand1) {
169 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type);
170 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type);
171 OperandScale scale = OperandScale::kSingle;
172 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
173 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
174 return BytecodeNode(bytecode, 2, scale, source_info, operand0, operand1);
175 }
176
177 template <Bytecode bytecode, ImplicitRegisterUse accum_use,
178 OperandType operand0_type, OperandType operand1_type,
179 OperandType operand2_type>
181 uint32_t operand0, uint32_t operand1,
182 uint32_t operand2) {
183 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type);
184 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type);
185 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 2), operand2_type);
186 OperandScale scale = OperandScale::kSingle;
187 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
188 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
189 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
190 return BytecodeNode(bytecode, 3, scale, source_info, operand0, operand1,
191 operand2);
192 }
193
194 template <Bytecode bytecode, ImplicitRegisterUse accum_use,
195 OperandType operand0_type, OperandType operand1_type,
196 OperandType operand2_type, OperandType operand3_type>
198 uint32_t operand0, uint32_t operand1,
199 uint32_t operand2, uint32_t operand3) {
200 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type);
201 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type);
202 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 2), operand2_type);
203 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 3), operand3_type);
204 OperandScale scale = OperandScale::kSingle;
205 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
206 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
207 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
208 scale = std::max(scale, ScaleForOperand<operand3_type>(operand3));
209 return BytecodeNode(bytecode, 4, scale, source_info, operand0, operand1,
210 operand2, operand3);
211 }
212
213 template <Bytecode bytecode, ImplicitRegisterUse accum_use,
214 OperandType operand0_type, OperandType operand1_type,
215 OperandType operand2_type, OperandType operand3_type,
216 OperandType operand4_type>
218 uint32_t operand0, uint32_t operand1,
219 uint32_t operand2, uint32_t operand3,
220 uint32_t operand4) {
221 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 0), operand0_type);
222 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 1), operand1_type);
223 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 2), operand2_type);
224 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 3), operand3_type);
225 DCHECK_EQ(Bytecodes::GetOperandType(bytecode, 4), operand4_type);
226 OperandScale scale = OperandScale::kSingle;
227 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
228 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
229 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
230 scale = std::max(scale, ScaleForOperand<operand3_type>(operand3));
231 scale = std::max(scale, ScaleForOperand<operand4_type>(operand4));
232 return BytecodeNode(bytecode, 5, scale, source_info, operand0, operand1,
233 operand2, operand3, operand4);
234 }
235
236 template <OperandType operand_type>
237 V8_INLINE static OperandScale ScaleForOperand(uint32_t operand) {
238 if (BytecodeOperands::IsScalableUnsignedByte(operand_type)) {
239 return Bytecodes::ScaleForUnsignedOperand(operand);
240 } else if (BytecodeOperands::IsScalableSignedByte(operand_type)) {
241 return Bytecodes::ScaleForSignedOperand(operand);
242 } else {
243 return OperandScale::kSingle;
244 }
245 }
246
247 V8_INLINE void UpdateScaleForOperand(int operand_index, uint32_t operand) {
248 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) {
249 operand_scale_ =
250 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand));
251 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(),
252 operand_index)) {
253 operand_scale_ =
254 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand));
255 }
256 }
257
258 V8_INLINE void SetOperand(int operand_index, uint32_t operand) {
259 operands_[operand_index] = operand;
260 UpdateScaleForOperand(operand_index, operand);
261 }
262
264 uint32_t operands_[Bytecodes::kMaxOperands];
268};
269
270V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
271 const BytecodeNode& node);
272
273} // namespace interpreter
274} // namespace internal
275} // namespace v8
276
277#endif // V8_INTERPRETER_BYTECODE_NODE_H_
interpreter::Bytecode bytecode
Definition builtins.cc:43
interpreter::OperandScale scale
Definition builtins.cc:44
#define DEFINE_BYTECODE_NODE_CREATOR(Name,...)
#define BYTECODE_LIST(V, V_TSA)
Definition bytecodes.h:479
V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, uint32_t operand2, uint32_t operand3, BytecodeSourceInfo source_info=BytecodeSourceInfo())
V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, BytecodeSourceInfo source_info=BytecodeSourceInfo())
void update_operand0(uint32_t operand0)
static V8_INLINE OperandScale ScaleForOperand(uint32_t operand)
static V8_INLINE BytecodeNode Create(BytecodeSourceInfo source_info, uint32_t operand0, uint32_t operand1)
static V8_INLINE BytecodeNode Create(BytecodeSourceInfo source_info, uint32_t operand0)
static V8_INLINE BytecodeNode Create(BytecodeSourceInfo source_info, uint32_t operand0, uint32_t operand1, uint32_t operand2, uint32_t operand3)
V8_INLINE BytecodeNode(Bytecode bytecode, int operand_count, OperandScale operand_scale, BytecodeSourceInfo source_info, uint32_t operand0=0, uint32_t operand1=0, uint32_t operand2=0, uint32_t operand3=0, uint32_t operand4=0)
V8_INLINE void SetOperand(int operand_index, uint32_t operand)
V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, uint32_t operand2, BytecodeSourceInfo source_info=BytecodeSourceInfo())
const BytecodeSourceInfo & source_info() const
void set_source_info(BytecodeSourceInfo source_info)
static V8_INLINE BytecodeNode Create(BytecodeSourceInfo source_info, uint32_t operand0, uint32_t operand1, uint32_t operand2, uint32_t operand3, uint32_t operand4)
V8_INLINE void UpdateScaleForOperand(int operand_index, uint32_t operand)
V8_INLINE BytecodeNode(Bytecode bytecode, BytecodeSourceInfo source_info=BytecodeSourceInfo())
bool operator!=(const BytecodeNode &other) const
V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0, BytecodeSourceInfo source_info=BytecodeSourceInfo())
static V8_INLINE BytecodeNode Create(BytecodeSourceInfo source_info, uint32_t operand0, uint32_t operand1, uint32_t operand2)
static V8_INLINE BytecodeNode Create(BytecodeSourceInfo source_info)
V8_INLINE BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, uint32_t operand2, uint32_t operand3, uint32_t operand4, BytecodeSourceInfo source_info=BytecodeSourceInfo())
base::Vector< const RegExpInstruction > bytecode_
std::ostream & operator<<(std::ostream &os, PaddingSpace padding)
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_INLINE
Definition v8config.h:500