[llvm] r353301 - [MCA] Speedup ResourceManager queries. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 6 06:57:28 PST 2019


Author: adibiagio
Date: Wed Feb  6 06:57:28 2019
New Revision: 353301

URL: http://llvm.org/viewvc/llvm-project?rev=353301&view=rev
Log:
[MCA] Speedup ResourceManager queries. NFCI

When a resource unit R is released, the ResourceManager notifies groups that
contain R. Before this patch, the logic in method ResourceManager::release()
implemented a potentially slow iterative search of dependent groups on the
entire set of processor resources.
This patch replaces that logic with a simpler (and often faster) lookup on array
`Resource2Groups`.  This patch gives an average speedup of ~3-4% (observed on a
release build when testing for target btver2).
No functional change intended.

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

Modified: llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp?rev=353301&r1=353300&r2=353301&view=diff
==============================================================================
--- llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp (original)
+++ llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp Wed Feb  6 06:57:28 2019
@@ -213,19 +213,20 @@ void ResourceManager::use(const Resource
 }
 
 void ResourceManager::release(const ResourceRef &RR) {
-  ResourceState &RS = *Resources[getResourceStateIndex(RR.first)];
+  unsigned RSID = getResourceStateIndex(RR.first);
+  ResourceState &RS = *Resources[RSID];
   bool WasFullyUsed = !RS.isReady();
   RS.releaseSubResource(RR.second);
   if (!WasFullyUsed)
     return;
 
-  for (std::unique_ptr<ResourceState> &Res : Resources) {
-    ResourceState &Current = *Res;
-    if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first)
-      continue;
-
-    if (Current.containsResource(RR.first))
-      Current.releaseSubResource(RR.first);
+  // Notify groups that RR.first is now available again.
+  uint64_t Users = Resource2Groups[RSID];
+  while (Users) {
+    unsigned GroupIndex = getResourceStateIndex(Users & (-Users));
+    ResourceState &CurrentUser = *Resources[GroupIndex];
+    CurrentUser.releaseSubResource(RR.first);
+    Users &= Users - 1;
   }
 }
 




More information about the llvm-commits mailing list