[llvm] r327214 - [llvm-mca] Views are now independent from resource masks. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 10 08:55:07 PST 2018


Author: adibiagio
Date: Sat Mar 10 08:55:07 2018
New Revision: 327214

URL: http://llvm.org/viewvc/llvm-project?rev=327214&view=rev
Log:
[llvm-mca] Views are now independent from resource masks. NFCI

This change removes method Backend::getProcResourceMasks() and simplifies some
logic in the Views. This effectively removes yet another dependency between the
views and the Backend.
No functional change intended.

Modified:
    llvm/trunk/tools/llvm-mca/Backend.h
    llvm/trunk/tools/llvm-mca/BackendStatistics.cpp
    llvm/trunk/tools/llvm-mca/ResourcePressureView.cpp
    llvm/trunk/tools/llvm-mca/ResourcePressureView.h
    llvm/trunk/tools/llvm-mca/Scheduler.cpp
    llvm/trunk/tools/llvm-mca/Scheduler.h
    llvm/trunk/tools/llvm-mca/llvm-mca.cpp

Modified: llvm/trunk/tools/llvm-mca/Backend.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Backend.h?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Backend.h (original)
+++ llvm/trunk/tools/llvm-mca/Backend.h Sat Mar 10 08:55:07 2018
@@ -70,7 +70,7 @@ public:
             this, MRI, Subtarget.getSchedModel().MicroOpBufferSize,
             RegisterFileSize, MaxRetirePerCycle, DispatchWidth, HWS.get())),
         SM(Source), Cycles(0) {
-    IB = llvm::make_unique<InstrBuilder>(MCII, getProcResourceMasks());
+    IB = llvm::make_unique<InstrBuilder>(MCII, HWS->getProcResourceMasks());
   }
 
   void run() {
@@ -93,9 +93,6 @@ public:
   const llvm::MCSchedModel &getSchedModel() const {
     return STI.getSchedModel();
   }
-  const llvm::ArrayRef<uint64_t> getProcResourceMasks() const {
-    return HWS->getProcResourceMasks();
-  }
 
   double getRThroughput(const InstrDesc &ID) const {
     return HWS->getRThroughput(ID);

Modified: llvm/trunk/tools/llvm-mca/BackendStatistics.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/BackendStatistics.cpp?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/BackendStatistics.cpp (original)
+++ llvm/trunk/tools/llvm-mca/BackendStatistics.cpp Sat Mar 10 08:55:07 2018
@@ -121,14 +121,13 @@ void BackendStatistics::printSchedulerUs
   std::string Buffer;
   raw_string_ostream TempStream(Buffer);
   TempStream << "\n\nScheduler's queue usage:\n";
-  const ArrayRef<uint64_t> ResourceMasks = B.getProcResourceMasks();
   for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
     const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);
     if (!ProcResource.BufferSize)
       continue;
 
     for (const BufferUsageEntry &Entry : Usage)
-      if (ResourceMasks[I] == Entry.first)
+      if (I == Entry.first)
         TempStream << ProcResource.Name << ",  " << Entry.second << '/'
                    << ProcResource.BufferSize << '\n';
   }

