| 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 575 |
| 576 // Select the correct X -> Word32 operator. | 576 // Select the correct X -> Word32 operator. |
| 577 const Operator* op = nullptr; | 577 const Operator* op = nullptr; |
| 578 if (output_type->Is(Type::None())) { | 578 if (output_type->Is(Type::None())) { |
| 579 // This is an impossible value; it should not be used at runtime. | 579 // This is an impossible value; it should not be used at runtime. |
| 580 // We just provide a dummy value here. | 580 // We just provide a dummy value here. |
| 581 return jsgraph()->Int32Constant(0); | 581 return jsgraph()->Int32Constant(0); |
| 582 } else if (output_rep == MachineRepresentation::kBit) { | 582 } else if (output_rep == MachineRepresentation::kBit) { |
| 583 return node; // Sloppy comparison -> word32 | 583 return node; // Sloppy comparison -> word32 |
| 584 } else if (output_rep == MachineRepresentation::kFloat64) { | 584 } else if (output_rep == MachineRepresentation::kFloat64) { |
| 585 if (output_type->Is(Type::Unsigned32())) { | 585 if (output_type->Is(Type::Signed32())) { |
| 586 op = machine()->ChangeFloat64ToUint32(); | |
| 587 } else if (output_type->Is(Type::Signed32())) { | |
| 588 op = machine()->ChangeFloat64ToInt32(); | 586 op = machine()->ChangeFloat64ToInt32(); |
| 589 } else if (use_info.truncation().IsUsedAsWord32()) { | |
| 590 op = machine()->TruncateFloat64ToWord32(); | |
| 591 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall || | 587 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall || |
| 592 use_info.type_check() == TypeCheckKind::kSigned32) { | 588 use_info.type_check() == TypeCheckKind::kSigned32) { |
| 593 op = simplified()->CheckedFloat64ToInt32( | 589 op = simplified()->CheckedFloat64ToInt32( |
| 594 output_type->Maybe(Type::MinusZero()) | 590 output_type->Maybe(Type::MinusZero()) |
| 595 ? use_info.minus_zero_check() | 591 ? use_info.minus_zero_check() |
| 596 : CheckForMinusZeroMode::kDontCheckForMinusZero); | 592 : CheckForMinusZeroMode::kDontCheckForMinusZero); |
| 593 } else if (output_type->Is(Type::Unsigned32())) { |
| 594 op = machine()->ChangeFloat64ToUint32(); |
| 595 } else if (use_info.truncation().IsUsedAsWord32()) { |
| 596 op = machine()->TruncateFloat64ToWord32(); |
| 597 } | 597 } |
| 598 } else if (output_rep == MachineRepresentation::kFloat32) { | 598 } else if (output_rep == MachineRepresentation::kFloat32) { |
| 599 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 | 599 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 |
| 600 if (output_type->Is(Type::Unsigned32())) { | 600 if (output_type->Is(Type::Signed32())) { |
| 601 op = machine()->ChangeFloat64ToUint32(); | |
| 602 } else if (output_type->Is(Type::Signed32())) { | |
| 603 op = machine()->ChangeFloat64ToInt32(); | 601 op = machine()->ChangeFloat64ToInt32(); |
| 604 } else if (use_info.truncation().IsUsedAsWord32()) { | |
| 605 op = machine()->TruncateFloat64ToWord32(); | |
| 606 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall || | 602 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall || |
| 607 use_info.type_check() == TypeCheckKind::kSigned32) { | 603 use_info.type_check() == TypeCheckKind::kSigned32) { |
| 608 op = simplified()->CheckedFloat64ToInt32( | 604 op = simplified()->CheckedFloat64ToInt32( |
| 609 output_type->Maybe(Type::MinusZero()) | 605 output_type->Maybe(Type::MinusZero()) |
| 610 ? CheckForMinusZeroMode::kCheckForMinusZero | 606 ? CheckForMinusZeroMode::kCheckForMinusZero |
| 611 : CheckForMinusZeroMode::kDontCheckForMinusZero); | 607 : CheckForMinusZeroMode::kDontCheckForMinusZero); |
| 608 } else if (output_type->Is(Type::Unsigned32())) { |
| 609 op = machine()->ChangeFloat64ToUint32(); |
| 610 } else if (use_info.truncation().IsUsedAsWord32()) { |
| 611 op = machine()->TruncateFloat64ToWord32(); |
| 612 } | 612 } |
| 613 } else if (output_rep == MachineRepresentation::kTaggedSigned) { | 613 } else if (output_rep == MachineRepresentation::kTaggedSigned) { |
| 614 if (output_type->Is(Type::Signed32())) { | 614 if (output_type->Is(Type::Signed32())) { |
| 615 op = simplified()->ChangeTaggedSignedToInt32(); | 615 op = simplified()->ChangeTaggedSignedToInt32(); |
| 616 } else if (use_info.truncation().IsUsedAsWord32()) { | 616 } else if (use_info.truncation().IsUsedAsWord32()) { |
| 617 if (use_info.type_check() != TypeCheckKind::kNone) { | 617 if (use_info.type_check() != TypeCheckKind::kNone) { |
| 618 op = simplified()->CheckedTruncateTaggedToWord32(); | 618 op = simplified()->CheckedTruncateTaggedToWord32(); |
| 619 } else { | 619 } else { |
| 620 op = simplified()->TruncateTaggedToWord32(); | 620 op = simplified()->TruncateTaggedToWord32(); |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 } else if (output_rep == MachineRepresentation::kTagged || | 623 } else if (output_rep == MachineRepresentation::kTagged || |
| 624 output_rep == MachineRepresentation::kTaggedPointer) { | 624 output_rep == MachineRepresentation::kTaggedPointer) { |
| 625 if (output_type->Is(Type::Unsigned32())) { | 625 if (output_type->Is(Type::Signed32())) { |
| 626 op = simplified()->ChangeTaggedToUint32(); | |
| 627 } else if (output_type->Is(Type::Signed32())) { | |
| 628 op = simplified()->ChangeTaggedToInt32(); | 626 op = simplified()->ChangeTaggedToInt32(); |
| 629 } else if (use_info.truncation().IsUsedAsWord32()) { | |
| 630 if (use_info.type_check() != TypeCheckKind::kNone) { | |
| 631 op = simplified()->CheckedTruncateTaggedToWord32(); | |
| 632 } else { | |
| 633 op = simplified()->TruncateTaggedToWord32(); | |
| 634 } | |
| 635 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) { | 627 } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) { |
| 636 op = simplified()->CheckedTaggedSignedToInt32(); | 628 op = simplified()->CheckedTaggedSignedToInt32(); |
| 637 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { | 629 } else if (use_info.type_check() == TypeCheckKind::kSigned32) { |
| 638 op = simplified()->CheckedTaggedToInt32( | 630 op = simplified()->CheckedTaggedToInt32( |
| 639 output_type->Maybe(Type::MinusZero()) | 631 output_type->Maybe(Type::MinusZero()) |
| 640 ? CheckForMinusZeroMode::kCheckForMinusZero | 632 ? CheckForMinusZeroMode::kCheckForMinusZero |
| 641 : CheckForMinusZeroMode::kDontCheckForMinusZero); | 633 : CheckForMinusZeroMode::kDontCheckForMinusZero); |
| 634 } else if (output_type->Is(Type::Unsigned32())) { |
| 635 op = simplified()->ChangeTaggedToUint32(); |
| 636 } else if (use_info.truncation().IsUsedAsWord32()) { |
| 637 if (use_info.type_check() != TypeCheckKind::kNone) { |
| 638 op = simplified()->CheckedTruncateTaggedToWord32(); |
| 639 } else { |
| 640 op = simplified()->TruncateTaggedToWord32(); |
| 641 } |
| 642 } | 642 } |
| 643 } else if (output_rep == MachineRepresentation::kWord32) { | 643 } else if (output_rep == MachineRepresentation::kWord32) { |
| 644 // Only the checked case should get here, the non-checked case is | 644 // Only the checked case should get here, the non-checked case is |
| 645 // handled in GetRepresentationFor. | 645 // handled in GetRepresentationFor. |
| 646 if (use_info.type_check() == TypeCheckKind::kSignedSmall || | 646 if (use_info.type_check() == TypeCheckKind::kSignedSmall || |
| 647 use_info.type_check() == TypeCheckKind::kSigned32) { | 647 use_info.type_check() == TypeCheckKind::kSigned32) { |
| 648 if (output_type->Is(Type::Signed32())) { | 648 if (output_type->Is(Type::Signed32())) { |
| 649 return node; | 649 return node; |
| 650 } else if (output_type->Is(Type::Unsigned32())) { | 650 } else if (output_type->Is(Type::Unsigned32())) { |
| 651 op = simplified()->CheckedUint32ToInt32(); | 651 op = simplified()->CheckedUint32ToInt32(); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 node); | 1002 node); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 Node* RepresentationChanger::InsertChangeUint32ToFloat64(Node* node) { | 1005 Node* RepresentationChanger::InsertChangeUint32ToFloat64(Node* node) { |
| 1006 return jsgraph()->graph()->NewNode(machine()->ChangeUint32ToFloat64(), node); | 1006 return jsgraph()->graph()->NewNode(machine()->ChangeUint32ToFloat64(), node); |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 } // namespace compiler | 1009 } // namespace compiler |
| 1010 } // namespace internal | 1010 } // namespace internal |
| 1011 } // namespace v8 | 1011 } // namespace v8 |
| OLD | NEW |