V8 Project
opcodes.h
Go to the documentation of this file.
1 // Copyright 2013 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_COMPILER_OPCODES_H_
6 #define V8_COMPILER_OPCODES_H_
7 
8 // Opcodes for control operators.
9 #define INNER_CONTROL_OP_LIST(V) \
10  V(Dead) \
11  V(Loop) \
12  V(Branch) \
13  V(IfTrue) \
14  V(IfFalse) \
15  V(Merge) \
16  V(Return) \
17  V(Throw)
18 
19 #define CONTROL_OP_LIST(V) \
20  INNER_CONTROL_OP_LIST(V) \
21  V(Start) \
22  V(End)
23 
24 // Opcodes for common operators.
25 #define LEAF_OP_LIST(V) \
26  V(Int32Constant) \
27  V(Int64Constant) \
28  V(Float32Constant) \
29  V(Float64Constant) \
30  V(ExternalConstant) \
31  V(NumberConstant) \
32  V(HeapConstant)
33 
34 #define INNER_OP_LIST(V) \
35  V(Phi) \
36  V(EffectPhi) \
37  V(ControlEffect) \
38  V(ValueEffect) \
39  V(Finish) \
40  V(FrameState) \
41  V(StateValues) \
42  V(Call) \
43  V(Parameter) \
44  V(Projection)
45 
46 #define COMMON_OP_LIST(V) \
47  LEAF_OP_LIST(V) \
48  INNER_OP_LIST(V)
49 
50 // Opcodes for JavaScript operators.
51 #define JS_COMPARE_BINOP_LIST(V) \
52  V(JSEqual) \
53  V(JSNotEqual) \
54  V(JSStrictEqual) \
55  V(JSStrictNotEqual) \
56  V(JSLessThan) \
57  V(JSGreaterThan) \
58  V(JSLessThanOrEqual) \
59  V(JSGreaterThanOrEqual)
60 
61 #define JS_BITWISE_BINOP_LIST(V) \
62  V(JSBitwiseOr) \
63  V(JSBitwiseXor) \
64  V(JSBitwiseAnd) \
65  V(JSShiftLeft) \
66  V(JSShiftRight) \
67  V(JSShiftRightLogical)
68 
69 #define JS_ARITH_BINOP_LIST(V) \
70  V(JSAdd) \
71  V(JSSubtract) \
72  V(JSMultiply) \
73  V(JSDivide) \
74  V(JSModulus)
75 
76 #define JS_SIMPLE_BINOP_LIST(V) \
77  JS_COMPARE_BINOP_LIST(V) \
78  JS_BITWISE_BINOP_LIST(V) \
79  JS_ARITH_BINOP_LIST(V)
80 
81 #define JS_LOGIC_UNOP_LIST(V) V(JSUnaryNot)
82 
83 #define JS_CONVERSION_UNOP_LIST(V) \
84  V(JSToBoolean) \
85  V(JSToNumber) \
86  V(JSToString) \
87  V(JSToName) \
88  V(JSToObject)
89 
90 #define JS_OTHER_UNOP_LIST(V) \
91  V(JSTypeOf)
92 
93 #define JS_SIMPLE_UNOP_LIST(V) \
94  JS_LOGIC_UNOP_LIST(V) \
95  JS_CONVERSION_UNOP_LIST(V) \
96  JS_OTHER_UNOP_LIST(V)
97 
98 #define JS_OBJECT_OP_LIST(V) \
99  V(JSCreate) \
100  V(JSLoadProperty) \
101  V(JSLoadNamed) \
102  V(JSStoreProperty) \
103  V(JSStoreNamed) \
104  V(JSDeleteProperty) \
105  V(JSHasProperty) \
106  V(JSInstanceOf)
107 
108 #define JS_CONTEXT_OP_LIST(V) \
109  V(JSLoadContext) \
110  V(JSStoreContext) \
111  V(JSCreateFunctionContext) \
112  V(JSCreateCatchContext) \
113  V(JSCreateWithContext) \
114  V(JSCreateBlockContext) \
115  V(JSCreateModuleContext) \
116  V(JSCreateGlobalContext)
117 
118 #define JS_OTHER_OP_LIST(V) \
119  V(JSCallConstruct) \
120  V(JSCallFunction) \
121  V(JSCallRuntime) \
122  V(JSYield) \
123  V(JSDebugger)
124 
125 #define JS_OP_LIST(V) \
126  JS_SIMPLE_BINOP_LIST(V) \
127  JS_SIMPLE_UNOP_LIST(V) \
128  JS_OBJECT_OP_LIST(V) \
129  JS_CONTEXT_OP_LIST(V) \
130  JS_OTHER_OP_LIST(V)
131 
132 // Opcodes for VirtuaMachine-level operators.
133 #define SIMPLIFIED_OP_LIST(V) \
134  V(BooleanNot) \
135  V(BooleanToNumber) \
136  V(NumberEqual) \
137  V(NumberLessThan) \
138  V(NumberLessThanOrEqual) \
139  V(NumberAdd) \
140  V(NumberSubtract) \
141  V(NumberMultiply) \
142  V(NumberDivide) \
143  V(NumberModulus) \
144  V(NumberToInt32) \
145  V(NumberToUint32) \
146  V(ReferenceEqual) \
147  V(StringEqual) \
148  V(StringLessThan) \
149  V(StringLessThanOrEqual) \
150  V(StringAdd) \
151  V(ChangeTaggedToInt32) \
152  V(ChangeTaggedToUint32) \
153  V(ChangeTaggedToFloat64) \
154  V(ChangeInt32ToTagged) \
155  V(ChangeUint32ToTagged) \
156  V(ChangeFloat64ToTagged) \
157  V(ChangeBoolToBit) \
158  V(ChangeBitToBool) \
159  V(LoadField) \
160  V(LoadElement) \
161  V(StoreField) \
162  V(StoreElement)
163 
164 // Opcodes for Machine-level operators.
165 #define MACHINE_OP_LIST(V) \
166  V(Load) \
167  V(Store) \
168  V(Word32And) \
169  V(Word32Or) \
170  V(Word32Xor) \
171  V(Word32Shl) \
172  V(Word32Shr) \
173  V(Word32Sar) \
174  V(Word32Ror) \
175  V(Word32Equal) \
176  V(Word64And) \
177  V(Word64Or) \
178  V(Word64Xor) \
179  V(Word64Shl) \
180  V(Word64Shr) \
181  V(Word64Sar) \
182  V(Word64Ror) \
183  V(Word64Equal) \
184  V(Int32Add) \
185  V(Int32AddWithOverflow) \
186  V(Int32Sub) \
187  V(Int32SubWithOverflow) \
188  V(Int32Mul) \
189  V(Int32Div) \
190  V(Int32UDiv) \
191  V(Int32Mod) \
192  V(Int32UMod) \
193  V(Int32LessThan) \
194  V(Int32LessThanOrEqual) \
195  V(Uint32LessThan) \
196  V(Uint32LessThanOrEqual) \
197  V(Int64Add) \
198  V(Int64Sub) \
199  V(Int64Mul) \
200  V(Int64Div) \
201  V(Int64UDiv) \
202  V(Int64Mod) \
203  V(Int64UMod) \
204  V(Int64LessThan) \
205  V(Int64LessThanOrEqual) \
206  V(ChangeFloat32ToFloat64) \
207  V(ChangeFloat64ToInt32) \
208  V(ChangeFloat64ToUint32) \
209  V(ChangeInt32ToFloat64) \
210  V(ChangeInt32ToInt64) \
211  V(ChangeUint32ToFloat64) \
212  V(ChangeUint32ToUint64) \
213  V(TruncateFloat64ToFloat32) \
214  V(TruncateFloat64ToInt32) \
215  V(TruncateInt64ToInt32) \
216  V(Float64Add) \
217  V(Float64Sub) \
218  V(Float64Mul) \
219  V(Float64Div) \
220  V(Float64Mod) \
221  V(Float64Sqrt) \
222  V(Float64Equal) \
223  V(Float64LessThan) \
224  V(Float64LessThanOrEqual)
225 
226 #define VALUE_OP_LIST(V) \
227  COMMON_OP_LIST(V) \
228  SIMPLIFIED_OP_LIST(V) \
229  MACHINE_OP_LIST(V) \
230  JS_OP_LIST(V)
231 
232 // The combination of all operators at all levels and the common operators.
233 #define ALL_OP_LIST(V) \
234  CONTROL_OP_LIST(V) \
235  VALUE_OP_LIST(V)
236 
237 namespace v8 {
238 namespace internal {
239 namespace compiler {
240 
241 // Declare an enumeration with all the opcodes at all levels so that they
242 // can be globally, uniquely numbered.
243 class IrOpcode {
244  public:
245  enum Value {
246 #define DECLARE_OPCODE(x) k##x,
248 #undef DECLARE_OPCODE
249  kLast = -1
250 #define COUNT_OPCODE(x) +1
252 #undef COUNT_OPCODE
253  };
254 
255  // Returns the mnemonic name of an opcode.
256  static const char* Mnemonic(Value val) {
257  switch (val) {
258 #define RETURN_NAME(x) \
259  case k##x: \
260  return #x;
262 #undef RETURN_NAME
263  default:
264  return "UnknownOpcode";
265  }
266  }
267 
268  static bool IsJsOpcode(Value val) {
269  switch (val) {
270 #define RETURN_NAME(x) \
271  case k##x: \
272  return true;
274 #undef RETURN_NAME
275  default:
276  return false;
277  }
278  }
279 
280  static bool IsControlOpcode(Value val) {
281  switch (val) {
282 #define RETURN_NAME(x) \
283  case k##x: \
284  return true;
286 #undef RETURN_NAME
287  default:
288  return false;
289  }
290  }
291 
292  static bool IsCommonOpcode(Value val) {
293  switch (val) {
294 #define RETURN_NAME(x) \
295  case k##x: \
296  return true;
299 #undef RETURN_NAME
300  default:
301  return false;
302  }
303  }
304 };
305 
306 } // namespace compiler
307 } // namespace internal
308 } // namespace v8
309 
310 #endif // V8_COMPILER_OPCODES_H_
static bool IsJsOpcode(Value val)
Definition: opcodes.h:268
static bool IsControlOpcode(Value val)
Definition: opcodes.h:280
static const char * Mnemonic(Value val)
Definition: opcodes.h:256
static bool IsCommonOpcode(Value val)
Definition: opcodes.h:292
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define COUNT_OPCODE(x)
#define ALL_OP_LIST(V)
Definition: opcodes.h:233
#define RETURN_NAME(x)
#define CONTROL_OP_LIST(V)
Definition: opcodes.h:19
#define COMMON_OP_LIST(V)
Definition: opcodes.h:46
#define JS_OP_LIST(V)
Definition: opcodes.h:125
#define DECLARE_OPCODE(x)
Definition: opcodes.h:246