[llvm] ef6f3c7 - [AMDGPU][MC][GFX11] Improve diagnostic messages for invalid VOPD syntax
Dmitry Preobrazhensky via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 14 05:22:15 PST 2022
Author: Dmitry Preobrazhensky
Date: 2022-11-14T16:20:20+03:00
New Revision: ef6f3c76f7f473c65ba8380c9d93adb752d1fc50
URL: https://github.com/llvm/llvm-project/commit/ef6f3c76f7f473c65ba8380c9d93adb752d1fc50
DIFF: https://github.com/llvm/llvm-project/commit/ef6f3c76f7f473c65ba8380c9d93adb752d1fc50.diff
LOG: [AMDGPU][MC][GFX11] Improve diagnostic messages for invalid VOPD syntax
Differential Revision: https://reviews.llvm.org/D137842
Added:
llvm/test/MC/AMDGPU/gfx11_asm_vopd_err.s
Modified:
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Removed:
llvm/test/MC/AMDGPU/gfx11_asm_vopd_errs.s
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 4fb9f137a8086..da08a5e4d5b63 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -4784,6 +4784,17 @@ bool AMDGPUAsmParser::checkUnsupportedInstruction(StringRef Mnemo,
return Error(IDLoc, "invalid instruction" + Suggestion);
}
+static bool isInvalidVOPDY(const OperandVector &Operands,
+ uint64_t InvalidOprIdx) {
+ assert(InvalidOprIdx < Operands.size());
+ const auto &Op = ((AMDGPUOperand &)*Operands[InvalidOprIdx]);
+ if (Op.isToken() && InvalidOprIdx > 1) {
+ const auto &PrevOp = ((AMDGPUOperand &)*Operands[InvalidOprIdx - 1]);
+ return PrevOp.isToken() && PrevOp.getToken() == "::";
+ }
+ return false;
+}
+
bool AMDGPUAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
OperandVector &Operands,
MCStreamer &Out,
@@ -4844,6 +4855,9 @@ bool AMDGPUAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
ErrorLoc = ((AMDGPUOperand &)*Operands[ErrorInfo]).getStartLoc();
if (ErrorLoc == SMLoc())
ErrorLoc = IDLoc;
+
+ if (isInvalidVOPDY(Operands, ErrorInfo))
+ return Error(ErrorLoc, "invalid VOPDY instruction");
}
return Error(ErrorLoc, "invalid operand for instruction");
}
@@ -8460,12 +8474,13 @@ OperandMatchResultTy AMDGPUAsmParser::parseVOPD(OperandVector &Operands) {
lex();
lex();
Operands.push_back(AMDGPUOperand::CreateToken(this, "::", S));
+ SMLoc OpYLoc = getLoc();
StringRef OpYName;
if (isToken(AsmToken::Identifier) && !Parser.parseIdentifier(OpYName)) {
- Operands.push_back(AMDGPUOperand::CreateToken(this, OpYName, S));
+ Operands.push_back(AMDGPUOperand::CreateToken(this, OpYName, OpYLoc));
return MatchOperand_Success;
}
- Error(S, "invalid VOPD :: usage");
+ Error(OpYLoc, "expected a VOPDY instruction after ::");
return MatchOperand_ParseFail;
}
return MatchOperand_NoMatch;
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_vopd_errs.s b/llvm/test/MC/AMDGPU/gfx11_asm_vopd_err.s
similarity index 90%
rename from llvm/test/MC/AMDGPU/gfx11_asm_vopd_errs.s
rename to llvm/test/MC/AMDGPU/gfx11_asm_vopd_err.s
index 3866cb458dbb0..bec22526bd124 100644
--- a/llvm/test/MC/AMDGPU/gfx11_asm_vopd_errs.s
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_vopd_err.s
@@ -267,3 +267,47 @@ v_dual_fmamk_f32 v6, v1, 0xaf123456, v3 :: v_dual_fmac_f32 v5, v2
// GFX11: error: src2 operands must use
diff erent VGPR banks
// GFX11-NEXT:{{^}}v_dual_fmamk_f32 v6, v1, 0xaf123456, v3 :: v_dual_fmac_f32 v5, v2, v3
// GFX11-NEXT:{{^}} ^
+
+//===----------------------------------------------------------------------===//
+// Check invalid VOPD syntax.
+//===----------------------------------------------------------------------===//
+
+v_dual_fmamk_f32 v6, v1, 0xaf123456, v2 : : v_dual_fmac_f32 v5, v2, v3
+// GFX11: error: unknown token in expression
+// GFX11-NEXT:{{^}}v_dual_fmamk_f32 v6, v1, 0xaf123456, v2 : : v_dual_fmac_f32 v5, v2, v3
+// GFX11-NEXT:{{^}} ^
+
+v_dual_fmamk_f32 v6, v1, 0xaf123456, v3
+// GFX11: error: too few operands for instruction
+// GFX11-NEXT:{{^}}v_dual_fmamk_f32 v6, v1, 0xaf123456, v3
+// GFX11-NEXT:{{^}}^
+
+v_dual_fmamk_f32 v6, v1, 0xaf123456, v2 :: v_dual_fmac_f32
+// GFX11: error: too few operands for instruction
+// GFX11-NEXT:{{^}}v_dual_fmamk_f32 v6, v1, 0xaf123456, v2 :: v_dual_fmac_f32
+// GFX11-NEXT:{{^}}^
+
+v_dual_add_f32 v255, v4 :: v_add_f32 v6, v1, v3
+// GFX11: error: invalid operand for instruction
+// GFX11-NEXT:{{^}}v_dual_add_f32 v255, v4 :: v_add_f32 v6, v1, v3
+// GFX11-NEXT:{{^}} ^
+
+v_dual_fmamk_f32 v6, v1, 0xaf123456, v3 ::
+// GFX11: error: expected a VOPDY instruction after ::
+// GFX11-NEXT:{{^}}v_dual_fmamk_f32 v6, v1, 0xaf123456, v3 ::
+// GFX11-NEXT:{{^}} ^
+
+v_add_f32 v6, v1, v3 ::
+// GFX11: error: expected a VOPDY instruction after ::
+// GFX11-NEXT:{{^}}v_add_f32 v6, v1, v3 ::
+// GFX11-NEXT:{{^}} ^
+
+v_dual_add_f32 v255::
+// GFX11: error: expected a VOPDY instruction after ::
+// GFX11-NEXT:{{^}}v_dual_add_f32 v255::
+// GFX11-NEXT:{{^}} ^
+
+v_dual_add_f32 v255, v4, v2 :: v_add_f32 v6, v1, v3
+// GFX11: error: invalid VOPDY instruction
+// GFX11-NEXT:{{^}}v_dual_add_f32 v255, v4, v2 :: v_add_f32 v6, v1, v3
+// GFX11-NEXT:{{^}} ^
More information about the llvm-commits
mailing list