blob: b3532c72ee966340180ebc0ac5bdfc3c7eef4fe3 [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
10///
11/// 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
45void BackendStatistics::printDispatchUnitStatistics(llvm::raw_ostream &OS) const {
46 std::string Buffer;
47 raw_string_ostream TempStream(Buffer);
48 TempStream << "\n\nDispatch Logic - "
49 << "number of cycles where we saw N instructions dispatched:\n";
50 TempStream << "[# dispatched], [# cycles]\n";
51 for (const std::pair<unsigned, unsigned> &Entry : DispatchGroupSizePerCycle) {
52 TempStream << " " << Entry.first << ", " << Entry.second
53 << " ("
54 << format("%.1f", ((double)Entry.second / NumCycles) * 100.0)
55 << "%)\n";
56 }
57
58 TempStream.flush();
59 OS << Buffer;
60}
61
62void BackendStatistics::printSchedulerStatistics(llvm::raw_ostream &OS) const {
63 std::string Buffer;
64 raw_string_ostream TempStream(Buffer);
65 TempStream << "\n\nSchedulers - number of cycles where we saw N instructions "
66 "issued:\n";
67 TempStream << "[# issued], [# cycles]\n";
68 for (const std::pair<unsigned, unsigned> &Entry : IssuedPerCycle) {
69 TempStream << " " << Entry.first << ", " << Entry.second << " ("
70 << format("%.1f", ((double)Entry.second / NumCycles) * 100)
71 << "%)\n";
72 }
73
74 TempStream.flush();
75 OS << Buffer;
76}
77
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000078void BackendStatistics::printRATStatistics(raw_ostream &OS,
79 unsigned TotalMappings,
80 unsigned MaxUsedMappings) const {
81 std::string Buffer;
82 raw_string_ostream TempStream(Buffer);
83 TempStream << "\n\nRegister Alias Table:";
84 TempStream << "\nTotal number of mappings created: " << TotalMappings;
85 TempStream << "\nMax number of mappings used: " << MaxUsedMappings
86 << '\n';
87 TempStream.flush();
88 OS << Buffer;
89}
90
91void BackendStatistics::printDispatchStalls(raw_ostream &OS,
92 unsigned RATStalls, unsigned RCUStalls,
93 unsigned SCHEDQStalls,
94 unsigned LDQStalls, unsigned STQStalls,
95 unsigned DGStalls) const {
96 std::string Buffer;
97 raw_string_ostream TempStream(Buffer);
98 TempStream << "\n\nDynamic Dispatch Stall Cycles:\n";
99 TempStream << "RAT - Register unavailable: "
100 << RATStalls;
101 TempStream << "\nRCU - Retire tokens unavailable: "
102 << RCUStalls;
103 TempStream << "\nSCHEDQ - Scheduler full: "
104 << SCHEDQStalls;
105 TempStream << "\nLQ - Load queue full: "
106 << LDQStalls;
107 TempStream << "\nSQ - Store queue full: "
108 << STQStalls;
109 TempStream << "\nGROUP - Static restrictions on the dispatch group: "
110 << DGStalls;
111 TempStream << '\n';
112 TempStream.flush();
113 OS << Buffer;
114}
115
116void BackendStatistics::printSchedulerUsage(raw_ostream &OS,
117 const MCSchedModel &SM, const ArrayRef<BufferUsageEntry> &Usage) const {
118 std::string Buffer;
119 raw_string_ostream TempStream(Buffer);
120 TempStream << "\n\nScheduler's queue usage:\n";
121 const ArrayRef<uint64_t> ResourceMasks = B.getProcResourceMasks();
122 for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
123 const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);
124 if (!ProcResource.BufferSize)
125 continue;
126
127 for (const BufferUsageEntry &Entry : Usage)
128 if (ResourceMasks[I] == Entry.first)
129 TempStream << ProcResource.Name << ", " << Entry.second << '/'
130 << ProcResource.BufferSize << '\n';
131 }
132
133 TempStream.flush();
134 OS << Buffer;
135}
136
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000137} // namespace mca
138