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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 return jsgraph()->graph()->NewNode(op, node); | 643 return jsgraph()->graph()->NewNode(op, node); |
644 } | 644 } |
645 | 645 |
646 | 646 |
647 Node* RepresentationChanger::GetBitRepresentationFor( | 647 Node* RepresentationChanger::GetBitRepresentationFor( |
648 Node* node, MachineRepresentation output_rep, Type* output_type) { | 648 Node* node, MachineRepresentation output_rep, Type* output_type) { |
649 // Eagerly fold representation changes for constants. | 649 // Eagerly fold representation changes for constants. |
650 switch (node->opcode()) { | 650 switch (node->opcode()) { |
651 case IrOpcode::kHeapConstant: { | 651 case IrOpcode::kHeapConstant: { |
652 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); | 652 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); |
653 DCHECK(value.is_identical_to(factory()->true_value()) || | 653 return jsgraph()->Int32Constant(value->BooleanValue() ? 1 : 0); |
654 value.is_identical_to(factory()->false_value())); | |
655 return jsgraph()->Int32Constant( | |
656 value.is_identical_to(factory()->true_value()) ? 1 : 0); | |
657 } | 654 } |
658 default: | 655 default: |
659 break; | 656 break; |
660 } | 657 } |
661 // Select the correct X -> Bit operator. | 658 // Select the correct X -> Bit operator. |
662 const Operator* op; | 659 const Operator* op; |
663 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 660 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { |
664 // This is an impossible value; it should not be used at runtime. | 661 // This is an impossible value; it should not be used at runtime. |
665 // We just provide a dummy value here. | 662 // We just provide a dummy value here. |
666 return jsgraph()->Int32Constant(0); | 663 return jsgraph()->Int32Constant(0); |
667 } else if (output_rep == MachineRepresentation::kTagged || | 664 } else if (output_rep == MachineRepresentation::kTagged || |
668 output_rep == MachineRepresentation::kTaggedSigned || | |
669 output_rep == MachineRepresentation::kTaggedPointer) { | 665 output_rep == MachineRepresentation::kTaggedPointer) { |
670 op = simplified()->ChangeTaggedToBit(); | 666 if (output_type->Is(Type::BooleanOrNullOrUndefined())) { |
| 667 // true is the only trueish Oddball. |
| 668 op = simplified()->ChangeTaggedToBit(); |
| 669 } else { |
| 670 op = simplified()->TruncateTaggedToBit(); |
| 671 } |
| 672 } else if (output_rep == MachineRepresentation::kTaggedSigned) { |
| 673 node = jsgraph()->graph()->NewNode(machine()->WordEqual(), node, |
| 674 jsgraph()->ZeroConstant()); |
| 675 return jsgraph()->graph()->NewNode(machine()->Word32Equal(), node, |
| 676 jsgraph()->Int32Constant(0)); |
| 677 } else if (IsWord(output_rep)) { |
| 678 node = jsgraph()->graph()->NewNode(machine()->Word32Equal(), node, |
| 679 jsgraph()->Int32Constant(0)); |
| 680 return jsgraph()->graph()->NewNode(machine()->Word32Equal(), node, |
| 681 jsgraph()->Int32Constant(0)); |
| 682 } else if (output_rep == MachineRepresentation::kFloat32) { |
| 683 node = jsgraph()->graph()->NewNode(machine()->Float32Abs(), node); |
| 684 return jsgraph()->graph()->NewNode(machine()->Float32LessThan(), |
| 685 jsgraph()->Float32Constant(0.0), node); |
| 686 } else if (output_rep == MachineRepresentation::kFloat64) { |
| 687 node = jsgraph()->graph()->NewNode(machine()->Float64Abs(), node); |
| 688 return jsgraph()->graph()->NewNode(machine()->Float64LessThan(), |
| 689 jsgraph()->Float64Constant(0.0), node); |
671 } else { | 690 } else { |
672 return TypeError(node, output_rep, output_type, | 691 return TypeError(node, output_rep, output_type, |
673 MachineRepresentation::kBit); | 692 MachineRepresentation::kBit); |
674 } | 693 } |
675 return jsgraph()->graph()->NewNode(op, node); | 694 return jsgraph()->graph()->NewNode(op, node); |
676 } | 695 } |
677 | 696 |
678 Node* RepresentationChanger::GetWord64RepresentationFor( | 697 Node* RepresentationChanger::GetWord64RepresentationFor( |
679 Node* node, MachineRepresentation output_rep, Type* output_type) { | 698 Node* node, MachineRepresentation output_rep, Type* output_type) { |
680 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { | 699 if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 } | 951 } |
933 | 952 |
934 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 953 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
935 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 954 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
936 node); | 955 node); |
937 } | 956 } |
938 | 957 |
939 } // namespace compiler | 958 } // namespace compiler |
940 } // namespace internal | 959 } // namespace internal |
941 } // namespace v8 | 960 } // namespace v8 |
OLD | NEW |