[llvm] r327425 - [llvm-mca] Remove the logic that computes the reciprocal throughput, and make the SummaryView independent from the Backend. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 13 10:24:32 PDT 2018


Author: adibiagio
Date: Tue Mar 13 10:24:32 2018
New Revision: 327425

URL: http://llvm.org/viewvc/llvm-project?rev=327425&view=rev
Log:
[llvm-mca] Remove the logic that computes the reciprocal throughput, and make the SummaryView independent from the Backend. NFCI

Since r327420, the tool can query the MCSchedModel interface to obtain the
reciprocal throughput information.
As a consequence, method `ResourceManager::getRThroughput`, and
method `Backend::getRThroughput` are no longer needed.

This patch simplifies the code by removing the custom RThroughput computation.
This patch also refactors class SummaryView by removing the dependency with
the Backend object.

No functional change intended.

Modified:
    llvm/trunk/tools/llvm-mca/Backend.h
    llvm/trunk/tools/llvm-mca/Scheduler.cpp
    llvm/trunk/tools/llvm-mca/Scheduler.h
    llvm/trunk/tools/llvm-mca/SummaryView.cpp
    llvm/trunk/tools/llvm-mca/SummaryView.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=327425&r1=327424&r2=327425&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Backend.h (original)
+++ llvm/trunk/tools/llvm-mca/Backend.h Tue Mar 13 10:24:32 2018
@@ -103,9 +103,6 @@ public:
     return STI.getSchedModel();
   }
 
-  double getRThroughput(const InstrDesc &ID) const {
-    return HWS->getRThroughput(ID);
-  }
   void getBuffersUsage(std::vector<BufferUsageEntry> &Usage) const {
     return HWS->getBuffersUsage(Usage);
   }

Modified: llvm/trunk/tools/llvm-mca/Scheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.cpp?rev=327425&r1=327424&r2=327425&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.cpp Tue Mar 13 10:24:32 2018
@@ -185,26 +185,6 @@ bool ResourceManager::mustIssueImmediate
                      });
 }
 
