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 "src/compiler/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-properties-inl.h" | 7 #include "src/compiler/node-properties-inl.h" |
8 #include "src/compiler/simplified-operator.h" | 8 #include "src/compiler/simplified-operator.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "test/compiler-unittests/graph-unittest.h" | 10 #include "test/compiler-unittests/graph-unittest.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 private: | 108 private: |
109 SimplifiedOperatorBuilder simplified_; | 109 SimplifiedOperatorBuilder simplified_; |
110 }; | 110 }; |
111 | 111 |
112 | 112 |
113 // ----------------------------------------------------------------------------- | 113 // ----------------------------------------------------------------------------- |
114 // Common. | 114 // Common. |
115 | 115 |
116 namespace { | |
117 | 116 |
118 class Common : public ChangeLoweringTest, | 117 class ChangeLoweringCommonTest |
119 public ::testing::WithParamInterface<MachineType> { | 118 : public ChangeLoweringTest, |
| 119 public ::testing::WithParamInterface<MachineType> { |
120 public: | 120 public: |
121 virtual ~Common() {} | 121 virtual ~ChangeLoweringCommonTest() {} |
122 | 122 |
123 virtual MachineType WordRepresentation() const V8_FINAL V8_OVERRIDE { | 123 virtual MachineType WordRepresentation() const V8_FINAL V8_OVERRIDE { |
124 return GetParam(); | 124 return GetParam(); |
125 } | 125 } |
126 }; | 126 }; |
127 | 127 |
128 | 128 |
129 TARGET_TEST_P(Common, ChangeBitToBool) { | 129 TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBitToBool) { |
130 Node* val = Parameter(0); | 130 Node* val = Parameter(0); |
131 Node* node = graph()->NewNode(simplified()->ChangeBitToBool(), val); | 131 Node* node = graph()->NewNode(simplified()->ChangeBitToBool(), val); |
132 Reduction reduction = Reduce(node); | 132 Reduction reduction = Reduce(node); |
133 ASSERT_TRUE(reduction.Changed()); | 133 ASSERT_TRUE(reduction.Changed()); |
134 | 134 |
135 Node* phi = reduction.replacement(); | 135 Node* phi = reduction.replacement(); |
136 Capture<Node*> branch; | 136 Capture<Node*> branch; |
137 EXPECT_THAT(phi, | 137 EXPECT_THAT(phi, |
138 IsPhi(IsTrue(), IsFalse(), | 138 IsPhi(IsTrue(), IsFalse(), |
139 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 139 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
140 IsBranch(val, graph()->start()))), | 140 IsBranch(val, graph()->start()))), |
141 IsIfFalse(CaptureEq(&branch))))); | 141 IsIfFalse(CaptureEq(&branch))))); |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 TARGET_TEST_P(Common, ChangeBoolToBit) { | 145 TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBoolToBit) { |
146 Node* val = Parameter(0); | 146 Node* val = Parameter(0); |
147 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); | 147 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); |
148 Reduction reduction = Reduce(node); | 148 Reduction reduction = Reduce(node); |
149 ASSERT_TRUE(reduction.Changed()); | 149 ASSERT_TRUE(reduction.Changed()); |
150 | 150 |
151 EXPECT_THAT(reduction.replacement(), IsWordEqual(val, IsTrue())); | 151 EXPECT_THAT(reduction.replacement(), IsWordEqual(val, IsTrue())); |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 TARGET_TEST_P(Common, ChangeFloat64ToTagged) { | 155 TARGET_TEST_P(ChangeLoweringCommonTest, ChangeFloat64ToTagged) { |
156 Node* val = Parameter(0); | 156 Node* val = Parameter(0); |
157 Node* node = graph()->NewNode(simplified()->ChangeFloat64ToTagged(), val); | 157 Node* node = graph()->NewNode(simplified()->ChangeFloat64ToTagged(), val); |
158 Reduction reduction = Reduce(node); | 158 Reduction reduction = Reduce(node); |
159 ASSERT_TRUE(reduction.Changed()); | 159 ASSERT_TRUE(reduction.Changed()); |
160 | 160 |
161 Node* finish = reduction.replacement(); | 161 Node* finish = reduction.replacement(); |
162 Capture<Node*> heap_number; | 162 Capture<Node*> heap_number; |
163 EXPECT_THAT( | 163 EXPECT_THAT( |
164 finish, | 164 finish, |
165 IsFinish( | 165 IsFinish( |
166 AllOf(CaptureEq(&heap_number), | 166 AllOf(CaptureEq(&heap_number), |
167 IsAllocateHeapNumber(IsValueEffect(val), graph()->start())), | 167 IsAllocateHeapNumber(IsValueEffect(val), graph()->start())), |
168 IsStore(kMachFloat64, kNoWriteBarrier, CaptureEq(&heap_number), | 168 IsStore(kMachFloat64, kNoWriteBarrier, CaptureEq(&heap_number), |
169 IsInt32Constant(HeapNumberValueOffset()), val, | 169 IsInt32Constant(HeapNumberValueOffset()), val, |
170 CaptureEq(&heap_number), graph()->start()))); | 170 CaptureEq(&heap_number), graph()->start()))); |
171 } | 171 } |
172 | 172 |
173 | 173 |
174 TARGET_TEST_P(Common, StringAdd) { | 174 TARGET_TEST_P(ChangeLoweringCommonTest, StringAdd) { |
175 Node* node = | 175 Node* node = |
176 graph()->NewNode(simplified()->StringAdd(), Parameter(0), Parameter(1)); | 176 graph()->NewNode(simplified()->StringAdd(), Parameter(0), Parameter(1)); |
177 Reduction reduction = Reduce(node); | 177 Reduction reduction = Reduce(node); |
178 EXPECT_FALSE(reduction.Changed()); | 178 EXPECT_FALSE(reduction.Changed()); |
179 } | 179 } |
180 | 180 |
181 } // namespace | |
182 | 181 |
183 | 182 INSTANTIATE_TEST_CASE_P(ChangeLoweringTest, ChangeLoweringCommonTest, |
184 INSTANTIATE_TEST_CASE_P(ChangeLoweringTest, Common, | |
185 ::testing::Values(kRepWord32, kRepWord64)); | 183 ::testing::Values(kRepWord32, kRepWord64)); |
186 | 184 |
187 | 185 |
188 // ----------------------------------------------------------------------------- | 186 // ----------------------------------------------------------------------------- |
189 // 32-bit | 187 // 32-bit |
190 | 188 |
191 | 189 |
192 class ChangeLowering32Test : public ChangeLoweringTest { | 190 class ChangeLowering32Test : public ChangeLoweringTest { |
193 public: | 191 public: |
194 virtual ~ChangeLowering32Test() {} | 192 virtual ~ChangeLowering32Test() {} |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 348 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
351 IsIfFalse(AllOf( | 349 IsIfFalse(AllOf( |
352 CaptureEq(&branch), | 350 CaptureEq(&branch), |
353 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 351 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), |
354 graph()->start())))))); | 352 graph()->start())))))); |
355 } | 353 } |
356 | 354 |
357 } // namespace compiler | 355 } // namespace compiler |
358 } // namespace internal | 356 } // namespace internal |
359 } // namespace v8 | 357 } // namespace v8 |
OLD | NEW |