blob: 3857c0e55a81a5761b402099693ef6dd8b97e817 [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]
20/// 0, 7 (5.4%)
21/// 1, 4 (3.1%)
22/// 2, 8 (6.2%)
23///
24/// Scheduler's queue usage:
25/// JALU01, 0/20
26/// JFPU01, 18/18
27/// JLSAGU, 0/12
28///
29//===----------------------------------------------------------------------===//
30
31#ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
32#define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
33
Matt Davis10aa09f2018-08-24 20:24:53 +000034#include "Views/View.h"
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000035#include "llvm/ADT/SmallVector.h"
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000036#include "llvm/MC/MCSubtargetInfo.h"
Andrea Di Biagioa88281d2018-06-18 17:04:56 +000037#include <map>
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000038
39namespace mca {
40
41class SchedulerStatistics : public View {
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000042 const llvm::MCSchedModel &SM;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000043
Andrea Di Biagioa88281d2018-06-18 17:04:56 +000044 using Histogram = std::map<unsigned, unsigned>;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000045 Histogram IssuedPerCycle;
46
47 unsigned NumIssued;
48 unsigned NumCycles;
49
50 // Tracks the usage of a scheduler's queue.
51 struct BufferUsage {
52 unsigned SlotsInUse;
53 unsigned MaxUsedSlots;
54 };
55
Andrea Di Biagioa88281d2018-06-18 17:04:56 +000056 std::map<unsigned, BufferUsage> BufferedResources;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000057
58 void updateHistograms() {
59 IssuedPerCycle[NumIssued]++;
60 NumIssued = 0;
61 }
62
63 void printSchedulerStatistics(llvm::raw_ostream &OS) const;
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000064 void printSchedulerUsage(llvm::raw_ostream &OS) const;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000065
66public:
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000067 SchedulerStatistics(const llvm::MCSubtargetInfo &STI)
Matt Davis0906a7f2018-07-12 16:56:17 +000068 : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0) {}
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000069
Matt Davis0906a7f2018-07-12 16:56:17 +000070 void onEvent(const HWInstructionEvent &Event) override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000071
Andrea Di Biagio3e646442018-04-12 10:49:40 +000072 void onCycleBegin() override { NumCycles++; }
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000073
Andrea Di Biagio3e646442018-04-12 10:49:40 +000074 void onCycleEnd() override { updateHistograms(); }
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000075
76 // Increases the number of used scheduler queue slots of every buffered
77 // resource in the Buffers set.
78 void onReservedBuffers(llvm::ArrayRef<unsigned> Buffers) override;
79
80 // Decreases by one the number of used scheduler queue slots of every
81 // buffered resource in the Buffers set.
82 void onReleasedBuffers(llvm::ArrayRef<unsigned> Buffers) override;
83
84 void printView(llvm::raw_ostream &OS) const override {
85 printSchedulerStatistics(OS);
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000086 printSchedulerUsage(OS);
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000087 }
88};
89} // namespace mca
90
91#endif