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