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 | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 151 | V(TruncateFloat64ToUint32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 152 | V(TruncateFloat32ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
| 153 | V(TruncateFloat32ToUint32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 154 | V(TryTruncateFloat32ToInt64, Operator::kNoProperties, 1, 0, 2) \ |
| 155 | V(TryTruncateFloat64ToInt64, Operator::kNoProperties, 1, 0, 2) \ |
| 156 | V(TryTruncateFloat32ToUint64, Operator::kNoProperties, 1, 0, 2) \ |
| 157 | V(TryTruncateFloat64ToUint64, Operator::kNoProperties, 1, 0, 2) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 158 | V(ChangeInt32ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 159 | V(RoundInt32ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 160 | V(RoundInt64ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
| 161 | V(RoundInt64ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 162 | V(RoundUint32ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | V(RoundUint64ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
| 164 | V(RoundUint64ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 165 | V(ChangeInt32ToInt64, Operator::kNoProperties, 1, 0, 1) \ |
| 166 | V(ChangeUint32ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
| 167 | V(ChangeUint32ToUint64, Operator::kNoProperties, 1, 0, 1) \ |
| 168 | V(TruncateFloat64ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 169 | V(TruncateInt64ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 170 | V(BitcastFloat32ToInt32, Operator::kNoProperties, 1, 0, 1) \ |
| 171 | V(BitcastFloat64ToInt64, Operator::kNoProperties, 1, 0, 1) \ |
| 172 | V(BitcastInt32ToFloat32, Operator::kNoProperties, 1, 0, 1) \ |
| 173 | V(BitcastInt64ToFloat64, Operator::kNoProperties, 1, 0, 1) \ |
| 174 | V(Float32Abs, Operator::kNoProperties, 1, 0, 1) \ |
| 175 | V(Float32Add, Operator::kCommutative, 2, 0, 1) \ |
| 176 | V(Float32Sub, Operator::kNoProperties, 2, 0, 1) \ |
| 177 | V(Float32Mul, Operator::kCommutative, 2, 0, 1) \ |
| 178 | V(Float32Div, Operator::kNoProperties, 2, 0, 1) \ |
| 179 | V(Float32Sqrt, Operator::kNoProperties, 1, 0, 1) \ |
| 180 | V(Float64Abs, Operator::kNoProperties, 1, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 181 | V(Float64Add, Operator::kCommutative, 2, 0, 1) \ |
| 182 | V(Float64Sub, Operator::kNoProperties, 2, 0, 1) \ |
| 183 | V(Float64Mul, Operator::kCommutative, 2, 0, 1) \ |
| 184 | V(Float64Div, Operator::kNoProperties, 2, 0, 1) \ |
| 185 | V(Float64Mod, Operator::kNoProperties, 2, 0, 1) \ |
| 186 | V(Float64Sqrt, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | V(Float32Equal, Operator::kCommutative, 2, 0, 1) \ |
| 188 | V(Float32LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 189 | V(Float32LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 190 | V(Float64Equal, Operator::kCommutative, 2, 0, 1) \ |
| 191 | V(Float64LessThan, Operator::kNoProperties, 2, 0, 1) \ |
| 192 | V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 193 | V(Float64ExtractLowWord32, Operator::kNoProperties, 1, 0, 1) \ |
| 194 | V(Float64ExtractHighWord32, Operator::kNoProperties, 1, 0, 1) \ |
| 195 | V(Float64InsertLowWord32, Operator::kNoProperties, 2, 0, 1) \ |
| 196 | V(Float64InsertHighWord32, Operator::kNoProperties, 2, 0, 1) \ |
| 197 | V(LoadStackPointer, Operator::kNoProperties, 0, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 198 | V(LoadFramePointer, Operator::kNoProperties, 0, 0, 1) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 199 | V(LoadParentFramePointer, Operator::kNoProperties, 0, 0, 1) \ |
| 200 | V(Int32PairAdd, Operator::kNoProperties, 4, 0, 2) \ |
| 201 | V(Int32PairSub, Operator::kNoProperties, 4, 0, 2) \ |
| 202 | V(Int32PairMul, Operator::kNoProperties, 4, 0, 2) \ |
| 203 | V(Word32PairShl, Operator::kNoProperties, 3, 0, 2) \ |
| 204 | V(Word32PairShr, Operator::kNoProperties, 3, 0, 2) \ |
| 205 | V(Word32PairSar, Operator::kNoProperties, 3, 0, 2) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 206 | |
| 207 | #define PURE_OPTIONAL_OP_LIST(V) \ |
| 208 | V(Word32Ctz, Operator::kNoProperties, 1, 0, 1) \ |
| 209 | V(Word64Ctz, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 210 | V(Word32ReverseBits, Operator::kNoProperties, 1, 0, 1) \ |
| 211 | V(Word64ReverseBits, Operator::kNoProperties, 1, 0, 1) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | V(Word32Popcnt, Operator::kNoProperties, 1, 0, 1) \ |
| 213 | V(Word64Popcnt, Operator::kNoProperties, 1, 0, 1) \ |
| 214 | V(Float32Max, Operator::kNoProperties, 2, 0, 1) \ |
| 215 | V(Float32Min, Operator::kNoProperties, 2, 0, 1) \ |
| 216 | V(Float64Max, Operator::kNoProperties, 2, 0, 1) \ |
| 217 | V(Float64Min, Operator::kNoProperties, 2, 0, 1) \ |
| 218 | V(Float32RoundDown, Operator::kNoProperties, 1, 0, 1) \ |
| 219 | V(Float64RoundDown, Operator::kNoProperties, 1, 0, 1) \ |
| 220 | V(Float32RoundUp, Operator::kNoProperties, 1, 0, 1) \ |
| 221 | V(Float64RoundUp, Operator::kNoProperties, 1, 0, 1) \ |
| 222 | V(Float32RoundTruncate, Operator::kNoProperties, 1, 0, 1) \ |
| 223 | V(Float64RoundTruncate, Operator::kNoProperties, 1, 0, 1) \ |
| 224 | V(Float64RoundTiesAway, Operator::kNoProperties, 1, 0, 1) \ |
| 225 | V(Float32RoundTiesEven, Operator::kNoProperties, 1, 0, 1) \ |
| 226 | V(Float64RoundTiesEven, Operator::kNoProperties, 1, 0, 1) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 227 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 228 | #define MACHINE_TYPE_LIST(V) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 229 | V(Float32) \ |
| 230 | V(Float64) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 231 | V(Simd128) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 232 | V(Int8) \ |
| 233 | V(Uint8) \ |
| 234 | V(Int16) \ |
| 235 | V(Uint16) \ |
| 236 | V(Int32) \ |
| 237 | V(Uint32) \ |
| 238 | V(Int64) \ |
| 239 | V(Uint64) \ |
| 240 | V(Pointer) \ |
| 241 | V(AnyTagged) |
| 242 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 243 | #define MACHINE_REPRESENTATION_LIST(V) \ |
| 244 | V(kFloat32) \ |
| 245 | V(kFloat64) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 246 | V(kSimd128) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 247 | V(kWord8) \ |
| 248 | V(kWord16) \ |
| 249 | V(kWord32) \ |
| 250 | V(kWord64) \ |
| 251 | V(kTagged) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 252 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 253 | struct MachineOperatorGlobalCache { |
| 254 | #define PURE(Name, properties, value_input_count, control_input_count, \ |
| 255 | output_count) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 256 | struct Name##Operator final : public Operator { \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 257 | Name##Operator() \ |
| 258 | : Operator(IrOpcode::k##Name, Operator::kPure | properties, #Name, \ |
| 259 | value_input_count, 0, control_input_count, output_count, 0, \ |
| 260 | 0) {} \ |
| 261 | }; \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 262 | Name##Operator k##Name; |
| 263 | PURE_OP_LIST(PURE) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 264 | PURE_OPTIONAL_OP_LIST(PURE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | #undef PURE |
| 266 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 267 | template <TruncationMode kMode> |
| 268 | struct TruncateFloat64ToInt32Operator final |
| 269 | : public Operator1<TruncationMode> { |
| 270 | TruncateFloat64ToInt32Operator() |
| 271 | : Operator1<TruncationMode>(IrOpcode::kTruncateFloat64ToInt32, |
| 272 | Operator::kPure, "TruncateFloat64ToInt32", |
| 273 | 1, 0, 0, 1, 0, 0, kMode) {} |
| 274 | }; |
| 275 | TruncateFloat64ToInt32Operator<TruncationMode::kJavaScript> |
| 276 | kTruncateFloat64ToInt32JavaScript; |
| 277 | TruncateFloat64ToInt32Operator<TruncationMode::kRoundToZero> |
| 278 | kTruncateFloat64ToInt32RoundToZero; |
| 279 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 280 | #define LOAD(Type) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 281 | struct Load##Type##Operator final : public Operator1<LoadRepresentation> { \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 282 | Load##Type##Operator() \ |
| 283 | : Operator1<LoadRepresentation>( \ |
| 284 | IrOpcode::kLoad, Operator::kNoThrow | Operator::kNoWrite, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 285 | "Load", 2, 1, 1, 1, 1, 0, MachineType::Type()) {} \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 286 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 287 | struct CheckedLoad##Type##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 288 | : public Operator1<CheckedLoadRepresentation> { \ |
| 289 | CheckedLoad##Type##Operator() \ |
| 290 | : Operator1<CheckedLoadRepresentation>( \ |
| 291 | IrOpcode::kCheckedLoad, Operator::kNoThrow | Operator::kNoWrite, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 292 | "CheckedLoad", 3, 1, 1, 1, 1, 0, MachineType::Type()) {} \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 293 | }; \ |
| 294 | Load##Type##Operator kLoad##Type; \ |
| 295 | CheckedLoad##Type##Operator kCheckedLoad##Type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 296 | MACHINE_TYPE_LIST(LOAD) |
| 297 | #undef LOAD |
| 298 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 299 | #define STACKSLOT(Type) \ |
| 300 | struct StackSlot##Type##Operator final \ |
| 301 | : public Operator1<MachineRepresentation> { \ |
| 302 | StackSlot##Type##Operator() \ |
| 303 | : Operator1<MachineRepresentation>( \ |
| 304 | IrOpcode::kStackSlot, Operator::kNoThrow, "StackSlot", 0, 0, 0, \ |
| 305 | 1, 0, 0, MachineType::Type().representation()) {} \ |
| 306 | }; \ |
| 307 | StackSlot##Type##Operator kStackSlot##Type; |
| 308 | MACHINE_TYPE_LIST(STACKSLOT) |
| 309 | #undef STACKSLOT |
| 310 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 311 | #define STORE(Type) \ |
| 312 | struct Store##Type##Operator : public Operator1<StoreRepresentation> { \ |
| 313 | explicit Store##Type##Operator(WriteBarrierKind write_barrier_kind) \ |
| 314 | : Operator1<StoreRepresentation>( \ |
| 315 | IrOpcode::kStore, Operator::kNoRead | Operator::kNoThrow, \ |
| 316 | "Store", 3, 1, 1, 0, 1, 0, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 317 | StoreRepresentation(MachineRepresentation::Type, \ |
| 318 | write_barrier_kind)) {} \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 319 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 320 | struct Store##Type##NoWriteBarrier##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 321 | : public Store##Type##Operator { \ |
| 322 | Store##Type##NoWriteBarrier##Operator() \ |
| 323 | : Store##Type##Operator(kNoWriteBarrier) {} \ |
| 324 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 325 | struct Store##Type##MapWriteBarrier##Operator final \ |
| 326 | : public Store##Type##Operator { \ |
| 327 | Store##Type##MapWriteBarrier##Operator() \ |
| 328 | : Store##Type##Operator(kMapWriteBarrier) {} \ |
| 329 | }; \ |
| 330 | struct Store##Type##PointerWriteBarrier##Operator final \ |
| 331 | : public Store##Type##Operator { \ |
| 332 | Store##Type##PointerWriteBarrier##Operator() \ |
| 333 | : Store##Type##Operator(kPointerWriteBarrier) {} \ |
| 334 | }; \ |
| 335 | struct Store##Type##FullWriteBarrier##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 336 | : public Store##Type##Operator { \ |
| 337 | Store##Type##FullWriteBarrier##Operator() \ |
| 338 | : Store##Type##Operator(kFullWriteBarrier) {} \ |
| 339 | }; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 340 | struct CheckedStore##Type##Operator final \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 341 | : public Operator1<CheckedStoreRepresentation> { \ |
| 342 | CheckedStore##Type##Operator() \ |
| 343 | : Operator1<CheckedStoreRepresentation>( \ |
| 344 | IrOpcode::kCheckedStore, Operator::kNoRead | Operator::kNoThrow, \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 345 | "CheckedStore", 4, 1, 1, 0, 1, 0, MachineRepresentation::Type) { \ |
| 346 | } \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 347 | }; \ |
| 348 | Store##Type##NoWriteBarrier##Operator kStore##Type##NoWriteBarrier; \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 349 | Store##Type##MapWriteBarrier##Operator kStore##Type##MapWriteBarrier; \ |
| 350 | Store##Type##PointerWriteBarrier##Operator \ |
| 351 | kStore##Type##PointerWriteBarrier; \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 352 | Store##Type##FullWriteBarrier##Operator kStore##Type##FullWriteBarrier; \ |
| 353 | CheckedStore##Type##Operator kCheckedStore##Type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 354 | MACHINE_REPRESENTATION_LIST(STORE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | #undef STORE |
| 356 | }; |
| 357 | |
| 358 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 359 | static base::LazyInstance<MachineOperatorGlobalCache>::type kCache = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 360 | LAZY_INSTANCE_INITIALIZER; |
| 361 | |
| 362 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 363 | MachineOperatorBuilder::MachineOperatorBuilder(Zone* zone, |
| 364 | MachineRepresentation word, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 365 | Flags flags) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 366 | : cache_(kCache.Get()), word_(word), flags_(flags) { |
| 367 | DCHECK(word == MachineRepresentation::kWord32 || |
| 368 | word == MachineRepresentation::kWord64); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 372 | #define PURE(Name, properties, value_input_count, control_input_count, \ |
| 373 | output_count) \ |
| 374 | const Operator* MachineOperatorBuilder::Name() { return &cache_.k##Name; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 375 | PURE_OP_LIST(PURE) |
| 376 | #undef PURE |
| 377 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 378 | #define PURE(Name, properties, value_input_count, control_input_count, \ |
| 379 | output_count) \ |
| 380 | const OptionalOperator MachineOperatorBuilder::Name() { \ |
| 381 | return OptionalOperator(flags_ & k##Name ? &cache_.k##Name : nullptr); \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 382 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 383 | PURE_OPTIONAL_OP_LIST(PURE) |
| 384 | #undef PURE |
| 385 | |
| 386 | |
| 387 | const Operator* MachineOperatorBuilder::TruncateFloat64ToInt32( |
| 388 | TruncationMode mode) { |
| 389 | switch (mode) { |
| 390 | case TruncationMode::kJavaScript: |
| 391 | return &cache_.kTruncateFloat64ToInt32JavaScript; |
| 392 | case TruncationMode::kRoundToZero: |
| 393 | return &cache_.kTruncateFloat64ToInt32RoundToZero; |
| 394 | } |
| 395 | UNREACHABLE(); |
| 396 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 400 | const Operator* MachineOperatorBuilder::Load(LoadRepresentation rep) { |
| 401 | #define LOAD(Type) \ |
| 402 | if (rep == MachineType::Type()) { \ |
| 403 | return &cache_.kLoad##Type; \ |
| 404 | } |
| 405 | MACHINE_TYPE_LIST(LOAD) |
| 406 | #undef LOAD |
| 407 | UNREACHABLE(); |
| 408 | return nullptr; |
| 409 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 410 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 411 | const Operator* MachineOperatorBuilder::StackSlot(MachineRepresentation rep) { |
| 412 | #define STACKSLOT(Type) \ |
| 413 | if (rep == MachineType::Type().representation()) { \ |
| 414 | return &cache_.kStackSlot##Type; \ |
| 415 | } |
| 416 | MACHINE_TYPE_LIST(STACKSLOT) |
| 417 | #undef STACKSLOT |
| 418 | UNREACHABLE(); |
| 419 | return nullptr; |
| 420 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 421 | |
| 422 | const Operator* MachineOperatorBuilder::Store(StoreRepresentation store_rep) { |
| 423 | switch (store_rep.representation()) { |
| 424 | #define STORE(kRep) \ |
| 425 | case MachineRepresentation::kRep: \ |
| 426 | switch (store_rep.write_barrier_kind()) { \ |
| 427 | case kNoWriteBarrier: \ |
| 428 | return &cache_.k##Store##kRep##NoWriteBarrier; \ |
| 429 | case kMapWriteBarrier: \ |
| 430 | return &cache_.k##Store##kRep##MapWriteBarrier; \ |
| 431 | case kPointerWriteBarrier: \ |
| 432 | return &cache_.k##Store##kRep##PointerWriteBarrier; \ |
| 433 | case kFullWriteBarrier: \ |
| 434 | return &cache_.k##Store##kRep##FullWriteBarrier; \ |
| 435 | } \ |
| 436 | break; |
| 437 | MACHINE_REPRESENTATION_LIST(STORE) |
| 438 | #undef STORE |
| 439 | case MachineRepresentation::kBit: |
| 440 | case MachineRepresentation::kNone: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | break; |
| 442 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 443 | UNREACHABLE(); |
| 444 | return nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
| 448 | const Operator* MachineOperatorBuilder::CheckedLoad( |
| 449 | CheckedLoadRepresentation rep) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 450 | #define LOAD(Type) \ |
| 451 | if (rep == MachineType::Type()) { \ |
| 452 | return &cache_.kCheckedLoad##Type; \ |
| 453 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 454 | MACHINE_TYPE_LIST(LOAD) |
| 455 | #undef LOAD |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 456 | UNREACHABLE(); |
| 457 | return nullptr; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | |
| 461 | const Operator* MachineOperatorBuilder::CheckedStore( |
| 462 | CheckedStoreRepresentation rep) { |
| 463 | switch (rep) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 464 | #define STORE(kRep) \ |
| 465 | case MachineRepresentation::kRep: \ |
| 466 | return &cache_.kCheckedStore##kRep; |
| 467 | MACHINE_REPRESENTATION_LIST(STORE) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 468 | #undef STORE |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 469 | case MachineRepresentation::kBit: |
| 470 | case MachineRepresentation::kNone: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 471 | break; |
| 472 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 473 | UNREACHABLE(); |
| 474 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 477 | // On 32 bit platforms we need to get a reference to optional operators of |
| 478 | // 64-bit instructions for later Int64Lowering, even though 32 bit platforms |
| 479 | // don't support the original 64-bit instruction. |
| 480 | const Operator* MachineOperatorBuilder::Word64PopcntPlaceholder() { |
| 481 | return &cache_.kWord64Popcnt; |
| 482 | } |
| 483 | |
| 484 | // On 32 bit platforms we need to get a reference to optional operators of |
| 485 | // 64-bit instructions for later Int64Lowering, even though 32 bit platforms |
| 486 | // don't support the original 64-bit instruction. |
| 487 | const Operator* MachineOperatorBuilder::Word64CtzPlaceholder() { |
| 488 | return &cache_.kWord64Ctz; |
| 489 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 490 | } // namespace compiler |
| 491 | } // namespace internal |
| 492 | } // namespace v8 |