Path: blob/main/contrib/llvm-project/llvm/tools/llvm-mca/Views/InstructionInfoView.h
35290 views
//===--------------------- InstructionInfoView.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 implements the instruction info view.10///11/// The goal fo the instruction info view is to print the latency and reciprocal12/// throughput information for every instruction in the input sequence.13/// This section also reports extra information related to the number of micro14/// opcodes, and opcode properties (i.e. 'MayLoad', 'MayStore', 'HasSideEffects)15///16/// Example:17///18/// Instruction Info:19/// [1]: #uOps20/// [2]: Latency21/// [3]: RThroughput22/// [4]: MayLoad23/// [5]: MayStore24/// [6]: HasSideEffects25///26/// [1] [2] [3] [4] [5] [6] Instructions:27/// 1 2 1.00 vmulps %xmm0, %xmm1, %xmm228/// 1 3 1.00 vhaddps %xmm2, %xmm2, %xmm329/// 1 3 1.00 vhaddps %xmm3, %xmm3, %xmm430//31//===----------------------------------------------------------------------===//3233#ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H34#define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H3536#include "Views/InstructionView.h"37#include "llvm/ADT/ArrayRef.h"38#include "llvm/ADT/SmallVector.h"39#include "llvm/MC/MCInst.h"40#include "llvm/MC/MCInstPrinter.h"41#include "llvm/MC/MCInstrInfo.h"42#include "llvm/MC/MCSubtargetInfo.h"43#include "llvm/MCA/CodeEmitter.h"44#include "llvm/MCA/CustomBehaviour.h"45#include "llvm/Support/raw_ostream.h"4647#define DEBUG_TYPE "llvm-mca"4849namespace llvm {50namespace mca {5152/// A view that prints out generic instruction information.53class InstructionInfoView : public InstructionView {54const llvm::MCInstrInfo &MCII;55CodeEmitter &CE;56bool PrintEncodings;57bool PrintBarriers;58using UniqueInst = std::unique_ptr<Instruction>;59ArrayRef<UniqueInst> LoweredInsts;60const InstrumentManager &IM;61using InstToInstrumentsT =62DenseMap<const MCInst *, SmallVector<mca::Instrument *>>;63const InstToInstrumentsT &InstToInstruments;6465struct InstructionInfoViewData {66unsigned NumMicroOpcodes = 0;67unsigned Latency = 0;68std::optional<double> RThroughput = 0.0;69bool mayLoad = false;70bool mayStore = false;71bool hasUnmodeledSideEffects = false;72};73using IIVDVec = SmallVector<InstructionInfoViewData, 16>;7475/// Place the data into the array of InstructionInfoViewData IIVD.76void collectData(MutableArrayRef<InstructionInfoViewData> IIVD) const;7778public:79InstructionInfoView(const llvm::MCSubtargetInfo &ST,80const llvm::MCInstrInfo &II, CodeEmitter &C,81bool ShouldPrintEncodings, llvm::ArrayRef<llvm::MCInst> S,82llvm::MCInstPrinter &IP,83ArrayRef<UniqueInst> LoweredInsts,84bool ShouldPrintBarriers, const InstrumentManager &IM,85const InstToInstrumentsT &InstToInstruments)86: InstructionView(ST, IP, S), MCII(II), CE(C),87PrintEncodings(ShouldPrintEncodings),88PrintBarriers(ShouldPrintBarriers), LoweredInsts(LoweredInsts), IM(IM),89InstToInstruments(InstToInstruments) {}9091void printView(llvm::raw_ostream &OS) const override;92StringRef getNameAsString() const override { return "InstructionInfoView"; }93json::Value toJSON() const override;94json::Object toJSON(const InstructionInfoViewData &IIVD) const;95};96} // namespace mca97} // namespace llvm9899#endif100101102