blob: 24b8e5c565bbc4e60607d342cee5a54bd13bcf6a [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- BackendStatistics.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///
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000011/// This file implements a View named BackendStatistics that knows how to
12/// collect and print a few statistics related to the retire unit.
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000013///
14/// Example:
15/// ========
16///
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000017/// Retire Control Unit - number of cycles where we saw N instructions retired:
18/// [# retired], [# cycles]
19/// 0, 9 (6.9%)
20/// 1, 6 (4.6%)
21/// 2, 1 (0.8%)
22/// 4, 3 (2.3%)
23///
24//===----------------------------------------------------------------------===//
25
26#ifndef LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H
27#define LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H
28
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000029#include "View.h"
Andrea Di Biagio91ab2ee2018-03-19 13:23:07 +000030#include "llvm/ADT/SmallVector.h"
Andrea Di Biagiofbf37cc2018-04-03 15:36:15 +000031#include "llvm/ADT/DenseMap.h"
Andrea Di Biagio09771ad2018-03-16 22:21:52 +000032#include "llvm/MC/MCSubtargetInfo.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000033
34namespace mca {
35
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000036class BackendStatistics : public View {
Andrea Di Biagio09771ad2018-03-16 22:21:52 +000037 const llvm::MCSubtargetInfo &STI;
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000038
Andrea Di Biagiofbf37cc2018-04-03 15:36:15 +000039 using Histogram = llvm::DenseMap<unsigned, unsigned>;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000040 Histogram RetiredPerCycle;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000041
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000042 unsigned NumRetired;
43 unsigned NumCycles;
44
45 void updateHistograms() {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000046 RetiredPerCycle[NumRetired]++;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000047 NumRetired = 0;
48 }
49
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000050 void printRCUStatistics(llvm::raw_ostream &OS, const Histogram &Histogram,
51 unsigned Cycles) const;
Andrea Di Biagio8af3fe82018-03-08 16:08:43 +000052
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000053public:
Andrea Di Biagio12ef5262018-03-21 18:11:05 +000054 BackendStatistics(const llvm::MCSubtargetInfo &sti)
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000055 : STI(sti), NumRetired(0), NumCycles(0) {}
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000056
Clement Courbet844f22d2018-03-13 13:11:01 +000057 void onInstructionEvent(const HWInstructionEvent &Event) override;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000058
59 void onCycleBegin(unsigned Cycle) override { NumCycles++; }
60
61 void onCycleEnd(unsigned Cycle) override { updateHistograms(); }
62
Andrea Di Biagio1cc29c02018-04-11 11:37:46 +000063 void printView(llvm::raw_ostream &OS) const override;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000064};
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000065} // namespace mca
66
67#endif