Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 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/ADT/DenseMap.h" |
| 37 | #include "llvm/MC/MCSubtargetInfo.h" |
| 38 | |
| 39 | namespace mca { |
| 40 | |
| 41 | class SchedulerStatistics : public View { |
| 42 | const llvm::MCSubtargetInfo &STI; |
| 43 | |
| 44 | using Histogram = llvm::DenseMap<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 | llvm::DenseMap<unsigned, BufferUsage> BufferedResources; |
| 57 | |
| 58 | void updateHistograms() { |
| 59 | IssuedPerCycle[NumIssued]++; |
| 60 | NumIssued = 0; |
| 61 | } |
| 62 | |
| 63 | void printSchedulerStatistics(llvm::raw_ostream &OS) const; |
| 64 | |
| 65 | void printIssuePerCycle(const Histogram &IssuePerCycle, |
| 66 | unsigned TotalCycles) const; |
| 67 | void printSchedulerUsage(llvm::raw_ostream &OS, |
| 68 | const llvm::MCSchedModel &SM) const; |
| 69 | |
| 70 | public: |
| 71 | SchedulerStatistics(const llvm::MCSubtargetInfo &sti) |
| 72 | : STI(sti), NumIssued(0), NumCycles(0) { } |
| 73 | |
| 74 | void onInstructionEvent(const HWInstructionEvent &Event) override; |
| 75 | |
| 76 | void onCycleBegin(unsigned Cycle) override { NumCycles++; } |
| 77 | |
| 78 | void onCycleEnd(unsigned Cycle) override { updateHistograms(); } |
| 79 | |
| 80 | // Increases the number of used scheduler queue slots of every buffered |
| 81 | // resource in the Buffers set. |
| 82 | void onReservedBuffers(llvm::ArrayRef<unsigned> Buffers) override; |
| 83 | |
| 84 | // Decreases by one the number of used scheduler queue slots of every |
| 85 | // buffered resource in the Buffers set. |
| 86 | void onReleasedBuffers(llvm::ArrayRef<unsigned> Buffers) override; |
| 87 | |
| 88 | void printView(llvm::raw_ostream &OS) const override { |
| 89 | printSchedulerStatistics(OS); |
| 90 | printSchedulerUsage(OS, STI.getSchedModel()); |
| 91 | } |
| 92 | }; |
| 93 | } // namespace mca |
| 94 | |
| 95 | #endif |