machine-operator.cc 50.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2014 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.

#include "src/compiler/machine-operator.h"

#include "src/base/lazy-instance.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/operator.h"

namespace v8 {
namespace internal {
namespace compiler {

15
bool operator==(StoreRepresentation lhs, StoreRepresentation rhs) {
16
  return lhs.representation() == rhs.representation() &&
17
         lhs.write_barrier_kind() == rhs.write_barrier_kind();
18 19 20
}


21 22 23
bool operator!=(StoreRepresentation lhs, StoreRepresentation rhs) {
  return !(lhs == rhs);
}
24 25


26
size_t hash_value(StoreRepresentation rep) {
27
  return base::hash_combine(rep.representation(), rep.write_barrier_kind());
28 29 30 31
}


std::ostream& operator<<(std::ostream& os, StoreRepresentation rep) {
32
  return os << "(" << rep.representation() << " : " << rep.write_barrier_kind()
33 34
            << ")";
}
35 36


37
LoadRepresentation LoadRepresentationOf(Operator const* op) {
38
  DCHECK(IrOpcode::kLoad == op->opcode() ||
39
         IrOpcode::kProtectedLoad == op->opcode() ||
40
         IrOpcode::kAtomicLoad == op->opcode());
41 42 43 44
  return OpParameter<LoadRepresentation>(op);
}


45
StoreRepresentation const& StoreRepresentationOf(Operator const* op) {
46 47
  DCHECK(IrOpcode::kStore == op->opcode() ||
         IrOpcode::kProtectedStore == op->opcode());
48 49 50
  return OpParameter<StoreRepresentation>(op);
}

51 52 53 54 55 56 57 58 59 60
UnalignedLoadRepresentation UnalignedLoadRepresentationOf(Operator const* op) {
  DCHECK_EQ(IrOpcode::kUnalignedLoad, op->opcode());
  return OpParameter<UnalignedLoadRepresentation>(op);
}

UnalignedStoreRepresentation const& UnalignedStoreRepresentationOf(
    Operator const* op) {
  DCHECK_EQ(IrOpcode::kUnalignedStore, op->opcode());
  return OpParameter<UnalignedStoreRepresentation>(op);
}
61

62 63 64 65 66 67 68 69 70 71 72
CheckedLoadRepresentation CheckedLoadRepresentationOf(Operator const* op) {
  DCHECK_EQ(IrOpcode::kCheckedLoad, op->opcode());
  return OpParameter<CheckedLoadRepresentation>(op);
}


CheckedStoreRepresentation CheckedStoreRepresentationOf(Operator const* op) {
  DCHECK_EQ(IrOpcode::kCheckedStore, op->opcode());
  return OpParameter<CheckedStoreRepresentation>(op);
}

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
bool operator==(StackSlotRepresentation lhs, StackSlotRepresentation rhs) {
  return lhs.size() == rhs.size() && lhs.alignment() == rhs.alignment();
}

bool operator!=(StackSlotRepresentation lhs, StackSlotRepresentation rhs) {
  return !(lhs == rhs);
}

size_t hash_value(StackSlotRepresentation rep) {
  return base::hash_combine(rep.size(), rep.alignment());
}

std::ostream& operator<<(std::ostream& os, StackSlotRepresentation rep) {
  return os << "(" << rep.size() << " : " << rep.alignment() << ")";
}

StackSlotRepresentation const& StackSlotRepresentationOf(Operator const* op) {
90
  DCHECK_EQ(IrOpcode::kStackSlot, op->opcode());
91
  return OpParameter<StackSlotRepresentation>(op);
92
}
93

94 95 96 97 98
MachineRepresentation AtomicStoreRepresentationOf(Operator const* op) {
  DCHECK_EQ(IrOpcode::kAtomicStore, op->opcode());
  return OpParameter<MachineRepresentation>(op);
}

99
MachineType AtomicOpRepresentationOf(Operator const* op) {
100 101 102
  return OpParameter<MachineType>(op);
}

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 136 137 138 139 140 141 142 143 144 145 146
#define PURE_BINARY_OP_LIST_32(V)                                           \
  V(Word32And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)    \
  V(Word32Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
  V(Word32Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)    \
  V(Word32Shl, Operator::kNoProperties, 2, 0, 1)                            \
  V(Word32Shr, Operator::kNoProperties, 2, 0, 1)                            \
  V(Word32Sar, Operator::kNoProperties, 2, 0, 1)                            \
  V(Word32Ror, Operator::kNoProperties, 2, 0, 1)                            \
  V(Word32Equal, Operator::kCommutative, 2, 0, 1)                           \
  V(Int32Add, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
  V(Int32Sub, Operator::kNoProperties, 2, 0, 1)                             \
  V(Int32Mul, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
  V(Int32MulHigh, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Int32Div, Operator::kNoProperties, 2, 1, 1)                             \
  V(Int32Mod, Operator::kNoProperties, 2, 1, 1)                             \
  V(Int32LessThan, Operator::kNoProperties, 2, 0, 1)                        \
  V(Int32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)                 \
  V(Uint32Div, Operator::kNoProperties, 2, 1, 1)                            \
  V(Uint32LessThan, Operator::kNoProperties, 2, 0, 1)                       \
  V(Uint32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)                \
  V(Uint32Mod, Operator::kNoProperties, 2, 1, 1)                            \
  V(Uint32MulHigh, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)

#define PURE_BINARY_OP_LIST_64(V)                                        \
  V(Word64And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Word64Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
  V(Word64Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Word64Shl, Operator::kNoProperties, 2, 0, 1)                         \
  V(Word64Shr, Operator::kNoProperties, 2, 0, 1)                         \
  V(Word64Sar, Operator::kNoProperties, 2, 0, 1)                         \
  V(Word64Ror, Operator::kNoProperties, 2, 0, 1)                         \
  V(Word64Equal, Operator::kCommutative, 2, 0, 1)                        \
  V(Int64Add, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
  V(Int64Sub, Operator::kNoProperties, 2, 0, 1)                          \
  V(Int64Mul, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
  V(Int64Div, Operator::kNoProperties, 2, 1, 1)                          \
  V(Int64Mod, Operator::kNoProperties, 2, 1, 1)                          \
  V(Int64LessThan, Operator::kNoProperties, 2, 0, 1)                     \
  V(Int64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
  V(Uint64Div, Operator::kNoProperties, 2, 1, 1)                         \
  V(Uint64Mod, Operator::kNoProperties, 2, 1, 1)                         \
  V(Uint64LessThan, Operator::kNoProperties, 2, 0, 1)                    \
  V(Uint64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)

147
#define MACHINE_PURE_OP_LIST(V)                                           \
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
  PURE_BINARY_OP_LIST_32(V)                                               \
  PURE_BINARY_OP_LIST_64(V)                                               \
  V(Word32Clz, Operator::kNoProperties, 1, 0, 1)                          \
  V(Word64Clz, Operator::kNoProperties, 1, 0, 1)                          \
  V(BitcastTaggedToWord, Operator::kNoProperties, 1, 0, 1)                \
  V(BitcastWordToTaggedSigned, Operator::kNoProperties, 1, 0, 1)          \
  V(TruncateFloat64ToWord32, Operator::kNoProperties, 1, 0, 1)            \
  V(ChangeFloat32ToFloat64, Operator::kNoProperties, 1, 0, 1)             \
  V(ChangeFloat64ToInt32, Operator::kNoProperties, 1, 0, 1)               \
  V(ChangeFloat64ToUint32, Operator::kNoProperties, 1, 0, 1)              \
  V(ChangeFloat64ToUint64, Operator::kNoProperties, 1, 0, 1)              \
  V(TruncateFloat64ToUint32, Operator::kNoProperties, 1, 0, 1)            \
  V(TruncateFloat32ToInt32, Operator::kNoProperties, 1, 0, 1)             \
  V(TruncateFloat32ToUint32, Operator::kNoProperties, 1, 0, 1)            \
  V(TryTruncateFloat32ToInt64, Operator::kNoProperties, 1, 0, 2)          \
  V(TryTruncateFloat64ToInt64, Operator::kNoProperties, 1, 0, 2)          \
  V(TryTruncateFloat32ToUint64, Operator::kNoProperties, 1, 0, 2)         \
  V(TryTruncateFloat64ToUint64, Operator::kNoProperties, 1, 0, 2)         \
  V(ChangeInt32ToFloat64, Operator::kNoProperties, 1, 0, 1)               \
  V(Float64SilenceNaN, Operator::kNoProperties, 1, 0, 1)                  \
  V(RoundFloat64ToInt32, Operator::kNoProperties, 1, 0, 1)                \
  V(RoundInt32ToFloat32, Operator::kNoProperties, 1, 0, 1)                \
  V(RoundInt64ToFloat32, Operator::kNoProperties, 1, 0, 1)                \
  V(RoundInt64ToFloat64, Operator::kNoProperties, 1, 0, 1)                \
  V(RoundUint32ToFloat32, Operator::kNoProperties, 1, 0, 1)               \
  V(RoundUint64ToFloat32, Operator::kNoProperties, 1, 0, 1)               \
  V(RoundUint64ToFloat64, Operator::kNoProperties, 1, 0, 1)               \
  V(ChangeInt32ToInt64, Operator::kNoProperties, 1, 0, 1)                 \
  V(ChangeUint32ToFloat64, Operator::kNoProperties, 1, 0, 1)              \
  V(ChangeUint32ToUint64, Operator::kNoProperties, 1, 0, 1)               \
  V(TruncateFloat64ToFloat32, Operator::kNoProperties, 1, 0, 1)           \
  V(TruncateInt64ToInt32, Operator::kNoProperties, 1, 0, 1)               \
  V(BitcastFloat32ToInt32, Operator::kNoProperties, 1, 0, 1)              \
  V(BitcastFloat64ToInt64, Operator::kNoProperties, 1, 0, 1)              \
  V(BitcastInt32ToFloat32, Operator::kNoProperties, 1, 0, 1)              \
  V(BitcastInt64ToFloat64, Operator::kNoProperties, 1, 0, 1)              \
  V(Float32Abs, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float32Add, Operator::kCommutative, 2, 0, 1)                          \
  V(Float32Sub, Operator::kNoProperties, 2, 0, 1)                         \
  V(Float32Mul, Operator::kCommutative, 2, 0, 1)                          \
  V(Float32Div, Operator::kNoProperties, 2, 0, 1)                         \
  V(Float32Neg, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float32Sqrt, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float32Max, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Float32Min, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Float64Abs, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Acos, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Acosh, Operator::kNoProperties, 1, 0, 1)                       \
  V(Float64Asin, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Asinh, Operator::kNoProperties, 1, 0, 1)                       \
  V(Float64Atan, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Atan2, Operator::kNoProperties, 2, 0, 1)                       \
  V(Float64Atanh, Operator::kNoProperties, 1, 0, 1)                       \
  V(Float64Cbrt, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Cos, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Cosh, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Exp, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Expm1, Operator::kNoProperties, 1, 0, 1)                       \
  V(Float64Log, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Log1p, Operator::kNoProperties, 1, 0, 1)                       \
  V(Float64Log2, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Log10, Operator::kNoProperties, 1, 0, 1)                       \
  V(Float64Max, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Float64Min, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
  V(Float64Neg, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Add, Operator::kCommutative, 2, 0, 1)                          \
  V(Float64Sub, Operator::kNoProperties, 2, 0, 1)                         \
  V(Float64Mul, Operator::kCommutative, 2, 0, 1)                          \
  V(Float64Div, Operator::kNoProperties, 2, 0, 1)                         \
  V(Float64Mod, Operator::kNoProperties, 2, 0, 1)                         \
  V(Float64Pow, Operator::kNoProperties, 2, 0, 1)                         \
  V(Float64Sin, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Sinh, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Sqrt, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float64Tan, Operator::kNoProperties, 1, 0, 1)                         \
  V(Float64Tanh, Operator::kNoProperties, 1, 0, 1)                        \
  V(Float32Equal, Operator::kCommutative, 2, 0, 1)                        \
  V(Float32LessThan, Operator::kNoProperties, 2, 0, 1)                    \
  V(Float32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)             \
  V(Float64Equal, Operator::kCommutative, 2, 0, 1)                        \
  V(Float64LessThan, Operator::kNoProperties, 2, 0, 1)                    \
  V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)             \
  V(Float64ExtractLowWord32, Operator::kNoProperties, 1, 0, 1)            \
  V(Float64ExtractHighWord32, Operator::kNoProperties, 1, 0, 1)           \
  V(Float64InsertLowWord32, Operator::kNoProperties, 2, 0, 1)             \
  V(Float64InsertHighWord32, Operator::kNoProperties, 2, 0, 1)            \
  V(LoadStackPointer, Operator::kNoProperties, 0, 0, 1)                   \
  V(LoadFramePointer, Operator::kNoProperties, 0, 0, 1)                   \
  V(LoadParentFramePointer, Operator::kNoProperties, 0, 0, 1)             \
  V(Int32PairAdd, Operator::kNoProperties, 4, 0, 2)                       \
  V(Int32PairSub, Operator::kNoProperties, 4, 0, 2)                       \
  V(Int32PairMul, Operator::kNoProperties, 4, 0, 2)                       \
  V(Word32PairShl, Operator::kNoProperties, 3, 0, 2)                      \
  V(Word32PairShr, Operator::kNoProperties, 3, 0, 2)                      \
  V(Word32PairSar, Operator::kNoProperties, 3, 0, 2)                      \
  V(F32x4Splat, Operator::kNoProperties, 1, 0, 1)                         \
  V(F32x4SConvertI32x4, Operator::kNoProperties, 1, 0, 1)                 \
  V(F32x4UConvertI32x4, Operator::kNoProperties, 1, 0, 1)                 \
  V(F32x4Abs, Operator::kNoProperties, 1, 0, 1)                           \
  V(F32x4Neg, Operator::kNoProperties, 1, 0, 1)                           \
  V(F32x4RecipApprox, Operator::kNoProperties, 1, 0, 1)                   \
  V(F32x4RecipSqrtApprox, Operator::kNoProperties, 1, 0, 1)               \
  V(F32x4Add, Operator::kCommutative, 2, 0, 1)                            \
251
  V(F32x4AddHoriz, Operator::kNoProperties, 2, 0, 1)                      \
252 253 254 255 256 257 258 259 260 261
  V(F32x4Sub, Operator::kNoProperties, 2, 0, 1)                           \
  V(F32x4Mul, Operator::kCommutative, 2, 0, 1)                            \
  V(F32x4Min, Operator::kCommutative, 2, 0, 1)                            \
  V(F32x4Max, Operator::kCommutative, 2, 0, 1)                            \
  V(F32x4Eq, Operator::kCommutative, 2, 0, 1)                             \
  V(F32x4Ne, Operator::kCommutative, 2, 0, 1)                             \
  V(F32x4Lt, Operator::kNoProperties, 2, 0, 1)                            \
  V(F32x4Le, Operator::kNoProperties, 2, 0, 1)                            \
  V(I32x4Splat, Operator::kNoProperties, 1, 0, 1)                         \
  V(I32x4SConvertF32x4, Operator::kNoProperties, 1, 0, 1)                 \
262 263
  V(I32x4SConvertI16x8Low, Operator::kNoProperties, 1, 0, 1)              \
  V(I32x4SConvertI16x8High, Operator::kNoProperties, 1, 0, 1)             \
264 265
  V(I32x4Neg, Operator::kNoProperties, 1, 0, 1)                           \
  V(I32x4Add, Operator::kCommutative, 2, 0, 1)                            \
266
  V(I32x4AddHoriz, Operator::kNoProperties, 2, 0, 1)                      \
267 268 269 270 271 272
  V(I32x4Sub, Operator::kNoProperties, 2, 0, 1)                           \
  V(I32x4Mul, Operator::kCommutative, 2, 0, 1)                            \
  V(I32x4MinS, Operator::kCommutative, 2, 0, 1)                           \
  V(I32x4MaxS, Operator::kCommutative, 2, 0, 1)                           \
  V(I32x4Eq, Operator::kCommutative, 2, 0, 1)                             \
  V(I32x4Ne, Operator::kCommutative, 2, 0, 1)                             \
273 274
  V(I32x4GtS, Operator::kNoProperties, 2, 0, 1)                           \
  V(I32x4GeS, Operator::kNoProperties, 2, 0, 1)                           \
275
  V(I32x4UConvertF32x4, Operator::kNoProperties, 1, 0, 1)                 \
276 277
  V(I32x4UConvertI16x8Low, Operator::kNoProperties, 1, 0, 1)              \
  V(I32x4UConvertI16x8High, Operator::kNoProperties, 1, 0, 1)             \
278 279
  V(I32x4MinU, Operator::kCommutative, 2, 0, 1)                           \
  V(I32x4MaxU, Operator::kCommutative, 2, 0, 1)                           \
280 281
  V(I32x4GtU, Operator::kNoProperties, 2, 0, 1)                           \
  V(I32x4GeU, Operator::kNoProperties, 2, 0, 1)                           \
282
  V(I16x8Splat, Operator::kNoProperties, 1, 0, 1)                         \
283 284
  V(I16x8SConvertI8x16Low, Operator::kNoProperties, 1, 0, 1)              \
  V(I16x8SConvertI8x16High, Operator::kNoProperties, 1, 0, 1)             \
285
  V(I16x8Neg, Operator::kNoProperties, 1, 0, 1)                           \
286
  V(I16x8SConvertI32x4, Operator::kNoProperties, 2, 0, 1)                 \
287 288
  V(I16x8Add, Operator::kCommutative, 2, 0, 1)                            \
  V(I16x8AddSaturateS, Operator::kCommutative, 2, 0, 1)                   \
289
  V(I16x8AddHoriz, Operator::kNoProperties, 2, 0, 1)                      \
290 291 292 293 294 295 296
  V(I16x8Sub, Operator::kNoProperties, 2, 0, 1)                           \
  V(I16x8SubSaturateS, Operator::kNoProperties, 2, 0, 1)                  \
  V(I16x8Mul, Operator::kCommutative, 2, 0, 1)                            \
  V(I16x8MinS, Operator::kCommutative, 2, 0, 1)                           \
  V(I16x8MaxS, Operator::kCommutative, 2, 0, 1)                           \
  V(I16x8Eq, Operator::kCommutative, 2, 0, 1)                             \
  V(I16x8Ne, Operator::kCommutative, 2, 0, 1)                             \
297 298
  V(I16x8GtS, Operator::kNoProperties, 2, 0, 1)                           \
  V(I16x8GeS, Operator::kNoProperties, 2, 0, 1)                           \
299 300 301
  V(I16x8UConvertI8x16Low, Operator::kNoProperties, 1, 0, 1)              \
  V(I16x8UConvertI8x16High, Operator::kNoProperties, 1, 0, 1)             \
  V(I16x8UConvertI32x4, Operator::kNoProperties, 2, 0, 1)                 \
302 303 304 305
  V(I16x8AddSaturateU, Operator::kCommutative, 2, 0, 1)                   \
  V(I16x8SubSaturateU, Operator::kNoProperties, 2, 0, 1)                  \
  V(I16x8MinU, Operator::kCommutative, 2, 0, 1)                           \
  V(I16x8MaxU, Operator::kCommutative, 2, 0, 1)                           \
306 307
  V(I16x8GtU, Operator::kNoProperties, 2, 0, 1)                           \
  V(I16x8GeU, Operator::kNoProperties, 2, 0, 1)                           \
308 309
  V(I8x16Splat, Operator::kNoProperties, 1, 0, 1)                         \
  V(I8x16Neg, Operator::kNoProperties, 1, 0, 1)                           \
310
  V(I8x16SConvertI16x8, Operator::kNoProperties, 2, 0, 1)                 \
311 312 313 314 315 316 317 318 319
  V(I8x16Add, Operator::kCommutative, 2, 0, 1)                            \
  V(I8x16AddSaturateS, Operator::kCommutative, 2, 0, 1)                   \
  V(I8x16Sub, Operator::kNoProperties, 2, 0, 1)                           \
  V(I8x16SubSaturateS, Operator::kNoProperties, 2, 0, 1)                  \
  V(I8x16Mul, Operator::kCommutative, 2, 0, 1)                            \
  V(I8x16MinS, Operator::kCommutative, 2, 0, 1)                           \
  V(I8x16MaxS, Operator::kCommutative, 2, 0, 1)                           \
  V(I8x16Eq, Operator::kCommutative, 2, 0, 1)                             \
  V(I8x16Ne, Operator::kCommutative, 2, 0, 1)                             \
320 321
  V(I8x16GtS, Operator::kNoProperties, 2, 0, 1)                           \
  V(I8x16GeS, Operator::kNoProperties, 2, 0, 1)                           \
322
  V(I8x16UConvertI16x8, Operator::kNoProperties, 2, 0, 1)                 \
323 324 325 326
  V(I8x16AddSaturateU, Operator::kCommutative, 2, 0, 1)                   \
  V(I8x16SubSaturateU, Operator::kNoProperties, 2, 0, 1)                  \
  V(I8x16MinU, Operator::kCommutative, 2, 0, 1)                           \
  V(I8x16MaxU, Operator::kCommutative, 2, 0, 1)                           \
327 328
  V(I8x16GtU, Operator::kNoProperties, 2, 0, 1)                           \
  V(I8x16GeU, Operator::kNoProperties, 2, 0, 1)                           \
329 330 331 332 333 334 335
  V(S128Load, Operator::kNoProperties, 2, 0, 1)                           \
  V(S128Store, Operator::kNoProperties, 3, 0, 1)                          \
  V(S128Zero, Operator::kNoProperties, 0, 0, 1)                           \
  V(S128And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)    \
  V(S128Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
  V(S128Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)    \
  V(S128Not, Operator::kNoProperties, 1, 0, 1)                            \
336
  V(S128Select, Operator::kNoProperties, 3, 0, 1)                         \
337 338 339 340 341 342
  V(S1x4AnyTrue, Operator::kNoProperties, 1, 0, 1)                        \
  V(S1x4AllTrue, Operator::kNoProperties, 1, 0, 1)                        \
  V(S1x8AnyTrue, Operator::kNoProperties, 1, 0, 1)                        \
  V(S1x8AllTrue, Operator::kNoProperties, 1, 0, 1)                        \
  V(S1x16AnyTrue, Operator::kNoProperties, 1, 0, 1)                       \
  V(S1x16AllTrue, Operator::kNoProperties, 1, 0, 1)
343

344
#define PURE_OPTIONAL_OP_LIST(V)                            \
345
  V(Word32Ctz, Operator::kNoProperties, 1, 0, 1)            \
346
  V(Word64Ctz, Operator::kNoProperties, 1, 0, 1)            \
347 348
  V(Word32ReverseBits, Operator::kNoProperties, 1, 0, 1)    \
  V(Word64ReverseBits, Operator::kNoProperties, 1, 0, 1)    \
349 350
  V(Word32ReverseBytes, Operator::kNoProperties, 1, 0, 1)   \
  V(Word64ReverseBytes, Operator::kNoProperties, 1, 0, 1)   \
351 352
  V(Int32AbsWithOverflow, Operator::kNoProperties, 1, 0, 1) \
  V(Int64AbsWithOverflow, Operator::kNoProperties, 1, 0, 1) \
353
  V(Word32Popcnt, Operator::kNoProperties, 1, 0, 1)         \
354
  V(Word64Popcnt, Operator::kNoProperties, 1, 0, 1)         \
355
  V(Float32RoundDown, Operator::kNoProperties, 1, 0, 1)     \
356
  V(Float64RoundDown, Operator::kNoProperties, 1, 0, 1)     \
357
  V(Float32RoundUp, Operator::kNoProperties, 1, 0, 1)       \
358
  V(Float64RoundUp, Operator::kNoProperties, 1, 0, 1)       \
359
  V(Float32RoundTruncate, Operator::kNoProperties, 1, 0, 1) \
360
  V(Float64RoundTruncate, Operator::kNoProperties, 1, 0, 1) \
361
  V(Float64RoundTiesAway, Operator::kNoProperties, 1, 0, 1) \
362
  V(Float32RoundTiesEven, Operator::kNoProperties, 1, 0, 1) \
363
  V(Float64RoundTiesEven, Operator::kNoProperties, 1, 0, 1)
364

365 366 367
#define OVERFLOW_OP_LIST(V)                                                \
  V(Int32AddWithOverflow, Operator::kAssociative | Operator::kCommutative) \
  V(Int32SubWithOverflow, Operator::kNoProperties)                         \
368
  V(Int32MulWithOverflow, Operator::kAssociative | Operator::kCommutative) \
369 370 371
  V(Int64AddWithOverflow, Operator::kAssociative | Operator::kCommutative) \
  V(Int64SubWithOverflow, Operator::kNoProperties)

372
#define MACHINE_TYPE_LIST(V) \
373 374
  V(Float32)                 \
  V(Float64)                 \
375
  V(Simd128)                 \
376 377 378 379 380 381 382 383 384
  V(Int8)                    \
  V(Uint8)                   \
  V(Int16)                   \
  V(Uint16)                  \
  V(Int32)                   \
  V(Uint32)                  \
  V(Int64)                   \
  V(Uint64)                  \
  V(Pointer)                 \
385 386
  V(TaggedSigned)            \
  V(TaggedPointer)           \
387
  V(AnyTagged)
388

389 390 391
#define MACHINE_REPRESENTATION_LIST(V) \
  V(kFloat32)                          \
  V(kFloat64)                          \
392
  V(kSimd128)                          \
393 394 395 396
  V(kWord8)                            \
  V(kWord16)                           \
  V(kWord32)                           \
  V(kWord64)                           \
397 398
  V(kTaggedSigned)                     \
  V(kTaggedPointer)                    \
399 400
  V(kTagged)

401 402 403 404 405 406 407 408
#define ATOMIC_TYPE_LIST(V) \
  V(Int8)                   \
  V(Uint8)                  \
  V(Int16)                  \
  V(Uint16)                 \
  V(Int32)                  \
  V(Uint32)

409 410 411 412 413
#define ATOMIC_REPRESENTATION_LIST(V) \
  V(kWord8)                           \
  V(kWord16)                          \
  V(kWord32)

414
#define SIMD_LANE_OP_LIST(V) \
415 416 417 418
  V(F32x4, 4)                \
  V(I32x4, 4)                \
  V(I16x8, 8)                \
  V(I8x16, 16)
419

420 421 422
#define SIMD_FORMAT_LIST(V) \
  V(32x4, 32)               \
  V(16x8, 16)               \
423
  V(8x16, 8)
424

425 426
#define STACK_SLOT_CACHED_SIZES_ALIGNMENTS_LIST(V) \
  V(4, 0) V(8, 0) V(16, 0) V(4, 4) V(8, 8) V(16, 16)
427

428 429 430 431 432 433
struct StackSlotOperator : public Operator1<StackSlotRepresentation> {
  explicit StackSlotOperator(int size, int alignment)
      : Operator1<StackSlotRepresentation>(
            IrOpcode::kStackSlot, Operator::kNoDeopt | Operator::kNoThrow,
            "StackSlot", 0, 0, 0, 1, 0, 0,
            StackSlotRepresentation(size, alignment)) {}
434 435
};

436 437 438
struct MachineOperatorGlobalCache {
#define PURE(Name, properties, value_input_count, control_input_count,         \
             output_count)                                                     \
439
  struct Name##Operator final : public Operator {                              \
440 441 442 443 444
    Name##Operator()                                                           \
        : Operator(IrOpcode::k##Name, Operator::kPure | properties, #Name,     \
                   value_input_count, 0, control_input_count, output_count, 0, \
                   0) {}                                                       \
  };                                                                           \
445
  Name##Operator k##Name;
446
  MACHINE_PURE_OP_LIST(PURE)
447
  PURE_OPTIONAL_OP_LIST(PURE)
448 449
#undef PURE

450 451 452 453 454 455 456 457 458 459 460
#define OVERFLOW_OP(Name, properties)                                        \
  struct Name##Operator final : public Operator {                            \
    Name##Operator()                                                         \
        : Operator(IrOpcode::k##Name,                                        \
                   Operator::kEliminatable | Operator::kNoRead | properties, \
                   #Name, 2, 0, 1, 2, 0, 0) {}                               \
  };                                                                         \
  Name##Operator k##Name;
  OVERFLOW_OP_LIST(OVERFLOW_OP)
#undef OVERFLOW_OP

461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
#define LOAD(Type)                                                            \
  struct Load##Type##Operator final : public Operator1<LoadRepresentation> {  \
    Load##Type##Operator()                                                    \
        : Operator1<LoadRepresentation>(                                      \
              IrOpcode::kLoad,                                                \
              Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,   \
              "Load", 2, 1, 1, 1, 1, 0, MachineType::Type()) {}               \
  };                                                                          \
  struct UnalignedLoad##Type##Operator final                                  \
      : public Operator1<UnalignedLoadRepresentation> {                       \
    UnalignedLoad##Type##Operator()                                           \
        : Operator1<UnalignedLoadRepresentation>(                             \
              IrOpcode::kUnalignedLoad,                                       \
              Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,   \
              "UnalignedLoad", 2, 1, 1, 1, 1, 0, MachineType::Type()) {}      \
  };                                                                          \
  struct CheckedLoad##Type##Operator final                                    \
      : public Operator1<CheckedLoadRepresentation> {                         \
    CheckedLoad##Type##Operator()                                             \
        : Operator1<CheckedLoadRepresentation>(                               \
              IrOpcode::kCheckedLoad,                                         \
              Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,   \
              "CheckedLoad", 3, 1, 1, 1, 1, 0, MachineType::Type()) {}        \
  };                                                                          \
  struct ProtectedLoad##Type##Operator final                                  \
      : public Operator1<LoadRepresentation> {                                \
    ProtectedLoad##Type##Operator()                                           \
        : Operator1<LoadRepresentation>(                                      \
              IrOpcode::kProtectedLoad,                                       \
490
              Operator::kNoDeopt | Operator::kNoThrow, "ProtectedLoad", 2, 1, \
491 492 493 494 495
              1, 1, 1, 0, MachineType::Type()) {}                             \
  };                                                                          \
  Load##Type##Operator kLoad##Type;                                           \
  UnalignedLoad##Type##Operator kUnalignedLoad##Type;                         \
  CheckedLoad##Type##Operator kCheckedLoad##Type;                             \
496
  ProtectedLoad##Type##Operator kProtectedLoad##Type;
497 498 499
  MACHINE_TYPE_LIST(LOAD)
#undef LOAD

500 501 502 503 504 505 506 507 508
#define STACKSLOT(Size, Alignment)                                     \
  struct StackSlotOfSize##Size##OfAlignment##Alignment##Operator final \
      : public StackSlotOperator {                                     \
    StackSlotOfSize##Size##OfAlignment##Alignment##Operator()          \
        : StackSlotOperator(Size, Alignment) {}                        \
  };                                                                   \
  StackSlotOfSize##Size##OfAlignment##Alignment##Operator              \
      kStackSlotOfSize##Size##OfAlignment##Alignment;
  STACK_SLOT_CACHED_SIZES_ALIGNMENTS_LIST(STACKSLOT)
509 510
#undef STACKSLOT

511 512 513 514
#define STORE(Type)                                                            \
  struct Store##Type##Operator : public Operator1<StoreRepresentation> {       \
    explicit Store##Type##Operator(WriteBarrierKind write_barrier_kind)        \
        : Operator1<StoreRepresentation>(                                      \
515 516
              IrOpcode::kStore,                                                \
              Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
517
              "Store", 3, 1, 1, 0, 1, 0,                                       \
518 519
              StoreRepresentation(MachineRepresentation::Type,                 \
                                  write_barrier_kind)) {}                      \
520
  };                                                                           \
521
  struct Store##Type##NoWriteBarrier##Operator final                           \
522 523 524 525
      : public Store##Type##Operator {                                         \
    Store##Type##NoWriteBarrier##Operator()                                    \
        : Store##Type##Operator(kNoWriteBarrier) {}                            \
  };                                                                           \
526 527 528 529 530 531 532 533 534 535
  struct Store##Type##MapWriteBarrier##Operator final                          \
      : public Store##Type##Operator {                                         \
    Store##Type##MapWriteBarrier##Operator()                                   \
        : Store##Type##Operator(kMapWriteBarrier) {}                           \
  };                                                                           \
  struct Store##Type##PointerWriteBarrier##Operator final                      \
      : public Store##Type##Operator {                                         \
    Store##Type##PointerWriteBarrier##Operator()                               \
        : Store##Type##Operator(kPointerWriteBarrier) {}                       \
  };                                                                           \
536
  struct Store##Type##FullWriteBarrier##Operator final                         \
537 538 539 540
      : public Store##Type##Operator {                                         \
    Store##Type##FullWriteBarrier##Operator()                                  \
        : Store##Type##Operator(kFullWriteBarrier) {}                          \
  };                                                                           \
541 542 543 544 545 546 547 548 549
  struct UnalignedStore##Type##Operator final                                  \
      : public Operator1<UnalignedStoreRepresentation> {                       \
    UnalignedStore##Type##Operator()                                           \
        : Operator1<UnalignedStoreRepresentation>(                             \
              IrOpcode::kUnalignedStore,                                       \
              Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
              "UnalignedStore", 3, 1, 1, 0, 1, 0,                              \
              MachineRepresentation::Type) {}                                  \
  };                                                                           \
550
  struct CheckedStore##Type##Operator final                                    \
551 552 553
      : public Operator1<CheckedStoreRepresentation> {                         \
    CheckedStore##Type##Operator()                                             \
        : Operator1<CheckedStoreRepresentation>(                               \
554 555
              IrOpcode::kCheckedStore,                                         \
              Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
556 557
              "CheckedStore", 4, 1, 1, 0, 1, 0, MachineRepresentation::Type) { \
    }                                                                          \
558
  };                                                                           \
559 560 561 562 563 564
  struct ProtectedStore##Type##Operator                                        \
      : public Operator1<StoreRepresentation> {                                \
    explicit ProtectedStore##Type##Operator()                                  \
        : Operator1<StoreRepresentation>(                                      \
              IrOpcode::kProtectedStore,                                       \
              Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
565
              "Store", 3, 1, 1, 0, 1, 0,                                       \
566 567 568
              StoreRepresentation(MachineRepresentation::Type,                 \
                                  kNoWriteBarrier)) {}                         \
  };                                                                           \
569
  Store##Type##NoWriteBarrier##Operator kStore##Type##NoWriteBarrier;          \
570 571 572
  Store##Type##MapWriteBarrier##Operator kStore##Type##MapWriteBarrier;        \
  Store##Type##PointerWriteBarrier##Operator                                   \
      kStore##Type##PointerWriteBarrier;                                       \
573
  Store##Type##FullWriteBarrier##Operator kStore##Type##FullWriteBarrier;      \
574
  UnalignedStore##Type##Operator kUnalignedStore##Type;                        \
575 576
  CheckedStore##Type##Operator kCheckedStore##Type;                            \
  ProtectedStore##Type##Operator kProtectedStore##Type;
577
  MACHINE_REPRESENTATION_LIST(STORE)
578
#undef STORE
579

580 581 582 583 584 585 586 587 588
#define ATOMIC_LOAD(Type)                                                   \
  struct AtomicLoad##Type##Operator final                                   \
      : public Operator1<LoadRepresentation> {                              \
    AtomicLoad##Type##Operator()                                            \
        : Operator1<LoadRepresentation>(                                    \
              IrOpcode::kAtomicLoad,                                        \
              Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite, \
              "AtomicLoad", 2, 1, 1, 1, 1, 0, MachineType::Type()) {}       \
  };                                                                        \
589
  AtomicLoad##Type##Operator kAtomicLoad##Type;
590 591 592 593 594 595 596 597
  ATOMIC_TYPE_LIST(ATOMIC_LOAD)
#undef ATOMIC_LOAD

#define ATOMIC_STORE(Type)                                                     \
  struct AtomicStore##Type##Operator                                           \
      : public Operator1<MachineRepresentation> {                              \
    AtomicStore##Type##Operator()                                              \
        : Operator1<MachineRepresentation>(                                    \
598 599
              IrOpcode::kAtomicStore,                                          \
              Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
600 601 602 603 604
              "AtomicStore", 3, 1, 1, 0, 1, 0, MachineRepresentation::Type) {} \
  };                                                                           \
  AtomicStore##Type##Operator kAtomicStore##Type;
  ATOMIC_REPRESENTATION_LIST(ATOMIC_STORE)
#undef STORE
605

606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
#define ATOMIC_OP(op, type)                                                    \
  struct op##type##Operator : public Operator1<MachineType> {                  \
    op##type##Operator()                                                       \
        : Operator1<MachineType>(IrOpcode::k##op,                              \
                                 Operator::kNoDeopt | Operator::kNoThrow, #op, \
                                 3, 1, 1, 1, 1, 0, MachineType::type()) {}     \
  };                                                                           \
  op##type##Operator k##op##type;
#define ATOMIC_OP_LIST(type)      \
  ATOMIC_OP(AtomicExchange, type) \
  ATOMIC_OP(AtomicAdd, type)      \
  ATOMIC_OP(AtomicSub, type)      \
  ATOMIC_OP(AtomicAnd, type)      \
  ATOMIC_OP(AtomicOr, type)       \
  ATOMIC_OP(AtomicXor, type)
  ATOMIC_TYPE_LIST(ATOMIC_OP_LIST)
#undef ATOMIC_OP_LIST
#undef ATOMIC_OP
624

625 626 627 628 629 630 631 632 633 634 635 636 637
#define ATOMIC_COMPARE_EXCHANGE(Type)                                       \
  struct AtomicCompareExchange##Type##Operator                              \
      : public Operator1<MachineType> {                                     \
    AtomicCompareExchange##Type##Operator()                                 \
        : Operator1<MachineType>(IrOpcode::kAtomicCompareExchange,          \
                                 Operator::kNoDeopt | Operator::kNoThrow,   \
                                 "AtomicCompareExchange", 4, 1, 1, 1, 1, 0, \
                                 MachineType::Type()) {}                    \
  };                                                                        \
  AtomicCompareExchange##Type##Operator kAtomicCompareExchange##Type;
  ATOMIC_TYPE_LIST(ATOMIC_COMPARE_EXCHANGE)
#undef ATOMIC_COMPARE_EXCHANGE

638 639 640 641 642 643 644 645 646 647 648 649 650
  // The {BitcastWordToTagged} operator must not be marked as pure (especially
  // not idempotent), because otherwise the splitting logic in the Scheduler
  // might decide to split these operators, thus potentially creating live
  // ranges of allocation top across calls or other things that might allocate.
  // See https://bugs.chromium.org/p/v8/issues/detail?id=6059 for more details.
  struct BitcastWordToTaggedOperator : public Operator {
    BitcastWordToTaggedOperator()
        : Operator(IrOpcode::kBitcastWordToTagged,
                   Operator::kEliminatable | Operator::kNoWrite,
                   "BitcastWordToTagged", 1, 0, 0, 1, 0, 0) {}
  };
  BitcastWordToTaggedOperator kBitcastWordToTagged;

651 652 653 654 655 656 657
  struct DebugAbortOperator : public Operator {
    DebugAbortOperator()
        : Operator(IrOpcode::kDebugAbort, Operator::kNoThrow, "DebugAbort", 1,
                   1, 1, 0, 1, 0) {}
  };
  DebugAbortOperator kDebugAbort;

658 659 660
  struct DebugBreakOperator : public Operator {
    DebugBreakOperator()
        : Operator(IrOpcode::kDebugBreak, Operator::kNoThrow, "DebugBreak", 0,
661
                   1, 1, 0, 1, 0) {}
662 663
  };
  DebugBreakOperator kDebugBreak;
664 665 666 667 668 669 670

