1 //===--------------------- DispatchStatistics.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 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.
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
27 /// Dispatch Logic - number of cycles where we saw N instructions dispatched:
28 /// [# dispatched], [# cycles]
32 //===----------------------------------------------------------------------===//
34 #ifndef LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H
35 #define LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H
38 #include "llvm/ADT/DenseMap.h"
39 #include "llvm/ADT/SmallVector.h"
40 #include "llvm/MC/MCSubtargetInfo.h"
44 class DispatchStatistics : public View {
45 unsigned NumDispatched;
48 // Counts dispatch stall events caused by unavailability of resources. There
49 // is one counter for every generic stall kind (see class HWStallEvent).
50 llvm::SmallVector<unsigned, 8> HWStalls;
52 using Histogram = llvm::DenseMap<unsigned, unsigned>;
53 Histogram DispatchGroupSizePerCycle;
55 void updateHistograms() {
56 DispatchGroupSizePerCycle[NumDispatched]++;
60 void printDispatchHistogram(llvm::raw_ostream &OS) const;
62 void printDispatchStalls(llvm::raw_ostream &OS) const;
65 DispatchStatistics() : NumDispatched(0), NumCycles(0),
66 HWStalls(HWStallEvent::LastGenericEvent) {}
68 void onInstructionEvent(const HWInstructionEvent &Event) override;
70 void onCycleBegin() override { NumCycles++; }
72 void onCycleEnd() override { updateHistograms(); }
74 void onStallEvent(const HWStallEvent &Event) override;
76 void printView(llvm::raw_ostream &OS) const override {
77 printDispatchStalls(OS);
78 printDispatchHistogram(OS);