[llvm] d61f2cf - [AMDGPU] Simplify exp target parsing

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 6 08:10:48 PST 2020


Author: Jay Foad
Date: 2020-11-06T16:09:34Z
New Revision: d61f2cfb9fc3286e615d8473452981efa6bfcbd9

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

LOG: [AMDGPU] Simplify exp target parsing

Treat any identifier as a potential exp target and diagnose them all the
same way as "invalid exp target"s.

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

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
    llvm/test/MC/AMDGPU/exp-err.s
    llvm/test/MC/AMDGPU/exp-gfx10.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 8bcdd05a80c0..71392dd7a75f 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -5854,10 +5854,8 @@ OperandMatchResultTy AMDGPUAsmParser::parseExpTgtImpl(StringRef Str,
     if (Str.getAsInteger(10, Val))
       return MatchOperand_ParseFail;
 
-    if (Val > 7) {
-      Error(getLoc(), "invalid exp target");
+    if (Val > 7)
       return MatchOperand_ParseFail;
-    }
 
     return MatchOperand_Success;
   }
@@ -5867,10 +5865,8 @@ OperandMatchResultTy AMDGPUAsmParser::parseExpTgtImpl(StringRef Str,
     if (Str.getAsInteger(10, Val))
       return MatchOperand_ParseFail;
 
-    if (Val > 4 || (Val == 4 && !isGFX10())) {
-      Error(getLoc(), "invalid exp target");
+    if (Val > 4 || (Val == 4 && !isGFX10()))
       return MatchOperand_ParseFail;
-    }
 
     Val += 12;
     return MatchOperand_Success;
@@ -5886,38 +5882,30 @@ OperandMatchResultTy AMDGPUAsmParser::parseExpTgtImpl(StringRef Str,
     if (Str.getAsInteger(10, Val))
       return MatchOperand_ParseFail;
 
-    if (Val >= 32) {
-      Error(getLoc(), "invalid exp target");
+    if (Val >= 32)
       return MatchOperand_ParseFail;
-    }
 
     Val += 32;
     return MatchOperand_Success;
   }
 
-  if (Str.startswith("invalid_target_")) {
-    Str = Str.drop_front(15);
-    if (Str.getAsInteger(10, Val))
-      return MatchOperand_ParseFail;
-
-    Error(getLoc(), "invalid exp target");
-    return MatchOperand_ParseFail;
-  }
-
-  return MatchOperand_NoMatch;
+  return MatchOperand_ParseFail;
 }
 
 OperandMatchResultTy AMDGPUAsmParser::parseExpTgt(OperandVector &Operands) {
-  uint8_t Val;
-  StringRef Str = Parser.getTok().getString();
+  if (!isToken(AsmToken::Identifier))
+    return MatchOperand_NoMatch;
 
-  auto Res = parseExpTgtImpl(Str, Val);
-  if (Res != MatchOperand_Success)
+  SMLoc S = getLoc();
+
+  uint8_t Val;
+  auto Res = parseExpTgtImpl(getTokenStr(), Val);
+  if (Res != MatchOperand_Success) {
+    Error(S, "invalid exp target");
     return Res;
+  }
 
-  SMLoc S = Parser.getTok().getLoc();
   Parser.Lex();
-
   Operands.push_back(AMDGPUOperand::CreateImm(this, Val, S,
                                               AMDGPUOperand::ImmTyExpTgt));
   return MatchOperand_Success;

diff  --git a/llvm/test/MC/AMDGPU/exp-err.s b/llvm/test/MC/AMDGPU/exp-err.s
index b3494a11fa08..ee83bef0c50b 100644
--- a/llvm/test/MC/AMDGPU/exp-err.s
+++ b/llvm/test/MC/AMDGPU/exp-err.s
@@ -23,28 +23,37 @@ exp invalid_target_11 v3, v2, v1, v0 done
 // GCN: :5: error: invalid exp target
 
 exp mrt-1 v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp mrtX v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp pos-1 v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp posX v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp param-1 v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp paramX v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp invalid_target_-1 v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
 
 exp invalid_target_X v3, v2, v1, v0
-// GCN: :5: error: failed parsing operand
+// GCN: :5: error: invalid exp target
+
+exp 0 v3, v2, v1, v0
+// GCN: :5: error: invalid operand for instruction
+
+exp , v3, v2, v1, v0
+// GCN: :5: error: unknown token in expression
+
+exp
+// GCN: :1: error: too few operands for instruction
 
 exp mrt0 s0, v0, v0, v0
 // GCN: 10: error: invalid operand for instruction

diff  --git a/llvm/test/MC/AMDGPU/exp-gfx10.s b/llvm/test/MC/AMDGPU/exp-gfx10.s
index 2a02cef542ee..89cd6123ba30 100644
--- a/llvm/test/MC/AMDGPU/exp-gfx10.s
+++ b/llvm/test/MC/AMDGPU/exp-gfx10.s
@@ -1,18 +1,15 @@
-// RUN: not llvm-mc -arch=amdgcn -mcpu=verde %s 2>&1 | FileCheck -check-prefix=SI --implicit-check-not=error: %s
-// RUN: not llvm-mc -arch=amdgcn -mcpu=tonga %s 2>&1 | FileCheck -check-prefix=VI --implicit-check-not=error: %s
+// RUN: not llvm-mc -arch=amdgcn -mcpu=verde %s 2>&1 | FileCheck -check-prefix=SIVI --implicit-check-not=error: %s
+// RUN: not llvm-mc -arch=amdgcn -mcpu=tonga %s 2>&1 | FileCheck -check-prefix=SIVI --implicit-check-not=error: %s
 // RUN: llvm-mc -arch=amdgcn -mcpu=gfx1010 -show-encoding %s | FileCheck -check-prefix=GFX10 %s
 
 exp prim v1, off, off, off
-// SI: :5: error: invalid operand for instruction
-// VI: :5: error: invalid operand for instruction
+// SIVI: :5: error: invalid exp target
 // GFX10: exp prim v1, off, off, off ; encoding: [0x41,0x01,0x00,0xf8,0x01,0x00,0x00,0x00]
 
 exp prim v2, v3, off, off
-// SI: :5: error: invalid operand for instruction
-// VI: :5: error: invalid operand for instruction
+// SIVI: :5: error: invalid exp target
 // GFX10: exp prim v2, v3, off, off ; encoding: [0x43,0x01,0x00,0xf8,0x02,0x03,0x00,0x00]
 
 exp pos4 v4, v3, v2, v1
-// SI: error: invalid exp target
-// VI: error: invalid exp target
+// SIVI: error: invalid exp target
 // GFX10: exp pos4 v4, v3, v2, v1 ; encoding: [0x0f,0x01,0x00,0xf8,0x04,0x03,0x02,0x01]


        


More information about the llvm-commits mailing list