[llvm] update_llc_test_checks: better support for non-llc tools (PR #93135)

Nicolai Hähnle via llvm-commits llvm-commits at lists.llvm.org
Mon May 27 08:34:38 PDT 2024


https://github.com/nhaehnle updated https://github.com/llvm/llvm-project/pull/93135

>From 1ff8c8cfc2bbf6b5689db52bca6ce07137544d46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= <nicolai.haehnle at amd.com>
Date: Wed, 22 May 2024 20:37:14 +0200
Subject: [PATCH 1/4] update_llc_test_checks: better support for non-llc tools

A full downstream fork can already hack up update_llc_test_checks.py to
support custom tools that output assembly.

A downstream frontend which is mean to build against upstream
llvm-project cannot do this, and so providing additional arguments to
support a non-standard tool is useful.

This also makes a minor adjustment to the regular expression for
matching AMDGPU functions when fewer comments are enabled, which happens
to be the case for our out-of-tree shader compiler (which motivated this
change).

Change-Id: I99045ca4643e7f4711eab9218203bb6f5c54e1fb
---
 .../Inputs/amdgpu_function_alt.ll             |  6 ++++
 .../Inputs/amdgpu_function_alt.ll.expected    | 11 +++++++
 .../Inputs/amdgpu_function_alt.s              | 32 +++++++++++++++++++
 .../amdgpu_function_alt.test                  | 22 +++++++++++++
 llvm/utils/UpdateTestChecks/asm.py            |  3 +-
 llvm/utils/update_llc_test_checks.py          | 15 +++++++--
 6 files changed, 86 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.s
 create mode 100644 llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test

diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll
new file mode 100644
index 0000000000000..36f1055924624
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll
@@ -0,0 +1,6 @@
+; RUN: cat %S/amdgpu_function_alt.s | FileCheck --check-prefixes=CHECK %s
+
+define float @sample(float %x) {
+  %y = fmul float %x, %x
+  ret float %y
+}
diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
new file mode 100644
index 0000000000000..3982111fab311
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --tool cat --march amdgcn --version 4
+; RUN: cat %S/amdgpu_function_alt.s | FileCheck --check-prefixes=CHECK %s
+
+define float @sample(float %x) {
+; CHECK-LABEL: sample:
+; CHECK:         s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; CHECK-NEXT:    v_mul_f32_e32 v0, v0, v0
+; CHECK-NEXT:    s_setpc_b64 s[30:31]
+  %y = fmul float %x, %x
+  ret float %y
+}
diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.s b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.s
new file mode 100644
index 0000000000000..d61e7cdd954ce
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.s
@@ -0,0 +1,32 @@
+	.text
+	.amdgcn_target "amdgcn--amdpal--gfx1030"
+	.globl	sample
+	.p2align	2
+	.type	sample, at function
+sample:
+	s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+	v_mul_f32_e32 v0, v0, v0
+	s_setpc_b64 s[30:31]
+.Lfunc_end0:
+	.size	sample, .Lfunc_end0-sample
+
+	.p2alignl 6, 3214868480
+	.fill 48, 4, 3214868480
+	.section	".note.GNU-stack","", at progbits
+	.amd_amdgpu_isa "amdgcn--amdpal--gfx1030"
+	.amdgpu_pal_metadata
+---
+amdpal.pipelines:
+  - .api:            !str ''
+    .shader_functions:
+      sample:
+        .backend_stack_size: 0
+        .lds_size:       0
+        .sgpr_count:     0x20
+        .stack_frame_size_in_bytes: 0
+        .vgpr_count:     0x1
+amdpal.version:
+  - 0x3
+  - 0
+...
+	.end_amdgpu_pal_metadata
diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test
new file mode 100644
index 0000000000000..266ec42685899
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test
@@ -0,0 +1,22 @@
+## Checks two things:
+# - matching functions in AMDGPU assembly output without certain comments in the assembly
+# - using the --tool and --march arguments
+
+# Using `cat` as a tool requires some unusual setup (compared to the other test
+# of UpdateTestChecks tools), because update_llc_test_checks only reliably
+# substitutes %S (source directory) when evaluating RUN lines in the .ll file.
+# The .ll file used during the test is a temporary copy, so we also need to
+# provide a temporary copy of the cat'd .s file to avoid relying on
+# implementation details of how llvm-lit chooses %t.
+
+# RUN: rm -rf %t && mkdir %t
+# RUN: cp -f %S/Inputs/amdgpu_function_alt.s %t/
+# RUN: cp -f %S/Inputs/amdgpu_function_alt.ll %t/
+
+# RUN: %update_llc_test_checks --llc-binary "" --tool cat --march=amdgcn --version 4 %t/amdgpu_function_alt.ll
+# RUN: diff -u %S/Inputs/amdgpu_function_alt.ll.expected %t/amdgpu_function_alt.ll
+
+# Check that re-running remembers the arguments and doesn't change anything
+
+# RUN: %update_llc_test_checks --llc-binary "" %t/amdgpu_function_alt.ll
+# RUN: diff -u %S/Inputs/amdgpu_function_alt.ll.expected %t/amdgpu_function_alt.ll
diff --git a/llvm/utils/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index f0c456a1648df..bcdc22f2a27fc 100644
--- a/llvm/utils/UpdateTestChecks/asm.py
+++ b/llvm/utils/UpdateTestChecks/asm.py
@@ -51,7 +51,8 @@ class string:
 )
 
 ASM_FUNCTION_AMDGPU_RE = re.compile(
-    r'^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?'
+    r'\.type\s+_?(?P<func>[^,\n]+), at function\n'
+    r'^_?(?P=func):(?:[ \t]*;+[ \t]*@"?(?P=func)"?)?\n'
     r"(?P<body>.*?)\n"  # (body of the function)
     # This list is incomplete
     r"^\s*(\.Lfunc_end[0-9]+:\n|\.section)",
diff --git a/llvm/utils/update_llc_test_checks.py b/llvm/utils/update_llc_test_checks.py
index 1ed0132781e2b..2f433df58bdf9 100755
--- a/llvm/utils/update_llc_test_checks.py
+++ b/llvm/utils/update_llc_test_checks.py
@@ -54,6 +54,16 @@ def main():
         default=False,
         help="Reduce scrubbing shuffles with memory operands",
     )
