blob: 6679c81efe954ada2db98196bab5d851828ee206 [file] [log] [blame]
Andrea Di Biagio821f6502018-04-10 14:55:14 +00001//===--------------------- 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///
Andrea Di Biagio8b647dc2018-08-30 10:50:20 +000027/// Dispatch Logic - number of cycles where we saw N micro opcodes dispatched:
Andrea Di Biagio821f6502018-04-10 14:55:14 +000028/// [# 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
Matt Davis10aa09f2018-08-24 20:24:53 +000037#include "Views/View.h"
Andrea Di Biagio821f6502018-04-10 14:55:14 +000038#include "llvm/ADT/SmallVector.h"
39#include "llvm/MC/MCSubtargetInfo.h"
Andrea Di Biagioa88281d2018-06-18 17:04:56 +000040#include <map>
Andrea Di Biagio821f6502018-04-10 14:55:14 +000041
Fangrui Song5a8fd652018-10-30 15:56:08 +000042namespace llvm {
Andrea Di Biagio821f6502018-04-10 14:55:14 +000043namespace mca {
44
45class DispatchStatistics : public View {
Andrea Di Biagio821f6502018-04-10 14:55:14 +000046 unsigned NumDispatched;
47 unsigned NumCycles;
48
49 // Counts dispatch stall events caused by unavailability of resources. There
50 // is one counter for every generic stall kind (see class HWStallEvent).
51 llvm::SmallVector<unsigned, 8> HWStalls;
52
Andrea Di Biagioa88281d2018-06-18 17:04:56 +000053 using Histogram = std::map<unsigned, unsigned>;
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000054 Histogram DispatchGroupSizePerCycle;
55
Andrea Di Biagio821f6502018-04-10 14:55:14 +000056 void updateHistograms() {
57 DispatchGroupSizePerCycle[NumDispatched]++;
58 NumDispatched = 0;
59 }
60
61 void printDispatchHistogram(llvm::raw_ostream &OS) const;
62
63 void printDispatchStalls(llvm::raw_ostream &OS) const;
Andrea Di Biagio821f6502018-04-10 14:55:14 +000064
65public:
Andrea Di Biagio641cca32018-04-25 10:27:30 +000066 DispatchStatistics()
67 : NumDispatched(0), NumCycles(0),
Andrea Di Biagio821f6502018-04-10 14:55:14 +000068 HWStalls(HWStallEvent::LastGenericEvent) {}
69
Matt Davis0906a7f2018-07-12 16:56:17 +000070 void onEvent(const HWStallEvent &Event) override;
71
72 void onEvent(const HWInstructionEvent &Event) override;
Andrea Di Biagio821f6502018-04-10 14:55:14 +000073
Andrea Di Biagio3e646442018-04-12 10:49:40 +000074 void onCycleBegin() override { NumCycles++; }
Andrea Di Biagio821f6502018-04-10 14:55:14 +000075
Andrea Di Biagio3e646442018-04-12 10:49:40 +000076 void onCycleEnd() override { updateHistograms(); }
Andrea Di Biagio821f6502018-04-10 14:55:14 +000077
Andrea Di Biagio821f6502018-04-10 14:55:14 +000078 void printView(llvm::raw_ostream &OS) const override {
79 printDispatchStalls(OS);
80 printDispatchHistogram(OS);
81 }
82};
83} // namespace mca
Fangrui Song5a8fd652018-10-30 15:56:08 +000084} // namespace llvm
Andrea Di Biagio821f6502018-04-10 14:55:14 +000085
86#endif