blob: ac15ed2cbb229b2c3db5ca742eef91f528762c5e [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///
17/// Dispatch Logic - number of cycles where we saw N instructions dispatched:
18/// [# dispatched], [# cycles]
19/// 0, 15 (11.5%)
20/// 5, 4 (3.1%)
21///
22/// Schedulers - number of cycles where we saw N instructions issued:
23/// [# issued], [# cycles]
24/// 0, 7 (5.4%)
25/// 1, 4 (3.1%)
26/// 2, 8 (6.2%)
27///
28/// Retire Control Unit - number of cycles where we saw N instructions retired:
29/// [# retired], [# cycles]
30/// 0, 9 (6.9%)
31/// 1, 6 (4.6%)
32/// 2, 1 (0.8%)
33/// 4, 3 (2.3%)
34///
35//===----------------------------------------------------------------------===//
36
37#ifndef LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H
38#define LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H
39
40#include "HWEventListener.h"
41#include "llvm/Support/raw_ostream.h"
42#include <map>
43
44namespace mca {
45
46class BackendStatistics : public HWEventListener {
47 using Histogram = std::map<unsigned, unsigned>;
48 Histogram DispatchGroupSizePerCycle;
49 Histogram RetiredPerCycle;
50 Histogram IssuedPerCycle;
51
52 unsigned NumDispatched;
53 unsigned NumIssued;
54 unsigned NumRetired;
55 unsigned NumCycles;
56
57 void updateHistograms() {
58 DispatchGroupSizePerCycle[NumDispatched]++;
59 IssuedPerCycle[NumIssued]++;
60 RetiredPerCycle[NumRetired]++;
61 NumDispatched = 0;
62 NumIssued = 0;
63 NumRetired = 0;
64 }
65
66 void printRetireUnitStatistics(llvm::raw_ostream &OS) const;
67 void printDispatchUnitStatistics(llvm::raw_ostream &OS) const;
68 void printSchedulerStatistics(llvm::raw_ostream &OS) const;
69
70public:
71 BackendStatistics() : NumDispatched(0), NumIssued(0), NumRetired(0) {}
72
73 void onInstructionDispatched(unsigned Index) override { NumDispatched++; }
74 void
75 onInstructionIssued(unsigned Index,
76 const llvm::ArrayRef<std::pair<ResourceRef, unsigned>>
77 & /* unused */) override {
78 NumIssued++;
79 }
80 void onInstructionRetired(unsigned Index) override { NumRetired++; }
81
82 void onCycleBegin(unsigned Cycle) override { NumCycles++; }
83
84 void onCycleEnd(unsigned Cycle) override { updateHistograms(); }
85
86 void printHistograms(llvm::raw_ostream &OS) {
87 printDispatchUnitStatistics(OS);
88 printSchedulerStatistics(OS);
89 printRetireUnitStatistics(OS);
90 }
91};
92
93} // namespace mca
94
95#endif