OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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_REPRESENTATION_CHANGE_H_ | 5 #ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_ |
6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_ | 6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_ |
7 | 7 |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // Types. | 29 // Types. |
30 tBool = 1 << 5, | 30 tBool = 1 << 5, |
31 tInt32 = 1 << 6, | 31 tInt32 = 1 << 6, |
32 tUint32 = 1 << 7, | 32 tUint32 = 1 << 7, |
33 tInt64 = 1 << 8, | 33 tInt64 = 1 << 8, |
34 tUint64 = 1 << 9, | 34 tUint64 = 1 << 9, |
35 tNumber = 1 << 10, | 35 tNumber = 1 << 10, |
36 tAny = 1 << 11 | 36 tAny = 1 << 11 |
37 }; | 37 }; |
38 | 38 |
| 39 #define REP_TYPE_STRLEN 24 |
| 40 |
39 typedef uint16_t RepTypeUnion; | 41 typedef uint16_t RepTypeUnion; |
40 | 42 |
| 43 |
| 44 inline void RenderRepTypeUnion(char* buf, RepTypeUnion info) { |
| 45 base::OS::SNPrintF(buf, REP_TYPE_STRLEN, "{%s%s%s%s%s %s%s%s%s%s%s%s}", |
| 46 (info & rBit) ? "k" : " ", (info & rWord32) ? "w" : " ", |
| 47 (info & rWord64) ? "q" : " ", |
| 48 (info & rFloat64) ? "f" : " ", |
| 49 (info & rTagged) ? "t" : " ", (info & tBool) ? "Z" : " ", |
| 50 (info & tInt32) ? "I" : " ", (info & tUint32) ? "U" : " ", |
| 51 (info & tInt64) ? "L" : " ", (info & tUint64) ? "J" : " ", |
| 52 (info & tNumber) ? "N" : " ", (info & tAny) ? "*" : " "); |
| 53 } |
| 54 |
| 55 |
41 const RepTypeUnion rMask = rBit | rWord32 | rWord64 | rFloat64 | rTagged; | 56 const RepTypeUnion rMask = rBit | rWord32 | rWord64 | rFloat64 | rTagged; |
42 const RepTypeUnion tMask = | 57 const RepTypeUnion tMask = |
43 tBool | tInt32 | tUint32 | tInt64 | tUint64 | tNumber | tAny; | 58 tBool | tInt32 | tUint32 | tInt64 | tUint64 | tNumber | tAny; |
44 const RepType rPtr = kPointerSize == 4 ? rWord32 : rWord64; | 59 const RepType rPtr = kPointerSize == 4 ? rWord32 : rWord64; |
45 | 60 |
46 | |
47 // Contains logic related to changing the representation of values for constants | 61 // Contains logic related to changing the representation of values for constants |
48 // and other nodes, as well as lowering Simplified->Machine operators. | 62 // and other nodes, as well as lowering Simplified->Machine operators. |
49 // Eagerly folds any representation changes for constants. | 63 // Eagerly folds any representation changes for constants. |
50 class RepresentationChanger { | 64 class RepresentationChanger { |
51 public: | 65 public: |
52 RepresentationChanger(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, | 66 RepresentationChanger(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, |
53 MachineOperatorBuilder* machine, Isolate* isolate) | 67 MachineOperatorBuilder* machine, Isolate* isolate) |
54 : jsgraph_(jsgraph), | 68 : jsgraph_(jsgraph), |
55 simplified_(simplified), | 69 simplified_(simplified), |
56 machine_(machine), | 70 machine_(machine), |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 RepType rElement = TypeForMachineRepresentation(access.representation); | 351 RepType rElement = TypeForMachineRepresentation(access.representation); |
338 return static_cast<RepType>(tElement | rElement); | 352 return static_cast<RepType>(tElement | rElement); |
339 } | 353 } |
340 | 354 |
341 RepType TypeForElement(const ElementAccess& access) { | 355 RepType TypeForElement(const ElementAccess& access) { |
342 RepType tElement = static_cast<RepType>(0); // TODO(titzer) | 356 RepType tElement = static_cast<RepType>(0); // TODO(titzer) |
343 RepType rElement = TypeForMachineRepresentation(access.representation); | 357 RepType rElement = TypeForMachineRepresentation(access.representation); |
344 return static_cast<RepType>(tElement | rElement); | 358 return static_cast<RepType>(tElement | rElement); |
345 } | 359 } |
346 | 360 |
347 RepType TypeForBasePointer(Node* node) { | 361 RepType TypeForBasePointer(const FieldAccess& access) { |
348 Type* upper = NodeProperties::GetBounds(node).upper; | 362 if (access.tag() != 0) return static_cast<RepType>(tAny | rTagged); |
349 if (upper->Is(Type::UntaggedPtr())) return rPtr; | 363 return kPointerSize == 8 ? rWord64 : rWord32; |
350 return static_cast<RepType>(tAny | rTagged); | 364 } |
| 365 |
| 366 RepType TypeForBasePointer(const ElementAccess& access) { |
| 367 if (access.tag() != 0) return static_cast<RepType>(tAny | rTagged); |
| 368 return kPointerSize == 8 ? rWord64 : rWord32; |
| 369 } |
| 370 |
| 371 RepType TypeFromUpperBound(Type* type) { |
| 372 if (type->Is(Type::None())) |
| 373 return tAny; // TODO(titzer): should be an error |
| 374 if (type->Is(Type::Signed32())) return tInt32; |
| 375 if (type->Is(Type::Unsigned32())) return tUint32; |
| 376 if (type->Is(Type::Number())) return tNumber; |
| 377 if (type->Is(Type::Boolean())) return tBool; |
| 378 return tAny; |
351 } | 379 } |
352 | 380 |
353 private: | 381 private: |
354 JSGraph* jsgraph_; | 382 JSGraph* jsgraph_; |
355 SimplifiedOperatorBuilder* simplified_; | 383 SimplifiedOperatorBuilder* simplified_; |
356 MachineOperatorBuilder* machine_; | 384 MachineOperatorBuilder* machine_; |
357 Isolate* isolate_; | 385 Isolate* isolate_; |
358 | 386 |
359 friend class RepresentationChangerTester; // accesses the below fields. | 387 friend class RepresentationChangerTester; // accesses the below fields. |
360 | 388 |
361 bool testing_type_errors_; // If {true}, don't abort on a type error. | 389 bool testing_type_errors_; // If {true}, don't abort on a type error. |
362 bool type_error_; // Set when a type error is detected. | 390 bool type_error_; // Set when a type error is detected. |
363 | 391 |
364 Node* TypeError(Node* node, RepTypeUnion output_type, RepTypeUnion use) { | 392 Node* TypeError(Node* node, RepTypeUnion output_type, RepTypeUnion use) { |
365 type_error_ = true; | 393 type_error_ = true; |
366 if (!testing_type_errors_) { | 394 if (!testing_type_errors_) { |
367 UNREACHABLE(); // TODO(titzer): report nicer type error | 395 char buf1[REP_TYPE_STRLEN]; |
| 396 char buf2[REP_TYPE_STRLEN]; |
| 397 RenderRepTypeUnion(buf1, output_type); |
| 398 RenderRepTypeUnion(buf2, use); |
| 399 V8_Fatal(__FILE__, __LINE__, |
| 400 "RepresentationChangerError: node #%d:%s of rep" |
| 401 "%s cannot be changed to rep%s", |
| 402 node->id(), node->op()->mnemonic(), buf1, buf2); |
368 } | 403 } |
369 return node; | 404 return node; |
370 } | 405 } |
371 | 406 |
372 JSGraph* jsgraph() { return jsgraph_; } | 407 JSGraph* jsgraph() { return jsgraph_; } |
373 Isolate* isolate() { return isolate_; } | 408 Isolate* isolate() { return isolate_; } |
374 SimplifiedOperatorBuilder* simplified() { return simplified_; } | 409 SimplifiedOperatorBuilder* simplified() { return simplified_; } |
375 MachineOperatorBuilder* machine() { return machine_; } | 410 MachineOperatorBuilder* machine() { return machine_; } |
376 }; | 411 }; |
377 } | 412 } |
378 } | 413 } |
379 } // namespace v8::internal::compiler | 414 } // namespace v8::internal::compiler |
380 | 415 |
381 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ | 416 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ |
OLD | NEW |