blob: c78e15e25b9a1026946fd6a3e516a96ab805e1e1 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include <iosfwd>
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010// Opcodes for control operators.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#define CONTROL_OP_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012 V(Start) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013 V(Loop) \
14 V(Branch) \
15 V(Switch) \
16 V(IfTrue) \
17 V(IfFalse) \
18 V(IfSuccess) \
19 V(IfException) \
20 V(IfValue) \
21 V(IfDefault) \
22 V(Merge) \
23 V(Deoptimize) \
24 V(Return) \
25 V(TailCall) \
26 V(Terminate) \
27 V(OsrNormalEntry) \
28 V(OsrLoopEntry) \
29 V(Throw) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 V(End)
31
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032// 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) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040 V(HeapConstant)
41
42#define INNER_OP_LIST(V) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040043 V(Select) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044 V(Phi) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045 V(EffectSet) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046 V(EffectPhi) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047 V(Guard) \
48 V(BeginRegion) \
49 V(FinishRegion) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 V(FrameState) \
51 V(StateValues) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 V(TypedStateValues) \
53 V(ObjectState) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000054 V(Call) \
55 V(Parameter) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 V(OsrValue) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057 V(Projection)
58
59#define COMMON_OP_LIST(V) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 CONSTANT_OP_LIST(V) \
61 INNER_OP_LIST(V) \
62 V(Dead)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063
64// Opcodes for JavaScript operators.
65#define JS_COMPARE_BINOP_LIST(V) \
66 V(JSEqual) \
67 V(JSNotEqual) \
68 V(JSStrictEqual) \
69 V(JSStrictNotEqual) \
70 V(JSLessThan) \
71 V(JSGreaterThan) \
72 V(JSLessThanOrEqual) \
73 V(JSGreaterThanOrEqual)
74
75#define JS_BITWISE_BINOP_LIST(V) \
76 V(JSBitwiseOr) \
77 V(JSBitwiseXor) \
78 V(JSBitwiseAnd) \
79 V(JSShiftLeft) \
80 V(JSShiftRight) \
81 V(JSShiftRightLogical)
82
83#define JS_ARITH_BINOP_LIST(V) \
84 V(JSAdd) \
85 V(JSSubtract) \
86 V(JSMultiply) \
87 V(JSDivide) \
88 V(JSModulus)
89
90#define JS_SIMPLE_BINOP_LIST(V) \
91 JS_COMPARE_BINOP_LIST(V) \
92 JS_BITWISE_BINOP_LIST(V) \
93 JS_ARITH_BINOP_LIST(V)
94
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095#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) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106 JS_CONVERSION_UNOP_LIST(V) \
107 JS_OTHER_UNOP_LIST(V)
108
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000109#define JS_OBJECT_OP_LIST(V) \
110 V(JSCreate) \
111 V(JSCreateArguments) \
112 V(JSCreateArray) \
113 V(JSCreateClosure) \
114 V(JSCreateIterResultObject) \
115 V(JSCreateLiteralArray) \
116 V(JSCreateLiteralObject) \
117 V(JSCreateLiteralRegExp) \
118 V(JSLoadProperty) \
119 V(JSLoadNamed) \
120 V(JSLoadGlobal) \
121 V(JSStoreProperty) \
122 V(JSStoreNamed) \
123 V(JSStoreGlobal) \
124 V(JSDeleteProperty) \
125 V(JSHasProperty) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000126 V(JSInstanceOf)
127
128#define JS_CONTEXT_OP_LIST(V) \
129 V(JSLoadContext) \
130 V(JSStoreContext) \
131 V(JSCreateFunctionContext) \
132 V(JSCreateCatchContext) \
133 V(JSCreateWithContext) \
134 V(JSCreateBlockContext) \
135 V(JSCreateModuleContext) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400136 V(JSCreateScriptContext)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137
138#define JS_OTHER_OP_LIST(V) \
139 V(JSCallConstruct) \
140 V(JSCallFunction) \
141 V(JSCallRuntime) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000142 V(JSConvertReceiver) \
143 V(JSForInDone) \
144 V(JSForInNext) \
145 V(JSForInPrepare) \
146 V(JSForInStep) \
147 V(JSLoadMessage) \
148 V(JSStoreMessage) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149 V(JSYield) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000150 V(JSStackCheck)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000151
152#define JS_OP_LIST(V) \
153 JS_SIMPLE_BINOP_LIST(V) \
154 JS_SIMPLE_UNOP_LIST(V) \
155 JS_OBJECT_OP_LIST(V) \
156 JS_CONTEXT_OP_LIST(V) \
157 JS_OTHER_OP_LIST(V)
158
159// Opcodes for VirtuaMachine-level operators.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000160#define SIMPLIFIED_COMPARE_BINOP_LIST(V) \
161 V(NumberEqual) \
162 V(NumberLessThan) \
163 V(NumberLessThanOrEqual) \
164 V(ReferenceEqual) \
165 V(StringEqual) \
166 V(StringLessThan) \
167 V(StringLessThanOrEqual)
168
169#define SIMPLIFIED_OP_LIST(V) \
170 SIMPLIFIED_COMPARE_BINOP_LIST(V) \
171 V(BooleanNot) \
172 V(BooleanToNumber) \
173 V(NumberAdd) \
174 V(NumberSubtract) \
175 V(NumberMultiply) \
176 V(NumberDivide) \
177 V(NumberModulus) \
178 V(NumberBitwiseOr) \
179 V(NumberBitwiseXor) \
180 V(NumberBitwiseAnd) \
181 V(NumberShiftLeft) \
182 V(NumberShiftRight) \
183 V(NumberShiftRightLogical) \
184 V(NumberToInt32) \
185 V(NumberToUint32) \
186 V(NumberIsHoleNaN) \
187 V(PlainPrimitiveToNumber) \
188 V(ChangeTaggedToInt32) \
189 V(ChangeTaggedToUint32) \
190 V(ChangeTaggedToFloat64) \
191 V(ChangeInt32ToTagged) \
192 V(ChangeUint32ToTagged) \
193 V(ChangeFloat64ToTagged) \
194 V(ChangeBoolToBit) \
195 V(ChangeBitToBool) \
196 V(Allocate) \
197 V(LoadField) \
198 V(LoadBuffer) \
199 V(LoadElement) \
200 V(StoreField) \
201 V(StoreBuffer) \
202 V(StoreElement) \
203 V(ObjectIsNumber) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100204 V(ObjectIsReceiver) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000205 V(ObjectIsSmi)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000206
207// Opcodes for Machine-level operators.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000208#define MACHINE_COMPARE_BINOP_LIST(V) \
209 V(Word32Equal) \
210 V(Word64Equal) \
211 V(Int32LessThan) \
212 V(Int32LessThanOrEqual) \
213 V(Uint32LessThan) \
214 V(Uint32LessThanOrEqual) \
215 V(Int64LessThan) \
216 V(Int64LessThanOrEqual) \
217 V(Uint64LessThan) \
218 V(Uint64LessThanOrEqual) \
219 V(Float32Equal) \
220 V(Float32LessThan) \
221 V(Float32LessThanOrEqual) \
222 V(Float64Equal) \
223 V(Float64LessThan) \
224 V(Float64LessThanOrEqual)
225
226#define MACHINE_OP_LIST(V) \
227 MACHINE_COMPARE_BINOP_LIST(V) \
228 V(Load) \
229 V(Store) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100230 V(StackSlot) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000231 V(Word32And) \
232 V(Word32Or) \
233 V(Word32Xor) \
234 V(Word32Shl) \
235 V(Word32Shr) \
236 V(Word32Sar) \
237 V(Word32Ror) \
238 V(Word32Clz) \
239 V(Word32Ctz) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100240 V(Word32ReverseBits) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000241 V(Word32Popcnt) \
242 V(Word64Popcnt) \
243 V(Word64And) \
244 V(Word64Or) \
245 V(Word64Xor) \
246 V(Word64Shl) \
247 V(Word64Shr) \
248 V(Word64Sar) \
249 V(Word64Ror) \
250 V(Word64Clz) \
251 V(Word64Ctz) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100252 V(Word64ReverseBits) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000253 V(Int32Add) \
254 V(Int32AddWithOverflow) \
255 V(Int32Sub) \
256 V(Int32SubWithOverflow) \
257 V(Int32Mul) \
258 V(Int32MulHigh) \
259 V(Int32Div) \
260 V(Int32Mod) \
261 V(Uint32Div) \
262 V(Uint32Mod) \
263 V(Uint32MulHigh) \
264 V(Int64Add) \
265 V(Int64AddWithOverflow) \
266 V(Int64Sub) \
267 V(Int64SubWithOverflow) \
268 V(Int64Mul) \
269 V(Int64Div) \
270 V(Int64Mod) \
271 V(Uint64Div) \
272 V(Uint64Mod) \
273 V(ChangeFloat32ToFloat64) \
274 V(ChangeFloat64ToInt32) \
275 V(ChangeFloat64ToUint32) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100276 V(TruncateFloat32ToInt32) \
277 V(TruncateFloat32ToUint32) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000278 V(TryTruncateFloat32ToInt64) \
279 V(TryTruncateFloat64ToInt64) \
280 V(TryTruncateFloat32ToUint64) \
281 V(TryTruncateFloat64ToUint64) \
282 V(ChangeInt32ToFloat64) \
283 V(ChangeInt32ToInt64) \
284 V(ChangeUint32ToFloat64) \
285 V(ChangeUint32ToUint64) \
286 V(TruncateFloat64ToFloat32) \
287 V(TruncateFloat64ToInt32) \
288 V(TruncateInt64ToInt32) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100289 V(RoundInt32ToFloat32) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000290 V(RoundInt64ToFloat32) \
291 V(RoundInt64ToFloat64) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100292 V(RoundUint32ToFloat32) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000293 V(RoundUint64ToFloat32) \
294 V(RoundUint64ToFloat64) \
295 V(BitcastFloat32ToInt32) \
296 V(BitcastFloat64ToInt64) \
297 V(BitcastInt32ToFloat32) \
298 V(BitcastInt64ToFloat64) \
299 V(Float32Add) \
300 V(Float32Sub) \
301 V(Float32Mul) \
302 V(Float32Div) \
303 V(Float32Max) \
304 V(Float32Min) \
305 V(Float32Abs) \
306 V(Float32Sqrt) \
307 V(Float32RoundDown) \
308 V(Float64Add) \
309 V(Float64Sub) \
310 V(Float64Mul) \
311 V(Float64Div) \
312 V(Float64Mod) \
313 V(Float64Max) \
314 V(Float64Min) \
315 V(Float64Abs) \
316 V(Float64Sqrt) \
317 V(Float64RoundDown) \
318 V(Float32RoundUp) \
319 V(Float64RoundUp) \
320 V(Float32RoundTruncate) \
321 V(Float64RoundTruncate) \
322 V(Float64RoundTiesAway) \
323 V(Float32RoundTiesEven) \
324 V(Float64RoundTiesEven) \
325 V(Float64ExtractLowWord32) \
326 V(Float64ExtractHighWord32) \
327 V(Float64InsertLowWord32) \
328 V(Float64InsertHighWord32) \
329 V(LoadStackPointer) \
330 V(LoadFramePointer) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100331 V(LoadParentFramePointer) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000332 V(CheckedLoad) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400333 V(CheckedStore)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000334
335#define VALUE_OP_LIST(V) \
336 COMMON_OP_LIST(V) \
337 SIMPLIFIED_OP_LIST(V) \
338 MACHINE_OP_LIST(V) \
339 JS_OP_LIST(V)
340
341// The combination of all operators at all levels and the common operators.
342#define ALL_OP_LIST(V) \
343 CONTROL_OP_LIST(V) \
344 VALUE_OP_LIST(V)
345
346namespace v8 {
347namespace internal {
348namespace compiler {
349
350// Declare an enumeration with all the opcodes at all levels so that they
351// can be globally, uniquely numbered.
352class IrOpcode {
353 public:
354 enum Value {
355#define DECLARE_OPCODE(x) k##x,
356 ALL_OP_LIST(DECLARE_OPCODE)
357#undef DECLARE_OPCODE
358 kLast = -1
359#define COUNT_OPCODE(x) +1
360 ALL_OP_LIST(COUNT_OPCODE)
361#undef COUNT_OPCODE
362 };
363
364 // Returns the mnemonic name of an opcode.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400365 static char const* Mnemonic(Value value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000366
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000367 // Returns true if opcode for common operator.
368 static bool IsCommonOpcode(Value value) {
369 return kStart <= value && value <= kDead;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370 }
371
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000372 // Returns true if opcode for control operator.
373 static bool IsControlOpcode(Value value) {
374 return kStart <= value && value <= kEnd;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000375 }
376
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000377 // Returns true if opcode for JavaScript operator.
378 static bool IsJsOpcode(Value value) {
379 return kJSEqual <= value && value <= kJSStackCheck;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400380 }
381
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000382 // Returns true if opcode for constant operator.
383 static bool IsConstantOpcode(Value value) {
384 return kInt32Constant <= value && value <= kHeapConstant;
385 }
386
387 static bool IsPhiOpcode(Value value) {
388 return value == kPhi || value == kEffectPhi;
389 }
390
391 static bool IsMergeOpcode(Value value) {
392 return value == kMerge || value == kLoop;
393 }
394
395 static bool IsIfProjectionOpcode(Value value) {
396 return kIfTrue <= value && value <= kIfDefault;
397 }
398
399 // Returns true if opcode can be inlined.
400 static bool IsInlineeOpcode(Value value) {
401 return value == kJSCallConstruct || value == kJSCallFunction;
402 }
403
404 // Returns true if opcode for comparison operator.
405 static bool IsComparisonOpcode(Value value) {
406 return (kJSEqual <= value && value <= kJSGreaterThanOrEqual) ||
407 (kNumberEqual <= value && value <= kStringLessThanOrEqual) ||
408 (kWord32Equal <= value && value <= kFloat64LessThanOrEqual);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409 }
410};
411
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412std::ostream& operator<<(std::ostream&, IrOpcode::Value);
413
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000414} // namespace compiler
415} // namespace internal
416} // namespace v8
417
418#endif // V8_COMPILER_OPCODES_H_