LLVM 22.0.0git
AMDGPUDisassembler.h
Go to the documentation of this file.
1//===- AMDGPUDisassembler.hpp - Disassembler for AMDGPU ISA -----*- 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//
9/// \file
10///
11/// This file contains declaration for AMDGPU ISA disassembler
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H
16#define LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H
17
18#include "SIDefines.h"
19#include "llvm/ADT/APInt.h"
22#include "llvm/MC/MCInst.h"
23#include "llvm/MC/MCInstrInfo.h"
25#include <memory>
26
27namespace llvm {
28
29class MCAsmInfo;
30class MCInst;
31class MCOperand;
32class MCSubtargetInfo;
33class Twine;
34
35//===----------------------------------------------------------------------===//
36// AMDGPUDisassembler
37//===----------------------------------------------------------------------===//
38
40private:
41 std::unique_ptr<MCInstrInfo const> const MCII;
42 const MCRegisterInfo &MRI;
43 const MCAsmInfo &MAI;
44 const unsigned TargetMaxInstBytes;
45 mutable ArrayRef<uint8_t> Bytes;
46 mutable uint32_t Literal;
47 mutable uint64_t Literal64;
48 mutable bool HasLiteral;
49 mutable std::optional<bool> EnableWavefrontSize32;
50 unsigned CodeObjectVersion;
51 const MCExpr *UCVersionW64Expr;
52 const MCExpr *UCVersionW32Expr;
53 const MCExpr *UCVersionMDPExpr;
54
55 const MCExpr *createConstantSymbolExpr(StringRef Id, int64_t Val);
56
57 void decodeImmOperands(MCInst &MI, const MCInstrInfo &MCII) const;
58
59public:
61 MCInstrInfo const *MCII);
62 ~AMDGPUDisassembler() override = default;
63
64 void setABIVersion(unsigned Version) override;
65
68 raw_ostream &CS) const override;
69
70 const char* getRegClassName(unsigned RegClassID) const;
71
72 MCOperand createRegOperand(unsigned int RegId) const;
73 MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const;
74 MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const;
75 MCOperand createVGPR16Operand(unsigned RegIdx, bool IsHi) const;
76
77 MCOperand errOperand(unsigned V, const Twine& ErrMsg) const;
78
79 template <typename InsnType>
80 DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, InsnType Inst,
81 uint64_t Address, raw_ostream &Comments) const;
82 template <typename InsnType>
83 DecodeStatus tryDecodeInst(const uint8_t *Table1, const uint8_t *Table2,
84 MCInst &MI, InsnType Inst, uint64_t Address,
85 raw_ostream &Comments) const;
86
89 uint64_t Address) const override;
90
93 uint64_t KdAddress) const;
94
98 raw_string_ostream &KdStream) const;
99
100 /// Decode as directives that handle COMPUTE_PGM_RSRC1.
101 /// \param FourByteBuffer - Bytes holding contents of COMPUTE_PGM_RSRC1.
102 /// \param KdStream - Stream to write the disassembled directives to.
103 // NOLINTNEXTLINE(readability-identifier-naming)
105 raw_string_ostream &KdStream) const;
106
107 /// Decode as directives that handle COMPUTE_PGM_RSRC2.
108 /// \param FourByteBuffer - Bytes holding contents of COMPUTE_PGM_RSRC2.
109 /// \param KdStream - Stream to write the disassembled directives to.
110 // NOLINTNEXTLINE(readability-identifier-naming)
112 raw_string_ostream &KdStream) const;
113
114 /// Decode as directives that handle COMPUTE_PGM_RSRC3.
115 /// \param FourByteBuffer - Bytes holding contents of COMPUTE_PGM_RSRC3.
116 /// \param KdStream - Stream to write the disassembled directives to.
117 // NOLINTNEXTLINE(readability-identifier-naming)
119 raw_string_ostream &KdStream) const;
120
121 void convertEXPInst(MCInst &MI) const;
122 void convertVINTERPInst(MCInst &MI) const;
123 void convertFMAanyK(MCInst &MI) const;
124 void convertSDWAInst(MCInst &MI) const;
125 void convertMAIInst(MCInst &MI) const;
126 void convertWMMAInst(MCInst &MI) const;
127 void convertDPP8Inst(MCInst &MI) const;
128 void convertMIMGInst(MCInst &MI) const;
129 void convertVOP3DPPInst(MCInst &MI) const;
130 void convertVOP3PDPPInst(MCInst &MI) const;
131 void convertVOPCDPPInst(MCInst &MI) const;
132 void convertVOPC64DPPInst(MCInst &MI) const;
133 void convertMacDPPInst(MCInst &MI) const;
134 void convertTrue16OpSel(MCInst &MI) const;
135
136 unsigned getVgprClassId(unsigned Width) const;
137 unsigned getAgprClassId(unsigned Width) const;
138 unsigned getSgprClassId(unsigned Width) const;
139 unsigned getTtmpClassId(unsigned Width) const;
140
141 static MCOperand decodeIntImmed(unsigned Imm);
142
143 MCOperand decodeMandatoryLiteralConstant(unsigned Imm) const;
145 MCOperand decodeLiteralConstant(bool ExtendFP64) const;
147
148 MCOperand decodeSrcOp(unsigned Width, unsigned Val) const;
149
150 MCOperand decodeNonVGPRSrcOp(unsigned Width, unsigned Val) const;
151
152 MCOperand decodeVOPDDstYOp(MCInst &Inst, unsigned Val) const;
153 MCOperand decodeSpecialReg32(unsigned Val) const;
154 MCOperand decodeSpecialReg64(unsigned Val) const;
155 MCOperand decodeSpecialReg96Plus(unsigned Val) const;
156
157 MCOperand decodeSDWASrc(unsigned Width, unsigned Val) const;
158 MCOperand decodeSDWASrc16(unsigned Val) const;
159 MCOperand decodeSDWASrc32(unsigned Val) const;
160 MCOperand decodeSDWAVopcDst(unsigned Val) const;
161
162 MCOperand decodeBoolReg(unsigned Val) const;
163 MCOperand decodeSplitBarrier(unsigned Val) const;
164 MCOperand decodeDpp8FI(unsigned Val) const;
165
166 MCOperand decodeVersionImm(unsigned Imm) const;
167
168 int getTTmpIdx(unsigned Val) const;
169
170 const MCInstrInfo *getMCII() const { return MCII.get(); }
171
172 bool isVI() const;
173 bool isGFX9() const;
174 bool isGFX90A() const;
175 bool isGFX9Plus() const;
176 bool isGFX10() const;
177 bool isGFX10Plus() const;
178 bool isGFX11() const;
179 bool isGFX11Plus() const;
180 bool isGFX12() const;
181 bool isGFX12Plus() const;
182 bool isGFX1250() const;
183
184 bool hasArchitectedFlatScratch() const;
185 bool hasKernargPreload() const;
186
187 bool isMacDPP(MCInst &MI) const;
188};
189
190//===----------------------------------------------------------------------===//
191// AMDGPUSymbolizer
192//===----------------------------------------------------------------------===//
193
195private:
196 void *DisInfo;
197 std::vector<uint64_t> ReferencedAddresses;
198
199public:
200 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
201 void *disInfo)
202 : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {}
203
204 bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream,
205 int64_t Value, uint64_t Address, bool IsBranch,
206 uint64_t Offset, uint64_t OpSize,
207 uint64_t InstSize) override;
208
210 int64_t Value,
211 uint64_t Address) override;
212
214 return ReferencedAddresses;
215 }
216};
217
218} // end namespace llvm
219
220#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H
This file implements a class to represent arbitrary precision integral constant values and operations...
uint64_t Size
IRTranslator LLVM IR MI
This file defines the SmallString class.
const MCInstrInfo * getMCII() const
MCOperand decodeLiteral64Constant() const
void convertVOPC64DPPInst(MCInst &MI) const
void convertEXPInst(MCInst &MI) const
MCOperand createRegOperand(unsigned int RegId) const
MCOperand decodeSpecialReg64(unsigned Val) const
const char * getRegClassName(unsigned RegClassID) const
Expected< bool > decodeCOMPUTE_PGM_RSRC1(uint32_t FourByteBuffer, raw_string_ostream &KdStream) const
Decode as directives that handle COMPUTE_PGM_RSRC1.
Expected< bool > decodeKernelDescriptorDirective(DataExtractor::Cursor &Cursor, ArrayRef< uint8_t > Bytes, raw_string_ostream &KdStream) const
void convertVOPCDPPInst(MCInst &MI) const
MCOperand decodeSpecialReg96Plus(unsigned Val) const
MCOperand decodeSDWASrc32(unsigned Val) const
void setABIVersion(unsigned Version) override
ELF-specific, set the ABI version from the object header.
Expected< bool > decodeCOMPUTE_PGM_RSRC2(uint32_t FourByteBuffer, raw_string_ostream &KdStream) const
Decode as directives that handle COMPUTE_PGM_RSRC2.
unsigned getAgprClassId(unsigned Width) const
MCOperand decodeDpp8FI(unsigned Val) const
MCOperand decodeSDWASrc(unsigned Width, unsigned Val) const
void convertFMAanyK(MCInst &MI) const
DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, InsnType Inst, uint64_t Address, raw_ostream &Comments) const
void convertMacDPPInst(MCInst &MI) const
MCOperand decodeVOPDDstYOp(MCInst &Inst, unsigned Val) const
MCOperand decodeBoolReg(unsigned Val) const
void convertDPP8Inst(MCInst &MI) const
MCOperand createVGPR16Operand(unsigned RegIdx, bool IsHi) const
MCOperand errOperand(unsigned V, const Twine &ErrMsg) const
MCOperand decodeVersionImm(unsigned Imm) const
Expected< bool > decodeKernelDescriptor(StringRef KdName, ArrayRef< uint8_t > Bytes, uint64_t KdAddress) const
MCOperand decodeSplitBarrier(unsigned Val) const
void convertVOP3DPPInst(MCInst &MI) const
void convertTrue16OpSel(MCInst &MI) const
MCOperand decodeMandatoryLiteralConstant(unsigned Imm) const
Expected< bool > decodeCOMPUTE_PGM_RSRC3(uint32_t FourByteBuffer, raw_string_ostream &KdStream) const
Decode as directives that handle COMPUTE_PGM_RSRC3.
MCOperand decodeNonVGPRSrcOp(unsigned Width, unsigned Val) const
MCOperand decodeSpecialReg32(unsigned Val) const
MCOperand decodeLiteralConstant(bool ExtendFP64) const
MCOperand decodeSDWAVopcDst(unsigned Val) const
~AMDGPUDisassembler() override=default
void convertVINTERPInst(MCInst &MI) const
void convertSDWAInst(MCInst &MI) const
MCOperand decodeSrcOp(unsigned Width, unsigned Val) const
unsigned getSgprClassId(unsigned Width) const
static MCOperand decodeIntImmed(unsigned Imm)
void convertWMMAInst(MCInst &MI) const
unsigned getVgprClassId(unsigned Width) const
void convertMAIInst(MCInst &MI) const
f8f6f4 instructions have different pseudos depending on the used formats.
unsigned getTtmpClassId(unsigned Width) const
DecodeStatus getInstruction(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CS) const override
Returns the disassembly of a single instruction.
MCOperand decodeMandatoryLiteral64Constant(uint64_t Imm) const
void convertMIMGInst(MCInst &MI) const
bool isMacDPP(MCInst &MI) const
int getTTmpIdx(unsigned Val) const
void convertVOP3PDPPInst(MCInst &MI) const
MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const
MCOperand decodeSDWASrc16(unsigned Val) const
Expected< bool > onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address) const override
Used to perform separate target specific disassembly for a particular symbol.
ArrayRef< uint64_t > getReferencedAddresses() const override
Get the MCSymbolizer's list of addresses that were referenced by symbolizable operands but not resolv...
bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t OpSize, uint64_t InstSize) override
Try to add a symbolic operand instead of Value to the MCInst.
AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo, void *disInfo)
void tryAddingPcLoadReferenceComment(raw_ostream &cStream, int64_t Value, uint64_t Address) override
Try to add a comment on the PC-relative load.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:55
Tagged union holding either a T or a Error.
Definition: Error.h:485
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
Context object for machine code objects.
Definition: MCContext.h:83
Superclass for all disassemblers.
const MCSubtargetInfo & STI
DecodeStatus
Ternary decode status.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:27
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:64
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:40
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Generic base class for all target subtargets.
Symbolize and annotate disassembled instructions.
Definition: MCSymbolizer.h:40
std::unique_ptr< MCRelocationInfo > RelInfo
Definition: MCSymbolizer.h:43
MCContext & Ctx
Definition: MCSymbolizer.h:42
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:851