[llvm-branch-commits] [llvm] 558b3bb - [AMDGPU][MC] Improved errors handling for SDWA operands

Dmitry Preobrazhensky via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jan 25 08:08:26 PST 2021


Author: Dmitry Preobrazhensky
Date: 2021-01-25T19:02:53+03:00
New Revision: 558b3bbb5b67387c5a29c1eb6548be81c1588adc

URL: https://github.com/llvm/llvm-project/commit/558b3bbb5b67387c5a29c1eb6548be81c1588adc
DIFF: https://github.com/llvm/llvm-project/commit/558b3bbb5b67387c5a29c1eb6548be81c1588adc.diff

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

Reviewers: rampitec

Differential Revision: https://reviews.llvm.org/D95212

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
    llvm/test/MC/AMDGPU/gfx10_err_pos.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 5146271befff..035278135cef 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1297,7 +1297,8 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
   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;
   }
 

diff  --git a/llvm/test/MC/AMDGPU/gfx10_err_pos.s b/llvm/test/MC/AMDGPU/gfx10_err_pos.s
index cb4f9ae91153..b0cf97921daa 100644
--- a/llvm/test/MC/AMDGPU/gfx10_err_pos.s
+++ b/llvm/test/MC/AMDGPU/gfx10_err_pos.s
@@ -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
 


        


More information about the llvm-branch-commits mailing list