Modified: llvm/trunk/tools/llvm-mca/ResourcePressureView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/ResourcePressureView.cpp?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/ResourcePressureView.cpp (original)
+++ llvm/trunk/tools/llvm-mca/ResourcePressureView.cpp Sat Mar 10 08:55:07 2018
@@ -19,8 +19,7 @@ namespace mca {
 
 using namespace llvm;
 
-void ResourcePressureView::initialize(
-    const ArrayRef<uint64_t> ProcResourceMasks) {
+void ResourcePressureView::initialize() {
   // Populate the map of resource descriptors.
   unsigned R2VIndex = 0;
   const MCSchedModel &SM = STI.getSchedModel();
@@ -31,9 +30,7 @@ void ResourcePressureView::initialize(
     if (ProcResource.SubUnitsIdxBegin || !NumUnits)
       continue;
 
-    uint64_t ResourceMask = ProcResourceMasks[I];
-    Resource2VecIndex.insert(
-        std::pair<uint64_t, unsigned>(ResourceMask, R2VIndex));
+    Resource2VecIndex.insert(std::pair<uint64_t, unsigned>(I, R2VIndex));
     R2VIndex += ProcResource.NumUnits;
   }
 

Modified: llvm/trunk/tools/llvm-mca/ResourcePressureView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/ResourcePressureView.h?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/ResourcePressureView.h (original)
+++ llvm/trunk/tools/llvm-mca/ResourcePressureView.h Sat Mar 10 08:55:07 2018
@@ -87,14 +87,13 @@ class ResourcePressureView : public View
                                          unsigned Executions) const;
   void printResourcePressurePerInstruction(llvm::raw_ostream &OS,
                                            unsigned Executions) const;
-  void initialize(const llvm::ArrayRef<uint64_t> ProcResoureMasks);
+  void initialize();
 
 public:
   ResourcePressureView(const llvm::MCSubtargetInfo &ST,
-                       llvm::MCInstPrinter &Printer, const SourceMgr &SM,
-                       const llvm::ArrayRef<uint64_t> ProcResourceMasks)
+                       llvm::MCInstPrinter &Printer, const SourceMgr &SM)
       : STI(ST), MCIP(Printer), Source(SM) {
-    initialize(ProcResourceMasks);
+    initialize();
   }
 
   void onInstructionIssued(

Modified: llvm/trunk/tools/llvm-mca/Scheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.cpp?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.cpp Sat Mar 10 08:55:07 2018
@@ -46,9 +46,10 @@ void ResourceState::dump() const {
 // ResourceDescriptor. Map 'Resources' allows to quickly obtain ResourceState
 // objects from resource mask identifiers.
 void ResourceManager::addResource(const MCProcResourceDesc &Desc,
+                                  unsigned Index,
                                   uint64_t Mask) {
   assert(Resources.find(Mask) == Resources.end() && "Resource already added!");
-  Resources[Mask] = llvm::make_unique<ResourceState>(Desc, Mask);
+  Resources[Mask] = llvm::make_unique<ResourceState>(Desc, Index, Mask);
 }
 
 // Populate vector ProcResID2Mask with resource masks. One per each processor
@@ -219,6 +220,9 @@ void ResourceManager::issueInstruction(
       ResourceRef Pipe = selectPipe(R.first);
       use(Pipe);
       BusyResources[Pipe] += CS.size();
+      // Replace the resource mask with a valid processor resource index.
+      const ResourceState &RS = *Resources[Pipe.first];
+      Pipe.first = RS.getProcResourceID();
       Pipes.emplace_back(std::pair<ResourceRef, unsigned>(Pipe, CS.size()));
     } else {
       assert((countPopulation(R.first) > 1) && "Expected a group!");

Modified: llvm/trunk/tools/llvm-mca/Scheduler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.h?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.h (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.h Sat Mar 10 08:55:07 2018
@@ -56,6 +56,8 @@ enum ResourceStateEvent {
 /// Internally, ResourceState uses a round-robin selector to identify
 /// which unit of the group shall be used next.
 class ResourceState {
+  // Index to the MCProcResourceDesc in the processor Model.
+  unsigned ProcResourceDescIndex;
   // A resource unique identifier generated by the tool.
   // For processor resource groups, the number of number of bits set in this
   // mask is equivalent to the cardinality of the group plus one.
@@ -181,8 +183,9 @@ class ResourceState {
   }
 
 public:
-  ResourceState(const llvm::MCProcResourceDesc &Desc, uint64_t Mask)
-      : ResourceMask(Mask) {
+  ResourceState(const llvm::MCProcResourceDesc &Desc, unsigned Index,
+                uint64_t Mask)
+      : ProcResourceDescIndex(Index), ResourceMask(Mask) {
     bool IsAGroup = llvm::countPopulation(ResourceMask) > 1;
     ResourceSizeMask = IsAGroup ? computeResourceSizeMaskForGroup(ResourceMask)
                                 : ((1ULL << Desc.NumUnits) - 1);
@@ -195,6 +198,7 @@ public:
     Unavailable = false;
   }
 
+  unsigned getProcResourceID() const { return ProcResourceDescIndex; }
   uint64_t getResourceMask() const { return ResourceMask; }
   int getBufferSize() const { return BufferSize; }
   unsigned getMaxUsedSlots() const { return MaxUsedSlots; }
@@ -274,9 +278,9 @@ public:
 /// 'second' index is an index for a "sub-resource" (i.e. unit).
 typedef std::pair<uint64_t, uint64_t> ResourceRef;
 
-// First: a resource mask identifying a buffered resource.
+// First: a MCProcResourceDesc index identifying a buffered resource.
 // Second: max number of buffer entries used in this resource.
-typedef std::pair<uint64_t, unsigned> BufferUsageEntry;
+typedef std::pair<unsigned, unsigned> BufferUsageEntry;
 
 /// A resource manager for processor resource units and groups.
 ///
@@ -300,7 +304,8 @@ class ResourceManager {
 
   // Adds a new resource state in Resources, as well as a new descriptor in
   // ResourceDescriptor.
-  void addResource(const llvm::MCProcResourceDesc &Desc, uint64_t Mask);
+  void addResource(const llvm::MCProcResourceDesc &Desc, unsigned Index,
+                   uint64_t Mask);
 
   // Compute processor resource masks for each processor resource declared by
   // the scheduling model.
@@ -310,7 +315,7 @@ class ResourceManager {
   void initialize(const llvm::MCSchedModel &SM) {
     computeProcResourceMasks(SM);
     for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I)
-      addResource(*SM.getProcResource(I), ProcResID2Mask[I]);
+      addResource(*SM.getProcResource(I), I, ProcResID2Mask[I]);
   }
 
   // Returns the actual resource unit that will be used.
@@ -400,7 +405,7 @@ public:
     for (const std::pair<uint64_t, UniqueResourceState> &Resource : Resources) {
       const ResourceState &RS = *Resource.second;
       if (RS.isBuffered())
-        Usage.emplace_back(std::pair<uint64_t, unsigned>(RS.getResourceMask(),
+        Usage.emplace_back(std::pair<unsigned, unsigned>(RS.getProcResourceID(),
                                                          RS.getMaxUsedSlots()));
     }
   }

Modified: llvm/trunk/tools/llvm-mca/llvm-mca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/llvm-mca.cpp?rev=327214&r1=327213&r2=327214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Sat Mar 10 08:55:07 2018
@@ -335,8 +335,7 @@ int main(int argc, char **argv) {
   }
 
   std::unique_ptr<mca::ResourcePressureView> RPV =
-      llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, *S,
-                                                   B->getProcResourceMasks());
+      llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, *S);
   Printer->addView(std::move(RPV));
 
   if (PrintTimelineView) {




More information about the llvm-commits mailing list