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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 return code()->IsReference(virtual_register); | 600 return code()->IsReference(virtual_register); |
601 } | 601 } |
602 | 602 |
603 bool ExistsUseWithoutDefinition(); | 603 bool ExistsUseWithoutDefinition(); |
604 | 604 |
605 void MarkAllocated(RegisterKind kind, int index); | 605 void MarkAllocated(RegisterKind kind, int index); |
606 | 606 |
607 PhiMapValue* InitializePhiMap(const InstructionBlock* block, | 607 PhiMapValue* InitializePhiMap(const InstructionBlock* block, |
608 PhiInstruction* phi); | 608 PhiInstruction* phi); |
609 PhiMapValue* GetPhiMapValueFor(int virtual_register); | 609 PhiMapValue* GetPhiMapValueFor(int virtual_register); |
| 610 bool IsBlockBoundary(LifetimePosition pos) const; |
610 | 611 |
611 private: | 612 private: |
612 Zone* const allocation_zone_; | 613 Zone* const allocation_zone_; |
613 Frame* const frame_; | 614 Frame* const frame_; |
614 InstructionSequence* const code_; | 615 InstructionSequence* const code_; |
615 const char* const debug_name_; | 616 const char* const debug_name_; |
616 const RegisterConfiguration* const config_; | 617 const RegisterConfiguration* const config_; |
617 PhiMap phi_map_; | 618 PhiMap phi_map_; |
618 ZoneVector<BitVector*> live_in_sets_; | 619 ZoneVector<BitVector*> live_in_sets_; |
619 ZoneVector<LiveRange*> live_ranges_; | 620 ZoneVector<LiveRange*> live_ranges_; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 LifetimePosition FindOptimalSplitPos(LifetimePosition start, | 762 LifetimePosition FindOptimalSplitPos(LifetimePosition start, |
762 LifetimePosition end); | 763 LifetimePosition end); |
763 | 764 |
764 void Spill(LiveRange* range); | 765 void Spill(LiveRange* range); |
765 | 766 |
766 // If we are trying to spill a range inside the loop try to | 767 // If we are trying to spill a range inside the loop try to |
767 // hoist spill position out to the point just before the loop. | 768 // hoist spill position out to the point just before the loop. |
768 LifetimePosition FindOptimalSpillingPos(LiveRange* range, | 769 LifetimePosition FindOptimalSpillingPos(LiveRange* range, |
769 LifetimePosition pos); | 770 LifetimePosition pos); |
770 | 771 |
| 772 const ZoneVector<LiveRange*>& GetFixedRegisters() const; |
| 773 |
771 private: | 774 private: |
772 RegisterAllocationData* const data_; | 775 RegisterAllocationData* const data_; |
773 const RegisterKind mode_; | 776 const RegisterKind mode_; |
774 const int num_registers_; | 777 const int num_registers_; |
775 | 778 |
776 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); | 779 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); |
777 }; | 780 }; |
778 | 781 |
779 | 782 |
780 class LinearScanAllocator final : public RegisterAllocator { | 783 class LinearScanAllocator final : public RegisterAllocator { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 ZoneVector<LiveRange*> active_live_ranges_; | 836 ZoneVector<LiveRange*> active_live_ranges_; |
834 ZoneVector<LiveRange*> inactive_live_ranges_; | 837 ZoneVector<LiveRange*> inactive_live_ranges_; |
835 | 838 |
836 #ifdef DEBUG | 839 #ifdef DEBUG |
837 LifetimePosition allocation_finger_; | 840 LifetimePosition allocation_finger_; |
838 #endif | 841 #endif |
839 | 842 |
840 DISALLOW_COPY_AND_ASSIGN(LinearScanAllocator); | 843 DISALLOW_COPY_AND_ASSIGN(LinearScanAllocator); |
841 }; | 844 }; |
842 | 845 |
843 class CoalescedLiveRanges; | |
844 | |
845 | |
846 // A variant of the LLVM Greedy Register Allocator. See | |
847 // http://blog.llvm.org/2011/09/greedy-register-allocation-in-llvm-30.html | |
848 class GreedyAllocator final : public RegisterAllocator { | |
849 public: | |
850 explicit GreedyAllocator(RegisterAllocationData* data, RegisterKind kind, | |
851 Zone* local_zone); | |
852 | |
853 void AllocateRegisters(); | |
854 | |
855 private: | |
856 LifetimePosition GetSplittablePos(LifetimePosition pos); | |
857 const RegisterConfiguration* config() const { return data()->config(); } | |
858 Zone* local_zone() const { return local_zone_; } | |
859 bool TryReuseSpillForPhi(LiveRange* range); | |
860 int GetHintedRegister(LiveRange* range); | |
861 | |
862 typedef ZonePriorityQueue<std::pair<unsigned, LiveRange*>> PQueue; | |
863 | |
864 unsigned GetLiveRangeSize(LiveRange* range); | |
865 void Enqueue(LiveRange* range); | |
866 | |
867 void Evict(LiveRange* range); | |
868 float CalculateSpillWeight(LiveRange* range); | |
869 float CalculateMaxSpillWeight(const ZoneSet<LiveRange*>& ranges); | |
870 | |
871 | |
872 bool TryAllocate(LiveRange* current, ZoneSet<LiveRange*>* conflicting); | |
873 bool TryAllocatePhysicalRegister(unsigned reg_id, LiveRange* range, | |
874 ZoneSet<LiveRange*>* conflicting); | |
875 bool HandleSpillOperands(LiveRange* range); | |
876 void AllocateBlockedRange(LiveRange* current, LifetimePosition pos, | |
877 bool spill); | |
878 | |
879 LiveRange* SpillBetweenUntil(LiveRange* range, LifetimePosition start, | |
880 LifetimePosition until, LifetimePosition end); | |
881 void AssignRangeToRegister(int reg_id, LiveRange* range); | |
882 | |
883 LifetimePosition FindProgressingSplitPosition(LiveRange* range, | |
884 bool* is_spill_pos); | |
885 | |
886 Zone* local_zone_; | |
887 ZoneVector<CoalescedLiveRanges*> allocations_; | |
888 PQueue queue_; | |
889 DISALLOW_COPY_AND_ASSIGN(GreedyAllocator); | |
890 }; | |
891 | |
892 | 846 |
893 class SpillSlotLocator final : public ZoneObject { | 847 class SpillSlotLocator final : public ZoneObject { |
894 public: | 848 public: |
895 explicit SpillSlotLocator(RegisterAllocationData* data); | 849 explicit SpillSlotLocator(RegisterAllocationData* data); |
896 | 850 |
897 void LocateSpillSlots(); | 851 void LocateSpillSlots(); |
898 | 852 |
899 private: | 853 private: |
900 RegisterAllocationData* data() const { return data_; } | 854 RegisterAllocationData* data() const { return data_; } |
901 | 855 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 RegisterAllocationData* const data_; | 920 RegisterAllocationData* const data_; |
967 | 921 |
968 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); | 922 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); |
969 }; | 923 }; |
970 | 924 |
971 } // namespace compiler | 925 } // namespace compiler |
972 } // namespace internal | 926 } // namespace internal |
973 } // namespace v8 | 927 } // namespace v8 |
974 | 928 |
975 #endif // V8_REGISTER_ALLOCATOR_H_ | 929 #endif // V8_REGISTER_ALLOCATOR_H_ |
OLD | NEW |