Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- ResourcePressureView.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 define class ResourcePressureView. |
| 12 | /// Class ResourcePressureView observes hardware events generated by |
| 13 | /// the Backend object and collects statistics related to resource usage at |
| 14 | /// instruction granularity. |
| 15 | /// Resource pressure information is then printed out to a stream in the |
| 16 | /// form of a table like the one from the example below: |
| 17 | /// |
| 18 | /// Resources: |
| 19 | /// [0] - JALU0 |
| 20 | /// [1] - JALU1 |
| 21 | /// [2] - JDiv |
| 22 | /// [3] - JFPM |
| 23 | /// [4] - JFPU0 |
| 24 | /// [5] - JFPU1 |
| 25 | /// [6] - JLAGU |
| 26 | /// [7] - JSAGU |
| 27 | /// [8] - JSTC |
| 28 | /// [9] - JVIMUL |
| 29 | /// |
| 30 | /// Resource pressure per iteration: |
| 31 | /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] |
| 32 | /// 0.00 0.00 0.00 0.00 2.00 2.00 0.00 0.00 0.00 0.00 |
| 33 | /// |
| 34 | /// Resource pressure by instruction: |
| 35 | /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions: |
| 36 | /// - - - - - 1.00 - - - - vpermilpd $1, %xmm0, |
| 37 | /// %xmm1 |
| 38 | /// - - - - 1.00 - - - - - vaddps %xmm0, %xmm1, |
| 39 | /// %xmm2 |
| 40 | /// - - - - - 1.00 - - - - vmovshdup %xmm2, %xmm3 |
| 41 | /// - - - - 1.00 - - - - - vaddss %xmm2, %xmm3, |
| 42 | /// %xmm4 |
| 43 | /// |
| 44 | /// In this example, we have AVX code executed on AMD Jaguar (btver2). |
| 45 | /// Both shuffles and vector floating point add operations on XMM registers have |
| 46 | /// a reciprocal throughput of 1cy. |
| 47 | /// Each add is issued to pipeline JFPU0, while each shuffle is issued to |
| 48 | /// pipeline JFPU1. The overall pressure per iteration is reported by two |
| 49 | /// tables: the first smaller table is the resource pressure per iteration; |
| 50 | /// the second table reports resource pressure per instruction. Values are the |
| 51 | /// average resource cycles consumed by an instruction. |
| 52 | /// Every vector add from the example uses resource JFPU0 for an average of 1cy |
| 53 | /// per iteration. Consequently, the resource pressure on JFPU0 is of 2cy per |
| 54 | /// iteration. |
| 55 | /// |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | |
| 58 | #ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H |
| 59 | #define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H |
| 60 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 61 | #include "SourceMgr.h" |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 62 | #include "View.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 63 | #include "llvm/MC/MCInstPrinter.h" |
| 64 | #include "llvm/MC/MCSubtargetInfo.h" |
| 65 | #include <map> |
| 66 | |
| 67 | namespace mca { |
| 68 | |
| 69 | class Backend; |
| 70 | |
| 71 | /// This class collects resource pressure statistics and it is able to print |
| 72 | /// out all the collected information as a table to an output stream. |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 73 | class ResourcePressureView : public View { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 74 | const llvm::MCSubtargetInfo &STI; |
| 75 | llvm::MCInstPrinter &MCIP; |
| 76 | const SourceMgr &Source; |
| 77 | |
| 78 | // Map to quickly get a resource descriptor from a mask. |
| 79 | std::map<uint64_t, unsigned> Resource2VecIndex; |
| 80 | |
| 81 | // Table of resources used by instructions. |
| 82 | std::vector<unsigned> ResourceUsage; |
| 83 | unsigned NumResourceUnits; |
| 84 | |
| 85 | const llvm::MCInst &GetMCInstFromIndex(unsigned Index) const; |
| 86 | void printResourcePressurePerIteration(llvm::raw_ostream &OS, |
| 87 | unsigned Executions) const; |
| 88 | void printResourcePressurePerInstruction(llvm::raw_ostream &OS, |
| 89 | unsigned Executions) const; |
Andrea Di Biagio | 0c54129 | 2018-03-10 16:55:07 +0000 | [diff] [blame] | 90 | void initialize(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 91 | |
| 92 | public: |
| 93 | ResourcePressureView(const llvm::MCSubtargetInfo &ST, |
Andrea Di Biagio | 0c54129 | 2018-03-10 16:55:07 +0000 | [diff] [blame] | 94 | llvm::MCInstPrinter &Printer, const SourceMgr &SM) |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 95 | : STI(ST), MCIP(Printer), Source(SM) { |
Andrea Di Biagio | 0c54129 | 2018-03-10 16:55:07 +0000 | [diff] [blame] | 96 | initialize(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 99 | void onInstructionEvent(const HWInstructionEvent &Event) override; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 100 | |
Andrea Di Biagio | 07eb79a | 2018-03-08 17:02:28 +0000 | [diff] [blame] | 101 | void printView(llvm::raw_ostream &OS) const override { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 102 | unsigned Executions = Source.getNumIterations(); |
| 103 | printResourcePressurePerIteration(OS, Executions); |
| 104 | printResourcePressurePerInstruction(OS, Executions); |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | } // namespace mca |
| 109 | |
| 110 | #endif |