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