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/register-configuration.h" |
10 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace compiler { | 15 namespace compiler { |
15 | 16 |
16 enum RegisterKind { | 17 enum RegisterKind { |
17 GENERAL_REGISTERS, | 18 GENERAL_REGISTERS, |
18 DOUBLE_REGISTERS | 19 DOUBLE_REGISTERS |
19 }; | 20 }; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 235 } |
235 UsePositionType type() const { return TypeField::decode(flags_); } | 236 UsePositionType type() const { return TypeField::decode(flags_); } |
236 void set_type(UsePositionType type, bool register_beneficial); | 237 void set_type(UsePositionType type, bool register_beneficial); |
237 | 238 |
238 LifetimePosition pos() const { return pos_; } | 239 LifetimePosition pos() const { return pos_; } |
239 | 240 |
240 UsePosition* next() const { return next_; } | 241 UsePosition* next() const { return next_; } |
241 void set_next(UsePosition* next) { next_ = next; } | 242 void set_next(UsePosition* next) { next_ = next; } |
242 | 243 |
243 // For hinting only. | 244 // For hinting only. |
244 void set_assigned_register(int register_index) { | 245 void set_assigned_register(int register_code) { |
245 flags_ = AssignedRegisterField::update(flags_, register_index); | 246 flags_ = AssignedRegisterField::update(flags_, register_code); |
246 } | 247 } |
247 | 248 |
248 UsePositionHintType hint_type() const { | 249 UsePositionHintType hint_type() const { |
249 return HintTypeField::decode(flags_); | 250 return HintTypeField::decode(flags_); |
250 } | 251 } |
251 bool HasHint() const; | 252 bool HasHint() const; |
252 bool HintRegister(int* register_index) const; | 253 bool HintRegister(int* register_code) const; |
253 void ResolveHint(UsePosition* use_pos); | 254 void ResolveHint(UsePosition* use_pos); |
254 bool IsResolved() const { | 255 bool IsResolved() const { |
255 return hint_type() != UsePositionHintType::kUnresolved; | 256 return hint_type() != UsePositionHintType::kUnresolved; |
256 } | 257 } |
257 static UsePositionHintType HintTypeForOperand(const InstructionOperand& op); | 258 static UsePositionHintType HintTypeForOperand(const InstructionOperand& op); |
258 | 259 |
259 private: | 260 private: |
260 typedef BitField<UsePositionType, 0, 2> TypeField; | 261 typedef BitField<UsePositionType, 0, 2> TypeField; |
261 typedef BitField<UsePositionHintType, 2, 3> HintTypeField; | 262 typedef BitField<UsePositionHintType, 2, 3> HintTypeField; |
262 typedef BitField<bool, 5, 1> RegisterBeneficialField; | 263 typedef BitField<bool, 5, 1> RegisterBeneficialField; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 public: | 637 public: |
637 class PhiMapValue : public ZoneObject { | 638 class PhiMapValue : public ZoneObject { |
638 public: | 639 public: |
639 PhiMapValue(PhiInstruction* phi, const InstructionBlock* block, Zone* zone); | 640 PhiMapValue(PhiInstruction* phi, const InstructionBlock* block, Zone* zone); |
640 | 641 |
641 const PhiInstruction* phi() const { return phi_; } | 642 const PhiInstruction* phi() const { return phi_; } |
642 const InstructionBlock* block() const { return block_; } | 643 const InstructionBlock* block() const { return block_; } |
643 | 644 |
644 // For hinting. | 645 // For hinting. |
645 int assigned_register() const { return assigned_register_; } | 646 int assigned_register() const { return assigned_register_; } |
646 void set_assigned_register(int register_index) { | 647 void set_assigned_register(int register_code) { |
647 DCHECK_EQ(assigned_register_, kUnassignedRegister); | 648 DCHECK_EQ(assigned_register_, kUnassignedRegister); |
648 assigned_register_ = register_index; | 649 assigned_register_ = register_code; |
649 } | 650 } |
650 void UnsetAssignedRegister() { assigned_register_ = kUnassignedRegister; } | 651 void UnsetAssignedRegister() { assigned_register_ = kUnassignedRegister; } |
651 | 652 |
652 void AddOperand(InstructionOperand* operand); | 653 void AddOperand(InstructionOperand* operand); |
653 void CommitAssignment(const InstructionOperand& operand); | 654 void CommitAssignment(const InstructionOperand& operand); |
654 | 655 |
655 private: | 656 private: |
656 PhiInstruction* const phi_; | 657 PhiInstruction* const phi_; |
657 const InstructionBlock* const block_; | 658 const InstructionBlock* const block_; |
658 ZoneVector<InstructionOperand*> incoming_operands_; | 659 ZoneVector<InstructionOperand*> incoming_operands_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 | 740 |
740 private: | 741 private: |
741 int GetNextLiveRangeId(); | 742 int GetNextLiveRangeId(); |
742 | 743 |
743 Zone* const allocation_zone_; | 744 Zone* const allocation_zone_; |
744 Frame* const frame_; | 745 Frame* const frame_; |
745 InstructionSequence* const code_; | 746 InstructionSequence* const code_; |
746 const char* const debug_name_; | 747 const char* const debug_name_; |
747 const RegisterConfiguration* const config_; | 748 const RegisterConfiguration* const config_; |
748 PhiMap phi_map_; | 749 PhiMap phi_map_; |
| 750 ZoneVector<int> allocatable_codes_; |
| 751 ZoneVector<int> allocatable_double_codes_; |
749 ZoneVector<BitVector*> live_in_sets_; | 752 ZoneVector<BitVector*> live_in_sets_; |
750 ZoneVector<BitVector*> live_out_sets_; | 753 ZoneVector<BitVector*> live_out_sets_; |
751 ZoneVector<TopLevelLiveRange*> live_ranges_; | 754 ZoneVector<TopLevelLiveRange*> live_ranges_; |
752 ZoneVector<TopLevelLiveRange*> fixed_live_ranges_; | 755 ZoneVector<TopLevelLiveRange*> fixed_live_ranges_; |
753 ZoneVector<TopLevelLiveRange*> fixed_double_live_ranges_; | 756 ZoneVector<TopLevelLiveRange*> fixed_double_live_ranges_; |
754 ZoneVector<SpillRange*> spill_ranges_; | 757 ZoneVector<SpillRange*> spill_ranges_; |
755 DelayedReferences delayed_references_; | 758 DelayedReferences delayed_references_; |
756 BitVector* assigned_registers_; | 759 BitVector* assigned_registers_; |
757 BitVector* assigned_double_registers_; | 760 BitVector* assigned_double_registers_; |
758 int virtual_register_count_; | 761 int virtual_register_count_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 859 |
857 class RegisterAllocator : public ZoneObject { | 860 class RegisterAllocator : public ZoneObject { |
858 public: | 861 public: |
859 explicit RegisterAllocator(RegisterAllocationData* data, RegisterKind kind); | 862 explicit RegisterAllocator(RegisterAllocationData* data, RegisterKind kind); |
860 | 863 |
861 protected: | 864 protected: |
862 RegisterAllocationData* data() const { return data_; } | 865 RegisterAllocationData* data() const { return data_; } |
863 InstructionSequence* code() const { return data()->code(); } | 866 InstructionSequence* code() const { return data()->code(); } |
864 RegisterKind mode() const { return mode_; } | 867 RegisterKind mode() const { return mode_; } |
865 int num_registers() const { return num_registers_; } | 868 int num_registers() const { return num_registers_; } |
| 869 int num_alloctable_registers() const { return num_allocatable_registers_; } |
| 870 int allocatable_register_code(int allocatable_index) const { |
| 871 return allocatable_register_codes_[allocatable_index]; |
| 872 } |
866 | 873 |
867 Zone* allocation_zone() const { return data()->allocation_zone(); } | 874 Zone* allocation_zone() const { return data()->allocation_zone(); } |
868 | 875 |
869 // Split the given range at the given position. | 876 // Split the given range at the given position. |
870 // If range starts at or after the given position then the | 877 // If range starts at or after the given position then the |
871 // original range is returned. | 878 // original range is returned. |
872 // Otherwise returns the live range that starts at pos and contains | 879 // Otherwise returns the live range that starts at pos and contains |
873 // all uses from the original range that follow pos. Uses at pos will | 880 // all uses from the original range that follow pos. Uses at pos will |
874 // still be owned by the original range after splitting. | 881 // still be owned by the original range after splitting. |
875 LiveRange* SplitRangeAt(LiveRange* range, LifetimePosition pos); | 882 LiveRange* SplitRangeAt(LiveRange* range, LifetimePosition pos); |
(...skipping 15 matching lines...) Expand all Loading... |
891 LifetimePosition FindOptimalSpillingPos(LiveRange* range, | 898 LifetimePosition FindOptimalSpillingPos(LiveRange* range, |
892 LifetimePosition pos); | 899 LifetimePosition pos); |
893 | 900 |
894 const ZoneVector<TopLevelLiveRange*>& GetFixedRegisters() const; | 901 const ZoneVector<TopLevelLiveRange*>& GetFixedRegisters() const; |
895 const char* RegisterName(int allocation_index) const; | 902 const char* RegisterName(int allocation_index) const; |
896 | 903 |
897 private: | 904 private: |
898 RegisterAllocationData* const data_; | 905 RegisterAllocationData* const data_; |
899 const RegisterKind mode_; | 906 const RegisterKind mode_; |
900 const int num_registers_; | 907 const int num_registers_; |
| 908 int num_allocatable_registers_; |
| 909 const int* allocatable_register_codes_; |
901 | 910 |
902 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); | 911 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); |
903 }; | 912 }; |
904 | 913 |
905 | 914 |
906 class LinearScanAllocator final : public RegisterAllocator { | 915 class LinearScanAllocator final : public RegisterAllocator { |
907 public: | 916 public: |
908 LinearScanAllocator(RegisterAllocationData* data, RegisterKind kind, | 917 LinearScanAllocator(RegisterAllocationData* data, RegisterKind kind, |
909 Zone* local_zone); | 918 Zone* local_zone); |
910 | 919 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 RegisterAllocationData* const data_; | 1061 RegisterAllocationData* const data_; |
1053 | 1062 |
1054 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); | 1063 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); |
1055 }; | 1064 }; |
1056 | 1065 |
1057 } // namespace compiler | 1066 } // namespace compiler |
1058 } // namespace internal | 1067 } // namespace internal |
1059 } // namespace v8 | 1068 } // namespace v8 |
1060 | 1069 |
1061 #endif // V8_REGISTER_ALLOCATOR_H_ | 1070 #endif // V8_REGISTER_ALLOCATOR_H_ |
OLD | NEW |