Skip to content

Commit b0c1a45

Browse files
AMDGPU/MC: Refactor decoders. Rework decoders for float immediates
decodeFPImmed creates immediate operand using register operand width, but size of created immediate should correspond to OperandType for RegisterOperand. e.g. OPW128 could be used for RegisterOperands that use v2f64 v4f32 and v8f16. Each RegisterOperands would have different OperandType and require that immediate is decoded using 64, 32 and 16 bit immediate respectively. decodeOperand_<RegClass> only provides width for register decoding, introduce decodeOperand_<RegClass>_Imm<ImmWidth> that also provides width for immediate decoding. Refactor RegisterOperands: - decoders get _Imm<ImmWidth> suffix in some cases - removed unused RegisterOperands defined via multiclass - use different RegisterOperand in a few places, new RegisterOperand's decoder corresponds to the number of bits used for operand's encoding Refactor decoder functions: - add asserts for the size of encoding that will be decoded - regroup them according to the method of decoding decodeOperand_<RegClass> (register only, no immediate) decoders can now create immediate of consistent size, use it for better diagnostic of 'invalid immediate'. Differential Revision: https://reviews.llvm.org/D142636
1 parent 6953dc9 commit b0c1a45

File tree

10 files changed

+310
-662
lines changed

10 files changed

+310
-662
lines changed

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 162 additions & 410 deletions
Large diffs are not rendered by default.

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -166,58 +166,6 @@ class AMDGPUDisassembler : public MCDisassembler {
166166
DecodeStatus convertVOPCDPPInst(MCInst &MI) const;
167167
void convertMacDPPInst(MCInst &MI) const;
168168

169-
MCOperand decodeOperand_VGPR_32(unsigned Val) const;
170-
MCOperand decodeOperand_VGPR_32_Lo128(unsigned Val) const;
171-
MCOperand decodeOperand_VRegOrLds_32(unsigned Val) const;
172-
173-
MCOperand decodeOperand_VS_32(unsigned Val) const;
174-
MCOperand decodeOperand_VS_64(unsigned Val) const;
175-
MCOperand decodeOperand_VS_128(unsigned Val) const;
176-
MCOperand decodeOperand_VSrc16(unsigned Val) const;
177-
MCOperand decodeOperand_VSrcV216(unsigned Val) const;
178-
MCOperand decodeOperand_VSrcV232(unsigned Val) const;
179-
180-
MCOperand decodeOperand_VReg_64(unsigned Val) const;
181-
MCOperand decodeOperand_VReg_96(unsigned Val) const;
182-
MCOperand decodeOperand_VReg_128(unsigned Val) const;
183-
MCOperand decodeOperand_VReg_256(unsigned Val) const;
184-
MCOperand decodeOperand_VReg_288(unsigned Val) const;
185-
MCOperand decodeOperand_VReg_320(unsigned Val) const;
186-
MCOperand decodeOperand_VReg_352(unsigned Val) const;
187-
MCOperand decodeOperand_VReg_384(unsigned Val) const;
188-
MCOperand decodeOperand_VReg_512(unsigned Val) const;
189-
MCOperand decodeOperand_VReg_1024(unsigned Val) const;
190-
191-
MCOperand decodeOperand_SReg_32(unsigned Val) const;
192-
MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const;
193-
MCOperand decodeOperand_SReg_32_XEXEC_HI(unsigned Val) const;
194-
MCOperand decodeOperand_SRegOrLds_32(unsigned Val) const;
195-
MCOperand decodeOperand_SReg_64(unsigned Val) const;
196-
MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const;
197-
MCOperand decodeOperand_SReg_128(unsigned Val) const;
198-
MCOperand decodeOperand_SReg_256(unsigned Val) const;
199-
MCOperand decodeOperand_SReg_288(unsigned Val) const;
200-
MCOperand decodeOperand_SReg_320(unsigned Val) const;
201-
MCOperand decodeOperand_SReg_352(unsigned Val) const;
202-
MCOperand decodeOperand_SReg_384(unsigned Val) const;
203-
MCOperand decodeOperand_SReg_512(unsigned Val) const;
204-
205-
MCOperand decodeOperand_AGPR_32(unsigned Val) const;
206-
MCOperand decodeOperand_AReg_64(unsigned Val) const;
207-
MCOperand decodeOperand_AReg_128(unsigned Val) const;
208-
MCOperand decodeOperand_AReg_256(unsigned Val) const;
209-
MCOperand decodeOperand_AReg_288(unsigned Val) const;
210-
MCOperand decodeOperand_AReg_320(unsigned Val) const;
211-
MCOperand decodeOperand_AReg_352(unsigned Val) const;
212-
MCOperand decodeOperand_AReg_384(unsigned Val) const;
213-
MCOperand decodeOperand_AReg_512(unsigned Val) const;
214-
MCOperand decodeOperand_AReg_1024(unsigned Val) const;
215-
MCOperand decodeOperand_AV_32(unsigned Val) const;
216-
MCOperand decodeOperand_AV_64(unsigned Val) const;
217-
MCOperand decodeOperand_AV_128(unsigned Val) const;
218-
MCOperand decodeOperand_AVDst_128(unsigned Val) const;
219-
MCOperand decodeOperand_AVDst_512(unsigned Val) const;
220-
221169
enum OpWidthTy {
222170
OPW32,
223171
OPW64,
@@ -244,18 +192,21 @@ class AMDGPUDisassembler : public MCDisassembler {
244192
unsigned getTtmpClassId(const OpWidthTy Width) const;
245193

246194
static MCOperand decodeIntImmed(unsigned Imm);
247-
static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm);
195+
static MCOperand decodeFPImmed(unsigned ImmWidth, unsigned Imm);
196+
248197
MCOperand decodeMandatoryLiteralConstant(unsigned Imm) const;
249198
MCOperand decodeLiteralConstant() const;
250199

251200
MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val,
252-
bool MandatoryLiteral = false) const;
253-
MCOperand decodeDstOp(const OpWidthTy Width, unsigned Val) const;
201+
bool MandatoryLiteral = false,
202+
unsigned ImmWidth = 0) const;
203+
254204
MCOperand decodeVOPDDstYOp(MCInst &Inst, unsigned Val) const;
255205
MCOperand decodeSpecialReg32(unsigned Val) const;
256206
MCOperand decodeSpecialReg64(unsigned Val) const;
257207

