opcodes.h 8.78 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_OPCODES_H_
#define V8_COMPILER_OPCODES_H_

// Opcodes for control operators.
9
#define INNER_CONTROL_OP_LIST(V) \
10 11 12 13 14 15 16 17
  V(Dead)                        \
  V(Loop)                        \
  V(Branch)                      \
  V(IfTrue)                      \
  V(IfFalse)                     \
  V(Merge)                       \
  V(Return)                      \
  V(Terminate)                   \
18
  V(Throw)
19

20 21 22 23 24
#define CONTROL_OP_LIST(V) \
  INNER_CONTROL_OP_LIST(V) \
  V(Start)                 \
  V(End)

25 26 27 28
// Opcodes for common operators.
#define LEAF_OP_LIST(V) \
  V(Int32Constant)      \
  V(Int64Constant)      \
29
  V(Float32Constant)    \
30 31 32 33 34 35
  V(Float64Constant)    \
  V(ExternalConstant)   \
  V(NumberConstant)     \
  V(HeapConstant)

#define INNER_OP_LIST(V) \
36
  V(Select)              \
37 38
  V(Phi)                 \
  V(EffectPhi)           \
39
  V(ValueEffect)         \
40
  V(Finish)              \
41
  V(FrameState)          \
42
  V(StateValues)         \
43
  V(Call)                \
44
  V(Parameter)           \
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
  V(Projection)

#define COMMON_OP_LIST(V) \
  LEAF_OP_LIST(V)         \
  INNER_OP_LIST(V)

// Opcodes for JavaScript operators.
#define JS_COMPARE_BINOP_LIST(V) \
  V(JSEqual)                     \
  V(JSNotEqual)                  \
  V(JSStrictEqual)               \
  V(JSStrictNotEqual)            \
  V(JSLessThan)                  \
  V(JSGreaterThan)               \
  V(JSLessThanOrEqual)           \
  V(JSGreaterThanOrEqual)

#define JS_BITWISE_BINOP_LIST(V) \
  V(JSBitwiseOr)                 \
  V(JSBitwiseXor)                \
  V(JSBitwiseAnd)                \
  V(JSShiftLeft)                 \
  V(JSShiftRight)                \
  V(JSShiftRightLogical)

#define JS_ARITH_BINOP_LIST(V) \
  V(JSAdd)                     \
  V(JSSubtract)                \
  V(JSMultiply)                \
  V(JSDivide)                  \
  V(JSModulus)

#define JS_SIMPLE_BINOP_LIST(V) \
  JS_COMPARE_BINOP_LIST(V)      \
  JS_BITWISE_BINOP_LIST(V)      \
  JS_ARITH_BINOP_LIST(V)

#define JS_LOGIC_UNOP_LIST(V) V(JSUnaryNot)

#define JS_CONVERSION_UNOP_LIST(V) \
  V(JSToBoolean)                   \
  V(JSToNumber)                    \
  V(JSToString)                    \
  V(JSToName)                      \
  V(JSToObject)

91 92
#define JS_OTHER_UNOP_LIST(V) \
  V(JSTypeOf)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

#define JS_SIMPLE_UNOP_LIST(V) \
  JS_LOGIC_UNOP_LIST(V)        \
  JS_CONVERSION_UNOP_LIST(V)   \
  JS_OTHER_UNOP_LIST(V)

#define JS_OBJECT_OP_LIST(V) \
  V(JSCreate)                \
  V(JSLoadProperty)          \
  V(JSLoadNamed)             \
  V(JSStoreProperty)         \
  V(JSStoreNamed)            \
  V(JSDeleteProperty)        \
  V(JSHasProperty)           \
  V(JSInstanceOf)

#define JS_CONTEXT_OP_LIST(V) \
  V(JSLoadContext)            \
  V(JSStoreContext)           \
  V(JSCreateFunctionContext)  \
  V(JSCreateCatchContext)     \
  V(JSCreateWithContext)      \
  V(JSCreateBlockContext)     \
  V(JSCreateModuleContext)    \
  V(JSCreateGlobalContext)

#define JS_OTHER_OP_LIST(V) \
  V(JSCallConstruct)        \
  V(JSCallFunction)         \
  V(JSCallRuntime)          \
  V(JSYield)                \
  V(JSDebugger)

#define JS_OP_LIST(V)     \
  JS_SIMPLE_BINOP_LIST(V) \
  JS_SIMPLE_UNOP_LIST(V)  \
  JS_OBJECT_OP_LIST(V)    \
  JS_CONTEXT_OP_LIST(V)   \
  JS_OTHER_OP_LIST(V)

// Opcodes for VirtuaMachine-level operators.
#define SIMPLIFIED_OP_LIST(V) \
  V(BooleanNot)               \
136
  V(BooleanToNumber)          \
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  V(NumberEqual)              \
  V(NumberLessThan)           \
  V(NumberLessThanOrEqual)    \
  V(NumberAdd)                \
  V(NumberSubtract)           \
  V(NumberMultiply)           \
  V(NumberDivide)             \
  V(NumberModulus)            \
  V(NumberToInt32)            \
  V(NumberToUint32)           \
  V(ReferenceEqual)           \
  V(StringEqual)              \
  V(StringLessThan)           \
  V(StringLessThanOrEqual)    \
  V(StringAdd)                \
  V(ChangeTaggedToInt32)      \
  V(ChangeTaggedToUint32)     \
  V(ChangeTaggedToFloat64)    \
  V(ChangeInt32ToTagged)      \
  V(ChangeUint32ToTagged)     \
  V(ChangeFloat64ToTagged)    \
  V(ChangeBoolToBit)          \
  V(ChangeBitToBool)          \
  V(LoadField)                \
  V(LoadElement)              \
  V(StoreField)               \
