Path: blob/main/contrib/llvm-project/llvm/tools/llvm-mca/Views/ResourcePressureView.h
35290 views
//===--------------------- ResourcePressureView.h ---------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8///9/// This file define class ResourcePressureView.10/// Class ResourcePressureView observes hardware events generated by11/// the Pipeline object and collects statistics related to resource usage at12/// instruction granularity.13/// Resource pressure information is then printed out to a stream in the14/// form of a table like the one from the example below:15///16/// Resources:17/// [0] - JALU018/// [1] - JALU119/// [2] - JDiv20/// [3] - JFPM21/// [4] - JFPU022/// [5] - JFPU123/// [6] - JLAGU24/// [7] - JSAGU25/// [8] - JSTC26/// [9] - JVIMUL27///28/// Resource pressure per iteration:29/// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]30/// 0.00 0.00 0.00 0.00 2.00 2.00 0.00 0.00 0.00 0.0031///32/// Resource pressure by instruction:33/// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions:34/// - - - - - 1.00 - - - - vpermilpd $1, %xmm0,35/// %xmm136/// - - - - 1.00 - - - - - vaddps %xmm0, %xmm1,37/// %xmm238/// - - - - - 1.00 - - - - vmovshdup %xmm2, %xmm339/// - - - - 1.00 - - - - - vaddss %xmm2, %xmm3,40/// %xmm441///42/// In this example, we have AVX code executed on AMD Jaguar (btver2).43/// Both shuffles and vector floating point add operations on XMM registers have44/// a reciprocal throughput of 1cy.45/// Each add is issued to pipeline JFPU0, while each shuffle is issued to46/// pipeline JFPU1. The overall pressure per iteration is reported by two47/// tables: the first smaller table is the resource pressure per iteration;48/// the second table reports resource pressure per instruction. Values are the49/// average resource cycles consumed by an instruction.50/// Every vector add from the example uses resource JFPU0 for an average of 1cy51/// per iteration. Consequently, the resource pressure on JFPU0 is of 2cy per52/// iteration.53///54//===----------------------------------------------------------------------===//5556#ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H57#define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H5859#include "Views/InstructionView.h"60#include "llvm/ADT/ArrayRef.h"61#include "llvm/ADT/DenseMap.h"62#include "llvm/MC/MCInst.h"63#include "llvm/MC/MCInstPrinter.h"64#include "llvm/MC/MCSubtargetInfo.h"65#include "llvm/Support/JSON.h"6667namespace llvm {68namespace mca {6970/// This class collects resource pressure statistics and it is able to print71/// out all the collected information as a table to an output stream.72class ResourcePressureView : public InstructionView {73unsigned LastInstructionIdx;7475// Map to quickly obtain the ResourceUsage column index from a processor76// resource ID.77llvm::DenseMap<unsigned, unsigned> Resource2VecIndex;7879// Table of resources used by instructions.80std::vector<ReleaseAtCycles> ResourceUsage;81unsigned NumResourceUnits;8283void printResourcePressurePerIter(llvm::raw_ostream &OS) const;84void printResourcePressurePerInst(llvm::raw_ostream &OS) const;8586public:87ResourcePressureView(const llvm::MCSubtargetInfo &sti,88llvm::MCInstPrinter &Printer,89llvm::ArrayRef<llvm::MCInst> S);9091void onEvent(const HWInstructionEvent &Event) override;92void printView(llvm::raw_ostream &OS) const override {93printResourcePressurePerIter(OS);94printResourcePressurePerInst(OS);95}96StringRef getNameAsString() const override { return "ResourcePressureView"; }97json::Value toJSON() const override;98};99} // namespace mca100} // namespace llvm101102#endif103104105