Andrea Di Biagio | 821f650 | 2018-04-10 14:55:14 +0000 | [diff] [blame^] | 1 | //===--------------------- DispatchStatistics.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 view that prints a few statistics related to the |
| 12 | /// dispatch logic. It collects and analyzes instruction dispatch events as |
| 13 | /// well as static/dynamic dispatch stall events. |
| 14 | /// |
| 15 | /// Example: |
| 16 | /// ======== |
| 17 | /// |
| 18 | /// Dynamic Dispatch Stall Cycles: |
| 19 | /// RAT - Register unavailable: 0 |
| 20 | /// RCU - Retire tokens unavailable: 0 |
| 21 | /// SCHEDQ - Scheduler full: 42 |
| 22 | /// LQ - Load queue full: 0 |
| 23 | /// SQ - Store queue full: 0 |
| 24 | /// GROUP - Static restrictions on the dispatch group: 0 |
| 25 | /// |
| 26 | /// |
| 27 | /// Dispatch Logic - number of cycles where we saw N instructions dispatched: |
| 28 | /// [# dispatched], [# cycles] |
| 29 | /// 0, 15 (11.5%) |
| 30 | /// 2, 4 (3.1%) |
| 31 | /// |
| 32 | //===----------------------------------------------------------------------===// |
| 33 | |
| 34 | #ifndef LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H |
| 35 | #define LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H |
| 36 | |
| 37 | #include "View.h" |
| 38 | #include "llvm/ADT/DenseMap.h" |
| 39 | #include "llvm/ADT/SmallVector.h" |
| 40 | #include "llvm/MC/MCSubtargetInfo.h" |
| 41 | |
| 42 | namespace mca { |
| 43 | |
| 44 | class DispatchStatistics : public View { |
| 45 | const llvm::MCSubtargetInfo &STI; |
| 46 | |
| 47 | using Histogram = llvm::DenseMap<unsigned, unsigned>; |
| 48 | Histogram DispatchGroupSizePerCycle; |
| 49 | |
| 50 | unsigned NumDispatched; |
| 51 | unsigned NumCycles; |
| 52 | |
| 53 | // Counts dispatch stall events caused by unavailability of resources. There |
| 54 | // is one counter for every generic stall kind (see class HWStallEvent). |
| 55 | llvm::SmallVector<unsigned, 8> HWStalls; |
| 56 | |
| 57 | void updateHistograms() { |
| 58 | DispatchGroupSizePerCycle[NumDispatched]++; |
| 59 | NumDispatched = 0; |
| 60 | } |
| 61 | |
| 62 | void printDispatchHistogram(llvm::raw_ostream &OS) const; |
| 63 | |
| 64 | void printDispatchStalls(llvm::raw_ostream &OS) const; |
| 65 | void printDispatchUnitUsage(llvm::raw_ostream &OS, const Histogram &Stats, |
| 66 | unsigned Cycles) const; |
| 67 | |
| 68 | public: |
| 69 | DispatchStatistics(const llvm::MCSubtargetInfo &sti) |
| 70 | : STI(sti), NumDispatched(0), NumCycles(0), |
| 71 | HWStalls(HWStallEvent::LastGenericEvent) {} |
| 72 | |
| 73 | void onInstructionEvent(const HWInstructionEvent &Event) override; |
| 74 | |
| 75 | void onCycleBegin(unsigned Cycle) override { NumCycles++; } |
| 76 | |
| 77 | void onCycleEnd(unsigned Cycle) override { updateHistograms(); } |
| 78 | |
| 79 | void onStallEvent(const HWStallEvent &Event) override { |
| 80 | if (Event.Type < HWStallEvent::LastGenericEvent) |
| 81 | HWStalls[Event.Type]++; |
| 82 | } |
| 83 | |
| 84 | void printView(llvm::raw_ostream &OS) const override { |
| 85 | printDispatchStalls(OS); |
| 86 | printDispatchHistogram(OS); |
| 87 | } |
| 88 | }; |
| 89 | } // namespace mca |
| 90 | |
| 91 | #endif |