1 //===--------------------- DispatchStatistics.h -----------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file implements a view that prints a few statistics related to the
11 /// dispatch logic. It collects and analyzes instruction dispatch events as
12 /// well as static/dynamic dispatch stall events.
17 /// Dynamic Dispatch Stall Cycles:
18 /// RAT - Register unavailable: 0
19 /// RCU - Retire tokens unavailable: 0
20 /// SCHEDQ - Scheduler full: 42
21 /// LQ - Load queue full: 0
22 /// SQ - Store queue full: 0
23 /// GROUP - Static restrictions on the dispatch group: 0
26 /// Dispatch Logic - number of cycles where we saw N micro opcodes dispatched:
27 /// [# dispatched], [# cycles]
31 //===----------------------------------------------------------------------===//
33 #ifndef LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H
34 #define LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H
36 #include "Views/View.h"
37 #include "llvm/ADT/SmallVector.h"
38 #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
= std::map
<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;
66 : NumDispatched(0), NumCycles(0),
67 HWStalls(HWStallEvent::LastGenericEvent
) {}
69 void onEvent(const HWStallEvent
&Event
) override
;
71 void onEvent(const HWInstructionEvent
&Event
) override
;
73 void onCycleBegin() override
{ NumCycles
++; }
75 void onCycleEnd() override
{ updateHistograms(); }
77 void printView(llvm::raw_ostream
&OS
) const override
{
78 printDispatchStalls(OS
);
79 printDispatchHistogram(OS
);