blob: 3515546f083e694c1762d1d68375422820b96dfd [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
45namespace mca {
46
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000047class SchedulerStatistics final : public View {
Andrea Di Biagio074ff7c2018-04-11 12:31:44 +000048 const llvm::MCSchedModel &SM;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000049 unsigned NumIssued;
50 unsigned NumCycles;
51
52 // Tracks the usage of a scheduler's queue.
53 struct BufferUsage {
54 unsigned SlotsInUse;
55 unsigned MaxUsedSlots;
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000056 uint64_t CumulativeNumUsedSlots;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000057 };
58
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000059 std::vector<unsigned> IssuedPerCycle;
60 std::vector<BufferUsage> Usage;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000061
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000062 void updateHistograms();
63 void printSchedulerStats(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)
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000068 : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0),
69 IssuedPerCycle(STI.getSchedModel().NumProcResourceKinds, 0),
70 Usage(STI.getSchedModel().NumProcResourceKinds, {0, 0, 0}) {}
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000071
Matt Davis0906a7f2018-07-12 16:56:17 +000072 void onEvent(const HWInstructionEvent &Event) override;
Andrea Di Biagio3e646442018-04-12 10:49:40 +000073 void onCycleBegin() override { NumCycles++; }
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.
Andrea Di Biagio29c5d5a2018-08-28 13:14:42 +000078 void onReservedBuffers(const InstRef &IR,
79 llvm::ArrayRef<unsigned> Buffers) override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000080
81 // Decreases by one the number of used scheduler queue slots of every
82 // buffered resource in the Buffers set.
Andrea Di Biagio29c5d5a2018-08-28 13:14:42 +000083 void onReleasedBuffers(const InstRef &IR,
84 llvm::ArrayRef<unsigned> Buffers) override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000085
Andrea Di Biagiob89b96c2018-08-27 14:52:52 +000086 void printView(llvm::raw_ostream &OS) const override;
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000087};
88} // namespace mca
89
90#endif