1 //===--------------------- SchedulerStatistics.h ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
18 /// Schedulers - number of cycles where we saw N instructions issued:
19 /// [# issued], [# cycles]
24 /// Scheduler's queue usage:
25 /// [1] Resource name.
26 /// [2] Average number of used buffer entries.
27 /// [3] Maximum number of used buffer entries.
28 /// [4] Total number of buffer entries.
35 //===----------------------------------------------------------------------===//
37 #ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
38 #define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
40 #include "Views/View.h"
41 #include "llvm/ADT/SmallVector.h"
42 #include "llvm/MC/MCSubtargetInfo.h"
47 class SchedulerStatistics final
: public View
{
48 const llvm::MCSchedModel
&SM
;
52 // Tracks the usage of a scheduler's queue.
55 unsigned MaxUsedSlots
;
56 uint64_t CumulativeNumUsedSlots
;
59 std::vector
<unsigned> IssuedPerCycle
;
60 std::vector
<BufferUsage
> Usage
;
62 void updateHistograms();
63 void printSchedulerStats(llvm::raw_ostream
&OS
) const;
64 void printSchedulerUsage(llvm::raw_ostream
&OS
) const;
67 SchedulerStatistics(const llvm::MCSubtargetInfo
&STI
)
68 : SM(STI
.getSchedModel()), NumIssued(0), NumCycles(0),
69 IssuedPerCycle(STI
.getSchedModel().NumProcResourceKinds
, 0),
70 Usage(STI
.getSchedModel().NumProcResourceKinds
, {0, 0, 0}) {}
72 void onEvent(const HWInstructionEvent
&Event
) override
;
74 void onCycleBegin() override
{ NumCycles
++; }
76 void onCycleEnd() override
{ updateHistograms(); }
78 // Increases the number of used scheduler queue slots of every buffered
79 // resource in the Buffers set.
80 void onReservedBuffers(const InstRef
&IR
,
81 llvm::ArrayRef
<unsigned> Buffers
) override
;
83 // Decreases by one the number of used scheduler queue slots of every
84 // buffered resource in the Buffers set.
85 void onReleasedBuffers(const InstRef
&IR
,
86 llvm::ArrayRef
<unsigned> Buffers
) override
;
88 void printView(llvm::raw_ostream
&OS
) const override
;