| 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 14 matching lines...) Expand all Loading... |
| 25 // [[START, END], [START, END]] | 25 // [[START, END], [START, END]] |
| 26 // | 26 // |
| 27 // Where the first half position corresponds to | 27 // Where the first half position corresponds to |
| 28 // | 28 // |
| 29 // [GapPosition::START, GapPosition::END] | 29 // [GapPosition::START, GapPosition::END] |
| 30 // | 30 // |
| 31 // and the second half position corresponds to | 31 // and the second half position corresponds to |
| 32 // | 32 // |
| 33 // [Lifetime::USED_AT_START, Lifetime::USED_AT_END] | 33 // [Lifetime::USED_AT_START, Lifetime::USED_AT_END] |
| 34 // | 34 // |
| 35 class LifetimePosition FINAL { | 35 class LifetimePosition final { |
| 36 public: | 36 public: |
| 37 // Return the lifetime position that corresponds to the beginning of | 37 // Return the lifetime position that corresponds to the beginning of |
| 38 // the gap with the given index. | 38 // the gap with the given index. |
| 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); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Code relies on kStep and kHalfStep being a power of two. | 123 // Code relies on kStep and kHalfStep being a power of two. |
| 124 STATIC_ASSERT(IS_POWER_OF_TWO(kHalfStep)); | 124 STATIC_ASSERT(IS_POWER_OF_TWO(kHalfStep)); |
| 125 | 125 |
| 126 explicit LifetimePosition(int value) : value_(value) {} | 126 explicit LifetimePosition(int value) : value_(value) {} |
| 127 | 127 |
| 128 int value_; | 128 int value_; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 | 131 |
| 132 // Representation of the non-empty interval [start,end[. | 132 // Representation of the non-empty interval [start,end[. |
| 133 class UseInterval FINAL : public ZoneObject { | 133 class UseInterval final : public ZoneObject { |
| 134 public: | 134 public: |
| 135 UseInterval(LifetimePosition start, LifetimePosition end) | 135 UseInterval(LifetimePosition start, LifetimePosition end) |
| 136 : start_(start), end_(end), next_(nullptr) { | 136 : start_(start), end_(end), next_(nullptr) { |
| 137 DCHECK(start.Value() < end.Value()); | 137 DCHECK(start.Value() < end.Value()); |
| 138 } | 138 } |
| 139 | 139 |
| 140 LifetimePosition start() const { return start_; } | 140 LifetimePosition start() const { return start_; } |
| 141 LifetimePosition end() const { return end_; } | 141 LifetimePosition end() const { return end_; } |
| 142 UseInterval* next() const { return next_; } | 142 UseInterval* next() const { return next_; } |
| 143 | 143 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 DISALLOW_COPY_AND_ASSIGN(UseInterval); | 168 DISALLOW_COPY_AND_ASSIGN(UseInterval); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 | 171 |
| 172 enum class UsePositionType : uint8_t { kAny, kRequiresRegister, kRequiresSlot }; | 172 enum class UsePositionType : uint8_t { kAny, kRequiresRegister, kRequiresSlot }; |
| 173 | 173 |
| 174 | 174 |
| 175 // Representation of a use position. | 175 // Representation of a use position. |
| 176 class UsePosition FINAL : public ZoneObject { | 176 class UsePosition final : public ZoneObject { |
| 177 public: | 177 public: |
| 178 UsePosition(LifetimePosition pos, InstructionOperand* operand, | 178 UsePosition(LifetimePosition pos, InstructionOperand* operand, |
| 179 InstructionOperand* hint); | 179 InstructionOperand* hint); |
| 180 | 180 |
| 181 InstructionOperand* operand() const { return operand_; } | 181 InstructionOperand* operand() const { return operand_; } |
| 182 bool HasOperand() const { return operand_ != nullptr; } | 182 bool HasOperand() const { return operand_ != nullptr; } |
| 183 | 183 |
| 184 InstructionOperand* hint() const { return hint_; } | 184 InstructionOperand* hint() const { return hint_; } |
| 185 bool HasHint() const; | 185 bool HasHint() const; |
| 186 bool RegisterIsBeneficial() const { | 186 bool RegisterIsBeneficial() const { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 205 uint8_t flags_; | 205 uint8_t flags_; |
| 206 | 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(UsePosition); | 207 DISALLOW_COPY_AND_ASSIGN(UsePosition); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 class SpillRange; | 210 class SpillRange; |
| 211 | 211 |
| 212 | 212 |
| 213 // Representation of SSA values' live ranges as a collection of (continuous) | 213 // Representation of SSA values' live ranges as a collection of (continuous) |
| 214 // intervals over the instruction ordering. | 214 // intervals over the instruction ordering. |
| 215 class LiveRange FINAL : public ZoneObject { | 215 class LiveRange final : public ZoneObject { |
| 216 public: | 216 public: |
| 217 static const int kInvalidAssignment = 0x7fffffff; | 217 static const int kInvalidAssignment = 0x7fffffff; |
| 218 | 218 |
| 219 LiveRange(int id, Zone* zone); | 219 LiveRange(int id, Zone* zone); |
| 220 | 220 |
| 221 UseInterval* first_interval() const { return first_interval_; } | 221 UseInterval* first_interval() const { return first_interval_; } |
| 222 UsePosition* first_pos() const { return first_pos_; } | 222 UsePosition* first_pos() const { return first_pos_; } |
| 223 LiveRange* parent() const { return parent_; } | 223 LiveRange* parent() const { return parent_; } |
| 224 LiveRange* TopLevel() { return (parent_ == nullptr) ? this : parent_; } | 224 LiveRange* TopLevel() { return (parent_ == nullptr) ? this : parent_; } |
| 225 const LiveRange* TopLevel() const { | 225 const LiveRange* TopLevel() const { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 SpillRange* spill_range_; | 380 SpillRange* spill_range_; |
| 381 }; | 381 }; |
| 382 SpillAtDefinitionList* spills_at_definition_; | 382 SpillAtDefinitionList* spills_at_definition_; |
| 383 | 383 |
| 384 friend class RegisterAllocator; // Assigns to kind_. | 384 friend class RegisterAllocator; // Assigns to kind_. |
| 385 | 385 |
| 386 DISALLOW_COPY_AND_ASSIGN(LiveRange); | 386 DISALLOW_COPY_AND_ASSIGN(LiveRange); |
| 387 }; | 387 }; |
| 388 | 388 |
| 389 | 389 |
| 390 class SpillRange FINAL : public ZoneObject { | 390 class SpillRange final : public ZoneObject { |
| 391 public: | 391 public: |
| 392 SpillRange(LiveRange* range, Zone* zone); | 392 SpillRange(LiveRange* range, Zone* zone); |
| 393 | 393 |
| 394 UseInterval* interval() const { return use_interval_; } | 394 UseInterval* interval() const { return use_interval_; } |
| 395 RegisterKind Kind() const { return live_ranges_[0]->Kind(); } | 395 RegisterKind Kind() const { return live_ranges_[0]->Kind(); } |
| 396 bool IsEmpty() const { return live_ranges_.empty(); } | 396 bool IsEmpty() const { return live_ranges_.empty(); } |
| 397 bool TryMerge(SpillRange* other); | 397 bool TryMerge(SpillRange* other); |
| 398 void SetOperand(AllocatedOperand* op); | 398 void SetOperand(AllocatedOperand* op); |
| 399 | 399 |
| 400 private: | 400 private: |
| 401 LifetimePosition End() const { return end_position_; } | 401 LifetimePosition End() const { return end_position_; } |
| 402 ZoneVector<LiveRange*>& live_ranges() { return live_ranges_; } | 402 ZoneVector<LiveRange*>& live_ranges() { return live_ranges_; } |
| 403 bool IsIntersectingWith(SpillRange* other) const; | 403 bool IsIntersectingWith(SpillRange* other) const; |
| 404 // Merge intervals, making sure the use intervals are sorted | 404 // Merge intervals, making sure the use intervals are sorted |
| 405 void MergeDisjointIntervals(UseInterval* other); | 405 void MergeDisjointIntervals(UseInterval* other); |
| 406 | 406 |
| 407 ZoneVector<LiveRange*> live_ranges_; | 407 ZoneVector<LiveRange*> live_ranges_; |
| 408 UseInterval* use_interval_; | 408 UseInterval* use_interval_; |
| 409 LifetimePosition end_position_; | 409 LifetimePosition end_position_; |
| 410 | 410 |
| 411 DISALLOW_COPY_AND_ASSIGN(SpillRange); | 411 DISALLOW_COPY_AND_ASSIGN(SpillRange); |
| 412 }; | 412 }; |
| 413 | 413 |
| 414 | 414 |
| 415 class RegisterAllocator FINAL : public ZoneObject { | 415 class RegisterAllocator final : public ZoneObject { |
| 416 public: | 416 public: |
| 417 explicit RegisterAllocator(const RegisterConfiguration* config, | 417 explicit RegisterAllocator(const RegisterConfiguration* config, |
| 418 Zone* local_zone, Frame* frame, | 418 Zone* local_zone, Frame* frame, |
| 419 InstructionSequence* code, | 419 InstructionSequence* code, |
| 420 const char* debug_name = nullptr); | 420 const char* debug_name = nullptr); |
| 421 | 421 |
| 422 const ZoneVector<LiveRange*>& live_ranges() const { return live_ranges_; } | 422 const ZoneVector<LiveRange*>& live_ranges() const { return live_ranges_; } |
| 423 const ZoneVector<LiveRange*>& fixed_live_ranges() const { | 423 const ZoneVector<LiveRange*>& fixed_live_ranges() const { |
| 424 return fixed_live_ranges_; | 424 return fixed_live_ranges_; |
| 425 } | 425 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 #endif | 661 #endif |
| 662 | 662 |
| 663 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); | 663 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); |
| 664 }; | 664 }; |
| 665 | 665 |
| 666 } // namespace compiler | 666 } // namespace compiler |
| 667 } // namespace internal | 667 } // namespace internal |
| 668 } // namespace v8 | 668 } // namespace v8 |
| 669 | 669 |
| 670 #endif // V8_REGISTER_ALLOCATOR_H_ | 670 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |