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_COMMON_OPERATOR_H_ | 5 #ifndef V8_COMPILER_COMMON_OPERATOR_H_ |
6 #define V8_COMPILER_COMMON_OPERATOR_H_ | 6 #define V8_COMPILER_COMMON_OPERATOR_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 184 } |
185 | 185 |
186 private: | 186 private: |
187 Zone* zone_; | 187 Zone* zone_; |
188 }; | 188 }; |
189 | 189 |
190 | 190 |
191 template <typename T> | 191 template <typename T> |
192 struct CommonOperatorTraits { | 192 struct CommonOperatorTraits { |
193 static inline bool Equals(T a, T b); | 193 static inline bool Equals(T a, T b); |
194 static inline bool HasValue(Operator* op); | 194 static inline bool HasValue(const Operator* op); |
195 static inline T ValueOf(Operator* op); | 195 static inline T ValueOf(const Operator* op); |
196 }; | 196 }; |
197 | 197 |
198 template <> | 198 template <> |
199 struct CommonOperatorTraits<int32_t> { | 199 struct CommonOperatorTraits<int32_t> { |
200 static inline bool Equals(int32_t a, int32_t b) { return a == b; } | 200 static inline bool Equals(int32_t a, int32_t b) { return a == b; } |
201 static inline bool HasValue(Operator* op) { | 201 static inline bool HasValue(const Operator* op) { |
202 return op->opcode() == IrOpcode::kInt32Constant || | 202 return op->opcode() == IrOpcode::kInt32Constant || |
203 op->opcode() == IrOpcode::kNumberConstant; | 203 op->opcode() == IrOpcode::kNumberConstant; |
204 } | 204 } |
205 static inline int32_t ValueOf(Operator* op) { | 205 static inline int32_t ValueOf(const Operator* op) { |
206 if (op->opcode() == IrOpcode::kNumberConstant) { | 206 if (op->opcode() == IrOpcode::kNumberConstant) { |
207 // TODO(titzer): cache the converted int32 value in NumberConstant. | 207 // TODO(titzer): cache the converted int32 value in NumberConstant. |
208 return FastD2I(reinterpret_cast<Operator1<double>*>(op)->parameter()); | 208 return FastD2I(OpParameter<double>(op)); |
209 } | 209 } |
210 CHECK_EQ(IrOpcode::kInt32Constant, op->opcode()); | 210 CHECK_EQ(IrOpcode::kInt32Constant, op->opcode()); |
211 return static_cast<Operator1<int32_t>*>(op)->parameter(); | 211 return OpParameter<int32_t>(op); |
212 } | 212 } |
213 }; | 213 }; |
214 | 214 |
215 template <> | 215 template <> |
216 struct CommonOperatorTraits<uint32_t> { | 216 struct CommonOperatorTraits<uint32_t> { |
217 static inline bool Equals(uint32_t a, uint32_t b) { return a == b; } | 217 static inline bool Equals(uint32_t a, uint32_t b) { return a == b; } |
218 static inline bool HasValue(Operator* op) { | 218 static inline bool HasValue(const Operator* op) { |
219 return CommonOperatorTraits<int32_t>::HasValue(op); | 219 return CommonOperatorTraits<int32_t>::HasValue(op); |
220 } | 220 } |
221 static inline uint32_t ValueOf(Operator* op) { | 221 static inline uint32_t ValueOf(const Operator* op) { |
222 if (op->opcode() == IrOpcode::kNumberConstant) { | 222 if (op->opcode() == IrOpcode::kNumberConstant) { |
223 // TODO(titzer): cache the converted uint32 value in NumberConstant. | 223 // TODO(titzer): cache the converted uint32 value in NumberConstant. |
224 return FastD2UI(reinterpret_cast<Operator1<double>*>(op)->parameter()); | 224 return FastD2UI(OpParameter<double>(op)); |
225 } | 225 } |
226 return static_cast<uint32_t>(CommonOperatorTraits<int32_t>::ValueOf(op)); | 226 return static_cast<uint32_t>(CommonOperatorTraits<int32_t>::ValueOf(op)); |
227 } | 227 } |
228 }; | 228 }; |
229 | 229 |
230 template <> | 230 template <> |
231 struct CommonOperatorTraits<int64_t> { | 231 struct CommonOperatorTraits<int64_t> { |
232 static inline bool Equals(int64_t a, int64_t b) { return a == b; } | 232 static inline bool Equals(int64_t a, int64_t b) { return a == b; } |
233 static inline bool HasValue(Operator* op) { | 233 static inline bool HasValue(const Operator* op) { |
234 return op->opcode() == IrOpcode::kInt32Constant || | 234 return op->opcode() == IrOpcode::kInt32Constant || |
235 op->opcode() == IrOpcode::kInt64Constant || | 235 op->opcode() == IrOpcode::kInt64Constant || |
236 op->opcode() == IrOpcode::kNumberConstant; | 236 op->opcode() == IrOpcode::kNumberConstant; |
237 } | 237 } |
238 static inline int64_t ValueOf(Operator* op) { | 238 static inline int64_t ValueOf(const Operator* op) { |
239 if (op->opcode() == IrOpcode::kInt32Constant) { | 239 if (op->opcode() == IrOpcode::kInt32Constant) { |
240 return static_cast<int64_t>(CommonOperatorTraits<int32_t>::ValueOf(op)); | 240 return static_cast<int64_t>(CommonOperatorTraits<int32_t>::ValueOf(op)); |
241 } | 241 } |
242 CHECK_EQ(IrOpcode::kInt64Constant, op->opcode()); | 242 CHECK_EQ(IrOpcode::kInt64Constant, op->opcode()); |
243 return static_cast<Operator1<int64_t>*>(op)->parameter(); | 243 return OpParameter<int64_t>(op); |
244 } | 244 } |
245 }; | 245 }; |
246 | 246 |
247 template <> | 247 template <> |
248 struct CommonOperatorTraits<uint64_t> { | 248 struct CommonOperatorTraits<uint64_t> { |
249 static inline bool Equals(uint64_t a, uint64_t b) { return a == b; } | 249 static inline bool Equals(uint64_t a, uint64_t b) { return a == b; } |
250 static inline bool HasValue(Operator* op) { | 250 static inline bool HasValue(const Operator* op) { |
251 return CommonOperatorTraits<int64_t>::HasValue(op); | 251 return CommonOperatorTraits<int64_t>::HasValue(op); |
252 } | 252 } |
253 static inline uint64_t ValueOf(Operator* op) { | 253 static inline uint64_t ValueOf(const Operator* op) { |
254 return static_cast<uint64_t>(CommonOperatorTraits<int64_t>::ValueOf(op)); | 254 return static_cast<uint64_t>(CommonOperatorTraits<int64_t>::ValueOf(op)); |
255 } | 255 } |
256 }; | 256 }; |
257 | 257 |
258 template <> | 258 template <> |
259 struct CommonOperatorTraits<double> { | 259 struct CommonOperatorTraits<double> { |
260 static inline bool Equals(double a, double b) { | 260 static inline bool Equals(double a, double b) { |
261 return DoubleRepresentation(a).bits == DoubleRepresentation(b).bits; | 261 return DoubleRepresentation(a).bits == DoubleRepresentation(b).bits; |
262 } | 262 } |
263 static inline bool HasValue(Operator* op) { | 263 static inline bool HasValue(const Operator* op) { |
264 return op->opcode() == IrOpcode::kFloat64Constant || | 264 return op->opcode() == IrOpcode::kFloat64Constant || |
265 op->opcode() == IrOpcode::kInt32Constant || | 265 op->opcode() == IrOpcode::kInt32Constant || |
266 op->opcode() == IrOpcode::kNumberConstant; | 266 op->opcode() == IrOpcode::kNumberConstant; |
267 } | 267 } |
268 static inline double ValueOf(Operator* op) { | 268 static inline double ValueOf(const Operator* op) { |
269 if (op->opcode() == IrOpcode::kFloat64Constant || | 269 if (op->opcode() == IrOpcode::kFloat64Constant || |
270 op->opcode() == IrOpcode::kNumberConstant) { | 270 op->opcode() == IrOpcode::kNumberConstant) { |
271 return reinterpret_cast<Operator1<double>*>(op)->parameter(); | 271 return OpParameter<double>(op); |
272 } | 272 } |
273 return static_cast<double>(CommonOperatorTraits<int32_t>::ValueOf(op)); | 273 return static_cast<double>(CommonOperatorTraits<int32_t>::ValueOf(op)); |
274 } | 274 } |
275 }; | 275 }; |
276 | 276 |
277 template <> | 277 template <> |
278 struct CommonOperatorTraits<ExternalReference> { | 278 struct CommonOperatorTraits<ExternalReference> { |
279 static inline bool Equals(ExternalReference a, ExternalReference b) { | 279 static inline bool Equals(ExternalReference a, ExternalReference b) { |
280 return a == b; | 280 return a == b; |
281 } | 281 } |
282 static inline bool HasValue(Operator* op) { | 282 static inline bool HasValue(const Operator* op) { |
283 return op->opcode() == IrOpcode::kExternalConstant; | 283 return op->opcode() == IrOpcode::kExternalConstant; |
284 } | 284 } |
285 static inline ExternalReference ValueOf(Operator* op) { | 285 static inline ExternalReference ValueOf(const Operator* op) { |
286 CHECK_EQ(IrOpcode::kExternalConstant, op->opcode()); | 286 CHECK_EQ(IrOpcode::kExternalConstant, op->opcode()); |
287 return static_cast<Operator1<ExternalReference>*>(op)->parameter(); | 287 return OpParameter<ExternalReference>(op); |
288 } | 288 } |
289 }; | 289 }; |
290 | 290 |
291 template <typename T> | 291 template <typename T> |
292 struct CommonOperatorTraits<PrintableUnique<T> > { | 292 struct CommonOperatorTraits<PrintableUnique<T> > { |
293 static inline bool HasValue(Operator* op) { | 293 static inline bool HasValue(const Operator* op) { |
294 return op->opcode() == IrOpcode::kHeapConstant; | 294 return op->opcode() == IrOpcode::kHeapConstant; |
295 } | 295 } |
296 static inline PrintableUnique<T> ValueOf(Operator* op) { | 296 static inline PrintableUnique<T> ValueOf(const Operator* op) { |
297 CHECK_EQ(IrOpcode::kHeapConstant, op->opcode()); | 297 CHECK_EQ(IrOpcode::kHeapConstant, op->opcode()); |
298 return static_cast<Operator1<PrintableUnique<T> >*>(op)->parameter(); | 298 return OpParameter<PrintableUnique<T> >(op); |
299 } | 299 } |
300 }; | 300 }; |
301 | 301 |
302 template <typename T> | 302 template <typename T> |
303 struct CommonOperatorTraits<Handle<T> > { | 303 struct CommonOperatorTraits<Handle<T> > { |
304 static inline bool HasValue(Operator* op) { | 304 static inline bool HasValue(const Operator* op) { |
305 return CommonOperatorTraits<PrintableUnique<T> >::HasValue(op); | 305 return CommonOperatorTraits<PrintableUnique<T> >::HasValue(op); |
306 } | 306 } |
307 static inline Handle<T> ValueOf(Operator* op) { | 307 static inline Handle<T> ValueOf(const Operator* op) { |
308 return CommonOperatorTraits<PrintableUnique<T> >::ValueOf(op).handle(); | 308 return CommonOperatorTraits<PrintableUnique<T> >::ValueOf(op).handle(); |
309 } | 309 } |
310 }; | 310 }; |
311 | 311 |
312 | 312 |
313 template <typename T> | 313 template <typename T> |
314 inline T ValueOf(Operator* op) { | 314 inline T ValueOf(const Operator* op) { |
315 return CommonOperatorTraits<T>::ValueOf(op); | 315 return CommonOperatorTraits<T>::ValueOf(op); |
316 } | 316 } |
317 } | 317 |
318 } | 318 } // namespace compiler |
319 } // namespace v8::internal::compiler | 319 } // namespace internal |
| 320 } // namespace v8 |
320 | 321 |
321 #endif // V8_COMPILER_COMMON_OPERATOR_H_ | 322 #endif // V8_COMPILER_COMMON_OPERATOR_H_ |
OLD | NEW |