Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | std::ostream& operator<<(std::ostream& os, TruncationMode mode) { |
| 16 | switch (mode) { |
| 17 | case TruncationMode::kJavaScript: |
| 18 | return os << "JavaScript"; |
| 19 | case TruncationMode::kRoundToZero: |
| 20 | return os << "RoundToZero"; |
| 21 | } |
| 22 | UNREACHABLE(); |
| 23 | return os; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | TruncationMode TruncationModeOf(Operator const* op) { |
| 28 | DCHECK_EQ(IrOpcode::kTruncateFloat64ToInt32, op->opcode()); |
| 29 | return OpParameter<TruncationMode>(op); |
| 30 | } |
| 31 | |
| 32 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 33 | std::ostream& operator<<(std::ostream& os, WriteBarrierKind kind) { |
| 34 | switch (kind) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | case kNoWriteBarrier: |
| 36 | return os << "NoWriteBarrier"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 37 | case kMapWriteBarrier: |
| 38 | return os << "MapWriteBarrier"; |
| 39 | case kPointerWriteBarrier: |
| 40 | return os << "PointerWriteBarrier"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 41 | case kFullWriteBarrier: |
| 42 | return os << "FullWriteBarrier"; |
| 43 | } |
| 44 | UNREACHABLE(); |
| 45 | return os; |
| 46 | } |
| 47 | |
| 48 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 49 | bool operator==(StoreRepresentation lhs, StoreRepresentation rhs) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | return lhs.representation() == rhs.representation() && |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 51 | lhs.write_barrier_kind() == rhs.write_barrier_kind(); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | bool operator!=(StoreRepresentation lhs, StoreRepresentation rhs) { |
| 56 | return !(lhs == rhs); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | size_t hash_value(StoreRepresentation rep) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 61 | return base::hash_combine(rep.representation(), rep.write_barrier_kind()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | |
| 65 | std::ostream& operator<<(std::ostream& os, StoreRepresentation rep) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | return os << "(" << rep.representation() << " : " << rep.write_barrier_kind() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | << ")"; |
| 68 | } |
| 69 | |
| 70 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 71 | LoadRepresentation LoadRepresentationOf(Operator const* op) { |
| 72 | DCHECK_EQ(IrOpcode::kLoad, op->opcode()); |
| 73 | return OpParameter<LoadRepresentation>(op); |
| 74 | } |
| 75 | |
| 76 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 77 | StoreRepresentation const& StoreRepresentationOf(Operator const* op) { |
| 78 | DCHECK_EQ(IrOpcode::kStore, op->opcode()); |
| 79 | return OpParameter<StoreRepresentation>(op); |
| 80 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 81 | |
| 82 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 83 | CheckedLoadRepresentation CheckedLoadRepresentationOf(Operator const* op) { |
| 84 | DCHECK_EQ(IrOpcode::kCheckedLoad, op->opcode()); |
| 85 | return OpParameter<CheckedLoadRepresentation>(op); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | CheckedStoreRepresentation CheckedStoreRepresentationOf(Operator const* op) { |
| 90 | DCHECK_EQ(IrOpcode::kCheckedStore, op->opcode()); |
| 91 | return OpParameter<CheckedStoreRepresentation>(op); |
| 92 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 93 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 94 | MachineRepresentation StackSlotRepresentationOf(Operator const* op) { |
| 95 | DCHECK_EQ(IrOpcode::kStackSlot, op->opcode()); |
| 96 | return OpParameter<MachineRepresentation>(op); |
| 97 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 98 | |
| 99 | #define PURE_OP_LIST(V) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 100 | V(Word32And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 101 | V(Word32Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 102 | V(Word32Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 103 | V(Word32Shl, Operator::kNoProperties, 2, 0, 1) \ |
| 104 | V(Word32Shr, Operator::kNoProperties, 2, 0, 1) \ |
| 105 | V(Word32Sar, Operator::kNoProperties, 2, 0, 1) \ |
| 106 | V(Word32Ror, Operator::kNoProperties, 2, 0, 1) \ |
| 107 | V(Word32Equal, Operator::kCommutative, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 108 | V(Word32Clz, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 109 | V(Word64And, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 110 | V(Word64Or, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 111 | V(Word64Xor, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 112 | V(Word64Shl, Operator::kNoProperties, 2, 0, 1) \ |
| 113 | V(Word64Shr, Operator::kNoProperties, 2, 0, 1) \ |
| 114 | V(Word64Sar, Operator::kNoProperties, 2, 0, 1) \ |
| 115 | V(Word64Ror, Operator::kNoProperties, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 116 | V(Word64Clz, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 117 | V(Word64Equal, Operator::kCommutative, 2, 0, 1) \ |
| 118 | V(Int32Add, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 119 | V(Int32AddWithOverflow, Operator::kAssociative | Operator::kCommutative, 2, \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 120 | 0, 2) \ |
| 121 | V(Int32Sub, Operator::kNoProperties, 2, 0, 1) \ |
| 122 | V(Int32SubWithOverflow, Operator::kNoProperties, 2, 0, 2) \ |
| 123 | V(Int32Mul, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 124 | V(Int32MulHigh, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 125 | V(Int32Div, Operator::kNoProperties, 2, 1, 1) \ |
| 126 | V(Int32Mod, Operator::kNoProperties, 2, 1, 1) \ |
| 127 | V(Int32LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 128 | V(Int32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
| 129 | V(Uint32Div, Operator::kNoProperties, 2, 1, 1) \ |
| 130 | V(Uint32LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 131 | V(Uint32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
| 132 | V(Uint32Mod, Operator::kNoProperties, 2, 1, 1) \ |
| 133 | V(Uint32MulHigh, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
| 134 | V(Int64Add, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 135 | V(Int64AddWithOverflow, Operator::kAssociative | Operator::kCommutative, 2, \ |
| 136 | 0, 2) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 137 | V(Int64Sub, Operator::kNoProperties, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 138 | V(Int64SubWithOverflow, Operator::kNoProperties, 2, 0, 2) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 139 | V(Int64Mul, Operator::kAssociative | Operator::kCommutative, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 140 | V(Int64Div, Operator::kNoProperties, 2, 1, 1) \ |
| 141 | V(Int64Mod, Operator::kNoProperties, 2, 1, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 142 | V(Int64LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 143 | V(Int64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 144 | V(Uint64Div, Operator::kNoProperties, 2, 1, 1) \ |
| 145 | V(Uint64Mod, Operator::kNoProperties, 2, 1, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 146 | V(Uint64LessThan, Operator::kNoProperties, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | V(Uint64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 148 | V(ChangeFloat32ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
| 149 | V(ChangeFloat64ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
| 150 | V(ChangeFloat64ToUint32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 151 | V(TruncateFloat32ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
| 152 | V(TruncateFloat32ToUint32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 153 | V(TryTruncateFloat32ToInt64, Operator::kNoProperties, 1, 0, 2) \ |
| 154 | V(TryTruncateFloat64ToInt64, Operator::kNoProperties, 1, 0, 2) \ |
| 155 | V(TryTruncateFloat32ToUint64, Operator::kNoProperties, 1, 0, 2) \ |
| 156 | V(TryTruncateFloat64ToUint64, Operator::kNoProperties, 1, 0, 2) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 157 | V(ChangeInt32ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 158 | V(RoundInt32ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 159 | V(RoundInt64ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
| 160 | V(RoundInt64ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 161 | V(RoundUint32ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 162 | V(RoundUint64ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
| 163 | V(RoundUint64ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 164 | V(ChangeInt32ToInt64, Operator::kNoProperties, 1, 0, 1) \ |
| 165 | V(ChangeUint32ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
| 166 | V(ChangeUint32ToUint64, Operator::kNoProperties, 1, 0, 1) \ |
| 167 | V(TruncateFloat64ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 168 | V(TruncateInt64ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 169 | V(BitcastFloat32ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
| 170 | V(BitcastFloat64ToInt64, Operator::kNoProperties, 1, 0, 1) \ |
| 171 | V(BitcastInt32ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
| 172 | V(BitcastInt64ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
| 173 | V(Float32Abs, Operator::kNoProperties, 1, 0, 1) \ |
| 174 | V(Float32Add, Operator::kCommutative, 2, 0, 1) \ |
| 175 | V(Float32Sub, Operator::kNoProperties, 2, 0, 1) \ |
| 176 | V(Float32Mul, Operator::kCommutative, 2, 0, 1) \ |
| 177 | V(Float32Div, Operator::kNoProperties, 2, 0, 1) \ |
| 178 | V(Float32Sqrt, Operator::kNoProperties, 1, 0, 1) \ |
| 179 | V(Float64Abs, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 180 | V(Float64Add, Operator::kCommutative, 2, 0, 1) \ |
| 181 | V(Float64Sub, Operator::kNoProperties, 2, 0, 1) \ |
| 182 | V(Float64Mul, Operator::kCommutative, 2, 0, 1) \ |
| 183 | V(Float64Div, Operator::kNoProperties, 2, 0, 1) \ |
| 184 | V(Float64Mod, Operator::kNoProperties, 2, 0, 1) \ |
| 185 | V(Float64Sqrt, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 186 | V(Float32Equal, Operator::kCommutative, 2, 0, 1) \ |
| 187 | V(Float32LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 188 | V(Float32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 189 | V(Float64Equal, Operator::kCommutative, 2, 0, 1) \ |
| 190 | V(Float64LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 191 | V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 192 | V(Float64ExtractLowWord32, Operator::kNoProperties, 1, 0, 1) \ |
| 193 | V(Float64ExtractHighWord32, Operator::kNoProperties, 1, 0, 1) \ |
| 194 | V(Float64InsertLowWord32, Operator::kNoProperties, 2, 0, 1) \ |
| 195 | V(Float64InsertHighWord32, Operator::kNoProperties, 2, 0, 1) \ |
| 196 | V(LoadStackPointer, Operator::kNoProperties, 0, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 197 | V(LoadFramePointer, Operator::kNoProperties, 0, 0, 1) \ |
| 198 | V(LoadParentFramePointer, Operator::kNoProperties, 0, 0, 1) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 199 | |
| 200 | #define PURE_OPTIONAL_OP_LIST(V) \ |
| 201 | V(Word32Ctz, Operator::kNoProperties, 1, 0, 1) \ |
| 202 | V(Word64Ctz, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 203 | V(Word32ReverseBits, Operator::kNoProperties, 1, 0, 1) \ |
| 204 | V(Word64ReverseBits, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 205 | V(Word32Popcnt, Operator::kNoProperties, 1, 0, 1) \ |
| 206 | V(Word64Popcnt, Operator::kNoProperties, 1, 0, 1) \ |
| 207 | V(Float32Max, Operator::kNoProperties, 2, 0, 1) \ |
| 208 | V(Float32Min, Operator::kNoProperties, 2, 0, 1) \ |
| 209 | V(Float64Max, Operator::kNoProperties, 2, 0, 1) \ |
| 210 | V(Float64Min, Operator::kNoProperties, 2, 0, 1) \ |
| 211 | V(Float32RoundDown, Operator::kNoProperties, 1, 0, 1) \ |
| 212 | V(Float64RoundDown, Operator::kNoProperties, 1, 0, 1) \ |
| 213 | V(Float32RoundUp, Operator::kNoProperties, 1, 0, 1) \ |
| 214 | V(Float64RoundUp, Operator::kNoProperties, 1, 0, 1) \ |
| 215 | V(Float32RoundTruncate, Operator::kNoProperties, 1, 0, 1) \ |
| 216 | V(Float64RoundTruncate, Operator::kNoProperties, 1, 0, 1) \ |
| 217 | V(Float64RoundTiesAway, Operator::kNoProperties, 1, 0, 1) \ |
| 218 | V(Float32RoundTiesEven, Operator::kNoProperties, 1, 0, 1) \ |
| 219 | V(Float64RoundTiesEven, Operator::kNoProperties, 1, 0, 1) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 220 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 221 | #define MACHINE_TYPE_LIST(V) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 222 | V(Float32) \ |
| 223 | V(Float64) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 224 | V(Simd128) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 225 | V(Int8) \ |
| 226 | V(Uint8) \ |
| 227 | V(Int16) \ |
| 228 | V(Uint16) \ |
| 229 | V(Int32) \ |
| 230 | V(Uint32) \ |
| 231 | V(Int64) \ |
| 232 | V(Uint64) \ |
| 233 | V(Pointer) \ |
| 234 | V(AnyTagged) |
| 235 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 236 | #define MACHINE_REPRESENTATION_LIST(V) \ |
| 237 | V(kFloat32) \ |
| 238 | V(kFloat64) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 239 | V(kSimd128) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 240 | V(kWord8) \ |
| 241 | V(kWord16) \ |
| 242 | V(kWord32) \ |
| 243 | V(kWord64) \ |
| 244 | V(kTagged) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 245 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 246 | struct MachineOperatorGlobalCache { |
| 247 | #define PURE(Name, properties, value_input_count, control_input_count, \ |
| 248 | output_count) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 249 | struct Name##Operator final : public Operator { \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 250 | Name##Operator() \ |
| 251 | : Operator(IrOpcode::k##Name, Operator::kPure | properties, #Name, \ |
| 252 | value_input_count, 0, control_input_count, output_count, 0, \ |
| 253 | 0) {} \ |
| 254 | }; \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 255 | Name##Operator k##Name; |
| 256 | PURE_OP_LIST(PURE) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 257 | PURE_OPTIONAL_OP_LIST(PURE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 258 | #undef PURE |
| 259 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 260 | template <TruncationMode kMode> |
| 261 | struct TruncateFloat64ToInt32Operator final |
| 262 | : public Operator1<TruncationMode> { |
| 263 | TruncateFloat64ToInt32Operator() |
| 264 | : Operator1<TruncationMode>(IrOpcode::kTruncateFloat64ToInt32, |
| 265 | Operator::kPure, "TruncateFloat64ToInt32", |
| 266 | 1, 0, 0, 1, 0, 0, kMode) {} |
| 267 | }; |
| 268 | TruncateFloat64ToInt32Operator<TruncationMode::kJavaScript> |
| 269 | kTruncateFloat64ToInt32JavaScript; |
| 270 | TruncateFloat64ToInt32Operator<TruncationMode::kRoundToZero> |
| 271 | kTruncateFloat64ToInt32RoundToZero; |
| 272 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 273 | #define LOAD(Type) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 274 | struct Load##Type##Operator final : public Operator1<LoadRepresentation> { \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 275 | Load##Type##Operator() \ |
| 276 | : Operator1<LoadRepresentation>( \ |
| 277 | IrOpcode::kLoad, Operator::kNoThrow | Operator::kNoWrite, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 278 | "Load", 2, 1, 1, 1, 1, 0, MachineType::Type()) {} \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 279 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 280 | struct CheckedLoad##Type##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 281 | : public Operator1<CheckedLoadRepresentation> { \ |
| 282 | CheckedLoad##Type##Operator() \ |
| 283 | : Operator1<CheckedLoadRepresentation>( \ |
| 284 | IrOpcode::kCheckedLoad, Operator::kNoThrow | Operator::kNoWrite, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 285 | "CheckedLoad", 3, 1, 1, 1, 1, 0, MachineType::Type()) {} \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 286 | }; \ |
| 287 | Load##Type##Operator kLoad##Type; \ |
| 288 | CheckedLoad##Type##Operator kCheckedLoad##Type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 289 | MACHINE_TYPE_LIST(LOAD) |
| 290 | #undef LOAD |
| 291 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 292 | #define STACKSLOT(Type) \ |
| 293 | struct StackSlot##Type##Operator final \ |
| 294 | : public Operator1<MachineRepresentation> { \ |
| 295 | StackSlot##Type##Operator() \ |
| 296 | : Operator1<MachineRepresentation>( \ |
| 297 | IrOpcode::kStackSlot, Operator::kNoThrow, "StackSlot", 0, 0, 0, \ |
| 298 | 1, 0, 0, MachineType::Type().representation()) {} \ |
| 299 | }; \ |
| 300 | StackSlot##Type##Operator kStackSlot##Type; |
| 301 | MACHINE_TYPE_LIST(STACKSLOT) |
| 302 | #undef STACKSLOT |
| 303 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 304 | #define STORE(Type) \ |
| 305 | struct Store##Type##Operator : public Operator1<StoreRepresentation> { \ |
| 306 | explicit Store##Type##Operator(WriteBarrierKind write_barrier_kind) \ |
| 307 | : Operator1<StoreRepresentation>( \ |
| 308 | IrOpcode::kStore, Operator::kNoRead | Operator::kNoThrow, \ |
| 309 | "Store", 3, 1, 1, 0, 1, 0, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 310 | StoreRepresentation(MachineRepresentation::Type, \ |
| 311 | write_barrier_kind)) {} \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 312 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 313 | struct Store##Type##NoWriteBarrier##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 314 | : public Store##Type##Operator { \ |
| 315 | Store##Type##NoWriteBarrier##Operator() \ |
| 316 | : Store##Type##Operator(kNoWriteBarrier) {} \ |
| 317 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 318 | struct Store##Type##MapWriteBarrier##Operator final \ |
| 319 | : public Store##Type##Operator { \ |
| 320 | Store##Type##MapWriteBarrier##Operator() \ |
| 321 | : Store##Type##Operator(kMapWriteBarrier) {} \ |
| 322 | }; \ |
| 323 | struct Store##Type##PointerWriteBarrier##Operator final \ |
| 324 | : public Store##Type##Operator { \ |
| 325 | Store##Type##PointerWriteBarrier##Operator() \ |
| 326 | : Store##Type##Operator(kPointerWriteBarrier) {} \ |
| 327 | }; \ |
| 328 | struct Store##Type##FullWriteBarrier##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 329 | : public Store##Type##Operator { \ |
| 330 | Store##Type##FullWriteBarrier##Operator() \ |
| 331 | : Store##Type##Operator(kFullWriteBarrier) {} \ |
| 332 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 333 | struct CheckedStore##Type##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 334 | : public Operator1<CheckedStoreRepresentation> { \ |
| 335 | CheckedStore##Type##Operator() \ |
| 336 | : Operator1<CheckedStoreRepresentation>( \ |
| 337 | IrOpcode::kCheckedStore, Operator::kNoRead | Operator::kNoThrow, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 338 | "CheckedStore", 4, 1, 1, 0, 1, 0, MachineRepresentation::Type) { \ |
| 339 | } \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 340 | }; \ |
| 341 | Store##Type##NoWriteBarrier##Operator kStore##Type##NoWriteBarrier; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 342 | Store##Type##MapWriteBarrier##Operator kStore##Type##MapWriteBarrier; \ |
| 343 | Store##Type##PointerWriteBarrier##Operator \ |
| 344 | kStore##Type##PointerWriteBarrier; \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 345 | Store##Type##FullWriteBarrier##Operator kStore##Type##FullWriteBarrier; \ |
| 346 | CheckedStore##Type##Operator kCheckedStore##Type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 347 | MACHINE_REPRESENTATION_LIST(STORE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 348 | #undef STORE |
| 349 | }; |
| 350 | |
| 351 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 352 | static base::LazyInstance<MachineOperatorGlobalCache>::type kCache = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 353 | LAZY_INSTANCE_INITIALIZER; |
| 354 | |
| 355 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 356 | MachineOperatorBuilder::MachineOperatorBuilder(Zone* zone, |
| 357 | MachineRepresentation word, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 358 | Flags flags) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 359 | : cache_(kCache.Get()), word_(word), flags_(flags) { |
| 360 | DCHECK(word == MachineRepresentation::kWord32 || |
| 361 | word == MachineRepresentation::kWord64); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 365 | #define PURE(Name, properties, value_input_count, control_input_count, \ |
| 366 | output_count) \ |
| 367 | const Operator* MachineOperatorBuilder::Name() { return &cache_.k##Name; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 368 | PURE_OP_LIST(PURE) |
| 369 | #undef PURE |
| 370 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 371 | #define PURE(Name, properties, value_input_count, control_input_count, \ |
| 372 | output_count) \ |
| 373 | const OptionalOperator MachineOperatorBuilder::Name() { \ |
| 374 | return OptionalOperator(flags_ & k##Name ? &cache_.k##Name : nullptr); \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 375 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 376 | PURE_OPTIONAL_OP_LIST(PURE) |
| 377 | #undef PURE |
| 378 | |
| 379 | |
| 380 | const Operator* MachineOperatorBuilder::TruncateFloat64ToInt32( |
| 381 | TruncationMode mode) { |
| 382 | switch (mode) { |
| 383 | case TruncationMode::kJavaScript: |
| 384 | return &cache_.kTruncateFloat64ToInt32JavaScript; |
| 385 | case TruncationMode::kRoundToZero: |
| 386 | return &cache_.kTruncateFloat64ToInt32RoundToZero; |
| 387 | } |
| 388 | UNREACHABLE(); |
| 389 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 393 | const Operator* MachineOperatorBuilder::Load(LoadRepresentation rep) { |
| 394 | #define LOAD(Type) \ |
| 395 | if (rep == MachineType::Type()) { \ |
| 396 | return &cache_.kLoad##Type; \ |
| 397 | } |
| 398 | MACHINE_TYPE_LIST(LOAD) |
| 399 | #undef LOAD |
| 400 | UNREACHABLE(); |
| 401 | return nullptr; |
| 402 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 403 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 404 | const Operator* MachineOperatorBuilder::StackSlot(MachineRepresentation rep) { |
| 405 | #define STACKSLOT(Type) \ |
| 406 | if (rep == MachineType::Type().representation()) { \ |
| 407 | return &cache_.kStackSlot##Type; \ |
| 408 | } |
| 409 | MACHINE_TYPE_LIST(STACKSLOT) |
| 410 | #undef STACKSLOT |
| 411 | UNREACHABLE(); |
| 412 | return nullptr; |
| 413 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 414 | |
| 415 | const Operator* MachineOperatorBuilder::Store(StoreRepresentation store_rep) { |
| 416 | switch (store_rep.representation()) { |
| 417 | #define STORE(kRep) \ |
| 418 | case MachineRepresentation::kRep: \ |
| 419 | switch (store_rep.write_barrier_kind()) { \ |
| 420 | case kNoWriteBarrier: \ |
| 421 | return &cache_.k##Store##kRep##NoWriteBarrier; \ |
| 422 | case kMapWriteBarrier: \ |
| 423 | return &cache_.k##Store##kRep##MapWriteBarrier; \ |
| 424 | case kPointerWriteBarrier: \ |
| 425 | return &cache_.k##Store##kRep##PointerWriteBarrier; \ |
| 426 | case kFullWriteBarrier: \ |
| 427 | return &cache_.k##Store##kRep##FullWriteBarrier; \ |
| 428 | } \ |
| 429 | break; |
| 430 | MACHINE_REPRESENTATION_LIST(STORE) |
| 431 | #undef STORE |
| 432 | case MachineRepresentation::kBit: |
| 433 | case MachineRepresentation::kNone: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 434 | break; |
| 435 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 436 | UNREACHABLE(); |
| 437 | return nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
| 441 | const Operator* MachineOperatorBuilder::CheckedLoad( |
| 442 | CheckedLoadRepresentation rep) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 443 | #define LOAD(Type) \ |
| 444 | if (rep == MachineType::Type()) { \ |
| 445 | return &cache_.kCheckedLoad##Type; \ |
| 446 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 447 | MACHINE_TYPE_LIST(LOAD) |
| 448 | #undef LOAD |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 449 | UNREACHABLE(); |
| 450 | return nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
| 454 | const Operator* MachineOperatorBuilder::CheckedStore( |
| 455 | CheckedStoreRepresentation rep) { |
| 456 | switch (rep) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 457 | #define STORE(kRep) \ |
| 458 | case MachineRepresentation::kRep: \ |
| 459 | return &cache_.kCheckedStore##kRep; |
| 460 | MACHINE_REPRESENTATION_LIST(STORE) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 461 | #undef STORE |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 462 | case MachineRepresentation::kBit: |
| 463 | case MachineRepresentation::kNone: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 464 | break; |
| 465 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 466 | UNREACHABLE(); |
| 467 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | } // namespace compiler |
| 471 | } // namespace internal |
| 472 | } // namespace v8 |