| 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 public: | 660 public: |
| 660 class PhiMapValue : public ZoneObject { | 661 class PhiMapValue : public ZoneObject { |
| 661 public: | 662 public: |
| 662 PhiMapValue(PhiInstruction* phi, const InstructionBlock* block, Zone* zone); | 663 PhiMapValue(PhiInstruction* phi, const InstructionBlock* block, Zone* zone); |
| 663 | 664 |
| 664 const PhiInstruction* phi() const { return phi_; } | 665 const PhiInstruction* phi() const { return phi_; } |
| 665 const InstructionBlock* block() const { return block_; } | 666 const InstructionBlock* block() const { return block_; } |
| 666 | 667 |
| 667 // For hinting. | 668 // For hinting. |
| 668 int assigned_register() const { return assigned_register_; } | 669 int assigned_register() const { return assigned_register_; } |
| 669 void set_assigned_register(int register_index) { | 670 void set_assigned_register(int register_code) { |
| 670 DCHECK_EQ(assigned_register_, kUnassignedRegister); | 671 DCHECK_EQ(assigned_register_, kUnassignedRegister); |
| 671 assigned_register_ = register_index; | 672 assigned_register_ = register_code; |
| 672 } | 673 } |
| 673 void UnsetAssignedRegister() { assigned_register_ = kUnassignedRegister; } | 674 void UnsetAssignedRegister() { assigned_register_ = kUnassignedRegister; } |
| 674 | 675 |
| 675 void AddOperand(InstructionOperand* operand); | 676 void AddOperand(InstructionOperand* operand); |
| 676 void CommitAssignment(const InstructionOperand& operand); | 677 void CommitAssignment(const InstructionOperand& operand); |
| 677 | 678 |
| 678 private: | 679 private: |
| 679 PhiInstruction* const phi_; | 680 PhiInstruction* const phi_; |
| 680 const InstructionBlock* const block_; | 681 const InstructionBlock* const block_; |
| 681 ZoneVector<InstructionOperand*> incoming_operands_; | 682 ZoneVector<InstructionOperand*> incoming_operands_; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 | 763 |
| 763 private: | 764 private: |
| 764 int GetNextLiveRangeId(); | 765 int GetNextLiveRangeId(); |
| 765 | 766 |
| 766 Zone* const allocation_zone_; | 767 Zone* const allocation_zone_; |
| 767 Frame* const frame_; | 768 Frame* const frame_; |
| 768 InstructionSequence* const code_; | 769 InstructionSequence* const code_; |
| 769 const char* const debug_name_; | 770 const char* const debug_name_; |
| 770 const RegisterConfiguration* const config_; | 771 const RegisterConfiguration* const config_; |
| 771 PhiMap phi_map_; | 772 PhiMap phi_map_; |
| 773 ZoneVector<int> allocatable_codes_; |
| 774 ZoneVector<int> allocatable_double_codes_; |
| 772 ZoneVector<BitVector*> live_in_sets_; | 775 ZoneVector<BitVector*> live_in_sets_; |
| 773 ZoneVector<BitVector*> live_out_sets_; | 776 ZoneVector<BitVector*> live_out_sets_; |
| 774 ZoneVector<TopLevelLiveRange*> live_ranges_; | 777 ZoneVector<TopLevelLiveRange*> live_ranges_; |
| 775 ZoneVector<TopLevelLiveRange*> fixed_live_ranges_; | 778 ZoneVector<TopLevelLiveRange*> fixed_live_ranges_; |
| 776 ZoneVector<TopLevelLiveRange*> fixed_double_live_ranges_; | 779 ZoneVector<TopLevelLiveRange*> fixed_double_live_ranges_; |
| 777 ZoneVector<SpillRange*> spill_ranges_; | 780 ZoneVector<SpillRange*> spill_ranges_; |
| 778 DelayedReferences delayed_references_; | 781 DelayedReferences delayed_references_; |
| 779 BitVector* assigned_registers_; | 782 BitVector* assigned_registers_; |
| 780 BitVector* assigned_double_registers_; | 783 BitVector* assigned_double_registers_; |
| 781 int virtual_register_count_; | 784 int virtual_register_count_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 | 882 |
| 880 class RegisterAllocator : public ZoneObject { | 883 class RegisterAllocator : public ZoneObject { |
| 881 public: | 884 public: |
| 882 explicit RegisterAllocator(RegisterAllocationData* data, RegisterKind kind); | 885 explicit RegisterAllocator(RegisterAllocationData* data, RegisterKind kind); |
| 883 | 886 |
| 884 protected: | 887 protected: |
| 885 RegisterAllocationData* data() const { return data_; } | 888 RegisterAllocationData* data() const { return data_; } |
| 886 InstructionSequence* code() const { return data()->code(); } | 889 InstructionSequence* code() const { return data()->code(); } |
| 887 RegisterKind mode() const { return mode_; } | 890 RegisterKind mode() const { return mode_; } |
| 888 int num_registers() const { return num_registers_; } | 891 int num_registers() const { return num_registers_; } |
| 892 int num_allocatable_registers() const { return num_allocatable_registers_; } |
| 893 int allocatable_register_code(int allocatable_index) const { |
| 894 return allocatable_register_codes_[allocatable_index]; |
| 895 } |
| 889 | 896 |
| 890 Zone* allocation_zone() const { return data()->allocation_zone(); } | 897 Zone* allocation_zone() const { return data()->allocation_zone(); } |
| 891 | 898 |
| 892 // Split the given range at the given position. | 899 // Split the given range at the given position. |
| 893 // If range starts at or after the given position then the | 900 // If range starts at or after the given position then the |
| 894 // original range is returned. | 901 // original range is returned. |
| 895 // Otherwise returns the live range that starts at pos and contains | 902 // Otherwise returns the live range that starts at pos and contains |
| 896 // all uses from the original range that follow pos. Uses at pos will | 903 // all uses from the original range that follow pos. Uses at pos will |
| 897 // still be owned by the original range after splitting. | 904 // still be owned by the original range after splitting. |
| 898 LiveRange* SplitRangeAt(LiveRange* range, LifetimePosition pos); | 905 LiveRange* SplitRangeAt(LiveRange* range, LifetimePosition pos); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 914 LifetimePosition FindOptimalSpillingPos(LiveRange* range, | 921 LifetimePosition FindOptimalSpillingPos(LiveRange* range, |
| 915 LifetimePosition pos); | 922 LifetimePosition pos); |
| 916 | 923 |
| 917 const ZoneVector<TopLevelLiveRange*>& GetFixedRegisters() const; | 924 const ZoneVector<TopLevelLiveRange*>& GetFixedRegisters() const; |
| 918 const char* RegisterName(int allocation_index) const; | 925 const char* RegisterName(int allocation_index) const; |
| 919 | 926 |
| 920 private: | 927 private: |
| 921 RegisterAllocationData* const data_; | 928 RegisterAllocationData* const data_; |
| 922 const RegisterKind mode_; | 929 const RegisterKind mode_; |
| 923 const int num_registers_; | 930 const int num_registers_; |
| 931 int num_allocatable_registers_; |
| 932 const int* allocatable_register_codes_; |
| 924 | 933 |
| 925 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); | 934 DISALLOW_COPY_AND_ASSIGN(RegisterAllocator); |
| 926 }; | 935 }; |
| 927 | 936 |
| 928 | 937 |
| 929 class LinearScanAllocator final : public RegisterAllocator { | 938 class LinearScanAllocator final : public RegisterAllocator { |
| 930 public: | 939 public: |
| 931 LinearScanAllocator(RegisterAllocationData* data, RegisterKind kind, | 940 LinearScanAllocator(RegisterAllocationData* data, RegisterKind kind, |
| 932 Zone* local_zone); | 941 Zone* local_zone); |
| 933 | 942 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 RegisterAllocationData* const data_; | 1084 RegisterAllocationData* const data_; |
| 1076 | 1085 |
| 1077 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); | 1086 DISALLOW_COPY_AND_ASSIGN(LiveRangeConnector); |
| 1078 }; | 1087 }; |
| 1079 | 1088 |
| 1080 } // namespace compiler | 1089 } // namespace compiler |
| 1081 } // namespace internal | 1090 } // namespace internal |
| 1082 } // namespace v8 | 1091 } // namespace v8 |
| 1083 | 1092 |
| 1084 #endif // V8_REGISTER_ALLOCATOR_H_ | 1093 #endif // V8_REGISTER_ALLOCATOR_H_ |
| OLD | NEW |