| 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/compiler/live-range-builder.h" |
| 6 #include "test/unittests/test-utils.h" | 7 #include "test/unittests/test-utils.h" |
| 7 | 8 |
| 8 namespace v8 { | 9 namespace v8 { |
| 9 namespace internal { | 10 namespace internal { |
| 10 namespace compiler { | 11 namespace compiler { |
| 11 | 12 |
| 12 | 13 |
| 13 // Utility offering shorthand syntax for building up a range by providing its ID | |
| 14 // and pairs (start, end) specifying intervals. Circumvents current incomplete | |
| 15 // support for C++ features such as instantiation lists, on OS X and Android. | |
| 16 class TestRangeBuilder { | |
| 17 public: | |
| 18 explicit TestRangeBuilder(Zone* zone) : id_(-1), pairs_(), zone_(zone) {} | |
| 19 | |
| 20 TestRangeBuilder& Id(int id) { | |
| 21 id_ = id; | |
| 22 return *this; | |
| 23 } | |
| 24 TestRangeBuilder& Add(int start, int end) { | |
| 25 pairs_.push_back({start, end}); | |
| 26 return *this; | |
| 27 } | |
| 28 | |
| 29 LiveRange* Build(int start, int end) { return Add(start, end).Build(); } | |
| 30 | |
| 31 LiveRange* Build() { | |
| 32 TopLevelLiveRange* range = | |
| 33 new (zone_) TopLevelLiveRange(id_, MachineType::kRepTagged); | |
| 34 // Traverse the provided interval specifications backwards, because that is | |
| 35 // what LiveRange expects. | |
| 36 for (int i = static_cast<int>(pairs_.size()) - 1; i >= 0; --i) { | |
| 37 Interval pair = pairs_[i]; | |
| 38 LifetimePosition start = LifetimePosition::FromInt(pair.first); | |
| 39 LifetimePosition end = LifetimePosition::FromInt(pair.second); | |
| 40 CHECK(start < end); | |
| 41 range->AddUseInterval(start, end, zone_); | |
| 42 } | |
| 43 | |
| 44 pairs_.clear(); | |
| 45 return range; | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 typedef std::pair<int, int> Interval; | |
| 50 typedef std::vector<Interval> IntervalList; | |
| 51 int id_; | |
| 52 IntervalList pairs_; | |
| 53 Zone* zone_; | |
| 54 }; | |
| 55 | |
| 56 | |
| 57 class CoalescedLiveRangesTest : public TestWithZone { | 14 class CoalescedLiveRangesTest : public TestWithZone { |
| 58 public: | 15 public: |
| 59 CoalescedLiveRangesTest() : TestWithZone(), ranges_(zone()) {} | 16 CoalescedLiveRangesTest() : TestWithZone(), ranges_(zone()) {} |
| 60 bool HasNoConflicts(const LiveRange* range); | 17 bool HasNoConflicts(const LiveRange* range); |
| 61 bool ConflictsPreciselyWith(const LiveRange* range, int id); | 18 bool ConflictsPreciselyWith(const LiveRange* range, int id); |
| 62 bool ConflictsPreciselyWith(const LiveRange* range, int id1, int id2); | 19 bool ConflictsPreciselyWith(const LiveRange* range, int id1, int id2); |
| 63 | 20 |
| 64 CoalescedLiveRanges& ranges() { return ranges_; } | 21 CoalescedLiveRanges& ranges() { return ranges_; } |
| 65 const CoalescedLiveRanges& ranges() const { return ranges_; } | 22 const CoalescedLiveRanges& ranges() const { return ranges_; } |
| 66 bool AllocationsAreValid() const; | 23 bool AllocationsAreValid() const; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 TestRangeBuilder(zone()).Id(3).Add(1, 8).Add(22, 25).Build(); | 259 TestRangeBuilder(zone()).Id(3).Add(1, 8).Add(22, 25).Build(); |
| 303 RemoveConflicts(query); | 260 RemoveConflicts(query); |
| 304 query = TestRangeBuilder(zone()).Id(4).Build(0, 60); | 261 query = TestRangeBuilder(zone()).Id(4).Build(0, 60); |
| 305 ASSERT_TRUE(ConflictsPreciselyWith(query, 2)); | 262 ASSERT_TRUE(ConflictsPreciselyWith(query, 2)); |
| 306 } | 263 } |
| 307 | 264 |
| 308 | 265 |
| 309 } // namespace compiler | 266 } // namespace compiler |
| 310 } // namespace internal | 267 } // namespace internal |
| 311 } // namespace v8 | 268 } // namespace v8 |
| OLD | NEW |