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