OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/simplified-operator.h" | 5 #include "src/compiler/simplified-operator.h" |
| 6 |
| 7 #include "src/base/lazy-instance.h" |
| 8 #include "src/compiler/opcodes.h" |
| 9 #include "src/compiler/operator.h" |
6 #include "src/types-inl.h" | 10 #include "src/types-inl.h" |
7 | 11 |
8 namespace v8 { | 12 namespace v8 { |
9 namespace internal { | 13 namespace internal { |
10 namespace compiler { | 14 namespace compiler { |
11 | 15 |
12 // static | 16 const FieldAccess& FieldAccessOf(const Operator* op) { |
13 bool StaticParameterTraits<FieldAccess>::Equals(const FieldAccess& lhs, | 17 DCHECK_NOT_NULL(op); |
14 const FieldAccess& rhs) { | 18 DCHECK(op->opcode() == IrOpcode::kLoadField || |
15 return lhs.base_is_tagged == rhs.base_is_tagged && lhs.offset == rhs.offset && | 19 op->opcode() == IrOpcode::kStoreField); |
16 lhs.machine_type == rhs.machine_type && lhs.type->Is(rhs.type); | 20 return OpParameter<FieldAccess>(op); |
17 } | 21 } |
18 | 22 |
19 | 23 |
20 // static | 24 const ElementAccess& ElementAccessOf(const Operator* op) { |
21 bool StaticParameterTraits<ElementAccess>::Equals(const ElementAccess& lhs, | 25 DCHECK_NOT_NULL(op); |
22 const ElementAccess& rhs) { | 26 DCHECK(op->opcode() == IrOpcode::kLoadElement || |
23 return lhs.base_is_tagged == rhs.base_is_tagged && | 27 op->opcode() == IrOpcode::kStoreElement); |
24 lhs.header_size == rhs.header_size && | 28 return OpParameter<ElementAccess>(op); |
25 lhs.machine_type == rhs.machine_type && lhs.type->Is(rhs.type); | |
26 } | 29 } |
27 | 30 |
| 31 |
| 32 // Specialization for static parameters of type {FieldAccess}. |
| 33 template <> |
| 34 struct StaticParameterTraits<FieldAccess> { |
| 35 static OStream& PrintTo(OStream& os, const FieldAccess& val) { |
| 36 return os << val.offset; |
| 37 } |
| 38 static int HashCode(const FieldAccess& val) { |
| 39 return (val.offset < 16) | (val.machine_type & 0xffff); |
| 40 } |
| 41 static bool Equals(const FieldAccess& lhs, const FieldAccess& rhs) { |
| 42 return lhs.base_is_tagged == rhs.base_is_tagged && |
| 43 lhs.offset == rhs.offset && lhs.machine_type == rhs.machine_type && |
| 44 lhs.type->Is(rhs.type); |
| 45 } |
| 46 }; |
| 47 |
| 48 |
| 49 // Specialization for static parameters of type {ElementAccess}. |
| 50 template <> |
| 51 struct StaticParameterTraits<ElementAccess> { |
| 52 static OStream& PrintTo(OStream& os, const ElementAccess& val) { |
| 53 return os << val.header_size; |
| 54 } |
| 55 static int HashCode(const ElementAccess& val) { |
| 56 return (val.header_size < 16) | (val.machine_type & 0xffff); |
| 57 } |
| 58 static bool Equals(const ElementAccess& lhs, const ElementAccess& rhs) { |
| 59 return lhs.base_is_tagged == rhs.base_is_tagged && |
| 60 lhs.header_size == rhs.header_size && |
| 61 lhs.machine_type == rhs.machine_type && lhs.type->Is(rhs.type); |
| 62 } |
| 63 }; |
| 64 |
| 65 |
| 66 #define PURE_OP_LIST(V) \ |
| 67 V(BooleanNot, Operator::kNoProperties, 1) \ |
| 68 V(NumberEqual, Operator::kCommutative, 2) \ |
| 69 V(NumberLessThan, Operator::kNoProperties, 2) \ |
| 70 V(NumberLessThanOrEqual, Operator::kNoProperties, 2) \ |
| 71 V(NumberAdd, Operator::kCommutative, 2) \ |
| 72 V(NumberSubtract, Operator::kNoProperties, 2) \ |
| 73 V(NumberMultiply, Operator::kCommutative, 2) \ |
| 74 V(NumberDivide, Operator::kNoProperties, 2) \ |
| 75 V(NumberModulus, Operator::kNoProperties, 2) \ |
| 76 V(NumberToInt32, Operator::kNoProperties, 1) \ |
| 77 V(NumberToUint32, Operator::kNoProperties, 1) \ |
| 78 V(StringEqual, Operator::kCommutative, 2) \ |
| 79 V(StringLessThan, Operator::kNoProperties, 2) \ |
| 80 V(StringLessThanOrEqual, Operator::kNoProperties, 2) \ |
| 81 V(StringAdd, Operator::kNoProperties, 2) \ |
| 82 V(ChangeTaggedToInt32, Operator::kNoProperties, 1) \ |
| 83 V(ChangeTaggedToUint32, Operator::kNoProperties, 1) \ |
| 84 V(ChangeTaggedToFloat64, Operator::kNoProperties, 1) \ |
| 85 V(ChangeInt32ToTagged, Operator::kNoProperties, 1) \ |
| 86 V(ChangeUint32ToTagged, Operator::kNoProperties, 1) \ |
| 87 V(ChangeFloat64ToTagged, Operator::kNoProperties, 1) \ |
| 88 V(ChangeBoolToBit, Operator::kNoProperties, 1) \ |
| 89 V(ChangeBitToBool, Operator::kNoProperties, 1) |
| 90 |
| 91 |
| 92 #define ACCESS_OP_LIST(V) \ |
| 93 V(LoadField, FieldAccess, Operator::kNoWrite, 1, 1) \ |
| 94 V(StoreField, FieldAccess, Operator::kNoRead, 2, 0) \ |
| 95 V(LoadElement, ElementAccess, Operator::kNoWrite, 2, 1) \ |
| 96 V(StoreElement, ElementAccess, Operator::kNoRead, 3, 0) |
| 97 |
| 98 |
| 99 struct SimplifiedOperatorBuilderImpl FINAL { |
| 100 #define PURE(Name, properties, input_count) \ |
| 101 struct Name##Operator FINAL : public SimpleOperator { \ |
| 102 Name##Operator() \ |
| 103 : SimpleOperator(IrOpcode::k##Name, Operator::kPure | properties, \ |
| 104 input_count, 1, #Name) {} \ |
| 105 }; \ |
| 106 Name##Operator k##Name; |
| 107 PURE_OP_LIST(PURE) |
| 108 #undef PURE |
| 109 }; |
| 110 |
| 111 |
| 112 static base::LazyInstance<SimplifiedOperatorBuilderImpl>::type kImpl = |
| 113 LAZY_INSTANCE_INITIALIZER; |
| 114 |
| 115 |
| 116 SimplifiedOperatorBuilder::SimplifiedOperatorBuilder(Zone* zone) |
| 117 : impl_(kImpl.Get()), zone_(zone) {} |
| 118 |
| 119 |
| 120 #define PURE(Name, properties, input_count) \ |
| 121 const Operator* SimplifiedOperatorBuilder::Name() const { \ |
| 122 return &impl_.k##Name; \ |
| 123 } |
| 124 PURE_OP_LIST(PURE) |
| 125 #undef PURE |
| 126 |
| 127 |
| 128 const Operator* SimplifiedOperatorBuilder::ReferenceEqual(Type* type) const { |
| 129 // TODO(titzer): What about the type parameter? |
| 130 return new (zone()) SimpleOperator(IrOpcode::kReferenceEqual, |
| 131 Operator::kCommutative | Operator::kPure, |
| 132 2, 1, "ReferenceEqual"); |
| 133 } |
| 134 |
| 135 |
| 136 #define ACCESS(Name, Type, properties, input_count, output_count) \ |
| 137 const Operator* SimplifiedOperatorBuilder::Name(const Type& access) const { \ |
| 138 return new (zone()) \ |
| 139 Operator1<Type>(IrOpcode::k##Name, Operator::kNoThrow | properties, \ |
| 140 input_count, output_count, #Name, access); \ |
| 141 } |
| 142 ACCESS_OP_LIST(ACCESS) |
| 143 #undef ACCESS |
| 144 |
28 } // namespace compiler | 145 } // namespace compiler |
29 } // namespace internal | 146 } // namespace internal |
30 } // namespace v8 | 147 } // namespace v8 |
OLD | NEW |