[llvm] r327128 - [llvm-mca] Move the logic that prints the summary into its own view. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 9 05:52:03 PST 2018


Author: adibiagio
Date: Fri Mar  9 05:52:03 2018
New Revision: 327128

URL: http://llvm.org/viewvc/llvm-project?rev=327128&view=rev
Log:
[llvm-mca] Move the logic that prints the summary into its own view. NFCI


Added:
    llvm/trunk/tools/llvm-mca/SummaryView.cpp
    llvm/trunk/tools/llvm-mca/SummaryView.h
Modified:
    llvm/trunk/tools/llvm-mca/BackendPrinter.cpp
    llvm/trunk/tools/llvm-mca/BackendPrinter.h
    llvm/trunk/tools/llvm-mca/CMakeLists.txt
    llvm/trunk/tools/llvm-mca/llvm-mca.cpp

Modified: llvm/trunk/tools/llvm-mca/BackendPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/BackendPrinter.cpp?rev=327128&r1=327127&r2=327128&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/BackendPrinter.cpp (original)
+++ llvm/trunk/tools/llvm-mca/BackendPrinter.cpp Fri Mar  9 05:52:03 2018
@@ -20,76 +20,7 @@ namespace mca {
 
 using namespace llvm;
 
-void BackendPrinter::printGeneralStatistics(raw_ostream &OS,
-                                            unsigned Iterations,
-                                            unsigned Cycles,
-                                            unsigned Instructions,
-                                            unsigned DispatchWidth) const {
-  unsigned TotalInstructions = Instructions * Iterations;
-  double IPC = (double)TotalInstructions / Cycles;
-
-  std::string Buffer;
-  raw_string_ostream TempStream(Buffer);
-  TempStream << "Iterations:     " << Iterations;
-  TempStream << "\nInstructions:   " << TotalInstructions;
-  TempStream << "\nTotal Cycles:   " << Cycles;
-  TempStream << "\nDispatch Width: " << DispatchWidth;
-  TempStream << "\nIPC:            " << format("%.2f", IPC) << '\n';
-  TempStream.flush();
-  OS << Buffer;
-}
-
-void BackendPrinter::printInstructionInfo(raw_ostream &OS) const {
-  std::string Buffer;
-  raw_string_ostream TempStream(Buffer);
-
-  TempStream << "\n\nInstruction Info:\n";
-  TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n"
-             << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects\n\n";
-
-  TempStream << "[1]    [2]    [3]    [4]    [5]    [6]\tInstructions:\n";
-  for (unsigned I = 0, E = B.getNumInstructions(); 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);
-    TempStream << ' ' << NumMicroOpcodes << "    ";
-    if (NumMicroOpcodes < 10)
-      TempStream << "  ";
-    else if (NumMicroOpcodes < 100)
-      TempStream << ' ';
-    TempStream << Latency << "   ";
-    if (Latency < 10.0)
-      TempStream << "  ";
-    else if (Latency < 100.0)
-      TempStream << ' ';
-    if (RThroughput) {
-      TempStream << format("%.2f", RThroughput) << ' ';
-      if (RThroughput < 10.0)
-        TempStream << "  ";
-      else if (RThroughput < 100.0)
-        TempStream << ' ';
-    } else {
-      TempStream << " -     ";
-    }
-    TempStream << (ID.MayLoad ? " *     " : "       ");
-    TempStream << (ID.MayStore ? " *     " : "       ");
-    TempStream << (ID.HasSideEffects ? " * " : "   ");
-    MCIP.printInst(&Inst, TempStream, "", B.getSTI());
-    TempStream << '\n';
-  }
-
-  TempStream.flush();
-  OS << Buffer;
-}
-
 void BackendPrinter::printReport(llvm::raw_ostream &OS) const {
-  unsigned Cycles = B.getNumCycles();
-  printGeneralStatistics(OS, B.getNumIterations(), Cycles, B.getNumInstructions(),
-                         B.getDispatchWidth());
-  printInstructionInfo(OS);
-
   for (const auto &V : Views)
     V->printView(OS);
 }

Modified: llvm/trunk/tools/llvm-mca/BackendPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/BackendPrinter.h?rev=327128&r1=327127&r2=327128&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/BackendPrinter.h (original)
+++ llvm/trunk/tools/llvm-mca/BackendPrinter.h Fri Mar  9 05:52:03 2018
@@ -10,10 +10,7 @@
 ///
 /// This file implements class BackendPrinter.
 ///
-/// BackendPrinter allows the customization of the performance report.  With the
-/// help of this class, users can specify their own custom sequence of views.
-/// Each view is then printed out in sequence when method printReport() is
-/// called.
+/// BackendPrinter allows the customization of the performance report.
 ///
 //===----------------------------------------------------------------------===//
 
