| 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/ostreams.h" | 9 #include "src/ostreams.h" |
| 10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 const InstructionOperand& spill_op); | 421 const InstructionOperand& spill_op); |
| 422 void SetUseHints(int register_index); | 422 void SetUseHints(int register_index); |
| 423 void UnsetUseHints() { SetUseHints(kUnassignedRegister); } | 423 void UnsetUseHints() { SetUseHints(kUnassignedRegister); } |
| 424 | 424 |
| 425 struct SpillAtDefinitionList; | 425 struct SpillAtDefinitionList; |
| 426 | 426 |
| 427 SpillAtDefinitionList* spills_at_definition() const { | 427 SpillAtDefinitionList* spills_at_definition() const { |
| 428 return spills_at_definition_; | 428 return spills_at_definition_; |
| 429 } | 429 } |
| 430 | 430 |
| 431 // Used solely by the Greedy Allocator: |
| 432 unsigned GetSize(); |
| 433 float weight() const { return weight_; } |
| 434 void set_weight(float weight) { weight_ = weight; } |
| 435 |
| 436 static const int kInvalidSize = -1; |
| 437 static const float kInvalidWeight; |
| 438 static const float kMaxWeight; |
| 439 |
| 431 private: | 440 private: |
| 432 void set_spill_type(SpillType value) { | 441 void set_spill_type(SpillType value) { |
| 433 bits_ = SpillTypeField::update(bits_, value); | 442 bits_ = SpillTypeField::update(bits_, value); |
| 434 } | 443 } |
| 435 | 444 |
| 436 void set_spilled(bool value) { bits_ = SpilledField::update(bits_, value); } | 445 void set_spilled(bool value) { bits_ = SpilledField::update(bits_, value); } |
| 437 | 446 |
| 438 UseInterval* FirstSearchIntervalForPosition(LifetimePosition position) const; | 447 UseInterval* FirstSearchIntervalForPosition(LifetimePosition position) const; |
| 439 void AdvanceLastProcessedMarker(UseInterval* to_start_of, | 448 void AdvanceLastProcessedMarker(UseInterval* to_start_of, |
| 440 LifetimePosition but_not_past) const; | 449 LifetimePosition but_not_past) const; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 461 SpillRange* spill_range_; | 470 SpillRange* spill_range_; |
| 462 }; | 471 }; |
| 463 SpillAtDefinitionList* spills_at_definition_; | 472 SpillAtDefinitionList* spills_at_definition_; |
| 464 // This is used as a cache, it doesn't affect correctness. | 473 // This is used as a cache, it doesn't affect correctness. |
| 465 mutable UseInterval* current_interval_; | 474 mutable UseInterval* current_interval_; |
| 466 // This is used as a cache, it doesn't affect correctness. | 475 // This is used as a cache, it doesn't affect correctness. |
| 467 mutable UsePosition* last_processed_use_; | 476 mutable UsePosition* last_processed_use_; |
| 468 // This is used as a cache, it's invalid outside of BuildLiveRanges. | 477 // This is used as a cache, it's invalid outside of BuildLiveRanges. |
| 469 mutable UsePosition* current_hint_position_; | 478 mutable UsePosition* current_hint_position_; |
| 470 | 479 |
| 480 // greedy: the number of LifetimePositions covered by this range. Used to |
| 481 // prioritize selecting live ranges for register assignment, as well as |
| 482 // in weight calculations. |
| 483 int size_; |
| 484 |
| 485 // greedy: a metric for resolving conflicts between ranges with an assigned |
| 486 // register and ranges that intersect them and need a register. |
| 487 float weight_; |
| 471 DISALLOW_COPY_AND_ASSIGN(LiveRange); | 488 DISALLOW_COPY_AND_ASSIGN(LiveRange); |
| 472 }; | 489 }; |
| 473 | 490 |
| 474 | 491 |
| 475 struct PrintableLiveRange { | 492 struct PrintableLiveRange { |
| 476 const RegisterConfiguration* register_configuration_; | 493 const RegisterConfiguration* register_configuration_; |
| 477 const LiveRange* range_; | 494 const LiveRange* range_; |
| 478 }; | 495 }; |
| 479 | 496 |
| 480 | 497 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 LifetimePosition end); | 780 LifetimePosition end); |
| 764 | 781 |
| 765 void Spill(LiveRange* range); | 782 void Spill(LiveRange* range); |
| 766 | 783 |
| 767 // If we are trying to spill a range inside the loop try to | 784 // If we are trying to spill a range inside the loop try to |
| 768 // hoist spill position out to the point just before the loop. | 785 // hoist spill position out to the point just before the loop. |
| 769 LifetimePosition FindOptimalSpillingPos(LiveRange* range, | 786 LifetimePosition FindOptimalSpillingPos(LiveRange* range, |
| 770 LifetimePosition pos); | 787 LifetimePosition pos); |
| 771 | 788 |
| 772 const ZoneVector<LiveRange*>& GetFixedRegisters() const; | 789 const ZoneVector<LiveRange*>& GetFixedRegisters() const; |
| 790 const char* RegisterName(int allocation_index) const; |
| 773 | 791 |
| 774 private: | 792 private: |
| 775 RegisterAllocationData* const data_; | 793 RegisterAllocationData* const data_; |
| 776 const RegisterKind mode_; | 794 const RegisterKind mode_; |
| 777 const int num_registers_; | 795 const int num_registers_; |
| 778 | 796 |
| 779 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); | 797 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); |
| 780 }; | 798 }; |
| 781 | 799 |
| 782 | 800 |
| 783 class LinearScanAllocator final : public RegisterAllocator { | 801 class LinearScanAllocator final : public RegisterAllocator { |
| 784 public: | 802 public: |
| 785 LinearScanAllocator(RegisterAllocationData* data, RegisterKind kind, | 803 LinearScanAllocator(RegisterAllocationData* data, RegisterKind kind, |
| 786 Zone* local_zone); | 804 Zone* local_zone); |
| 787 | 805 |
| 788 // Phase 4: compute register assignments. | 806 // Phase 4: compute register assignments. |
| 789 void AllocateRegisters(); | 807 void AllocateRegisters(); |
| 790 | 808 |
| 791 private: | 809 private: |
| 792 const char* RegisterName(int allocation_index) const; | |
| 793 | |
| 794 ZoneVector<LiveRange*>& unhandled_live_ranges() { | 810 ZoneVector<LiveRange*>& unhandled_live_ranges() { |
| 795 return unhandled_live_ranges_; | 811 return unhandled_live_ranges_; |
| 796 } | 812 } |
| 797 ZoneVector<LiveRange*>& active_live_ranges() { return active_live_ranges_; } | 813 ZoneVector<LiveRange*>& active_live_ranges() { return active_live_ranges_; } |
| 798 ZoneVector<LiveRange*>& inactive_live_ranges() { | 814 ZoneVector<LiveRange*>& inactive_live_ranges() { |
| 799 return inactive_live_ranges_; | 815 return inactive_live_ranges_; |
| 800 } | 816 } |
| 801 | 817 |
| 802 void SetLiveRangeAssignedRegister(LiveRange* range, int reg); | 818 void SetLiveRangeAssignedRegister(LiveRange* range, int reg); |
| 803 | 819 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 RegisterAllocationData* const data_; | 936 RegisterAllocationData* const data_; |
| 921 | 937 |
| 922 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); | 938 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); |
| 923 }; | 939 }; |
| 924 | 940 |
| 925 } // namespace compiler | 941 } // namespace compiler |
| 926 } // namespace internal | 942 } // namespace internal |
| 927 } // namespace v8 | 943 } // namespace v8 |
| 928 | 944 |
| 929 #endif // V8_REGISTER_ALLOCATOR_H_ | 945 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |