[llvm-branch-commits] [llvm] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jun 4 08:30:26 PDT 2024


https://github.com/koachan updated https://github.com/llvm/llvm-project/pull/94249

>From 2debba6d10e3025ae5b312ef8ef8e1f68bc2b794 Mon Sep 17 00:00:00 2001
From: Koakuma <koachan at protonmail.com>
Date: Tue, 4 Jun 2024 22:30:09 +0700
Subject: [PATCH] Update tests and apply suggestions

Created using spr 1.3.4
---
 .../Target/Sparc/AsmParser/SparcAsmParser.cpp | 28 ++++--
 llvm/test/MC/Disassembler/Sparc/sparc-v9.txt  | 58 +++++++++++-
 llvm/test/MC/Sparc/sparcv9-instructions.s     | 90 +++++++++++++++++++
 3 files changed, 165 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index a0dec24e3200a..f0a3a4e88b30c 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -1120,23 +1120,33 @@ ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector &Operands) {
   SMLoc E = Parser.getTok().getEndLoc();
   int64_t PrefetchVal = 0;
 
-  if (getLexer().getKind() == AsmToken::Hash) {
+  switch (getLexer().getKind()) {
+  case AsmToken::LParen:
+  case AsmToken::Integer:
+  case AsmToken::Identifier:
+  case AsmToken::Plus:
+  case AsmToken::Minus:
+  case AsmToken::Tilde:
+    if (getParser().parseAbsoluteExpression(PrefetchVal) ||
+        !isUInt<5>(PrefetchVal))
+      return Error(S, "invalid prefetch number, must be between 0 and 31");
+    break;
+  case AsmToken::Hash: {
     SMLoc TagStart = getLexer().peekTok(false).getLoc();
     Parser.Lex(); // Eat the '#'.
-    auto PrefetchName = Parser.getTok().getString();
-    auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
+    const StringRef PrefetchName = Parser.getTok().getString();
+    const SparcPrefetchTag::PrefetchTag *PrefetchTag =
+        SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
     Parser.Lex(); // Eat the identifier token.
 
     if (!PrefetchTag)
       return Error(TagStart, "unknown prefetch tag");
 
     PrefetchVal = PrefetchTag->Encoding;
-  } else if (!getParser().parseAbsoluteExpression(PrefetchVal)) {
-    if (!isUInt<5>(PrefetchVal))
-      return Error(S, "invalid prefetch number, must be between 0 and 31");
-  } else {
-    return Error(S, "malformed prefetch tag, must be a constant integer "
-                    "expression, or a named tag");
+    break;
+  }
+  default:
+    return ParseStatus::NoMatch;
   }
 
   Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S, E));
diff --git a/llvm/test/MC/Disassembler/Sparc/sparc-v9.txt b/llvm/test/MC/Disassembler/Sparc/sparc-v9.txt
index 49b6e339435f1..d561216fec6f2 100644
--- a/llvm/test/MC/Disassembler/Sparc/sparc-v9.txt
+++ b/llvm/test/MC/Disassembler/Sparc/sparc-v9.txt
@@ -132,11 +132,65 @@
 # CHECK: membar #LoadLoad | #StoreLoad | #LoadStore | #StoreStore | #Lookaside | #MemIssue | #Sync
 0x81 0x43 0xe0 0x7f
 
+# CHECK: prefetch  [%i1+3968], #n_reads
+0xc1 0x6e 0x6f 0x80
+
 # CHECK: prefetch  [%i1+3968], #one_read
-0xc3,0x6e,0x6f,0x80
+0xc3 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #n_writes
+0xc5 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #one_write
+0xc7 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #page
+0xc9 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #unified
+0xe3 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #n_reads_strong
+0xe9 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #one_read_strong
+0xeb 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #n_writes_strong
+0xed 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+3968], #one_write_strong
+0xef 0x6e 0x6f 0x80
+
+# CHECK: prefetch  [%i1+%i2], #n_reads
+0xc1 0x6e 0x40 0x1a
 
 # CHECK: prefetch  [%i1+%i2], #one_read
-0xc3,0x6e,0x40,0x1a
+0xc3 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #n_writes
+0xc5 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #one_write
+0xc7 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #page
+0xc9 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #unified
+0xe3 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #n_reads_strong
+0xe9 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #one_read_strong
+0xeb 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #n_writes_strong
+0xed 0x6e 0x40 0x1a
+
+# CHECK: prefetch  [%i1+%i2], #one_write_strong
+0xef 0x6e 0x40 0x1a
 
 # CHECK: done
 0x81,0xf0,0x00,0x00
diff --git a/llvm/test/MC/Sparc/sparcv9-instructions.s b/llvm/test/MC/Sparc/sparcv9-instructions.s
index f0348eb70f1c5..80f67ac30bc82 100644
--- a/llvm/test/MC/Sparc/sparcv9-instructions.s
+++ b/llvm/test/MC/Sparc/sparcv9-instructions.s
@@ -542,21 +542,111 @@
         ! V9: prefetch  [%i1+3968], #one_read  ! encoding: [0xc3,0x6e,0x6f,0x80]
         prefetch  [ %i1 + 0xf80 ], 1
 
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_reads
+        ! V9: prefetch  [%i1+3968], #n_reads  ! encoding: [0xc1,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #n_reads
+
         ! V8:      error: unexpected token
         ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_read
         ! V9: prefetch  [%i1+3968], #one_read  ! encoding: [0xc3,0x6e,0x6f,0x80]
         prefetch  [ %i1 + 0xf80 ], #one_read
 
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_writes
+        ! V9: prefetch  [%i1+3968], #n_writes  ! encoding: [0xc5,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #n_writes
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_write
+        ! V9: prefetch  [%i1+3968], #one_write  ! encoding: [0xc7,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #one_write
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #page
+        ! V9: prefetch  [%i1+3968], #page  ! encoding: [0xc9,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #page
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #unified
+        ! V9: prefetch  [%i1+3968], #unified  ! encoding: [0xe3,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #unified
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_reads_strong
+        ! V9: prefetch  [%i1+3968], #n_reads_strong  ! encoding: [0xe9,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #n_reads_strong
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_read_strong
+        ! V9: prefetch  [%i1+3968], #one_read_strong  ! encoding: [0xeb,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #one_read_strong
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_writes_strong
+        ! V9: prefetch  [%i1+3968], #n_writes_strong  ! encoding: [0xed,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #n_writes_strong
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_write_strong
+        ! V9: prefetch  [%i1+3968], #one_write_strong  ! encoding: [0xef,0x6e,0x6f,0x80]
+        prefetch  [ %i1 + 0xf80 ], #one_write_strong
+
         ! V8:      error: invalid operand for instruction
         ! V8-NEXT: prefetch  [ %i1 + %i2 ], 1
         ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
         prefetch  [ %i1 + %i2 ], 1
 
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #n_reads
+        ! V9: prefetch  [%i1+%i2], #n_reads  ! encoding: [0xc1,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #n_reads
+
         ! V8:      error: unexpected token
         ! V8-NEXT: prefetch  [ %i1 + %i2 ], #one_read
         ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
         prefetch  [ %i1 + %i2 ], #one_read
 
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #n_writes
+        ! V9: prefetch  [%i1+%i2], #n_writes  ! encoding: [0xc5,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #n_writes
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #one_write
+        ! V9: prefetch  [%i1+%i2], #one_write  ! encoding: [0xc7,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #one_write
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #page
+        ! V9: prefetch  [%i1+%i2], #page  ! encoding: [0xc9,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #page
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #unified
+        ! V9: prefetch  [%i1+%i2], #unified  ! encoding: [0xe3,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #unified
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #n_reads_strong
+        ! V9: prefetch  [%i1+%i2], #n_reads_strong  ! encoding: [0xe9,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #n_reads_strong
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #one_read_strong
+        ! V9: prefetch  [%i1+%i2], #one_read_strong  ! encoding: [0xeb,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #one_read_strong
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #n_writes_strong
+        ! V9: prefetch  [%i1+%i2], #n_writes_strong  ! encoding: [0xed,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #n_writes_strong
+
+        ! V8:      error: unexpected token
+        ! V8-NEXT: prefetch  [ %i1 + %i2 ], #one_write_strong
+        ! V9: prefetch  [%i1+%i2], #one_write_strong  ! encoding: [0xef,0x6e,0x40,0x1a]
+        prefetch  [ %i1 + %i2 ], #one_write_strong
+
         ! V8:      error: instruction requires a CPU feature not currently enabled
         ! V8-NEXT: done
         ! V9: done      ! encoding: [0x81,0xf0,0x00,0x00]



More information about the llvm-branch-commits mailing list