@@ -21,15 +18,14 @@
 #define LLVM_TOOLS_LLVM_MCA_BACKENDPRINTER_H
 
 #include "Backend.h"
+#include "View.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/MC/MCInstPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 
 #define DEBUG_TYPE "llvm-mca"
 
 namespace mca {
 
-class View;
 
 /// \brief A printer class that knows how to collects statistics on the
 /// code analyzed by the llvm-mca tool.
@@ -39,23 +35,17 @@ class View;
 /// classes the task of printing out timeline information as well as
 /// resource pressure.
 class BackendPrinter {
-  const Backend &B;
-  llvm::MCInstPrinter &MCIP;
+  Backend &B;
   llvm::SmallVector<std::unique_ptr<View>, 8> Views;
 
-  void printGeneralStatistics(llvm::raw_ostream &OS,
-                              unsigned Iterations, unsigned Cycles,
-                              unsigned Instructions,
-                              unsigned DispatchWidth) const;
-  void printInstructionInfo(llvm::raw_ostream &OS) const;
-
 public:
-  BackendPrinter(const Backend &backend, llvm::MCInstPrinter &IP)
-      : B(backend), MCIP(IP) {}
+  BackendPrinter(Backend &backend) : B(backend) {}
 
-  llvm::MCInstPrinter &getMCInstPrinter() const { return MCIP; }
+  void addView(std::unique_ptr<View> V) {
+    B.addEventListener(V.get());
+    Views.emplace_back(std::move(V));
+  }
 
-  void addView(std::unique_ptr<View> V) { Views.emplace_back(std::move(V)); }
   void printReport(llvm::raw_ostream &OS) const;
 };
 

Modified: llvm/trunk/tools/llvm-mca/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/CMakeLists.txt?rev=327128&r1=327127&r2=327128&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-mca/CMakeLists.txt Fri Mar  9 05:52:03 2018
@@ -22,5 +22,6 @@ add_llvm_tool(llvm-mca
   ResourcePressureView.cpp
   Scheduler.cpp
   TimelineView.cpp
+  SummaryView.cpp
   View.cpp
   )

Added: llvm/trunk/tools/llvm-mca/SummaryView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/SummaryView.cpp?rev=327128&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-mca/SummaryView.cpp (added)
+++ llvm/trunk/tools/llvm-mca/SummaryView.cpp Fri Mar  9 05:52:03 2018
@@ -0,0 +1,83 @@
+//===--------------------- SummaryView.cpp -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+///
+/// This file implements the functionalities used by the SummaryView to print
+/// the report information.
+///
+//===----------------------------------------------------------------------===//
+
+#include "SummaryView.h"
+#include "llvm/CodeGen/TargetSchedule.h"
+
+namespace mca {
+
+using namespace llvm;
+
+void SummaryView::printSummary(raw_ostream &OS) const {
+  unsigned TotalInstructions = Instructions * Iterations;
+  double IPC = (double)TotalInstructions / TotalCycles;
+
+  std::string Buffer;
+  raw_string_ostream TempStream(Buffer);
+  TempStream << "Iterations:     " << Iterations;
+  TempStream << "\nInstructions:   " << TotalInstructions;
+  TempStream << "\nTotal Cycles:   " << TotalCycles;
+  TempStream << "\nDispatch Width: " << DispatchWidth;
+  TempStream << "\nIPC:            " << format("%.2f", IPC) << '\n';
+  TempStream.flush();
+  OS << Buffer;
+}
+
+void SummaryView::printInstructionInfo(raw_ostream &OS) const {
+  std::string Buffer;
+  raw_string_ostream TempStream(Buffer);
+
+  TempStream << "\n\nInstruction Info:\n";
+  TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n"
+             << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects\n\n";
+
+  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);
+    TempStream << ' ' << NumMicroOpcodes << "    ";
+    if (NumMicroOpcodes < 10)
+      TempStream << "  ";
+    else if (NumMicroOpcodes < 100)
+      TempStream << ' ';
+    TempStream << Latency << "   ";
+    if (Latency < 10.0)
+      TempStream << "  ";
+    else if (Latency < 100.0)
+      TempStream << ' ';
+    if (RThroughput) {
+      TempStream << format("%.2f", RThroughput) << ' ';
+      if (RThroughput < 10.0)
+        TempStream << "  ";
+      else if (RThroughput < 100.0)
+        TempStream << ' ';
+    } else {
+      TempStream << " -     ";
+    }
+    TempStream << (ID.MayLoad ? " *     " : "       ");
+    TempStream << (ID.MayStore ? " *     " : "       ");
+    TempStream << (ID.HasSideEffects ? " * " : "   ");
+    MCIP.printInst(&Inst, TempStream, "", B.getSTI());
+    TempStream << '\n';
+  }
+
+  TempStream.flush();
+  OS << Buffer;
+}
+
+} // namespace mca.

