]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-mca/SchedulerStatistics.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-mca / SchedulerStatistics.h
1 //===--------------------- SchedulerStatistics.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 defines class SchedulerStatistics. Class SchedulerStatistics is a
12 /// View that listens to instruction issue events in order to print general
13 /// statistics related to the hardware schedulers.
14 ///
15 /// Example:
16 /// ========
17 ///
18 /// Schedulers - number of cycles where we saw N instructions issued:
19 /// [# issued], [# cycles]
20 ///  0,          7  (5.4%)
21 ///  1,          4  (3.1%)
22 ///  2,          8  (6.2%)
23 ///
24 /// Scheduler's queue usage:
25 /// JALU01,  0/20
26 /// JFPU01,  18/18
27 /// JLSAGU,  0/12
28 ///
29 //===----------------------------------------------------------------------===//
30
31 #ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
32 #define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
33
34 #include "View.h"
35 #include "llvm/ADT/SmallVector.h"
36 #include "llvm/MC/MCSubtargetInfo.h"
37 #include <map>
38
39 namespace mca {
40
41 class SchedulerStatistics : public View {
42   const llvm::MCSchedModel &SM;
43
44   using Histogram = std::map<unsigned, unsigned>;
45   Histogram IssuedPerCycle;
46
47   unsigned NumIssued;
48   unsigned NumCycles;
49
50   // Tracks the usage of a scheduler's queue.
51   struct BufferUsage {
52     unsigned SlotsInUse;
53     unsigned MaxUsedSlots;
54   };
55
56   std::map<unsigned, BufferUsage> BufferedResources;
57
58   void updateHistograms() {
59     IssuedPerCycle[NumIssued]++;
60     NumIssued = 0;
61   }
62
63   void printSchedulerStatistics(llvm::raw_ostream &OS) const;
64   void printSchedulerUsage(llvm::raw_ostream &OS) const;
65
66 public:
67   SchedulerStatistics(const llvm::MCSubtargetInfo &STI)
68       : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0) {}
69
70   void onEvent(const HWInstructionEvent &Event) override;
71
72   void onCycleBegin() override { NumCycles++; }
73
74   void onCycleEnd() override { updateHistograms(); }
75
76   // Increases the number of used scheduler queue slots of every buffered
77   // resource in the Buffers set.
78   void onReservedBuffers(llvm::ArrayRef<unsigned> Buffers) override;
79
80   // Decreases by one the number of used scheduler queue slots of every
81   // buffered resource in the Buffers set.
82   void onReleasedBuffers(llvm::ArrayRef<unsigned> Buffers) override;
83
84   void printView(llvm::raw_ostream &OS) const override {
85     printSchedulerStatistics(OS);
86     printSchedulerUsage(OS);
87   }
88 };
89 } // namespace mca
90
91 #endif