1 //===--------------------- InstructionInfoView.h ----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file implements the instruction info view.
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)
25 /// [6]: HasSideEffects
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
32 //===----------------------------------------------------------------------===//
34 #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
35 #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
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"
48 #define DEBUG_TYPE "llvm-mca"
53 /// A view that prints out generic instruction information.
54 class InstructionInfoView
: public InstructionView
{
55 const llvm::MCInstrInfo
&MCII
;
59 using UniqueInst
= std::unique_ptr
<Instruction
>;
60 ArrayRef
<UniqueInst
> LoweredInsts
;
61 const InstrumentManager
&IM
;
62 using InstToInstrumentsT
=
63 DenseMap
<const MCInst
*, SmallVector
<mca::Instrument
*>>;
64 const InstToInstrumentsT
&InstToInstruments
;
66 struct InstructionInfoViewData
{
67 unsigned NumMicroOpcodes
= 0;
69 std::optional
<double> RThroughput
= 0.0;
71 bool mayStore
= false;
72 bool hasUnmodeledSideEffects
= false;
74 using IIVDVec
= SmallVector
<InstructionInfoViewData
, 16>;
76 /// Place the data into the array of InstructionInfoViewData IIVD.
77 void collectData(MutableArrayRef
<InstructionInfoViewData
> IIVD
) const;
80 InstructionInfoView(const llvm::MCSubtargetInfo
&ST
,
81 const llvm::MCInstrInfo
&II
, CodeEmitter
&C
,
82 bool ShouldPrintEncodings
, llvm::ArrayRef
<llvm::MCInst
> S
,
83 llvm::MCInstPrinter
&IP
,
84 ArrayRef
<UniqueInst
> LoweredInsts
,
85 bool ShouldPrintBarriers
, const InstrumentManager
&IM
,
86 const InstToInstrumentsT
&InstToInstruments
)
87 : InstructionView(ST
, IP
, S
), MCII(II
), CE(C
),
88 PrintEncodings(ShouldPrintEncodings
),
89 PrintBarriers(ShouldPrintBarriers
), LoweredInsts(LoweredInsts
), IM(IM
),
90 InstToInstruments(InstToInstruments
) {}
92 void printView(llvm::raw_ostream
&OS
) const override
;
93 StringRef
getNameAsString() const override
{ return "InstructionInfoView"; }
94 json::Value
toJSON() const override
;
95 json::Object
toJSON(const InstructionInfoViewData
&IIVD
) const;