| 1 | //===--------------------- InstructionInfoView.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-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// |
| 10 | /// This file implements the instruction info view. |
| 11 | /// |
| 12 | /// The goal fo the instruction info view is to print the latency and reciprocal |
| 13 | /// throughput information for every instruction in the input sequence. |
| 14 | /// This section also reports extra information related to the number of micro |
| 15 | /// opcodes, and opcode properties (i.e. 'MayLoad', 'MayStore', 'HasSideEffects) |
| 16 | /// |
| 17 | /// Example: |
| 18 | /// |
| 19 | /// Instruction Info: |
| 20 | /// [1]: #uOps |
| 21 | /// [2]: Latency |
| 22 | /// [3]: RThroughput |
| 23 | /// [4]: MayLoad |
| 24 | /// [5]: MayStore |
| 25 | /// [6]: HasSideEffects |
| 26 | /// |
| 27 | /// [1] [2] [3] [4] [5] [6] Instructions: |
| 28 | /// 1 2 1.00 vmulps %xmm0, %xmm1, %xmm2 |
| 29 | /// 1 3 1.00 vhaddps %xmm2, %xmm2, %xmm3 |
| 30 | /// 1 3 1.00 vhaddps %xmm3, %xmm3, %xmm4 |
| 31 | // |
| 32 | //===----------------------------------------------------------------------===// |
| 33 | |
| 34 | #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H |
| 35 | #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H |
| 36 | |
| 37 | #include "Views/InstructionView.h" |
| 38 | #include "llvm/ADT/ArrayRef.h" |
| 39 | #include "llvm/ADT/SmallVector.h" |
| 40 | #include "llvm/MC/MCInst.h" |
| 41 | #include "llvm/MC/MCInstPrinter.h" |
| 42 | #include "llvm/MC/MCInstrInfo.h" |
| 43 | #include "llvm/MC/MCSubtargetInfo.h" |
| 44 | #include "llvm/MCA/CodeEmitter.h" |
| 45 | #include "llvm/MCA/CustomBehaviour.h" |
| 46 | #include "llvm/Support/raw_ostream.h" |
| 47 | |
| 48 | #define DEBUG_TYPE "llvm-mca" |
| 49 | |
| 50 | namespace llvm { |
| 51 | namespace mca { |
| 52 | |
| 53 | /// A view that prints out generic instruction information. |
| 54 | class InstructionInfoView : public InstructionView { |
| 55 | const llvm::MCInstrInfo &MCII; |
| 56 | CodeEmitter &CE; |
| 57 | bool PrintEncodings; |
| 58 | bool PrintBarriers; |
| 59 | bool PrintFullInfo; |
| 60 | using UniqueInst = std::unique_ptr<Instruction>; |
| 61 | ArrayRef<UniqueInst> LoweredInsts; |
| 62 | const InstrumentManager &IM; |
| 63 | using InstToInstrumentsT = |
| 64 | DenseMap<const MCInst *, SmallVector<mca::Instrument *>>; |
| 65 | const InstToInstrumentsT &InstToInstruments; |
| 66 | |
| 67 | struct InstructionInfoViewData { |
| 68 | unsigned NumMicroOpcodes = 0; |
| 69 | // Latency + ForwardingDelayCycles: negative ReadAdvance |
| 70 | unsigned Latency = 0; |
| 71 | // ReadAvance Bypasses cycles: Latency - ReadAdvance (positive value) |
| 72 | unsigned Bypass = 0; |
| 73 | std::optional<double> RThroughput = 0.0; |
| 74 | bool mayLoad = false; |
| 75 | bool mayStore = false; |
| 76 | bool hasUnmodeledSideEffects = false; |
| 77 | StringRef OpcodeName = "" ; |
| 78 | std::string Resources = "" ; |
| 79 | }; |
| 80 | using IIVDVec = SmallVector<InstructionInfoViewData, 16>; |
| 81 | |
| 82 | /// Place the data into the array of InstructionInfoViewData IIVD. |
| 83 | void collectData(MutableArrayRef<InstructionInfoViewData> IIVD) const; |
| 84 | |
| 85 | /// Extract comment (//, /* */) from the source assembly placed just after |
| 86 | /// instruction. |
| 87 | void (raw_ostream &OS, const llvm::MCInst &Inst) const; |
| 88 | |
| 89 | public: |
| 90 | InstructionInfoView(const llvm::MCSubtargetInfo &ST, |
| 91 | const llvm::MCInstrInfo &II, CodeEmitter &C, |
| 92 | bool ShouldPrintEncodings, llvm::ArrayRef<llvm::MCInst> S, |
| 93 | llvm::MCInstPrinter &IP, |
| 94 | ArrayRef<UniqueInst> LoweredInsts, |
| 95 | bool ShouldPrintBarriers, bool ShouldPrintFullInfo, |
| 96 | const InstrumentManager &IM, |
| 97 | const InstToInstrumentsT &InstToInstruments) |
| 98 | : InstructionView(ST, IP, S), MCII(II), CE(C), |
| 99 | PrintEncodings(ShouldPrintEncodings), |
| 100 | PrintBarriers(ShouldPrintBarriers), PrintFullInfo(ShouldPrintFullInfo), |
| 101 | LoweredInsts(LoweredInsts), IM(IM), |
| 102 | InstToInstruments(InstToInstruments) {} |
| 103 | |
| 104 | void printView(llvm::raw_ostream &OS) const override; |
| 105 | StringRef getNameAsString() const override { return "InstructionInfoView" ; } |
| 106 | json::Value toJSON() const override; |
| 107 | json::Object toJSON(const InstructionInfoViewData &IIVD) const; |
| 108 | }; |
| 109 | } // namespace mca |
| 110 | } // namespace llvm |
| 111 | |
| 112 | #endif |
| 113 | |