1 //===--------------------- ResourcePressureView.h ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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:
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
34 /// Resource pressure by instruction:
35 /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions:
36 /// - - - - - 1.00 - - - - vpermilpd $1, %xmm0,
38 /// - - - - 1.00 - - - - - vaddps %xmm0, %xmm1,
40 /// - - - - - 1.00 - - - - vmovshdup %xmm2, %xmm3
41 /// - - - - 1.00 - - - - - vaddss %xmm2, %xmm3,
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
56 //===----------------------------------------------------------------------===//
58 #ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
59 #define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
61 #include "SourceMgr.h"
63 #include "llvm/ADT/DenseMap.h"
64 #include "llvm/MC/MCInstPrinter.h"
65 #include "llvm/MC/MCSubtargetInfo.h"
72 /// This class collects resource pressure statistics and it is able to print
73 /// out all the collected information as a table to an output stream.
74 class ResourcePressureView : public View {
75 const llvm::MCSubtargetInfo &STI;
76 llvm::MCInstPrinter &MCIP;
77 const SourceMgr &Source;
79 // Map to quickly obtain the ResourceUsage column index from a processor
81 llvm::DenseMap<unsigned, unsigned> Resource2VecIndex;
83 // Table of resources used by instructions.
84 std::vector<double> ResourceUsage;
85 unsigned NumResourceUnits;
87 const llvm::MCInst &GetMCInstFromIndex(unsigned Index) const;
88 void printResourcePressurePerIteration(llvm::raw_ostream &OS,
89 unsigned Executions) const;
90 void printResourcePressurePerInstruction(llvm::raw_ostream &OS,
91 unsigned Executions) const;
95 ResourcePressureView(const llvm::MCSubtargetInfo &sti,
96 llvm::MCInstPrinter &Printer, const SourceMgr &SM)
97 : STI(sti), MCIP(Printer), Source(SM) {
101 void onInstructionEvent(const HWInstructionEvent &Event) override;
103 void printView(llvm::raw_ostream &OS) const override {
104 unsigned Executions = Source.getNumIterations();
105 printResourcePressurePerIteration(OS, Executions);
106 printResourcePressurePerInstruction(OS, Executions);