| 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 #ifndef V8_REGISTER_ALLOCATOR_H_ | 5 #ifndef V8_REGISTER_ALLOCATOR_H_ |
| 6 #define V8_REGISTER_ALLOCATOR_H_ | 6 #define V8_REGISTER_ALLOCATOR_H_ |
| 7 | 7 |
| 8 #include "src/compiler/instruction.h" | 8 #include "src/compiler/instruction.h" |
| 9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 static LifetimePosition GapFromInstructionIndex(int index) { | 39 static LifetimePosition GapFromInstructionIndex(int index) { |
| 40 return LifetimePosition(index * kStep); | 40 return LifetimePosition(index * kStep); |
| 41 } | 41 } |
| 42 // Return the lifetime position that corresponds to the beginning of | 42 // Return the lifetime position that corresponds to the beginning of |
| 43 // the instruction with the given index. | 43 // the instruction with the given index. |
| 44 static LifetimePosition InstructionFromInstructionIndex(int index) { | 44 static LifetimePosition InstructionFromInstructionIndex(int index) { |
| 45 return LifetimePosition(index * kStep + kHalfStep); | 45 return LifetimePosition(index * kStep + kHalfStep); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Returns a numeric representation of this lifetime position. | 48 // Returns a numeric representation of this lifetime position. |
| 49 int Value() const { return value_; } | 49 int value() const { return value_; } |
| 50 | 50 |
| 51 // Returns the index of the instruction to which this lifetime position | 51 // Returns the index of the instruction to which this lifetime position |
| 52 // corresponds. | 52 // corresponds. |
| 53 int ToInstructionIndex() const { | 53 int ToInstructionIndex() const { |
| 54 DCHECK(IsValid()); | 54 DCHECK(IsValid()); |
| 55 return value_ / kStep; | 55 return value_ / kStep; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Returns true if this lifetime position corresponds to a START value | 58 // Returns true if this lifetime position corresponds to a START value |
| 59 bool IsStart() const { return (value_ & (kHalfStep - 1)) == 0; } | 59 bool IsStart() const { return (value_ & (kHalfStep - 1)) == 0; } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 | 71 |
| 72 // Returns the lifetime position for the current gap START. | 72 // Returns the lifetime position for the current gap START. |
| 73 LifetimePosition FullStart() const { | 73 LifetimePosition FullStart() const { |
| 74 DCHECK(IsValid()); | 74 DCHECK(IsValid()); |
| 75 return LifetimePosition(value_ & ~(kStep - 1)); | 75 return LifetimePosition(value_ & ~(kStep - 1)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Returns the lifetime position for the current END. | 78 // Returns the lifetime position for the current END. |
| 79 LifetimePosition End() const { | 79 LifetimePosition End() const { |
| 80 DCHECK(IsValid()); | 80 DCHECK(IsValid()); |
| 81 return LifetimePosition(Start().Value() + kHalfStep / 2); | 81 return LifetimePosition(Start().value_ + kHalfStep / 2); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Returns the lifetime position for the beginning of the next START. | 84 // Returns the lifetime position for the beginning of the next START. |
| 85 LifetimePosition NextStart() const { | 85 LifetimePosition NextStart() const { |
| 86 DCHECK(IsValid()); | 86 DCHECK(IsValid()); |
| 87 return LifetimePosition(Start().Value() + kHalfStep); | 87 return LifetimePosition(Start().value_ + kHalfStep); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Returns the lifetime position for the beginning of the next gap START. | 90 // Returns the lifetime position for the beginning of the next gap START. |
| 91 LifetimePosition NextFullStart() const { | 91 LifetimePosition NextFullStart() const { |
| 92 DCHECK(IsValid()); | 92 DCHECK(IsValid()); |
| 93 return LifetimePosition(FullStart().Value() + kStep); | 93 return LifetimePosition(FullStart().value_ + kStep); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Returns the lifetime position for the beginning of the previous START. | 96 // Returns the lifetime position for the beginning of the previous START. |
| 97 LifetimePosition PrevStart() const { | 97 LifetimePosition PrevStart() const { |
| 98 DCHECK(IsValid()); | 98 DCHECK(IsValid()); |
| 99 DCHECK(value_ >= kHalfStep); | 99 DCHECK(value_ >= kHalfStep); |
| 100 return LifetimePosition(Start().Value() - kHalfStep); | 100 return LifetimePosition(Start().value_ - kHalfStep); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Constructs the lifetime position which does not correspond to any | 103 // Constructs the lifetime position which does not correspond to any |
| 104 // instruction. | 104 // instruction. |
| 105 LifetimePosition() : value_(-1) {} | 105 LifetimePosition() : value_(-1) {} |
| 106 | 106 |
| 107 // Returns true if this lifetime positions corrensponds to some | 107 // Returns true if this lifetime positions corrensponds to some |
| 108 // instruction. | 108 // instruction. |
| 109 bool IsValid() const { return value_ != -1; } | 109 bool IsValid() const { return value_ != -1; } |
| 110 | 110 |
| 111 bool operator<(const LifetimePosition& that) const { |
| 112 return this->value_ < that.value_; |
| 113 } |
| 114 |
| 115 bool operator<=(const LifetimePosition& that) const { |
| 116 return this->value_ <= that.value_; |
| 117 } |
| 118 |
| 119 bool operator==(const LifetimePosition& that) const { |
| 120 return this->value_ == that.value_; |
| 121 } |
| 122 |
| 123 bool operator!=(const LifetimePosition& that) const { |
| 124 return this->value_ != that.value_; |
| 125 } |
| 126 |
| 127 bool operator>(const LifetimePosition& that) const { |
| 128 return this->value_ > that.value_; |
| 129 } |
| 130 |
| 131 bool operator>=(const LifetimePosition& that) const { |
| 132 return this->value_ >= that.value_; |
| 133 } |
| 134 |
| 111 static inline LifetimePosition Invalid() { return LifetimePosition(); } | 135 static inline LifetimePosition Invalid() { return LifetimePosition(); } |
| 112 | 136 |
| 113 static inline LifetimePosition MaxPosition() { | 137 static inline LifetimePosition MaxPosition() { |
| 114 // We have to use this kind of getter instead of static member due to | 138 // We have to use this kind of getter instead of static member due to |
| 115 // crash bug in GDB. | 139 // crash bug in GDB. |
| 116 return LifetimePosition(kMaxInt); | 140 return LifetimePosition(kMaxInt); |
| 117 } | 141 } |
| 118 | 142 |
| 119 private: | 143 private: |
| 120 static const int kHalfStep = 2; | 144 static const int kHalfStep = 2; |
| 121 static const int kStep = 2 * kHalfStep; | 145 static const int kStep = 2 * kHalfStep; |
| 122 | 146 |
| 123 // Code relies on kStep and kHalfStep being a power of two. | 147 // Code relies on kStep and kHalfStep being a power of two. |
| 124 STATIC_ASSERT(IS_POWER_OF_TWO(kHalfStep)); | 148 STATIC_ASSERT(IS_POWER_OF_TWO(kHalfStep)); |
| 125 | 149 |
| 126 explicit LifetimePosition(int value) : value_(value) {} | 150 explicit LifetimePosition(int value) : value_(value) {} |
| 127 | 151 |
| 128 int value_; | 152 int value_; |
| 129 }; | 153 }; |
| 130 | 154 |
| 131 | 155 |
| 132 // Representation of the non-empty interval [start,end[. | 156 // Representation of the non-empty interval [start,end[. |
| 133 class UseInterval final : public ZoneObject { | 157 class UseInterval final : public ZoneObject { |
| 134 public: | 158 public: |
| 135 UseInterval(LifetimePosition start, LifetimePosition end) | 159 UseInterval(LifetimePosition start, LifetimePosition end) |
| 136 : start_(start), end_(end), next_(nullptr) { | 160 : start_(start), end_(end), next_(nullptr) { |
| 137 DCHECK(start.Value() < end.Value()); | 161 DCHECK(start < end); |
| 138 } | 162 } |
| 139 | 163 |
| 140 LifetimePosition start() const { return start_; } | 164 LifetimePosition start() const { return start_; } |
| 141 void set_start(LifetimePosition start) { start_ = start; } | 165 void set_start(LifetimePosition start) { start_ = start; } |
| 142 LifetimePosition end() const { return end_; } | 166 LifetimePosition end() const { return end_; } |
| 143 void set_end(LifetimePosition end) { end_ = end; } | 167 void set_end(LifetimePosition end) { end_ = end; } |
| 144 UseInterval* next() const { return next_; } | 168 UseInterval* next() const { return next_; } |
| 145 void set_next(UseInterval* next) { next_ = next; } | 169 void set_next(UseInterval* next) { next_ = next; } |
| 146 | 170 |
| 147 // Split this interval at the given position without effecting the | 171 // Split this interval at the given position without effecting the |
| 148 // live range that owns it. The interval must contain the position. | 172 // live range that owns it. The interval must contain the position. |
| 149 UseInterval* SplitAt(LifetimePosition pos, Zone* zone); | 173 UseInterval* SplitAt(LifetimePosition pos, Zone* zone); |
| 150 | 174 |
| 151 // If this interval intersects with other return smallest position | 175 // If this interval intersects with other return smallest position |
| 152 // that belongs to both of them. | 176 // that belongs to both of them. |
| 153 LifetimePosition Intersect(const UseInterval* other) const { | 177 LifetimePosition Intersect(const UseInterval* other) const { |
| 154 if (other->start().Value() < start_.Value()) return other->Intersect(this); | 178 if (other->start() < start_) return other->Intersect(this); |
| 155 if (other->start().Value() < end_.Value()) return other->start(); | 179 if (other->start() < end_) return other->start(); |
| 156 return LifetimePosition::Invalid(); | 180 return LifetimePosition::Invalid(); |
| 157 } | 181 } |
| 158 | 182 |
| 159 bool Contains(LifetimePosition point) const { | 183 bool Contains(LifetimePosition point) const { |
| 160 return start_.Value() <= point.Value() && point.Value() < end_.Value(); | 184 return start_ <= point && point < end_; |
| 161 } | 185 } |
| 162 | 186 |
| 163 private: | 187 private: |
| 164 LifetimePosition start_; | 188 LifetimePosition start_; |
| 165 LifetimePosition end_; | 189 LifetimePosition end_; |
| 166 UseInterval* next_; | 190 UseInterval* next_; |
| 167 | 191 |
| 168 DISALLOW_COPY_AND_ASSIGN(UseInterval); | 192 DISALLOW_COPY_AND_ASSIGN(UseInterval); |
| 169 }; | 193 }; |
| 170 | 194 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 RegisterAllocationData* const data_; | 816 RegisterAllocationData* const data_; |
| 793 | 817 |
| 794 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); | 818 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); |
| 795 }; | 819 }; |
| 796 | 820 |
| 797 } // namespace compiler | 821 } // namespace compiler |
| 798 } // namespace internal | 822 } // namespace internal |
| 799 } // namespace v8 | 823 } // namespace v8 |
| 800 | 824 |
| 801 #endif // V8_REGISTER_ALLOCATOR_H_ | 825 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |