Home | History | Annotate | Download | only in compiler
      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 // Opcodes for control operators.
     11 #define CONTROL_OP_LIST(V) \
     12   V(Start)                 \
     13   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)            \
     24   V(Return)                \
     25   V(TailCall)              \
     26   V(Terminate)             \
     27   V(OsrNormalEntry)        \
     28   V(OsrLoopEntry)          \
     29   V(Throw)                 \
     30   V(End)
     31 
     32 // Opcodes for constant operators.
     33 #define CONSTANT_OP_LIST(V) \
     34   V(Int32Constant)          \
     35   V(Int64Constant)          \
     36   V(Float32Constant)        \
     37   V(Float64Constant)        \
     38   V(ExternalConstant)       \
     39   V(NumberConstant)         \
     40   V(HeapConstant)
     41 
     42 #define INNER_OP_LIST(V) \
     43   V(Select)              \
     44   V(Phi)                 \
     45   V(EffectSet)           \
     46   V(EffectPhi)           \
     47   V(Guard)               \
     48   V(BeginRegion)         \
     49   V(FinishRegion)        \
     50   V(FrameState)          \
     51   V(StateValues)         \
     52   V(TypedStateValues)    \
     53   V(ObjectState)         \
     54   V(Call)                \
     55   V(Parameter)           \
     56   V(OsrValue)            \
     57   V(Projection)
     58 
     59 #define COMMON_OP_LIST(V) \
     60   CONSTANT_OP_LIST(V)     \
     61   INNER_OP_LIST(V)        \
     62   V(Dead)
     63 
     64 // Opcodes for JavaScript operators.
     65 #define JS_COMPARE_BINOP_LIST(V) \
     66   V(JSEqual)                     \
     67   V(JSNotEqual)                  \
     68   V(JSStrictEqual)               \
     69   V(JSStrictNotEqual)            \
     70   V(JSLessThan)                  \
     71   V(JSGreaterThan)               \
     72   V(JSLessThanOrEqual)           \
     73   V(JSGreaterThanOrEqual)
     74 
     75 #define JS_BITWISE_BINOP_LIST(V) \
     76   V(JSBitwiseOr)                 \
     77   V(JSBitwiseXor)                \
     78   V(JSBitwiseAnd)                \
     79   V(JSShiftLeft)                 \
     80   V(JSShiftRight)                \
     81   V(JSShiftRightLogical)
     82 
     83 #define JS_ARITH_BINOP_LIST(V) \
     84   V(JSAdd)                     \
     85   V(JSSubtract)                \
     86   V(JSMultiply)                \
     87   V(JSDivide)                  \
     88   V(JSModulus)
     89 
     90 #define JS_SIMPLE_BINOP_LIST(V) \
     91   JS_COMPARE_BINOP_LIST(V)      \
     92   JS_BITWISE_BINOP_LIST(V)      \
     93   JS_ARITH_BINOP_LIST(V)
     94 
     95 #define JS_CONVERSION_UNOP_LIST(V) \
     96   V(JSToBoolean)                   \
     97   V(JSToNumber)                    \
     98   V(JSToString)                    \
     99   V(JSToName)                      \
    100   V(JSToObject)
    101 
    102 #define JS_OTHER_UNOP_LIST(V) \
    103   V(JSTypeOf)
    104 
    105 #define JS_SIMPLE_UNOP_LIST(V) \
    106   JS_CONVERSION_UNOP_LIST(V)   \
    107   JS_OTHER_UNOP_LIST(V)
    108 
    109 #define JS_OBJECT_OP_LIST(V)  \
    110   V(JSCreate)                 \
    111   V(JSCreateArguments)        \
    112   V(JSCreateArray)            \
    113   V(JSCreateClosure)          \
    114   V(JSCreateIterResultObject) \
    115   V(JSCreateLiteralArray)     \
    116   V(JSCreateLiteralObject)    \
    117   V(JSCreateLiteralRegExp)    \
    118   V(JSLoadProperty)           \
    119   V(JSLoadNamed)              \
    120   V(JSLoadGlobal)             \
    121   V(JSStoreProperty)          \
    122   V(JSStoreNamed)             \
    123   V(JSStoreGlobal)            \
    124   V(JSDeleteProperty)         \
    125   V(JSHasProperty)            \
    126   V(JSInstanceOf)
    127 
    128 #define JS_CONTEXT_OP_LIST(V) \
    129   V(JSLoadContext)            \
    130   V(JSStoreContext)           \
    131   V(JSLoadDynamic)            \
    132   V(JSCreateFunctionContext)  \
    133   V(JSCreateCatchContext)     \
    134   V(JSCreateWithContext)      \
    135   V(JSCreateBlockContext)     \
    136   V(JSCreateModuleContext)    \
    137   V(JSCreateScriptContext)
    138 
    139 #define JS_OTHER_OP_LIST(V) \
    140   V(JSCallConstruct)        \
    141   V(JSCallFunction)         \
    142   V(JSCallRuntime)          \
    143   V(JSConvertReceiver)      \
    144   V(JSForInDone)            \
    145   V(JSForInNext)            \
    146   V(JSForInPrepare)         \
    147   V(JSForInStep)            \
    148   V(JSLoadMessage)          \
    149   V(JSStoreMessage)         \
    150   V(JSYield)                \
    151   V(JSStackCheck)
    152 
    153 #define JS_OP_LIST(V)     \
    154   JS_SIMPLE_BINOP_LIST(V) \
    155   JS_SIMPLE_UNOP_LIST(V)  \
    156   JS_OBJECT_OP_LIST(V)    \
    157   JS_CONTEXT_OP_LIST(V)   \
    158   JS_OTHER_OP_LIST(V)
    159 
    160 // Opcodes for VirtuaMachine-level operators.
    161 #define SIMPLIFIED_COMPARE_BINOP_LIST(V) \
    162   V(NumberEqual)                         \
    163   V(NumberLessThan)                      \
    164   V(NumberLessThanOrEqual)               \
    165   V(ReferenceEqual)                      \
    166   V(StringEqual)                         \
    167   V(StringLessThan)                      \
    168   V(StringLessThanOrEqual)
    169 
    170 #define SIMPLIFIED_OP_LIST(V)      \
    171   SIMPLIFIED_COMPARE_BINOP_LIST(V) \
    172   V(BooleanNot)                    \
    173   V(BooleanToNumber)               \
    174   V(NumberAdd)                     \
    175   V(NumberSubtract)                \
    176   V(NumberMultiply)                \
    177   V(NumberDivide)                  \
    178   V(NumberModulus)                 \
    179   V(NumberBitwiseOr)               \
    180   V(NumberBitwiseXor)              \
    181   V(NumberBitwiseAnd)              \
    182   V(NumberShiftLeft)               \
    183   V(NumberShiftRight)              \
    184   V(NumberShiftRightLogical)       \
    185   V(NumberToInt32)                 \
    186   V(NumberToUint32)                \
    187   V(NumberIsHoleNaN)               \
    188   V(PlainPrimitiveToNumber)        \
    189   V(ChangeTaggedToInt32)           \
    190   V(ChangeTaggedToUint32)          \
    191   V(ChangeTaggedToFloat64)         \
    192   V(ChangeInt32ToTagged)           \
    193   V(ChangeUint32ToTagged)          \
    194   V(ChangeFloat64ToTagged)         \
    195   V(ChangeBoolToBit)               \
    196   V(ChangeBitToBool)               \
    197   V(Allocate)                      \
    198   V(LoadField)                     \
    199   V(LoadBuffer)                    \
    200   V(LoadElement)                   \
    201   V(StoreField)                    \
    202   V(StoreBuffer)                   \
    203   V(StoreElement)                  \
    204   V(ObjectIsNumber)                \
    205   V(ObjectIsSmi)
    206 
    207 // Opcodes for Machine-level operators.
    208 #define MACHINE_COMPARE_BINOP_LIST(V) \
    209   V(Word32Equal)                      \
    210   V(Word64Equal)                      \
    211   V(Int32LessThan)                    \
    212   V(Int32LessThanOrEqual)             \
    213   V(Uint32LessThan)                   \
    214   V(Uint32LessThanOrEqual)            \
    215   V(Int64LessThan)                    \
    216   V(Int64LessThanOrEqual)             \
    217   V(Uint64LessThan)                   \
    218   V(Uint64LessThanOrEqual)            \
    219   V(Float32Equal)                     \
    220   V(Float32LessThan)                  \
    221   V(Float32LessThanOrEqual)           \
    222   V(Float64Equal)                     \
    223   V(Float64LessThan)                  \
    224   V(Float64LessThanOrEqual)
    225 
    226 #define MACHINE_OP_LIST(V)      \
    227   MACHINE_COMPARE_BINOP_LIST(V) \
    228   V(Load)                       \
    229   V(Store)                      \
    230   V(Word32And)                  \
    231   V(Word32Or)                   \
    232   V(Word32Xor)                  \
    233   V(Word32Shl)                  \
    234   V(Word32Shr)                  \
    235   V(Word32Sar)                  \
    236   V(Word32Ror)                  \
    237   V(Word32Clz)                  \
    238   V(Word32Ctz)                  \
    239   V(Word32Popcnt)               \
    240   V(Word64Popcnt)               \
    241   V(Word64And)                  \
    242   V(Word64Or)                   \
    243   V(Word64Xor)                  \
    244   V(Word64Shl)                  \
    245   V(Word64Shr)                  \
    246   V(Word64Sar)                  \
    247   V(Word64Ror)                  \
    248   V(Word64Clz)                  \
    249   V(Word64Ctz)                  \
    250   V(Int32Add)                   \
    251   V(Int32AddWithOverflow)       \
    252   V(Int32Sub)                   \
    253   V(Int32SubWithOverflow)       \
    254   V(Int32Mul)                   \
    255   V(Int32MulHigh)               \
    256   V(Int32Div)                   \
    257   V(Int32Mod)                   \
    258   V(Uint32Div)                  \
    259   V(Uint32Mod)                  \
    260   V(Uint32MulHigh)              \
    261   V(Int64Add)                   \
    262   V(Int64AddWithOverflow)       \
    263   V(Int64Sub)                   \
    264   V(Int64SubWithOverflow)       \
    265   V(Int64Mul)                   \
    266   V(Int64Div)                   \
    267   V(Int64Mod)                   \
    268   V(Uint64Div)                  \
    269   V(Uint64Mod)                  \
    270   V(ChangeFloat32ToFloat64)     \
    271   V(ChangeFloat64ToInt32)       \
    272   V(ChangeFloat64ToUint32)      \
    273   V(TryTruncateFloat32ToInt64)  \
    274   V(TryTruncateFloat64ToInt64)  \
    275   V(TryTruncateFloat32ToUint64) \
    276   V(TryTruncateFloat64ToUint64) \
    277   V(ChangeInt32ToFloat64)       \
    278   V(ChangeInt32ToInt64)         \
    279   V(ChangeUint32ToFloat64)      \
    280   V(ChangeUint32ToUint64)       \
    281   V(TruncateFloat64ToFloat32)   \
    282   V(TruncateFloat64ToInt32)     \
    283   V(TruncateInt64ToInt32)       \
    284   V(RoundInt64ToFloat32)        \
    285   V(RoundInt64ToFloat64)        \
    286   V(RoundUint64ToFloat32)       \
    287   V(RoundUint64ToFloat64)       \
    288   V(BitcastFloat32ToInt32)      \
    289   V(BitcastFloat64ToInt64)      \
    290   V(BitcastInt32ToFloat32)      \
    291   V(BitcastInt64ToFloat64)      \
    292   V(Float32Add)                 \
    293   V(Float32Sub)                 \
    294   V(Float32Mul)                 \
    295   V(Float32Div)                 \
    296   V(Float32Max)                 \
    297   V(Float32Min)                 \
    298   V(Float32Abs)                 \
    299   V(Float32Sqrt)                \
    300   V(Float32RoundDown)           \
    301   V(Float64Add)                 \
    302   V(Float64Sub)                 \
    303   V(Float64Mul)                 \
    304   V(Float64Div)                 \
    305   V(Float64Mod)                 \
    306   V(Float64Max)                 \
    307   V(Float64Min)                 \
    308   V(Float64Abs)                 \
    309   V(Float64Sqrt)                \
    310   V(Float64RoundDown)           \
    311   V(Float32RoundUp)             \
    312   V(Float64RoundUp)             \
    313   V(Float32RoundTruncate)       \
    314   V(Float64RoundTruncate)       \
    315   V(Float64RoundTiesAway)       \
    316   V(Float32RoundTiesEven)       \
    317   V(Float64RoundTiesEven)       \
    318   V(Float64ExtractLowWord32)    \
    319   V(Float64ExtractHighWord32)   \
    320   V(Float64InsertLowWord32)     \
    321   V(Float64InsertHighWord32)    \
    322   V(LoadStackPointer)           \
    323   V(LoadFramePointer)           \
    324   V(CheckedLoad)                \
    325   V(CheckedStore)
    326 
    327 #define VALUE_OP_LIST(V) \
    328   COMMON_OP_LIST(V)      \
    329   SIMPLIFIED_OP_LIST(V)  \
    330   MACHINE_OP_LIST(V)     \
    331   JS_OP_LIST(V)
    332 
    333 // The combination of all operators at all levels and the common operators.
    334 #define ALL_OP_LIST(V) \
    335   CONTROL_OP_LIST(V)   \
    336   VALUE_OP_LIST(V)
    337 
    338 namespace v8 {
    339 namespace internal {
    340 namespace compiler {
    341 
    342 // Declare an enumeration with all the opcodes at all levels so that they
    343 // can be globally, uniquely numbered.
    344 class IrOpcode {
    345  public:
    346   enum Value {
    347 #define DECLARE_OPCODE(x) k##x,
    348     ALL_OP_LIST(DECLARE_OPCODE)
    349 #undef DECLARE_OPCODE
    350     kLast = -1
    351 #define COUNT_OPCODE(x) +1
    352             ALL_OP_LIST(COUNT_OPCODE)
    353 #undef COUNT_OPCODE
    354   };
    355 
    356   // Returns the mnemonic name of an opcode.
    357   static char const* Mnemonic(Value value);
    358 
    359   // Returns true if opcode for common operator.
    360   static bool IsCommonOpcode(Value value) {
    361     return kStart <= value && value <= kDead;
    362   }
    363 
    364   // Returns true if opcode for control operator.
    365   static bool IsControlOpcode(Value value) {
    366     return kStart <= value && value <= kEnd;
    367   }
    368 
    369   // Returns true if opcode for JavaScript operator.
    370   static bool IsJsOpcode(Value value) {
    371     return kJSEqual <= value && value <= kJSStackCheck;
    372   }
    373 
    374   // Returns true if opcode for constant operator.
    375   static bool IsConstantOpcode(Value value) {
    376     return kInt32Constant <= value && value <= kHeapConstant;
    377   }
    378 
    379   static bool IsPhiOpcode(Value value) {
    380     return value == kPhi || value == kEffectPhi;
    381   }
    382 
    383   static bool IsMergeOpcode(Value value) {
    384     return value == kMerge || value == kLoop;
    385   }
    386 
    387   static bool IsIfProjectionOpcode(Value value) {
    388     return kIfTrue <= value && value <= kIfDefault;
    389   }
    390 
    391   // Returns true if opcode can be inlined.
    392   static bool IsInlineeOpcode(Value value) {
    393     return value == kJSCallConstruct || value == kJSCallFunction;
    394   }
    395 
    396   // Returns true if opcode for comparison operator.
    397   static bool IsComparisonOpcode(Value value) {
    398     return (kJSEqual <= value && value <= kJSGreaterThanOrEqual) ||
    399            (kNumberEqual <= value && value <= kStringLessThanOrEqual) ||
    400            (kWord32Equal <= value && value <= kFloat64LessThanOrEqual);
    401   }
    402 };
    403 
    404 std::ostream& operator<<(std::ostream&, IrOpcode::Value);
    405 
    406 }  // namespace compiler
    407 }  // namespace internal
    408 }  // namespace v8
    409 
    410 #endif  // V8_COMPILER_OPCODES_H_
    411