| 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/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/compiler/instruction.h" | 9 #include "src/compiler/instruction.h" |
| 10 #include "src/globals.h" | 10 #include "src/globals.h" |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // This is used as a cache, it doesn't affect correctness. | 461 // This is used as a cache, it doesn't affect correctness. |
| 462 mutable UsePosition* last_processed_use_; | 462 mutable UsePosition* last_processed_use_; |
| 463 // This is used as a cache, it's invalid outside of BuildLiveRanges. | 463 // This is used as a cache, it's invalid outside of BuildLiveRanges. |
| 464 mutable UsePosition* current_hint_position_; | 464 mutable UsePosition* current_hint_position_; |
| 465 // Cache the last position splintering stopped at. | 465 // Cache the last position splintering stopped at. |
| 466 mutable UsePosition* splitting_pointer_; | 466 mutable UsePosition* splitting_pointer_; |
| 467 | 467 |
| 468 DISALLOW_COPY_AND_ASSIGN(LiveRange); | 468 DISALLOW_COPY_AND_ASSIGN(LiveRange); |
| 469 }; | 469 }; |
| 470 | 470 |
| 471 | |
| 472 class LiveRangeGroup final : public ZoneObject { | 471 class LiveRangeGroup final : public ZoneObject { |
| 473 public: | 472 public: |
| 474 explicit LiveRangeGroup(Zone* zone) : ranges_(zone) {} | 473 explicit LiveRangeGroup(Zone* zone) : ranges_(zone) {} |
| 475 ZoneVector<LiveRange*>& ranges() { return ranges_; } | 474 ZoneVector<LiveRange*>& ranges() { return ranges_; } |
| 476 const ZoneVector<LiveRange*>& ranges() const { return ranges_; } | 475 const ZoneVector<LiveRange*>& ranges() const { return ranges_; } |
| 477 | 476 |
| 478 int assigned_register() const { return assigned_register_; } | 477 int assigned_register() const { return assigned_register_; } |
| 479 void set_assigned_register(int reg) { assigned_register_ = reg; } | 478 void set_assigned_register(int reg) { assigned_register_ = reg; } |
| 480 | 479 |
| 481 private: | 480 private: |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 675 |
| 677 struct PrintableLiveRange { | 676 struct PrintableLiveRange { |
| 678 const RegisterConfiguration* register_configuration_; | 677 const RegisterConfiguration* register_configuration_; |
| 679 const LiveRange* range_; | 678 const LiveRange* range_; |
| 680 }; | 679 }; |
| 681 | 680 |
| 682 | 681 |
| 683 std::ostream& operator<<(std::ostream& os, | 682 std::ostream& operator<<(std::ostream& os, |
| 684 const PrintableLiveRange& printable_range); | 683 const PrintableLiveRange& printable_range); |
| 685 | 684 |
| 686 | |
| 687 class SpillRange final : public ZoneObject { | 685 class SpillRange final : public ZoneObject { |
| 688 public: | 686 public: |
| 689 static const int kUnassignedSlot = -1; | 687 static const int kUnassignedSlot = -1; |
| 690 SpillRange(TopLevelLiveRange* range, Zone* zone); | 688 SpillRange(TopLevelLiveRange* range, Zone* zone); |
| 691 | 689 |
| 692 UseInterval* interval() const { return use_interval_; } | 690 UseInterval* interval() const { return use_interval_; } |
| 693 | 691 |
| 694 bool IsEmpty() const { return live_ranges_.empty(); } | 692 bool IsEmpty() const { return live_ranges_.empty(); } |
| 695 bool TryMerge(SpillRange* other); | 693 bool TryMerge(SpillRange* other); |
| 696 bool HasSlot() const { return assigned_slot_ != kUnassignedSlot; } | 694 bool HasSlot() const { return assigned_slot_ != kUnassignedSlot; } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 719 | 717 |
| 720 ZoneVector<TopLevelLiveRange*> live_ranges_; | 718 ZoneVector<TopLevelLiveRange*> live_ranges_; |
| 721 UseInterval* use_interval_; | 719 UseInterval* use_interval_; |
| 722 LifetimePosition end_position_; | 720 LifetimePosition end_position_; |
| 723 int assigned_slot_; | 721 int assigned_slot_; |
| 724 int byte_width_; | 722 int byte_width_; |
| 725 | 723 |
| 726 DISALLOW_COPY_AND_ASSIGN(SpillRange); | 724 DISALLOW_COPY_AND_ASSIGN(SpillRange); |
| 727 }; | 725 }; |
| 728 | 726 |
| 729 | |
| 730 class RegisterAllocationData final : public ZoneObject { | 727 class RegisterAllocationData final : public ZoneObject { |
| 731 public: | 728 public: |
| 732 class PhiMapValue : public ZoneObject { | 729 class PhiMapValue : public ZoneObject { |
| 733 public: | 730 public: |
| 734 PhiMapValue(PhiInstruction* phi, const InstructionBlock* block, Zone* zone); | 731 PhiMapValue(PhiInstruction* phi, const InstructionBlock* block, Zone* zone); |
| 735 | 732 |
| 736 const PhiInstruction* phi() const { return phi_; } | 733 const PhiInstruction* phi() const { return phi_; } |
| 737 const InstructionBlock* block() const { return block_; } | 734 const InstructionBlock* block() const { return block_; } |
| 738 | 735 |
| 739 // For hinting. | 736 // For hinting. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 ZoneVector<SpillRange*> spill_ranges_; | 860 ZoneVector<SpillRange*> spill_ranges_; |
| 864 DelayedReferences delayed_references_; | 861 DelayedReferences delayed_references_; |
| 865 BitVector* assigned_registers_; | 862 BitVector* assigned_registers_; |
| 866 BitVector* assigned_double_registers_; | 863 BitVector* assigned_double_registers_; |
| 867 int virtual_register_count_; | 864 int virtual_register_count_; |
| 868 RangesWithPreassignedSlots preassigned_slot_ranges_; | 865 RangesWithPreassignedSlots preassigned_slot_ranges_; |
| 869 | 866 |
| 870 DISALLOW_COPY_AND_ASSIGN(RegisterAllocationData); | 867 DISALLOW_COPY_AND_ASSIGN(RegisterAllocationData); |
| 871 }; | 868 }; |
| 872 | 869 |
| 873 | |
| 874 class ConstraintBuilder final : public ZoneObject { | 870 class ConstraintBuilder final : public ZoneObject { |
| 875 public: | 871 public: |
| 876 explicit ConstraintBuilder(RegisterAllocationData* data); | 872 explicit ConstraintBuilder(RegisterAllocationData* data); |
| 877 | 873 |
| 878 // Phase 1 : insert moves to account for fixed register operands. | 874 // Phase 1 : insert moves to account for fixed register operands. |
| 879 void MeetRegisterConstraints(); | 875 void MeetRegisterConstraints(); |
| 880 | 876 |
| 881 // Phase 2: deconstruct SSA by inserting moves in successors and the headers | 877 // Phase 2: deconstruct SSA by inserting moves in successors and the headers |
| 882 // of blocks containing phis. | 878 // of blocks containing phis. |
| 883 void ResolvePhis(); | 879 void ResolvePhis(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 894 void MeetConstraintsAfter(int index); | 890 void MeetConstraintsAfter(int index); |
| 895 void MeetRegisterConstraintsForLastInstructionInBlock( | 891 void MeetRegisterConstraintsForLastInstructionInBlock( |
| 896 const InstructionBlock* block); | 892 const InstructionBlock* block); |
| 897 void ResolvePhis(const InstructionBlock* block); | 893 void ResolvePhis(const InstructionBlock* block); |
| 898 | 894 |
| 899 RegisterAllocationData* const data_; | 895 RegisterAllocationData* const data_; |
| 900 | 896 |
| 901 DISALLOW_COPY_AND_ASSIGN(ConstraintBuilder); | 897 DISALLOW_COPY_AND_ASSIGN(ConstraintBuilder); |
| 902 }; | 898 }; |
| 903 | 899 |
| 904 | |
| 905 class LiveRangeBuilder final : public ZoneObject { | 900 class LiveRangeBuilder final : public ZoneObject { |
| 906 public: | 901 public: |
| 907 explicit LiveRangeBuilder(RegisterAllocationData* data, Zone* local_zone); | 902 explicit LiveRangeBuilder(RegisterAllocationData* data, Zone* local_zone); |
| 908 | 903 |
| 909 // Phase 3: compute liveness of all virtual register. | 904 // Phase 3: compute liveness of all virtual register. |
| 910 void BuildLiveRanges(); | 905 void BuildLiveRanges(); |
| 911 static BitVector* ComputeLiveOut(const InstructionBlock* block, | 906 static BitVector* ComputeLiveOut(const InstructionBlock* block, |
| 912 RegisterAllocationData* data); | 907 RegisterAllocationData* data); |
| 913 | 908 |
| 914 private: | 909 private: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 InstructionOperand* operand) { | 956 InstructionOperand* operand) { |
| 962 Use(block_start, position, operand, nullptr, UsePositionHintType::kNone); | 957 Use(block_start, position, operand, nullptr, UsePositionHintType::kNone); |
| 963 } | 958 } |
| 964 | 959 |
| 965 RegisterAllocationData* const data_; | 960 RegisterAllocationData* const data_; |
| 966 ZoneMap<InstructionOperand*, UsePosition*> phi_hints_; | 961 ZoneMap<InstructionOperand*, UsePosition*> phi_hints_; |
| 967 | 962 |
| 968 DISALLOW_COPY_AND_ASSIGN(LiveRangeBuilder); | 963 DISALLOW_COPY_AND_ASSIGN(LiveRangeBuilder); |
| 969 }; | 964 }; |
| 970 | 965 |
| 971 | |
| 972 class RegisterAllocator : public ZoneObject { | 966 class RegisterAllocator : public ZoneObject { |
| 973 public: | 967 public: |
| 974 RegisterAllocator(RegisterAllocationData* data, RegisterKind kind); | 968 RegisterAllocator(RegisterAllocationData* data, RegisterKind kind); |
| 975 | 969 |
| 976 protected: | 970 protected: |
| 977 RegisterAllocationData* data() const { return data_; } | 971 RegisterAllocationData* data() const { return data_; } |
| 978 InstructionSequence* code() const { return data()->code(); } | 972 InstructionSequence* code() const { return data()->code(); } |
| 979 RegisterKind mode() const { return mode_; } | 973 RegisterKind mode() const { return mode_; } |
| 980 int num_registers() const { return num_registers_; } | 974 int num_registers() const { return num_registers_; } |
| 981 int num_allocatable_registers() const { return num_allocatable_registers_; } | 975 int num_allocatable_registers() const { return num_allocatable_registers_; } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 ZoneVector<LiveRange*> active_live_ranges_; | 1097 ZoneVector<LiveRange*> active_live_ranges_; |
| 1104 ZoneVector<LiveRange*> inactive_live_ranges_; | 1098 ZoneVector<LiveRange*> inactive_live_ranges_; |
| 1105 | 1099 |
| 1106 #ifdef DEBUG | 1100 #ifdef DEBUG |
| 1107 LifetimePosition allocation_finger_; | 1101 LifetimePosition allocation_finger_; |
| 1108 #endif | 1102 #endif |
| 1109 | 1103 |
| 1110 DISALLOW_COPY_AND_ASSIGN(LinearScanAllocator); | 1104 DISALLOW_COPY_AND_ASSIGN(LinearScanAllocator); |
| 1111 }; | 1105 }; |
| 1112 | 1106 |
| 1113 | |
| 1114 class SpillSlotLocator final : public ZoneObject { | 1107 class SpillSlotLocator final : public ZoneObject { |
| 1115 public: | 1108 public: |
| 1116 explicit SpillSlotLocator(RegisterAllocationData* data); | 1109 explicit SpillSlotLocator(RegisterAllocationData* data); |
| 1117 | 1110 |
| 1118 void LocateSpillSlots(); | 1111 void LocateSpillSlots(); |
| 1119 | 1112 |
| 1120 private: | 1113 private: |
| 1121 RegisterAllocationData* data() const { return data_; } | 1114 RegisterAllocationData* data() const { return data_; } |
| 1122 | 1115 |
| 1123 RegisterAllocationData* const data_; | 1116 RegisterAllocationData* const data_; |
| 1124 | 1117 |
| 1125 DISALLOW_COPY_AND_ASSIGN(SpillSlotLocator); | 1118 DISALLOW_COPY_AND_ASSIGN(SpillSlotLocator); |
| 1126 }; | 1119 }; |
| 1127 | 1120 |
| 1128 | |
| 1129 class OperandAssigner final : public ZoneObject { | 1121 class OperandAssigner final : public ZoneObject { |
| 1130 public: | 1122 public: |
| 1131 explicit OperandAssigner(RegisterAllocationData* data); | 1123 explicit OperandAssigner(RegisterAllocationData* data); |
| 1132 | 1124 |
| 1133 // Phase 5: assign spill splots. | 1125 // Phase 5: assign spill splots. |
| 1134 void AssignSpillSlots(); | 1126 void AssignSpillSlots(); |
| 1135 | 1127 |
| 1136 // Phase 6: commit assignment. | 1128 // Phase 6: commit assignment. |
| 1137 void CommitAssignment(); | 1129 void CommitAssignment(); |
| 1138 | 1130 |
| 1139 private: | 1131 private: |
| 1140 RegisterAllocationData* data() const { return data_; } | 1132 RegisterAllocationData* data() const { return data_; } |
| 1141 | 1133 |
| 1142 RegisterAllocationData* const data_; | 1134 RegisterAllocationData* const data_; |
| 1143 | 1135 |
| 1144 DISALLOW_COPY_AND_ASSIGN(OperandAssigner); | 1136 DISALLOW_COPY_AND_ASSIGN(OperandAssigner); |
| 1145 }; | 1137 }; |
| 1146 | 1138 |
| 1147 | |
| 1148 class ReferenceMapPopulator final : public ZoneObject { | 1139 class ReferenceMapPopulator final : public ZoneObject { |
| 1149 public: | 1140 public: |
| 1150 explicit ReferenceMapPopulator(RegisterAllocationData* data); | 1141 explicit ReferenceMapPopulator(RegisterAllocationData* data); |
| 1151 | 1142 |
| 1152 // Phase 7: compute values for pointer maps. | 1143 // Phase 7: compute values for pointer maps. |
| 1153 void PopulateReferenceMaps(); | 1144 void PopulateReferenceMaps(); |
| 1154 | 1145 |
| 1155 private: | 1146 private: |
| 1156 RegisterAllocationData* data() const { return data_; } | 1147 RegisterAllocationData* data() const { return data_; } |
| 1157 | 1148 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 RegisterAllocationData* const data_; | 1194 RegisterAllocationData* const data_; |
| 1204 | 1195 |
| 1205 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); | 1196 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); |
| 1206 }; | 1197 }; |
| 1207 | 1198 |
| 1208 } // namespace compiler | 1199 } // namespace compiler |
| 1209 } // namespace internal | 1200 } // namespace internal |
| 1210 } // namespace v8 | 1201 } // namespace v8 |
| 1211 | 1202 |
| 1212 #endif // V8_REGISTER_ALLOCATOR_H_ | 1203 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |