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 #include <iosfwd>
9 
10 #include "src/common/globals.h"
11 
12 // Opcodes for control operators.
13 #define CONTROL_OP_LIST(V)           \
14   V(Start)                           \
15   V(Loop)                            \
16   V(Branch)                          \
17   V(Switch)                          \
18   V(IfTrue)                          \
19   V(IfFalse)                         \
20   V(IfSuccess)                       \
21   V(IfException)                     \
22   V(IfValue)                         \
23   V(IfDefault)                       \
24   V(Merge)                           \
25   V(Deoptimize)                      \
26   V(DeoptimizeIf)                    \
27   V(DeoptimizeUnless)                \
28   V(DynamicCheckMapsWithDeoptUnless) \
29   V(TrapIf)                          \
30   V(TrapUnless)                      \
31   V(Return)                          \
32   V(TailCall)                        \
33   V(Terminate)                       \
34   V(Throw)                           \
35   V(End)
36 
37 // Opcodes for constant operators.
38 #define CONSTANT_OP_LIST(V)   \
39   V(Int32Constant)            \
40   V(Int64Constant)            \
41   V(TaggedIndexConstant)      \
42   V(Float32Constant)          \
43   V(Float64Constant)          \
44   V(ExternalConstant)         \
45   V(NumberConstant)           \
46   V(PointerConstant)          \
47   V(HeapConstant)             \
48   V(CompressedHeapConstant)   \
49   V(RelocatableInt32Constant) \
50   V(RelocatableInt64Constant)
51 
52 #define INNER_OP_LIST(V)    \
53   V(Select)                 \
54   V(Phi)                    \
55   V(EffectPhi)              \
56   V(InductionVariablePhi)   \
57   V(Checkpoint)             \
58   V(BeginRegion)            \
59   V(FinishRegion)           \
60   V(FrameState)             \
61   V(StateValues)            \
62   V(TypedStateValues)       \
63   V(ArgumentsElementsState) \
64   V(ArgumentsLengthState)   \
65   V(ObjectState)            \
66   V(ObjectId)               \
67   V(TypedObjectState)       \
68   V(Call)                   \
69   V(Parameter)              \
70   V(OsrValue)               \
71   V(LoopExit)               \
72   V(LoopExitValue)          \
73   V(LoopExitEffect)         \
74   V(Projection)             \
75   V(Retain)                 \
76   V(MapGuard)               \
77   V(FoldConstant)           \
78   V(TypeGuard)
79 
80 #define COMMON_OP_LIST(V) \
81   CONSTANT_OP_LIST(V)     \
82   INNER_OP_LIST(V)        \
83   V(Unreachable)          \
84   V(DeadValue)            \
85   V(Dead)                 \
86   V(Plug)                 \
87   V(StaticAssert)
88 
89 // Opcodes for JavaScript operators.
90 // Arguments are JSName (the name with a 'JS' prefix), and Name.
91 #define JS_COMPARE_BINOP_LIST(V)        \
92   V(JSEqual, Equal)                     \
93   V(JSStrictEqual, StrictEqual)         \
94   V(JSLessThan, LessThan)               \
95   V(JSGreaterThan, GreaterThan)         \
96   V(JSLessThanOrEqual, LessThanOrEqual) \
97   V(JSGreaterThanOrEqual, GreaterThanOrEqual)
98 
99 #define JS_BITWISE_BINOP_LIST(V) \
100   V(JSBitwiseOr, BitwiseOr)      \
101   V(JSBitwiseXor, BitwiseXor)    \
102   V(JSBitwiseAnd, BitwiseAnd)    \
103   V(JSShiftLeft, ShiftLeft)      \
104   V(JSShiftRight, ShiftRight)    \
105   V(JSShiftRightLogical, ShiftRightLogical)
106 
107 #define JS_ARITH_BINOP_LIST(V) \
108   V(JSAdd, Add)                \
109   V(JSSubtract, Subtract)      \
110   V(JSMultiply, Multiply)      \
111   V(JSDivide, Divide)          \
112   V(JSModulus, Modulus)        \
113   V(JSExponentiate, Exponentiate)
114 
115 #define JS_SIMPLE_BINOP_LIST(V) \
116   JS_COMPARE_BINOP_LIST(V)      \
117   JS_BITWISE_BINOP_LIST(V)      \
118   JS_ARITH_BINOP_LIST(V)        \
119   V(JSHasInPrototypeChain)      \
120   V(JSInstanceOf)               \
121   V(JSOrdinaryHasInstance)
122 
123 #define JS_CONVERSION_UNOP_LIST(V) \
124   V(JSToLength)                    \
125   V(JSToName)                      \
126   V(JSToNumber)                    \
127   V(JSToNumberConvertBigInt)       \
128   V(JSToNumeric)                   \
129   V(JSToObject)                    \
130   V(JSToString)                    \
131   V(JSParseInt)
132 
133 #define JS_BITWISE_UNOP_LIST(V) \
134   V(JSBitwiseNot, BitwiseNot)   \
135   V(JSNegate, Negate)
136 
137 #define JS_ARITH_UNOP_LIST(V) \
138   V(JSDecrement, Decrement)   \
139   V(JSIncrement, Increment)
140 
141 #define JS_SIMPLE_UNOP_LIST(V) \
142   JS_ARITH_UNOP_LIST(V)        \
143   JS_BITWISE_UNOP_LIST(V)      \
144   JS_CONVERSION_UNOP_LIST(V)
145 
146 #define JS_CREATE_OP_LIST(V)     \
147   V(JSCloneObject)               \
148   V(JSCreate)                    \
149   V(JSCreateArguments)           \
150   V(JSCreateArray)               \
151   V(JSCreateArrayFromIterable)   \
152   V(JSCreateArrayIterator)       \
153   V(JSCreateAsyncFunctionObject) \
154   V(JSCreateBoundFunction)       \
155   V(JSCreateClosure)             \
156   V(JSCreateCollectionIterator)  \
157   V(JSCreateEmptyLiteralArray)   \
158   V(JSCreateEmptyLiteralObject)  \
159   V(JSCreateGeneratorObject)     \
160   V(JSCreateIterResultObject)    \
161   V(JSCreateKeyValueArray)       \
162   V(JSCreateLiteralArray)        \
163   V(JSCreateLiteralObject)       \
164   V(JSCreateLiteralRegExp)       \
165   V(JSCreateObject)              \
166   V(JSCreatePromise)             \
167   V(JSCreateStringIterator)      \
168   V(JSCreateTypedArray)          \
169   V(JSGetTemplateObject)
170 
171 #define JS_OBJECT_OP_LIST(V)      \
172   JS_CREATE_OP_LIST(V)            \
173   V(JSLoadProperty)               \
174   V(JSLoadNamed)                  \
175   V(JSLoadNamedFromSuper)         \
176   V(JSLoadGlobal)                 \
177   V(JSStoreProperty)              \
178   V(JSStoreNamed)                 \
179   V(JSStoreNamedOwn)              \
180   V(JSStoreGlobal)                \
181   V(JSStoreDataPropertyInLiteral) \
182   V(JSStoreInArrayLiteral)        \
183   V(JSDeleteProperty)             \
184   V(JSHasProperty)                \
185   V(JSGetSuperConstructor)
186 
187 #define JS_CONTEXT_OP_LIST(V) \
188   V(JSHasContextExtension)    \
189   V(JSLoadContext)            \
190   V(JSStoreContext)           \
191   V(JSCreateFunctionContext)  \
192   V(JSCreateCatchContext)     \
193   V(JSCreateWithContext)      \
194   V(JSCreateBlockContext)
195 
196 #define JS_CALL_OP_LIST(V) \
197   V(JSCall)                \
198   V(JSCallForwardVarargs)  \
199   V(JSCallWithArrayLike)   \
200   V(JSCallWithSpread)      \
201   IF_WASM(V, JSWasmCall)
202 
203 #define JS_CONSTRUCT_OP_LIST(V) \
204   V(JSConstructForwardVarargs)  \
205   V(JSConstruct)                \
206   V(JSConstructWithArrayLike)   \
207   V(JSConstructWithSpread)
208 
209 #define JS_OTHER_OP_LIST(V)            \
210   JS_CALL_OP_LIST(V)                   \
211   JS_CONSTRUCT_OP_LIST(V)              \
212   V(JSAsyncFunctionEnter)              \
213   V(JSAsyncFunctionReject)             \
214   V(JSAsyncFunctionResolve)            \
215   V(JSCallRuntime)                     \
216   V(JSForInEnumerate)                  \
217   V(JSForInNext)                       \
218   V(JSForInPrepare)                    \
219   V(JSGetIterator)                     \
220   V(JSLoadMessage)                     \
221   V(JSStoreMessage)                    \
222   V(JSLoadModule)                      \
223   V(JSStoreModule)                     \
224   V(JSGetImportMeta)                   \
225   V(JSGeneratorStore)                  \
226   V(JSGeneratorRestoreContinuation)    \
227   V(JSGeneratorRestoreContext)         \
228   V(JSGeneratorRestoreRegister)        \
229   V(JSGeneratorRestoreInputOrDebugPos) \
230   V(JSFulfillPromise)                  \
231   V(JSPerformPromiseThen)              \
232   V(JSPromiseResolve)                  \
233   V(JSRejectPromise)                   \
234   V(JSResolvePromise)                  \
235   V(JSStackCheck)                      \
236   V(JSObjectIsArray)                   \
237   V(JSRegExpTest)                      \
238   V(JSDebugger)
239 
240 #define JS_OP_LIST(V)     \
241   JS_SIMPLE_BINOP_LIST(V) \
242   JS_SIMPLE_UNOP_LIST(V)  \
243   JS_OBJECT_OP_LIST(V)    \
244   JS_CONTEXT_OP_LIST(V)   \
245   JS_OTHER_OP_LIST(V)
246 
247 // Opcodes for VirtuaMachine-level operators.
248 #define SIMPLIFIED_CHANGE_OP_LIST(V) \
249   V(ChangeTaggedSignedToInt32)       \
250   V(ChangeTaggedSignedToInt64)       \
251   V(ChangeTaggedToInt32)             \
252   V(ChangeTaggedToInt64)             \
253   V(ChangeTaggedToUint32)            \
254   V(ChangeTaggedToFloat64)           \
255   V(ChangeTaggedToTaggedSigned)      \
256   V(ChangeInt31ToTaggedSigned)       \
257   V(ChangeInt32ToTagged)             \
258   V(ChangeInt64ToTagged)             \
259   V(ChangeUint32ToTagged)            \
260   V(ChangeUint64ToTagged)            \
261   V(ChangeFloat64ToTagged)           \
262   V(ChangeFloat64ToTaggedPointer)    \
263   V(ChangeTaggedToBit)               \
264   V(ChangeBitToTagged)               \
265   V(ChangeUint64ToBigInt)            \
266   V(TruncateBigIntToUint64)          \
267   V(TruncateTaggedToWord32)          \
268   V(TruncateTaggedToFloat64)         \
269   V(TruncateTaggedToBit)             \
270   V(TruncateTaggedPointerToBit)
271 
272 #define SIMPLIFIED_CHECKED_OP_LIST(V) \
273   V(CheckedInt32Add)                  \
274   V(CheckedInt32Sub)                  \
275   V(CheckedInt32Div)                  \
276   V(CheckedInt32Mod)                  \
277   V(CheckedUint32Div)                 \
278   V(CheckedUint32Mod)                 \
279   V(CheckedInt32Mul)                  \
280   V(CheckedInt32ToTaggedSigned)       \
281   V(CheckedInt64ToInt32)              \
282   V(CheckedInt64ToTaggedSigned)       \
283   V(CheckedUint32Bounds)              \
284   V(CheckedUint32ToInt32)             \
285   V(CheckedUint32ToTaggedSigned)      \
286   V(CheckedUint64Bounds)              \
287   V(CheckedUint64ToInt32)             \
288   V(CheckedUint64ToTaggedSigned)      \
289   V(CheckedFloat64ToInt32)            \
290   V(CheckedFloat64ToInt64)            \
291   V(CheckedTaggedSignedToInt32)       \
292   V(CheckedTaggedToInt32)             \
293   V(CheckedTaggedToArrayIndex)        \
294   V(CheckedTruncateTaggedToWord32)    \
295   V(CheckedTaggedToFloat64)           \
296   V(CheckedTaggedToInt64)             \
297   V(CheckedTaggedToTaggedSigned)      \
298   V(CheckedTaggedToTaggedPointer)
299 
300 #define SIMPLIFIED_COMPARE_BINOP_LIST(V) \
301   V(NumberEqual)                         \
302   V(NumberLessThan)                      \
303   V(NumberLessThanOrEqual)               \
304   V(SpeculativeNumberEqual)              \
305   V(SpeculativeNumberLessThan)           \
306   V(SpeculativeNumberLessThanOrEqual)    \
307   V(ReferenceEqual)                      \
308   V(SameValue)                           \
309   V(SameValueNumbersOnly)                \
310   V(NumberSameValue)                     \
311   V(StringEqual)                         \
312   V(StringLessThan)                      \
313   V(StringLessThanOrEqual)
314 
315 #define SIMPLIFIED_NUMBER_BINOP_LIST(V) \
316   V(NumberAdd)                          \
317   V(NumberSubtract)                     \
318   V(NumberMultiply)                     \
319   V(NumberDivide)                       \
320   V(NumberModulus)                      \
321   V(NumberBitwiseOr)                    \
322   V(NumberBitwiseXor)                   \
323   V(NumberBitwiseAnd)                   \
324   V(NumberShiftLeft)                    \
325   V(NumberShiftRight)                   \
326   V(NumberShiftRightLogical)            \
327   V(NumberAtan2)                        \
328   V(NumberImul)                         \
329   V(NumberMax)                          \
330   V(NumberMin)                          \
331   V(NumberPow)
332 
333 #define SIMPLIFIED_BIGINT_BINOP_LIST(V) \
334   V(BigIntAdd)                          \
335   V(BigIntSubtract)
336 
337 #define SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(V) \
338   V(SpeculativeNumberAdd)                           \
339   V(SpeculativeNumberSubtract)                      \
340   V(SpeculativeNumberMultiply)                      \
341   V(SpeculativeNumberPow)                           \
342   V(SpeculativeNumberDivide)                        \
343   V(SpeculativeNumberModulus)                       \
344   V(SpeculativeNumberBitwiseAnd)                    \
345   V(SpeculativeNumberBitwiseOr)                     \
346   V(SpeculativeNumberBitwiseXor)                    \
347   V(SpeculativeNumberShiftLeft)                     \
348   V(SpeculativeNumberShiftRight)                    \
349   V(SpeculativeNumberShiftRightLogical)             \
350   V(SpeculativeSafeIntegerAdd)                      \
351   V(SpeculativeSafeIntegerSubtract)
352 
353 #define SIMPLIFIED_NUMBER_UNOP_LIST(V) \
354   V(NumberAbs)                         \
355   V(NumberAcos)                        \
356   V(NumberAcosh)                       \
357   V(NumberAsin)                        \
358   V(NumberAsinh)                       \
359   V(NumberAtan)                        \
360   V(NumberAtanh)                       \
361   V(NumberCbrt)                        \
362   V(NumberCeil)                        \
363   V(NumberClz32)                       \
364   V(NumberCos)                         \
365   V(NumberCosh)                        \
366   V(NumberExp)                         \
367   V(NumberExpm1)                       \
368   V(NumberFloor)                       \
369   V(NumberFround)                      \
370   V(NumberLog)                         \
371   V(NumberLog1p)                       \
372   V(NumberLog2)                        \
373   V(NumberLog10)                       \
374   V(NumberRound)                       \
375   V(NumberSign)                        \
376   V(NumberSin)                         \
377   V(NumberSinh)                        \
378   V(NumberSqrt)                        \
379   V(NumberTan)                         \
380   V(NumberTanh)                        \
381   V(NumberTrunc)                       \
382   V(NumberToBoolean)                   \
383   V(NumberToInt32)                     \
384   V(NumberToString)                    \
385   V(NumberToUint32)                    \
386   V(NumberToUint8Clamped)              \
387   V(NumberSilenceNaN)
388 
389 #define SIMPLIFIED_BIGINT_UNOP_LIST(V) \
390   V(BigIntNegate)                      \
391   V(CheckBigInt)
392 
393 #define SIMPLIFIED_SPECULATIVE_NUMBER_UNOP_LIST(V) V(SpeculativeToNumber)
394 
395 #define SIMPLIFIED_OTHER_OP_LIST(V)     \
396   V(Allocate)                           \
397   V(AllocateRaw)                        \
398   V(ArgumentsLength)                    \
399   V(AssertType)                         \
400   V(BooleanNot)                         \
401   V(CheckBounds)                        \
402   V(CheckClosure)                       \
403   V(CheckEqualsInternalizedString)      \
404   V(CheckEqualsSymbol)                  \
405   V(CheckFloat64Hole)                   \
406   V(CheckHeapObject)                    \
407   V(CheckIf)                            \
408   V(CheckInternalizedString)            \
409   V(CheckMaps)                          \
410   V(CheckNotTaggedHole)                 \
411   V(CheckNumber)                        \
412   V(CheckReceiver)                      \
413   V(CheckReceiverOrNullOrUndefined)     \
414   V(CheckSmi)                           \
415   V(CheckString)                        \
416   V(CheckSymbol)                        \
417   V(CompareMaps)                        \
418   V(ConvertReceiver)                    \
419   V(ConvertTaggedHoleToUndefined)       \
420   V(DateNow)                            \
421   V(DelayedStringConstant)              \
422   V(DynamicCheckMaps)                   \
423   V(EnsureWritableFastElements)         \
424   V(FastApiCall)                        \
425   V(FindOrderedHashMapEntry)            \
426   V(FindOrderedHashMapEntryForInt32Key) \
427   V(LoadDataViewElement)                \
428   V(LoadElement)                        \
429   V(LoadField)                          \
430   V(LoadFieldByIndex)                   \
431   V(LoadFromObject)                     \
432   V(LoadMessage)                        \
433   V(LoadStackArgument)                  \
434   V(LoadTypedElement)                   \
435   V(MaybeGrowFastElements)              \
436   V(NewArgumentsElements)               \
437   V(NewConsString)                      \
438   V(NewDoubleElements)                  \
439   V(NewSmiOrObjectElements)             \
440   V(NumberIsFinite)                     \
441   V(NumberIsFloat64Hole)                \
442   V(NumberIsInteger)                    \
443   V(NumberIsMinusZero)                  \
444   V(NumberIsNaN)                        \
445   V(NumberIsSafeInteger)                \
446   V(ObjectIsArrayBufferView)            \
447   V(ObjectIsBigInt)                     \
448   V(ObjectIsCallable)                   \
449   V(ObjectIsConstructor)                \
450   V(ObjectIsDetectableCallable)         \
451   V(ObjectIsFiniteNumber)               \
452   V(ObjectIsInteger)                    \
453   V(ObjectIsMinusZero)                  \
454   V(ObjectIsNaN)                        \
455   V(ObjectIsNonCallable)                \
456   V(ObjectIsNumber)                     \
457   V(ObjectIsReceiver)                   \
458   V(ObjectIsSafeInteger)                \
459   V(ObjectIsSmi)                        \
460   V(ObjectIsString)                     \
461   V(ObjectIsSymbol)                     \
462   V(ObjectIsUndetectable)               \
463   V(PlainPrimitiveToFloat64)            \
464   V(PlainPrimitiveToNumber)             \
465   V(PlainPrimitiveToWord32)             \
466   V(RestLength)                         \
467   V(RuntimeAbort)                       \
468   V(StoreDataViewElement)               \
469   V(StoreElement)                       \
470   V(StoreField)                         \
471   V(StoreMessage)                       \
472   V(StoreSignedSmallElement)            \
473   V(StoreToObject)                      \
474   V(StoreTypedElement)                  \
475   V(StringCharCodeAt)                   \
476   V(StringCodePointAt)                  \
477   V(StringConcat)                       \
478   V(StringFromCodePointAt)              \
479   V(StringFromSingleCharCode)           \
480   V(StringFromSingleCodePoint)          \
481   V(StringIndexOf)                      \
482   V(StringLength)                       \
483   V(StringSubstring)                    \
484   V(StringToLowerCaseIntl)              \
485   V(StringToNumber)                     \
486   V(StringToUpperCaseIntl)              \
487   V(TierUpCheck)                        \
488   V(ToBoolean)                          \
489   V(TransitionAndStoreElement)          \
490   V(TransitionAndStoreNonNumberElement) \
491   V(TransitionAndStoreNumberElement)    \
492   V(TransitionElementsKind)             \
493   V(TypeOf)                             \
494   V(UpdateInterruptBudget)              \
495   V(VerifyType)
496 
497 #define SIMPLIFIED_SPECULATIVE_BIGINT_BINOP_LIST(V) \
498   V(SpeculativeBigIntAdd)                           \
499   V(SpeculativeBigIntSubtract)
500 
501 #define SIMPLIFIED_SPECULATIVE_BIGINT_UNOP_LIST(V) \
502   V(SpeculativeBigIntAsUintN)                      \
503   V(SpeculativeBigIntNegate)
504 
505 #define SIMPLIFIED_OP_LIST(V)                 \
506   SIMPLIFIED_CHANGE_OP_LIST(V)                \
507   SIMPLIFIED_CHECKED_OP_LIST(V)               \
508   SIMPLIFIED_COMPARE_BINOP_LIST(V)            \
509   SIMPLIFIED_NUMBER_BINOP_LIST(V)             \
510   SIMPLIFIED_BIGINT_BINOP_LIST(V)             \
511   SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(V) \
512   SIMPLIFIED_NUMBER_UNOP_LIST(V)              \
513   SIMPLIFIED_BIGINT_UNOP_LIST(V)              \
514   SIMPLIFIED_SPECULATIVE_NUMBER_UNOP_LIST(V)  \
515   SIMPLIFIED_SPECULATIVE_BIGINT_UNOP_LIST(V)  \
516   SIMPLIFIED_SPECULATIVE_BIGINT_BINOP_LIST(V) \
517   SIMPLIFIED_OTHER_OP_LIST(V)
518 
519 // Opcodes for Machine-level operators.
520 #define MACHINE_COMPARE_BINOP_LIST(V) \
521   V(Word32Equal)                      \
522   V(Word64Equal)                      \
523   V(Int32LessThan)                    \
524   V(Int32LessThanOrEqual)             \
525   V(Uint32LessThan)                   \
526   V(Uint32LessThanOrEqual)            \
527   V(Int64LessThan)                    \
528   V(Int64LessThanOrEqual)             \
529   V(Uint64LessThan)                   \
530   V(Uint64LessThanOrEqual)            \
531   V(Float32Equal)                     \
532   V(Float32LessThan)                  \
533   V(Float32LessThanOrEqual)           \
534   V(Float64Equal)                     \
535   V(Float64LessThan)                  \
536   V(Float64LessThanOrEqual)
537 
538 #define MACHINE_UNOP_32_LIST(V) \
539   V(Word32Clz)                  \
540   V(Word32Ctz)                  \
541   V(Int32AbsWithOverflow)       \
542   V(Word32ReverseBits)          \
543   V(Word32ReverseBytes)
544 
545 #define MACHINE_BINOP_32_LIST(V) \
546   V(Word32And)                   \
547   V(Word32Or)                    \
548   V(Word32Xor)                   \
549   V(Word32Shl)                   \
550   V(Word32Shr)                   \
551   V(Word32Sar)                   \
552   V(Word32Rol)                   \
553   V(Word32Ror)                   \
554   V(Int32Add)                    \
555   V(Int32AddWithOverflow)        \
556   V(Int32Sub)                    \
557   V(Int32SubWithOverflow)        \
558   V(Int32Mul)                    \
559   V(Int32MulWithOverflow)        \
560   V(Int32MulHigh)                \
561   V(Int32Div)                    \
562   V(Int32Mod)                    \
563   V(Uint32Div)                   \
564   V(Uint32Mod)                   \
565   V(Uint32MulHigh)
566 
567 #define MACHINE_BINOP_64_LIST(V) \
568   V(Word64And)                   \
569   V(Word64Or)                    \
570   V(Word64Xor)                   \
571   V(Word64Shl)                   \
572   V(Word64Shr)                   \
573   V(Word64Sar)                   \
574   V(Word64Rol)                   \
575   V(Word64Ror)                   \
576   V(Word64RolLowerable)          \
577   V(Word64RorLowerable)          \
578   V(Int64Add)                    \
579   V(Int64AddWithOverflow)        \
580   V(Int64Sub)                    \
581   V(Int64SubWithOverflow)        \
582   V(Int64Mul)                    \
583   V(Int64Div)                    \
584   V(Int64Mod)                    \
585   V(Uint64Div)                   \
586   V(Uint64Mod)
587 
588 #define MACHINE_FLOAT32_UNOP_LIST(V) \
589   V(Float32Abs)                      \
590   V(Float32Neg)                      \
591   V(Float32RoundDown)                \
592   V(Float32RoundTiesEven)            \
593   V(Float32RoundTruncate)            \
594   V(Float32RoundUp)                  \
595   V(Float32Sqrt)
596 
597 #define MACHINE_FLOAT32_BINOP_LIST(V) \
598   V(Float32Add)                       \
599   V(Float32Sub)                       \
600   V(Float32Mul)                       \
601   V(Float32Div)                       \
602   V(Float32Max)                       \
603   V(Float32Min)
604 
605 #define MACHINE_FLOAT64_UNOP_LIST(V) \
606   V(Float64Abs)                      \
607   V(Float64Acos)                     \
608   V(Float64Acosh)                    \
609   V(Float64Asin)                     \
610   V(Float64Asinh)                    \
611   V(Float64Atan)                     \
612   V(Float64Atanh)                    \
613   V(Float64Cbrt)                     \
614   V(Float64Cos)                      \
615   V(Float64Cosh)                     \
616   V(Float64Exp)                      \
617   V(Float64Expm1)                    \
618   V(Float64Log)                      \
619   V(Float64Log1p)                    \
620   V(Float64Log10)                    \
621   V(Float64Log2)                     \
622   V(Float64Neg)                      \
623   V(Float64RoundDown)                \
624   V(Float64RoundTiesAway)            \
625   V(Float64RoundTiesEven)            \
626   V(Float64RoundTruncate)            \
627   V(Float64RoundUp)                  \
628   V(Float64Sin)                      \
629   V(Float64Sinh)                     \
630   V(Float64Sqrt)                     \
631   V(Float64Tan)                      \
632   V(Float64Tanh)
633 
634 #define MACHINE_FLOAT64_BINOP_LIST(V) \
635   V(Float64Atan2)                     \
636   V(Float64Max)                       \
637   V(Float64Min)                       \
638   V(Float64Add)                       \
639   V(Float64Sub)                       \
640   V(Float64Mul)                       \
641   V(Float64Div)                       \
642   V(Float64Mod)                       \
643   V(Float64Pow)
644 
645 #define MACHINE_ATOMIC_OP_LIST(V)    \
646   V(Word32AtomicLoad)                \
647   V(Word32AtomicStore)               \
648   V(Word32AtomicExchange)            \
649   V(Word32AtomicCompareExchange)     \
650   V(Word32AtomicAdd)                 \
651   V(Word32AtomicSub)                 \
652   V(Word32AtomicAnd)                 \
653   V(Word32AtomicOr)                  \
654   V(Word32AtomicXor)                 \
655   V(Word32AtomicPairLoad)            \
656   V(Word32AtomicPairStore)           \
657   V(Word32AtomicPairAdd)             \
658   V(Word32AtomicPairSub)             \
659   V(Word32AtomicPairAnd)             \
660   V(Word32AtomicPairOr)              \
661   V(Word32AtomicPairXor)             \
662   V(Word32AtomicPairExchange)        \
663   V(Word32AtomicPairCompareExchange) \
664   V(Word64AtomicLoad)                \
665   V(Word64AtomicStore)               \
666   V(Word64AtomicAdd)                 \
667   V(Word64AtomicSub)                 \
668   V(Word64AtomicAnd)                 \
669   V(Word64AtomicOr)                  \
670   V(Word64AtomicXor)                 \
671   V(Word64AtomicExchange)            \
672   V(Word64AtomicCompareExchange)
673 
674 #define MACHINE_OP_LIST(V)               \
675   MACHINE_UNOP_32_LIST(V)                \
676   MACHINE_BINOP_32_LIST(V)               \
677   MACHINE_BINOP_64_LIST(V)               \
678   MACHINE_COMPARE_BINOP_LIST(V)          \
679   MACHINE_FLOAT32_BINOP_LIST(V)          \
680   MACHINE_FLOAT32_UNOP_LIST(V)           \
681   MACHINE_FLOAT64_BINOP_LIST(V)          \
682   MACHINE_FLOAT64_UNOP_LIST(V)           \
683   MACHINE_ATOMIC_OP_LIST(V)              \
684   V(AbortCSADcheck)                      \
685   V(DebugBreak)                          \
686   V(Comment)                             \
687   V(Load)                                \
688   V(LoadImmutable)                       \
689   V(Store)                               \
690   V(StackSlot)                           \
691   V(Word32Popcnt)                        \
692   V(Word64Popcnt)                        \
693   V(Word64Clz)                           \
694   V(Word64Ctz)                           \
695   V(Word64ClzLowerable)                  \
696   V(Word64CtzLowerable)                  \
697   V(Word64ReverseBits)                   \
698   V(Word64ReverseBytes)                  \
699   V(Simd128ReverseBytes)                 \
700   V(Int64AbsWithOverflow)                \
701   V(BitcastTaggedToWord)                 \
702   V(BitcastTaggedToWordForTagAndSmiBits) \
703   V(BitcastWordToTagged)                 \
704   V(BitcastWordToTaggedSigned)           \
705   V(TruncateFloat64ToWord32)             \
706   V(ChangeFloat32ToFloat64)              \
707   V(ChangeFloat64ToInt32)                \
708   V(ChangeFloat64ToInt64)                \
709   V(ChangeFloat64ToUint32)               \
710   V(ChangeFloat64ToUint64)               \
711   V(Float64SilenceNaN)                   \
712   V(TruncateFloat64ToInt64)              \
713   V(TruncateFloat64ToUint32)             \
714   V(TruncateFloat32ToInt32)              \
715   V(TruncateFloat32ToUint32)             \
716   V(TryTruncateFloat32ToInt64)           \
717   V(TryTruncateFloat64ToInt64)           \
718   V(TryTruncateFloat32ToUint64)          \
719   V(TryTruncateFloat64ToUint64)          \
720   V(ChangeInt32ToFloat64)                \
721   V(BitcastWord32ToWord64)               \
722   V(ChangeInt32ToInt64)                  \
723   V(ChangeInt64ToFloat64)                \
724   V(ChangeUint32ToFloat64)               \
725   V(ChangeUint32ToUint64)                \
726   V(TruncateFloat64ToFloat32)            \
727   V(TruncateInt64ToInt32)                \
728   V(RoundFloat64ToInt32)                 \
729   V(RoundInt32ToFloat32)                 \
730   V(RoundInt64ToFloat32)                 \
731   V(RoundInt64ToFloat64)                 \
732   V(RoundUint32ToFloat32)                \
733   V(RoundUint64ToFloat32)                \
734   V(RoundUint64ToFloat64)                \
735   V(BitcastFloat32ToInt32)               \
736   V(BitcastFloat64ToInt64)               \
737   V(BitcastInt32ToFloat32)               \
738   V(BitcastInt64ToFloat64)               \
739   V(Float64ExtractLowWord32)             \
740   V(Float64ExtractHighWord32)            \
741   V(Float64InsertLowWord32)              \
742   V(Float64InsertHighWord32)             \
743   V(Word32Select)                        \
744   V(Word64Select)                        \
745   V(Float32Select)                       \
746   V(Float64Select)                       \
747   V(LoadStackCheckOffset)                \
748   V(LoadFramePointer)                    \
749   V(LoadParentFramePointer)              \
750   V(UnalignedLoad)                       \
751   V(UnalignedStore)                      \
752   V(Int32PairAdd)                        \
753   V(Int32PairSub)                        \
754   V(Int32PairMul)                        \
755   V(Word32PairShl)                       \
756   V(Word32PairShr)                       \
757   V(Word32PairSar)                       \
758   V(ProtectedLoad)                       \
759   V(ProtectedStore)                      \
760   V(MemoryBarrier)                       \
761   V(SignExtendWord8ToInt32)              \
762   V(SignExtendWord16ToInt32)             \
763   V(SignExtendWord8ToInt64)              \
764   V(SignExtendWord16ToInt64)             \
765   V(SignExtendWord32ToInt64)             \
766   V(UnsafePointerAdd)                    \
767   V(StackPointerGreaterThan)
768 
769 #define MACHINE_SIMD_OP_LIST(V) \
770   V(F64x2Splat)                 \
771   V(F64x2ExtractLane)           \
772   V(F64x2ReplaceLane)           \
773   V(F64x2Abs)                   \
774   V(F64x2Neg)                   \
775   V(F64x2Sqrt)                  \
776   V(F64x2Add)                   \
777   V(F64x2Sub)                   \
778   V(F64x2Mul)                   \
779   V(F64x2Div)                   \
780   V(F64x2Min)                   \
781   V(F64x2Max)                   \
782   V(F64x2Eq)                    \
783   V(F64x2Ne)                    \
784   V(F64x2Lt)                    \
785   V(F64x2Le)                    \
786   V(F64x2Qfma)                  \
787   V(F64x2Qfms)                  \
788   V(F64x2Pmin)                  \
789   V(F64x2Pmax)                  \
790   V(F64x2Ceil)                  \
791   V(F64x2Floor)                 \
792   V(F64x2Trunc)                 \
793   V(F64x2NearestInt)            \
794   V(F64x2ConvertLowI32x4S)      \
795   V(F64x2ConvertLowI32x4U)      \
796   V(F64x2PromoteLowF32x4)       \
797   V(F32x4Splat)                 \
798   V(F32x4ExtractLane)           \
799   V(F32x4ReplaceLane)           \
800   V(F32x4SConvertI32x4)         \
801   V(F32x4UConvertI32x4)         \
802   V(F32x4Abs)                   \
803   V(F32x4Neg)                   \
804   V(F32x4Sqrt)                  \
805   V(F32x4RecipApprox)           \
806   V(F32x4RecipSqrtApprox)       \
807   V(F32x4Add)                   \
808   V(F32x4Sub)                   \
809   V(F32x4Mul)                   \
810   V(F32x4Div)                   \
811   V(F32x4Min)                   \
812   V(F32x4Max)                   \
813   V(F32x4Eq)                    \
814   V(F32x4Ne)                    \
815   V(F32x4Lt)                    \
816   V(F32x4Le)                    \
817   V(F32x4Gt)                    \
818   V(F32x4Ge)                    \
819   V(F32x4Qfma)                  \
820   V(F32x4Qfms)                  \
821   V(F32x4Pmin)                  \
822   V(F32x4Pmax)                  \
823   V(F32x4Ceil)                  \
824   V(F32x4Floor)                 \
825   V(F32x4Trunc)                 \
826   V(F32x4NearestInt)            \
827   V(F32x4DemoteF64x2Zero)       \
828   V(I64x2Splat)                 \
829   V(I64x2SplatI32Pair)          \
830   V(I64x2ExtractLane)           \
831   V(I64x2ReplaceLane)           \
832   V(I64x2ReplaceLaneI32Pair)    \
833   V(I64x2Abs)                   \
834   V(I64x2Neg)                   \
835   V(I64x2SConvertI32x4Low)      \
836   V(I64x2SConvertI32x4High)     \
837   V(I64x2UConvertI32x4Low)      \
838   V(I64x2UConvertI32x4High)     \
839   V(I64x2BitMask)               \
840   V(I64x2Shl)                   \
841   V(I64x2ShrS)                  \
842   V(I64x2Add)                   \
843   V(I64x2Sub)                   \
844   V(I64x2Mul)                   \
845   V(I64x2Eq)                    \
846   V(I64x2Ne)                    \
847   V(I64x2GtS)                   \
848   V(I64x2GeS)                   \
849   V(I64x2ShrU)                  \
850   V(I64x2ExtMulLowI32x4S)       \
851   V(I64x2ExtMulHighI32x4S)      \
852   V(I64x2ExtMulLowI32x4U)       \
853   V(I64x2ExtMulHighI32x4U)      \
854   V(I32x4Splat)                 \
855   V(I32x4ExtractLane)           \
856   V(I32x4ReplaceLane)           \
857   V(I32x4SConvertF32x4)         \
858   V(I32x4SConvertI16x8Low)      \
859   V(I32x4SConvertI16x8High)     \
860   V(I32x4Neg)                   \
861   V(I32x4Shl)                   \
862   V(I32x4ShrS)                  \
863   V(I32x4Add)                   \
864   V(I32x4Sub)                   \
865   V(I32x4Mul)                   \
866   V(I32x4MinS)                  \
867   V(I32x4MaxS)                  \
868   V(I32x4Eq)                    \
869   V(I32x4Ne)                    \
870   V(I32x4LtS)                   \
871   V(I32x4LeS)                   \
872   V(I32x4GtS)                   \
873   V(I32x4GeS)                   \
874   V(I32x4UConvertF32x4)         \
875   V(I32x4UConvertI16x8Low)      \
876   V(I32x4UConvertI16x8High)     \
877   V(I32x4ShrU)                  \
878   V(I32x4MinU)                  \
879   V(I32x4MaxU)                  \
880   V(I32x4LtU)                   \
881   V(I32x4LeU)                   \
882   V(I32x4GtU)                   \
883   V(I32x4GeU)                   \
884   V(I32x4Abs)                   \
885   V(I32x4BitMask)               \
886   V(I32x4DotI16x8S)             \
887   V(I32x4ExtMulLowI16x8S)       \
888   V(I32x4ExtMulHighI16x8S)      \
889   V(I32x4ExtMulLowI16x8U)       \
890   V(I32x4ExtMulHighI16x8U)      \
891   V(I32x4ExtAddPairwiseI16x8S)  \
892   V(I32x4ExtAddPairwiseI16x8U)  \
893   V(I32x4TruncSatF64x2SZero)    \
894   V(I32x4TruncSatF64x2UZero)    \
895   V(I16x8Splat)                 \
896   V(I16x8ExtractLaneU)          \
897   V(I16x8ExtractLaneS)          \
898   V(I16x8ReplaceLane)           \
899   V(I16x8SConvertI8x16Low)      \
900   V(I16x8SConvertI8x16High)     \
901   V(I16x8Neg)                   \
902   V(I16x8Shl)                   \
903   V(I16x8ShrS)                  \
904   V(I16x8SConvertI32x4)         \
905   V(I16x8Add)                   \
906   V(I16x8AddSatS)               \
907   V(I16x8Sub)                   \
908   V(I16x8SubSatS)               \
909   V(I16x8Mul)                   \
910   V(I16x8MinS)                  \
911   V(I16x8MaxS)                  \
912   V(I16x8Eq)                    \
913   V(I16x8Ne)                    \
914   V(I16x8LtS)                   \
915   V(I16x8LeS)                   \
916   V(I16x8GtS)                   \
917   V(I16x8GeS)                   \
918   V(I16x8UConvertI8x16Low)      \
919   V(I16x8UConvertI8x16High)     \
920   V(I16x8ShrU)                  \
921   V(I16x8UConvertI32x4)         \
922   V(I16x8AddSatU)               \
923   V(I16x8SubSatU)               \
924   V(I16x8MinU)                  \
925   V(I16x8MaxU)                  \
926   V(I16x8LtU)                   \
927   V(I16x8LeU)                   \
928   V(I16x8GtU)                   \
929   V(I16x8GeU)                   \
930   V(I16x8RoundingAverageU)      \
931   V(I16x8Q15MulRSatS)           \
932   V(I16x8Abs)                   \
933   V(I16x8BitMask)               \
934   V(I16x8ExtMulLowI8x16S)       \
935   V(I16x8ExtMulHighI8x16S)      \
936   V(I16x8ExtMulLowI8x16U)       \
937   V(I16x8ExtMulHighI8x16U)      \
938   V(I16x8ExtAddPairwiseI8x16S)  \
939   V(I16x8ExtAddPairwiseI8x16U)  \
940   V(I8x16Splat)                 \
941   V(I8x16ExtractLaneU)          \
942   V(I8x16ExtractLaneS)          \
943   V(I8x16ReplaceLane)           \
944   V(I8x16SConvertI16x8)         \
945   V(I8x16Neg)                   \
946   V(I8x16Shl)                   \
947   V(I8x16ShrS)                  \
948   V(I8x16Add)                   \
949   V(I8x16AddSatS)               \
950   V(I8x16Sub)                   \
951   V(I8x16SubSatS)               \
952   V(I8x16MinS)                  \
953   V(I8x16MaxS)                  \
954   V(I8x16Eq)                    \
955   V(I8x16Ne)                    \
956   V(I8x16LtS)                   \
957   V(I8x16LeS)                   \
958   V(I8x16GtS)                   \
959   V(I8x16GeS)                   \
960   V(I8x16UConvertI16x8)         \
961   V(I8x16AddSatU)               \
962   V(I8x16SubSatU)               \
963   V(I8x16ShrU)                  \
964   V(I8x16MinU)                  \
965   V(I8x16MaxU)                  \
966   V(I8x16LtU)                   \
967   V(I8x16LeU)                   \
968   V(I8x16GtU)                   \
969   V(I8x16GeU)                   \
970   V(I8x16RoundingAverageU)      \
971   V(I8x16Popcnt)                \
972   V(I8x16Abs)                   \
973   V(I8x16BitMask)               \
974   V(S128Zero)                   \
975   V(S128Const)                  \
976   V(S128Not)                    \
977   V(S128And)                    \
978   V(S128Or)                     \
979   V(S128Xor)                    \
980   V(S128Select)                 \
981   V(S128AndNot)                 \
982   V(I8x16Swizzle)               \
983   V(I8x16Shuffle)               \
984   V(V128AnyTrue)                \
985   V(I64x2AllTrue)               \
986   V(I32x4AllTrue)               \
987   V(I16x8AllTrue)               \
988   V(I8x16AllTrue)               \
989   V(LoadTransform)              \
990   V(LoadLane)                   \
991   V(StoreLane)
992 
993 #define VALUE_OP_LIST(V)  \
994   COMMON_OP_LIST(V)       \
995   SIMPLIFIED_OP_LIST(V)   \
996   MACHINE_OP_LIST(V)      \
997   MACHINE_SIMD_OP_LIST(V) \
998   JS_OP_LIST(V)
999 
1000 // The combination of all operators at all levels and the common operators.
1001 #define ALL_OP_LIST(V) \
1002   CONTROL_OP_LIST(V)   \
1003   VALUE_OP_LIST(V)
1004 
1005 namespace v8 {
1006 namespace internal {
1007 namespace compiler {
1008 
1009 // Declare an enumeration with all the opcodes at all levels so that they
1010 // can be globally, uniquely numbered.
1011 class V8_EXPORT_PRIVATE IrOpcode {
1012  public:
1013   enum Value {
1014 #define DECLARE_OPCODE(x, ...) k##x,
1015     ALL_OP_LIST(DECLARE_OPCODE)
1016 #undef DECLARE_OPCODE
1017         kLast = -1
1018 #define COUNT_OPCODE(...) +1
1019                 ALL_OP_LIST(COUNT_OPCODE)
1020 #undef COUNT_OPCODE
1021   };
1022 
1023   // Returns the mnemonic name of an opcode.
1024   static char const* Mnemonic(Value value);
1025 
1026   // Returns true if opcode for common operator.
IsCommonOpcode(Value value)1027   static bool IsCommonOpcode(Value value) {
1028     return kStart <= value && value <= kStaticAssert;
1029   }
1030 
1031   // Returns true if opcode for control operator.
IsControlOpcode(Value value)1032   static bool IsControlOpcode(Value value) {
1033     return kStart <= value && value <= kEnd;
1034   }
1035 
1036   // Returns true if opcode for JavaScript operator.
IsJsOpcode(Value value)1037   static bool IsJsOpcode(Value value) {
1038     return kJSEqual <= value && value <= kJSDebugger;
1039   }
1040 
1041   // Returns true if opcode for constant operator.
IsConstantOpcode(Value value)1042   static bool IsConstantOpcode(Value value) {
1043 #define CASE(Name) \
1044   case k##Name:    \
1045     return true;
1046     switch (value) {
1047       CONSTANT_OP_LIST(CASE);
1048       default:
1049         return false;
1050     }
1051 #undef CASE
1052     UNREACHABLE();
1053   }
1054 
IsPhiOpcode(Value value)1055   static bool IsPhiOpcode(Value value) {
1056     return value == kPhi || value == kEffectPhi;
1057   }
1058 
IsMergeOpcode(Value value)1059   static bool IsMergeOpcode(Value value) {
1060     return value == kMerge || value == kLoop;
1061   }
1062 
IsIfProjectionOpcode(Value value)1063   static bool IsIfProjectionOpcode(Value value) {
1064     return kIfTrue <= value && value <= kIfDefault;
1065   }
1066 
1067   // Returns true if opcode terminates control flow in a graph (i.e.
1068   // respective nodes are expected to have control uses by the graphs {End}
1069   // node only).
IsGraphTerminator(Value value)1070   static bool IsGraphTerminator(Value value) {
1071     return value == kDeoptimize || value == kReturn || value == kTailCall ||
1072            value == kTerminate || value == kThrow;
1073   }
1074 
1075   // Returns true if opcode can be inlined.
IsInlineeOpcode(Value value)1076   static bool IsInlineeOpcode(Value value) {
1077     return value == kJSConstruct || value == kJSCall;
1078   }
1079 
1080   // Returns true if opcode for comparison operator.
IsComparisonOpcode(Value value)1081   static bool IsComparisonOpcode(Value value) {
1082 #define CASE(Name, ...) \
1083   case k##Name:         \
1084     return true;
1085     switch (value) {
1086       JS_COMPARE_BINOP_LIST(CASE);
1087       SIMPLIFIED_COMPARE_BINOP_LIST(CASE);
1088       MACHINE_COMPARE_BINOP_LIST(CASE);
1089       default:
1090         return false;
1091     }
1092 #undef CASE
1093     UNREACHABLE();
1094   }
1095 
IsContextChainExtendingOpcode(Value value)1096   static bool IsContextChainExtendingOpcode(Value value) {
1097     return kJSCreateFunctionContext <= value && value <= kJSCreateBlockContext;
1098   }
1099 
1100   // These opcode take the feedback vector as an input, and implement
1101   // feedback-collecting logic in generic lowering.
IsFeedbackCollectingOpcode(Value value)1102   static bool IsFeedbackCollectingOpcode(Value value) {
1103 #define CASE(Name, ...) \
1104   case k##Name:         \
1105     return true;
1106     switch (value) {
1107       JS_ARITH_BINOP_LIST(CASE)
1108       JS_ARITH_UNOP_LIST(CASE)
1109       JS_BITWISE_BINOP_LIST(CASE)
1110       JS_BITWISE_UNOP_LIST(CASE)
1111       JS_COMPARE_BINOP_LIST(CASE)
1112       case kJSCall:
1113       case kJSCallWithArrayLike:
1114       case kJSCallWithSpread:
1115       case kJSCloneObject:
1116       case kJSConstruct:
1117       case kJSConstructWithArrayLike:
1118       case kJSConstructWithSpread:
1119       case kJSCreateEmptyLiteralArray:
1120       case kJSCreateLiteralArray:
1121       case kJSCreateLiteralObject:
1122       case kJSCreateLiteralRegExp:
1123       case kJSForInNext:
1124       case kJSForInPrepare:
1125       case kJSGetIterator:
1126       case kJSGetTemplateObject:
1127       case kJSHasProperty:
1128       case kJSInstanceOf:
1129       case kJSLoadGlobal:
1130       case kJSLoadNamed:
1131       case kJSLoadNamedFromSuper:
1132       case kJSLoadProperty:
1133       case kJSStoreDataPropertyInLiteral:
1134       case kJSStoreGlobal:
1135       case kJSStoreInArrayLiteral:
1136       case kJSStoreNamed:
1137       case kJSStoreNamedOwn:
1138       case kJSStoreProperty:
1139         return true;
1140       default:
1141         return false;
1142     }
1143 #undef CASE
1144     UNREACHABLE();
1145   }
1146 
IsFeedbackCollectingOpcode(int16_t value)1147   static bool IsFeedbackCollectingOpcode(int16_t value) {
1148     DCHECK(0 <= value && value <= kLast);
1149     return IsFeedbackCollectingOpcode(static_cast<IrOpcode::Value>(value));
1150   }
1151 };
1152 
1153 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, IrOpcode::Value);
1154 
1155 }  // namespace compiler
1156 }  // namespace internal
1157 }  // namespace v8
1158 
1159 #endif  // V8_COMPILER_OPCODES_H_
1160