OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_LIVE_RANGE_BUILDER_H_ |
| 6 #define V8_LIVE_RANGE_BUILDER_H_ |
| 7 |
| 8 #include "src/compiler/register-allocator.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 namespace compiler { |
| 13 |
| 14 |
| 15 // Utility offering shorthand syntax for building up a range by providing its ID |
| 16 // and pairs (start, end) specifying intervals. Circumvents current incomplete |
| 17 // support for C++ features such as instantiation lists, on OS X and Android. |
| 18 class TestRangeBuilder { |
| 19 public: |
| 20 explicit TestRangeBuilder(Zone* zone) : id_(-1), pairs_(), zone_(zone) {} |
| 21 |
| 22 TestRangeBuilder& Id(int id) { |
| 23 id_ = id; |
| 24 return *this; |
| 25 } |
| 26 TestRangeBuilder& Add(int start, int end) { |
| 27 pairs_.push_back({start, end}); |
| 28 return *this; |
| 29 } |
| 30 |
| 31 LiveRange* Build(int start, int end) { return Add(start, end).Build(); } |
| 32 |
| 33 LiveRange* Build() { |
| 34 TopLevelLiveRange* range = |
| 35 new (zone_) TopLevelLiveRange(id_, MachineType::kRepTagged); |
| 36 // Traverse the provided interval specifications backwards, because that is |
| 37 // what LiveRange expects. |
| 38 for (int i = static_cast<int>(pairs_.size()) - 1; i >= 0; --i) { |
| 39 Interval pair = pairs_[i]; |
| 40 LifetimePosition start = LifetimePosition::FromInt(pair.first); |
| 41 LifetimePosition end = LifetimePosition::FromInt(pair.second); |
| 42 CHECK(start < end); |
| 43 range->AddUseInterval(start, end, zone_); |
| 44 } |
| 45 |
| 46 pairs_.clear(); |
| 47 return range; |
| 48 } |
| 49 |
| 50 private: |
| 51 typedef std::pair<int, int> Interval; |
| 52 typedef std::vector<Interval> IntervalList; |
| 53 int id_; |
| 54 IntervalList pairs_; |
| 55 Zone* zone_; |
| 56 }; |
| 57 |
| 58 |
| 59 } // namespace compiler |
| 60 } // namespace internal |
| 61 } // namespace v8 |
| 62 |
| 63 #endif // V8_LIVE_RANGE_BUILDER_H_ |
OLD | NEW |