blob: 56dd3af19124aa516e5e0e0423e013d6d9bc5644 [file] [log] [blame]
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +00001//===--------------------- 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]
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000020/// 0, 6 (2.9%)
21/// 1, 106 (50.7%)
22/// 2, 97 (46.4%)
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000023///
24/// Scheduler's queue usage:
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000025/// [1] Resource name.
26/// [2] Average number of used buffer entries.
27/// [3] Maximum number of used buffer entries.
28/// [4] Total number of buffer entries.
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000029///
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000030/// [1] [2] [3] [4]
31/// JALU01 0 0 20
32/// JFPU01 15 18 18
33/// JLSAGU 0 0 12
34//
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000035//===----------------------------------------------------------------------===//
36
37#ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
38#define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
39
Matt Davis10aa09f2018-08-24 20:24:53 +000040#include "Views/View.h"
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000041#include "llvm/ADT/SmallVector.h"
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000042#include "llvm/MC/MCSubtargetInfo.h"
Andrea Di Biagioa88281d2018-06-18 17:04:56 +000043#include <map>
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000044
Fangrui Song5a8fd652018-10-30 15:56:08 +000045namespace llvm {
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000046namespace mca {
47
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000048class SchedulerStatistics final : public View {
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000049 const llvm::MCSchedModel &SM;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000050 unsigned NumIssued;
51 unsigned NumCycles;
52
53 // Tracks the usage of a scheduler's queue.
54 struct BufferUsage {
55 unsigned SlotsInUse;
56 unsigned MaxUsedSlots;
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000057 uint64_t CumulativeNumUsedSlots;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000058 };
59
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000060 std::vector<unsigned> IssuedPerCycle;
61 std::vector<BufferUsage> Usage;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000062
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000063 void updateHistograms();
64 void printSchedulerStats(llvm::raw_ostream &OS) const;
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000065 void printSchedulerUsage(llvm::raw_ostream &OS) const;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000066
67public:
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000068 SchedulerStatistics(const llvm::MCSubtargetInfo &STI)
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000069 : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0),
70 IssuedPerCycle(STI.getSchedModel().NumProcResourceKinds, 0),
71 Usage(STI.getSchedModel().NumProcResourceKinds, {0, 0, 0}) {}
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000072
Matt Davis0906a7f2018-07-12 16:56:17 +000073 void onEvent(const HWInstructionEvent &Event) override;
Andrea Di Biagio3e646442018-04-12 10:49:40 +000074 void onCycleBegin() override { NumCycles++; }
Andrea Di Biagio3e646442018-04-12 10:49:40 +000075 void onCycleEnd() override { updateHistograms(); }
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000076
77 // Increases the number of used scheduler queue slots of every buffered
78 // resource in the Buffers set.
Andrea Di Biagio29c5d5a2018-08-28 13:14:42 +000079 void onReservedBuffers(const InstRef &IR,
80 llvm::ArrayRef<unsigned> Buffers) override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000081
82 // Decreases by one the number of used scheduler queue slots of every
83 // buffered resource in the Buffers set.
Andrea Di Biagio29c5d5a2018-08-28 13:14:42 +000084 void onReleasedBuffers(const InstRef &IR,
85 llvm::ArrayRef<unsigned> Buffers) override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000086
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000087 void printView(llvm::raw_ostream &OS) const override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000088};
89} // namespace mca
Fangrui Song5a8fd652018-10-30 15:56:08 +000090} // namespace llvm
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000091
92#endif