-double ResourceManager::getRThroughput(const InstrDesc &ID) const {
-  double RThroughput = 0;
-  for (const std::pair<uint64_t, ResourceUsage> &Usage : ID.Resources) {
-    const CycleSegment &CS = Usage.second.CS;
-    assert(CS.begin() == 0);
-
-    if (Usage.second.isReserved()) {
-      RThroughput = std::max(RThroughput, (double)CS.size());
-      continue;
-    }
-
-    unsigned Population = std::max(1U, countPopulation(Usage.first) - 1);
-    unsigned NumUnits = Population * getNumUnits(Usage.first);
-    NumUnits -= Usage.second.NumUnits - 1;
-    unsigned Cycles = CS.size();
-    RThroughput = std::max(RThroughput, (double)Cycles / NumUnits);
-  }
-  return RThroughput;
-}
-
 void ResourceManager::issueInstruction(
     unsigned Index, const InstrDesc &Desc,
     SmallVectorImpl<std::pair<ResourceRef, unsigned>> &Pipes) {

Modified: llvm/trunk/tools/llvm-mca/Scheduler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.h?rev=327425&r1=327424&r2=327425&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.h (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.h Tue Mar 13 10:24:32 2018
@@ -396,7 +396,6 @@ public:
   bool mustIssueImmediately(const InstrDesc &Desc);
 
   bool canBeIssued(const InstrDesc &Desc) const;
-  double getRThroughput(const InstrDesc &Desc) const;
 
   void issueInstruction(
       unsigned Index, const InstrDesc &Desc,
@@ -532,10 +531,6 @@ public:
   Event canBeDispatched(const InstrDesc &Desc) const;
   Instruction *scheduleInstruction(unsigned Idx, Instruction *MCIS);
 
-  double getRThroughput(const InstrDesc &Desc) const {
-    return Resources->getRThroughput(Desc);
-  }
-
   void cycleEvent(unsigned Cycle);
 
   void getBuffersUsage(std::vector<BufferUsageEntry> &Usage) const {

Modified: llvm/trunk/tools/llvm-mca/SummaryView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/SummaryView.cpp?rev=327425&r1=327424&r2=327425&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/SummaryView.cpp (original)
+++ llvm/trunk/tools/llvm-mca/SummaryView.cpp Tue Mar 13 10:24:32 2018
@@ -21,6 +21,8 @@ namespace mca {
 using namespace llvm;
 
 void SummaryView::printSummary(raw_ostream &OS) const {
+  unsigned Iterations = Source.getNumIterations();
+  unsigned Instructions = Source.size();
   unsigned TotalInstructions = Instructions * Iterations;
   double IPC = (double)TotalInstructions / TotalCycles;
 
@@ -38,6 +40,8 @@ void SummaryView::printSummary(raw_ostre
 void SummaryView::printInstructionInfo(raw_ostream &OS) const {
   std::string Buffer;
   raw_string_ostream TempStream(Buffer);
+  const MCSchedModel &SM = STI.getSchedModel();
+  unsigned Instructions = Source.size();
 
   TempStream << "\n\nInstruction Info:\n";
   TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n"
@@ -45,34 +49,41 @@ void SummaryView::printInstructionInfo(r
 
   TempStream << "[1]    [2]    [3]    [4]    [5]    [6]\tInstructions:\n";
   for (unsigned I = 0, E = Instructions; I < E; ++I) {
-    const MCInst &Inst = B.getMCInstFromIndex(I);
-    const InstrDesc &ID = B.getInstrDesc(Inst);
-    unsigned NumMicroOpcodes = ID.NumMicroOps;
-    unsigned Latency = ID.MaxLatency;
-    double RThroughput = B.getRThroughput(ID);
+    const MCInst &Inst = Source.getMCInstFromIndex(I);
+    const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode());
+    const MCSchedClassDesc &SCDesc =
+        *SM.getSchedClassDesc(MCDesc.getSchedClass());
+
+    unsigned NumMicroOpcodes = SCDesc.NumMicroOps;
+    unsigned Latency = MCSchedModel::computeInstrLatency(STI, SCDesc);
+    Optional<double> RThroughput =
+        MCSchedModel::getReciprocalThroughput(STI, SCDesc);
+
     TempStream << ' ' << NumMicroOpcodes << "    ";
     if (NumMicroOpcodes < 10)
       TempStream << "  ";
     else if (NumMicroOpcodes < 100)
       TempStream << ' ';
     TempStream << Latency << "   ";
-    if (Latency < 10.0)
+    if (Latency < 10)
       TempStream << "  ";
-    else if (Latency < 100.0)
+    else if (Latency < 100)
       TempStream << ' ';
-    if (RThroughput) {
-      TempStream << format("%.2f", RThroughput) << ' ';
-      if (RThroughput < 10.0)
+
+    if (RThroughput.hasValue()) {
+      double RT = RThroughput.getValue();
+      TempStream << format("%.2f", RT) << ' ';
+      if (RT < 10.0)
         TempStream << "  ";
-      else if (RThroughput < 100.0)
+      else if (RT < 100.0)
         TempStream << ' ';
     } else {
       TempStream << " -     ";
     }
-    TempStream << (ID.MayLoad ? " *     " : "       ");
-    TempStream << (ID.MayStore ? " *     " : "       ");
-    TempStream << (ID.HasSideEffects ? " * " : "   ");
-    MCIP.printInst(&Inst, TempStream, "", B.getSTI());
+    TempStream << (MCDesc.mayLoad() ? " *     " : "       ");
+    TempStream << (MCDesc.mayStore() ? " *     " : "       ");
+    TempStream << (MCDesc.hasUnmodeledSideEffects() ? " * " : "   ");
+    MCIP.printInst(&Inst, TempStream, "", STI);
     TempStream << '\n';
   }
 

Modified: llvm/trunk/tools/llvm-mca/SummaryView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/SummaryView.h?rev=327425&r1=327424&r2=327425&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/SummaryView.h (original)
+++ llvm/trunk/tools/llvm-mca/SummaryView.h Tue Mar 13 10:24:32 2018
@@ -49,9 +49,11 @@
 #ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
 #define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
 
-#include "Backend.h"
+#include "SourceMgr.h"
 #include "View.h"
 #include "llvm/MC/MCInstPrinter.h"
+#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/MCInstrInfo.h"
 #include "llvm/Support/raw_ostream.h"
 
 #define DEBUG_TYPE "llvm-mca"
@@ -66,10 +68,11 @@ namespace mca {
 /// classes the task of printing out timeline information as well as
 /// resource pressure.
 class SummaryView : public View {
-  const Backend &B;
+  const llvm::MCSubtargetInfo &STI;
+  const llvm::MCInstrInfo &MCII;
+  const SourceMgr &Source;
   llvm::MCInstPrinter &MCIP;
-  const unsigned Iterations;
-  const unsigned Instructions;
+
   const unsigned DispatchWidth;
   unsigned TotalCycles;
 
@@ -77,10 +80,10 @@ class SummaryView : public View {
   void printInstructionInfo(llvm::raw_ostream &OS) const;
 
 public:
-  SummaryView(const Backend &backend, llvm::MCInstPrinter &IP,
-              unsigned NumIterations, unsigned NumInstructions, unsigned Width)
-      : B(backend), MCIP(IP), Iterations(NumIterations),
-        Instructions(NumInstructions), DispatchWidth(Width), TotalCycles(0) {}
+  SummaryView(const llvm::MCSubtargetInfo &sti, const llvm::MCInstrInfo &mcii,
+              const SourceMgr &S, llvm::MCInstPrinter &IP, unsigned Width)
+      : STI(sti), MCII(mcii), Source(S), MCIP(IP), DispatchWidth(Width),
+        TotalCycles(0) {}
 
   void onCycleEnd(unsigned /* unused */) override { ++TotalCycles; }
 

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=327425&r1=327424&r2=327425&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Tue Mar 13 10:24:32 2018
@@ -324,8 +324,8 @@ int main(int argc, char **argv) {
   std::unique_ptr<mca::BackendPrinter> Printer =
       llvm::make_unique<mca::BackendPrinter>(*B);
 
-  std::unique_ptr<mca::SummaryView> SV = llvm::make_unique<mca::SummaryView>(
-      *B, *IP, S->getNumIterations(), S->size(), Width);
+  std::unique_ptr<mca::SummaryView> SV =
+      llvm::make_unique<mca::SummaryView>(*STI, *MCII, *S, *IP, Width);
   Printer->addView(std::move(SV));
 
   if (PrintModeVerbose) {




More information about the llvm-commits mailing list