1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

[llvm-mca] Split the InstructionInfoView from the SummaryView.

llvm-svn: 328358
This commit is contained in:
Andrea Di Biagio 2018-03-23 19:40:04 +00:00
parent 75bf396b72
commit 90cef4c604
6 changed files with 155 additions and 106 deletions

View File

@ -17,6 +17,7 @@ add_llvm_tool(llvm-mca
HWEventListener.cpp
InstrBuilder.cpp
Instruction.cpp
InstructionInfoView.cpp
LSUnit.cpp
llvm-mca.cpp
ResourcePressureView.cpp

View File

@ -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<double> 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.

View File

@ -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

View File

@ -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<double> 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.

View File

@ -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

View File

@ -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<mca::BackendPrinter> Printer =
llvm::make_unique<mca::BackendPrinter>(*B);
Printer->addView(llvm::make_unique<mca::SummaryView>(*S, Width));
Printer->addView(
llvm::make_unique<mca::SummaryView>(*STI, *MCII, *S, *IP, Width));
llvm::make_unique<mca::InstructionInfoView>(*STI, *MCII, *S, *IP));
if (PrintModeVerbose)
Printer->addView(llvm::make_unique<mca::BackendStatistics>(*STI));