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:
29 //===----------------------------------------------------------------------===//
31 #ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
32 #define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
35 #include "llvm/ADT/SmallVector.h"
36 #include "llvm/MC/MCSubtargetInfo.h"
41 class SchedulerStatistics : public View {
42 const llvm::MCSchedModel &SM;
44 using Histogram = std::map<unsigned, unsigned>;
45 Histogram IssuedPerCycle;
50 // Tracks the usage of a scheduler's queue.
53 unsigned MaxUsedSlots;
56 std::map<unsigned, BufferUsage> BufferedResources;
58 void updateHistograms() {
59 IssuedPerCycle[NumIssued]++;
63 void printSchedulerStatistics(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) {}
70 void onEvent(const HWInstructionEvent &Event) override;
72 void onCycleBegin() override { NumCycles++; }
74 void onCycleEnd() override { updateHistograms(); }
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;
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;
84 void printView(llvm::raw_ostream &OS) const override {
85 printSchedulerStatistics(OS);
86 printSchedulerUsage(OS);