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_COALESCED_LIVE_RANGES_H_ |
| 6 #define V8_COALESCED_LIVE_RANGES_H_ |
| 7 |
| 8 #include "src/compiler/register-allocator.h" |
| 9 #include "src/zone-containers.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace compiler { |
| 14 |
| 15 |
| 16 class AllocationScheduler; |
| 17 |
| 18 |
| 19 // Collection of live ranges allocated to the same register. |
| 20 // It supports efficiently finding all conflicts for a given, non-allocated |
| 21 // range. See AllocatedInterval. |
| 22 // Allocated live ranges do not intersect. At most, individual use intervals |
| 23 // touch. We store, for a live range, an AllocatedInterval corresponding to each |
| 24 // of that range's UseIntervals. We keep the list of AllocatedIntervals sorted |
| 25 // by starts. Then, given the non-intersecting property, we know that |
| 26 // consecutive AllocatedIntervals have the property that the "smaller"'s end is |
| 27 // less or equal to the "larger"'s start. |
| 28 // This allows for quick (logarithmic complexity) identification of the first |
| 29 // AllocatedInterval to conflict with a given LiveRange, and then for efficient |
| 30 // traversal of conflicts. |
| 31 class CoalescedLiveRanges : public ZoneObject { |
| 32 public: |
| 33 explicit CoalescedLiveRanges(Zone* zone) : storage_(zone) {} |
| 34 void clear() { storage_.clear(); } |
| 35 |
| 36 bool empty() const { return storage_.empty(); } |
| 37 |
| 38 // Returns kInvalidWeight if there are no conflicts, or the largest weight of |
| 39 // a range conflicting with the given range. |
| 40 float GetMaximumConflictingWeight(const LiveRange* range) const; |
| 41 |
| 42 // Evicts all conflicts of the given range, and reschedules them with the |
| 43 // provided scheduler. |
| 44 void EvictAndRescheduleConflicts(LiveRange* range, |
| 45 AllocationScheduler* scheduler); |
| 46 |
| 47 // Allocates a range with a pre-calculated candidate weight. |
| 48 void AllocateRange(LiveRange* range); |
| 49 |
| 50 // TODO(mtrofin): remove this in favor of comprehensive unit tests. |
| 51 bool VerifyAllocationsAreValid() const; |
| 52 |
| 53 private: |
| 54 static const float kAllocatedRangeMultiplier; |
| 55 // Storage detail for CoalescedLiveRanges. |
| 56 struct AllocatedInterval { |
| 57 LifetimePosition start; |
| 58 LifetimePosition end; |
| 59 LiveRange* range; |
| 60 bool operator<(const AllocatedInterval& other) const { |
| 61 return start < other.start; |
| 62 } |
| 63 bool operator>(const AllocatedInterval& other) const { |
| 64 return start > other.start; |
| 65 } |
| 66 }; |
| 67 typedef ZoneSet<AllocatedInterval> IntervalStore; |
| 68 typedef IntervalStore::const_iterator interval_iterator; |
| 69 |
| 70 IntervalStore& storage() { return storage_; } |
| 71 const IntervalStore& storage() const { return storage_; } |
| 72 |
| 73 // Augment the weight of a range that is about to be allocated. |
| 74 static void UpdateWeightAtAllocation(LiveRange* range); |
| 75 |
| 76 // Reduce the weight of a range that has lost allocation. |
| 77 static void UpdateWeightAtEviction(LiveRange* range); |
| 78 |
| 79 // Intersection utilities. |
| 80 static bool Intersects(LifetimePosition a_start, LifetimePosition a_end, |
| 81 LifetimePosition b_start, LifetimePosition b_end) { |
| 82 return a_start < b_end && b_start < a_end; |
| 83 } |
| 84 static AllocatedInterval AsAllocatedInterval(LifetimePosition pos) { |
| 85 return {pos, LifetimePosition::Invalid(), nullptr}; |
| 86 } |
| 87 |
| 88 bool QueryIntersectsAllocatedInterval(const UseInterval* query, |
| 89 interval_iterator& pos) const { |
| 90 DCHECK(query != nullptr); |
| 91 return pos != storage().end() && |
| 92 Intersects(query->start(), query->end(), pos->start, pos->end); |
| 93 } |
| 94 |
| 95 void Remove(LiveRange* range); |
| 96 |
| 97 // Get the first interval intersecting query. Since the intervals are sorted, |
| 98 // subsequent intervals intersecting query follow. |
| 99 interval_iterator GetFirstConflict(const UseInterval* query) const; |
| 100 |
| 101 IntervalStore storage_; |
| 102 DISALLOW_COPY_AND_ASSIGN(CoalescedLiveRanges); |
| 103 }; |
| 104 |
| 105 |
| 106 } // namespace compiler |
| 107 } // namespace internal |
| 108 } // namespace v8 |
| 109 #endif // V8_COALESCED_LIVE_RANGES_H_ |
OLD | NEW |