[llvm] [UpdateTestChecks] Add support for SPIRV in update_llc_test_checks.py (PR #66213)

Paulo Matos via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 04:58:23 PDT 2023


https://github.com/pmatos updated https://github.com/llvm/llvm-project/pull/66213

>From 308d1d448d78fc0a49223b60ebbf0fa79175b310 Mon Sep 17 00:00:00 2001
From: Paulo Matos <pmatos at igalia.com>
Date: Wed, 13 Sep 2023 15:40:56 +0200
Subject: [PATCH] [UpdateTestChecks] Add support for SPIRV in
 update_llc_test_checks.py

We have to change the location of the comment for function start
in SPIRV. We add a new command line flag --skip-check-label, because
there's no function label on SPIRV.

Previously https://reviews.llvm.org/D157858
---
 llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp     |  1 +
 .../SPIRV/extensions/SPV_INTEL_optnone.ll     |  8 +++++
 llvm/utils/UpdateTestChecks/asm.py            | 30 +++++++++++++++++++
 llvm/utils/UpdateTestChecks/common.py         | 12 ++++++--
 4 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index 27da0f21f1571d3..bc0cd64b0b4d154 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -118,6 +118,7 @@ void SPIRVAsmPrinter::emitFunctionHeader() {
     OutStreamer->getCommentOS()
         << "-- Begin function "
         << GlobalValue::dropLLVMManglingEscape(F.getName()) << '\n';
+    OutStreamer->addBlankLine();
   }
 
   auto Section = getObjFileLowering().SectionForGlobal(&F, TM);
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_optnone.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_optnone.ll
index 99d22a4a2ee639a..370c2e9e9d05118 100644
--- a/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_optnone.ll
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_optnone.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --skip-check-label --version 3
 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown --spirv-extensions=SPV_INTEL_optnone %s -o - | FileCheck %s --check-prefix=CHECK-EXTENSION
 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-NO-EXTENSION
 
@@ -12,6 +13,13 @@
 
 ; Function Attrs: nounwind optnone noinline
 define spir_func void @_Z3foov() #0 {
+; CHECK-EXTENSION:         %5 = OpLabel
+; CHECK-EXTENSION-NEXT:    OpReturn
+; CHECK-EXTENSION-NEXT:    OpFunctionEnd
+;
+; CHECK-NO-EXTENSION:         %5 = OpLabel
+; CHECK-NO-EXTENSION-NEXT:    OpReturn
+; CHECK-NO-EXTENSION-NEXT:    OpFunctionEnd
 entry:
   ret void
 }
diff --git a/llvm/utils/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index 33579065132179c..ea823d766469aeb 100644
--- a/llvm/utils/UpdateTestChecks/asm.py
+++ b/llvm/utils/UpdateTestChecks/asm.py
@@ -15,6 +15,11 @@ class string:
 # RegEx: this is where the magic happens.
 
 ##### Assembly parser
+#
+# The set of per-arch regular expressions define several groups.
+# The required groups are "func" (function name) and "body" (body of the function).
+# Although some backends require some additional groups like: "directives"
+# and "func_name_separator"
 
 ASM_FUNCTION_X86_RE = re.compile(
     r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?'
@@ -197,6 +202,18 @@ class string:
     flags=(re.M | re.S),
 )
 
+# We parse the function name from the comments issued by the backend:
+# ; -- Begin function <name>
+# and then the final comment
+# ; -- End function
+# If these change in the future, we need to change the regex.
+ASM_FUNCTION_SPIRV_RE = re.compile(
+    r'[ \t]+; \-\- Begin function (?P<func>[^\n]+)\n'
+    r"(?P<body>.*?)\n"
+    r"[ \t]+; \-\- End function",
+    flags=(re.M | re.S),
+)
+
 ASM_FUNCTION_VE_RE = re.compile(
     r"^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n"
     r"(?:\s*\.?L(?P=func)\$local:\n)?"  # optional .L<func>$local: due to -fno-semantic-interposition
@@ -433,6 +450,17 @@ def scrub_asm_sparc(asm, args):
     return asm
 
 
+def scrub_asm_spirv(asm, args):
+    # Scrub runs of whitespace out of the assembly, but leave the leading
+    # whitespace in place.
+    asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
+    # Expand the tabs used for indentation.
+    asm = string.expandtabs(asm, 2)
+    # Strip trailing whitespace.
+    asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
+    return asm
+
+
 def scrub_asm_systemz(asm, args):
     # Scrub runs of whitespace out of the assembly, but leave the leading
     # whitespace in place.
@@ -547,6 +575,8 @@ def get_run_handler(triple):
         "riscv64": (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE),
         "lanai": (scrub_asm_lanai, ASM_FUNCTION_LANAI_RE),
         "sparc": (scrub_asm_sparc, ASM_FUNCTION_SPARC_RE),
+        "spirv32": (scrub_asm_spirv, ASM_FUNCTION_SPIRV_RE),
+        "spirv64": (scrub_asm_spirv, ASM_FUNCTION_SPIRV_RE),
         "s390x": (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE),
         "wasm32": (scrub_asm_wasm, ASM_FUNCTION_WASM_RE),
         "wasm64": (scrub_asm_wasm, ASM_FUNCTION_WASM_RE),
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 22c05322d9c7dbc..4f7b3bb6fb85e90 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -196,6 +196,13 @@ def __call__(self, parser, namespace, values, option_string=None):
         default=[],
         help="List of regular expressions such that, for matching global value declarations, literal integer values should be encoded in hex in the associated FileCheck directives",
     )
+    parser.add_argument(
+        "--skip-check-label",
+        action="store_true",
+        dest="skip_check_label",
+        default=False,
+        help="Skip CHECK-LABEL line generation per function",
+    )
     # FIXME: in 3.9, we can use argparse.BooleanOptionalAction. At that point,
     # we need to rename the flag to just -generate-body-for-unused-prefixes.
     parser.add_argument(
@@ -212,10 +219,11 @@ def __call__(self, parser, namespace, values, option_string=None):
     )
     args = parser.parse_args()
     # TODO: This should not be handled differently from the other options
-    global _verbose, _global_value_regex, _global_hex_value_regex
+    global _verbose, _global_value_regex, _global_hex_value_regex, _skip_check_label
     _verbose = args.verbose
     _global_value_regex = args.global_value_regex
     _global_hex_value_regex = args.global_hex_value_regex
+    _skip_check_label = args.skip_check_label
     return args
 
 
@@ -1306,7 +1314,7 @@ def add_checks(
                 output_lines.append(
                     "%s %s-SAME: %s" % (comment_marker, checkprefix, args_and_sig)
                 )
-            else:
+            elif not _skip_check_label:
                 output_lines.append(
                     check_label_format
                     % (



More information about the llvm-commits mailing list