deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / compiler / opcodes.h
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_OPCODES_H_
6 #define V8_COMPILER_OPCODES_H_
7
8 // Opcodes for control operators.
9 #define INNER_CONTROL_OP_LIST(V) \
10   V(Dead)                        \
11   V(Loop)                        \
12   V(Branch)                      \
13   V(Switch)                      \
14   V(IfTrue)                      \
15   V(IfFalse)                     \
16   V(IfSuccess)                   \
17   V(IfException)                 \
18   V(IfValue)                     \
19   V(IfDefault)                   \
20   V(Merge)                       \
21   V(Deoptimize)                  \
22   V(Return)                      \
23   V(OsrNormalEntry)              \
24   V(OsrLoopEntry)                \
25   V(Throw)
26
27 #define CONTROL_OP_LIST(V) \
28   INNER_CONTROL_OP_LIST(V) \
29   V(Start)                 \
30   V(End)
31
32 // Opcodes for constant operators.
33 #define CONSTANT_OP_LIST(V) \
34   V(Int32Constant)          \
35   V(Int64Constant)          \
36   V(Float32Constant)        \
37   V(Float64Constant)        \
38   V(ExternalConstant)       \
39   V(NumberConstant)         \
40   V(HeapConstant)
41
42 #define INNER_OP_LIST(V) \
43   V(Select)              \
44   V(Phi)                 \
45   V(EffectSet)           \
46   V(EffectPhi)           \
47   V(ValueEffect)         \
48   V(Finish)              \
49   V(FrameState)          \
50   V(StateValues)         \
51   V(TypedStateValues)    \
52   V(Call)                \
53   V(Parameter)           \
54   V(OsrValue)            \
55   V(Projection)
56
57 #define COMMON_OP_LIST(V) \
58   CONSTANT_OP_LIST(V)     \
59   INNER_OP_LIST(V)        \
60   V(Always)
61
62 // Opcodes for JavaScript operators.
63 #define JS_COMPARE_BINOP_LIST(V) \
64   V(JSEqual)                     \
65   V(JSNotEqual)                  \
66   V(JSStrictEqual)               \
67   V(JSStrictNotEqual)            \
68   V(JSLessThan)                  \
69   V(JSGreaterThan)               \
70   V(JSLessThanOrEqual)           \
71   V(JSGreaterThanOrEqual)
72
73 #define JS_BITWISE_BINOP_LIST(V) \
74   V(JSBitwiseOr)                 \
75   V(JSBitwiseXor)                \
76   V(JSBitwiseAnd)                \
77   V(JSShiftLeft)                 \
78   V(JSShiftRight)                \
79   V(JSShiftRightLogical)
80
81 #define JS_ARITH_BINOP_LIST(V) \
82   V(JSAdd)                     \
83   V(JSSubtract)                \
84   V(JSMultiply)                \
85   V(JSDivide)                  \
86   V(JSModulus)
87
88 #define JS_SIMPLE_BINOP_LIST(V) \
89   JS_COMPARE_BINOP_LIST(V)      \
90   JS_BITWISE_BINOP_LIST(V)      \
91   JS_ARITH_BINOP_LIST(V)
92
93 #define JS_LOGIC_UNOP_LIST(V) V(JSUnaryNot)
94
95 #define JS_CONVERSION_UNOP_LIST(V) \
96   V(JSToBoolean)                   \
97   V(JSToNumber)                    \
98   V(JSToString)                    \
99   V(JSToName)                      \
100   V(JSToObject)
101
102 #define JS_OTHER_UNOP_LIST(V) \
103   V(JSTypeOf)
104
105 #define JS_SIMPLE_UNOP_LIST(V) \
106   JS_LOGIC_UNOP_LIST(V)        \
107   JS_CONVERSION_UNOP_LIST(V)   \
108   JS_OTHER_UNOP_LIST(V)
109
110 #define JS_OBJECT_OP_LIST(V) \
111   V(JSCreate)                \
112   V(JSLoadProperty)          \
113   V(JSLoadNamed)             \
114   V(JSStoreProperty)         \
115   V(JSStoreNamed)            \
116   V(JSDeleteProperty)        \
117   V(JSHasProperty)           \
118   V(JSInstanceOf)
119
120 #define JS_CONTEXT_OP_LIST(V) \
121   V(JSLoadContext)            \
122   V(JSStoreContext)           \
123   V(JSCreateFunctionContext)  \
124   V(JSCreateCatchContext)     \
125   V(JSCreateWithContext)      \
126   V(JSCreateBlockContext)     \
127   V(JSCreateModuleContext)    \
128   V(JSCreateScriptContext)
129
130 #define JS_OTHER_OP_LIST(V) \
131   V(JSCallConstruct)        \
132   V(JSCallFunction)         \
133   V(JSCallRuntime)          \
134   V(JSYield)                \
135   V(JSStackCheck)
136
137 #define JS_OP_LIST(V)     \
138   JS_SIMPLE_BINOP_LIST(V) \
139   JS_SIMPLE_UNOP_LIST(V)  \
140   JS_OBJECT_OP_LIST(V)    \
141   JS_CONTEXT_OP_LIST(V)   \
142   JS_OTHER_OP_LIST(V)
143
144 // Opcodes for VirtuaMachine-level operators.
145 #define SIMPLIFIED_COMPARE_BINOP_LIST(V) \
146   V(NumberEqual)                         \
147   V(NumberLessThan)                      \
148   V(NumberLessThanOrEqual)               \
149   V(ReferenceEqual)                      \
150   V(StringEqual)                         \
151   V(StringLessThan)                      \
152   V(StringLessThanOrEqual)
153
154 #define SIMPLIFIED_OP_LIST(V)      \
155   SIMPLIFIED_COMPARE_BINOP_LIST(V) \
156   V(BooleanNot)                    \
157   V(BooleanToNumber)               \
158   V(NumberAdd)                     \
159   V(NumberSubtract)                \
160   V(NumberMultiply)                \
161   V(NumberDivide)                  \
162   V(NumberModulus)                 \
163   V(NumberToInt32)                 \
164   V(NumberToUint32)                \
165   V(PlainPrimitiveToNumber)        \
166   V(StringAdd)                     \
167   V(ChangeTaggedToInt32)           \
168   V(ChangeTaggedToUint32)          \
169   V(ChangeTaggedToFloat64)         \
170   V(ChangeInt32ToTagged)           \
171   V(ChangeUint32ToTagged)          \
172   V(ChangeFloat64ToTagged)         \
173   V(ChangeBoolToBit)               \
174   V(ChangeBitToBool)               \
175   V(LoadField)                     \
176   V(LoadBuffer)                    \
177   V(LoadElement)                   \
178   V(StoreField)                    \
179   V(StoreBuffer)                   \
180   V(StoreElement)                  \
181   V(ObjectIsSmi)                   \
182   V(ObjectIsNonNegativeSmi)
183
184 // Opcodes for Machine-level operators.
185 #define MACHINE_COMPARE_BINOP_LIST(V) \
186   V(Word32Equal)                      \
187   V(Word64Equal)                      \
188   V(Int32LessThan)                    \
189   V(Int32LessThanOrEqual)             \
190   V(Uint32LessThan)                   \
191   V(Uint32LessThanOrEqual)            \
192   V(Int64LessThan)                    \
193   V(Int64LessThanOrEqual)             \
194   V(Uint64LessThan)                   \
195   V(Float64Equal)                     \
196   V(Float64LessThan)                  \
197   V(Float64LessThanOrEqual)
198
199 #define MACHINE_OP_LIST(V)      \
200   MACHINE_COMPARE_BINOP_LIST(V) \
201   V(Load)                       \
202   V(Store)                      \
203   V(Word32And)                  \
204   V(Word32Or)                   \
205   V(Word32Xor)                  \
206   V(Word32Shl)                  \
207   V(Word32Shr)                  \
208   V(Word32Sar)                  \
209   V(Word32Ror)                  \
210   V(Word32Clz)                  \
211   V(Word64And)                  \
212   V(Word64Or)                   \
213   V(Word64Xor)                  \
214   V(Word64Shl)                  \
215   V(Word64Shr)                  \
216   V(Word64Sar)                  \
217   V(Word64Ror)                  \
218   V(Int32Add)                   \
219   V(Int32AddWithOverflow)       \
220   V(Int32Sub)                   \
221   V(Int32SubWithOverflow)       \
222   V(Int32Mul)                   \
223   V(Int32MulHigh)               \
224   V(Int32Div)                   \
225   V(Int32Mod)                   \
226   V(Uint32Div)                  \
227   V(Uint32Mod)                  \
228   V(Uint32MulHigh)              \
229   V(Int64Add)                   \
230   V(Int64Sub)                   \
231   V(Int64Mul)                   \
232   V(Int64Div)                   \
233   V(Int64Mod)                   \
234   V(Uint64Div)                  \
235   V(Uint64Mod)                  \
236   V(ChangeFloat32ToFloat64)     \
237   V(ChangeFloat64ToInt32)       \
238   V(ChangeFloat64ToUint32)      \
239   V(ChangeInt32ToFloat64)       \
240   V(ChangeInt32ToInt64)         \
241   V(ChangeUint32ToFloat64)      \
242   V(ChangeUint32ToUint64)       \
243   V(TruncateFloat64ToFloat32)   \
244   V(TruncateFloat64ToInt32)     \
245   V(TruncateInt64ToInt32)       \
246   V(Float64Add)                 \
247   V(Float64Sub)                 \
248   V(Float64Mul)                 \
249   V(Float64Div)                 \
250   V(Float64Mod)                 \
251   V(Float64Max)                 \
252   V(Float64Min)                 \
253   V(Float64Sqrt)                \
254   V(Float64RoundDown)           \
255   V(Float64RoundTruncate)       \
256   V(Float64RoundTiesAway)       \
257   V(Float64ExtractLowWord32)    \
258   V(Float64ExtractHighWord32)   \
259   V(Float64InsertLowWord32)     \
260   V(Float64InsertHighWord32)    \
261   V(LoadStackPointer)           \
262   V(CheckedLoad)                \
263   V(CheckedStore)
264
265 #define VALUE_OP_LIST(V) \
266   COMMON_OP_LIST(V)      \
267   SIMPLIFIED_OP_LIST(V)  \
268   MACHINE_OP_LIST(V)     \
269   JS_OP_LIST(V)
270
271 // The combination of all operators at all levels and the common operators.
272 #define ALL_OP_LIST(V) \
273   CONTROL_OP_LIST(V)   \
274   VALUE_OP_LIST(V)
275
276 namespace v8 {
277 namespace internal {
278 namespace compiler {
279
280 // Declare an enumeration with all the opcodes at all levels so that they
281 // can be globally, uniquely numbered.
282 class IrOpcode {
283  public:
284   enum Value {
285 #define DECLARE_OPCODE(x) k##x,
286     ALL_OP_LIST(DECLARE_OPCODE)
287 #undef DECLARE_OPCODE
288     kLast = -1
289 #define COUNT_OPCODE(x) +1
290             ALL_OP_LIST(COUNT_OPCODE)
291 #undef COUNT_OPCODE
292   };
293
294   // Returns the mnemonic name of an opcode.
295   static char const* Mnemonic(Value value);
296
297   // Returns true if opcode for common operator.
298   static bool IsCommonOpcode(Value value) {
299     return kDead <= value && value <= kAlways;
300   }
301
302   // Returns true if opcode for control operator.
303   static bool IsControlOpcode(Value value) {
304     return kDead <= value && value <= kEnd;
305   }
306
307   // Returns true if opcode for JavaScript operator.
308   static bool IsJsOpcode(Value value) {
309     return kJSEqual <= value && value <= kJSStackCheck;
310   }
311
312   // Returns true if opcode for constant operator.
313   static bool IsConstantOpcode(Value value) {
314     return kInt32Constant <= value && value <= kHeapConstant;
315   }
316
317   static bool IsPhiOpcode(Value value) {
318     return value == kPhi || value == kEffectPhi;
319   }
320
321   static bool IsMergeOpcode(Value value) {
322     return value == kMerge || value == kLoop;
323   }
324
325   static bool IsIfProjectionOpcode(Value value) {
326     return kIfTrue <= value && value <= kIfDefault;
327   }
328
329   // Returns true if opcode for comparison operator.
330   static bool IsComparisonOpcode(Value value) {
331     return (kJSEqual <= value && value <= kJSGreaterThanOrEqual) ||
332            (kNumberEqual <= value && value <= kStringLessThanOrEqual) ||
333            (kWord32Equal <= value && value <= kFloat64LessThanOrEqual);
334   }
335 };
336
337 }  // namespace compiler
338 }  // namespace internal
339 }  // namespace v8
340
341 #endif  // V8_COMPILER_OPCODES_H_