xref: /freebsd-src/contrib/llvm-project/llvm/tools/llvm-mca/Views/InstructionInfoView.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric //===--------------------- InstructionInfoView.h ----------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric ///
100b57cec5SDimitry Andric /// This file implements the instruction info view.
110b57cec5SDimitry Andric ///
120b57cec5SDimitry Andric /// The goal fo the instruction info view is to print the latency and reciprocal
130b57cec5SDimitry Andric /// throughput information for every instruction in the input sequence.
140b57cec5SDimitry Andric /// This section also reports extra information related to the number of micro
150b57cec5SDimitry Andric /// opcodes, and opcode properties (i.e. 'MayLoad', 'MayStore', 'HasSideEffects)
160b57cec5SDimitry Andric ///
170b57cec5SDimitry Andric /// Example:
180b57cec5SDimitry Andric ///
190b57cec5SDimitry Andric /// Instruction Info:
200b57cec5SDimitry Andric /// [1]: #uOps
210b57cec5SDimitry Andric /// [2]: Latency
220b57cec5SDimitry Andric /// [3]: RThroughput
230b57cec5SDimitry Andric /// [4]: MayLoad
240b57cec5SDimitry Andric /// [5]: MayStore
250b57cec5SDimitry Andric /// [6]: HasSideEffects
260b57cec5SDimitry Andric ///
270b57cec5SDimitry Andric /// [1]    [2]    [3]    [4]    [5]    [6]	Instructions:
280b57cec5SDimitry Andric ///  1      2     1.00                    	vmulps	%xmm0, %xmm1, %xmm2
290b57cec5SDimitry Andric ///  1      3     1.00                    	vhaddps	%xmm2, %xmm2, %xmm3
300b57cec5SDimitry Andric ///  1      3     1.00                    	vhaddps	%xmm3, %xmm3, %xmm4
310b57cec5SDimitry Andric //
320b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
350b57cec5SDimitry Andric #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
360b57cec5SDimitry Andric 
37e8d8bef9SDimitry Andric #include "Views/InstructionView.h"
380b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
39e8d8bef9SDimitry Andric #include "llvm/ADT/SmallVector.h"
400b57cec5SDimitry Andric #include "llvm/MC/MCInst.h"
410b57cec5SDimitry Andric #include "llvm/MC/MCInstPrinter.h"
420b57cec5SDimitry Andric #include "llvm/MC/MCInstrInfo.h"
430b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
448bcb0991SDimitry Andric #include "llvm/MCA/CodeEmitter.h"
45*06c3fb27SDimitry Andric #include "llvm/MCA/CustomBehaviour.h"
460b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric #define DEBUG_TYPE "llvm-mca"
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric namespace llvm {
510b57cec5SDimitry Andric namespace mca {
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric /// A view that prints out generic instruction information.
54e8d8bef9SDimitry Andric class InstructionInfoView : public InstructionView {
550b57cec5SDimitry Andric   const llvm::MCInstrInfo &MCII;
568bcb0991SDimitry Andric   CodeEmitter &CE;
578bcb0991SDimitry Andric   bool PrintEncodings;
5804eeddc0SDimitry Andric   bool PrintBarriers;
5904eeddc0SDimitry Andric   using UniqueInst = std::unique_ptr<Instruction>;
6004eeddc0SDimitry Andric   ArrayRef<UniqueInst> LoweredInsts;
61*06c3fb27SDimitry Andric   const InstrumentManager &IM;
62*06c3fb27SDimitry Andric   using InstToInstrumentsT =
63*06c3fb27SDimitry Andric       DenseMap<const MCInst *, SmallVector<mca::Instrument *>>;
64*06c3fb27SDimitry Andric   const InstToInstrumentsT &InstToInstruments;
65e8d8bef9SDimitry Andric 
66e8d8bef9SDimitry Andric   struct InstructionInfoViewData {
67e8d8bef9SDimitry Andric     unsigned NumMicroOpcodes = 0;
68e8d8bef9SDimitry Andric     unsigned Latency = 0;
69bdd1243dSDimitry Andric     std::optional<double> RThroughput = 0.0;
70e8d8bef9SDimitry Andric     bool mayLoad = false;
71e8d8bef9SDimitry Andric     bool mayStore = false;
72e8d8bef9SDimitry Andric     bool hasUnmodeledSideEffects = false;
73e8d8bef9SDimitry Andric   };
74e8d8bef9SDimitry Andric   using IIVDVec = SmallVector<InstructionInfoViewData, 16>;
75e8d8bef9SDimitry Andric 
76e8d8bef9SDimitry Andric   /// Place the data into the array of InstructionInfoViewData IIVD.
77e8d8bef9SDimitry Andric   void collectData(MutableArrayRef<InstructionInfoViewData> IIVD) const;
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric 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)808bcb0991SDimitry Andric   InstructionInfoView(const llvm::MCSubtargetInfo &ST,
818bcb0991SDimitry Andric                       const llvm::MCInstrInfo &II, CodeEmitter &C,
828bcb0991SDimitry Andric                       bool ShouldPrintEncodings, llvm::ArrayRef<llvm::MCInst> S,
8304eeddc0SDimitry Andric                       llvm::MCInstPrinter &IP,
8404eeddc0SDimitry Andric                       ArrayRef<UniqueInst> LoweredInsts,
85*06c3fb27SDimitry Andric                       bool ShouldPrintBarriers, const InstrumentManager &IM,
86*06c3fb27SDimitry Andric                       const InstToInstrumentsT &InstToInstruments)
87e8d8bef9SDimitry Andric       : InstructionView(ST, IP, S), MCII(II), CE(C),
8804eeddc0SDimitry Andric         PrintEncodings(ShouldPrintEncodings),
89*06c3fb27SDimitry Andric         PrintBarriers(ShouldPrintBarriers), LoweredInsts(LoweredInsts), IM(IM),
90*06c3fb27SDimitry Andric         InstToInstruments(InstToInstruments) {}
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric   void printView(llvm::raw_ostream &OS) const override;
getNameAsString()93e8d8bef9SDimitry Andric   StringRef getNameAsString() const override { return "InstructionInfoView"; }
94e8d8bef9SDimitry Andric   json::Value toJSON() const override;
95e8d8bef9SDimitry Andric   json::Object toJSON(const InstructionInfoViewData &IIVD) const;
960b57cec5SDimitry Andric };
970b57cec5SDimitry Andric } // namespace mca
980b57cec5SDimitry Andric } // namespace llvm
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric #endif
101