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 <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
11 #include "src/compiler/js-graph.h" | 11 #include "src/compiler/js-graph.h" |
12 #include "src/compiler/machine-operator.h" | 12 #include "src/compiler/machine-operator.h" |
13 #include "src/compiler/simplified-operator.h" | 13 #include "src/compiler/simplified-operator.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace compiler { | 17 namespace compiler { |
18 | 18 |
19 // Contains logic related to changing the representation of values for constants | 19 // Contains logic related to changing the representation of values for constants |
20 // and other nodes, as well as lowering Simplified->Machine operators. | 20 // and other nodes, as well as lowering Simplified->Machine operators. |
21 // Eagerly folds any representation changes for constants. | 21 // Eagerly folds any representation changes for constants. |
22 class RepresentationChanger { | 22 class RepresentationChanger { |
23 public: | 23 public: |
24 RepresentationChanger(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, | 24 RepresentationChanger(JSGraph* jsgraph, Isolate* isolate) |
25 Isolate* isolate) | |
26 : jsgraph_(jsgraph), | 25 : jsgraph_(jsgraph), |
27 simplified_(simplified), | |
28 isolate_(isolate), | 26 isolate_(isolate), |
29 testing_type_errors_(false), | 27 testing_type_errors_(false), |
30 type_error_(false) {} | 28 type_error_(false) {} |
31 | 29 |
32 // TODO(titzer): should Word64 also be implicitly convertable to others? | 30 // TODO(titzer): should Word64 also be implicitly convertable to others? |
33 static bool IsWord(MachineTypeUnion type) { | 31 static bool IsWord(MachineTypeUnion type) { |
34 return (type & (kRepWord8 | kRepWord16 | kRepWord32)) != 0; | 32 return (type & (kRepWord8 | kRepWord16 | kRepWord32)) != 0; |
35 } | 33 } |
36 | 34 |
37 Node* GetRepresentationFor(Node* node, MachineTypeUnion output_type, | 35 Node* GetRepresentationFor(Node* node, MachineTypeUnion output_type, |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 return kTypeAny; // TODO(titzer): should be an error | 404 return kTypeAny; // TODO(titzer): should be an error |
407 if (type->Is(Type::Signed32())) return kTypeInt32; | 405 if (type->Is(Type::Signed32())) return kTypeInt32; |
408 if (type->Is(Type::Unsigned32())) return kTypeUint32; | 406 if (type->Is(Type::Unsigned32())) return kTypeUint32; |
409 if (type->Is(Type::Number())) return kTypeNumber; | 407 if (type->Is(Type::Number())) return kTypeNumber; |
410 if (type->Is(Type::Boolean())) return kTypeBool; | 408 if (type->Is(Type::Boolean())) return kTypeBool; |
411 return kTypeAny; | 409 return kTypeAny; |
412 } | 410 } |
413 | 411 |
414 private: | 412 private: |
415 JSGraph* jsgraph_; | 413 JSGraph* jsgraph_; |
416 SimplifiedOperatorBuilder* simplified_; | |
417 Isolate* isolate_; | 414 Isolate* isolate_; |
418 | 415 |
419 friend class RepresentationChangerTester; // accesses the below fields. | 416 friend class RepresentationChangerTester; // accesses the below fields. |
420 | 417 |
421 bool testing_type_errors_; // If {true}, don't abort on a type error. | 418 bool testing_type_errors_; // If {true}, don't abort on a type error. |
422 bool type_error_; // Set when a type error is detected. | 419 bool type_error_; // Set when a type error is detected. |
423 | 420 |
424 Node* TypeError(Node* node, MachineTypeUnion output_type, | 421 Node* TypeError(Node* node, MachineTypeUnion output_type, |
425 MachineTypeUnion use) { | 422 MachineTypeUnion use) { |
426 type_error_ = true; | 423 type_error_ = true; |
(...skipping 19 matching lines...) Expand all Loading... |
446 } | 443 } |
447 | 444 |
448 Node* InsertChangeTaggedToFloat64(Node* node) { | 445 Node* InsertChangeTaggedToFloat64(Node* node) { |
449 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 446 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
450 node); | 447 node); |
451 } | 448 } |
452 | 449 |
453 JSGraph* jsgraph() const { return jsgraph_; } | 450 JSGraph* jsgraph() const { return jsgraph_; } |
454 Isolate* isolate() const { return isolate_; } | 451 Isolate* isolate() const { return isolate_; } |
455 Factory* factory() const { return isolate()->factory(); } | 452 Factory* factory() const { return isolate()->factory(); } |
456 SimplifiedOperatorBuilder* simplified() { return simplified_; } | 453 SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); } |
457 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } | 454 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } |
458 }; | 455 }; |
459 | 456 |
460 } // namespace compiler | 457 } // namespace compiler |
461 } // namespace internal | 458 } // namespace internal |
462 } // namespace v8 | 459 } // namespace v8 |
463 | 460 |
464 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ | 461 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ |
OLD | NEW |