Skip to content

UpdateTestChecks: Don't check meta details in func definition w/--global none #124205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2025

Conversation

jsji
Copy link
Member

@jsji jsji commented Jan 23, 2025

When --check-globals none, we skipped all the globals in check lines.
However, we are still checking the meta info in function defintion.

The generated checks are still sensitive to metadata changes.

This is to scrub the meta info and match them with {{.*}} instead.

@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-testing-tools

Author: Jinsong Ji (jsji)

Changes

When --check-globals none, we skipped all the globals in check lines.
However, we are still checking the meta info in function defintion.

The generated checks still sensitive to metadata changes

This is to scrub the meta info and match them with {{.*}} instead.


Full diff: https://github.com/llvm/llvm-project/pull/124205.diff

6 Files Affected:

  • (added) llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll (+33)
  • (added) llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll.expected (+33)
  • (added) llvm/test/tools/UpdateTestChecks/update_test_checks/global_none_meta.test (+3)
  • (modified) llvm/utils/UpdateTestChecks/common.py (+13-2)
  • (modified) llvm/utils/update_cc_test_checks.py (+1-1)
  • (modified) llvm/utils/update_test_checks.py (+1-1)
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll
new file mode 100644
index 00000000000000..b9fd8a47df14be
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5
+; RUN: opt < %s -S | FileCheck %s
+
+; Function Attrs: convergent noinline nounwind
+declare hidden spir_func void @__cxx_global_var_init() #0
+
+; Function Attrs: convergent noinline nounwind
+define hidden spir_kernel void @_GLOBAL__sub_I_global_init.clcpp() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
+; CHECK-LABEL: define hidden spir_kernel void @_GLOBAL__sub_I_global_init.clcpp(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {{.*}}{
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    call spir_func void @__cxx_global_var_init()
+; CHECK-NEXT:    ret void
+;
+entry:
+  call spir_func void @__cxx_global_var_init()
+  ret void
+}
+
+attributes #0 = { convergent noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+!llvm.module.flags = !{!0}
+!opencl.ocl.version = !{!1}
+!opencl.cxx.version = !{!2}
+!opencl.spir.version = !{!1}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 2, i32 0}
+!2 = !{i32 1, i32 0}
+!3 = !{!"clang version 20.0.0git"}
+!4 = !{}
+
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll.expected
new file mode 100644
index 00000000000000..b9fd8a47df14be
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/global_none_meta.ll.expected
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5
+; RUN: opt < %s -S | FileCheck %s
+
+; Function Attrs: convergent noinline nounwind
+declare hidden spir_func void @__cxx_global_var_init() #0
+
+; Function Attrs: convergent noinline nounwind
+define hidden spir_kernel void @_GLOBAL__sub_I_global_init.clcpp() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
+; CHECK-LABEL: define hidden spir_kernel void @_GLOBAL__sub_I_global_init.clcpp(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {{.*}}{
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    call spir_func void @__cxx_global_var_init()
+; CHECK-NEXT:    ret void
+;
+entry:
+  call spir_func void @__cxx_global_var_init()
+  ret void
+}
+
+attributes #0 = { convergent noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+!llvm.module.flags = !{!0}
+!opencl.ocl.version = !{!1}
+!opencl.cxx.version = !{!2}
+!opencl.spir.version = !{!1}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 2, i32 0}
+!2 = !{i32 1, i32 0}
+!3 = !{!"clang version 20.0.0git"}
+!4 = !{}
+
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/global_none_meta.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/global_none_meta.test
new file mode 100644
index 00000000000000..11a4665c44f929
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/global_none_meta.test
@@ -0,0 +1,3 @@
+## Basic test checking that update_test_checks.py --check-globals none works correctly
+# RUN: cp -f %S/Inputs/global_none_meta.ll %t.ll && %update_test_checks %t.ll --check-globals none
+# RUN: diff -u %t.ll %S/Inputs/global_none_meta.ll.expected
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 1a875c2b523e42..05d4f81dc35447 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -982,6 +982,7 @@ def get_failed_prefixes(self):
 ##### Generator of LLVM IR CHECK lines
 
 SCRUB_IR_COMMENT_RE = re.compile(r"\s*;.*")
+SCRUB_IR_FUNC_META_RE = re.compile(r'((?:\!(?!dbg\b)[a-zA-Z_]\w*(?:\s+![0-9]+)?)\s*)+')
 
 # TODO: We should also derive check lines for global, debug, loop declarations, etc..
 
