| 1 | //===--------------------- ResourcePressureView.h ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// |
| 10 | /// This file define class ResourcePressureView. |
| 11 | /// Class ResourcePressureView observes hardware events generated by |
| 12 | /// the Pipeline object and collects statistics related to resource usage at |
| 13 | /// instruction granularity. |
| 14 | /// Resource pressure information is then printed out to a stream in the |
| 15 | /// form of a table like the one from the example below: |
| 16 | /// |
| 17 | /// Resources: |
| 18 | /// [0] - JALU0 |
| 19 | /// [1] - JALU1 |
| 20 | /// [2] - JDiv |
| 21 | /// [3] - JFPM |
| 22 | /// [4] - JFPU0 |
| 23 | /// [5] - JFPU1 |
| 24 | /// [6] - JLAGU |
| 25 | /// [7] - JSAGU |
| 26 | /// [8] - JSTC |
| 27 | /// [9] - JVIMUL |
| 28 | /// |
| 29 | /// Resource pressure per iteration: |
| 30 | /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] |
| 31 | /// 0.00 0.00 0.00 0.00 2.00 2.00 0.00 0.00 0.00 0.00 |
| 32 | /// |
| 33 | /// Resource pressure by instruction: |
| 34 | /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions: |
| 35 | /// - - - - - 1.00 - - - - vpermilpd $1, %xmm0, |
| 36 | /// %xmm1 |
| 37 | /// - - - - 1.00 - - - - - vaddps %xmm0, %xmm1, |
| 38 | /// %xmm2 |
| 39 | /// - - - - - 1.00 - - - - vmovshdup %xmm2, %xmm3 |
| 40 | /// - - - - 1.00 - - - - - vaddss %xmm2, %xmm3, |
| 41 | /// %xmm4 |
| 42 | /// |
| 43 | /// In this example, we have AVX code executed on AMD Jaguar (btver2). |
| 44 | /// Both shuffles and vector floating point add operations on XMM registers have |
| 45 | /// a reciprocal throughput of 1cy. |
| 46 | /// Each add is issued to pipeline JFPU0, while each shuffle is issued to |
| 47 | /// pipeline JFPU1. The overall pressure per iteration is reported by two |
| 48 | /// tables: the first smaller table is the resource pressure per iteration; |
| 49 | /// the second table reports resource pressure per instruction. Values are the |
| 50 | /// average resource cycles consumed by an instruction. |
| 51 | /// Every vector add from the example uses resource JFPU0 for an average of 1cy |
| 52 | /// per iteration. Consequently, the resource pressure on JFPU0 is of 2cy per |
| 53 | /// iteration. |
| 54 | /// |
| 55 | //===----------------------------------------------------------------------===// |
| 56 | |
| 57 | #ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H |
| 58 | #define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H |
| 59 | |
| 60 | #include "Views/InstructionView.h" |
| 61 | #include "llvm/ADT/ArrayRef.h" |
| 62 | #include "llvm/ADT/DenseMap.h" |
| 63 | #include "llvm/MC/MCInst.h" |
| 64 | #include "llvm/MC/MCInstPrinter.h" |
| 65 | #include "llvm/MC/MCSubtargetInfo.h" |
| 66 | #include "llvm/Support/JSON.h" |
| 67 | |
| 68 | namespace llvm { |
| 69 | namespace mca { |
| 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. |
| 73 | class ResourcePressureView : public InstructionView { |
| 74 | unsigned LastInstructionIdx; |
| 75 | |
| 76 | // Map to quickly obtain the ResourceUsage column index from a processor |
| 77 | // resource ID. |
| 78 | llvm::DenseMap<unsigned, unsigned> Resource2VecIndex; |
| 79 | |
| 80 | struct ResourceReleaseAtCycles { |
| 81 | unsigned ResourceIdx; |
| 82 | ReleaseAtCycles Cycles; |
| 83 | }; |
| 84 | using InstResourceUsage = std::vector<ResourceReleaseAtCycles>; |
| 85 | std::vector<InstResourceUsage> ResourceUsage; |
| 86 | InstResourceUsage CommonResourceUsage; |
| 87 | unsigned NumResourceUnits; |
| 88 | |
| 89 | void printResourcePressurePerIter(llvm::raw_ostream &OS) const; |
| 90 | void printResourcePressurePerInst(llvm::raw_ostream &OS) const; |
| 91 | |
| 92 | public: |
| 93 | ResourcePressureView(const llvm::MCSubtargetInfo &sti, |
| 94 | llvm::MCInstPrinter &Printer, |
| 95 | llvm::ArrayRef<llvm::MCInst> S); |
| 96 | |
| 97 | void onEvent(const HWInstructionEvent &Event) override; |
| 98 | void printView(llvm::raw_ostream &OS) const override { |
| 99 | printResourcePressurePerIter(OS); |
| 100 | printResourcePressurePerInst(OS); |
| 101 | } |
| 102 | StringRef getNameAsString() const override { return "ResourcePressureView" ; } |
| 103 | json::Value toJSON() const override; |
| 104 | }; |
| 105 | } // namespace mca |
| 106 | } // namespace llvm |
| 107 | |
| 108 | #endif |
| 109 | |