blob: d310a7b02eb5e126233ccb43ac65beffe15f3673 [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- BackendStatistics.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
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000010///
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000011/// Functionalities used by the BackendPrinter to print out histograms
12/// related to number of {dispatch/issue/retire} per number of cycles.
13///
14//===----------------------------------------------------------------------===//
15
16#include "BackendStatistics.h"
17#include "llvm/Support/Format.h"
18
19using namespace llvm;
20
21namespace mca {
22
23void BackendStatistics::printRetireUnitStatistics(llvm::raw_ostream &OS) const {
24 std::string Buffer;
25 raw_string_ostream TempStream(Buffer);
26 TempStream << "\n\nRetire Control Unit - "
27 << "number of cycles where we saw N instructions retired:\n";
28 TempStream << "[# retired], [# cycles]\n";
29
30 for (const std::pair<unsigned, unsigned> &Entry : RetiredPerCycle) {
31 TempStream << " " << Entry.first;
32 if (Entry.first < 10)
33 TempStream << ", ";
34 else
35 TempStream << ", ";
36 TempStream << Entry.second << " ("
37 << format("%.1f", ((double)Entry.second / NumCycles) * 100.0)
38 << "%)\n";
39 }
40
41 TempStream.flush();
42 OS << Buffer;
43}
44
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000045void BackendStatistics::printDispatchUnitStatistics(
46 llvm::raw_ostream &OS) const {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000047 std::string Buffer;
48 raw_string_ostream TempStream(Buffer);
49 TempStream << "\n\nDispatch Logic - "
50 << "number of cycles where we saw N instructions dispatched:\n";
51 TempStream << "[# dispatched], [# cycles]\n";
52 for (const std::pair<unsigned, unsigned> &Entry : DispatchGroupSizePerCycle) {
53 TempStream << " " << Entry.first << ", " << Entry.second
54 << " ("
55 << format("%.1f", ((double)Entry.second / NumCycles) * 100.0)
56 << "%)\n";
57 }
58
59 TempStream.flush();
60 OS << Buffer;
61}
62
63void BackendStatistics::printSchedulerStatistics(llvm::raw_ostream &OS) const {
64 std::string Buffer;
65 raw_string_ostream TempStream(Buffer);
66 TempStream << "\n\nSchedulers - number of cycles where we saw N instructions "
67 "issued:\n";
68 TempStream << "[# issued], [# cycles]\n";
69 for (const std::pair<unsigned, unsigned> &Entry : IssuedPerCycle) {
70 TempStream << " " << Entry.first << ", " << Entry.second << " ("
71 << format("%.1f", ((double)Entry.second / NumCycles) * 100)
72 << "%)\n";
73 }
74
75 TempStream.flush();
76 OS << Buffer;
77}
78
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000079void BackendStatistics::printRATStatistics(raw_ostream &OS,
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000080 unsigned TotalMappings,
81 unsigned MaxUsedMappings) const {
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000082 std::string Buffer;
83 raw_string_ostream TempStream(Buffer);
84 TempStream << "\n\nRegister Alias Table:";
85 TempStream << "\nTotal number of mappings created: " << TotalMappings;
86 TempStream << "\nMax number of mappings used: " << MaxUsedMappings
87 << '\n';
88 TempStream.flush();
89 OS << Buffer;
90}
91
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +000092void BackendStatistics::printDispatchStalls(raw_ostream &OS, unsigned RATStalls,
93 unsigned RCUStalls,
94 unsigned SCHEDQStalls,
95 unsigned LDQStalls,
96 unsigned STQStalls,
97 unsigned DGStalls) const {
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000098 std::string Buffer;
99 raw_string_ostream TempStream(Buffer);
100 TempStream << "\n\nDynamic Dispatch Stall Cycles:\n";
101 TempStream << "RAT - Register unavailable: "
102 << RATStalls;
103 TempStream << "\nRCU - Retire tokens unavailable: "
104 << RCUStalls;
105 TempStream << "\nSCHEDQ - Scheduler full: "
106 << SCHEDQStalls;
107 TempStream << "\nLQ - Load queue full: "
108 << LDQStalls;
109 TempStream << "\nSQ - Store queue full: "
110 << STQStalls;
111 TempStream << "\nGROUP - Static restrictions on the dispatch group: "
112 << DGStalls;
113 TempStream << '\n';
114 TempStream.flush();
115 OS << Buffer;
116}
117
Andrea Di Biagio53e6ade2018-03-09 12:50:42 +0000118void BackendStatistics::printSchedulerUsage(
119 raw_ostream &OS, const MCSchedModel &SM,
120 const ArrayRef<BufferUsageEntry> &Usage) const {
Andrea Di Biagio79487382018-03-10 17:40:25 +0000121
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000122 std::string Buffer;
123 raw_string_ostream TempStream(Buffer);
124 TempStream << "\n\nScheduler's queue usage:\n";
Andrea Di Biagio79487382018-03-10 17:40:25 +0000125 // Early exit if no buffered resources were consumed.
126 if (Usage.empty()) {
127 TempStream << "No scheduler resources used.\n";
128 TempStream.flush();
129 OS << Buffer;
130 return;
131 }
132
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000133 for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
134 const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);
135 if (!ProcResource.BufferSize)
136 continue;
137
138 for (const BufferUsageEntry &Entry : Usage)
Andrea Di Biagio0c541292018-03-10 16:55:07 +0000139 if (I == Entry.first)
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +0000140 TempStream << ProcResource.Name << ", " << Entry.second << '/'
141 << ProcResource.BufferSize << '\n';
142 }
143
144 TempStream.flush();
145 OS << Buffer;
146}
147
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000148} // namespace mca