@@ -1086,6 +1087,7 @@ def __init__(
         nameless_values: List[NamelessValue],
         regexp_prefix,
         regexp_suffix,
+        no_meta_details = False
     ):
         self._version = version
         self._mode = mode
@@ -1093,6 +1095,7 @@ def __init__(
 
         self._regexp_prefix = regexp_prefix
         self._regexp_suffix = regexp_suffix
+        self._no_meta_details = no_meta_details
 
         self._regexp, _ = self._build_regexp(False, False)
         (
@@ -1146,6 +1149,9 @@ def get_regexp(self):
     def get_unstable_globals_regexp(self):
         return self._unstable_globals_regexp
 
+    def no_meta_details(self):
+        return self._no_meta_details
+
     # The entire match is group 0, the prefix has one group (=1), the entire
     # IR_VALUE_REGEXP_STRING is one group (=2), and then the nameless values start.
     FIRST_NAMELESS_GROUP_IN_MATCH = 3
@@ -1174,7 +1180,7 @@ def get_nameless_value_from_match(self, match) -> NamelessValue:
         return self.get_match_info(match)[1]
 
 
-def make_ir_generalizer(version):
+def make_ir_generalizer(version, no_meta_details):
     values = []
 
     if version >= 5:
@@ -1223,7 +1229,7 @@ def make_ir_generalizer(version):
     #        not (unstable_ids_only and nameless_value.match_literally)
     # ]
 
-    return GeneralizerInfo(version, GeneralizerInfo.MODE_IR, values, prefix, suffix)
+    return GeneralizerInfo(version, GeneralizerInfo.MODE_IR, values, prefix, suffix, no_meta_details)
 
 
 def make_asm_generalizer(version):
@@ -1725,6 +1731,7 @@ def generalize_check_lines(
     original_check_lines=None,
     *,
     unstable_globals_only=False,
+    no_meta_details = False,
 ):
     if unstable_globals_only:
         regexp = ginfo.get_unstable_globals_regexp()
@@ -1754,6 +1761,9 @@ def escape_braces(match_obj):
                     break
             # Ignore any comments, since the check lines will too.
             scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r"", line)
+            # Ignore the metadata details if check global is none
+            if no_meta_details:
+               scrubbed_line = SCRUB_IR_FUNC_META_RE.sub(r"{{.*}}", scrubbed_line)
             lines[i] = scrubbed_line
 
     if not preserve_names:
@@ -1985,6 +1995,7 @@ def add_checks(
                     global_vars_seen,
                     preserve_names,
                     original_check_lines=[],
+                    no_meta_details=ginfo.no_meta_details()
                 )[0]
             func_name_separator = func_dict[checkprefix][func_name].func_name_separator
             if "[[" in args_and_sig:
diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index 7a4796eaabb3bf..7b8fff6f24c084 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -368,7 +368,7 @@ def main():
 
         # Store only filechecked runlines.
         filecheck_run_list = [i for i in run_list if i[0]]
-        ginfo = common.make_ir_generalizer(version=ti.args.version)
+        ginfo = common.make_ir_generalizer(ti.args.version, ti.args.check_globals == "none")
         builder = common.FunctionTestBuilder(
             run_list=filecheck_run_list,
             flags=ti.args,
diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index b413c253e39757..e71910bbb7e421 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -153,7 +153,7 @@ def main():
             # now, we just ignore all but the last.
             prefix_list.append((check_prefixes, tool_cmd_args, preprocess_cmd))
 
-        ginfo = common.make_ir_generalizer(ti.args.version)
+        ginfo = common.make_ir_generalizer(ti.args.version, ti.args.check_globals == "none")
         global_vars_seen_dict = {}
         builder = common.FunctionTestBuilder(
             run_list=prefix_list,

@jsji jsji requested review from nhaehnle and tru January 23, 2025 23:17
Copy link

github-actions bot commented Jan 23, 2025

✅ With the latest revision this PR passed the Python code formatter.

@jsji
Copy link
Member Author

jsji commented Jan 28, 2025

Gentle ping.

@jsji
Copy link
Member Author

jsji commented Feb 3, 2025

@llvm/pr-subscribers-testing-tools Any one can help review? Thanks.

@jsji jsji requested a review from KanRobert February 7, 2025 15:14
@jsji jsji self-assigned this Feb 7, 2025
@jsji
Copy link
Member Author

jsji commented Feb 12, 2025

Ping...

@jsji jsji merged commit 5d4998b into llvm:main Feb 20, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants