109 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8/// \file9///10/// This file define class ResourcePressureView.11/// Class ResourcePressureView observes hardware events generated by12/// the Pipeline object and collects statistics related to resource usage at13/// instruction granularity.14/// Resource pressure information is then printed out to a stream in the15/// form of a table like the one from the example below:16///17/// Resources:18/// [0] - JALU019/// [1] - JALU120/// [2] - JDiv21/// [3] - JFPM22/// [4] - JFPU023/// [5] - JFPU124/// [6] - JLAGU25/// [7] - JSAGU26/// [8] - JSTC27/// [9] - JVIMUL28///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.0032///33/// Resource pressure by instruction:34/// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions:35/// - - - - - 1.00 - - - - vpermilpd $1, %xmm0,36/// %xmm137/// - - - - 1.00 - - - - - vaddps %xmm0, %xmm1,38/// %xmm239/// - - - - - 1.00 - - - - vmovshdup %xmm2, %xmm340/// - - - - 1.00 - - - - - vaddss %xmm2, %xmm3,41/// %xmm442///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 have45/// a reciprocal throughput of 1cy.46/// Each add is issued to pipeline JFPU0, while each shuffle is issued to47/// pipeline JFPU1. The overall pressure per iteration is reported by two48/// tables: the first smaller table is the resource pressure per iteration;49/// the second table reports resource pressure per instruction. Values are the50/// average resource cycles consumed by an instruction.51/// Every vector add from the example uses resource JFPU0 for an average of 1cy52/// per iteration. Consequently, the resource pressure on JFPU0 is of 2cy per53/// iteration.54///55//===----------------------------------------------------------------------===//56 57#ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H58#define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H59 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 68namespace llvm {69namespace mca {70 71/// This class collects resource pressure statistics and it is able to print72/// out all the collected information as a table to an output stream.73class ResourcePressureView : public InstructionView {74 unsigned LastInstructionIdx;75 76 // Map to quickly obtain the ResourceUsage column index from a processor77 // 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 92public: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 mca106} // namespace llvm107 108#endif109