163 164 165
  V(StoreElement)             \
  V(ObjectIsSmi)              \
  V(ObjectIsNonNegativeSmi)
166 167

// Opcodes for Machine-level operators.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
#define MACHINE_OP_LIST(V)    \
  V(Load)                     \
  V(Store)                    \
  V(Word32And)                \
  V(Word32Or)                 \
  V(Word32Xor)                \
  V(Word32Shl)                \
  V(Word32Shr)                \
  V(Word32Sar)                \
  V(Word32Ror)                \
  V(Word32Equal)              \
  V(Word64And)                \
  V(Word64Or)                 \
  V(Word64Xor)                \
  V(Word64Shl)                \
  V(Word64Shr)                \
  V(Word64Sar)                \
  V(Word64Ror)                \
  V(Word64Equal)              \
  V(Int32Add)                 \
  V(Int32AddWithOverflow)     \
  V(Int32Sub)                 \
  V(Int32SubWithOverflow)     \
  V(Int32Mul)                 \
192
  V(Int32MulHigh)             \
193 194 195 196
  V(Int32Div)                 \
  V(Int32Mod)                 \
  V(Int32LessThan)            \
  V(Int32LessThanOrEqual)     \
197
  V(Uint32Div)                \
198 199
  V(Uint32LessThan)           \
  V(Uint32LessThanOrEqual)    \
200
  V(Uint32Mod)                \
201
  V(Uint32MulHigh)            \
202 203 204 205 206 207 208
  V(Int64Add)                 \
  V(Int64Sub)                 \
  V(Int64Mul)                 \
  V(Int64Div)                 \
  V(Int64Mod)                 \
  V(Int64LessThan)            \
  V(Int64LessThanOrEqual)     \
209
  V(Uint64Div)                \
210
  V(Uint64LessThan)           \
211
  V(Uint64Mod)                \
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
  V(ChangeFloat32ToFloat64)   \
  V(ChangeFloat64ToInt32)     \
  V(ChangeFloat64ToUint32)    \
  V(ChangeInt32ToFloat64)     \
  V(ChangeInt32ToInt64)       \
  V(ChangeUint32ToFloat64)    \
  V(ChangeUint32ToUint64)     \
  V(TruncateFloat64ToFloat32) \
  V(TruncateFloat64ToInt32)   \
  V(TruncateInt64ToInt32)     \
  V(Float64Add)               \
  V(Float64Sub)               \
  V(Float64Mul)               \
  V(Float64Div)               \
  V(Float64Mod)               \
227
  V(Float64Sqrt)              \
228 229
  V(Float64Equal)             \
  V(Float64LessThan)          \
230
  V(Float64LessThanOrEqual)   \
231 232 233 234
  V(Float64Floor)             \
  V(Float64Ceil)              \
  V(Float64RoundTruncate)     \
  V(Float64RoundTiesAway)     \
235
  V(LoadStackPointer)
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

#define VALUE_OP_LIST(V) \
  COMMON_OP_LIST(V)      \
  SIMPLIFIED_OP_LIST(V)  \
  MACHINE_OP_LIST(V)     \
  JS_OP_LIST(V)

// The combination of all operators at all levels and the common operators.
#define ALL_OP_LIST(V) \
  CONTROL_OP_LIST(V)   \
  VALUE_OP_LIST(V)

namespace v8 {
namespace internal {
namespace compiler {

// Declare an enumeration with all the opcodes at all levels so that they
// can be globally, uniquely numbered.
class IrOpcode {
 public:
  enum Value {
#define DECLARE_OPCODE(x) k##x,
    ALL_OP_LIST(DECLARE_OPCODE)
#undef DECLARE_OPCODE
    kLast = -1
#define COUNT_OPCODE(x) +1
            ALL_OP_LIST(COUNT_OPCODE)
#undef COUNT_OPCODE
  };

  // Returns the mnemonic name of an opcode.
  static const char* Mnemonic(Value val) {
268
    // TODO(turbofan): make this a table lookup.
269 270 271 272 273 274 275 276 277 278 279 280 281
    switch (val) {
#define RETURN_NAME(x) \
  case k##x:           \
    return #x;
      ALL_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
      default:
        return "UnknownOpcode";
    }
  }

  static bool IsJsOpcode(Value val) {
    switch (val) {
282
// TODO(turbofan): make this a range check.
283 284 285 286 287 288 289 290 291 292 293 294
#define RETURN_NAME(x) \
  case k##x:           \
    return true;
      JS_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
      default:
        return false;
    }
  }

  static bool IsControlOpcode(Value val) {
    switch (val) {
295
// TODO(turbofan): make this a range check.
296 297 298 299 300 301 302 303 304 305
#define RETURN_NAME(x) \
  case k##x:           \
    return true;
      CONTROL_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
      default:
        return false;
    }
  }

306 307
  static bool IsLeafOpcode(Value val) {
    switch (val) {
308
// TODO(turbofan): make this a table lookup.
309 310 311 312 313 314 315 316 317 318
#define RETURN_NAME(x) \
  case k##x:           \
    return true;
      LEAF_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
      default:
        return false;
    }
  }

319 320
  static bool IsCommonOpcode(Value val) {
    switch (val) {
321
// TODO(turbofan): make this a table lookup or a range check.
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
#define RETURN_NAME(x) \
  case k##x:           \
    return true;
      CONTROL_OP_LIST(RETURN_NAME)
      COMMON_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
      default:
        return false;
    }
  }
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_OPCODES_H_