OLD | NEW |
(Empty) | |
| 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 |
| 15 OStream& operator<<(OStream& os, const WriteBarrierKind& write_barrier_kind) { |
| 16 switch (write_barrier_kind) { |
| 17 case kNoWriteBarrier: |
| 18 return os << "NoWriteBarrier"; |
| 19 case kFullWriteBarrier: |
| 20 return os << "FullWriteBarrier"; |
| 21 } |
| 22 UNREACHABLE(); |
| 23 return os; |
| 24 } |
| 25 |
| 26 |
| 27 OStream& operator<<(OStream& os, const StoreRepresentation& rep) { |
| 28 return os << "(" << rep.machine_type() << " : " << rep.write_barrier_kind() |
| 29 << ")"; |
| 30 } |
| 31 |
| 32 |
| 33 template <> |
| 34 struct StaticParameterTraits<StoreRepresentation> { |
| 35 static OStream& PrintTo(OStream& os, const StoreRepresentation& rep) { |
| 36 return os << rep; |
| 37 } |
| 38 static int HashCode(const StoreRepresentation& rep) { |
| 39 return rep.machine_type() + rep.write_barrier_kind(); |
| 40 } |
| 41 static bool Equals(const StoreRepresentation& rep1, |
| 42 const StoreRepresentation& rep2) { |
| 43 return rep1 == rep2; |
| 44 } |
| 45 }; |
| 46 |
| 47 |
| 48 template <> |
| 49 struct StaticParameterTraits<LoadRepresentation> { |
| 50 static OStream& PrintTo(OStream& os, LoadRepresentation type) { // NOLINT |
| 51 return os << type; |
| 52 } |
| 53 static int HashCode(LoadRepresentation type) { return type; } |
| 54 static bool Equals(LoadRepresentation lhs, LoadRepresentation rhs) { |
| 55 return lhs == rhs; |
| 56 } |
| 57 }; |
| 58 |
| 59 |
| 60 #define PURE_OP_LIST(V) \ |
| 61 V(Word32And, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 62 V(Word32Or, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 63 V(Word32Xor, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 64 V(Word32Shl, Operator::kNoProperties, 2, 1) \ |
| 65 V(Word32Shr, Operator::kNoProperties, 2, 1) \ |
| 66 V(Word32Sar, Operator::kNoProperties, 2, 1) \ |
| 67 V(Word32Ror, Operator::kNoProperties, 2, 1) \ |
| 68 V(Word32Equal, Operator::kCommutative, 2, 1) \ |
| 69 V(Word64And, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 70 V(Word64Or, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 71 V(Word64Xor, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 72 V(Word64Shl, Operator::kNoProperties, 2, 1) \ |
| 73 V(Word64Shr, Operator::kNoProperties, 2, 1) \ |
| 74 V(Word64Sar, Operator::kNoProperties, 2, 1) \ |
| 75 V(Word64Ror, Operator::kNoProperties, 2, 1) \ |
| 76 V(Word64Equal, Operator::kCommutative, 2, 1) \ |
| 77 V(Int32Add, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 78 V(Int32AddWithOverflow, Operator::kAssociative | Operator::kCommutative, 2, \ |
| 79 2) \ |
| 80 V(Int32Sub, Operator::kNoProperties, 2, 1) \ |
| 81 V(Int32SubWithOverflow, Operator::kNoProperties, 2, 2) \ |
| 82 V(Int32Mul, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 83 V(Int32Div, Operator::kNoProperties, 2, 1) \ |
| 84 V(Int32UDiv, Operator::kNoProperties, 2, 1) \ |
| 85 V(Int32Mod, Operator::kNoProperties, 2, 1) \ |
| 86 V(Int32UMod, Operator::kNoProperties, 2, 1) \ |
| 87 V(Int32LessThan, Operator::kNoProperties, 2, 1) \ |
| 88 V(Int32LessThanOrEqual, Operator::kNoProperties, 2, 1) \ |
| 89 V(Uint32LessThan, Operator::kNoProperties, 2, 1) \ |
| 90 V(Uint32LessThanOrEqual, Operator::kNoProperties, 2, 1) \ |
| 91 V(Int64Add, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 92 V(Int64Sub, Operator::kNoProperties, 2, 1) \ |
| 93 V(Int64Mul, Operator::kAssociative | Operator::kCommutative, 2, 1) \ |
| 94 V(Int64Div, Operator::kNoProperties, 2, 1) \ |
| 95 V(Int64UDiv, Operator::kNoProperties, 2, 1) \ |
| 96 V(Int64Mod, Operator::kNoProperties, 2, 1) \ |
| 97 V(Int64UMod, Operator::kNoProperties, 2, 1) \ |
| 98 V(Int64LessThan, Operator::kNoProperties, 2, 1) \ |
| 99 V(Int64LessThanOrEqual, Operator::kNoProperties, 2, 1) \ |
| 100 V(ChangeFloat64ToInt32, Operator::kNoProperties, 1, 1) \ |
| 101 V(ChangeFloat64ToUint32, Operator::kNoProperties, 1, 1) \ |
| 102 V(ChangeInt32ToFloat64, Operator::kNoProperties, 1, 1) \ |
| 103 V(ChangeInt32ToInt64, Operator::kNoProperties, 1, 1) \ |
| 104 V(ChangeUint32ToFloat64, Operator::kNoProperties, 1, 1) \ |
| 105 V(ChangeUint32ToUint64, Operator::kNoProperties, 1, 1) \ |
| 106 V(TruncateFloat64ToInt32, Operator::kNoProperties, 1, 1) \ |
| 107 V(TruncateInt64ToInt32, Operator::kNoProperties, 1, 1) \ |
| 108 V(Float64Add, Operator::kCommutative, 2, 1) \ |
| 109 V(Float64Sub, Operator::kNoProperties, 2, 1) \ |
| 110 V(Float64Mul, Operator::kCommutative, 2, 1) \ |
| 111 V(Float64Div, Operator::kNoProperties, 2, 1) \ |
| 112 V(Float64Mod, Operator::kNoProperties, 2, 1) \ |
| 113 V(Float64Equal, Operator::kCommutative, 2, 1) \ |
| 114 V(Float64LessThan, Operator::kNoProperties, 2, 1) \ |
| 115 V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 1) |
| 116 |
| 117 |
| 118 #define MACHINE_TYPE_LIST(V) \ |
| 119 V(MachFloat32) \ |
| 120 V(MachFloat64) \ |
| 121 V(MachInt8) \ |
| 122 V(MachUint8) \ |
| 123 V(MachInt16) \ |
| 124 V(MachUint16) \ |
| 125 V(MachInt32) \ |
| 126 V(MachUint32) \ |
| 127 V(MachInt64) \ |
| 128 V(MachUint64) \ |
| 129 V(MachAnyTagged) \ |
| 130 V(RepBit) \ |
| 131 V(RepWord8) \ |
| 132 V(RepWord16) \ |
| 133 V(RepWord32) \ |
| 134 V(RepWord64) \ |
| 135 V(RepFloat32) \ |
| 136 V(RepFloat64) \ |
| 137 V(RepTagged) |
| 138 |
| 139 |
| 140 struct MachineOperatorBuilderImpl { |
| 141 #define PURE(Name, properties, input_count, output_count) \ |
| 142 struct Name##Operator FINAL : public SimpleOperator { \ |
| 143 Name##Operator() \ |
| 144 : SimpleOperator(IrOpcode::k##Name, Operator::kPure | properties, \ |
| 145 input_count, output_count, #Name) {} \ |
| 146 }; \ |
| 147 Name##Operator k##Name; |
| 148 PURE_OP_LIST(PURE) |
| 149 #undef PURE |
| 150 |
| 151 #define LOAD(Type) \ |
| 152 struct Load##Type##Operator FINAL : public Operator1<LoadRepresentation> { \ |
| 153 Load##Type##Operator() \ |
| 154 : Operator1<LoadRepresentation>( \ |
| 155 IrOpcode::kLoad, Operator::kNoThrow | Operator::kNoWrite, 2, 1, \ |
| 156 "Load", k##Type) {} \ |
| 157 }; \ |
| 158 Load##Type##Operator k##Load##Type; |
| 159 MACHINE_TYPE_LIST(LOAD) |
| 160 #undef LOAD |
| 161 |
| 162 #define STORE(Type) \ |
| 163 struct Store##Type##Operator : public Operator1<StoreRepresentation> { \ |
| 164 explicit Store##Type##Operator(WriteBarrierKind write_barrier_kind) \ |
| 165 : Operator1<StoreRepresentation>( \ |
| 166 IrOpcode::kStore, Operator::kNoRead | Operator::kNoThrow, 3, 0, \ |
| 167 "Store", StoreRepresentation(k##Type, write_barrier_kind)) {} \ |
| 168 }; \ |
| 169 struct Store##Type##NoWriteBarrier##Operator FINAL \ |
| 170 : public Store##Type##Operator { \ |
| 171 Store##Type##NoWriteBarrier##Operator() \ |
| 172 : Store##Type##Operator(kNoWriteBarrier) {} \ |
| 173 }; \ |
| 174 struct Store##Type##FullWriteBarrier##Operator FINAL \ |
| 175 : public Store##Type##Operator { \ |
| 176 Store##Type##FullWriteBarrier##Operator() \ |
| 177 : Store##Type##Operator(kFullWriteBarrier) {} \ |
| 178 }; \ |
| 179 Store##Type##NoWriteBarrier##Operator k##Store##Type##NoWriteBarrier; \ |
| 180 Store##Type##FullWriteBarrier##Operator k##Store##Type##FullWriteBarrier; |
| 181 MACHINE_TYPE_LIST(STORE) |
| 182 #undef STORE |
| 183 }; |
| 184 |
| 185 |
| 186 static base::LazyInstance<MachineOperatorBuilderImpl>::type kImpl = |
| 187 LAZY_INSTANCE_INITIALIZER; |
| 188 |
| 189 |
| 190 MachineOperatorBuilder::MachineOperatorBuilder(MachineType word) |
| 191 : impl_(kImpl.Get()), word_(word) { |
| 192 DCHECK(word == kRepWord32 || word == kRepWord64); |
| 193 } |
| 194 |
| 195 |
| 196 #define PURE(Name, properties, input_count, output_count) \ |
| 197 const Operator* MachineOperatorBuilder::Name() { return &impl_.k##Name; } |
| 198 PURE_OP_LIST(PURE) |
| 199 #undef PURE |
| 200 |
| 201 |
| 202 const Operator* MachineOperatorBuilder::Load(LoadRepresentation rep) { |
| 203 switch (rep) { |
| 204 #define LOAD(Type) \ |
| 205 case k##Type: \ |
| 206 return &impl_.k##Load##Type; |
| 207 MACHINE_TYPE_LIST(LOAD) |
| 208 #undef LOAD |
| 209 |
| 210 default: |
| 211 break; |
| 212 } |
| 213 UNREACHABLE(); |
| 214 return NULL; |
| 215 } |
| 216 |
| 217 |
| 218 const Operator* MachineOperatorBuilder::Store(StoreRepresentation rep) { |
| 219 switch (rep.machine_type()) { |
| 220 #define STORE(Type) \ |
| 221 case k##Type: \ |
| 222 switch (rep.write_barrier_kind()) { \ |
| 223 case kNoWriteBarrier: \ |
| 224 return &impl_.k##Store##Type##NoWriteBarrier; \ |
| 225 case kFullWriteBarrier: \ |
| 226 return &impl_.k##Store##Type##FullWriteBarrier; \ |
| 227 } \ |
| 228 break; |
| 229 MACHINE_TYPE_LIST(STORE) |
| 230 #undef STORE |
| 231 |
| 232 default: |
| 233 break; |
| 234 } |
| 235 UNREACHABLE(); |
| 236 return NULL; |
| 237 } |
| 238 |
| 239 } // namespace compiler |
| 240 } // namespace internal |
| 241 } // namespace v8 |
OLD | NEW |