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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 return jsgraph()->graph()->NewNode(op, node); | 475 return jsgraph()->graph()->NewNode(op, node); |
476 } | 476 } |
477 | 477 |
478 | 478 |
479 Node* RepresentationChanger::GetBitRepresentationFor( | 479 Node* RepresentationChanger::GetBitRepresentationFor( |
480 Node* node, MachineRepresentation output_rep, Type* output_type) { | 480 Node* node, MachineRepresentation output_rep, Type* output_type) { |
481 // Eagerly fold representation changes for constants. | 481 // Eagerly fold representation changes for constants. |
482 switch (node->opcode()) { | 482 switch (node->opcode()) { |
483 case IrOpcode::kHeapConstant: { | 483 case IrOpcode::kHeapConstant: { |
484 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); | 484 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); |
485 return jsgraph()->Int32Constant(value->BooleanValue() ? 1 : 0); | 485 DCHECK(value.is_identical_to(factory()->true_value()) || |
| 486 value.is_identical_to(factory()->false_value())); |
| 487 return jsgraph()->Int32Constant( |
| 488 value.is_identical_to(factory()->true_value()) ? 1 : 0); |
486 } | 489 } |
487 default: | 490 default: |
488 break; | 491 break; |
489 } | 492 } |
490 // Select the correct X -> Bit operator. | 493 // Select the correct X -> Bit operator. |
491 const Operator* op; | 494 const Operator* op; |
492 if (IsWord(output_rep)) { | 495 if (output_rep == MachineRepresentation::kTagged) { |
493 return jsgraph()->graph()->NewNode(machine()->Word32Equal(), node, | 496 op = simplified()->ChangeTaggedToBit(); |
494 jsgraph()->Int32Constant(0)); | |
495 } else if (output_rep == MachineRepresentation::kFloat32) { | |
496 node = jsgraph()->graph()->NewNode(machine()->Float32Abs(), node); | |
497 return jsgraph()->graph()->NewNode(machine()->Float32LessThan(), | |
498 jsgraph()->Float32Constant(0.0), node); | |
499 } else if (output_rep == MachineRepresentation::kFloat64) { | |
500 node = jsgraph()->graph()->NewNode(machine()->Float64Abs(), node); | |
501 return jsgraph()->graph()->NewNode(machine()->Float64LessThan(), | |
502 jsgraph()->Float64Constant(0.0), node); | |
503 } else if (output_rep == MachineRepresentation::kTagged) { | |
504 if (output_type->Is(Type::Boolean())) { | |
505 op = simplified()->ChangeTaggedToBit(); | |
506 } else { | |
507 op = simplified()->TruncateTaggedToBit(); | |
508 } | |
509 } else { | 497 } else { |
510 return TypeError(node, output_rep, output_type, | 498 return TypeError(node, output_rep, output_type, |
511 MachineRepresentation::kBit); | 499 MachineRepresentation::kBit); |
512 } | 500 } |
513 return jsgraph()->graph()->NewNode(op, node); | 501 return jsgraph()->graph()->NewNode(op, node); |
514 } | 502 } |
515 | 503 |
516 Node* RepresentationChanger::GetWord64RepresentationFor( | 504 Node* RepresentationChanger::GetWord64RepresentationFor( |
517 Node* node, MachineRepresentation output_rep, Type* output_type) { | 505 Node* node, MachineRepresentation output_rep, Type* output_type) { |
518 if (output_rep == MachineRepresentation::kBit) { | 506 if (output_rep == MachineRepresentation::kBit) { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 809 } |
822 | 810 |
823 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 811 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
824 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 812 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
825 node); | 813 node); |
826 } | 814 } |
827 | 815 |
828 } // namespace compiler | 816 } // namespace compiler |
829 } // namespace internal | 817 } // namespace internal |
830 } // namespace v8 | 818 } // namespace v8 |
OLD | NEW |