• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 #include "src/compiler/machine-operator.h"
6 
7 #include "src/base/lazy-instance.h"
8 #include "src/compiler/opcodes.h"
9 #include "src/compiler/operator.h"
10 
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14 
operator ==(StoreRepresentation lhs,StoreRepresentation rhs)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 
operator !=(StoreRepresentation lhs,StoreRepresentation rhs)21 bool operator!=(StoreRepresentation lhs, StoreRepresentation rhs) {
22   return !(lhs == rhs);
23 }
24 
25 
hash_value(StoreRepresentation rep)26 size_t hash_value(StoreRepresentation rep) {
27   return base::hash_combine(rep.representation(), rep.write_barrier_kind());
28 }
29 
30 
operator <<(std::ostream & os,StoreRepresentation rep)31 std::ostream& operator<<(std::ostream& os, StoreRepresentation rep) {
32   return os << "(" << rep.representation() << " : " << rep.write_barrier_kind()
33             << ")";
34 }
35 
36 
LoadRepresentationOf(Operator const * op)37 LoadRepresentation LoadRepresentationOf(Operator const* op) {
38   DCHECK(IrOpcode::kLoad == op->opcode() ||
39          IrOpcode::kProtectedLoad == op->opcode() ||
40          IrOpcode::kAtomicLoad == op->opcode());
41   return OpParameter<LoadRepresentation>(op);
42 }
43 
44 
StoreRepresentationOf(Operator const * op)45 StoreRepresentation const& StoreRepresentationOf(Operator const* op) {
46   DCHECK(IrOpcode::kStore == op->opcode() ||
47          IrOpcode::kProtectedStore == op->opcode());
48   return OpParameter<StoreRepresentation>(op);
49 }
50 
UnalignedLoadRepresentationOf(Operator const * op)51 UnalignedLoadRepresentation UnalignedLoadRepresentationOf(Operator const* op) {
52   DCHECK_EQ(IrOpcode::kUnalignedLoad, op->opcode());
53   return OpParameter<UnalignedLoadRepresentation>(op);
54 }
55 
UnalignedStoreRepresentationOf(Operator const * op)56 UnalignedStoreRepresentation const& UnalignedStoreRepresentationOf(
57     Operator const* op) {
58   DCHECK_EQ(IrOpcode::kUnalignedStore, op->opcode());
59   return OpParameter<UnalignedStoreRepresentation>(op);
60 }
61 
CheckedLoadRepresentationOf(Operator const * op)62 CheckedLoadRepresentation CheckedLoadRepresentationOf(Operator const* op) {
63   DCHECK_EQ(IrOpcode::kCheckedLoad, op->opcode());
64   return OpParameter<CheckedLoadRepresentation>(op);
65 }
66 
67 
CheckedStoreRepresentationOf(Operator const * op)68 CheckedStoreRepresentation CheckedStoreRepresentationOf(Operator const* op) {
69   DCHECK_EQ(IrOpcode::kCheckedStore, op->opcode());
70   return OpParameter<CheckedStoreRepresentation>(op);
71 }
72 
StackSlotSizeOf(Operator const * op)73 int StackSlotSizeOf(Operator const* op) {
74   DCHECK_EQ(IrOpcode::kStackSlot, op->opcode());
75   return OpParameter<int>(op);
76 }
77 
AtomicStoreRepresentationOf(Operator const * op)78 MachineRepresentation AtomicStoreRepresentationOf(Operator const* op) {
79   DCHECK_EQ(IrOpcode::kAtomicStore, op->opcode());
80   return OpParameter<MachineRepresentation>(op);
81 }
82 
83 #define PURE_BINARY_OP_LIST_32(V)                                           \
84   V(Word32And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)    \
85   V(Word32Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
86   V(Word32Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)    \
87   V(Word32Shl, Operator::kNoProperties, 2, 0, 1)                            \
88   V(Word32Shr, Operator::kNoProperties, 2, 0, 1)                            \
89   V(Word32Sar, Operator::kNoProperties, 2, 0, 1)                            \
90   V(Word32Ror, Operator::kNoProperties, 2, 0, 1)                            \
91   V(Word32Equal, Operator::kCommutative, 2, 0, 1)                           \
92   V(Int32Add, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
93   V(Int32Sub, Operator::kNoProperties, 2, 0, 1)                             \
94   V(Int32Mul, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)     \
95   V(Int32MulHigh, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
96   V(Int32Div, Operator::kNoProperties, 2, 1, 1)                             \
97   V(Int32Mod, Operator::kNoProperties, 2, 1, 1)                             \
98   V(Int32LessThan, Operator::kNoProperties, 2, 0, 1)                        \
99   V(Int32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)                 \
100   V(Uint32Div, Operator::kNoProperties, 2, 1, 1)                            \
101   V(Uint32LessThan, Operator::kNoProperties, 2, 0, 1)                       \
102   V(Uint32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)                \
103   V(Uint32Mod, Operator::kNoProperties, 2, 1, 1)                            \
104   V(Uint32MulHigh, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)
105 
106 #define PURE_BINARY_OP_LIST_64(V)                                        \
107   V(Word64And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
108   V(Word64Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
109   V(Word64Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
110   V(Word64Shl, Operator::kNoProperties, 2, 0, 1)                         \
111   V(Word64Shr, Operator::kNoProperties, 2, 0, 1)                         \
112   V(Word64Sar, Operator::kNoProperties, 2, 0, 1)                         \
113   V(Word64Ror, Operator::kNoProperties, 2, 0, 1)                         \
114   V(Word64Equal, Operator::kCommutative, 2, 0, 1)                        \
115   V(Int64Add, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
116   V(Int64Sub, Operator::kNoProperties, 2, 0, 1)                          \
117   V(Int64Mul, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
118   V(Int64Div, Operator::kNoProperties, 2, 1, 1)                          \
119   V(Int64Mod, Operator::kNoProperties, 2, 1, 1)                          \
120   V(Int64LessThan, Operator::kNoProperties, 2, 0, 1)                     \
121   V(Int64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
122   V(Uint64Div, Operator::kNoProperties, 2, 1, 1)                         \
123   V(Uint64Mod, Operator::kNoProperties, 2, 1, 1)                         \
124   V(Uint64LessThan, Operator::kNoProperties, 2, 0, 1)                    \
125   V(Uint64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)
126 
127 #define PURE_OP_LIST(V)                                                    \
128   PURE_BINARY_OP_LIST_32(V)                                                \
129   PURE_BINARY_OP_LIST_64(V)                                                \
130   V(Word32Clz, Operator::kNoProperties, 1, 0, 1)                           \
131   V(Word64Clz, Operator::kNoProperties, 1, 0, 1)                           \
132   V(BitcastTaggedToWord, Operator::kNoProperties, 1, 0, 1)                 \
133   V(BitcastWordToTaggedSigned, Operator::kNoProperties, 1, 0, 1)           \
134   V(TruncateFloat64ToWord32, Operator::kNoProperties, 1, 0, 1)             \
135   V(ChangeFloat32ToFloat64, Operator::kNoProperties, 1, 0, 1)              \
136   V(ChangeFloat64ToInt32, Operator::kNoProperties, 1, 0, 1)                \
137   V(ChangeFloat64ToUint32, Operator::kNoProperties, 1, 0, 1)               \
138   V(TruncateFloat64ToUint32, Operator::kNoProperties, 1, 0, 1)             \
139   V(TruncateFloat32ToInt32, Operator::kNoProperties, 1, 0, 1)              \
140   V(TruncateFloat32ToUint32, Operator::kNoProperties, 1, 0, 1)             \
141   V(TryTruncateFloat32ToInt64, Operator::kNoProperties, 1, 0, 2)           \
142   V(TryTruncateFloat64ToInt64, Operator::kNoProperties, 1, 0, 2)           \
143   V(TryTruncateFloat32ToUint64, Operator::kNoProperties, 1, 0, 2)          \
144   V(TryTruncateFloat64ToUint64, Operator::kNoProperties, 1, 0, 2)          \
145   V(ChangeInt32ToFloat64, Operator::kNoProperties, 1, 0, 1)                \
146   V(Float64SilenceNaN, Operator::kNoProperties, 1, 0, 1)                   \
147   V(RoundFloat64ToInt32, Operator::kNoProperties, 1, 0, 1)                 \
148   V(RoundInt32ToFloat32, Operator::kNoProperties, 1, 0, 1)                 \
149   V(RoundInt64ToFloat32, Operator::kNoProperties, 1, 0, 1)                 \
150   V(RoundInt64ToFloat64, Operator::kNoProperties, 1, 0, 1)                 \
151   V(RoundUint32ToFloat32, Operator::kNoProperties, 1, 0, 1)                \
152   V(RoundUint64ToFloat32, Operator::kNoProperties, 1, 0, 1)                \
153   V(RoundUint64ToFloat64, Operator::kNoProperties, 1, 0, 1)                \
154   V(ChangeInt32ToInt64, Operator::kNoProperties, 1, 0, 1)                  \
155   V(ChangeUint32ToFloat64, Operator::kNoProperties, 1, 0, 1)               \
156   V(ChangeUint32ToUint64, Operator::kNoProperties, 1, 0, 1)                \
157   V(TruncateFloat64ToFloat32, Operator::kNoProperties, 1, 0, 1)            \
158   V(TruncateInt64ToInt32, Operator::kNoProperties, 1, 0, 1)                \
159   V(BitcastFloat32ToInt32, Operator::kNoProperties, 1, 0, 1)               \
160   V(BitcastFloat64ToInt64, Operator::kNoProperties, 1, 0, 1)               \
161   V(BitcastInt32ToFloat32, Operator::kNoProperties, 1, 0, 1)               \
162   V(BitcastInt64ToFloat64, Operator::kNoProperties, 1, 0, 1)               \
163   V(Float32Abs, Operator::kNoProperties, 1, 0, 1)                          \
164   V(Float32Add, Operator::kCommutative, 2, 0, 1)                           \
165   V(Float32Sub, Operator::kNoProperties, 2, 0, 1)                          \
166   V(Float32Mul, Operator::kCommutative, 2, 0, 1)                           \
167   V(Float32Div, Operator::kNoProperties, 2, 0, 1)                          \
168   V(Float32Neg, Operator::kNoProperties, 1, 0, 1)                          \
169   V(Float32Sqrt, Operator::kNoProperties, 1, 0, 1)                         \
170   V(Float32Max, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
171   V(Float32Min, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
172   V(Float64Abs, Operator::kNoProperties, 1, 0, 1)                          \
173   V(Float64Acos, Operator::kNoProperties, 1, 0, 1)                         \
174   V(Float64Acosh, Operator::kNoProperties, 1, 0, 1)                        \
175   V(Float64Asin, Operator::kNoProperties, 1, 0, 1)                         \
176   V(Float64Asinh, Operator::kNoProperties, 1, 0, 1)                        \
177   V(Float64Atan, Operator::kNoProperties, 1, 0, 1)                         \
178   V(Float64Atan2, Operator::kNoProperties, 2, 0, 1)                        \
179   V(Float64Atanh, Operator::kNoProperties, 1, 0, 1)                        \
180   V(Float64Cbrt, Operator::kNoProperties, 1, 0, 1)                         \
181   V(Float64Cos, Operator::kNoProperties, 1, 0, 1)                          \
182   V(Float64Cosh, Operator::kNoProperties, 1, 0, 1)                         \
183   V(Float64Exp, Operator::kNoProperties, 1, 0, 1)                          \
184   V(Float64Expm1, Operator::kNoProperties, 1, 0, 1)                        \
185   V(Float64Log, Operator::kNoProperties, 1, 0, 1)                          \
186   V(Float64Log1p, Operator::kNoProperties, 1, 0, 1)                        \
187   V(Float64Log2, Operator::kNoProperties, 1, 0, 1)                         \
188   V(Float64Log10, Operator::kNoProperties, 1, 0, 1)                        \
189   V(Float64Max, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
190   V(Float64Min, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
191   V(Float64Neg, Operator::kNoProperties, 1, 0, 1)                          \
192   V(Float64Add, Operator::kCommutative, 2, 0, 1)                           \
193   V(Float64Sub, Operator::kNoProperties, 2, 0, 1)                          \
194   V(Float64Mul, Operator::kCommutative, 2, 0, 1)                           \
195   V(Float64Div, Operator::kNoProperties, 2, 0, 1)                          \
196   V(Float64Mod, Operator::kNoProperties, 2, 0, 1)                          \
197   V(Float64Pow, Operator::kNoProperties, 2, 0, 1)                          \
198   V(Float64Sin, Operator::kNoProperties, 1, 0, 1)                          \
199   V(Float64Sinh, Operator::kNoProperties, 1, 0, 1)                         \
200   V(Float64Sqrt, Operator::kNoProperties, 1, 0, 1)                         \
201   V(Float64Tan, Operator::kNoProperties, 1, 0, 1)                          \
202   V(Float64Tanh, Operator::kNoProperties, 1, 0, 1)                         \
203   V(Float32Equal, Operator::kCommutative, 2, 0, 1)                         \
204   V(Float32LessThan, Operator::kNoProperties, 2, 0, 1)                     \
205   V(Float32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
206   V(Float64Equal, Operator::kCommutative, 2, 0, 1)                         \
207   V(Float64LessThan, Operator::kNoProperties, 2, 0, 1)                     \
208   V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
209   V(Float64ExtractLowWord32, Operator::kNoProperties, 1, 0, 1)             \
210   V(Float64ExtractHighWord32, Operator::kNoProperties, 1, 0, 1)            \
211   V(Float64InsertLowWord32, Operator::kNoProperties, 2, 0, 1)              \
212   V(Float64InsertHighWord32, Operator::kNoProperties, 2, 0, 1)             \
213   V(LoadStackPointer, Operator::kNoProperties, 0, 0, 1)                    \
214   V(LoadFramePointer, Operator::kNoProperties, 0, 0, 1)                    \
215   V(LoadParentFramePointer, Operator::kNoProperties, 0, 0, 1)              \
216   V(Int32PairAdd, Operator::kNoProperties, 4, 0, 2)                        \
217   V(Int32PairSub, Operator::kNoProperties, 4, 0, 2)                        \
218   V(Int32PairMul, Operator::kNoProperties, 4, 0, 2)                        \
219   V(Word32PairShl, Operator::kNoProperties, 3, 0, 2)                       \
220   V(Word32PairShr, Operator::kNoProperties, 3, 0, 2)                       \
221   V(Word32PairSar, Operator::kNoProperties, 3, 0, 2)                       \
222   V(CreateFloat32x4, Operator::kNoProperties, 4, 0, 1)                     \
223   V(Float32x4Abs, Operator::kNoProperties, 1, 0, 1)                        \
224   V(Float32x4Neg, Operator::kNoProperties, 1, 0, 1)                        \
225   V(Float32x4Sqrt, Operator::kNoProperties, 1, 0, 1)                       \
226   V(Float32x4RecipApprox, Operator::kNoProperties, 1, 0, 1)                \
227   V(Float32x4RecipSqrtApprox, Operator::kNoProperties, 1, 0, 1)            \
228   V(Float32x4Add, Operator::kCommutative, 2, 0, 1)                         \
229   V(Float32x4Sub, Operator::kNoProperties, 2, 0, 1)                        \
230   V(Float32x4Mul, Operator::kCommutative, 2, 0, 1)                         \
231   V(Float32x4Div, Operator::kNoProperties, 2, 0, 1)                        \
232   V(Float32x4Min, Operator::kCommutative, 2, 0, 1)                         \
233   V(Float32x4Max, Operator::kCommutative, 2, 0, 1)                         \
234   V(Float32x4MinNum, Operator::kCommutative, 2, 0, 1)                      \
235   V(Float32x4MaxNum, Operator::kCommutative, 2, 0, 1)                      \
236   V(Float32x4Equal, Operator::kCommutative, 2, 0, 1)                       \
237   V(Float32x4NotEqual, Operator::kCommutative, 2, 0, 1)                    \
238   V(Float32x4LessThan, Operator::kNoProperties, 2, 0, 1)                   \
239   V(Float32x4LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)            \
240   V(Float32x4GreaterThan, Operator::kNoProperties, 2, 0, 1)                \
241   V(Float32x4GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)         \
242   V(Float32x4FromInt32x4, Operator::kNoProperties, 1, 0, 1)                \
243   V(Float32x4FromUint32x4, Operator::kNoProperties, 1, 0, 1)               \
244   V(CreateInt32x4, Operator::kNoProperties, 4, 0, 1)                       \
245   V(Int32x4Neg, Operator::kNoProperties, 1, 0, 1)                          \
246   V(Int32x4Add, Operator::kCommutative, 2, 0, 1)                           \
247   V(Int32x4Sub, Operator::kNoProperties, 2, 0, 1)                          \
248   V(Int32x4Mul, Operator::kCommutative, 2, 0, 1)                           \
249   V(Int32x4Min, Operator::kCommutative, 2, 0, 1)                           \
250   V(Int32x4Max, Operator::kCommutative, 2, 0, 1)                           \
251   V(Int32x4Equal, Operator::kCommutative, 2, 0, 1)                         \
252   V(Int32x4NotEqual, Operator::kCommutative, 2, 0, 1)                      \
253   V(Int32x4LessThan, Operator::kNoProperties, 2, 0, 1)                     \
254   V(Int32x4LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
255   V(Int32x4GreaterThan, Operator::kNoProperties, 2, 0, 1)                  \
256   V(Int32x4GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)           \
257   V(Int32x4FromFloat32x4, Operator::kNoProperties, 1, 0, 1)                \
258   V(Uint32x4Min, Operator::kCommutative, 2, 0, 1)                          \
259   V(Uint32x4Max, Operator::kCommutative, 2, 0, 1)                          \
260   V(Uint32x4LessThan, Operator::kNoProperties, 2, 0, 1)                    \
261   V(Uint32x4LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)             \
262   V(Uint32x4GreaterThan, Operator::kNoProperties, 2, 0, 1)                 \
263   V(Uint32x4GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)          \
264   V(Uint32x4FromFloat32x4, Operator::kNoProperties, 1, 0, 1)               \
265   V(Bool32x4And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
266   V(Bool32x4Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
267   V(Bool32x4Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
268   V(Bool32x4Not, Operator::kNoProperties, 1, 0, 1)                         \
269   V(Bool32x4AnyTrue, Operator::kNoProperties, 1, 0, 1)                     \
270   V(Bool32x4AllTrue, Operator::kNoProperties, 1, 0, 1)                     \
271   V(CreateInt16x8, Operator::kNoProperties, 8, 0, 1)                       \
272   V(Int16x8Neg, Operator::kNoProperties, 1, 0, 1)                          \
273   V(Int16x8Add, Operator::kCommutative, 2, 0, 1)                           \
274   V(Int16x8AddSaturate, Operator::kCommutative, 2, 0, 1)                   \
275   V(Int16x8Sub, Operator::kNoProperties, 2, 0, 1)                          \
276   V(Int16x8SubSaturate, Operator::kNoProperties, 2, 0, 1)                  \
277   V(Int16x8Mul, Operator::kCommutative, 2, 0, 1)                           \
278   V(Int16x8Min, Operator::kCommutative, 2, 0, 1)                           \
279   V(Int16x8Max, Operator::kCommutative, 2, 0, 1)                           \
280   V(Int16x8Equal, Operator::kCommutative, 2, 0, 1)                         \
281   V(Int16x8NotEqual, Operator::kCommutative, 2, 0, 1)                      \
282   V(Int16x8LessThan, Operator::kNoProperties, 2, 0, 1)                     \
283   V(Int16x8LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
284   V(Int16x8GreaterThan, Operator::kNoProperties, 2, 0, 1)                  \
285   V(Int16x8GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)           \
286   V(Uint16x8AddSaturate, Operator::kCommutative, 2, 0, 1)                  \
287   V(Uint16x8SubSaturate, Operator::kNoProperties, 2, 0, 1)                 \
288   V(Uint16x8Min, Operator::kCommutative, 2, 0, 1)                          \
289   V(Uint16x8Max, Operator::kCommutative, 2, 0, 1)                          \
290   V(Uint16x8LessThan, Operator::kNoProperties, 2, 0, 1)                    \
291   V(Uint16x8LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)             \
292   V(Uint16x8GreaterThan, Operator::kNoProperties, 2, 0, 1)                 \
293   V(Uint16x8GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)          \
294   V(Bool16x8And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
295   V(Bool16x8Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
296   V(Bool16x8Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
297   V(Bool16x8Not, Operator::kNoProperties, 1, 0, 1)                         \
298   V(Bool16x8AnyTrue, Operator::kNoProperties, 1, 0, 1)                     \
299   V(Bool16x8AllTrue, Operator::kNoProperties, 1, 0, 1)                     \
300   V(CreateInt8x16, Operator::kNoProperties, 16, 0, 1)                      \
301   V(Int8x16Neg, Operator::kNoProperties, 1, 0, 1)                          \
302   V(Int8x16Add, Operator::kCommutative, 2, 0, 1)                           \
303   V(Int8x16AddSaturate, Operator::kCommutative, 2, 0, 1)                   \
304   V(Int8x16Sub, Operator::kNoProperties, 2, 0, 1)                          \
305   V(Int8x16SubSaturate, Operator::kNoProperties, 2, 0, 1)                  \
306   V(Int8x16Mul, Operator::kCommutative, 2, 0, 1)                           \
307   V(Int8x16Min, Operator::kCommutative, 2, 0, 1)                           \
308   V(Int8x16Max, Operator::kCommutative, 2, 0, 1)                           \
309   V(Int8x16Equal, Operator::kCommutative, 2, 0, 1)                         \
310   V(Int8x16NotEqual, Operator::kCommutative, 2, 0, 1)                      \
311   V(Int8x16LessThan, Operator::kNoProperties, 2, 0, 1)                     \
312   V(Int8x16LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)              \
313   V(Int8x16GreaterThan, Operator::kNoProperties, 2, 0, 1)                  \
314   V(Int8x16GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)           \
315   V(Uint8x16AddSaturate, Operator::kCommutative, 2, 0, 1)                  \
316   V(Uint8x16SubSaturate, Operator::kNoProperties, 2, 0, 1)                 \
317   V(Uint8x16Min, Operator::kCommutative, 2, 0, 1)                          \
318   V(Uint8x16Max, Operator::kCommutative, 2, 0, 1)                          \
319   V(Uint8x16LessThan, Operator::kNoProperties, 2, 0, 1)                    \
320   V(Uint8x16LessThanOrEqual, Operator::kNoProperties, 2, 0, 1)             \
321   V(Uint8x16GreaterThan, Operator::kNoProperties, 2, 0, 1)                 \
322   V(Uint8x16GreaterThanOrEqual, Operator::kNoProperties, 2, 0, 1)          \
323   V(Bool8x16And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
324   V(Bool8x16Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
325   V(Bool8x16Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \
326   V(Bool8x16Not, Operator::kNoProperties, 1, 0, 1)                         \
327   V(Bool8x16AnyTrue, Operator::kNoProperties, 1, 0, 1)                     \
328   V(Bool8x16AllTrue, Operator::kNoProperties, 1, 0, 1)                     \
329   V(Simd128Load, Operator::kNoProperties, 2, 0, 1)                         \
330   V(Simd128Load1, Operator::kNoProperties, 2, 0, 1)                        \
331   V(Simd128Load2, Operator::kNoProperties, 2, 0, 1)                        \
332   V(Simd128Load3, Operator::kNoProperties, 2, 0, 1)                        \
333   V(Simd128Store, Operator::kNoProperties, 3, 0, 1)                        \
334   V(Simd128Store1, Operator::kNoProperties, 3, 0, 1)                       \
335   V(Simd128Store2, Operator::kNoProperties, 3, 0, 1)                       \
336   V(Simd128Store3, Operator::kNoProperties, 3, 0, 1)                       \
337   V(Simd128And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
338   V(Simd128Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)   \
339   V(Simd128Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1)  \
340   V(Simd128Not, Operator::kNoProperties, 1, 0, 1)                          \
341   V(Simd32x4Select, Operator::kNoProperties, 3, 0, 1)                      \
342   V(Simd16x8Select, Operator::kNoProperties, 3, 0, 1)                      \
343   V(Simd8x16Select, Operator::kNoProperties, 3, 0, 1)
344 
345 #define PURE_OPTIONAL_OP_LIST(V)                            \
346   V(Word32Ctz, Operator::kNoProperties, 1, 0, 1)            \
347   V(Word64Ctz, Operator::kNoProperties, 1, 0, 1)            \
348   V(Word32ReverseBits, Operator::kNoProperties, 1, 0, 1)    \
349   V(Word64ReverseBits, Operator::kNoProperties, 1, 0, 1)    \
350   V(Word32ReverseBytes, Operator::kNoProperties, 1, 0, 1)   \
351   V(Word64ReverseBytes, Operator::kNoProperties, 1, 0, 1)   \
352   V(Word32Popcnt, Operator::kNoProperties, 1, 0, 1)         \
353   V(Word64Popcnt, Operator::kNoProperties, 1, 0, 1)         \
354   V(Float32RoundDown, Operator::kNoProperties, 1, 0, 1)     \
355   V(Float64RoundDown, Operator::kNoProperties, 1, 0, 1)     \
356   V(Float32RoundUp, Operator::kNoProperties, 1, 0, 1)       \
357   V(Float64RoundUp, Operator::kNoProperties, 1, 0, 1)       \
358   V(Float32RoundTruncate, Operator::kNoProperties, 1, 0, 1) \
359   V(Float64RoundTruncate, Operator::kNoProperties, 1, 0, 1) \
360   V(Float64RoundTiesAway, Operator::kNoProperties, 1, 0, 1) \
361   V(Float32RoundTiesEven, Operator::kNoProperties, 1, 0, 1) \
362   V(Float64RoundTiesEven, Operator::kNoProperties, 1, 0, 1)
363 
364 #define OVERFLOW_OP_LIST(V)                                                \
365   V(Int32AddWithOverflow, Operator::kAssociative | Operator::kCommutative) \
366   V(Int32SubWithOverflow, Operator::kNoProperties)                         \
367   V(Int32MulWithOverflow, Operator::kAssociative | Operator::kCommutative) \
368   V(Int64AddWithOverflow, Operator::kAssociative | Operator::kCommutative) \
369   V(Int64SubWithOverflow, Operator::kNoProperties)
370 
371 #define MACHINE_TYPE_LIST(V) \
372   V(Float32)                 \
373   V(Float64)                 \
374   V(Simd128)                 \
375   V(Int8)                    \
376   V(Uint8)                   \
377   V(Int16)                   \
378   V(Uint16)                  \
379   V(Int32)                   \
380   V(Uint32)                  \
381   V(Int64)                   \
382   V(Uint64)                  \
383   V(Pointer)                 \
384   V(TaggedSigned)            \
385   V(TaggedPointer)           \
386   V(AnyTagged)
387 
388 #define MACHINE_REPRESENTATION_LIST(V) \
389   V(kFloat32)                          \
390   V(kFloat64)                          \
391   V(kSimd128)                          \
392   V(kWord8)                            \
393   V(kWord16)                           \
394   V(kWord32)                           \
395   V(kWord64)                           \
396   V(kTaggedSigned)                     \
397   V(kTaggedPointer)                    \
398   V(kTagged)
399 
400 #define ATOMIC_TYPE_LIST(V) \
401   V(Int8)                   \
402   V(Uint8)                  \
403   V(Int16)                  \
404   V(Uint16)                 \
405   V(Int32)                  \
406   V(Uint32)
407 
408 #define ATOMIC_REPRESENTATION_LIST(V) \
409   V(kWord8)                           \
410   V(kWord16)                          \
411   V(kWord32)
412 
413 #define SIMD_LANE_OP_LIST(V) \
414   V(Float32x4, 4)            \
415   V(Int32x4, 4)              \
416   V(Int16x8, 8)              \
417   V(Int8x16, 16)
418 
419 #define SIMD_FORMAT_LIST(V) \
420   V(32x4, 32)               \
421   V(16x8, 16)               \
422   V(8x16, 8)
423 
424 #define STACK_SLOT_CACHED_SIZES_LIST(V) V(4) V(8) V(16)
425 
426 struct StackSlotOperator : public Operator1<int> {
StackSlotOperatorv8::internal::compiler::StackSlotOperator427   explicit StackSlotOperator(int size)
428       : Operator1<int>(IrOpcode::kStackSlot,
429                        Operator::kNoDeopt | Operator::kNoThrow, "StackSlot", 0,
430                        0, 0, 1, 0, 0, size) {}
431 };
432 
433 struct MachineOperatorGlobalCache {
434 #define PURE(Name, properties, value_input_count, control_input_count,         \
435              output_count)                                                     \
436   struct Name##Operator final : public Operator {                              \
437     Name##Operator()                                                           \
438         : Operator(IrOpcode::k##Name, Operator::kPure | properties, #Name,     \
439                    value_input_count, 0, control_input_count, output_count, 0, \
440                    0) {}                                                       \
441   };                                                                           \
442   Name##Operator k##Name;
443   PURE_OP_LIST(PURE)
444   PURE_OPTIONAL_OP_LIST(PURE)
445 #undef PURE
446 
447 #define OVERFLOW_OP(Name, properties)                                        \
448   struct Name##Operator final : public Operator {                            \
449     Name##Operator()                                                         \
450         : Operator(IrOpcode::k##Name,                                        \
451                    Operator::kEliminatable | Operator::kNoRead | properties, \
452                    #Name, 2, 0, 1, 2, 0, 0) {}                               \
453   };                                                                         \
454   Name##Operator k##Name;
455   OVERFLOW_OP_LIST(OVERFLOW_OP)
456 #undef OVERFLOW_OP
457 
458 #define LOAD(Type)                                                            \
459   struct Load##Type##Operator final : public Operator1<LoadRepresentation> {  \
460     Load##Type##Operator()                                                    \
461         : Operator1<LoadRepresentation>(                                      \
462               IrOpcode::kLoad,                                                \
463               Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,   \
464               "Load", 2, 1, 1, 1, 1, 0, MachineType::Type()) {}               \
465   };                                                                          \
466   struct UnalignedLoad##Type##Operator final                                  \
467       : public Operator1<UnalignedLoadRepresentation> {                       \
468     UnalignedLoad##Type##Operator()                                           \
469         : Operator1<UnalignedLoadRepresentation>(                             \
470               IrOpcode::kUnalignedLoad,                                       \
471               Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,   \
472               "UnalignedLoad", 2, 1, 1, 1, 1, 0, MachineType::Type()) {}      \
473   };                                                                          \
474   struct CheckedLoad##Type##Operator final                                    \
475       : public Operator1<CheckedLoadRepresentation> {                         \
476     CheckedLoad##Type##Operator()                                             \
477         : Operator1<CheckedLoadRepresentation>(                               \
478               IrOpcode::kCheckedLoad,                                         \
479               Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,   \
480               "CheckedLoad", 3, 1, 1, 1, 1, 0, MachineType::Type()) {}        \
481   };                                                                          \
482   struct ProtectedLoad##Type##Operator final                                  \
483       : public Operator1<LoadRepresentation> {                                \
484     ProtectedLoad##Type##Operator()                                           \
485         : Operator1<LoadRepresentation>(                                      \
486               IrOpcode::kProtectedLoad,                                       \
487               Operator::kNoDeopt | Operator::kNoThrow, "ProtectedLoad", 3, 1, \
488               1, 1, 1, 0, MachineType::Type()) {}                             \
489   };                                                                          \
490   Load##Type##Operator kLoad##Type;                                           \
491   UnalignedLoad##Type##Operator kUnalignedLoad##Type;                         \
492   CheckedLoad##Type##Operator kCheckedLoad##Type;                             \
493   ProtectedLoad##Type##Operator kProtectedLoad##Type;
494   MACHINE_TYPE_LIST(LOAD)
495 #undef LOAD
496 
497 #define STACKSLOT(Size)                                                     \
498   struct StackSlotOfSize##Size##Operator final : public StackSlotOperator { \
499     StackSlotOfSize##Size##Operator() : StackSlotOperator(Size) {}          \
500   };                                                                        \
501   StackSlotOfSize##Size##Operator kStackSlotSize##Size;
502   STACK_SLOT_CACHED_SIZES_LIST(STACKSLOT)
503 #undef STACKSLOT
504 
505 #define STORE(Type)                                                            \
506   struct Store##Type##Operator : public Operator1<StoreRepresentation> {       \
507     explicit Store##Type##Operator(WriteBarrierKind write_barrier_kind)        \
508         : Operator1<StoreRepresentation>(                                      \
509               IrOpcode::kStore,                                                \
510               Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
511               "Store", 3, 1, 1, 0, 1, 0,                                       \
512               StoreRepresentation(MachineRepresentation::Type,                 \
513                                   write_barrier_kind)) {}                      \
514   };                                                                           \
515   struct Store##Type##NoWriteBarrier##Operator final                           \
516       : public Store##Type##Operator {                                         \
517     Store##Type##NoWriteBarrier##Operator()                                    \
518         : Store##Type##Operator(kNoWriteBarrier) {}                            \
519   };                                                                           \
520   struct Store##Type##MapWriteBarrier##Operator final                          \
521       : public Store##Type##Operator {                                         \
522     Store##Type##MapWriteBarrier##Operator()                                   \
523         : Store##Type##Operator(kMapWriteBarrier) {}                           \
524   };                                                                           \
525   struct Store##Type##PointerWriteBarrier##Operator final                      \
526       : public Store##Type##Operator {                                         \
527     Store##Type##PointerWriteBarrier##Operator()                               \
528         : Store##Type##Operator(kPointerWriteBarrier) {}                       \
529   };                                                                           \
530   struct Store##Type##FullWriteBarrier##Operator final                         \
531       : public Store##Type##Operator {                                         \
532     Store##Type##FullWriteBarrier##Operator()                                  \
533         : Store##Type##Operator(kFullWriteBarrier) {}                          \
534   };                                                                           \
535   struct UnalignedStore##Type##Operator final                                  \
536       : public Operator1<UnalignedStoreRepresentation> {                       \
537     UnalignedStore##Type##Operator()                                           \
538         : Operator1<UnalignedStoreRepresentation>(                             \
539               IrOpcode::kUnalignedStore,                                       \
540               Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
541               "UnalignedStore", 3, 1, 1, 0, 1, 0,                              \
542               MachineRepresentation::Type) {}                                  \
543   };                                                                           \
544   struct CheckedStore##Type##Operator final                                    \
545       : public Operator1<CheckedStoreRepresentation> {                         \
546     CheckedStore##Type##Operator()                                             \
547         : Operator1<CheckedStoreRepresentation>(                               \
548               IrOpcode::kCheckedStore,                                         \
549               Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
550               "CheckedStore", 4, 1, 1, 0, 1, 0, MachineRepresentation::Type) { \
551     }                                                                          \
552   };                                                                           \
553   struct ProtectedStore##Type##Operator                                        \
554       : public Operator1<StoreRepresentation> {                                \
555     explicit ProtectedStore##Type##Operator()                                  \
556         : Operator1<StoreRepresentation>(                                      \
557               IrOpcode::kProtectedStore,                                       \
558               Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
559               "Store", 4, 1, 1, 0, 1, 0,                                       \
560               StoreRepresentation(MachineRepresentation::Type,                 \
561                                   kNoWriteBarrier)) {}                         \
562   };                                                                           \
563   Store##Type##NoWriteBarrier##Operator kStore##Type##NoWriteBarrier;          \
564   Store##Type##MapWriteBarrier##Operator kStore##Type##MapWriteBarrier;        \
565   Store##Type##PointerWriteBarrier##Operator                                   \
566       kStore##Type##PointerWriteBarrier;                                       \
567   Store##Type##FullWriteBarrier##Operator kStore##Type##FullWriteBarrier;      \
568   UnalignedStore##Type##Operator kUnalignedStore##Type;                        \
569   CheckedStore##Type##Operator kCheckedStore##Type;                            \
570   ProtectedStore##Type##Operator kProtectedStore##Type;
571   MACHINE_REPRESENTATION_LIST(STORE)
572 #undef STORE
573 
574 #define ATOMIC_LOAD(Type)                                                   \
575   struct AtomicLoad##Type##Operator final                                   \
576       : public Operator1<LoadRepresentation> {                              \
577     AtomicLoad##Type##Operator()                                            \
578         : Operator1<LoadRepresentation>(                                    \
579               IrOpcode::kAtomicLoad,                                        \
580               Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite, \
581               "AtomicLoad", 2, 1, 1, 1, 1, 0, MachineType::Type()) {}       \
582   };                                                                        \
583   AtomicLoad##Type##Operator kAtomicLoad##Type;
584   ATOMIC_TYPE_LIST(ATOMIC_LOAD)
585 #undef ATOMIC_LOAD
586 
587 #define ATOMIC_STORE(Type)                                                     \
588   struct AtomicStore##Type##Operator                                           \
589       : public Operator1<MachineRepresentation> {                              \
590     AtomicStore##Type##Operator()                                              \
591         : Operator1<MachineRepresentation>(                                    \
592               IrOpcode::kAtomicStore,                                          \
593               Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,     \
594               "AtomicStore", 3, 1, 1, 0, 1, 0, MachineRepresentation::Type) {} \
595   };                                                                           \
596   AtomicStore##Type##Operator kAtomicStore##Type;
597   ATOMIC_REPRESENTATION_LIST(ATOMIC_STORE)
598 #undef STORE
599 
600   // The {BitcastWordToTagged} operator must not be marked as pure (especially
601   // not idempotent), because otherwise the splitting logic in the Scheduler
602   // might decide to split these operators, thus potentially creating live
603   // ranges of allocation top across calls or other things that might allocate.
604   // See https://bugs.chromium.org/p/v8/issues/detail?id=6059 for more details.
605   struct BitcastWordToTaggedOperator : public Operator {
BitcastWordToTaggedOperatorv8::internal::compiler::MachineOperatorGlobalCache::BitcastWordToTaggedOperator606     BitcastWordToTaggedOperator()
607         : Operator(IrOpcode::kBitcastWordToTagged,
608                    Operator::kEliminatable | Operator::kNoWrite,
609                    "BitcastWordToTagged", 1, 0, 0, 1, 0, 0) {}
610   };
611   BitcastWordToTaggedOperator kBitcastWordToTagged;
612 
613   struct DebugBreakOperator : public Operator {
DebugBreakOperatorv8::internal::compiler::MachineOperatorGlobalCache::DebugBreakOperator614     DebugBreakOperator()
615         : Operator(IrOpcode::kDebugBreak, Operator::kNoThrow, "DebugBreak", 0,
616                    0, 0, 0, 0, 0) {}
617   };
618   DebugBreakOperator kDebugBreak;
619 
620   struct UnsafePointerAddOperator final : public Operator {
UnsafePointerAddOperatorv8::internal::compiler::MachineOperatorGlobalCache::UnsafePointerAddOperator621     UnsafePointerAddOperator()
622         : Operator(IrOpcode::kUnsafePointerAdd, Operator::kKontrol,
623                    "UnsafePointerAdd", 2, 1, 1, 1, 1, 0) {}
624   };
625   UnsafePointerAddOperator kUnsafePointerAdd;
626 };
627 
628 struct CommentOperator : public Operator1<const char*> {
CommentOperatorv8::internal::compiler::CommentOperator629   explicit CommentOperator(const char* msg)
630       : Operator1<const char*>(IrOpcode::kComment, Operator::kNoThrow,
631                                "Comment", 0, 0, 0, 0, 0, 0, msg) {}
632 };
633 
634 static base::LazyInstance<MachineOperatorGlobalCache>::type kCache =
635     LAZY_INSTANCE_INITIALIZER;
636 
MachineOperatorBuilder(Zone * zone,MachineRepresentation word,Flags flags,AlignmentRequirements alignmentRequirements)637 MachineOperatorBuilder::MachineOperatorBuilder(
638     Zone* zone, MachineRepresentation word, Flags flags,
639     AlignmentRequirements alignmentRequirements)
640     : zone_(zone),
641       cache_(kCache.Get()),
642       word_(word),
643       flags_(flags),
644       alignment_requirements_(alignmentRequirements) {
645   DCHECK(word == MachineRepresentation::kWord32 ||
646          word == MachineRepresentation::kWord64);
647 }
648 
UnalignedLoad(UnalignedLoadRepresentation rep)649 const Operator* MachineOperatorBuilder::UnalignedLoad(
650     UnalignedLoadRepresentation rep) {
651 #define LOAD(Type)                       \
652   if (rep == MachineType::Type()) {      \
653     return &cache_.kUnalignedLoad##Type; \
654   }
655   MACHINE_TYPE_LIST(LOAD)
656 #undef LOAD
657   UNREACHABLE();
658   return nullptr;
659 }
660 
UnalignedStore(UnalignedStoreRepresentation rep)661 const Operator* MachineOperatorBuilder::UnalignedStore(
662     UnalignedStoreRepresentation rep) {
663   switch (rep) {
664 #define STORE(kRep)                 \
665   case MachineRepresentation::kRep: \
666     return &cache_.kUnalignedStore##kRep;
667     MACHINE_REPRESENTATION_LIST(STORE)
668 #undef STORE
669     case MachineRepresentation::kBit:
670     case MachineRepresentation::kSimd1x4:
671     case MachineRepresentation::kSimd1x8:
672     case MachineRepresentation::kSimd1x16:
673     case MachineRepresentation::kNone:
674       break;
675   }
676   UNREACHABLE();
677   return nullptr;
678 }
679 
680 #define PURE(Name, properties, value_input_count, control_input_count, \
681              output_count)                                             \
682   const Operator* MachineOperatorBuilder::Name() { return &cache_.k##Name; }
683 PURE_OP_LIST(PURE)
684 #undef PURE
685 
686 #define PURE(Name, properties, value_input_count, control_input_count, \
687              output_count)                                             \
688   const OptionalOperator MachineOperatorBuilder::Name() {              \
689     return OptionalOperator(flags_ & k##Name, &cache_.k##Name);        \
690   }
PURE_OPTIONAL_OP_LIST(PURE)691 PURE_OPTIONAL_OP_LIST(PURE)
692 #undef PURE
693 
694 #define OVERFLOW_OP(Name, properties) \
695   const Operator* MachineOperatorBuilder::Name() { return &cache_.k##Name; }
696 OVERFLOW_OP_LIST(OVERFLOW_OP)
697 #undef OVERFLOW_OP
698 
699 const Operator* MachineOperatorBuilder::Load(LoadRepresentation rep) {
700 #define LOAD(Type)                  \
701   if (rep == MachineType::Type()) { \
702     return &cache_.kLoad##Type;     \
703   }
704     MACHINE_TYPE_LIST(LOAD)
705 #undef LOAD
706   UNREACHABLE();
707   return nullptr;
708 }
709 
ProtectedLoad(LoadRepresentation rep)710 const Operator* MachineOperatorBuilder::ProtectedLoad(LoadRepresentation rep) {
711 #define LOAD(Type)                       \
712   if (rep == MachineType::Type()) {      \
713     return &cache_.kProtectedLoad##Type; \
714   }
715   MACHINE_TYPE_LIST(LOAD)
716 #undef LOAD
717   UNREACHABLE();
718   return nullptr;
719 }
720 
StackSlot(int size)721 const Operator* MachineOperatorBuilder::StackSlot(int size) {
722   DCHECK_LE(0, size);
723 #define CASE_CACHED_SIZE(Size) \
724   case Size:                   \
725     return &cache_.kStackSlotSize##Size;
726   switch (size) {
727     STACK_SLOT_CACHED_SIZES_LIST(CASE_CACHED_SIZE);
728     default:
729       return new (zone_) StackSlotOperator(size);
730   }
731 #undef CASE_CACHED_SIZE
732 }
733 
StackSlot(MachineRepresentation rep)734 const Operator* MachineOperatorBuilder::StackSlot(MachineRepresentation rep) {
735   return StackSlot(1 << ElementSizeLog2Of(rep));
736 }
737 
Store(StoreRepresentation store_rep)738 const Operator* MachineOperatorBuilder::Store(StoreRepresentation store_rep) {
739   switch (store_rep.representation()) {
740 #define STORE(kRep)                                         \
741   case MachineRepresentation::kRep:                         \
742     switch (store_rep.write_barrier_kind()) {               \
743       case kNoWriteBarrier:                                 \
744         return &cache_.k##Store##kRep##NoWriteBarrier;      \
745       case kMapWriteBarrier:                                \
746         return &cache_.k##Store##kRep##MapWriteBarrier;     \
747       case kPointerWriteBarrier:                            \
748         return &cache_.k##Store##kRep##PointerWriteBarrier; \
749       case kFullWriteBarrier:                               \
750         return &cache_.k##Store##kRep##FullWriteBarrier;    \
751     }                                                       \
752     break;
753     MACHINE_REPRESENTATION_LIST(STORE)
754 #undef STORE
755     case MachineRepresentation::kBit:
756     case MachineRepresentation::kSimd1x4:
757     case MachineRepresentation::kSimd1x8:
758     case MachineRepresentation::kSimd1x16:
759     case MachineRepresentation::kNone:
760       break;
761   }
762   UNREACHABLE();
763   return nullptr;
764 }
765 
ProtectedStore(MachineRepresentation rep)766 const Operator* MachineOperatorBuilder::ProtectedStore(
767     MachineRepresentation rep) {
768   switch (rep) {
769 #define STORE(kRep)                       \
770   case MachineRepresentation::kRep:       \
771     return &cache_.kProtectedStore##kRep; \
772     break;
773     MACHINE_REPRESENTATION_LIST(STORE)
774 #undef STORE
775     case MachineRepresentation::kBit:
776     case MachineRepresentation::kSimd1x4:
777     case MachineRepresentation::kSimd1x8:
778     case MachineRepresentation::kSimd1x16:
779     case MachineRepresentation::kNone:
780       break;
781   }
782   UNREACHABLE();
783   return nullptr;
784 }
785 
UnsafePointerAdd()786 const Operator* MachineOperatorBuilder::UnsafePointerAdd() {
787   return &cache_.kUnsafePointerAdd;
788 }
789 
BitcastWordToTagged()790 const Operator* MachineOperatorBuilder::BitcastWordToTagged() {
791   return &cache_.kBitcastWordToTagged;
792 }
793 
DebugBreak()794 const Operator* MachineOperatorBuilder::DebugBreak() {
795   return &cache_.kDebugBreak;
796 }
797 
Comment(const char * msg)798 const Operator* MachineOperatorBuilder::Comment(const char* msg) {
799   return new (zone_) CommentOperator(msg);
800 }
801 
CheckedLoad(CheckedLoadRepresentation rep)802 const Operator* MachineOperatorBuilder::CheckedLoad(
803     CheckedLoadRepresentation rep) {
804 #define LOAD(Type)                     \
805   if (rep == MachineType::Type()) {    \
806     return &cache_.kCheckedLoad##Type; \
807   }
808     MACHINE_TYPE_LIST(LOAD)
809 #undef LOAD
810   UNREACHABLE();
811   return nullptr;
812 }
813 
814 
CheckedStore(CheckedStoreRepresentation rep)815 const Operator* MachineOperatorBuilder::CheckedStore(
816     CheckedStoreRepresentation rep) {
817   switch (rep) {
818 #define STORE(kRep)                 \
819   case MachineRepresentation::kRep: \
820     return &cache_.kCheckedStore##kRep;
821     MACHINE_REPRESENTATION_LIST(STORE)
822 #undef STORE
823     case MachineRepresentation::kBit:
824     case MachineRepresentation::kSimd1x4:
825     case MachineRepresentation::kSimd1x8:
826     case MachineRepresentation::kSimd1x16:
827     case MachineRepresentation::kNone:
828       break;
829   }
830   UNREACHABLE();
831   return nullptr;
832 }
833 
AtomicLoad(LoadRepresentation rep)834 const Operator* MachineOperatorBuilder::AtomicLoad(LoadRepresentation rep) {
835 #define LOAD(Type)                    \
836   if (rep == MachineType::Type()) {   \
837     return &cache_.kAtomicLoad##Type; \
838   }
839   ATOMIC_TYPE_LIST(LOAD)
840 #undef LOAD
841   UNREACHABLE();
842   return nullptr;
843 }
844 
AtomicStore(MachineRepresentation rep)845 const Operator* MachineOperatorBuilder::AtomicStore(MachineRepresentation rep) {
846 #define STORE(kRep)                         \
847   if (rep == MachineRepresentation::kRep) { \
848     return &cache_.kAtomicStore##kRep;      \
849   }
850   ATOMIC_REPRESENTATION_LIST(STORE)
851 #undef STORE
852   UNREACHABLE();
853   return nullptr;
854 }
855 
856 #define SIMD_LANE_OPS(Type, lane_count)                                     \
857   const Operator* MachineOperatorBuilder::Type##ExtractLane(                \
858       int32_t lane_index) {                                                 \
859     DCHECK(0 <= lane_index && lane_index < lane_count);                     \
860     return new (zone_)                                                      \
861         Operator1<int32_t>(IrOpcode::k##Type##ExtractLane, Operator::kPure, \
862                            "Extract lane", 1, 0, 0, 1, 0, 0, lane_index);   \
863   }                                                                         \
864   const Operator* MachineOperatorBuilder::Type##ReplaceLane(                \
865       int32_t lane_index) {                                                 \
866     DCHECK(0 <= lane_index && lane_index < lane_count);                     \
867     return new (zone_)                                                      \
868         Operator1<int32_t>(IrOpcode::k##Type##ReplaceLane, Operator::kPure, \
869                            "Replace lane", 2, 0, 0, 1, 0, 0, lane_index);   \
870   }
871 SIMD_LANE_OP_LIST(SIMD_LANE_OPS)
872 #undef SIMD_LANE_OPS
873 
874 #define SIMD_SHIFT_OPS(format, bits)                                        \
875   const Operator* MachineOperatorBuilder::Int##format##ShiftLeftByScalar(   \
876       int32_t shift) {                                                      \
877     DCHECK(0 <= shift && shift < bits);                                     \
878     return new (zone_) Operator1<int32_t>(                                  \
879         IrOpcode::kInt##format##ShiftLeftByScalar, Operator::kPure,         \
880         "Shift left", 1, 0, 0, 1, 0, 0, shift);                             \
881   }                                                                         \
882   const Operator* MachineOperatorBuilder::Int##format##ShiftRightByScalar(  \
883       int32_t shift) {                                                      \
884     DCHECK(0 < shift && shift <= bits);                                     \
885     return new (zone_) Operator1<int32_t>(                                  \
886         IrOpcode::kInt##format##ShiftRightByScalar, Operator::kPure,        \
887         "Arithmetic shift right", 1, 0, 0, 1, 0, 0, shift);                 \
888   }                                                                         \
889   const Operator* MachineOperatorBuilder::Uint##format##ShiftRightByScalar( \
890       int32_t shift) {                                                      \
891     DCHECK(0 <= shift && shift < bits);                                     \
892     return new (zone_) Operator1<int32_t>(                                  \
893         IrOpcode::kUint##format##ShiftRightByScalar, Operator::kPure,       \
894         "Shift right", 1, 0, 0, 1, 0, 0, shift);                            \
895   }
896 SIMD_FORMAT_LIST(SIMD_SHIFT_OPS)
897 #undef SIMD_SHIFT_OPS
898 
899 // TODO(bbudge) Add Shuffle, DCHECKs based on format.
900 #define SIMD_PERMUTE_OPS(format, bits)                                         \
901   const Operator* MachineOperatorBuilder::Simd##format##Swizzle(               \
902       uint32_t swizzle) {                                                      \
903     return new (zone_)                                                         \
904         Operator1<uint32_t>(IrOpcode::kSimd##format##Swizzle, Operator::kPure, \
905                             "Swizzle", 2, 0, 0, 1, 0, 0, swizzle);             \
906   }
907 SIMD_FORMAT_LIST(SIMD_PERMUTE_OPS)
908 #undef SIMD_PERMUTE_OPS
909 
910 }  // namespace compiler
911 }  // namespace internal
912 }  // namespace v8
913