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 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
8 #include "src/compiler/change-lowering.h" | 8 #include "src/compiler/change-lowering.h" |
9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
10 #include "src/compiler/graph-reducer.h" | 10 #include "src/compiler/graph-reducer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 public: | 32 public: |
33 SimplifiedLoweringTester(MachineType p0 = kMachNone, | 33 SimplifiedLoweringTester(MachineType p0 = kMachNone, |
34 MachineType p1 = kMachNone, | 34 MachineType p1 = kMachNone, |
35 MachineType p2 = kMachNone, | 35 MachineType p2 = kMachNone, |
36 MachineType p3 = kMachNone, | 36 MachineType p3 = kMachNone, |
37 MachineType p4 = kMachNone) | 37 MachineType p4 = kMachNone) |
38 : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), | 38 : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), |
39 typer(this->graph(), MaybeHandle<Context>()), | 39 typer(this->graph(), MaybeHandle<Context>()), |
40 javascript(this->zone()), | 40 javascript(this->zone()), |
41 jsgraph(this->graph(), this->common(), &javascript, this->machine()), | 41 jsgraph(this->graph(), this->common(), &javascript, this->machine()), |
42 lowering(&jsgraph) {} | 42 lowering(&jsgraph, this->zone()) {} |
43 | 43 |
44 Typer typer; | 44 Typer typer; |
45 JSOperatorBuilder javascript; | 45 JSOperatorBuilder javascript; |
46 JSGraph jsgraph; | 46 JSGraph jsgraph; |
47 SimplifiedLowering lowering; | 47 SimplifiedLowering lowering; |
48 | 48 |
49 void LowerAllNodes() { | 49 void LowerAllNodes() { |
50 this->End(); | 50 this->End(); |
51 typer.Run(); | 51 typer.Run(); |
52 lowering.LowerAllNodes(); | 52 lowering.LowerAllNodes(); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 } | 691 } |
692 | 692 |
693 void CheckLoweringTruncatedBinop(IrOpcode::Value expected, const Operator* op, | 693 void CheckLoweringTruncatedBinop(IrOpcode::Value expected, const Operator* op, |
694 const Operator* trunc) { | 694 const Operator* trunc) { |
695 Node* node = graph()->NewNode(op, p0, p1); | 695 Node* node = graph()->NewNode(op, p0, p1); |
696 Return(graph()->NewNode(trunc, node)); | 696 Return(graph()->NewNode(trunc, node)); |
697 Lower(); | 697 Lower(); |
698 CHECK_EQ(expected, node->opcode()); | 698 CHECK_EQ(expected, node->opcode()); |
699 } | 699 } |
700 | 700 |
701 void Lower() { | 701 void Lower() { SimplifiedLowering(&jsgraph, jsgraph.zone()).LowerAllNodes(); } |
702 SimplifiedLowering(&jsgraph).LowerAllNodes(); | |
703 } | |
704 | 702 |
705 // Inserts the node as the return value of the graph. | 703 // Inserts the node as the return value of the graph. |
706 Node* Return(Node* node) { | 704 Node* Return(Node* node) { |
707 ret->ReplaceInput(0, node); | 705 ret->ReplaceInput(0, node); |
708 return node; | 706 return node; |
709 } | 707 } |
710 | 708 |
711 // Inserts the node as the effect input to the return of the graph. | 709 // Inserts the node as the effect input to the return of the graph. |
712 void Effect(Node* node) { ret->ReplaceInput(1, node); } | 710 void Effect(Node* node) { ret->ReplaceInput(1, node); } |
713 | 711 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 return graph()->NewNode(common()->Int64Constant(v)); | 780 return graph()->NewNode(common()->Int64Constant(v)); |
783 } | 781 } |
784 | 782 |
785 SimplifiedOperatorBuilder* simplified() { return &main_simplified_; } | 783 SimplifiedOperatorBuilder* simplified() { return &main_simplified_; } |
786 MachineOperatorBuilder* machine() { return &main_machine_; } | 784 MachineOperatorBuilder* machine() { return &main_machine_; } |
787 CommonOperatorBuilder* common() { return &main_common_; } | 785 CommonOperatorBuilder* common() { return &main_common_; } |
788 Graph* graph() { return main_graph_; } | 786 Graph* graph() { return main_graph_; } |
789 }; | 787 }; |
790 | 788 |
791 | 789 |
| 790 TEST(LowerAnyToBoolean_bit_bit) { |
| 791 // AnyToBoolean(x: kRepBit) used as kRepBit |
| 792 HandleAndZoneScope scope; |
| 793 Factory* f = scope.main_zone()->isolate()->factory(); |
| 794 Handle<Object> zero = f->NewNumber(0); |
| 795 Handle<Object> one = f->NewNumber(1); |
| 796 Type* singleton_zero = Type::Constant(zero, scope.main_zone()); |
| 797 Type* singleton_one = Type::Constant(one, scope.main_zone()); |
| 798 Type* zero_one_range = Type::Range(zero, one, scope.main_zone()); |
| 799 static Type* kTypes[] = { |
| 800 singleton_zero, singleton_one, zero_one_range, Type::Boolean(), |
| 801 Type::Union(Type::Boolean(), singleton_zero, scope.main_zone()), |
| 802 Type::Union(Type::Boolean(), singleton_one, scope.main_zone()), |
| 803 Type::Union(Type::Boolean(), zero_one_range, scope.main_zone())}; |
| 804 for (Type* type : kTypes) { |
| 805 TestingGraph t(type); |
| 806 Node* x = t.ExampleWithTypeAndRep(type, kRepBit); |
| 807 Node* cnv = t.graph()->NewNode(t.simplified()->AnyToBoolean(), x); |
| 808 Node* use = t.Branch(cnv); |
| 809 t.Lower(); |
| 810 CHECK_EQ(x, use->InputAt(0)); |
| 811 } |
| 812 } |
| 813 |
| 814 |
| 815 TEST(LowerAnyToBoolean_tagged_tagged) { |
| 816 // AnyToBoolean(x: kRepTagged) used as kRepTagged |
| 817 TestingGraph t(Type::Any()); |
| 818 Node* x = t.p0; |
| 819 Node* cnv = t.graph()->NewNode(t.simplified()->AnyToBoolean(), x); |
| 820 Node* use = t.Use(cnv, kRepTagged); |
| 821 t.Return(use); |
| 822 t.Lower(); |
| 823 CHECK_EQ(IrOpcode::kCall, cnv->opcode()); |
| 824 CHECK_EQ(IrOpcode::kHeapConstant, cnv->InputAt(0)->opcode()); |
| 825 CHECK_EQ(x, cnv->InputAt(1)); |
| 826 CHECK_EQ(t.jsgraph.NoContextConstant(), cnv->InputAt(2)); |
| 827 } |
| 828 |
| 829 |
792 TEST(LowerBooleanNot_bit_bit) { | 830 TEST(LowerBooleanNot_bit_bit) { |
793 // BooleanNot(x: kRepBit) used as kRepBit | 831 // BooleanNot(x: kRepBit) used as kRepBit |
794 TestingGraph t(Type::Boolean()); | 832 TestingGraph t(Type::Boolean()); |
795 Node* b = t.ExampleWithOutput(kRepBit); | 833 Node* b = t.ExampleWithOutput(kRepBit); |
796 Node* inv = t.graph()->NewNode(t.simplified()->BooleanNot(), b); | 834 Node* inv = t.graph()->NewNode(t.simplified()->BooleanNot(), b); |
797 Node* use = t.Branch(inv); | 835 Node* use = t.Branch(inv); |
798 t.Lower(); | 836 t.Lower(); |
799 Node* cmp = use->InputAt(0); | 837 Node* cmp = use->InputAt(0); |
800 CHECK_EQ(t.machine()->Word32Equal()->opcode(), cmp->opcode()); | 838 CHECK_EQ(t.machine()->Word32Equal()->opcode(), cmp->opcode()); |
801 CHECK(b == cmp->InputAt(0) || b == cmp->InputAt(1)); | 839 CHECK(b == cmp->InputAt(0) || b == cmp->InputAt(1)); |
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2030 Bounds phi_bounds = Bounds::Either(Bounds(d.arg1), Bounds(d.arg2), z); | 2068 Bounds phi_bounds = Bounds::Either(Bounds(d.arg1), Bounds(d.arg2), z); |
2031 NodeProperties::SetBounds(phi, phi_bounds); | 2069 NodeProperties::SetBounds(phi, phi_bounds); |
2032 | 2070 |
2033 Node* use = t.Use(phi, d.use); | 2071 Node* use = t.Use(phi, d.use); |
2034 t.Return(use); | 2072 t.Return(use); |
2035 t.Lower(); | 2073 t.Lower(); |
2036 | 2074 |
2037 CHECK_EQ(d.expected, OpParameter<MachineType>(phi)); | 2075 CHECK_EQ(d.expected, OpParameter<MachineType>(phi)); |
2038 } | 2076 } |
2039 } | 2077 } |
OLD | NEW |