diff options
Diffstat (limited to 'llvm/tools/llvm-mca')
-rw-r--r-- | llvm/tools/llvm-mca/BackendPrinter.cpp | 69 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/BackendPrinter.h | 26 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/SummaryView.cpp | 83 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/SummaryView.h | 95 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/llvm-mca.cpp | 10 |
6 files changed, 193 insertions, 91 deletions
diff --git a/llvm/tools/llvm-mca/BackendPrinter.cpp b/llvm/tools/llvm-mca/BackendPrinter.cpp index d98082ad237..7772903a3d7 100644 --- a/llvm/tools/llvm-mca/BackendPrinter.cpp +++ b/llvm/tools/llvm-mca/BackendPrinter.cpp @@ -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); } diff --git a/llvm/tools/llvm-mca/BackendPrinter.h b/llvm/tools/llvm-mca/BackendPrinter.h index f018cc830f8..d8ab123b679 100644 --- a/llvm/tools/llvm-mca/BackendPrinter.h +++ b/llvm/tools/llvm-mca/BackendPrinter.h @@ -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; }; diff --git a/llvm/tools/llvm-mca/CMakeLists.txt b/llvm/tools/llvm-mca/CMakeLists.txt index e6a743551cd..126c75e18f7 100644 --- a/llvm/tools/llvm-mca/CMakeLists.txt +++ b/llvm/tools/llvm-mca/CMakeLists.txt @@ -22,5 +22,6 @@ add_llvm_tool(llvm-mca ResourcePressureView.cpp Scheduler.cpp TimelineView.cpp + SummaryView.cpp View.cpp ) diff --git a/llvm/tools/llvm-mca/SummaryView.cpp b/llvm/tools/llvm-mca/SummaryView.cpp new file mode 100644 index 00000000000..7b1252ad057 --- /dev/null +++ b/llvm/tools/llvm-mca/SummaryView.cpp @@ -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. diff --git a/llvm/tools/llvm-mca/SummaryView.h b/llvm/tools/llvm-mca/SummaryView.h new file mode 100644 index 00000000000..d42d60c6e69 --- /dev/null +++ b/llvm/tools/llvm-mca/SummaryView.h @@ -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 diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index efc20e926b7..6e14f0b0caa 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -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)); } |