From df5d9486aa4e044b0d7954689fa578fae02e06a0 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Fri, 23 Mar 2018 19:40:04 +0000 Subject: [PATCH] [llvm-mca] Split the InstructionInfoView from the SummaryView. llvm-svn: 328358 --- llvm/tools/llvm-mca/CMakeLists.txt | 1 + llvm/tools/llvm-mca/InstructionInfoView.cpp | 75 +++++++++++++++++++++++++++++ llvm/tools/llvm-mca/InstructionInfoView.h | 66 +++++++++++++++++++++++++ llvm/tools/llvm-mca/SummaryView.cpp | 60 ++--------------------- llvm/tools/llvm-mca/SummaryView.h | 54 ++------------------- llvm/tools/llvm-mca/llvm-mca.cpp | 5 +- 6 files changed, 155 insertions(+), 106 deletions(-) create mode 100644 llvm/tools/llvm-mca/InstructionInfoView.cpp create mode 100644 llvm/tools/llvm-mca/InstructionInfoView.h diff --git a/llvm/tools/llvm-mca/CMakeLists.txt b/llvm/tools/llvm-mca/CMakeLists.txt index 99db82b..9358c08 100644 --- a/llvm/tools/llvm-mca/CMakeLists.txt +++ b/llvm/tools/llvm-mca/CMakeLists.txt @@ -17,6 +17,7 @@ add_llvm_tool(llvm-mca HWEventListener.cpp InstrBuilder.cpp Instruction.cpp + InstructionInfoView.cpp LSUnit.cpp llvm-mca.cpp ResourcePressureView.cpp diff --git a/llvm/tools/llvm-mca/InstructionInfoView.cpp b/llvm/tools/llvm-mca/InstructionInfoView.cpp new file mode 100644 index 0000000..289ca03 --- /dev/null +++ b/llvm/tools/llvm-mca/InstructionInfoView.cpp @@ -0,0 +1,75 @@ +//===--------------------- InstructionInfoView.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 InstructionView API. +/// +//===----------------------------------------------------------------------===// + +#include "InstructionInfoView.h" + +namespace mca { + +using namespace llvm; + +void InstructionInfoView::printView(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" + << "[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 = 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 RThroughput = + MCSchedModel::getReciprocalThroughput(STI, SCDesc); + + TempStream << ' ' << NumMicroOpcodes << " "; + if (NumMicroOpcodes < 10) + TempStream << " "; + else if (NumMicroOpcodes < 100) + TempStream << ' '; + TempStream << Latency << " "; + if (Latency < 10) + TempStream << " "; + else if (Latency < 100) + TempStream << ' '; + + if (RThroughput.hasValue()) { + double RT = RThroughput.getValue(); + TempStream << format("%.2f", RT) << ' '; + if (RT < 10.0) + TempStream << " "; + else if (RT < 100.0) + TempStream << ' '; + } else { + TempStream << " - "; + } + TempStream << (MCDesc.mayLoad() ? " * " : " "); + TempStream << (MCDesc.mayStore() ? " * " : " "); + TempStream << (MCDesc.hasUnmodeledSideEffects() ? " * " : " "); + MCIP.printInst(&Inst, TempStream, "", STI); + TempStream << '\n'; + } + + TempStream.flush(); + OS << Buffer; +} +} // namespace mca. diff --git a/llvm/tools/llvm-mca/InstructionInfoView.h b/llvm/tools/llvm-mca/InstructionInfoView.h new file mode 100644 index 0000000..85d0644 --- /dev/null +++ b/llvm/tools/llvm-mca/InstructionInfoView.h @@ -0,0 +1,66 @@ +//===--------------------- InstructionInfoView.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 instruction info view. +/// +/// The goal fo the instruction info view is to print the latency and reciprocal +/// throughput information for every instruction in the input sequence. +/// This section also reports extra information related to the number of micro +/// opcodes, and opcode properties (i.e. 'MayLoad', 'MayStore', 'HasSideEffects) +/// +/// Example: +/// +/// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H +#define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H + +#include "SourceMgr.h" +#include "View.h" +#include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/Support/raw_ostream.h" + +#define DEBUG_TYPE "llvm-mca" + +namespace mca { + +/// \brief A view that prints out generic instruction information. +class InstructionInfoView : public View { + const llvm::MCSubtargetInfo &STI; + const llvm::MCInstrInfo &MCII; + const SourceMgr &Source; + llvm::MCInstPrinter &MCIP; + +public: + InstructionInfoView(const llvm::MCSubtargetInfo &sti, + const llvm::MCInstrInfo &mcii, const SourceMgr &S, + llvm::MCInstPrinter &IP) + : STI(sti), MCII(mcii), Source(S), MCIP(IP) {} + + void printView(llvm::raw_ostream &OS) const override; +}; +} // namespace mca + +#endif diff --git a/llvm/tools/llvm-mca/SummaryView.cpp b/llvm/tools/llvm-mca/SummaryView.cpp index ccc7e5d..f7d0900 100644 --- a/llvm/tools/llvm-mca/SummaryView.cpp +++ b/llvm/tools/llvm-mca/SummaryView.cpp @@ -14,13 +14,15 @@ //===----------------------------------------------------------------------===// #include "SummaryView.h" -#include "llvm/CodeGen/TargetSchedule.h" +#include "llvm/Support/Format.h" namespace mca { +#define DEBUG_TYPE "llvm-mca" + using namespace llvm; -void SummaryView::printSummary(raw_ostream &OS) const { +void SummaryView::printView(raw_ostream &OS) const { unsigned Iterations = Source.getNumIterations(); unsigned Instructions = Source.size(); unsigned TotalInstructions = Instructions * Iterations; @@ -37,58 +39,4 @@ void SummaryView::printSummary(raw_ostream &OS) const { OS << Buffer; } -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" - << "[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 = 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 RThroughput = - MCSchedModel::getReciprocalThroughput(STI, SCDesc); - - TempStream << ' ' << NumMicroOpcodes << " "; - if (NumMicroOpcodes < 10) - TempStream << " "; - else if (NumMicroOpcodes < 100) - TempStream << ' '; - TempStream << Latency << " "; - if (Latency < 10) - TempStream << " "; - else if (Latency < 100) - TempStream << ' '; - - if (RThroughput.hasValue()) { - double RT = RThroughput.getValue(); - TempStream << format("%.2f", RT) << ' '; - if (RT < 10.0) - TempStream << " "; - else if (RT < 100.0) - TempStream << ' '; - } else { - TempStream << " - "; - } - TempStream << (MCDesc.mayLoad() ? " * " : " "); - TempStream << (MCDesc.mayStore() ? " * " : " "); - TempStream << (MCDesc.hasUnmodeledSideEffects() ? " * " : " "); - MCIP.printInst(&Inst, TempStream, "", STI); - TempStream << '\n'; - } - - TempStream.flush(); - OS << Buffer; -} - } // namespace mca. diff --git a/llvm/tools/llvm-mca/SummaryView.h b/llvm/tools/llvm-mca/SummaryView.h index db2d4c4..083e6b0 100644 --- a/llvm/tools/llvm-mca/SummaryView.h +++ b/llvm/tools/llvm-mca/SummaryView.h @@ -21,29 +21,9 @@ /// 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 +/// The summary view collects 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 @@ -51,48 +31,24 @@ #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" - 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. +/// \brief A view that collects and prints a few performance numbers. class SummaryView : public View { - const llvm::MCSubtargetInfo &STI; - const llvm::MCInstrInfo &MCII; const SourceMgr &Source; - llvm::MCInstPrinter &MCIP; - const unsigned DispatchWidth; unsigned TotalCycles; - void printSummary(llvm::raw_ostream &OS) const; - void printInstructionInfo(llvm::raw_ostream &OS) const; - public: - 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) {} + SummaryView(const SourceMgr &S, unsigned Width) + : Source(S), DispatchWidth(Width), TotalCycles(0) {} void onCycleEnd(unsigned /* unused */) override { ++TotalCycles; } - void printView(llvm::raw_ostream &OS) const override { - printSummary(OS); - printInstructionInfo(OS); - } + void printView(llvm::raw_ostream &OS) const override; }; - } // namespace mca #endif diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index 5c085af..2ddba76 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -23,6 +23,7 @@ #include "BackendPrinter.h" #include "BackendStatistics.h" +#include "InstructionInfoView.h" #include "ResourcePressureView.h" #include "SummaryView.h" #include "TimelineView.h" @@ -332,8 +333,10 @@ int main(int argc, char **argv) { std::unique_ptr Printer = llvm::make_unique(*B); + Printer->addView(llvm::make_unique(*S, Width)); + Printer->addView( - llvm::make_unique(*STI, *MCII, *S, *IP, Width)); + llvm::make_unique(*STI, *MCII, *S, *IP)); if (PrintModeVerbose) Printer->addView(llvm::make_unique(*STI)); -- 2.7.4