From: Andrea Di Biagio Date: Thu, 3 Jan 2019 14:47:46 +0000 (+0000) Subject: [MCA] Improve code comment and reuse an helper function in ResourceManager. NFCI X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ae663f5c35277c185fd3c5b48376a36915fb1ea;p=llvm [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 --- diff --git a/include/llvm/MCA/HardwareUnits/ResourceManager.h b/include/llvm/MCA/HardwareUnits/ResourceManager.h index 5429f2b8cf0..7ae1a218ed6 100644 --- a/include/llvm/MCA/HardwareUnits/ResourceManager.h +++ b/include/llvm/MCA/HardwareUnits/ResourceManager.h @@ -144,12 +144,14 @@ class ResourceState { /// A ProcResource can have multiple units. /// - /// For processor resource groups, - /// this field default to the value of field `ResourceMask`; the number of - /// bits set is equal to the cardinality of the group. For normal (i.e. - /// non-group) resources, the number of bits set in this mask is equivalent - /// to the number of units declared by the processor model (see field - /// 'NumUnits' in 'ProcResourceUnits'). + /// For processor resource groups this field is a mask of contained resource + /// units. It is obtained from ResourceMask by clearing the highest set bit. + /// The number of resource units in a group can be simply computed as the + /// population count of this field. + /// + /// For normal (i.e. non-group) resources, the number of bits set in this mask + /// is equivalent to the number of units declared by the processor model (see + /// field 'NumUnits' in 'ProcResourceUnits'). uint64_t ResourceSizeMask; /// A mask of ready units. diff --git a/lib/MCA/HardwareUnits/ResourceManager.cpp b/lib/MCA/HardwareUnits/ResourceManager.cpp index 9fc92cd8185..6c21b771330 100644 --- a/lib/MCA/HardwareUnits/ResourceManager.cpp +++ b/lib/MCA/HardwareUnits/ResourceManager.cpp @@ -24,11 +24,17 @@ namespace mca { #define DEBUG_TYPE "llvm-mca" ResourceStrategy::~ResourceStrategy() = default; +// Returns the index of the highest bit set. For resource masks, the position of +// the highest bit set can be used to construct a resource mask identifier. +static unsigned getResourceStateIndex(uint64_t Mask) { + return std::numeric_limits::digits - countLeadingZeros(Mask); +} + static uint64_t selectImpl(uint64_t CandidateMask, uint64_t &NextInSequenceMask) { - CandidateMask = 1ULL << (countLeadingZeros(CandidateMask) ^ - (std::numeric_limits::digits - 1)); - NextInSequenceMask &= (CandidateMask ^ (CandidateMask - 1)); + // The upper bit set in CandidateMask identifies our next candidate resource. + CandidateMask = 1ULL << (getResourceStateIndex(CandidateMask) - 1); + NextInSequenceMask &= (CandidateMask | (CandidateMask - 1)); return CandidateMask; } @@ -69,8 +75,7 @@ ResourceState::ResourceState(const MCProcResourceDesc &Desc, unsigned Index, BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask) > 1) { if (IsAGroup) { ResourceSizeMask = - ResourceMask ^ (1ULL << (countLeadingZeros(ResourceMask) ^ - (std::numeric_limits::digits - 1))); + ResourceMask ^ 1ULL << (getResourceStateIndex(ResourceMask) - 1); } else { ResourceSizeMask = (1ULL << Desc.NumUnits) - 1; } @@ -103,10 +108,6 @@ void ResourceState::dump() const { } #endif -static unsigned getResourceStateIndex(uint64_t Mask) { - return std::numeric_limits::digits - countLeadingZeros(Mask); -} - static std::unique_ptr getStrategyFor(const ResourceState &RS) { if (RS.isAResourceGroup() || RS.getNumUnits() > 1)