[llvm] 34388f9 - update_llc_test_checks: better support for non-llc tools (#93135)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 27 10:17:08 PDT 2024
Author: Nicolai Hähnle
Date: 2024-05-27T19:17:04+02:00
New Revision: 34388f986af1289492d043b56b6cba17468d1f8d
URL: https://github.com/llvm/llvm-project/commit/34388f986af1289492d043b56b6cba17468d1f8d
DIFF: https://github.com/llvm/llvm-project/commit/34388f986af1289492d043b56b6cba17468d1f8d.diff
LOG: update_llc_test_checks: better support for non-llc tools (#93135)
A full downstream fork can already hack up update_llc_test_checks.py to
support custom tools that output assembly.
An out-of-tree frontend which is meant 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).
Added:
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.ll.expected
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_function_alt.s
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu_function_alt.test
Modified:
llvm/utils/UpdateTestChecks/asm.py
llvm/utils/update_llc_test_checks.py
Removed:
################################################################################
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..ef5378a720e51
--- /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 --default-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..5142b01945eba
--- /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 --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
+# 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.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 --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.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/UpdateTestChecks/asm.py b/llvm/utils/UpdateTestChecks/asm.py
index 33ede81a41601..cce00e4a28027 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 c8598e74a1345..3e9380d95e3f6 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():
@@ -54,6 +56,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(
+ "--default-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 +101,7 @@ def main():
if m:
triple_in_cmd = m.groups()[0]
- march_in_cmd = None
+ march_in_cmd = ti.args.default_march
m = common.MARCH_ARG_RE.search(llc_cmd)
if m:
march_in_cmd = m.groups()[0]
@@ -101,7 +113,11 @@ def main():
from UpdateTestChecks import asm as output_type
common.verify_filecheck_prefixes(filecheck_cmd)
- if llc_tool not in LLC_LIKE_TOOLS:
+
+ 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
More information about the llvm-commits
mailing list