[llvm] r350322 - [MCA] Improve code comment and reuse an helper function in ResourceManager. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 3 06:47:46 PST 2019


Author: adibiagio
Date: Thu Jan  3 06:47:46 2019
New Revision: 350322

URL: http://llvm.org/viewvc/llvm-project?rev=350322&view=rev
Log:
[MCA] Improve code comment and reuse an helper function in ResourceManager. NFCI

Modified:
    llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h
    llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp

Modified: llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h?rev=350322&r1=350321&r2=350322&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h (original)
+++ llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h Thu Jan  3 06:47:46 2019
@@ -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.

Modified: llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp?rev=350322&r1=350321&r2=350322&view=diff
==============================================================================
--- llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp (original)
+++ llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp Thu Jan  3 06:47:46 2019
@@ -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<uint64_t>::digits - countLeadingZeros(Mask);
+}
+
 static uint64_t selectImpl(uint64_t CandidateMask,
                            uint64_t &NextInSequenceMask) {
-  CandidateMask = 1ULL << (countLeadingZeros(CandidateMask) ^
-                           (std::numeric_limits<uint64_t>::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 MCPro
       BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask) > 1) {
   if (IsAGroup) {
     ResourceSizeMask =
-        ResourceMask ^ (1ULL << (countLeadingZeros(ResourceMask) ^
-                                 (std::numeric_limits<uint64_t>::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<uint64_t>::digits - countLeadingZeros(Mask);
-}
-
 static std::unique_ptr<ResourceStrategy>
 getStrategyFor(const ResourceState &RS) {
   if (RS.isAResourceGroup() || RS.getNumUnits() > 1)




More information about the llvm-commits mailing list