| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/compiler/representation-change.h" | 5 #include "src/compiler/representation-change.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 case IrOpcode::kFloat64Constant: | 205 case IrOpcode::kFloat64Constant: |
| 206 case IrOpcode::kFloat32Constant: | 206 case IrOpcode::kFloat32Constant: |
| 207 return TypeError(node, output_rep, output_type, | 207 return TypeError(node, output_rep, output_type, |
| 208 MachineRepresentation::kTaggedSigned); | 208 MachineRepresentation::kTaggedSigned); |
| 209 default: | 209 default: |
| 210 break; | 210 break; |
| 211 } | 211 } |
| 212 // Select the correct X -> Tagged operator. | 212 // Select the correct X -> Tagged operator. |
| 213 const Operator* op; | 213 const Operator* op; |
| 214 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 214 if (output_type->Is(Type::None())) { |
| 215 // This is an impossible value; it should not be used at runtime. | 215 // This is an impossible value; it should not be used at runtime. |
| 216 // We just provide a dummy value here. | 216 // We just provide a dummy value here. |
| 217 return jsgraph()->Constant(0); | 217 return jsgraph()->Constant(0); |
| 218 } else if (IsWord(output_rep)) { | 218 } else if (IsWord(output_rep)) { |
| 219 if (output_type->Is(Type::Signed31())) { | 219 if (output_type->Is(Type::Signed31())) { |
| 220 op = simplified()->ChangeInt31ToTaggedSigned(); | 220 op = simplified()->ChangeInt31ToTaggedSigned(); |
| 221 } else if (machine()->Is64() && output_type->Is(Type::Signed32())) { | 221 } else if (machine()->Is64() && output_type->Is(Type::Signed32())) { |
| 222 op = simplified()->ChangeInt32ToTagged(); | 222 op = simplified()->ChangeInt32ToTagged(); |
| 223 } else { | 223 } else { |
| 224 return TypeError(node, output_rep, output_type, | 224 return TypeError(node, output_rep, output_type, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 246 MachineRepresentation::kTaggedPointer); | 246 MachineRepresentation::kTaggedPointer); |
| 247 } | 247 } |
| 248 case IrOpcode::kFloat64Constant: | 248 case IrOpcode::kFloat64Constant: |
| 249 case IrOpcode::kFloat32Constant: | 249 case IrOpcode::kFloat32Constant: |
| 250 return TypeError(node, output_rep, output_type, | 250 return TypeError(node, output_rep, output_type, |
| 251 MachineRepresentation::kTaggedPointer); | 251 MachineRepresentation::kTaggedPointer); |
| 252 default: | 252 default: |
| 253 break; | 253 break; |
| 254 } | 254 } |
| 255 // Select the correct X -> Tagged operator. | 255 // Select the correct X -> Tagged operator. |
| 256 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 256 if (output_type->Is(Type::None())) { |
| 257 // This is an impossible value; it should not be used at runtime. | 257 // This is an impossible value; it should not be used at runtime. |
| 258 // We just provide a dummy value here. | 258 // We just provide a dummy value here. |
| 259 return jsgraph()->TheHoleConstant(); | 259 return jsgraph()->TheHoleConstant(); |
| 260 } | 260 } |
| 261 return TypeError(node, output_rep, output_type, | 261 return TypeError(node, output_rep, output_type, |
| 262 MachineRepresentation::kTaggedPointer); | 262 MachineRepresentation::kTaggedPointer); |
| 263 } | 263 } |
| 264 | 264 |
| 265 Node* RepresentationChanger::GetTaggedRepresentationFor( | 265 Node* RepresentationChanger::GetTaggedRepresentationFor( |
| 266 Node* node, MachineRepresentation output_rep, Type* output_type, | 266 Node* node, MachineRepresentation output_rep, Type* output_type, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 291 default: | 291 default: |
| 292 break; | 292 break; |
| 293 } | 293 } |
| 294 if (output_rep == MachineRepresentation::kTaggedSigned || | 294 if (output_rep == MachineRepresentation::kTaggedSigned || |
| 295 output_rep == MachineRepresentation::kTaggedPointer) { | 295 output_rep == MachineRepresentation::kTaggedPointer) { |
| 296 // this is a no-op. | 296 // this is a no-op. |
| 297 return node; | 297 return node; |
| 298 } | 298 } |
| 299 // Select the correct X -> Tagged operator. | 299 // Select the correct X -> Tagged operator. |
| 300 const Operator* op; | 300 const Operator* op; |
| 301 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 301 if (output_type->Is(Type::None())) { |
| 302 // This is an impossible value; it should not be used at runtime. | 302 // This is an impossible value; it should not be used at runtime. |
| 303 // We just provide a dummy value here. | 303 // We just provide a dummy value here. |
| 304 return jsgraph()->TheHoleConstant(); | 304 return jsgraph()->TheHoleConstant(); |
| 305 } else if (output_rep == MachineRepresentation::kBit) { | 305 } else if (output_rep == MachineRepresentation::kBit) { |
| 306 if (output_type->Is(Type::Boolean())) { | 306 if (output_type->Is(Type::Boolean())) { |
| 307 op = simplified()->ChangeBitToTagged(); | 307 op = simplified()->ChangeBitToTagged(); |
| 308 } else { | 308 } else { |
| 309 return TypeError(node, output_rep, output_type, | 309 return TypeError(node, output_rep, output_type, |
| 310 MachineRepresentation::kTagged); | 310 MachineRepresentation::kTagged); |
| 311 } | 311 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 int32_t value = OpParameter<int32_t>(node); | 373 int32_t value = OpParameter<int32_t>(node); |
| 374 return jsgraph()->Float32Constant(static_cast<float>(value)); | 374 return jsgraph()->Float32Constant(static_cast<float>(value)); |
| 375 } | 375 } |
| 376 case IrOpcode::kFloat32Constant: | 376 case IrOpcode::kFloat32Constant: |
| 377 return node; // No change necessary. | 377 return node; // No change necessary. |
| 378 default: | 378 default: |
| 379 break; | 379 break; |
| 380 } | 380 } |
| 381 // Select the correct X -> Float32 operator. | 381 // Select the correct X -> Float32 operator. |
| 382 const Operator* op = nullptr; | 382 const Operator* op = nullptr; |
| 383 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 383 if (output_type->Is(Type::None())) { |
| 384 // This is an impossible value; it should not be used at runtime. | 384 // This is an impossible value; it should not be used at runtime. |
| 385 // We just provide a dummy value here. | 385 // We just provide a dummy value here. |
| 386 return jsgraph()->Float32Constant(0.0f); | 386 return jsgraph()->Float32Constant(0.0f); |
| 387 } else if (IsWord(output_rep)) { | 387 } else if (IsWord(output_rep)) { |
| 388 if (output_type->Is(Type::Signed32())) { | 388 if (output_type->Is(Type::Signed32())) { |
| 389 // int32 -> float64 -> float32 | 389 // int32 -> float64 -> float32 |
| 390 op = machine()->ChangeInt32ToFloat64(); | 390 op = machine()->ChangeInt32ToFloat64(); |
| 391 node = jsgraph()->graph()->NewNode(op, node); | 391 node = jsgraph()->graph()->NewNode(op, node); |
| 392 op = machine()->TruncateFloat64ToFloat32(); | 392 op = machine()->TruncateFloat64ToFloat32(); |
| 393 } else if (output_type->Is(Type::Unsigned32()) || | 393 } else if (output_type->Is(Type::Unsigned32()) || |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 case IrOpcode::kFloat64Constant: | 443 case IrOpcode::kFloat64Constant: |
| 444 return node; // No change necessary. | 444 return node; // No change necessary. |
| 445 case IrOpcode::kFloat32Constant: | 445 case IrOpcode::kFloat32Constant: |
| 446 return jsgraph()->Float64Constant(OpParameter<float>(node)); | 446 return jsgraph()->Float64Constant(OpParameter<float>(node)); |
| 447 default: | 447 default: |
| 448 break; | 448 break; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 // Select the correct X -> Float64 operator. | 451 // Select the correct X -> Float64 operator. |
| 452 const Operator* op = nullptr; | 452 const Operator* op = nullptr; |
| 453 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 453 if (output_type->Is(Type::None())) { |
| 454 // This is an impossible value; it should not be used at runtime. | 454 // This is an impossible value; it should not be used at runtime. |
| 455 // We just provide a dummy value here. | 455 // We just provide a dummy value here. |
| 456 return jsgraph()->Float64Constant(0.0); | 456 return jsgraph()->Float64Constant(0.0); |
| 457 } else if (IsWord(output_rep)) { | 457 } else if (IsWord(output_rep)) { |
| 458 if (output_type->Is(Type::Signed32())) { | 458 if (output_type->Is(Type::Signed32())) { |
| 459 op = machine()->ChangeInt32ToFloat64(); | 459 op = machine()->ChangeInt32ToFloat64(); |
| 460 } else if (output_type->Is(Type::Unsigned32()) || | 460 } else if (output_type->Is(Type::Unsigned32()) || |
| 461 use_info.truncation().IsUsedAsWord32()) { | 461 use_info.truncation().IsUsedAsWord32()) { |
| 462 // Either the output is uint32 or the uses only care about the | 462 // Either the output is uint32 or the uses only care about the |
| 463 // low 32 bits (so we can pick uint32 safely). | 463 // low 32 bits (so we can pick uint32 safely). |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 return MakeTruncatedInt32Constant(fv); | 529 return MakeTruncatedInt32Constant(fv); |
| 530 } | 530 } |
| 531 break; | 531 break; |
| 532 } | 532 } |
| 533 default: | 533 default: |
| 534 break; | 534 break; |
| 535 } | 535 } |
| 536 | 536 |
| 537 // Select the correct X -> Word32 operator. | 537 // Select the correct X -> Word32 operator. |
| 538 const Operator* op = nullptr; | 538 const Operator* op = nullptr; |
| 539 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 539 if (output_type->Is(Type::None())) { |
| 540 // This is an impossible value; it should not be used at runtime. | 540 // This is an impossible value; it should not be used at runtime. |
| 541 // We just provide a dummy value here. | 541 // We just provide a dummy value here. |
| 542 return jsgraph()->Int32Constant(0); | 542 return jsgraph()->Int32Constant(0); |
| 543 } else if (output_rep == MachineRepresentation::kBit) { | 543 } else if (output_rep == MachineRepresentation::kBit) { |
| 544 return node; // Sloppy comparison -> word32 | 544 return node; // Sloppy comparison -> word32 |
| 545 } else if (output_rep == MachineRepresentation::kFloat64) { | 545 } else if (output_rep == MachineRepresentation::kFloat64) { |
| 546 if (output_type->Is(Type::Unsigned32())) { | 546 if (output_type->Is(Type::Unsigned32())) { |
| 547 op = machine()->ChangeFloat64ToUint32(); | 547 op = machine()->ChangeFloat64ToUint32(); |
| 548 } else if (output_type->Is(Type::Signed32())) { | 548 } else if (output_type->Is(Type::Signed32())) { |
| 549 op = machine()->ChangeFloat64ToInt32(); | 549 op = machine()->ChangeFloat64ToInt32(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 switch (node->opcode()) { | 651 switch (node->opcode()) { |
| 652 case IrOpcode::kHeapConstant: { | 652 case IrOpcode::kHeapConstant: { |
| 653 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); | 653 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); |
| 654 return jsgraph()->Int32Constant(value->BooleanValue() ? 1 : 0); | 654 return jsgraph()->Int32Constant(value->BooleanValue() ? 1 : 0); |
| 655 } | 655 } |
| 656 default: | 656 default: |
| 657 break; | 657 break; |
| 658 } | 658 } |
| 659 // Select the correct X -> Bit operator. | 659 // Select the correct X -> Bit operator. |
| 660 const Operator* op; | 660 const Operator* op; |
| 661 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 661 if (output_type->Is(Type::None())) { |
| 662 // This is an impossible value; it should not be used at runtime. | 662 // This is an impossible value; it should not be used at runtime. |
| 663 // We just provide a dummy value here. | 663 // We just provide a dummy value here. |
| 664 return jsgraph()->Int32Constant(0); | 664 return jsgraph()->Int32Constant(0); |
| 665 } else if (output_rep == MachineRepresentation::kTagged || | 665 } else if (output_rep == MachineRepresentation::kTagged || |
| 666 output_rep == MachineRepresentation::kTaggedPointer) { | 666 output_rep == MachineRepresentation::kTaggedPointer) { |
| 667 if (output_type->Is(Type::BooleanOrNullOrUndefined())) { | 667 if (output_type->Is(Type::BooleanOrNullOrUndefined())) { |
| 668 // true is the only trueish Oddball. | 668 // true is the only trueish Oddball. |
| 669 op = simplified()->ChangeTaggedToBit(); | 669 op = simplified()->ChangeTaggedToBit(); |
| 670 } else { | 670 } else { |
| 671 op = simplified()->TruncateTaggedToBit(); | 671 op = simplified()->TruncateTaggedToBit(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 690 jsgraph()->Float64Constant(0.0), node); | 690 jsgraph()->Float64Constant(0.0), node); |
| 691 } else { | 691 } else { |
| 692 return TypeError(node, output_rep, output_type, | 692 return TypeError(node, output_rep, output_type, |
| 693 MachineRepresentation::kBit); | 693 MachineRepresentation::kBit); |
| 694 } | 694 } |
| 695 return jsgraph()->graph()->NewNode(op, node); | 695 return jsgraph()->graph()->NewNode(op, node); |
| 696 } | 696 } |
| 697 | 697 |
| 698 Node* RepresentationChanger::GetWord64RepresentationFor( | 698 Node* RepresentationChanger::GetWord64RepresentationFor( |
| 699 Node* node, MachineRepresentation output_rep, Type* output_type) { | 699 Node* node, MachineRepresentation output_rep, Type* output_type) { |
| 700 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 700 if (output_type->Is(Type::None())) { |
| 701 // This is an impossible value; it should not be used at runtime. | 701 // This is an impossible value; it should not be used at runtime. |
| 702 // We just provide a dummy value here. | 702 // We just provide a dummy value here. |
| 703 return jsgraph()->Int64Constant(0); | 703 return jsgraph()->Int64Constant(0); |
| 704 } else if (output_rep == MachineRepresentation::kBit) { | 704 } else if (output_rep == MachineRepresentation::kBit) { |
| 705 return node; // Sloppy comparison -> word64 | 705 return node; // Sloppy comparison -> word64 |
| 706 } | 706 } |
| 707 // Can't really convert Word64 to anything else. Purported to be internal. | 707 // Can't really convert Word64 to anything else. Purported to be internal. |
| 708 return TypeError(node, output_rep, output_type, | 708 return TypeError(node, output_rep, output_type, |
| 709 MachineRepresentation::kWord64); | 709 MachineRepresentation::kWord64); |
| 710 } | 710 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 } | 952 } |
| 953 | 953 |
| 954 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 954 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
| 955 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 955 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
| 956 node); | 956 node); |
| 957 } | 957 } |
| 958 | 958 |
| 959 } // namespace compiler | 959 } // namespace compiler |
| 960 } // namespace internal | 960 } // namespace internal |
| 961 } // namespace v8 | 961 } // namespace v8 |
| OLD | NEW |