| 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/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
| 11 #include "src/compiler/node-properties-inl.h" | 11 #include "src/compiler/node-properties-inl.h" |
| 12 #include "src/compiler/simplified-operator.h" | 12 #include "src/compiler/simplified-operator.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 namespace compiler { | 16 namespace compiler { |
| 17 | 17 |
| 18 // Contains logic related to changing the representation of values for constants | 18 // Contains logic related to changing the representation of values for constants |
| 19 // and other nodes, as well as lowering Simplified->Machine operators. | 19 // and other nodes, as well as lowering Simplified->Machine operators. |
| 20 // Eagerly folds any representation changes for constants. | 20 // Eagerly folds any representation changes for constants. |
| 21 class RepresentationChanger { | 21 class RepresentationChanger { |
| 22 public: | 22 public: |
| 23 RepresentationChanger(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, | 23 RepresentationChanger(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, |
| 24 MachineOperatorBuilder* machine, Isolate* isolate) | 24 Isolate* isolate) |
| 25 : jsgraph_(jsgraph), | 25 : jsgraph_(jsgraph), |
| 26 simplified_(simplified), | 26 simplified_(simplified), |
| 27 machine_(machine), | |
| 28 isolate_(isolate), | 27 isolate_(isolate), |
| 29 testing_type_errors_(false), | 28 testing_type_errors_(false), |
| 30 type_error_(false) {} | 29 type_error_(false) {} |
| 31 | 30 |
| 32 // TODO(titzer): should Word64 also be implicitly convertable to others? | 31 // TODO(titzer): should Word64 also be implicitly convertable to others? |
| 33 static const MachineTypeUnion rWord = | 32 static const MachineTypeUnion rWord = |
| 34 kRepBit | kRepWord8 | kRepWord16 | kRepWord32; | 33 kRepBit | kRepWord8 | kRepWord16 | kRepWord32; |
| 35 | 34 |
| 36 Node* GetRepresentationFor(Node* node, MachineTypeUnion output_type, | 35 Node* GetRepresentationFor(Node* node, MachineTypeUnion output_type, |
| 37 MachineTypeUnion use_type) { | 36 MachineTypeUnion use_type) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 if (type->Is(Type::Signed32())) return kTypeInt32; | 301 if (type->Is(Type::Signed32())) return kTypeInt32; |
| 303 if (type->Is(Type::Unsigned32())) return kTypeUint32; | 302 if (type->Is(Type::Unsigned32())) return kTypeUint32; |
| 304 if (type->Is(Type::Number())) return kTypeNumber; | 303 if (type->Is(Type::Number())) return kTypeNumber; |
| 305 if (type->Is(Type::Boolean())) return kTypeBool; | 304 if (type->Is(Type::Boolean())) return kTypeBool; |
| 306 return kTypeAny; | 305 return kTypeAny; |
| 307 } | 306 } |
| 308 | 307 |
| 309 private: | 308 private: |
| 310 JSGraph* jsgraph_; | 309 JSGraph* jsgraph_; |
| 311 SimplifiedOperatorBuilder* simplified_; | 310 SimplifiedOperatorBuilder* simplified_; |
| 312 MachineOperatorBuilder* machine_; | |
| 313 Isolate* isolate_; | 311 Isolate* isolate_; |
| 314 | 312 |
| 315 friend class RepresentationChangerTester; // accesses the below fields. | 313 friend class RepresentationChangerTester; // accesses the below fields. |
| 316 | 314 |
| 317 bool testing_type_errors_; // If {true}, don't abort on a type error. | 315 bool testing_type_errors_; // If {true}, don't abort on a type error. |
| 318 bool type_error_; // Set when a type error is detected. | 316 bool type_error_; // Set when a type error is detected. |
| 319 | 317 |
| 320 Node* TypeError(Node* node, MachineTypeUnion output_type, | 318 Node* TypeError(Node* node, MachineTypeUnion output_type, |
| 321 MachineTypeUnion use) { | 319 MachineTypeUnion use) { |
| 322 type_error_ = true; | 320 type_error_ = true; |
| 323 if (!testing_type_errors_) { | 321 if (!testing_type_errors_) { |
| 324 OStringStream out_str; | 322 OStringStream out_str; |
| 325 out_str << static_cast<MachineType>(output_type); | 323 out_str << static_cast<MachineType>(output_type); |
| 326 | 324 |
| 327 OStringStream use_str; | 325 OStringStream use_str; |
| 328 use_str << static_cast<MachineType>(use); | 326 use_str << static_cast<MachineType>(use); |
| 329 | 327 |
| 330 V8_Fatal(__FILE__, __LINE__, | 328 V8_Fatal(__FILE__, __LINE__, |
| 331 "RepresentationChangerError: node #%d:%s of " | 329 "RepresentationChangerError: node #%d:%s of " |
| 332 "%s cannot be changed to %s", | 330 "%s cannot be changed to %s", |
| 333 node->id(), node->op()->mnemonic(), out_str.c_str(), | 331 node->id(), node->op()->mnemonic(), out_str.c_str(), |
| 334 use_str.c_str()); | 332 use_str.c_str()); |
| 335 } | 333 } |
| 336 return node; | 334 return node; |
| 337 } | 335 } |
| 338 | 336 |
| 339 JSGraph* jsgraph() { return jsgraph_; } | 337 JSGraph* jsgraph() { return jsgraph_; } |
| 340 Isolate* isolate() { return isolate_; } | 338 Isolate* isolate() { return isolate_; } |
| 341 SimplifiedOperatorBuilder* simplified() { return simplified_; } | 339 SimplifiedOperatorBuilder* simplified() { return simplified_; } |
| 342 MachineOperatorBuilder* machine() { return machine_; } | 340 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } |
| 343 }; | 341 }; |
| 344 } | 342 } |
| 345 } | 343 } |
| 346 } // namespace v8::internal::compiler | 344 } // namespace v8::internal::compiler |
| 347 | 345 |
| 348 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ | 346 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ |
| OLD | NEW |