[llvm] 905fa15 - [AMDGPU][AsmParser] Distinguish literal and modifier SMEM offsets.
Ivan Kosarev via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 28 04:59:11 PST 2023
Author: Ivan Kosarev
Date: 2023-02-28T12:58:54Z
New Revision: 905fa15d84a69a0b31332868880568c825d9b0f1
URL: https://github.com/llvm/llvm-project/commit/905fa15d84a69a0b31332868880568c825d9b0f1
DIFF: https://github.com/llvm/llvm-project/commit/905fa15d84a69a0b31332868880568c825d9b0f1.diff
LOG: [AMDGPU][AsmParser] Distinguish literal and modifier SMEM offsets.
Reviewed By: foad
Differential Revision: https://reviews.llvm.org/D144902
Added:
Modified:
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/lib/Target/AMDGPU/SMInstructions.td
llvm/test/MC/AMDGPU/gfx11_asm_err.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 99931018811a0..70b186d28d89b 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -119,6 +119,7 @@ class AMDGPUOperand : public MCParsedAsmOperand {
ImmTyInstOffset,
ImmTyOffset0,
ImmTyOffset1,
+ ImmTySMEMOffsetMod,
ImmTyCPol,
ImmTySWZ,
ImmTyTFE,
@@ -372,7 +373,7 @@ class AMDGPUOperand : public MCParsedAsmOperand {
bool isOffset() const { return isImmTy(ImmTyOffset) && isUInt<16>(getImm()); }
bool isOffset0() const { return isImmTy(ImmTyOffset0) && isUInt<8>(getImm()); }
bool isOffset1() const { return isImmTy(ImmTyOffset1) && isUInt<8>(getImm()); }
-
+ bool isSMEMOffsetMod() const { return isImmTy(ImmTySMEMOffsetMod); }
bool isFlatOffset() const { return isImmTy(ImmTyOffset) || isImmTy(ImmTyInstOffset); }
bool isGDS() const { return isImmTy(ImmTyGDS); }
bool isLDS() const { return isImmTy(ImmTyLDS); }
@@ -1034,6 +1035,7 @@ class AMDGPUOperand : public MCParsedAsmOperand {
case ImmTyInstOffset: OS << "InstOffset"; break;
case ImmTyOffset0: OS << "Offset0"; break;
case ImmTyOffset1: OS << "Offset1"; break;
+ case ImmTySMEMOffsetMod: OS << "SMEMOffsetMod"; break;
case ImmTyCPol: OS << "CPol"; break;
case ImmTySWZ: OS << "SWZ"; break;
case ImmTyTFE: OS << "TFE"; break;
@@ -1755,6 +1757,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
AMDGPUOperand::Ptr defaultSMRDOffset8() const;
AMDGPUOperand::Ptr defaultSMEMOffset() const;
+ AMDGPUOperand::Ptr defaultSMEMOffsetMod() const;
AMDGPUOperand::Ptr defaultSMRDLiteralOffset() const;
AMDGPUOperand::Ptr defaultFlatOffset() const;
@@ -4154,7 +4157,7 @@ SMLoc AMDGPUAsmParser::getSMEMOffsetLoc(const OperandVector &Operands) const {
// Start with second operand because SMEM Offset cannot be dst or src0.
for (unsigned i = 2, e = Operands.size(); i != e; ++i) {
AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
- if (Op.isSMEMOffset())
+ if (Op.isSMEMOffset() || Op.isSMEMOffsetMod())
return Op.getStartLoc();
}
return getLoc();
@@ -7938,7 +7941,8 @@ void AMDGPUAsmParser::cvtSMEMAtomic(MCInst &Inst, const OperandVector &Operands)
if ((int)Inst.getNumOperands() <=
AMDGPU::getNamedOperandIdx(Inst.getOpcode(), AMDGPU::OpName::offset))
- addOptionalImmOperand(Inst, Operands, OptionalIdx, AMDGPUOperand::ImmTyOffset);
+ addOptionalImmOperand(Inst, Operands, OptionalIdx,
+ AMDGPUOperand::ImmTySMEMOffsetMod);
addOptionalImmOperand(Inst, Operands, OptionalIdx, AMDGPUOperand::ImmTyCPol, 0);
}
@@ -7962,8 +7966,8 @@ bool AMDGPUOperand::isSMRDOffset8() const {
}
bool AMDGPUOperand::isSMEMOffset() const {
- return isImmTy(ImmTyNone) ||
- isImmTy(ImmTyOffset); // Offset range is checked later by validator.
+ // Offset range is checked later by validator.
+ return isImmLiteral();
}
bool AMDGPUOperand::isSMRDLiteralOffset() const {
@@ -7977,7 +7981,12 @@ AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset8() const {
}
AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMEMOffset() const {
- return AMDGPUOperand::CreateImm(this, 0, SMLoc(), AMDGPUOperand::ImmTyOffset);
+ return AMDGPUOperand::CreateImm(this, 0, SMLoc());
+}
+
+AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMEMOffsetMod() const {
+ return AMDGPUOperand::CreateImm(this, 0, SMLoc(),
+ AMDGPUOperand::ImmTySMEMOffsetMod);
}
AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDLiteralOffset() const {
@@ -9147,8 +9156,6 @@ AMDGPUAsmParser::parseCustomOperand(OperandVector &Operands, unsigned MCK) {
case MCK_ImmNegLo:
return parseOperandArrayWithPrefix("neg_lo", Operands,
AMDGPUOperand::ImmTyNegLo);
- case MCK_ImmSMEMOffset:
- return parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
case MCK_ImmOModSI:
return parseOModOperand(Operands);
case MCK_ImmOpSel:
@@ -9216,8 +9223,6 @@ unsigned AMDGPUAsmParser::validateTargetOperandClass(MCParsedAsmOperand &Op,
return Operand.isInterpAttr() ? Match_Success : Match_InvalidOperand;
case MCK_AttrChan:
return Operand.isAttrChan() ? Match_Success : Match_InvalidOperand;
- case MCK_ImmSMEMOffset:
- return Operand.isSMEMOffset() ? Match_Success : Match_InvalidOperand;
case MCK_SReg_64:
case MCK_SReg_64_XEXEC:
// Null is defined as a 32-bit register but
diff --git a/llvm/lib/Target/AMDGPU/SMInstructions.td b/llvm/lib/Target/AMDGPU/SMInstructions.td
index f271f6d42857d..715d4076c4e08 100644
--- a/llvm/lib/Target/AMDGPU/SMInstructions.td
+++ b/llvm/lib/Target/AMDGPU/SMInstructions.td
@@ -11,17 +11,11 @@ def smrd_offset_8 : NamedOperandU32<"SMRDOffset8",
let OperandType = "OPERAND_IMMEDIATE";
}
-class SMEMOffset : NamedOperandU32<"SMEMOffset",
- NamedMatchClass<"SMEMOffset">> {
- let OperandType = "OPERAND_IMMEDIATE";
- let EncoderMethod = "getSMEMOffsetEncoding";
- let DecoderMethod = "decodeSMEMOffset";
-}
-
-def smem_offset : SMEMOffset;
-
-def smem_offset_mod : SMEMOffset {
- let PrintMethod = "printSMEMOffsetMod";
+let OperandType = "OPERAND_IMMEDIATE",
+ EncoderMethod = "getSMEMOffsetEncoding",
+ DecoderMethod = "decodeSMEMOffset" in {
+def smem_offset : NamedOperandU32<"SMEMOffset", NamedMatchClass<"SMEMOffset">>;
+def smem_offset_mod : NamedIntOperand<i32, "offset", "SMEMOffsetMod">;
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_err.s b/llvm/test/MC/AMDGPU/gfx11_asm_err.s
index 860d0a53b2b43..f668b2458aef5 100644
--- a/llvm/test/MC/AMDGPU/gfx11_asm_err.s
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_err.s
@@ -140,3 +140,6 @@ v_fmac_f32_e64_dpp v5, v2, s3 quad_perm:[3,2,1,0]
v_fmac_f32_e64_dpp v5, v2, 0x1234 quad_perm:[3,2,1,0]
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
+
+s_load_dword s1, s[2:3], s0 0x1
+// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
More information about the llvm-commits
mailing list