  struct UnsafePointerAddOperator final : public Operator {
    UnsafePointerAddOperator()
        : Operator(IrOpcode::kUnsafePointerAdd, Operator::kKontrol,
                   "UnsafePointerAdd", 2, 1, 1, 1, 1, 0) {}
  };
  UnsafePointerAddOperator kUnsafePointerAdd;
671 672
};

673 674 675 676 677
struct CommentOperator : public Operator1<const char*> {
  explicit CommentOperator(const char* msg)
      : Operator1<const char*>(IrOpcode::kComment, Operator::kNoThrow,
                               "Comment", 0, 0, 0, 0, 0, 0, msg) {}
};
678

679 680
static base::LazyInstance<MachineOperatorGlobalCache>::type
    kMachineOperatorGlobalCache = LAZY_INSTANCE_INITIALIZER;
681

682 683 684
MachineOperatorBuilder::MachineOperatorBuilder(
    Zone* zone, MachineRepresentation word, Flags flags,
    AlignmentRequirements alignmentRequirements)
685
    : zone_(zone),
686
      cache_(kMachineOperatorGlobalCache.Get()),
687 688 689
      word_(word),
      flags_(flags),
      alignment_requirements_(alignmentRequirements) {
690 691
  DCHECK(word == MachineRepresentation::kWord32 ||
         word == MachineRepresentation::kWord64);
692 693
}

694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
const Operator* MachineOperatorBuilder::UnalignedLoad(
    UnalignedLoadRepresentation rep) {
#define LOAD(Type)                       \
  if (rep == MachineType::Type()) {      \
    return &cache_.kUnalignedLoad##Type; \
  }
  MACHINE_TYPE_LIST(LOAD)
#undef LOAD
  UNREACHABLE();
}

const Operator* MachineOperatorBuilder::UnalignedStore(
    UnalignedStoreRepresentation rep) {
  switch (rep) {
#define STORE(kRep)                 \
  case MachineRepresentation::kRep: \
    return &cache_.kUnalignedStore##kRep;
    MACHINE_REPRESENTATION_LIST(STORE)
#undef STORE
    case MachineRepresentation::kBit:
    case MachineRepresentation::kNone:
      break;
  }
  UNREACHABLE();
}
719

720 721 722
#define PURE(Name, properties, value_input_count, control_input_count, \
             output_count)                                             \
  const Operator* MachineOperatorBuilder::Name() { return &cache_.k##Name; }
723
MACHINE_PURE_OP_LIST(PURE)
724 725
#undef PURE

726 727 728 729
#define PURE(Name, properties, value_input_count, control_input_count, \
             output_count)                                             \
  const OptionalOperator MachineOperatorBuilder::Name() {              \
    return OptionalOperator(flags_ & k##Name, &cache_.k##Name);        \
730 731 732
  }
PURE_OPTIONAL_OP_LIST(PURE)
#undef PURE
733

734 735 736 737
#define OVERFLOW_OP(Name, properties) \
  const Operator* MachineOperatorBuilder::Name() { return &cache_.k##Name; }
OVERFLOW_OP_LIST(OVERFLOW_OP)
#undef OVERFLOW_OP
738

739
const Operator* MachineOperatorBuilder::Load(LoadRepresentation rep) {
740 741 742 743
#define LOAD(Type)                  \
  if (rep == MachineType::Type()) { \
    return &cache_.kLoad##Type;     \
  }
744 745
    MACHINE_TYPE_LIST(LOAD)
#undef LOAD
746
  UNREACHABLE();
747 748 749 750 751 752 753 754 755 756
}

const Operator* MachineOperatorBuilder::ProtectedLoad(LoadRepresentation rep) {
#define LOAD(Type)                       \
  if (rep == MachineType::Type()) {      \
    return &cache_.kProtectedLoad##Type; \
  }
  MACHINE_TYPE_LIST(LOAD)
#undef LOAD
  UNREACHABLE();
757 758
}

759
const Operator* MachineOperatorBuilder::StackSlot(int size, int alignment) {
760
  DCHECK_LE(0, size);
761 762 763 764
  DCHECK(alignment == 0 || alignment == 4 || alignment == 8 || alignment == 16);
#define CASE_CACHED_SIZE(Size, Alignment)                          \
  if (size == Size && alignment == Alignment) {                    \
    return &cache_.kStackSlotOfSize##Size##OfAlignment##Alignment; \
765
  }
766 767 768

  STACK_SLOT_CACHED_SIZES_ALIGNMENTS_LIST(CASE_CACHED_SIZE)

769
#undef CASE_CACHED_SIZE
770
  return new (zone_) StackSlotOperator(size, alignment);
771 772
}

773 774 775
const Operator* MachineOperatorBuilder::StackSlot(MachineRepresentation rep,
                                                  int alignment) {
  return StackSlot(1 << ElementSizeLog2Of(rep), alignment);
776
}
777

778
const Operator* MachineOperatorBuilder::Store(StoreRepresentation store_rep) {
779 780 781
  switch (store_rep.representation()) {
#define STORE(kRep)                                         \
  case MachineRepresentation::kRep:                         \
782
    switch (store_rep.write_barrier_kind()) {               \
783
      case kNoWriteBarrier:                                 \
784
        return &cache_.k##Store##kRep##NoWriteBarrier;      \
785
      case kMapWriteBarrier:                                \
786
        return &cache_.k##Store##kRep##MapWriteBarrier;     \
787
      case kPointerWriteBarrier:                            \
788
        return &cache_.k##Store##kRep##PointerWriteBarrier; \
789
      case kFullWriteBarrier:                               \
790
        return &cache_.k##Store##kRep##FullWriteBarrier;    \
791
    }                                                       \
792 793
    break;
    MACHINE_REPRESENTATION_LIST(STORE)
794
#undef STORE
795 796
    case MachineRepresentation::kBit:
    case MachineRepresentation::kNone:
797 798
      break;
  }
799
  UNREACHABLE();
800
}
801

802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
const Operator* MachineOperatorBuilder::ProtectedStore(
    MachineRepresentation rep) {
  switch (rep) {
#define STORE(kRep)                       \
  case MachineRepresentation::kRep:       \
    return &cache_.kProtectedStore##kRep; \
    break;
    MACHINE_REPRESENTATION_LIST(STORE)
#undef STORE
    case MachineRepresentation::kBit:
    case MachineRepresentation::kNone:
      break;
  }
  UNREACHABLE();
}

818 819 820 821
const Operator* MachineOperatorBuilder::UnsafePointerAdd() {
  return &cache_.kUnsafePointerAdd;
}

822 823 824 825
const Operator* MachineOperatorBuilder::BitcastWordToTagged() {
  return &cache_.kBitcastWordToTagged;
}

826 827 828 829
const Operator* MachineOperatorBuilder::DebugAbort() {
  return &cache_.kDebugAbort;
}

830 831 832
const Operator* MachineOperatorBuilder::DebugBreak() {
  return &cache_.kDebugBreak;
}
833

834 835 836 837
const Operator* MachineOperatorBuilder::Comment(const char* msg) {
  return new (zone_) CommentOperator(msg);
}

838 839
const Operator* MachineOperatorBuilder::CheckedLoad(
    CheckedLoadRepresentation rep) {
840 841 842 843
#define LOAD(Type)                     \
  if (rep == MachineType::Type()) {    \
    return &cache_.kCheckedLoad##Type; \
  }
844 845
    MACHINE_TYPE_LIST(LOAD)
#undef LOAD
846
  UNREACHABLE();
847 848 849 850 851
}


const Operator* MachineOperatorBuilder::CheckedStore(
    CheckedStoreRepresentation rep) {
852 853 854 855 856
  switch (rep) {
#define STORE(kRep)                 \
  case MachineRepresentation::kRep: \
    return &cache_.kCheckedStore##kRep;
    MACHINE_REPRESENTATION_LIST(STORE)
857
#undef STORE
858 859
    case MachineRepresentation::kBit:
    case MachineRepresentation::kNone:
860 861
      break;
  }
862
  UNREACHABLE();
863 864
}

865 866 867 868 869 870 871 872 873 874
const Operator* MachineOperatorBuilder::AtomicLoad(LoadRepresentation rep) {
#define LOAD(Type)                    \
  if (rep == MachineType::Type()) {   \
    return &cache_.kAtomicLoad##Type; \
  }
  ATOMIC_TYPE_LIST(LOAD)
#undef LOAD
  UNREACHABLE();
}

875 876 877 878 879 880 881 882 883 884
const Operator* MachineOperatorBuilder::AtomicStore(MachineRepresentation rep) {
#define STORE(kRep)                         \
  if (rep == MachineRepresentation::kRep) { \
    return &cache_.kAtomicStore##kRep;      \
  }
  ATOMIC_REPRESENTATION_LIST(STORE)
#undef STORE
  UNREACHABLE();
}

885 886 887 888 889 890 891 892 893 894
const Operator* MachineOperatorBuilder::AtomicExchange(MachineType rep) {
#define EXCHANGE(kRep)                    \
  if (rep == MachineType::kRep()) {       \
    return &cache_.kAtomicExchange##kRep; \
  }
  ATOMIC_TYPE_LIST(EXCHANGE)
#undef EXCHANGE
  UNREACHABLE();
}

895 896 897 898 899 900 901 902 903 904
const Operator* MachineOperatorBuilder::AtomicCompareExchange(MachineType rep) {
#define COMPARE_EXCHANGE(kRep)                   \
  if (rep == MachineType::kRep()) {              \
    return &cache_.kAtomicCompareExchange##kRep; \
  }
  ATOMIC_TYPE_LIST(COMPARE_EXCHANGE)
#undef COMPARE_EXCHANGE
  UNREACHABLE();
}

905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
const Operator* MachineOperatorBuilder::AtomicAdd(MachineType rep) {
#define ADD(kRep)                    \
  if (rep == MachineType::kRep()) {  \
    return &cache_.kAtomicAdd##kRep; \
  }
  ATOMIC_TYPE_LIST(ADD)
#undef ADD
  UNREACHABLE();
}

const Operator* MachineOperatorBuilder::AtomicSub(MachineType rep) {
#define SUB(kRep)                    \
  if (rep == MachineType::kRep()) {  \
    return &cache_.kAtomicSub##kRep; \
  }
  ATOMIC_TYPE_LIST(SUB)
#undef SUB
  UNREACHABLE();
}

const Operator* MachineOperatorBuilder::AtomicAnd(MachineType rep) {
#define AND(kRep)                    \
  if (rep == MachineType::kRep()) {  \
    return &cache_.kAtomicAnd##kRep; \
  }
  ATOMIC_TYPE_LIST(AND)
#undef AND
  UNREACHABLE();
}

const Operator* MachineOperatorBuilder::AtomicOr(MachineType rep) {
#define OR(kRep)                    \
  if (rep == MachineType::kRep()) { \
    return &cache_.kAtomicOr##kRep; \
  }
  ATOMIC_TYPE_LIST(OR)
#undef OR
  UNREACHABLE();
}

const Operator* MachineOperatorBuilder::AtomicXor(MachineType rep) {
#define XOR(kRep)                    \
  if (rep == MachineType::kRep()) {  \
    return &cache_.kAtomicXor##kRep; \
  }
  ATOMIC_TYPE_LIST(XOR)
#undef XOR
  UNREACHABLE();
}

955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
#define SIMD_LANE_OPS(Type, lane_count)                                     \
  const Operator* MachineOperatorBuilder::Type##ExtractLane(                \
      int32_t lane_index) {                                                 \
    DCHECK(0 <= lane_index && lane_index < lane_count);                     \
    return new (zone_)                                                      \
        Operator1<int32_t>(IrOpcode::k##Type##ExtractLane, Operator::kPure, \
                           "Extract lane", 1, 0, 0, 1, 0, 0, lane_index);   \
  }                                                                         \
  const Operator* MachineOperatorBuilder::Type##ReplaceLane(                \
      int32_t lane_index) {                                                 \
    DCHECK(0 <= lane_index && lane_index < lane_count);                     \
    return new (zone_)                                                      \
        Operator1<int32_t>(IrOpcode::k##Type##ReplaceLane, Operator::kPure, \
                           "Replace lane", 2, 0, 0, 1, 0, 0, lane_index);   \
  }
970 971 972
SIMD_LANE_OP_LIST(SIMD_LANE_OPS)
#undef SIMD_LANE_OPS

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
#define SIMD_SHIFT_OPS(format, bits)                                           \
  const Operator* MachineOperatorBuilder::I##format##Shl(int32_t shift) {      \
    DCHECK(0 <= shift && shift < bits);                                        \
    return new (zone_)                                                         \
        Operator1<int32_t>(IrOpcode::kI##format##Shl, Operator::kPure,         \
                           "Shift left", 1, 0, 0, 1, 0, 0, shift);             \
  }                                                                            \
  const Operator* MachineOperatorBuilder::I##format##ShrS(int32_t shift) {     \
    DCHECK(0 < shift && shift <= bits);                                        \
    return new (zone_)                                                         \
        Operator1<int32_t>(IrOpcode::kI##format##ShrS, Operator::kPure,        \
                           "Arithmetic shift right", 1, 0, 0, 1, 0, 0, shift); \
  }                                                                            \
  const Operator* MachineOperatorBuilder::I##format##ShrU(int32_t shift) {     \
    DCHECK(0 <= shift && shift < bits);                                        \
    return new (zone_)                                                         \
        Operator1<int32_t>(IrOpcode::kI##format##ShrU, Operator::kPure,        \
                           "Shift right", 1, 0, 0, 1, 0, 0, shift);            \
991
  }
992
SIMD_FORMAT_LIST(SIMD_SHIFT_OPS)
993 994
#undef SIMD_SHIFT_OPS

995 996
const Operator* MachineOperatorBuilder::S8x16Shuffle(
    const uint8_t shuffle[16]) {
997 998 999 1000 1001
  uint8_t* array = zone_->NewArray<uint8_t>(16);
  memcpy(array, shuffle, 16);
  return new (zone_)
      Operator1<uint8_t*>(IrOpcode::kS8x16Shuffle, Operator::kPure, "Shuffle",
                          2, 0, 0, 1, 0, 0, array);
1002
}
1003

1004 1005 1006
}  // namespace compiler
}  // namespace internal
}  // namespace v8