258-
MCOperand decodeSDWASrc(const OpWidthTy Width, unsigned Val) const;
208+
MCOperand decodeSDWASrc(const OpWidthTy Width, unsigned Val,
209+
unsigned ImmWidth = 0) const;
259210
MCOperand decodeSDWASrc16(unsigned Val) const;
260211
MCOperand decodeSDWASrc32(unsigned Val) const;
261212
MCOperand decodeSDWAVopcDst(unsigned Val) const;

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,10 @@ void AMDGPUInstPrinter::printRegularOperand(const MCInst *MI, unsigned OpNo,
737737
O << formatDec(Op.getImm());
738738
break;
739739
case MCOI::OPERAND_REGISTER:
740-
// FIXME: This should be removed and handled somewhere else. Seems to come
741-
// from a disassembler bug.
742-
O << "/*invalid immediate*/";
740+
// Disassembler does not fail when operand should not allow immediate
741+
// operands but decodes them into 32bit immediate operand.
742+
printImmediate32(Op.getImm(), STI, O);
743+
O << "/*Invalid immediate*/";
743744
break;
744745
default:
745746
// We hit this for the immediate instruction bits that don't yet have a

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ class getVOP3SrcForVT<ValueType VT> {
17071707
bit isFP = isFloatType<VT>.ret;
17081708
RegisterOperand ret =
17091709
!if(!eq(VT.Size, 128),
1710-
VSrc_128,
1710+
VRegSrc_128,
17111711
!if(!eq(VT.Size, 64),
17121712
!if(isFP,
17131713
!if(!eq(VT.Value, v2f32.Value),
@@ -2435,7 +2435,7 @@ class VOPProfile <list<ValueType> _ArgVT, bit _EnableClamp = 0> {
24352435
field RegisterClass Src1DPP = getVregSrcForVT<Src1VT>.ret;
24362436
field RegisterClass Src2DPP = getVregSrcForVT<Src2VT>.ret;
24372437
field RegisterOperand Src0VOP3DPP = VGPRSrc_32;
2438-
field RegisterOperand Src1VOP3DPP = VGPRSrc_32;
2438+
field RegisterOperand Src1VOP3DPP = VRegSrc_32;
24392439
field RegisterOperand Src2VOP3DPP = getVOP3DPPSrcForVT<Src2VT>.ret;
24402440
field RegisterOperand Src0SDWA = getSDWASrcForVT<Src0VT>.ret;
24412441
field RegisterOperand Src1SDWA = getSDWASrcForVT<Src0VT>.ret;

0 commit comments

Comments
 (0)