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/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/control-reducer.h" | 10 #include "src/compiler/control-reducer.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 CHECK(IsUsedBy(T.start, T.p0)); | 214 CHECK(IsUsedBy(T.start, T.p0)); |
215 CheckInputs(T.p0, T.start); | 215 CheckInputs(T.p0, T.start); |
216 } | 216 } |
217 | 217 |
218 | 218 |
219 TEST(Trim1_dead) { | 219 TEST(Trim1_dead) { |
220 ControlReducerTester T; | 220 ControlReducerTester T; |
221 CHECK(IsUsedBy(T.start, T.p0)); | 221 CHECK(IsUsedBy(T.start, T.p0)); |
222 T.Trim(); | 222 T.Trim(); |
223 CHECK(!IsUsedBy(T.start, T.p0)); | 223 CHECK(!IsUsedBy(T.start, T.p0)); |
224 CHECK_EQ(NULL, T.p0->InputAt(0)); | 224 CHECK(!T.p0->InputAt(0)); |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 TEST(Trim2_live) { | 228 TEST(Trim2_live) { |
229 ControlReducerTester T; | 229 ControlReducerTester T; |
230 Node* phi = | 230 Node* phi = |
231 T.graph.NewNode(T.common.Phi(kMachAnyTagged, 2), T.one, T.half, T.start); | 231 T.graph.NewNode(T.common.Phi(kMachAnyTagged, 2), T.one, T.half, T.start); |
232 CHECK(IsUsedBy(T.one, phi)); | 232 CHECK(IsUsedBy(T.one, phi)); |
233 CHECK(IsUsedBy(T.half, phi)); | 233 CHECK(IsUsedBy(T.half, phi)); |
234 CHECK(IsUsedBy(T.start, phi)); | 234 CHECK(IsUsedBy(T.start, phi)); |
(...skipping 10 matching lines...) Expand all Loading... |
245 ControlReducerTester T; | 245 ControlReducerTester T; |
246 Node* phi = | 246 Node* phi = |
247 T.graph.NewNode(T.common.Phi(kMachAnyTagged, 2), T.one, T.half, T.start); | 247 T.graph.NewNode(T.common.Phi(kMachAnyTagged, 2), T.one, T.half, T.start); |
248 CHECK(IsUsedBy(T.one, phi)); | 248 CHECK(IsUsedBy(T.one, phi)); |
249 CHECK(IsUsedBy(T.half, phi)); | 249 CHECK(IsUsedBy(T.half, phi)); |
250 CHECK(IsUsedBy(T.start, phi)); | 250 CHECK(IsUsedBy(T.start, phi)); |
251 T.Trim(); | 251 T.Trim(); |
252 CHECK(!IsUsedBy(T.one, phi)); | 252 CHECK(!IsUsedBy(T.one, phi)); |
253 CHECK(!IsUsedBy(T.half, phi)); | 253 CHECK(!IsUsedBy(T.half, phi)); |
254 CHECK(!IsUsedBy(T.start, phi)); | 254 CHECK(!IsUsedBy(T.start, phi)); |
255 CHECK_EQ(NULL, phi->InputAt(0)); | 255 CHECK(!phi->InputAt(0)); |
256 CHECK_EQ(NULL, phi->InputAt(1)); | 256 CHECK(!phi->InputAt(1)); |
257 CHECK_EQ(NULL, phi->InputAt(2)); | 257 CHECK(!phi->InputAt(2)); |
258 } | 258 } |
259 | 259 |
260 | 260 |
261 TEST(Trim_chain1) { | 261 TEST(Trim_chain1) { |
262 ControlReducerTester T; | 262 ControlReducerTester T; |
263 const int kDepth = 15; | 263 const int kDepth = 15; |
264 Node* live[kDepth]; | 264 Node* live[kDepth]; |
265 Node* dead[kDepth]; | 265 Node* dead[kDepth]; |
266 Node* end = T.start; | 266 Node* end = T.start; |
267 for (int i = 0; i < kDepth; i++) { | 267 for (int i = 0; i < kDepth; i++) { |
268 live[i] = end = T.graph.NewNode(T.common.Merge(1), end); | 268 live[i] = end = T.graph.NewNode(T.common.Merge(1), end); |
269 dead[i] = T.graph.NewNode(T.common.Merge(1), end); | 269 dead[i] = T.graph.NewNode(T.common.Merge(1), end); |
270 } | 270 } |
271 // end -> live[last] -> live[last-1] -> ... -> start | 271 // end -> live[last] -> live[last-1] -> ... -> start |
272 // dead[last] ^ dead[last-1] ^ ... ^ | 272 // dead[last] ^ dead[last-1] ^ ... ^ |
273 T.graph.SetEnd(end); | 273 T.graph.SetEnd(end); |
274 T.Trim(); | 274 T.Trim(); |
275 for (int i = 0; i < kDepth; i++) { | 275 for (int i = 0; i < kDepth; i++) { |
276 CHECK(!IsUsedBy(live[i], dead[i])); | 276 CHECK(!IsUsedBy(live[i], dead[i])); |
277 CHECK_EQ(NULL, dead[i]->InputAt(0)); | 277 CHECK(!dead[i]->InputAt(0)); |
278 CHECK_EQ(i == 0 ? T.start : live[i - 1], live[i]->InputAt(0)); | 278 CHECK_EQ(i == 0 ? T.start : live[i - 1], live[i]->InputAt(0)); |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 TEST(Trim_chain2) { | 283 TEST(Trim_chain2) { |
284 ControlReducerTester T; | 284 ControlReducerTester T; |
285 const int kDepth = 15; | 285 const int kDepth = 15; |
286 Node* live[kDepth]; | 286 Node* live[kDepth]; |
287 Node* dead[kDepth]; | 287 Node* dead[kDepth]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 CHECK(IsUsedBy(T.start, loop)); | 347 CHECK(IsUsedBy(T.start, loop)); |
348 CHECK(IsUsedBy(loop, end)); | 348 CHECK(IsUsedBy(loop, end)); |
349 CHECK(IsUsedBy(loop, loop)); | 349 CHECK(IsUsedBy(loop, loop)); |
350 CheckInputs(loop, T.start, loop); | 350 CheckInputs(loop, T.start, loop); |
351 CheckInputs(end, loop); | 351 CheckInputs(end, loop); |
352 | 352 |
353 // phi should have been trimmed away. | 353 // phi should have been trimmed away. |
354 CHECK(!IsUsedBy(loop, phi)); | 354 CHECK(!IsUsedBy(loop, phi)); |
355 CHECK(!IsUsedBy(T.one, phi)); | 355 CHECK(!IsUsedBy(T.one, phi)); |
356 CHECK(!IsUsedBy(T.half, phi)); | 356 CHECK(!IsUsedBy(T.half, phi)); |
357 CHECK_EQ(NULL, phi->InputAt(0)); | 357 CHECK(!phi->InputAt(0)); |
358 CHECK_EQ(NULL, phi->InputAt(1)); | 358 CHECK(!phi->InputAt(1)); |
359 CHECK_EQ(NULL, phi->InputAt(2)); | 359 CHECK(!phi->InputAt(2)); |
360 } | 360 } |
361 | 361 |
362 | 362 |
363 void CheckTrimConstant(ControlReducerTester* T, Node* k) { | 363 void CheckTrimConstant(ControlReducerTester* T, Node* k) { |
364 Node* phi = T->graph.NewNode(T->common.Phi(kMachInt32, 1), k, T->start); | 364 Node* phi = T->graph.NewNode(T->common.Phi(kMachInt32, 1), k, T->start); |
365 CHECK(IsUsedBy(k, phi)); | 365 CHECK(IsUsedBy(k, phi)); |
366 T->Trim(); | 366 T->Trim(); |
367 CHECK(!IsUsedBy(k, phi)); | 367 CHECK(!IsUsedBy(k, phi)); |
368 CHECK_EQ(NULL, phi->InputAt(0)); | 368 CHECK(!phi->InputAt(0)); |
369 CHECK_EQ(NULL, phi->InputAt(1)); | 369 CHECK(!phi->InputAt(1)); |
370 } | 370 } |
371 | 371 |
372 | 372 |
373 TEST(Trim_constants) { | 373 TEST(Trim_constants) { |
374 ControlReducerTester T; | 374 ControlReducerTester T; |
375 int32_t int32_constants[] = { | 375 int32_t int32_constants[] = { |
376 0, -1, -2, 2, 2, 3, 3, 4, 4, 5, 5, 4, 5, 6, 6, 7, 8, 7, 8, 9, | 376 0, -1, -2, 2, 2, 3, 3, 4, 4, 5, 5, 4, 5, 6, 6, 7, 8, 7, 8, 9, |
377 0, -11, -12, 12, 12, 13, 13, 14, 14, 15, 15, 14, 15, 6, 6, 7, 8, 7, 8, 9}; | 377 0, -11, -12, 12, 12, 13, 13, 14, 14, 15, 15, 14, 15, 6, 6, 7, 8, 7, 8, 9}; |
378 | 378 |
379 for (size_t i = 0; i < arraysize(int32_constants); i++) { | 379 for (size_t i = 0; i < arraysize(int32_constants); i++) { |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 ControlReducerTester R; | 947 ControlReducerTester R; |
948 for (int i = 0; i < 5; i++) { | 948 for (int i = 0; i < 5; i++) { |
949 Node* merge = R.graph.NewNode(R.common.Merge(1), R.dead); | 949 Node* merge = R.graph.NewNode(R.common.Merge(1), R.dead); |
950 for (int j = 0; j < i; j++) { | 950 for (int j = 0; j < i; j++) { |
951 merge = R.graph.NewNode(R.common.Merge(1), merge); | 951 merge = R.graph.NewNode(R.common.Merge(1), merge); |
952 } | 952 } |
953 Node* end = R.graph.NewNode(R.common.End(), merge); | 953 Node* end = R.graph.NewNode(R.common.End(), merge); |
954 R.graph.SetEnd(end); | 954 R.graph.SetEnd(end); |
955 R.ReduceGraph(); | 955 R.ReduceGraph(); |
956 CHECK(merge->IsDead()); | 956 CHECK(merge->IsDead()); |
957 CHECK_EQ(NULL, end->InputAt(0)); // end dies. | 957 CHECK(!end->InputAt(0)); // end dies. |
958 } | 958 } |
959 } | 959 } |
960 | 960 |
961 | 961 |
962 TEST(CMergeReduce_dead_chain2) { | 962 TEST(CMergeReduce_dead_chain2) { |
963 ControlReducerTester R; | 963 ControlReducerTester R; |
964 for (int i = 0; i < 5; i++) { | 964 for (int i = 0; i < 5; i++) { |
965 Node* merge = R.graph.NewNode(R.common.Merge(1), R.start); | 965 Node* merge = R.graph.NewNode(R.common.Merge(1), R.start); |
966 for (int j = 0; j < i; j++) { | 966 for (int j = 0; j < i; j++) { |
967 merge = R.graph.NewNode(R.common.Merge(2), merge, R.dead); | 967 merge = R.graph.NewNode(R.common.Merge(2), merge, R.dead); |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 | 1506 |
1507 Node* ret = R.Return(d1.phi, R.start, d1.merge); | 1507 Node* ret = R.Return(d1.phi, R.start, d1.merge); |
1508 | 1508 |
1509 R.ReduceGraph(); // d1 gets folded true. | 1509 R.ReduceGraph(); // d1 gets folded true. |
1510 | 1510 |
1511 CheckInputs(ret, y2, R.start, R.start); | 1511 CheckInputs(ret, y2, R.start, R.start); |
1512 CheckDeadDiamond(d1); | 1512 CheckDeadDiamond(d1); |
1513 CheckDeadDiamond(d2); | 1513 CheckDeadDiamond(d2); |
1514 CheckDeadDiamond(d3); | 1514 CheckDeadDiamond(d3); |
1515 } | 1515 } |
OLD | NEW |