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// Exposes an interface expected by autogenerated code in
36// FixedLenDecoderEmitter
38private:
39 uint64_t Lo = 0;
40 uint64_t Hi = 0;
41
42public:
43 DecoderUInt128() = default;
45 operator bool() const { return Lo || Hi; }
47 unsigned BitPosition) const {
48 assert(NumBits && NumBits <= 64);
49 assert(BitPosition < 128);
50 uint64_t Val;
51 if (BitPosition < 64)
52 Val = Lo >> BitPosition | Hi << 1 << (63 - BitPosition);
53 else
54 Val = Hi >> (BitPosition - 64);
55 return Val & ((uint64_t(2) << (NumBits - 1)) - 1);
56 }
58 return DecoderUInt128(Lo & RHS.Lo, Hi & RHS.Hi);
59 }
61 return *this & DecoderUInt128(RHS);
62 }
65 return Lo == RHS.Lo && Hi == RHS.Hi;
66 }
68 return Lo != RHS.Lo || Hi != RHS.Hi;
69 }
70 bool operator!=(const int &RHS) { return *this != DecoderUInt128(RHS); }
71};
72
73//===----------------------------------------------------------------------===//
74// AMDGPUDisassembler
75//===----------------------------------------------------------------------===//
76
78private:
79 std::unique_ptr<MCInstrInfo const> const MCII;
80 const MCRegisterInfo &MRI;
81 const MCAsmInfo &MAI;
82 const unsigned TargetMaxInstBytes;
83 mutable ArrayRef<uint8_t> Bytes;
84 mutable uint32_t Literal;
85 mutable uint64_t Literal64;
86 mutable bool HasLiteral;
87 mutable std::optional<bool> EnableWavefrontSize32;
88 unsigned CodeObjectVersion;
89 const MCExpr *UCVersionW64Expr;
90 const MCExpr *UCVersionW32Expr;
91 const MCExpr *UCVersionMDPExpr;
92
93 const MCExpr *createConstantSymbolExpr(StringRef Id, int64_t Val);
94
95 void decodeImmOperands(MCInst &MI, const MCInstrInfo &MCII) const;
96
97public:
99 MCInstrInfo const *MCII);
100 ~AMDGPUDisassembler() override = default;
101
102 void setABIVersion(unsigned Version) override;
103
106 raw_ostream &CS) const override;
107
108 const char* getRegClassName(unsigned RegClassID) const;
109
110 MCOperand createRegOperand(unsigned int RegId) const;
111 MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const;
112 MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const;
113 MCOperand createVGPR16Operand(unsigned RegIdx, bool IsHi) const;
114
115 MCOperand errOperand(unsigned V, const Twine& ErrMsg) const;
116
117 template <typename InsnType>
118 DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, InsnType Inst,
119 uint64_t Address, raw_ostream &Comments) const;
120 template <typename InsnType>
121 DecodeStatus tryDecodeInst(const uint8_t *Table1, const uint8_t *Table2,
122 MCInst &MI, InsnType Inst, uint64_t Address,
123 raw_ostream &Comments) const;
124
126 ArrayRef<uint8_t> Bytes,
127 uint64_t Address) const override;
128
130 ArrayRef<uint8_t> Bytes,
131 uint64_t KdAddress) const;
132
135 ArrayRef<uint8_t> Bytes,
136 raw_string_ostream &KdStream) const;
137
138 /// Decode as directives that handle COMPUTE_PGM_RSRC1.
139 /// \param FourByteBuffer - Bytes holding contents of COMPUTE_PGM_RSRC1.
140 /// \param KdStream - Stream to write the disassembled directives to.
141 // NOLINTNEXTLINE(readability-identifier-naming)
143 raw_string_ostream &KdStream) const;
144
145 /// Decode as directives that handle COMPUTE_PGM_RSRC2.
146 /// \param FourByteBuffer - Bytes holding contents of COMPUTE_PGM_RSRC2.
147 /// \param KdStream - Stream to write the disassembled directives to.
148 // NOLINTNEXTLINE(readability-identifier-naming)
150 raw_string_ostream &KdStream) const;
151
152 /// Decode as directives that handle COMPUTE_PGM_RSRC3.
153 /// \param FourByteBuffer - Bytes holding contents of COMPUTE_PGM_RSRC3.
154 /// \param KdStream - Stream to write the disassembled directives to.
155 // NOLINTNEXTLINE(readability-identifier-naming)
157 raw_string_ostream &KdStream) const;
158
159 void convertEXPInst(MCInst &MI) const;
160 void convertVINTERPInst(MCInst &MI) const;
161 void convertFMAanyK(MCInst &MI) const;
162 void convertSDWAInst(MCInst &MI) const;
163 void convertMAIInst(MCInst &MI) const;
164 void convertWMMAInst(MCInst &MI) const;
165 void convertDPP8Inst(MCInst &MI) const;
166 void convertMIMGInst(MCInst &MI) const;
167 void convertVOP3DPPInst(MCInst &MI) const;
168 void convertVOP3PDPPInst(MCInst &MI) const;
169 void convertVOPCDPPInst(MCInst &MI) const;
170 void convertVOPC64DPPInst(MCInst &MI) const;
171 void convertMacDPPInst(MCInst &MI) const;
172 void convertTrue16OpSel(MCInst &MI) const;
173
174 unsigned getVgprClassId(unsigned Width) const;
175 unsigned getAgprClassId(unsigned Width) const;
176 unsigned getSgprClassId(unsigned Width) const;
177 unsigned getTtmpClassId(unsigned Width) const;
178
179 static MCOperand decodeIntImmed(unsigned Imm);
180
181 MCOperand decodeMandatoryLiteralConstant(unsigned Imm) const;
183 MCOperand decodeLiteralConstant(bool ExtendFP64) const;
185
186 MCOperand decodeSrcOp(unsigned Width, unsigned Val) const;
187
188 MCOperand decodeNonVGPRSrcOp(unsigned Width, unsigned Val) const;
189
190 MCOperand decodeVOPDDstYOp(MCInst &Inst, unsigned Val) const;
191 MCOperand decodeSpecialReg32(unsigned Val) const;
192 MCOperand decodeSpecialReg64(unsigned Val) const;
193 MCOperand decodeSpecialReg96Plus(unsigned Val) const;
194
195 MCOperand decodeSDWASrc(unsigned Width, unsigned Val) const;
196 MCOperand decodeSDWASrc16(unsigned Val) const;
197 MCOperand decodeSDWASrc32(unsigned Val) const;
198 MCOperand decodeSDWAVopcDst(unsigned Val) const;
199
200 MCOperand decodeBoolReg(unsigned Val) const;
201 MCOperand decodeSplitBarrier(unsigned Val) const;
202 MCOperand decodeDpp8FI(unsigned Val) const;
203
204 MCOperand decodeVersionImm(unsigned Imm) const;
205
206 int getTTmpIdx(unsigned Val) const;
207
208 const MCInstrInfo *getMCII() const { return MCII.get(); }
209
210 bool isVI() const;
211 bool isGFX9() const;
212 bool isGFX90A() const;
213 bool isGFX9Plus() const;
214 bool isGFX10() const;
215 bool isGFX10Plus() const;
216 bool isGFX11() const;
217 bool isGFX11Plus() const;
218 bool isGFX12() const;
219 bool isGFX12Plus() const;
220 bool isGFX1250() const;
221
222 bool hasArchitectedFlatScratch() const;
223 bool hasKernargPreload() const;
224
225 bool isMacDPP(MCInst &MI) const;
226};
227
228//===----------------------------------------------------------------------===//
229// AMDGPUSymbolizer
230//===----------------------------------------------------------------------===//
231
233private:
234 void *DisInfo;
235 std::vector<uint64_t> ReferencedAddresses;
236
237public:
238 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
239 void *disInfo)
240 : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {}
241
242 bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream,
243 int64_t Value, uint64_t Address, bool IsBranch,
244 uint64_t Offset, uint64_t OpSize,
245 uint64_t InstSize) override;
246
248 int64_t Value,
249 uint64_t Address) override;
250
252 return ReferencedAddresses;
253 }
254};
255
256} // end namespace llvm
257
258#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
Value * RHS
support::ulittle16_t & Lo
Definition: aarch32.cpp:205
support::ulittle16_t & Hi
Definition: aarch32.cpp:204
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
bool operator==(const DecoderUInt128 &RHS)
DecoderUInt128 operator~() const
bool operator!=(const DecoderUInt128 &RHS)
DecoderUInt128 operator&(const uint64_t &RHS) const
DecoderUInt128 operator&(const DecoderUInt128 &RHS) const
DecoderUInt128(uint64_t Lo, uint64_t Hi=0)
DecoderUInt128()=default
uint64_t extractBitsAsZExtValue(unsigned NumBits, unsigned BitPosition) const
bool operator!=(const int &RHS)
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:856