Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit 0d15ae3

Browse files
committed
[llvm-mca] Move the logic that prints the summary into its own view. NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327128 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e9b1df3 commit 0d15ae3

File tree

6 files changed

+193
-91
lines changed

6 files changed

+193
-91
lines changed

tools/llvm-mca/BackendPrinter.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,7 @@ namespace mca {
2020

2121
using namespace llvm;
2222

23-
void BackendPrinter::printGeneralStatistics(raw_ostream &OS,
24-
unsigned Iterations,
25-
unsigned Cycles,
26-
unsigned Instructions,
27-
unsigned DispatchWidth) const {
28-
unsigned TotalInstructions = Instructions * Iterations;
29-
double IPC = (double)TotalInstructions / Cycles;
30-
31-
std::string Buffer;
32-
raw_string_ostream TempStream(Buffer);
33-
TempStream << "Iterations: " << Iterations;
34-
TempStream << "\nInstructions: " << TotalInstructions;
35-
TempStream << "\nTotal Cycles: " << Cycles;
36-
TempStream << "\nDispatch Width: " << DispatchWidth;
37-
TempStream << "\nIPC: " << format("%.2f", IPC) << '\n';
38-
TempStream.flush();
39-
OS << Buffer;
40-
}
41-
42-
void BackendPrinter::printInstructionInfo(raw_ostream &OS) const {
43-
std::string Buffer;
44-
raw_string_ostream TempStream(Buffer);
45-
46-
TempStream << "\n\nInstruction Info:\n";
47-
TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n"
48-
<< "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects\n\n";
49-
50-
TempStream << "[1] [2] [3] [4] [5] [6]\tInstructions:\n";
51-
for (unsigned I = 0, E = B.getNumInstructions(); I < E; ++I) {
52-
const MCInst &Inst = B.getMCInstFromIndex(I);
53-
const InstrDesc &ID = B.getInstrDesc(Inst);
54-
unsigned NumMicroOpcodes = ID.NumMicroOps;
55-
unsigned Latency = ID.MaxLatency;
56-
double RThroughput = B.getRThroughput(ID);
57-
TempStream << ' ' << NumMicroOpcodes << " ";
58-
if (NumMicroOpcodes < 10)
59-
TempStream << " ";
60-
else if (NumMicroOpcodes < 100)
61-
TempStream << ' ';
62-
TempStream << Latency << " ";
63-
if (Latency < 10.0)
64-
TempStream << " ";
65-
else if (Latency < 100.0)
66-
TempStream << ' ';
67-
if (RThroughput) {
68-
TempStream << format("%.2f", RThroughput) << ' ';
69-
if (RThroughput < 10.0)
70-
TempStream << " ";
71-
else if (RThroughput < 100.0)
72-
TempStream << ' ';
73-
} else {
74-
TempStream << " - ";
75-
}
76-
TempStream << (ID.MayLoad ? " * " : " ");
77-
TempStream << (ID.MayStore ? " * " : " ");
78-
TempStream << (ID.HasSideEffects ? " * " : " ");
79-
MCIP.printInst(&Inst, TempStream, "", B.getSTI());
80-
TempStream << '\n';
81-
}
82-
83-
TempStream.flush();
84-
OS << Buffer;
85-
}
86-
8723
void BackendPrinter::printReport(llvm::raw_ostream &OS) const {
88-
unsigned Cycles = B.getNumCycles();
89-
printGeneralStatistics(OS, B.getNumIterations(), Cycles, B.getNumInstructions(),
90-
B.getDispatchWidth());
91-
printInstructionInfo(OS);
92-
9324
for (const auto &V : Views)
9425
V->printView(OS);
9526
}

tools/llvm-mca/BackendPrinter.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,22 @@
1010
///
1111
/// This file implements class BackendPrinter.
1212
///
13-
/// BackendPrinter allows the customization of the performance report. With the
14-
/// help of this class, users can specify their own custom sequence of views.
15-
/// Each view is then printed out in sequence when method printReport() is
16-
/// called.
13+
/// BackendPrinter allows the customization of the performance report.
1714
///
1815
//===----------------------------------------------------------------------===//
1916

2017
#ifndef LLVM_TOOLS_LLVM_MCA_BACKENDPRINTER_H
2118
#define LLVM_TOOLS_LLVM_MCA_BACKENDPRINTER_H
2219

2320
#include "Backend.h"
21+
#include "View.h"
2422
#include "llvm/ADT/SmallVector.h"
25-
#include "llvm/MC/MCInstPrinter.h"
2623
#include "llvm/Support/raw_ostream.h"
2724

2825
#define DEBUG_TYPE "llvm-mca"
2926

3027
namespace mca {
3128

32-
class View;
3329

3430
/// \brief A printer class that knows how to collects statistics on the
3531
/// code analyzed by the llvm-mca tool.
@@ -39,23 +35,17 @@ class View;
3935
/// classes the task of printing out timeline information as well as
4036
/// resource pressure.
4137
class BackendPrinter {
42-
const Backend &B;
43-
llvm::MCInstPrinter &MCIP;
38+
Backend &B;
4439
llvm::SmallVector<std::unique_ptr<View>, 8> Views;
4540

46-
void printGeneralStatistics(llvm::raw_ostream &OS,
47-
unsigned Iterations, unsigned Cycles,
48-
unsigned Instructions,
49-
unsigned DispatchWidth) const;
50-
void printInstructionInfo(llvm::raw_ostream &OS) const;
51-
5241
public:
53-
BackendPrinter(const Backend &backend, llvm::MCInstPrinter &IP)
54-
: B(backend), MCIP(IP) {}
42+
BackendPrinter(Backend &backend) : B(backend) {}
5543

56-
llvm::MCInstPrinter &getMCInstPrinter() const { return MCIP; }
44+
void addView(std::unique_ptr<View> V) {
45+
B.addEventListener(V.get());
46+
Views.emplace_back(std::move(V));
47+
}
5748

58-
void addView(std::unique_ptr<View> V) { Views.emplace_back(std::move(V)); }
5949
void printReport(llvm::raw_ostream &OS) const;
6050
};
6151

tools/llvm-mca/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ add_llvm_tool(llvm-mca
2222
ResourcePressureView.cpp
2323
Scheduler.cpp
2424
TimelineView.cpp
25+
SummaryView.cpp
2526
View.cpp
2627
)

tools/llvm-mca/SummaryView.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//===--------------------- SummaryView.cpp -------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
/// \file
10+
///
11+
/// This file implements the functionalities used by the SummaryView to print
12+
/// the report information.
13+
///
14+
//===----------------------------------------------------------------------===//
15+
16+
#include "SummaryView.h"
17+
#include "llvm/CodeGen/TargetSchedule.h"
18+
19+
namespace mca {
20+
21+
using namespace llvm;
22+
23+
void SummaryView::printSummary(raw_ostream &OS) const {
24+
unsigned TotalInstructions = Instructions * Iterations;
25+
double IPC = (double)TotalInstructions / TotalCycles;
26+
27+
std::string Buffer;
28+
raw_string_ostream TempStream(Buffer);
29+
TempStream << "Iterations: " << Iterations;
30+
TempStream << "\nInstructions: " << TotalInstructions;
31+
TempStream << "\nTotal Cycles: " << TotalCycles;
32+
TempStream << "\nDispatch Width: " << DispatchWidth;
33+
TempStream << "\nIPC: " << format("%.2f", IPC) << '\n';
34+
TempStream.flush();
35+
OS << Buffer;
36+
}
37+
38+
void SummaryView::printInstructionInfo(raw_ostream &OS) const {
39+
std::string Buffer;
40+
raw_string_ostream TempStream(Buffer);
41+
42+
TempStream << "\n\nInstruction Info:\n";
43+
TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n"
44+
<< "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects\n\n";
45+
46+
TempStream << "[1] [2] [3] [4] [5] [6]\tInstructions:\n";
47+
for (unsigned I = 0, E = Instructions; I < E; ++I) {
48+
const MCInst &Inst = B.getMCInstFromIndex(I);
49+
const InstrDesc &ID = B.getInstrDesc(Inst);
50+
unsigned NumMicroOpcodes = ID.NumMicroOps;
51+
unsigned Latency = ID.MaxLatency;
52+
double RThroughput = B.getRThroughput(ID);
53+
TempStream << ' ' << NumMicroOpcodes << " ";
54+
if (NumMicroOpcodes < 10)
55+
TempStream << " ";
56+
else if (NumMicroOpcodes < 100)
57+
TempStream << ' ';
58+
TempStream << Latency << " ";
59+
if (Latency < 10.0)
60+
TempStream << " ";
61+
else if (Latency < 100.0)
62+
TempStream << ' ';
63+
if (RThroughput) {
64+
TempStream << format("%.2f", RThroughput) << ' ';
65+
if (RThroughput < 10.0)
66+
TempStream << " ";
67+
else if (RThroughput < 100.0)
68+
TempStream << ' ';
69+
} else {
70+
TempStream << " - ";
71+
}
72+
TempStream << (ID.MayLoad ? " * " : " ");
73+
TempStream << (ID.MayStore ? " * " : " ");
74+
TempStream << (ID.HasSideEffects ? " * " : " ");
75+
MCIP.printInst(&Inst, TempStream, "", B.getSTI());
76+
TempStream << '\n';
77+
}
78+
79+
TempStream.flush();
80+
OS << Buffer;
81+
}
82+
83+
} // namespace mca.

tools/llvm-mca/SummaryView.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//===--------------------- SummaryView.h ---------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
/// \file
10+
///
11+
/// This file implements the summary view.
12+
///
13+
/// The goal of the summary view is to give a very quick overview of the
14+
/// performance throughput. Below is an example of summary view:
15+
///
16+
///
17+
/// Iterations: 300
18+
/// Instructions: 900
19+
/// Total Cycles: 610
20+
/// Dispatch Width: 2
21+
/// IPC: 1.48
22+
///
23+
///
24+
/// Instruction Info:
25+
/// [1]: #uOps
26+
/// [2]: Latency
27+
/// [3]: RThroughput
28+
/// [4]: MayLoad
29+
/// [5]: MayStore
30+
/// [6]: HasSideEffects
31+
///
32+
/// [1] [2] [3] [4] [5] [6] Instructions:
33+
/// 1 2 1.00 vmulps %xmm0, %xmm1, %xmm2
34+
/// 1 3 1.00 vhaddps %xmm2, %xmm2, %xmm3
35+
/// 1 3 1.00 vhaddps %xmm3, %xmm3, %xmm4
36+
///
37+
/// The summary view is structured in two sections.
38+
///
39+
/// The first section collects a a few performance numbers. The two main
40+
/// performance indicators are 'Total Cycles' and IPC (Instructions Per Cycle).
41+
///
42+
/// The second section shows the latency and reciprocal throughput of every
43+
/// instruction in the sequence. This section also reports extra informaton
44+
/// related to the number of micro opcodes, and opcode properties (i.e.
45+
/// 'MayLoad', 'MayStore', 'HasSideEffects)
46+
///
47+
//===----------------------------------------------------------------------===//
48+
49+
#ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
50+
#define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
51+
52+
#include "Backend.h"
53+
#include "View.h"
54+
#include "llvm/MC/MCInstPrinter.h"
55+
#include "llvm/Support/raw_ostream.h"
56+
57+
#define DEBUG_TYPE "llvm-mca"
58+
59+
namespace mca {
60+
61+
/// \brief A printer class that knows how to collects statistics on the
62+
/// code analyzed by the llvm-mca tool.
63+
///
64+
/// This class knows how to print out the analysis information collected
65+
/// during the execution of the code. Internally, it delegates to other
66+
/// classes the task of printing out timeline information as well as
67+
/// resource pressure.
68+
class SummaryView : public View {
69+
const Backend &B;
70+
llvm::MCInstPrinter &MCIP;
71+
const unsigned Iterations;
72+
const unsigned Instructions;
73+
const unsigned DispatchWidth;
74+
unsigned TotalCycles;
75+
76+
void printSummary(llvm::raw_ostream &OS) const;
77+
void printInstructionInfo(llvm::raw_ostream &OS) const;
78+
79+
public:
80+
SummaryView(const Backend &backend, llvm::MCInstPrinter &IP,
81+
unsigned NumIterations, unsigned NumInstructions, unsigned Width)
82+
: B(backend), MCIP(IP), Iterations(NumIterations),
83+
Instructions(NumInstructions), DispatchWidth(Width), TotalCycles(0) {}
84+
85+
void onCycleEnd(unsigned /* unused */) override { ++TotalCycles; }
86+
87+
void printView(llvm::raw_ostream &OS) const override {
88+
printSummary(OS);
89+
printInstructionInfo(OS);
90+
}
91+
};
92+
93+
} // namespace mca
94+
95+
#endif

tools/llvm-mca/llvm-mca.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "BackendPrinter.h"
2525
#include "BackendStatistics.h"
2626
#include "ResourcePressureView.h"
27+
#include "SummaryView.h"
2728
#include "TimelineView.h"
2829
#include "llvm/MC/MCAsmInfo.h"
2930
#include "llvm/MC/MCContext.h"
@@ -321,26 +322,27 @@ int main(int argc, char **argv) {
321322
LoadQueueSize, StoreQueueSize, AssumeNoAlias);
322323

323324
std::unique_ptr<mca::BackendPrinter> Printer =
324-
llvm::make_unique<mca::BackendPrinter>(*B, *IP);
325+
llvm::make_unique<mca::BackendPrinter>(*B);
326+
327+
std::unique_ptr<mca::SummaryView> SV = llvm::make_unique<mca::SummaryView>(
328+
*B, *IP, S->getNumIterations(), S->size(), Width);
329+
Printer->addView(std::move(SV));
325330

326331
if (PrintModeVerbose) {
327332
std::unique_ptr<mca::BackendStatistics> BS =
328333
llvm::make_unique<mca::BackendStatistics>(*B);
329-
B->addEventListener(BS.get());
330334
Printer->addView(std::move(BS));
331335
}
332336

333337
std::unique_ptr<mca::ResourcePressureView> RPV =
334338
llvm::make_unique<mca::ResourcePressureView>(*STI, *IP, *S,
335339
B->getProcResourceMasks());
336-
B->addEventListener(RPV.get());
337340
Printer->addView(std::move(RPV));
338341

339342
if (PrintTimelineView) {
340343
std::unique_ptr<mca::TimelineView> TV =
341344
llvm::make_unique<mca::TimelineView>(
342345
*STI, *IP, *S, TimelineMaxIterations, TimelineMaxCycles);
343-
B->addEventListener(TV.get());
344346
Printer->addView(std::move(TV));
345347
}
346348

0 commit comments

Comments
 (0)