Added: llvm/trunk/tools/llvm-mca/SummaryView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/SummaryView.h?rev=327128&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-mca/SummaryView.h (added)
+++ llvm/trunk/tools/llvm-mca/SummaryView.h Fri Mar  9 05:52:03 2018
@@ -0,0 +1,95 @@
+//===--------------------- SummaryView.h ---------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+///
+/// This file implements the summary view.
+///
+/// The goal of the summary view is to give a very quick overview of the
+/// performance throughput. Below is an example of summary view:
+///
+///
+/// Iterations:     300
+/// Instructions:   900
+/// Total Cycles:   610
+/// Dispatch Width: 2
+/// IPC:            1.48
+///
+///
+/// Instruction Info:
+/// [1]: #uOps
+/// [2]: Latency
+/// [3]: RThroughput
+/// [4]: MayLoad
+/// [5]: MayStore
+/// [6]: HasSideEffects
+///
+/// [1]    [2]    [3]    [4]    [5]    [6]	Instructions:
+///  1      2     1.00                    	vmulps	%xmm0, %xmm1, %xmm2
+///  1      3     1.00                    	vhaddps	%xmm2, %xmm2, %xmm3
+///  1      3     1.00                    	vhaddps	%xmm3, %xmm3, %xmm4
+///
+/// The summary view is structured in two sections.
+///
+/// The first section collects a a few performance numbers. The two main
+/// performance indicators are 'Total Cycles' and IPC (Instructions Per Cycle).
+///
+/// The second section shows the latency and reciprocal throughput of every
+/// instruction in the sequence. This section also reports extra informaton
+/// related to the number of micro opcodes, and opcode properties (i.e.
+/// 'MayLoad', 'MayStore', 'HasSideEffects)
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
+#define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
+
+#include "Backend.h"
+#include "View.h"
+#include "llvm/MC/MCInstPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+
+#define DEBUG_TYPE "llvm-mca"
+
+namespace mca {
+
+/// \brief A printer class that knows how to collects statistics on the
+/// code analyzed by the llvm-mca tool.
+///
+/// This class knows how to print out the analysis information collected
+/// during the execution of the code. Internally, it delegates to other
+/// classes the task of printing out timeline information as well as
+/// resource pressure.
+class SummaryView : public View {
+  const Backend &B;
+  llvm::MCInstPrinter &MCIP;
+  const unsigned Iterations;
+  const unsigned Instructions;
+  const unsigned DispatchWidth;
+  unsigned TotalCycles;
+
+  void printSummary(llvm::raw_ostream &OS) const;
+  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) {}
+
+  void onCycleEnd(unsigned /* unused */) override { ++TotalCycles; }
+
+  void printView(llvm::raw_ostream &OS) const override {
+    printSummary(OS);
+    printInstructionInfo(OS);
+  }
+};
+
+} // namespace mca
+
+#endif

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=327128&r1=327127&r2=327128&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Fri Mar  9 05:52:03 2018
@@ -24,6 +24,7 @@
 #include "BackendPrinter.h"
 #include "BackendStatistics.h"
 #include "ResourcePressureView.h"
+#include "SummaryView.h"
 #include "TimelineView.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
@@ -321,26 +322,27 @@ int main(int argc, char **argv) {
       LoadQueueSize, StoreQueueSize, AssumeNoAlias);
 
   std::unique_ptr<mca::BackendPrinter> Printer =
-      llvm::make_unique<mca::BackendPrinter>(*B, *IP);
+      llvm::make_unique<mca::BackendPrinter>(*B);
+
+  std::unique_ptr<mca::SummaryView> SV = llvm::make_unique<mca::SummaryView>(
+      *B, *IP, S->getNumIterations(), S->size(), Width);
+  Printer->addView(std::move(SV));
 
   if (PrintModeVerbose) {
     std::unique_ptr<mca::BackendStatistics> BS =
         llvm::make_unique<mca::BackendStatistics>(*B);
-    B->addEventListener(BS.get());
     Printer->addView(std::move(BS));
   }
 
   std::unique_ptr<mca::ResourcePressureView> RPV =
       llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, *S,
                                                    B->getProcResourceMasks());
-  B->addEventListener(RPV.get());
   Printer->addView(std::move(RPV));
 
   if (PrintTimelineView) {
     std::unique_ptr<mca::TimelineView> TV =
         llvm::make_unique<mca::TimelineView>(
             *STI, *IP, *S, TimelineMaxIterations, TimelineMaxCycles);
-    B->addEventListener(TV.get());
     Printer->addView(std::move(TV));
   }
 




More information about the llvm-commits mailing list