[AMDGPU][MC] Improved errors handling for SDWA operands

Reviewers: rampitec

Differential Revision: https://reviews.llvm.org/D95212
This commit is contained in:
Dmitry Preobrazhensky 2021-01-25 19:01:19 +03:00
parent f80782590c
commit 558b3bbb5b
2 changed files with 48 additions and 5 deletions

View File

@ -1297,7 +1297,8 @@ public:
parseNamedBit(const char *Name, OperandVector &Operands,
AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone);
OperandMatchResultTy parseStringWithPrefix(StringRef Prefix,
StringRef &Value);
StringRef &Value,
SMLoc &StringLoc);
bool isModifier();
bool isOperandModifier(const AsmToken &Token, const AsmToken &NextToken) const;
@ -5099,11 +5100,15 @@ static void addOptionalImmOperand(
}
OperandMatchResultTy
AMDGPUAsmParser::parseStringWithPrefix(StringRef Prefix, StringRef &Value) {
AMDGPUAsmParser::parseStringWithPrefix(StringRef Prefix,
StringRef &Value,
SMLoc &StringLoc) {
if (!trySkipId(Prefix, AsmToken::Colon))
return MatchOperand_NoMatch;
return parseId(Value) ? MatchOperand_Success : MatchOperand_ParseFail;
StringLoc = getLoc();
return parseId(Value, "expected an identifier") ? MatchOperand_Success
: MatchOperand_ParseFail;
}
//===----------------------------------------------------------------------===//
@ -7523,7 +7528,8 @@ AMDGPUAsmParser::parseSDWASel(OperandVector &Operands, StringRef Prefix,
StringRef Value;
OperandMatchResultTy res;
res = parseStringWithPrefix(Prefix, Value);
SMLoc StringLoc;
res = parseStringWithPrefix(Prefix, Value, StringLoc);
if (res != MatchOperand_Success) {
return res;
}
@ -7540,6 +7546,7 @@ AMDGPUAsmParser::parseSDWASel(OperandVector &Operands, StringRef Prefix,
.Default(0xffffffff);
if (Int == 0xffffffff) {
Error(StringLoc, "invalid " + Twine(Prefix) + " value");
return MatchOperand_ParseFail;
}
@ -7555,7 +7562,8 @@ AMDGPUAsmParser::parseSDWADstUnused(OperandVector &Operands) {
StringRef Value;
OperandMatchResultTy res;
res = parseStringWithPrefix("dst_unused", Value);
SMLoc StringLoc;
res = parseStringWithPrefix("dst_unused", Value, StringLoc);
if (res != MatchOperand_Success) {
return res;
}
@ -7568,6 +7576,7 @@ AMDGPUAsmParser::parseSDWADstUnused(OperandVector &Operands) {
.Default(0xffffffff);
if (Int == 0xffffffff) {
Error(StringLoc, "invalid dst_unused value");
return MatchOperand_ParseFail;
}

View File

@ -483,6 +483,24 @@ v_mov_b32_sdwa v1, sext(u)
// CHECK-NEXT:{{^}}v_mov_b32_sdwa v1, sext(u)
// CHECK-NEXT:{{^}} ^
//==============================================================================
// expected an identifier
v_mov_b32_sdwa v5, v1 dst_sel:
// CHECK: error: expected an identifier
// CHECK-NEXT:{{^}}v_mov_b32_sdwa v5, v1 dst_sel:
// CHECK-NEXT:{{^}} ^
v_mov_b32_sdwa v5, v1 dst_sel:0
// CHECK: error: expected an identifier
// CHECK-NEXT:{{^}}v_mov_b32_sdwa v5, v1 dst_sel:0
// CHECK-NEXT:{{^}} ^
v_mov_b32_sdwa v5, v1 dst_sel:DWORD dst_unused:[UNUSED_PAD]
// CHECK: error: expected an identifier
// CHECK-NEXT:{{^}}v_mov_b32_sdwa v5, v1 dst_sel:DWORD dst_unused:[UNUSED_PAD]
// CHECK-NEXT:{{^}} ^
//==============================================================================
// expected an opening square bracket
@ -623,6 +641,22 @@ s_waitcnt vmcnt(0) & expcnt(0) x(0)
// CHECK-NEXT:{{^}}s_waitcnt vmcnt(0) & expcnt(0) x(0)
// CHECK-NEXT:{{^}} ^
//==============================================================================
// invalid dst_sel value
v_mov_b32_sdwa v5, v1 dst_sel:WORD
// CHECK: error: invalid dst_sel value
// CHECK-NEXT:{{^}}v_mov_b32_sdwa v5, v1 dst_sel:WORD
// CHECK-NEXT:{{^}} ^
//==============================================================================
// invalid dst_unused value
v_mov_b32_sdwa v5, v1 dst_unused:UNUSED
// CHECK: error: invalid dst_unused value
// CHECK-NEXT:{{^}}v_mov_b32_sdwa v5, v1 dst_unused:UNUSED
// CHECK-NEXT:{{^}} ^
//==============================================================================
// invalid exp target