[llvm] 586df38 - [AMDGPU][MC] Corrected parsing of optional modifiers
Dmitry Preobrazhensky via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 2 03:52:51 PST 2021
Author: Dmitry Preobrazhensky
Date: 2021-02-02T14:52:29+03:00
New Revision: 586df38478b2bf2a85128e72a5300da9b1b09a5e
URL: https://github.com/llvm/llvm-project/commit/586df38478b2bf2a85128e72a5300da9b1b09a5e
DIFF: https://github.com/llvm/llvm-project/commit/586df38478b2bf2a85128e72a5300da9b1b09a5e.diff
LOG: [AMDGPU][MC] Corrected parsing of optional modifiers
Fixed bugs in parsing of "no*" modifiers and improved errors handling.
See https://bugs.llvm.org/show_bug.cgi?id=41282.
Differential Revision: https://reviews.llvm.org/D95675
Added:
Modified:
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/test/MC/AMDGPU/flat-global.s
llvm/test/MC/AMDGPU/flat-scratch-instructions.s
llvm/test/MC/AMDGPU/gfx8_err_pos.s
llvm/test/MC/AMDGPU/gfx9_err_pos.s
llvm/test/MC/AMDGPU/vop3-modifiers-err.s
llvm/test/MC/AMDGPU/vop3-modifiers.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 3f3f0863dced..3d9e322a57f5 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1294,7 +1294,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
bool (*ConvertResult)(int64_t&) = nullptr);
OperandMatchResultTy
- parseNamedBit(const char *Name, OperandVector &Operands,
+ parseNamedBit(StringRef Name, OperandVector &Operands,
AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone);
OperandMatchResultTy parseStringWithPrefix(StringRef Prefix,
StringRef &Value,
@@ -1403,6 +1403,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
bool isId(const AsmToken &Token, const StringRef Id) const;
bool isToken(const AsmToken::TokenKind Kind) const;
bool trySkipId(const StringRef Id);
+ bool trySkipId(const StringRef Pref, const StringRef Id);
bool trySkipId(const StringRef Id, const AsmToken::TokenKind Kind);
bool trySkipToken(const AsmToken::TokenKind Kind);
bool skipToken(const AsmToken::TokenKind Kind, const StringRef ErrMsg);
@@ -5043,39 +5044,31 @@ AMDGPUAsmParser::parseOperandArrayWithPrefix(const char *Prefix,
}
OperandMatchResultTy
-AMDGPUAsmParser::parseNamedBit(const char *Name, OperandVector &Operands,
+AMDGPUAsmParser::parseNamedBit(StringRef Name, OperandVector &Operands,
AMDGPUOperand::ImmTy ImmTy) {
- int64_t Bit = 0;
+ int64_t Bit;
SMLoc S = getLoc();
- // We are at the end of the statement, and this is a default argument, so
- // use a default value.
- if (!isToken(AsmToken::EndOfStatement)) {
- switch(getTokenKind()) {
- case AsmToken::Identifier: {
- StringRef Tok = getTokenStr();
- if (Tok == Name) {
- if (Tok == "r128" && !hasMIMG_R128())
- Error(S, "r128 modifier is not supported on this GPU");
- if (Tok == "a16" && !isGFX9() && !hasGFX10A16())
- Error(S, "a16 modifier is not supported on this GPU");
- Bit = 1;
- Parser.Lex();
- } else if (Tok.startswith("no") && Tok.endswith(Name)) {
- Bit = 0;
- Parser.Lex();
- } else {
- return MatchOperand_NoMatch;
- }
- break;
- }
- default:
- return MatchOperand_NoMatch;
- }
+ if (trySkipId(Name)) {
+ Bit = 1;
+ } else if (trySkipId("no", Name)) {
+ Bit = 0;
+ } else {
+ return MatchOperand_NoMatch;
}
- if (!isGFX10Plus() && ImmTy == AMDGPUOperand::ImmTyDLC)
+ if (Name == "r128" && !hasMIMG_R128()) {
+ Error(S, "r128 modifier is not supported on this GPU");
+ return MatchOperand_ParseFail;
+ }
+ if (Name == "a16" && !isGFX9() && !hasGFX10A16()) {
+ Error(S, "a16 modifier is not supported on this GPU");
+ return MatchOperand_ParseFail;
+ }
+ if (!isGFX10Plus() && ImmTy == AMDGPUOperand::ImmTyDLC) {
+ Error(S, "dlc modifier is not supported on this GPU");
return MatchOperand_ParseFail;
+ }
if (isGFX9() && ImmTy == AMDGPUOperand::ImmTyA16)
ImmTy = AMDGPUOperand::ImmTyR128A16;
@@ -5933,6 +5926,18 @@ AMDGPUAsmParser::trySkipId(const StringRef Id) {
return false;
}
+bool
+AMDGPUAsmParser::trySkipId(const StringRef Pref, const StringRef Id) {
+ if (isToken(AsmToken::Identifier)) {
+ StringRef Tok = getTokenStr();
+ if (Tok.startswith(Pref) && Tok.drop_front(Pref.size()) == Id) {
+ lex();
+ return true;
+ }
+ }
+ return false;
+}
+
bool
AMDGPUAsmParser::trySkipId(const StringRef Id, const AsmToken::TokenKind Kind) {
if (isId(Id) && peekToken().is(Kind)) {
diff --git a/llvm/test/MC/AMDGPU/flat-global.s b/llvm/test/MC/AMDGPU/flat-global.s
index 2afb283054e6..2dac9c4c1100 100644
--- a/llvm/test/MC/AMDGPU/flat-global.s
+++ b/llvm/test/MC/AMDGPU/flat-global.s
@@ -12,7 +12,7 @@ global_load_ubyte v1, v[3:4], off
global_load_ubyte v1, v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x20,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_sbyte v1, v[3:4], off
@@ -22,7 +22,7 @@ global_load_sbyte v1, v[3:4], off
global_load_sbyte v1, v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x24,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_ushort v1, v[3:4], off
@@ -32,7 +32,7 @@ global_load_ushort v1, v[3:4], off
global_load_ushort v1, v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x28,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_sshort v1, v[3:4], off
@@ -42,7 +42,7 @@ global_load_sshort v1, v[3:4], off
global_load_sshort v1, v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x2c,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_dword v1, v[3:4], off
@@ -52,7 +52,7 @@ global_load_dword v1, v[3:4], off
global_load_dword v1, v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x30,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_dwordx2 v[1:2], v[3:4], off
@@ -62,7 +62,7 @@ global_load_dwordx2 v[1:2], v[3:4], off
global_load_dwordx2 v[1:2], v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x34,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_dwordx3 v[1:3], v[3:4], off
@@ -72,7 +72,7 @@ global_load_dwordx3 v[1:3], v[3:4], off
global_load_dwordx3 v[1:3], v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x3c,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_dwordx4 v[1:4], v[3:4], off
@@ -82,7 +82,7 @@ global_load_dwordx4 v[1:4], v[3:4], off
global_load_dwordx4 v[1:4], v[3:4], off dlc
// GFX10: encoding: [0x00,0x90,0x38,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_load_dword v1, v[3:4], off offset:0
@@ -122,7 +122,7 @@ global_store_byte v[3:4], v1, off
global_store_byte v[3:4], v1, off dlc
// GFX10: encoding: [0x00,0x90,0x60,0xdc,0x03,0x01,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_store_short v[3:4], v1, off
@@ -132,7 +132,7 @@ global_store_short v[3:4], v1, off
global_store_short v[3:4], v1, off dlc
// GFX10: encoding: [0x00,0x90,0x68,0xdc,0x03,0x01,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_store_dword v[3:4], v1, off
@@ -142,7 +142,7 @@ global_store_dword v[3:4], v1, off
global_store_dword v[3:4], v1, off dlc
// GFX10: encoding: [0x00,0x90,0x70,0xdc,0x03,0x01,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_store_dwordx2 v[3:4], v[1:2], off
@@ -152,7 +152,7 @@ global_store_dwordx2 v[3:4], v[1:2], off
global_store_dwordx2 v[3:4], v[1:2], off dlc
// GFX10: encoding: [0x00,0x90,0x74,0xdc,0x03,0x01,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_store_dwordx3 v[3:4], v[1:3], off
@@ -162,7 +162,7 @@ global_store_dwordx3 v[3:4], v[1:3], off
global_store_dwordx3 v[3:4], v[1:3], off dlc
// GFX10: encoding: [0x00,0x90,0x7c,0xdc,0x03,0x01,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_store_dwordx4 v[3:4], v[1:4], off
@@ -172,7 +172,7 @@ global_store_dwordx4 v[3:4], v[1:4], off
global_store_dwordx4 v[3:4], v[1:4], off dlc
// GFX10: encoding: [0x00,0x90,0x78,0xdc,0x03,0x01,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
global_store_dword v[3:4], v1, off offset:12
diff --git a/llvm/test/MC/AMDGPU/flat-scratch-instructions.s b/llvm/test/MC/AMDGPU/flat-scratch-instructions.s
index ad35310df535..0f4fae7546b7 100644
--- a/llvm/test/MC/AMDGPU/flat-scratch-instructions.s
+++ b/llvm/test/MC/AMDGPU/flat-scratch-instructions.s
@@ -12,7 +12,7 @@ scratch_load_ubyte v1, v2, off
scratch_load_ubyte v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x20,0xdc,0x02,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_sbyte v1, v2, off
@@ -22,7 +22,7 @@ scratch_load_sbyte v1, v2, off
scratch_load_sbyte v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x24,0xdc,0x02,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_ushort v1, v2, off
@@ -32,7 +32,7 @@ scratch_load_ushort v1, v2, off
scratch_load_ushort v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x28,0xdc,0x02,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_sshort v1, v2, off
@@ -42,7 +42,7 @@ scratch_load_sshort v1, v2, off
scratch_load_sshort v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x2c,0xdc,0x02,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_dword v1, v2, off
@@ -52,7 +52,7 @@ scratch_load_dword v1, v2, off
scratch_load_dword v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x30,0xdc,0x02,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_dwordx2 v[1:2], v3, off
@@ -62,7 +62,7 @@ scratch_load_dwordx2 v[1:2], v3, off
scratch_load_dwordx2 v[1:2], v3, off dlc
// GFX10: encoding: [0x00,0x50,0x34,0xdc,0x03,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_dwordx3 v[1:3], v4, off
@@ -72,7 +72,7 @@ scratch_load_dwordx3 v[1:3], v4, off
scratch_load_dwordx3 v[1:3], v4, off dlc
// GFX10: encoding: [0x00,0x50,0x3c,0xdc,0x04,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_dwordx4 v[1:4], v5, off
@@ -82,7 +82,7 @@ scratch_load_dwordx4 v[1:4], v5, off
scratch_load_dwordx4 v[1:4], v5, off dlc
// GFX10: encoding: [0x00,0x50,0x38,0xdc,0x05,0x00,0x7d,0x01]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_load_dword v1, v2, off offset:0
@@ -142,7 +142,7 @@ scratch_store_byte v1, v2, off
scratch_store_byte v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x60,0xdc,0x01,0x02,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_store_short v1, v2, off
@@ -152,7 +152,7 @@ scratch_store_short v1, v2, off
scratch_store_short v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x68,0xdc,0x01,0x02,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_store_dword v1, v2, off
@@ -162,7 +162,7 @@ scratch_store_dword v1, v2, off
scratch_store_dword v1, v2, off dlc
// GFX10: encoding: [0x00,0x50,0x70,0xdc,0x01,0x02,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_store_dwordx2 v1, v[2:3], off
@@ -172,7 +172,7 @@ scratch_store_dwordx2 v1, v[2:3], off
scratch_store_dwordx2 v1, v[2:3], off dlc
// GFX10: encoding: [0x00,0x50,0x74,0xdc,0x01,0x02,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_store_dwordx3 v1, v[2:4], off
@@ -182,7 +182,7 @@ scratch_store_dwordx3 v1, v[2:4], off
scratch_store_dwordx3 v1, v[2:4], off dlc
// GFX10: encoding: [0x00,0x50,0x7c,0xdc,0x01,0x02,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_store_dwordx4 v1, v[2:5], off
@@ -192,7 +192,7 @@ scratch_store_dwordx4 v1, v[2:5], off
scratch_store_dwordx4 v1, v[2:5], off dlc
// GFX10: encoding: [0x00,0x50,0x78,0xdc,0x01,0x02,0x7d,0x00]
-// GFX9-ERR: error: failed parsing operand
+// GFX9-ERR: error: dlc modifier is not supported on this GPU
// VI-ERR: error: instruction not supported on this GPU
scratch_store_dword v1, v2, off offset:12
diff --git a/llvm/test/MC/AMDGPU/gfx8_err_pos.s b/llvm/test/MC/AMDGPU/gfx8_err_pos.s
index 66195cb6b336..382245f21d2a 100644
--- a/llvm/test/MC/AMDGPU/gfx8_err_pos.s
+++ b/llvm/test/MC/AMDGPU/gfx8_err_pos.s
@@ -8,6 +8,11 @@ image_gather4 v[5:8], v1, s[8:15], s[12:15] dmask:0x1 a16
// CHECK-NEXT:{{^}}image_gather4 v[5:8], v1, s[8:15], s[12:15] dmask:0x1 a16
// CHECK-NEXT:{{^}} ^
+image_gather4 v[5:8], v1, s[8:15], s[12:15] dmask:0x1 noa16
+// CHECK: error: a16 modifier is not supported on this GPU
+// CHECK-NEXT:{{^}}image_gather4 v[5:8], v1, s[8:15], s[12:15] dmask:0x1 noa16
+// CHECK-NEXT:{{^}} ^
+
//==============================================================================
// expected a 20-bit unsigned offset
diff --git a/llvm/test/MC/AMDGPU/gfx9_err_pos.s b/llvm/test/MC/AMDGPU/gfx9_err_pos.s
index 36611ecf002e..f6e696482ed9 100644
--- a/llvm/test/MC/AMDGPU/gfx9_err_pos.s
+++ b/llvm/test/MC/AMDGPU/gfx9_err_pos.s
@@ -16,6 +16,19 @@ v_div_scale_f64 v[24:25], vcc, -|v[22:23]|, v[22:23], v[20:21]
// CHECK-NEXT:{{^}}v_div_scale_f64 v[24:25], vcc, -|v[22:23]|, v[22:23], v[20:21]
// CHECK-NEXT:{{^}}^
+//==============================================================================
+// dlc modifier is not supported on this GPU
+
+scratch_load_ubyte v1, v2, off dlc
+// CHECK: error: dlc modifier is not supported on this GPU
+// CHECK-NEXT:{{^}}scratch_load_ubyte v1, v2, off dlc
+// CHECK-NEXT:{{^}} ^
+
+scratch_load_ubyte v1, v2, off nodlc
+// CHECK: error: dlc modifier is not supported on this GPU
+// CHECK-NEXT:{{^}}scratch_load_ubyte v1, v2, off nodlc
+// CHECK-NEXT:{{^}} ^
+
//==============================================================================
// duplicate VGPR index mode
@@ -173,6 +186,11 @@ image_atomic_add v10, v6, s[8:15] dmask:0x1 r128
// CHECK-NEXT:{{^}}image_atomic_add v10, v6, s[8:15] dmask:0x1 r128
// CHECK-NEXT:{{^}} ^
+image_atomic_add v10, v6, s[8:15] dmask:0x1 nor128
+// CHECK: error: r128 modifier is not supported on this GPU
+// CHECK-NEXT:{{^}}image_atomic_add v10, v6, s[8:15] dmask:0x1 nor128
+// CHECK-NEXT:{{^}} ^
+
//==============================================================================
// unified format is not supported on this GPU
diff --git a/llvm/test/MC/AMDGPU/vop3-modifiers-err.s b/llvm/test/MC/AMDGPU/vop3-modifiers-err.s
index 95811c789e84..4c4a8c79e1c2 100644
--- a/llvm/test/MC/AMDGPU/vop3-modifiers-err.s
+++ b/llvm/test/MC/AMDGPU/vop3-modifiers-err.s
@@ -13,3 +13,6 @@ v_ceil_f32 v0, --1
v_ceil_f16 v0, abs(neg(1))
// CHECK: error: failed parsing operand
+
+v_cvt_f16_u16_e64 v5, s1 noXXXclamp
+// CHECK: error: invalid operand for instruction
diff --git a/llvm/test/MC/AMDGPU/vop3-modifiers.s b/llvm/test/MC/AMDGPU/vop3-modifiers.s
index f18a38caac38..8c9767bda26d 100644
--- a/llvm/test/MC/AMDGPU/vop3-modifiers.s
+++ b/llvm/test/MC/AMDGPU/vop3-modifiers.s
@@ -386,3 +386,6 @@ v_cvt_f16_i16_e64 v5, s1 clamp
// NB: output modifiers are not supported for f16
v_cvt_f16_u16_e64 v5, s1 clamp
// CHECK: [0x05,0x80,0x79,0xd1,0x01,0x00,0x00,0x00]
+
+v_cvt_f16_u16_e64 v5, s1 noclamp
+// CHECK: [0x05,0x00,0x79,0xd1,0x01,0x00,0x00,0x00]
More information about the llvm-commits
mailing list