blob: b038d154b77e9a826248dff51eb045fabf90a19a [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include <iosfwd>
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010// Opcodes for control operators.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#define CONTROL_OP_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012 V(Start) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013 V(Loop) \
14 V(Branch) \
15 V(Switch) \
16 V(IfTrue) \
17 V(IfFalse) \
18 V(IfSuccess) \
19 V(IfException) \
20 V(IfValue) \
21 V(IfDefault) \
22 V(Merge) \
23 V(Deoptimize) \
Ben Murdochda12d292016-06-02 14:46:10 +010024 V(DeoptimizeIf) \
25 V(DeoptimizeUnless) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 V(Return) \
27 V(TailCall) \
28 V(Terminate) \
29 V(OsrNormalEntry) \
30 V(OsrLoopEntry) \
31 V(Throw) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032 V(End)
33
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034// Opcodes for constant operators.
35#define CONSTANT_OP_LIST(V) \
36 V(Int32Constant) \
37 V(Int64Constant) \
38 V(Float32Constant) \
39 V(Float64Constant) \
40 V(ExternalConstant) \
41 V(NumberConstant) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 V(HeapConstant)
43
44#define INNER_OP_LIST(V) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040045 V(Select) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046 V(Phi) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047 V(EffectSet) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048 V(EffectPhi) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 V(Guard) \
50 V(BeginRegion) \
51 V(FinishRegion) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052 V(FrameState) \
53 V(StateValues) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054 V(TypedStateValues) \
55 V(ObjectState) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 V(Call) \
57 V(Parameter) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 V(OsrValue) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 V(Projection)
60
61#define COMMON_OP_LIST(V) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000062 CONSTANT_OP_LIST(V) \
63 INNER_OP_LIST(V) \
64 V(Dead)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065
66// Opcodes for JavaScript operators.
67#define JS_COMPARE_BINOP_LIST(V) \
68 V(JSEqual) \
69 V(JSNotEqual) \
70 V(JSStrictEqual) \
71 V(JSStrictNotEqual) \
72 V(JSLessThan) \
73 V(JSGreaterThan) \
74 V(JSLessThanOrEqual) \
75 V(JSGreaterThanOrEqual)
76
77#define JS_BITWISE_BINOP_LIST(V) \
78 V(JSBitwiseOr) \
79 V(JSBitwiseXor) \
80 V(JSBitwiseAnd) \
81 V(JSShiftLeft) \
82 V(JSShiftRight) \
83 V(JSShiftRightLogical)
84
85#define JS_ARITH_BINOP_LIST(V) \
86 V(JSAdd) \
87 V(JSSubtract) \
88 V(JSMultiply) \
89 V(JSDivide) \
90 V(JSModulus)
91
92#define JS_SIMPLE_BINOP_LIST(V) \
93 JS_COMPARE_BINOP_LIST(V) \
94 JS_BITWISE_BINOP_LIST(V) \
95 JS_ARITH_BINOP_LIST(V)
96
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097#define JS_CONVERSION_UNOP_LIST(V) \
98 V(JSToBoolean) \
Ben Murdochda12d292016-06-02 14:46:10 +010099 V(JSToInteger) \
100 V(JSToLength) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 V(JSToName) \
Ben Murdochda12d292016-06-02 14:46:10 +0100102 V(JSToNumber) \
103 V(JSToObject) \
104 V(JSToString)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105
106#define JS_OTHER_UNOP_LIST(V) \
107 V(JSTypeOf)
108
109#define JS_SIMPLE_UNOP_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000110 JS_CONVERSION_UNOP_LIST(V) \
111 JS_OTHER_UNOP_LIST(V)
112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113#define JS_OBJECT_OP_LIST(V) \
114 V(JSCreate) \
115 V(JSCreateArguments) \
116 V(JSCreateArray) \
117 V(JSCreateClosure) \
118 V(JSCreateIterResultObject) \
119 V(JSCreateLiteralArray) \
120 V(JSCreateLiteralObject) \
121 V(JSCreateLiteralRegExp) \
122 V(JSLoadProperty) \
123 V(JSLoadNamed) \
124 V(JSLoadGlobal) \
125 V(JSStoreProperty) \
126 V(JSStoreNamed) \
127 V(JSStoreGlobal) \
128 V(JSDeleteProperty) \
129 V(JSHasProperty) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130 V(JSInstanceOf)
131
132#define JS_CONTEXT_OP_LIST(V) \
133 V(JSLoadContext) \
134 V(JSStoreContext) \
135 V(JSCreateFunctionContext) \
136 V(JSCreateCatchContext) \
137 V(JSCreateWithContext) \
138 V(JSCreateBlockContext) \
139 V(JSCreateModuleContext) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400140 V(JSCreateScriptContext)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141
142#define JS_OTHER_OP_LIST(V) \
143 V(JSCallConstruct) \
144 V(JSCallFunction) \
145 V(JSCallRuntime) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000146 V(JSConvertReceiver) \
147 V(JSForInDone) \
148 V(JSForInNext) \
149 V(JSForInPrepare) \
150 V(JSForInStep) \
151 V(JSLoadMessage) \
152 V(JSStoreMessage) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000153 V(JSYield) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000154 V(JSStackCheck)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000155
156#define JS_OP_LIST(V) \
157 JS_SIMPLE_BINOP_LIST(V) \
158 JS_SIMPLE_UNOP_LIST(V) \
159 JS_OBJECT_OP_LIST(V) \
160 JS_CONTEXT_OP_LIST(V) \
161 JS_OTHER_OP_LIST(V)
162
163// Opcodes for VirtuaMachine-level operators.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000164#define SIMPLIFIED_COMPARE_BINOP_LIST(V) \
165 V(NumberEqual) \
166 V(NumberLessThan) \
167 V(NumberLessThanOrEqual) \
168 V(ReferenceEqual) \
169 V(StringEqual) \
170 V(StringLessThan) \
171 V(StringLessThanOrEqual)
172
173#define SIMPLIFIED_OP_LIST(V) \
174 SIMPLIFIED_COMPARE_BINOP_LIST(V) \
175 V(BooleanNot) \
176 V(BooleanToNumber) \
177 V(NumberAdd) \
178 V(NumberSubtract) \
179 V(NumberMultiply) \
180 V(NumberDivide) \
181 V(NumberModulus) \
182 V(NumberBitwiseOr) \
183 V(NumberBitwiseXor) \
184 V(NumberBitwiseAnd) \
185 V(NumberShiftLeft) \
186 V(NumberShiftRight) \
187 V(NumberShiftRightLogical) \
Ben Murdochda12d292016-06-02 14:46:10 +0100188 V(NumberImul) \
189 V(NumberClz32) \
190 V(NumberCeil) \
191 V(NumberFloor) \
192 V(NumberRound) \
193 V(NumberTrunc) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000194 V(NumberToInt32) \
195 V(NumberToUint32) \
196 V(NumberIsHoleNaN) \
197 V(PlainPrimitiveToNumber) \
Ben Murdochda12d292016-06-02 14:46:10 +0100198 V(StringToNumber) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000199 V(ChangeTaggedToInt32) \
200 V(ChangeTaggedToUint32) \
201 V(ChangeTaggedToFloat64) \
202 V(ChangeInt32ToTagged) \
203 V(ChangeUint32ToTagged) \
204 V(ChangeFloat64ToTagged) \
205 V(ChangeBoolToBit) \
206 V(ChangeBitToBool) \
207 V(Allocate) \
208 V(LoadField) \
209 V(LoadBuffer) \
210 V(LoadElement) \
211 V(StoreField) \
212 V(StoreBuffer) \
213 V(StoreElement) \
214 V(ObjectIsNumber) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100215 V(ObjectIsReceiver) \
Ben Murdochda12d292016-06-02 14:46:10 +0100216 V(ObjectIsSmi) \
217 V(ObjectIsUndetectable)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218
219// Opcodes for Machine-level operators.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000220#define MACHINE_COMPARE_BINOP_LIST(V) \
221 V(Word32Equal) \
222 V(Word64Equal) \
223 V(Int32LessThan) \
224 V(Int32LessThanOrEqual) \
225 V(Uint32LessThan) \
226 V(Uint32LessThanOrEqual) \
227 V(Int64LessThan) \
228 V(Int64LessThanOrEqual) \
229 V(Uint64LessThan) \
230 V(Uint64LessThanOrEqual) \
231 V(Float32Equal) \
232 V(Float32LessThan) \
233 V(Float32LessThanOrEqual) \
234 V(Float64Equal) \
235 V(Float64LessThan) \
236 V(Float64LessThanOrEqual)
237
238#define MACHINE_OP_LIST(V) \
239 MACHINE_COMPARE_BINOP_LIST(V) \
240 V(Load) \
241 V(Store) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100242 V(StackSlot) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000243 V(Word32And) \
244 V(Word32Or) \
245 V(Word32Xor) \
246 V(Word32Shl) \
247 V(Word32Shr) \
248 V(Word32Sar) \
249 V(Word32Ror) \
250 V(Word32Clz) \
251 V(Word32Ctz) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100252 V(Word32ReverseBits) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000253 V(Word32Popcnt) \
254 V(Word64Popcnt) \
255 V(Word64And) \
256 V(Word64Or) \
257 V(Word64Xor) \
258 V(Word64Shl) \
259 V(Word64Shr) \
260 V(Word64Sar) \
261 V(Word64Ror) \
262 V(Word64Clz) \
263 V(Word64Ctz) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100264 V(Word64ReverseBits) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000265 V(Int32Add) \
266 V(Int32AddWithOverflow) \
267 V(Int32Sub) \
268 V(Int32SubWithOverflow) \
269 V(Int32Mul) \
270 V(Int32MulHigh) \
271 V(Int32Div) \
272 V(Int32Mod) \
273 V(Uint32Div) \
274 V(Uint32Mod) \
275 V(Uint32MulHigh) \
276 V(Int64Add) \
277 V(Int64AddWithOverflow) \
278 V(Int64Sub) \
279 V(Int64SubWithOverflow) \
280 V(Int64Mul) \
281 V(Int64Div) \
282 V(Int64Mod) \
283 V(Uint64Div) \
284 V(Uint64Mod) \
285 V(ChangeFloat32ToFloat64) \
286 V(ChangeFloat64ToInt32) \
287 V(ChangeFloat64ToUint32) \
Ben Murdochda12d292016-06-02 14:46:10 +0100288 V(TruncateFloat64ToUint32) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100289 V(TruncateFloat32ToInt32) \
290 V(TruncateFloat32ToUint32) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000291 V(TryTruncateFloat32ToInt64) \
292 V(TryTruncateFloat64ToInt64) \
293 V(TryTruncateFloat32ToUint64) \
294 V(TryTruncateFloat64ToUint64) \
295 V(ChangeInt32ToFloat64) \
296 V(ChangeInt32ToInt64) \
297 V(ChangeUint32ToFloat64) \
298 V(ChangeUint32ToUint64) \
299 V(TruncateFloat64ToFloat32) \
300 V(TruncateFloat64ToInt32) \
301 V(TruncateInt64ToInt32) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100302 V(RoundInt32ToFloat32) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000303 V(RoundInt64ToFloat32) \
304 V(RoundInt64ToFloat64) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100305 V(RoundUint32ToFloat32) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000306 V(RoundUint64ToFloat32) \
307 V(RoundUint64ToFloat64) \
308 V(BitcastFloat32ToInt32) \
309 V(BitcastFloat64ToInt64) \
310 V(BitcastInt32ToFloat32) \
311 V(BitcastInt64ToFloat64) \
312 V(Float32Add) \
313 V(Float32Sub) \
314 V(Float32Mul) \
315 V(Float32Div) \
316 V(Float32Max) \
317 V(Float32Min) \
318 V(Float32Abs) \
319 V(Float32Sqrt) \
320 V(Float32RoundDown) \
321 V(Float64Add) \
322 V(Float64Sub) \
323 V(Float64Mul) \
324 V(Float64Div) \
325 V(Float64Mod) \
326 V(Float64Max) \
327 V(Float64Min) \
328 V(Float64Abs) \
329 V(Float64Sqrt) \
330 V(Float64RoundDown) \
331 V(Float32RoundUp) \
332 V(Float64RoundUp) \
333 V(Float32RoundTruncate) \
334 V(Float64RoundTruncate) \
335 V(Float64RoundTiesAway) \
336 V(Float32RoundTiesEven) \
337 V(Float64RoundTiesEven) \
338 V(Float64ExtractLowWord32) \
339 V(Float64ExtractHighWord32) \
340 V(Float64InsertLowWord32) \
341 V(Float64InsertHighWord32) \
342 V(LoadStackPointer) \
343 V(LoadFramePointer) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100344 V(LoadParentFramePointer) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000345 V(CheckedLoad) \
Ben Murdochda12d292016-06-02 14:46:10 +0100346 V(CheckedStore) \
347 V(Int32PairAdd) \
348 V(Int32PairSub) \
349 V(Int32PairMul) \
350 V(Word32PairShl) \
351 V(Word32PairShr) \
352 V(Word32PairSar)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000353
354#define VALUE_OP_LIST(V) \
355 COMMON_OP_LIST(V) \
356 SIMPLIFIED_OP_LIST(V) \
357 MACHINE_OP_LIST(V) \
358 JS_OP_LIST(V)
359
360// The combination of all operators at all levels and the common operators.
361#define ALL_OP_LIST(V) \
362 CONTROL_OP_LIST(V) \
363 VALUE_OP_LIST(V)
364
365namespace v8 {
366namespace internal {
367namespace compiler {
368
369// Declare an enumeration with all the opcodes at all levels so that they
370// can be globally, uniquely numbered.
371class IrOpcode {
372 public:
373 enum Value {
374#define DECLARE_OPCODE(x) k##x,
375 ALL_OP_LIST(DECLARE_OPCODE)
376#undef DECLARE_OPCODE
377 kLast = -1
378#define COUNT_OPCODE(x) +1
379 ALL_OP_LIST(COUNT_OPCODE)
380#undef COUNT_OPCODE
381 };
382
383 // Returns the mnemonic name of an opcode.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400384 static char const* Mnemonic(Value value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000385
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000386 // Returns true if opcode for common operator.
387 static bool IsCommonOpcode(Value value) {
388 return kStart <= value && value <= kDead;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000389 }
390
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000391 // Returns true if opcode for control operator.
392 static bool IsControlOpcode(Value value) {
393 return kStart <= value && value <= kEnd;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000394 }
395
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000396 // Returns true if opcode for JavaScript operator.
397 static bool IsJsOpcode(Value value) {
398 return kJSEqual <= value && value <= kJSStackCheck;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400399 }
400
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000401 // Returns true if opcode for constant operator.
402 static bool IsConstantOpcode(Value value) {
403 return kInt32Constant <= value && value <= kHeapConstant;
404 }
405
406 static bool IsPhiOpcode(Value value) {
407 return value == kPhi || value == kEffectPhi;
408 }
409
410 static bool IsMergeOpcode(Value value) {
411 return value == kMerge || value == kLoop;
412 }
413
414 static bool IsIfProjectionOpcode(Value value) {
415 return kIfTrue <= value && value <= kIfDefault;
416 }
417
418 // Returns true if opcode can be inlined.
419 static bool IsInlineeOpcode(Value value) {
420 return value == kJSCallConstruct || value == kJSCallFunction;
421 }
422
423 // Returns true if opcode for comparison operator.
424 static bool IsComparisonOpcode(Value value) {
425 return (kJSEqual <= value && value <= kJSGreaterThanOrEqual) ||
426 (kNumberEqual <= value && value <= kStringLessThanOrEqual) ||
427 (kWord32Equal <= value && value <= kFloat64LessThanOrEqual);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000428 }
429};
430
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000431std::ostream& operator<<(std::ostream&, IrOpcode::Value);
432
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000433} // namespace compiler
434} // namespace internal
435} // namespace v8
436
437#endif // V8_COMPILER_OPCODES_H_