[PATCH] D136351: [llvm-exegesis] getNonRedundantWriteProcRes - perform basic toplogical sorting (PR58500)

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 02:46:39 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG97bd44f436ea: [llvm-exegesis] getNonRedundantWriteProcRes - perform basic toplogical sorting… (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D136351?vs=469212&id=470095#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136351/new/

https://reviews.llvm.org/D136351

Files:
  llvm/tools/llvm-exegesis/lib/CMakeLists.txt
  llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp


Index: llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
+++ llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
@@ -10,6 +10,7 @@
 #include "BenchmarkResult.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MCA/Support.h"
 #include "llvm/Support/FormatVariadic.h"
 #include <limits>
 #include <unordered_set>
@@ -45,7 +46,7 @@
 //
 // Note that in this case, P016 does not contribute any cycles, so it would
 // be removed by this function.
-// FIXME: Move this to MCSubtargetInfo and use it in llvm-mca.
+// FIXME: Merge this with the equivalent in llvm-mca.
 static SmallVector<MCWriteProcResEntry, 8>
 getNonRedundantWriteProcRes(const MCSchedClassDesc &SCDesc,
                             const MCSubtargetInfo &STI) {
@@ -53,12 +54,33 @@
   const auto &SM = STI.getSchedModel();
   const unsigned NumProcRes = SM.getNumProcResourceKinds();
 
-  // This assumes that the ProcResDescs are sorted in topological order, which
-  // is guaranteed by the tablegen backend.
-  SmallVector<float, 32> ProcResUnitUsage(NumProcRes);
+  // Collect resource masks.
+  SmallVector<uint64_t> ProcResourceMasks(NumProcRes);
+  mca::computeProcResourceMasks(SM, ProcResourceMasks);
+
+  // Sort entries by smaller resources for (basic) topological ordering.
+  using ResourceMaskAndEntry = std::pair<uint64_t, const MCWriteProcResEntry *>;
+  SmallVector<ResourceMaskAndEntry, 8> ResourceMaskAndEntries;
   for (const auto *WPR = STI.getWriteProcResBegin(&SCDesc),
                   *const WPREnd = STI.getWriteProcResEnd(&SCDesc);
        WPR != WPREnd; ++WPR) {
+    uint64_t Mask = ProcResourceMasks[WPR->ProcResourceIdx];
+    ResourceMaskAndEntries.push_back({Mask, WPR});
+  }
+  sort(ResourceMaskAndEntries,
+       [](const ResourceMaskAndEntry &A, const ResourceMaskAndEntry &B) {
+         unsigned popcntA = countPopulation(A.first);
+         unsigned popcntB = countPopulation(B.first);
+         if (popcntA < popcntB)
+           return true;
+         if (popcntA > popcntB)
+           return false;
+         return A.first < B.first;
+       });
+
+  SmallVector<float, 32> ProcResUnitUsage(NumProcRes);
+  for (const ResourceMaskAndEntry &Entry : ResourceMaskAndEntries) {
+    const MCWriteProcResEntry *WPR = Entry.second;
     const MCProcResourceDesc *const ProcResDesc =
         SM.getProcResource(WPR->ProcResourceIdx);
     if (ProcResDesc->SubUnitsIdxBegin == nullptr) {
Index: llvm/tools/llvm-exegesis/lib/CMakeLists.txt
===================================================================
--- llvm/tools/llvm-exegesis/lib/CMakeLists.txt
+++ llvm/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -26,6 +26,7 @@
   ExecutionEngine
   GlobalISel
   MC
+  MCA
   MCDisassembler
   MCJIT
   MCParser


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136351.470095.patch
Type: text/x-patch
Size: 2876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221024/efe8f6e1/attachment.bin>


More information about the llvm-commits mailing list