Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: test/unittests/compiler/live-range-unittest.cc

Issue 1391023007: [turbofan] Splinter into one range. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 5
6 #include "test/unittests/compiler/live-range-builder.h" 6 #include "test/unittests/compiler/live-range-builder.h"
7 #include "test/unittests/test-utils.h" 7 #include "test/unittests/test-utils.h"
8 8
9 9
10 // TODO(mtrofin): would we want to centralize this definition? 10 // TODO(mtrofin): would we want to centralize this definition?
(...skipping 14 matching lines...) Expand all
25 class LiveRangeUnitTest : public TestWithZone { 25 class LiveRangeUnitTest : public TestWithZone {
26 public: 26 public:
27 // Split helper, to avoid int->LifetimePosition conversion nuisance. 27 // Split helper, to avoid int->LifetimePosition conversion nuisance.
28 LiveRange* Split(LiveRange* range, int pos) { 28 LiveRange* Split(LiveRange* range, int pos) {
29 return range->SplitAt(LifetimePosition::FromInt(pos), zone()); 29 return range->SplitAt(LifetimePosition::FromInt(pos), zone());
30 } 30 }
31 31
32 32
33 TopLevelLiveRange* Splinter(TopLevelLiveRange* top, int start, int end, 33 TopLevelLiveRange* Splinter(TopLevelLiveRange* top, int start, int end,
34 int new_id = 0) { 34 int new_id = 0) {
35 TopLevelLiveRange* ret = 35 if (top->splinter() == nullptr) {
36 new (zone()) TopLevelLiveRange(new_id, MachineType::kRepTagged); 36 TopLevelLiveRange* ret =
37 new (zone()) TopLevelLiveRange(new_id, MachineType::kRepTagged);
38 top->SetSplinter(ret);
39 }
37 top->Splinter(LifetimePosition::FromInt(start), 40 top->Splinter(LifetimePosition::FromInt(start),
38 LifetimePosition::FromInt(end), ret, zone()); 41 LifetimePosition::FromInt(end), zone());
39 return ret; 42 return top->splinter();
40 } 43 }
41 44
42 // Ranges first and second match structurally. 45 // Ranges first and second match structurally.
43 bool RangesMatch(LiveRange* first, LiveRange* second) { 46 bool RangesMatch(LiveRange* first, LiveRange* second) {
44 if (first->Start() != second->Start() || first->End() != second->End()) { 47 if (first->Start() != second->Start() || first->End() != second->End()) {
45 return false; 48 return false;
46 } 49 }
47 UseInterval* i1 = first->first_interval(); 50 UseInterval* i1 = first->first_interval();
48 UseInterval* i2 = second->first_interval(); 51 UseInterval* i2 = second->first_interval();
49 52
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 EXPECT_EQ(range, splinter->splintered_from()); 373 EXPECT_EQ(range, splinter->splintered_from());
371 374
372 TopLevelLiveRange* expected_source = 375 TopLevelLiveRange* expected_source =
373 TestRangeBuilder(zone()).Add(0, 3).Add(6, 8).Build(); 376 TestRangeBuilder(zone()).Add(0, 3).Add(6, 8).Build();
374 TopLevelLiveRange* expected_splinter = TestRangeBuilder(zone()).Build(5, 6); 377 TopLevelLiveRange* expected_splinter = TestRangeBuilder(zone()).Build(5, 6);
375 EXPECT_TRUE(RangesMatch(expected_source, range)); 378 EXPECT_TRUE(RangesMatch(expected_source, range));
376 EXPECT_TRUE(RangesMatch(expected_splinter, splinter)); 379 EXPECT_TRUE(RangesMatch(expected_splinter, splinter));
377 } 380 }
378 381
379 382
383 TEST_F(LiveRangeUnitTest, SplinterMergeMultipleTimes) {
384 TopLevelLiveRange* range =
385 TestRangeBuilder(zone()).Add(0, 3).Add(5, 10).Add(12, 16).Build();
386 Splinter(range, 4, 6);
387 Splinter(range, 8, 14);
388 TopLevelLiveRange* splinter = range->splinter();
389 EXPECT_EQ(nullptr, range->next());
390 EXPECT_EQ(nullptr, splinter->next());
391 EXPECT_EQ(range, splinter->splintered_from());
392
393 TopLevelLiveRange* expected_source =
394 TestRangeBuilder(zone()).Add(0, 3).Add(6, 8).Add(14, 16).Build();
395 TopLevelLiveRange* expected_splinter =
396 TestRangeBuilder(zone()).Add(5, 6).Add(8, 10).Add(12, 14).Build();
397 EXPECT_TRUE(RangesMatch(expected_source, range));
398 EXPECT_TRUE(RangesMatch(expected_splinter, splinter));
399 }
400
401
380 TEST_F(LiveRangeUnitTest, MergeMultipleIntervalsRight) { 402 TEST_F(LiveRangeUnitTest, MergeMultipleIntervalsRight) {
381 TopLevelLiveRange* original = 403 TopLevelLiveRange* original =
382 TestRangeBuilder(zone()).Add(0, 3).Add(5, 8).Build(); 404 TestRangeBuilder(zone()).Add(0, 3).Add(5, 8).Build();
383 TopLevelLiveRange* splinter = Splinter(original, 4, 6); 405 TopLevelLiveRange* splinter = Splinter(original, 4, 6);
384 original->Merge(splinter, zone()); 406 original->Merge(splinter, zone());
385 407
386 TopLevelLiveRange* result = 408 TopLevelLiveRange* result =
387 TestRangeBuilder(zone()).Add(0, 3).Add(5, 8).Build(); 409 TestRangeBuilder(zone()).Add(0, 3).Add(5, 8).Build();
388 LiveRange* child_1 = Split(result, 5); 410 LiveRange* child_1 = Split(result, 5);
389 Split(child_1, 6); 411 Split(child_1, 6);
(...skipping 19 matching lines...) Expand all
409 } 431 }
410 432
411 433
412 TEST_F(LiveRangeUnitTest, IDGeneration) { 434 TEST_F(LiveRangeUnitTest, IDGeneration) {
413 TopLevelLiveRange* vreg = TestRangeBuilder(zone()).Id(2).Build(0, 100); 435 TopLevelLiveRange* vreg = TestRangeBuilder(zone()).Id(2).Build(0, 100);
414 EXPECT_EQ(2, vreg->vreg()); 436 EXPECT_EQ(2, vreg->vreg());
415 EXPECT_EQ(0, vreg->relative_id()); 437 EXPECT_EQ(0, vreg->relative_id());
416 438
417 TopLevelLiveRange* splinter = 439 TopLevelLiveRange* splinter =
418 new (zone()) TopLevelLiveRange(101, MachineType::kRepTagged); 440 new (zone()) TopLevelLiveRange(101, MachineType::kRepTagged);
441 vreg->SetSplinter(splinter);
419 vreg->Splinter(LifetimePosition::FromInt(4), LifetimePosition::FromInt(12), 442 vreg->Splinter(LifetimePosition::FromInt(4), LifetimePosition::FromInt(12),
420 splinter, zone()); 443 zone());
421 444
422 EXPECT_EQ(101, splinter->vreg()); 445 EXPECT_EQ(101, splinter->vreg());
423 EXPECT_EQ(1, splinter->relative_id()); 446 EXPECT_EQ(1, splinter->relative_id());
424 447
425 LiveRange* child = vreg->SplitAt(LifetimePosition::FromInt(50), zone()); 448 LiveRange* child = vreg->SplitAt(LifetimePosition::FromInt(50), zone());
426 449
427 EXPECT_EQ(2, child->relative_id()); 450 EXPECT_EQ(2, child->relative_id());
428 451
429 LiveRange* splinter_child = 452 LiveRange* splinter_child =
430 splinter->SplitAt(LifetimePosition::FromInt(8), zone()); 453 splinter->SplitAt(LifetimePosition::FromInt(8), zone());
431 454
432 EXPECT_EQ(1, splinter->relative_id()); 455 EXPECT_EQ(1, splinter->relative_id());
433 EXPECT_EQ(3, splinter_child->relative_id()); 456 EXPECT_EQ(3, splinter_child->relative_id());
434 457
435 vreg->Merge(splinter, zone()); 458 vreg->Merge(splinter, zone());
436 EXPECT_EQ(1, splinter->relative_id()); 459 EXPECT_EQ(1, splinter->relative_id());
437 } 460 }
438 461
439 } // namespace compiler 462 } // namespace compiler
440 } // namespace internal 463 } // namespace internal
441 } // namespace v8 464 } // namespace v8
OLDNEW
« src/compiler/register-allocator.cc ('K') | « src/compiler/register-allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698