+    parser.add_argument(
+        "--tool",
+        default=None,
+        help="Treat the given tool name as an llc-like tool for which check lines should be generated",
+    )
+    parser.add_argument(
+        "--march",
+        default=None,
+        help="Set a default -march for when neither triple nor arch are found in a RUN line",
+    )
     parser.add_argument("tests", nargs="+")
     initial_args = common.parse_commandline_args(parser)
 
@@ -89,7 +99,7 @@ def main():
             if m:
                 triple_in_cmd = m.groups()[0]
 
-            march_in_cmd = None
+            march_in_cmd = ti.args.march
             m = common.MARCH_ARG_RE.search(llc_cmd)
             if m:
                 march_in_cmd = m.groups()[0]
@@ -101,7 +111,8 @@ def main():
                 from UpdateTestChecks import asm as output_type
 
             common.verify_filecheck_prefixes(filecheck_cmd)
-            if llc_tool not in LLC_LIKE_TOOLS:
+            if llc_tool not in LLC_LIKE_TOOLS and \
+               (not ti.args.tool or llc_tool != ti.args.tool):
                 common.warn("Skipping non-llc RUN line: " + l)
                 continue
 

>From a554f37107e3120027d4a817fa21814d2a872b2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= <nicolai.haehnle at amd.com>
Date: Thu, 23 May 2024 16:02:59 +0200
Subject: [PATCH 2/4] Fix Python formatting

Change-Id: I3025a6559cd4c32dbde35f171b945a7235a740fd
---
 llvm/utils/UpdateTestChecks/asm.py   | 2 +-
 llvm/utils/update_llc_test_checks.py | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index bcdc22f2a27fc..a8f8ab82a826d 100644
