| 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 | 6 |
| 7 #include <ostream> // NOLINT(readability/streams) | |
| 8 | |
| 9 #include "src/base/lazy-instance.h" | 7 #include "src/base/lazy-instance.h" |
| 10 #include "src/compiler/opcodes.h" | 8 #include "src/compiler/opcodes.h" |
| 11 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
| 12 #include "src/types-inl.h" | 10 #include "src/types-inl.h" |
| 13 | 11 |
| 14 namespace v8 { | 12 namespace v8 { |
| 15 namespace internal { | 13 namespace internal { |
| 16 namespace compiler { | 14 namespace compiler { |
| 17 | 15 |
| 18 std::ostream& operator<<(std::ostream& os, BaseTaggedness base_taggedness) { | 16 std::ostream& operator<<(std::ostream& os, BaseTaggedness base_taggedness) { |
| 19 switch (base_taggedness) { | 17 switch (base_taggedness) { |
| 20 case kUntaggedBase: | 18 case kUntaggedBase: |
| 21 return os << "untagged base"; | 19 return os << "untagged base"; |
| 22 case kTaggedBase: | 20 case kTaggedBase: |
| 23 return os << "tagged base"; | 21 return os << "tagged base"; |
| 24 } | 22 } |
| 25 UNREACHABLE(); | 23 UNREACHABLE(); |
| 26 return os; | 24 return os; |
| 27 } | 25 } |
| 28 | 26 |
| 29 | 27 |
| 30 bool operator==(FieldAccess const& lhs, FieldAccess const& rhs) { | 28 bool operator==(FieldAccess const& lhs, FieldAccess const& rhs) { |
| 31 return lhs.base_is_tagged == rhs.base_is_tagged && lhs.offset == rhs.offset && | 29 return lhs.base_is_tagged == rhs.base_is_tagged && lhs.offset == rhs.offset && |
| 32 lhs.type == rhs.type && lhs.machine_type == rhs.machine_type; | 30 lhs.machine_type == rhs.machine_type; |
| 33 } | 31 } |
| 34 | 32 |
| 35 | 33 |
| 36 bool operator!=(FieldAccess const& lhs, FieldAccess const& rhs) { | 34 bool operator!=(FieldAccess const& lhs, FieldAccess const& rhs) { |
| 37 return !(lhs == rhs); | 35 return !(lhs == rhs); |
| 38 } | 36 } |
| 39 | 37 |
| 40 | 38 |
| 39 size_t hash_value(FieldAccess const& access) { |
| 40 return base::hash_combine(access.base_is_tagged, access.offset, |
| 41 access.machine_type); |
| 42 } |
| 43 |
| 44 |
| 41 std::ostream& operator<<(std::ostream& os, FieldAccess const& access) { | 45 std::ostream& operator<<(std::ostream& os, FieldAccess const& access) { |
| 42 os << "[" << access.base_is_tagged << ", " << access.offset << ", "; | 46 os << "[" << access.base_is_tagged << ", " << access.offset << ", "; |
| 43 #ifdef OBJECT_PRINT | 47 #ifdef OBJECT_PRINT |
| 44 Handle<Name> name; | 48 Handle<Name> name; |
| 45 if (access.name.ToHandle(&name)) { | 49 if (access.name.ToHandle(&name)) { |
| 46 name->Print(os); | 50 name->Print(os); |
| 47 os << ", "; | 51 os << ", "; |
| 48 } | 52 } |
| 49 #endif | 53 #endif |
| 50 access.type->PrintTo(os); | 54 access.type->PrintTo(os); |
| 51 os << ", " << access.machine_type << "]"; | 55 os << ", " << access.machine_type << "]"; |
| 52 return os; | 56 return os; |
| 53 } | 57 } |
| 54 | 58 |
| 55 | 59 |
| 56 std::ostream& operator<<(std::ostream& os, BoundsCheckMode bounds_check_mode) { | 60 std::ostream& operator<<(std::ostream& os, BoundsCheckMode bounds_check_mode) { |
| 57 switch (bounds_check_mode) { | 61 switch (bounds_check_mode) { |
| 58 case kNoBoundsCheck: | 62 case kNoBoundsCheck: |
| 59 return os << "no bounds check"; | 63 return os << "no bounds check"; |
| 60 case kTypedArrayBoundsCheck: | 64 case kTypedArrayBoundsCheck: |
| 61 return os << "ignore out of bounds"; | 65 return os << "ignore out of bounds"; |
| 62 } | 66 } |
| 63 UNREACHABLE(); | 67 UNREACHABLE(); |
| 64 return os; | 68 return os; |
| 65 } | 69 } |
| 66 | 70 |
| 67 | 71 |
| 68 bool operator==(ElementAccess const& lhs, ElementAccess const& rhs) { | 72 bool operator==(ElementAccess const& lhs, ElementAccess const& rhs) { |
| 69 return lhs.base_is_tagged == rhs.base_is_tagged && | 73 return lhs.base_is_tagged == rhs.base_is_tagged && |
| 70 lhs.header_size == rhs.header_size && lhs.type == rhs.type && | 74 lhs.header_size == rhs.header_size && |
| 71 lhs.machine_type == rhs.machine_type; | 75 lhs.machine_type == rhs.machine_type; |
| 72 } | 76 } |
| 73 | 77 |
| 74 | 78 |
| 75 bool operator!=(ElementAccess const& lhs, ElementAccess const& rhs) { | 79 bool operator!=(ElementAccess const& lhs, ElementAccess const& rhs) { |
| 76 return !(lhs == rhs); | 80 return !(lhs == rhs); |
| 77 } | 81 } |
| 78 | 82 |
| 79 | 83 |
| 84 size_t hash_value(ElementAccess const& access) { |
| 85 return base::hash_combine(access.base_is_tagged, access.header_size, |
| 86 access.machine_type); |
| 87 } |
| 88 |
| 89 |
| 80 std::ostream& operator<<(std::ostream& os, ElementAccess const& access) { | 90 std::ostream& operator<<(std::ostream& os, ElementAccess const& access) { |
| 81 os << "[" << access.base_is_tagged << ", " << access.header_size << ", "; | 91 os << access.base_is_tagged << ", " << access.header_size << ", "; |
| 82 access.type->PrintTo(os); | 92 access.type->PrintTo(os); |
| 83 os << ", " << access.machine_type << ", " << access.bounds_check << "]"; | 93 os << ", " << access.machine_type << ", " << access.bounds_check; |
| 84 return os; | 94 return os; |
| 85 } | 95 } |
| 86 | 96 |
| 87 | 97 |
| 88 const FieldAccess& FieldAccessOf(const Operator* op) { | 98 const FieldAccess& FieldAccessOf(const Operator* op) { |
| 89 DCHECK_NOT_NULL(op); | 99 DCHECK_NOT_NULL(op); |
| 90 DCHECK(op->opcode() == IrOpcode::kLoadField || | 100 DCHECK(op->opcode() == IrOpcode::kLoadField || |
| 91 op->opcode() == IrOpcode::kStoreField); | 101 op->opcode() == IrOpcode::kStoreField); |
| 92 return OpParameter<FieldAccess>(op); | 102 return OpParameter<FieldAccess>(op); |
| 93 } | 103 } |
| 94 | 104 |
| 95 | 105 |
| 96 const ElementAccess& ElementAccessOf(const Operator* op) { | 106 const ElementAccess& ElementAccessOf(const Operator* op) { |
| 97 DCHECK_NOT_NULL(op); | 107 DCHECK_NOT_NULL(op); |
| 98 DCHECK(op->opcode() == IrOpcode::kLoadElement || | 108 DCHECK(op->opcode() == IrOpcode::kLoadElement || |
| 99 op->opcode() == IrOpcode::kStoreElement); | 109 op->opcode() == IrOpcode::kStoreElement); |
| 100 return OpParameter<ElementAccess>(op); | 110 return OpParameter<ElementAccess>(op); |
| 101 } | 111 } |
| 102 | 112 |
| 103 | 113 |
| 104 // Specialization for static parameters of type {FieldAccess}. | |
| 105 template <> | |
| 106 struct StaticParameterTraits<FieldAccess> { | |
| 107 static std::ostream& PrintTo(std::ostream& os, const FieldAccess& val) { | |
| 108 return os << val.offset; | |
| 109 } | |
| 110 static int HashCode(const FieldAccess& val) { | |
| 111 return (val.offset < 16) | (val.machine_type & 0xffff); | |
| 112 } | |
| 113 static bool Equals(const FieldAccess& lhs, const FieldAccess& rhs) { | |
| 114 return lhs.base_is_tagged == rhs.base_is_tagged && | |
| 115 lhs.offset == rhs.offset && lhs.machine_type == rhs.machine_type && | |
| 116 lhs.type->Is(rhs.type); | |
| 117 } | |
| 118 }; | |
| 119 | |
| 120 | |
| 121 // Specialization for static parameters of type {ElementAccess}. | |
| 122 template <> | |
| 123 struct StaticParameterTraits<ElementAccess> { | |
| 124 static std::ostream& PrintTo(std::ostream& os, const ElementAccess& access) { | |
| 125 return os << access; | |
| 126 } | |
| 127 static int HashCode(const ElementAccess& access) { | |
| 128 return (access.header_size < 16) | (access.machine_type & 0xffff); | |
| 129 } | |
| 130 static bool Equals(const ElementAccess& lhs, const ElementAccess& rhs) { | |
| 131 return lhs.base_is_tagged == rhs.base_is_tagged && | |
| 132 lhs.header_size == rhs.header_size && | |
| 133 lhs.machine_type == rhs.machine_type && lhs.type->Is(rhs.type); | |
| 134 } | |
| 135 }; | |
| 136 | |
| 137 | |
| 138 #define PURE_OP_LIST(V) \ | 114 #define PURE_OP_LIST(V) \ |
| 139 V(BooleanNot, Operator::kNoProperties, 1) \ | 115 V(BooleanNot, Operator::kNoProperties, 1) \ |
| 140 V(BooleanToNumber, Operator::kNoProperties, 1) \ | 116 V(BooleanToNumber, Operator::kNoProperties, 1) \ |
| 141 V(NumberEqual, Operator::kCommutative, 2) \ | 117 V(NumberEqual, Operator::kCommutative, 2) \ |
| 142 V(NumberLessThan, Operator::kNoProperties, 2) \ | 118 V(NumberLessThan, Operator::kNoProperties, 2) \ |
| 143 V(NumberLessThanOrEqual, Operator::kNoProperties, 2) \ | 119 V(NumberLessThanOrEqual, Operator::kNoProperties, 2) \ |
| 144 V(NumberAdd, Operator::kCommutative, 2) \ | 120 V(NumberAdd, Operator::kCommutative, 2) \ |
| 145 V(NumberSubtract, Operator::kNoProperties, 2) \ | 121 V(NumberSubtract, Operator::kNoProperties, 2) \ |
| 146 V(NumberMultiply, Operator::kCommutative, 2) \ | 122 V(NumberMultiply, Operator::kCommutative, 2) \ |
| 147 V(NumberDivide, Operator::kNoProperties, 2) \ | 123 V(NumberDivide, Operator::kNoProperties, 2) \ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return new (zone()) \ | 185 return new (zone()) \ |
| 210 Operator1<Type>(IrOpcode::k##Name, Operator::kNoThrow | properties, \ | 186 Operator1<Type>(IrOpcode::k##Name, Operator::kNoThrow | properties, \ |
| 211 input_count, output_count, #Name, access); \ | 187 input_count, output_count, #Name, access); \ |
| 212 } | 188 } |
| 213 ACCESS_OP_LIST(ACCESS) | 189 ACCESS_OP_LIST(ACCESS) |
| 214 #undef ACCESS | 190 #undef ACCESS |
| 215 | 191 |
| 216 } // namespace compiler | 192 } // namespace compiler |
| 217 } // namespace internal | 193 } // namespace internal |
| 218 } // namespace v8 | 194 } // namespace v8 |
| OLD | NEW |