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/coalesced-live-ranges.h" | 5 #include "src/compiler/coalesced-live-ranges.h" |
6 #include "test/unittests/test-utils.h" | 6 #include "test/unittests/test-utils.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace compiler { | 10 namespace compiler { |
(...skipping 11 matching lines...) Expand all Loading... |
22 return *this; | 22 return *this; |
23 } | 23 } |
24 TestRangeBuilder& Add(int start, int end) { | 24 TestRangeBuilder& Add(int start, int end) { |
25 pairs_.push_back({start, end}); | 25 pairs_.push_back({start, end}); |
26 return *this; | 26 return *this; |
27 } | 27 } |
28 | 28 |
29 LiveRange* Build(int start, int end) { return Add(start, end).Build(); } | 29 LiveRange* Build(int start, int end) { return Add(start, end).Build(); } |
30 | 30 |
31 LiveRange* Build() { | 31 LiveRange* Build() { |
32 LiveRange* range = new (zone_) LiveRange(id_, MachineType::kRepTagged); | 32 TopLevelLiveRange* range = |
| 33 new (zone_) TopLevelLiveRange(id_, MachineType::kRepTagged); |
33 // Traverse the provided interval specifications backwards, because that is | 34 // Traverse the provided interval specifications backwards, because that is |
34 // what LiveRange expects. | 35 // what LiveRange expects. |
35 for (int i = static_cast<int>(pairs_.size()) - 1; i >= 0; --i) { | 36 for (int i = static_cast<int>(pairs_.size()) - 1; i >= 0; --i) { |
36 Interval pair = pairs_[i]; | 37 Interval pair = pairs_[i]; |
37 LifetimePosition start = LifetimePosition::FromInt(pair.first); | 38 LifetimePosition start = LifetimePosition::FromInt(pair.first); |
38 LifetimePosition end = LifetimePosition::FromInt(pair.second); | 39 LifetimePosition end = LifetimePosition::FromInt(pair.second); |
39 CHECK(start < end); | 40 CHECK(start < end); |
40 range->AddUseInterval(start, end, zone_); | 41 range->AddUseInterval(start, end, zone_); |
41 } | 42 } |
42 | 43 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 LiveRangeIDs set(zone()); | 94 LiveRangeIDs set(zone()); |
94 return IsRangeConflictingWith(range, set); | 95 return IsRangeConflictingWith(range, set); |
95 } | 96 } |
96 | 97 |
97 | 98 |
98 void CoalescedLiveRangesTest::RemoveConflicts(LiveRange* range) { | 99 void CoalescedLiveRangesTest::RemoveConflicts(LiveRange* range) { |
99 auto conflicts = ranges().GetConflicts(range); | 100 auto conflicts = ranges().GetConflicts(range); |
100 LiveRangeIDs seen(zone()); | 101 LiveRangeIDs seen(zone()); |
101 for (auto c = conflicts.Current(); c != nullptr; | 102 for (auto c = conflicts.Current(); c != nullptr; |
102 c = conflicts.RemoveCurrentAndGetNext()) { | 103 c = conflicts.RemoveCurrentAndGetNext()) { |
103 EXPECT_FALSE(seen.count(c->id()) > 0); | 104 int id = c->TopLevel()->vreg(); |
104 seen.insert(c->id()); | 105 EXPECT_FALSE(seen.count(id) > 0); |
| 106 seen.insert(c->TopLevel()->vreg()); |
105 } | 107 } |
106 } | 108 } |
107 | 109 |
108 | 110 |
109 bool CoalescedLiveRangesTest::AllocationsAreValid() const { | 111 bool CoalescedLiveRangesTest::AllocationsAreValid() const { |
110 return ranges().VerifyAllocationsAreValidForTesting(); | 112 return ranges().VerifyAllocationsAreValidForTesting(); |
111 } | 113 } |
112 | 114 |
113 | 115 |
114 bool CoalescedLiveRangesTest::IsRangeConflictingWith(const LiveRange* range, | 116 bool CoalescedLiveRangesTest::IsRangeConflictingWith(const LiveRange* range, |
115 const LiveRangeIDs& ids) { | 117 const LiveRangeIDs& ids) { |
116 LiveRangeIDs found_ids(zone()); | 118 LiveRangeIDs found_ids(zone()); |
117 | 119 |
118 auto conflicts = ranges().GetConflicts(range); | 120 auto conflicts = ranges().GetConflicts(range); |
119 for (auto conflict = conflicts.Current(); conflict != nullptr; | 121 for (auto conflict = conflicts.Current(); conflict != nullptr; |
120 conflict = conflicts.GetNext()) { | 122 conflict = conflicts.GetNext()) { |
121 found_ids.insert(conflict->id()); | 123 found_ids.insert(conflict->TopLevel()->vreg()); |
122 } | 124 } |
123 return found_ids == ids; | 125 return found_ids == ids; |
124 } | 126 } |
125 | 127 |
126 | 128 |
127 TEST_F(CoalescedLiveRangesTest, VisitEmptyAllocations) { | 129 TEST_F(CoalescedLiveRangesTest, VisitEmptyAllocations) { |
128 LiveRange* range = TestRangeBuilder(zone()).Id(1).Build(1, 5); | 130 LiveRange* range = TestRangeBuilder(zone()).Id(1).Build(1, 5); |
129 ASSERT_TRUE(ranges().empty()); | 131 ASSERT_TRUE(ranges().empty()); |
130 ASSERT_TRUE(AllocationsAreValid()); | 132 ASSERT_TRUE(AllocationsAreValid()); |
131 ASSERT_TRUE(HasNoConflicts(range)); | 133 ASSERT_TRUE(HasNoConflicts(range)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 TestRangeBuilder(zone()).Id(3).Add(1, 8).Add(22, 25).Build(); | 302 TestRangeBuilder(zone()).Id(3).Add(1, 8).Add(22, 25).Build(); |
301 RemoveConflicts(query); | 303 RemoveConflicts(query); |
302 query = TestRangeBuilder(zone()).Id(4).Build(0, 60); | 304 query = TestRangeBuilder(zone()).Id(4).Build(0, 60); |
303 ASSERT_TRUE(ConflictsPreciselyWith(query, 2)); | 305 ASSERT_TRUE(ConflictsPreciselyWith(query, 2)); |
304 } | 306 } |
305 | 307 |
306 | 308 |
307 } // namespace compiler | 309 } // namespace compiler |
308 } // namespace internal | 310 } // namespace internal |
309 } // namespace v8 | 311 } // namespace v8 |
OLD | NEW |