blob: 28c3e0de1361ec562fabca740d375f867d9133e2 [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- BackendStatistics.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 a printer class for printing generic Backend
12/// statistics related to the dispatch logic, scheduler and retire unit.
13///
14/// Example:
15/// ========
16///
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000017/// Dynamic Dispatch Stall Cycles:
18/// RAT - Register unavailable: 0
19/// RCU - Retire tokens unavailable: 0
20/// SCHEDQ - Scheduler full: 42
21/// LQ - Load queue full: 0
22/// SQ - Store queue full: 0
23/// GROUP - Static restrictions on the dispatch group: 0
24///
25///
26/// Register Alias Table:
27/// Total number of mappings created: 210
28/// Max number of mappings used: 35
29///
30///
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000031/// Dispatch Logic - number of cycles where we saw N instructions dispatched:
32/// [# dispatched], [# cycles]
33/// 0, 15 (11.5%)
34/// 5, 4 (3.1%)
35///
36/// Schedulers - number of cycles where we saw N instructions issued:
37/// [# issued], [# cycles]
38/// 0, 7 (5.4%)
39/// 1, 4 (3.1%)
40/// 2, 8 (6.2%)
41///
42/// Retire Control Unit - number of cycles where we saw N instructions retired:
43/// [# retired], [# cycles]
44/// 0, 9 (6.9%)
45/// 1, 6 (4.6%)
46/// 2, 1 (0.8%)
47/// 4, 3 (2.3%)
48///
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000049///
50/// Scheduler's queue usage:
51/// JALU01, 0/20
52/// JFPU01, 18/18
53/// JLSAGU, 0/12
54///
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000055//===----------------------------------------------------------------------===//
56
57#ifndef LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H
58#define LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H
59
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000060#include "Backend.h"
61#include "View.h"
Andrea Di Biagio09771ad2018-03-16 22:21:52 +000062#include "llvm/MC/MCSubtargetInfo.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000063#include "llvm/Support/raw_ostream.h"
64#include <map>
65
66namespace mca {
67
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000068class BackendStatistics : public View {
69 // TODO: remove the dependency from Backend.
70 const Backend &B;
Andrea Di Biagio09771ad2018-03-16 22:21:52 +000071 const llvm::MCSubtargetInfo &STI;
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000072
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000073 using Histogram = std::map<unsigned, unsigned>;
74 Histogram DispatchGroupSizePerCycle;
75 Histogram RetiredPerCycle;
76 Histogram IssuedPerCycle;
77
78 unsigned NumDispatched;
79 unsigned NumIssued;
80 unsigned NumRetired;
81 unsigned NumCycles;
82
83 void updateHistograms() {
84 DispatchGroupSizePerCycle[NumDispatched]++;
85 IssuedPerCycle[NumIssued]++;
86 RetiredPerCycle[NumRetired]++;
87 NumDispatched = 0;
88 NumIssued = 0;
89 NumRetired = 0;
90 }
91
92 void printRetireUnitStatistics(llvm::raw_ostream &OS) const;
93 void printDispatchUnitStatistics(llvm::raw_ostream &OS) const;
94 void printSchedulerStatistics(llvm::raw_ostream &OS) const;
95
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000096 void printDispatchStalls(llvm::raw_ostream &OS, unsigned RATStalls,
97 unsigned RCUStalls, unsigned SQStalls,
98 unsigned LDQStalls, unsigned STQStalls,
99 unsigned DGStalls) const;
100 void printRATStatistics(llvm::raw_ostream &OS, unsigned Mappings,
101 unsigned MaxUsedMappings) const;
102 void printRCUStatistics(llvm::raw_ostream &OS, const Histogram &Histogram,
103 unsigned Cycles) const;
104 void printDispatchUnitUsage(llvm::raw_ostream &OS, const Histogram &Stats,
105 unsigned Cycles) const;
106 void printIssuePerCycle(const Histogram &IssuePerCycle,
107 unsigned TotalCycles) const;
108 void printSchedulerUsage(llvm::raw_ostream &OS, const llvm::MCSchedModel &SM,
109 const llvm::ArrayRef<BufferUsageEntry> &Usage) const;
110
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000111public:
Andrea Di Biagio09771ad2018-03-16 22:21:52 +0000112 BackendStatistics(const Backend &backend, const llvm::MCSubtargetInfo &sti)
113 : B(backend), STI(sti), NumDispatched(0), NumIssued(0), NumRetired(0),
114 NumCycles(0) {}
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000115
Clement Courbet844f22d2018-03-13 13:11:01 +0000116 void onInstructionEvent(const HWInstructionEvent &Event) override;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000117
118 void onCycleBegin(unsigned Cycle) override { NumCycles++; }
119
120 void onCycleEnd(unsigned Cycle) override { updateHistograms(); }
121
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000122 void printView(llvm::raw_ostream &OS) const override {
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +0000123 printDispatchStalls(OS, B.getNumRATStalls(), B.getNumRCUStalls(),
124 B.getNumSQStalls(), B.getNumLDQStalls(),
125 B.getNumSTQStalls(), B.getNumDispatchGroupStalls());
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000126 printRATStatistics(OS, B.getTotalRegisterMappingsCreated(),
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +0000127 B.getMaxUsedRegisterMappings());
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000128 printDispatchUnitStatistics(OS);
129 printSchedulerStatistics(OS);
130 printRetireUnitStatistics(OS);
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000131
132 std::vector<BufferUsageEntry> Usage;
133 B.getBuffersUsage(Usage);
Andrea Di Biagio09771ad2018-03-16 22:21:52 +0000134 printSchedulerUsage(OS, STI.getSchedModel(), Usage);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000135 }
136};
137
138} // namespace mca
139
140#endif