110aa09f0SMatt Davis //===--------------------- InstructionInfoView.h ----------------*- C++ -*-===// 210aa09f0SMatt Davis // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 610aa09f0SMatt Davis // 710aa09f0SMatt Davis //===----------------------------------------------------------------------===// 810aa09f0SMatt Davis /// \file 910aa09f0SMatt Davis /// 1010aa09f0SMatt Davis /// This file implements the instruction info view. 1110aa09f0SMatt Davis /// 1210aa09f0SMatt Davis /// The goal fo the instruction info view is to print the latency and reciprocal 1310aa09f0SMatt Davis /// throughput information for every instruction in the input sequence. 1410aa09f0SMatt Davis /// This section also reports extra information related to the number of micro 1510aa09f0SMatt Davis /// opcodes, and opcode properties (i.e. 'MayLoad', 'MayStore', 'HasSideEffects) 1610aa09f0SMatt Davis /// 1710aa09f0SMatt Davis /// Example: 1810aa09f0SMatt Davis /// 1910aa09f0SMatt Davis /// Instruction Info: 2010aa09f0SMatt Davis /// [1]: #uOps 2110aa09f0SMatt Davis /// [2]: Latency 2210aa09f0SMatt Davis /// [3]: RThroughput 2310aa09f0SMatt Davis /// [4]: MayLoad 2410aa09f0SMatt Davis /// [5]: MayStore 2510aa09f0SMatt Davis /// [6]: HasSideEffects 2610aa09f0SMatt Davis /// 2710aa09f0SMatt Davis /// [1] [2] [3] [4] [5] [6] Instructions: 2810aa09f0SMatt Davis /// 1 2 1.00 vmulps %xmm0, %xmm1, %xmm2 2910aa09f0SMatt Davis /// 1 3 1.00 vhaddps %xmm2, %xmm2, %xmm3 3010aa09f0SMatt Davis /// 1 3 1.00 vhaddps %xmm3, %xmm3, %xmm4 3110aa09f0SMatt Davis // 3210aa09f0SMatt Davis //===----------------------------------------------------------------------===// 3310aa09f0SMatt Davis 3410aa09f0SMatt Davis #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H 3510aa09f0SMatt Davis #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H 3610aa09f0SMatt Davis 37d38be2baSWolfgang Pieb #include "Views/InstructionView.h" 3884d00513SAndrea Di Biagio #include "llvm/ADT/ArrayRef.h" 39cf6adecdSWolfgang Pieb #include "llvm/ADT/SmallVector.h" 4084d00513SAndrea Di Biagio #include "llvm/MC/MCInst.h" 4110aa09f0SMatt Davis #include "llvm/MC/MCInstPrinter.h" 4210aa09f0SMatt Davis #include "llvm/MC/MCInstrInfo.h" 4310aa09f0SMatt Davis #include "llvm/MC/MCSubtargetInfo.h" 44cbec9af6SAndrea Di Biagio #include "llvm/MCA/CodeEmitter.h" 45*c1fe1474SMichael Maitland #include "llvm/MCA/CustomBehaviour.h" 4610aa09f0SMatt Davis #include "llvm/Support/raw_ostream.h" 4710aa09f0SMatt Davis 4810aa09f0SMatt Davis #define DEBUG_TYPE "llvm-mca" 4910aa09f0SMatt Davis 505a8fd657SFangrui Song namespace llvm { 5110aa09f0SMatt Davis namespace mca { 5210aa09f0SMatt Davis 5310aa09f0SMatt Davis /// A view that prints out generic instruction information. 54e02920feSWolfgang Pieb class InstructionInfoView : public InstructionView { 5510aa09f0SMatt Davis const llvm::MCInstrInfo &MCII; 56cbec9af6SAndrea Di Biagio CodeEmitter &CE; 57cbec9af6SAndrea Di Biagio bool PrintEncodings; 5885e6e748SPatrick Holland bool PrintBarriers; 5985e6e748SPatrick Holland using UniqueInst = std::unique_ptr<Instruction>; 6085e6e748SPatrick Holland ArrayRef<UniqueInst> LoweredInsts; 61*c1fe1474SMichael Maitland const InstrumentManager &IM; 62*c1fe1474SMichael Maitland using InstToInstrumentsT = 63*c1fe1474SMichael Maitland DenseMap<const MCInst *, SmallVector<mca::Instrument *>>; 64*c1fe1474SMichael Maitland const InstToInstrumentsT &InstToInstruments; 6510aa09f0SMatt Davis 66cf6adecdSWolfgang Pieb struct InstructionInfoViewData { 67cf6adecdSWolfgang Pieb unsigned NumMicroOpcodes = 0; 68cf6adecdSWolfgang Pieb unsigned Latency = 0; 69da2f5d0aSFangrui Song std::optional<double> RThroughput = 0.0; 70cf6adecdSWolfgang Pieb bool mayLoad = false; 71cf6adecdSWolfgang Pieb bool mayStore = false; 72cf6adecdSWolfgang Pieb bool hasUnmodeledSideEffects = false; 73cf6adecdSWolfgang Pieb }; 74cf6adecdSWolfgang Pieb using IIVDVec = SmallVector<InstructionInfoViewData, 16>; 75cf6adecdSWolfgang Pieb 76cf6adecdSWolfgang Pieb /// Place the data into the array of InstructionInfoViewData IIVD. 77cf6adecdSWolfgang Pieb void collectData(MutableArrayRef<InstructionInfoViewData> IIVD) const; 78cf6adecdSWolfgang Pieb 7910aa09f0SMatt Davis public: InstructionInfoView(const llvm::MCSubtargetInfo & ST,const llvm::MCInstrInfo & II,CodeEmitter & C,bool ShouldPrintEncodings,llvm::ArrayRef<llvm::MCInst> S,llvm::MCInstPrinter & IP,ArrayRef<UniqueInst> LoweredInsts,bool ShouldPrintBarriers,const InstrumentManager & IM,const InstToInstrumentsT & InstToInstruments)80cbec9af6SAndrea Di Biagio InstructionInfoView(const llvm::MCSubtargetInfo &ST, 81cbec9af6SAndrea Di Biagio const llvm::MCInstrInfo &II, CodeEmitter &C, 82cbec9af6SAndrea Di Biagio bool ShouldPrintEncodings, llvm::ArrayRef<llvm::MCInst> S, 8385e6e748SPatrick Holland llvm::MCInstPrinter &IP, 8485e6e748SPatrick Holland ArrayRef<UniqueInst> LoweredInsts, 85*c1fe1474SMichael Maitland bool ShouldPrintBarriers, const InstrumentManager &IM, 86*c1fe1474SMichael Maitland const InstToInstrumentsT &InstToInstruments) 87e02920feSWolfgang Pieb : InstructionView(ST, IP, S), MCII(II), CE(C), 8885e6e748SPatrick Holland PrintEncodings(ShouldPrintEncodings), 89*c1fe1474SMichael Maitland PrintBarriers(ShouldPrintBarriers), LoweredInsts(LoweredInsts), IM(IM), 90*c1fe1474SMichael Maitland InstToInstruments(InstToInstruments) {} 9110aa09f0SMatt Davis 9210aa09f0SMatt Davis void printView(llvm::raw_ostream &OS) const override; getNameAsString()93d38be2baSWolfgang Pieb StringRef getNameAsString() const override { return "InstructionInfoView"; } 94c6e8f814SWolfgang Pieb json::Value toJSON() const override; 95d38be2baSWolfgang Pieb json::Object toJSON(const InstructionInfoViewData &IIVD) const; 9610aa09f0SMatt Davis }; 9710aa09f0SMatt Davis } // namespace mca 985a8fd657SFangrui Song } // namespace llvm 9910aa09f0SMatt Davis 10010aa09f0SMatt Davis #endif 101