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