llvm.org GIT mirror llvm / 2ae663f
[MCA] Improve code comment and reuse an helper function in ResourceManager. NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350322 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 1 year, 10 months ago
2 changed file(s) with 18 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
143143
144144 /// A ProcResource can have multiple units.
145145 ///
146 /// For processor resource groups,
147 /// this field default to the value of field `ResourceMask`; the number of
148 /// bits set is equal to the cardinality of the group. For normal (i.e.
149 /// non-group) resources, the number of bits set in this mask is equivalent
150 /// to the number of units declared by the processor model (see field
151 /// 'NumUnits' in 'ProcResourceUnits').
146 /// For processor resource groups this field is a mask of contained resource
147 /// units. It is obtained from ResourceMask by clearing the highest set bit.
148 /// The number of resource units in a group can be simply computed as the
149 /// population count of this field.
150 ///
151 /// For normal (i.e. non-group) resources, the number of bits set in this mask
152 /// is equivalent to the number of units declared by the processor model (see
153 /// field 'NumUnits' in 'ProcResourceUnits').
152154 uint64_t ResourceSizeMask;
153155
154156 /// A mask of ready units.
2323 #define DEBUG_TYPE "llvm-mca"
2424 ResourceStrategy::~ResourceStrategy() = default;
2525
26 // Returns the index of the highest bit set. For resource masks, the position of
27 // the highest bit set can be used to construct a resource mask identifier.
28 static unsigned getResourceStateIndex(uint64_t Mask) {
29 return std::numeric_limits::digits - countLeadingZeros(Mask);
30 }
31
2632 static uint64_t selectImpl(uint64_t CandidateMask,
2733 uint64_t &NextInSequenceMask) {
28 CandidateMask = 1ULL << (countLeadingZeros(CandidateMask) ^
29 (std::numeric_limits::digits - 1));
30 NextInSequenceMask &= (CandidateMask ^ (CandidateMask - 1));
34 // The upper bit set in CandidateMask identifies our next candidate resource.
35 CandidateMask = 1ULL << (getResourceStateIndex(CandidateMask) - 1);
36 NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
3137 return CandidateMask;
3238 }
3339
6874 BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask) > 1) {
6975 if (IsAGroup) {
7076 ResourceSizeMask =
71 ResourceMask ^ (1ULL << (countLeadingZeros(ResourceMask) ^
72 (std::numeric_limits::digits - 1)));
77 ResourceMask ^ 1ULL << (getResourceStateIndex(ResourceMask) - 1);
7378 } else {
7479 ResourceSizeMask = (1ULL << Desc.NumUnits) - 1;
7580 }
101106 << ", Reserved=" << Unavailable << '\n';
102107 }
103108 #endif
104
105 static unsigned getResourceStateIndex(uint64_t Mask) {
106 return std::numeric_limits::digits - countLeadingZeros(Mask);
107 }
108109
109110 static std::unique_ptr
110111 getStrategyFor(const ResourceState &RS) {