OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef V8_COMPILER_OPERATOR_H_ | 5 #ifndef V8_COMPILER_OPERATOR_H_ |
6 #define V8_COMPILER_OPERATOR_H_ | 6 #define V8_COMPILER_OPERATOR_H_ |
7 | 7 |
8 #include <ostream> // NOLINT(readability/streams) | 8 #include <ostream> // NOLINT(readability/streams) |
9 | 9 |
10 #include "src/base/flags.h" | 10 #include "src/base/flags.h" |
11 #include "src/base/functional.h" | 11 #include "src/base/functional.h" |
| 12 #include "src/handles.h" |
12 #include "src/zone.h" | 13 #include "src/zone.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 namespace compiler { | 17 namespace compiler { |
17 | 18 |
18 // An operator represents description of the "computation" of a node in the | 19 // An operator represents description of the "computation" of a node in the |
19 // compiler IR. A computation takes values (i.e. data) as input and produces | 20 // compiler IR. A computation takes values (i.e. data) as input and produces |
20 // zero or more values as output. The side-effects of a computation must be | 21 // zero or more values as output. The side-effects of a computation must be |
21 // captured by additional control and data dependencies which are part of the | 22 // captured by additional control and data dependencies which are part of the |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 : Operator(opcode, properties, mnemonic, value_in, effect_in, control_in, | 149 : Operator(opcode, properties, mnemonic, value_in, effect_in, control_in, |
149 value_out, effect_out, control_out), | 150 value_out, effect_out, control_out), |
150 parameter_(parameter), | 151 parameter_(parameter), |
151 pred_(pred), | 152 pred_(pred), |
152 hash_(hash) {} | 153 hash_(hash) {} |
153 | 154 |
154 T const& parameter() const { return parameter_; } | 155 T const& parameter() const { return parameter_; } |
155 | 156 |
156 bool Equals(const Operator* other) const final { | 157 bool Equals(const Operator* other) const final { |
157 if (opcode() != other->opcode()) return false; | 158 if (opcode() != other->opcode()) return false; |
158 const Operator1<T>* that = reinterpret_cast<const Operator1<T>*>(other); | 159 const Operator1<T, Pred, Hash>* that = |
| 160 reinterpret_cast<const Operator1<T, Pred, Hash>*>(other); |
159 return this->pred_(this->parameter(), that->parameter()); | 161 return this->pred_(this->parameter(), that->parameter()); |
160 } | 162 } |
161 size_t HashCode() const final { | 163 size_t HashCode() const final { |
162 return base::hash_combine(this->opcode(), this->hash_(this->parameter())); | 164 return base::hash_combine(this->opcode(), this->hash_(this->parameter())); |
163 } | 165 } |
164 virtual void PrintParameter(std::ostream& os) const { | 166 virtual void PrintParameter(std::ostream& os) const { |
165 os << "[" << this->parameter() << "]"; | 167 os << "[" << this->parameter() << "]"; |
166 } | 168 } |
167 | 169 |
168 protected: | 170 protected: |
169 void PrintTo(std::ostream& os) const final { | 171 void PrintTo(std::ostream& os) const final { |
170 os << mnemonic(); | 172 os << mnemonic(); |
171 PrintParameter(os); | 173 PrintParameter(os); |
172 } | 174 } |
173 | 175 |
174 private: | 176 private: |
175 T const parameter_; | 177 T const parameter_; |
176 Pred const pred_; | 178 Pred const pred_; |
177 Hash const hash_; | 179 Hash const hash_; |
178 }; | 180 }; |
179 | 181 |
180 | 182 |
181 // Helper to extract parameters from Operator1<*> operator. | 183 // Helper to extract parameters from Operator1<*> operator. |
182 template <typename T> | 184 template <typename T> |
183 inline T const& OpParameter(const Operator* op) { | 185 inline T const& OpParameter(const Operator* op) { |
184 return reinterpret_cast<const Operator1<T>*>(op)->parameter(); | 186 return reinterpret_cast<const Operator1<T>*>(op)->parameter(); |
185 } | 187 } |
186 | 188 |
187 // NOTE: We have to be careful to use the right equal/hash functions below, for | 189 // NOTE: We have to be careful to use the right equal/hash functions below, for |
188 // float/double we always use the ones operating on the bit level. | 190 // float/double we always use the ones operating on the bit level, for Handle<> |
| 191 // we always use the ones operating on the location level. |
189 template <> | 192 template <> |
190 inline float const& OpParameter(const Operator* op) { | 193 inline float const& OpParameter(const Operator* op) { |
191 return reinterpret_cast<const Operator1<float, base::bit_equal_to<float>, | 194 return reinterpret_cast<const Operator1<float, base::bit_equal_to<float>, |
192 base::bit_hash<float>>*>(op) | 195 base::bit_hash<float>>*>(op) |
193 ->parameter(); | 196 ->parameter(); |
194 } | 197 } |
195 | 198 |
196 template <> | 199 template <> |
197 inline double const& OpParameter(const Operator* op) { | 200 inline double const& OpParameter(const Operator* op) { |
198 return reinterpret_cast<const Operator1<double, base::bit_equal_to<double>, | 201 return reinterpret_cast<const Operator1<double, base::bit_equal_to<double>, |
199 base::bit_hash<double>>*>(op) | 202 base::bit_hash<double>>*>(op) |
200 ->parameter(); | 203 ->parameter(); |
201 } | 204 } |
202 | 205 |
| 206 template <> |
| 207 inline Handle<HeapObject> const& OpParameter(const Operator* op) { |
| 208 return reinterpret_cast< |
| 209 const Operator1<Handle<HeapObject>, Handle<HeapObject>::equal_to, |
| 210 Handle<HeapObject>::hash>*>(op)->parameter(); |
| 211 } |
| 212 |
| 213 template <> |
| 214 inline Handle<String> const& OpParameter(const Operator* op) { |
| 215 return reinterpret_cast<const Operator1< |
| 216 Handle<String>, Handle<String>::equal_to, Handle<String>::hash>*>(op) |
| 217 ->parameter(); |
| 218 } |
| 219 |
203 } // namespace compiler | 220 } // namespace compiler |
204 } // namespace internal | 221 } // namespace internal |
205 } // namespace v8 | 222 } // namespace v8 |
206 | 223 |
207 #endif // V8_COMPILER_OPERATOR_H_ | 224 #endif // V8_COMPILER_OPERATOR_H_ |
OLD | NEW |