--- a/llvm/utils/UpdateTestChecks/asm.py
+++ b/llvm/utils/UpdateTestChecks/asm.py
@@ -51,7 +51,7 @@ class string:
 )
 
 ASM_FUNCTION_AMDGPU_RE = re.compile(
-    r'\.type\s+_?(?P<func>[^,\n]+), at function\n'
+    r"\.type\s+_?(?P<func>[^,\n]+), at function\n"
     r'^_?(?P=func):(?:[ \t]*;+[ \t]*@"?(?P=func)"?)?\n'
     r"(?P<body>.*?)\n"  # (body of the function)
     # This list is incomplete
diff --git a/llvm/utils/update_llc_test_checks.py b/llvm/utils/update_llc_test_checks.py
index 2f433df58bdf9..5569b2bc7ccb6 100755
--- a/llvm/utils/update_llc_test_checks.py
+++ b/llvm/utils/update_llc_test_checks.py
@@ -111,8 +111,9 @@ def main():
                 from UpdateTestChecks import asm as output_type
 
             common.verify_filecheck_prefixes(filecheck_cmd)
-            if llc_tool not in LLC_LIKE_TOOLS and \
-               (not ti.args.tool or llc_tool != ti.args.tool):
+            if llc_tool not in LLC_LIKE_TOOLS and (
+                not ti.args.tool or llc_tool != ti.args.tool
+            ):
                 common.warn("Skipping non-llc RUN line: " + l)
                 continue
 

>From 2d58cc7c7ec3c0dce1d7e8d1d122be02569b40d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= <nicolai.haehnle at amd.com>
Date: Mon, 27 May 2024 17:21:39 +0200
Subject: [PATCH 3/4] Address review comments

---
 .../Inputs/amdgpu_function_alt.ll.expected       |  2 +-
 .../amdgpu_function_alt.test                     | 16 ++++++++--------
 llvm/utils/update_llc_test_checks.py             | 14 ++++++++------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
index 3982111fab311..ef5378a720e51 100644
--- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --tool cat --march amdgcn --version 4
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --tool cat --default-march amdgcn --version 4
 ; RUN: cat %S/amdgpu_function_alt.s | FileCheck --check-prefixes=CHECK %s
 
 define float @sample(float %x) {
diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test
index 266ec42685899..5142b01945eba 100644
--- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test
+++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test
@@ -1,6 +1,6 @@
 ## Checks two things:
 # - matching functions in AMDGPU assembly output without certain comments in the assembly
-# - using the --tool and --march arguments
+# - using the --tool and --default-march arguments
 
 # Using `cat` as a tool requires some unusual setup (compared to the other test
 # of UpdateTestChecks tools), because update_llc_test_checks only reliably
@@ -9,14 +9,14 @@
 # provide a temporary copy of the cat'd .s file to avoid relying on
 # implementation details of how llvm-lit chooses %t.
 
-# RUN: rm -rf %t && mkdir %t
-# RUN: cp -f %S/Inputs/amdgpu_function_alt.s %t/
-# RUN: cp -f %S/Inputs/amdgpu_function_alt.ll %t/
+# RUN: rm -rf %t.dir && mkdir %t.dir
+# RUN: cp -f %S/Inputs/amdgpu_function_alt.s %t.dir/
+# RUN: cp -f %S/Inputs/amdgpu_function_alt.ll %t.dir/
 
-# RUN: %update_llc_test_checks --llc-binary "" --tool cat --march=amdgcn --version 4 %t/amdgpu_function_alt.ll
-# RUN: diff -u %S/Inputs/amdgpu_function_alt.ll.expected %t/amdgpu_function_alt.ll
+# RUN: %update_llc_test_checks --llc-binary "" --tool cat --default-march=amdgcn --version 4 %t.dir/amdgpu_function_alt.ll
+# RUN: diff -u %S/Inputs/amdgpu_function_alt.ll.expected %t.dir/amdgpu_function_alt.ll
 
 # Check that re-running remembers the arguments and doesn't change anything
 
-# RUN: %update_llc_test_checks --llc-binary "" %t/amdgpu_function_alt.ll
-# RUN: diff -u %S/Inputs/amdgpu_function_alt.ll.expected %t/amdgpu_function_alt.ll
+# RUN: %update_llc_test_checks --llc-binary "" %t.dir/amdgpu_function_alt.ll
+# RUN: diff -u %S/Inputs/amdgpu_function_alt.ll.expected %t.dir/amdgpu_function_alt.ll
diff --git a/llvm/utils/update_llc_test_checks.py b/llvm/utils/update_llc_test_checks.py
index 5569b2bc7ccb6..bda2d5fd54979 100755
--- a/llvm/utils/update_llc_test_checks.py
+++ b/llvm/utils/update_llc_test_checks.py
@@ -16,7 +16,7 @@
 
 # llc is the only llc-like in the LLVM tree but downstream forks can add
 # additional ones here if they have them.
-LLC_LIKE_TOOLS = ("llc",)
+LLC_LIKE_TOOLS = ["llc",]
 
 
 def main():
@@ -60,7 +60,7 @@ def main():
         help="Treat the given tool name as an llc-like tool for which check lines should be generated",
     )
     parser.add_argument(
-        "--march",
+        "--default-march",
         default=None,
         help="Set a default -march for when neither triple nor arch are found in a RUN line",
     )
@@ -99,7 +99,7 @@ def main():
             if m:
                 triple_in_cmd = m.groups()[0]
 
-            march_in_cmd = ti.args.march
+            march_in_cmd = ti.args.default_march
             m = common.MARCH_ARG_RE.search(llc_cmd)
             if m:
                 march_in_cmd = m.groups()[0]
@@ -111,9 +111,11 @@ def main():
                 from UpdateTestChecks import asm as output_type
 
             common.verify_filecheck_prefixes(filecheck_cmd)
-            if llc_tool not in LLC_LIKE_TOOLS and (
-                not ti.args.tool or llc_tool != ti.args.tool
-            ):
+
+            llc_like_tools = LLC_LIKE_TOOLS[:]
+            if ti.args.tool:
+                llc_like_tools.append(ti.args.tool)
+            if llc_tool not in llc_like_tools:
                 common.warn("Skipping non-llc RUN line: " + l)
                 continue
 

>From b32f871e8a1c5e7b8418d4977c2a164c6abb6a6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= <nicolai.haehnle at amd.com>
Date: Mon, 27 May 2024 17:34:25 +0200
Subject: [PATCH 4/4] More formatting

---
 llvm/utils/update_llc_test_checks.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/utils/update_llc_test_checks.py b/llvm/utils/update_llc_test_checks.py
index bda2d5fd54979..962f694d2c184 100755
--- a/llvm/utils/update_llc_test_checks.py
+++ b/llvm/utils/update_llc_test_checks.py
@@ -16,7 +16,9 @@
 
 # llc is the only llc-like in the LLVM tree but downstream forks can add
 # additional ones here if they have them.
-LLC_LIKE_TOOLS = ["llc",]
+LLC_LIKE_TOOLS = [
+    "llc",
+]
 
 
 def main():



More information about the llvm-commits mailing list