Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- 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 Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame^] | 11 | /// 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 Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 13 | /// |
| 14 | /// Example: |
| 15 | /// ======== |
| 16 | /// |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 17 | /// 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 Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 29 | #include "View.h" |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallVector.h" |
Andrea Di Biagio | fbf37cc | 2018-04-03 15:36:15 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/DenseMap.h" |
Andrea Di Biagio | 09771ad | 2018-03-16 22:21:52 +0000 | [diff] [blame] | 32 | #include "llvm/MC/MCSubtargetInfo.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 33 | |
| 34 | namespace mca { |
| 35 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 36 | class BackendStatistics : public View { |
Andrea Di Biagio | 09771ad | 2018-03-16 22:21:52 +0000 | [diff] [blame] | 37 | const llvm::MCSubtargetInfo &STI; |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 38 | |
Andrea Di Biagio | fbf37cc | 2018-04-03 15:36:15 +0000 | [diff] [blame] | 39 | using Histogram = llvm::DenseMap<unsigned, unsigned>; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 40 | Histogram RetiredPerCycle; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 41 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 42 | unsigned NumRetired; |
| 43 | unsigned NumCycles; |
| 44 | |
| 45 | void updateHistograms() { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 46 | RetiredPerCycle[NumRetired]++; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 47 | NumRetired = 0; |
| 48 | } |
| 49 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 50 | void printRCUStatistics(llvm::raw_ostream &OS, const Histogram &Histogram, |
| 51 | unsigned Cycles) const; |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 52 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 53 | public: |
Andrea Di Biagio | 12ef526 | 2018-03-21 18:11:05 +0000 | [diff] [blame] | 54 | BackendStatistics(const llvm::MCSubtargetInfo &sti) |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame^] | 55 | : STI(sti), NumRetired(0), NumCycles(0) {} |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 56 | |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 57 | void onInstructionEvent(const HWInstructionEvent &Event) override; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 58 | |
| 59 | void onCycleBegin(unsigned Cycle) override { NumCycles++; } |
| 60 | |
| 61 | void onCycleEnd(unsigned Cycle) override { updateHistograms(); } |
| 62 | |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame^] | 63 | void printView(llvm::raw_ostream &OS) const override; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 64 | }; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 65 | } // namespace mca |
| 66 | |
| 67 | #endif |