Skip to content

Commit 5d4998b

Browse files
authored
UpdateTestChecks: Don't check meta details in func definition w/--global none (#124205)
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.
1 parent 007f601 commit 5d4998b

File tree

6 files changed

+90
-4
lines changed

6 files changed

+90
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5
2+
; RUN: opt < %s -S | FileCheck %s
3+
4+
; Function Attrs: convergent noinline nounwind
5+
declare hidden spir_func void @__cxx_global_var_init() #0
6+
7+
; Function Attrs: convergent noinline nounwind
8+
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 {
9+
; CHECK-LABEL: define hidden spir_kernel void @_GLOBAL__sub_I_global_init.clcpp(
10+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {{.*}}{
11+
; CHECK-NEXT: [[ENTRY:.*:]]
12+
; CHECK-NEXT: call spir_func void @__cxx_global_var_init()
13+
; CHECK-NEXT: ret void
14+
;
15+
entry:
16+
call spir_func void @__cxx_global_var_init()
17+
ret void
18+
}
19+
20+
attributes #0 = { convergent noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
21+
22+
!llvm.module.flags = !{!0}
23+
!opencl.ocl.version = !{!1}
24+
!opencl.cxx.version = !{!2}
25+
!opencl.spir.version = !{!1}
26+
!llvm.ident = !{!3}
27+
28+
!0 = !{i32 1, !"wchar_size", i32 4}
29+
!1 = !{i32 2, i32 0}
30+
!2 = !{i32 1, i32 0}
31+
!3 = !{!"clang version 20.0.0git"}
32+
!4 = !{}
33+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5
2+
; RUN: opt < %s -S | FileCheck %s
3+
4+
; Function Attrs: convergent noinline nounwind
5+
declare hidden spir_func void @__cxx_global_var_init() #0
6+
7+
; Function Attrs: convergent noinline nounwind
8+
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 {
9+
; CHECK-LABEL: define hidden spir_kernel void @_GLOBAL__sub_I_global_init.clcpp(
10+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {{.*}}{
11+
; CHECK-NEXT: [[ENTRY:.*:]]
12+
; CHECK-NEXT: call spir_func void @__cxx_global_var_init()
13+
; CHECK-NEXT: ret void
14+
;
15+
entry:
16+
call spir_func void @__cxx_global_var_init()
17+
ret void
18+
}
19+
20+
attributes #0 = { convergent noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
21+
22+
!llvm.module.flags = !{!0}
23+
!opencl.ocl.version = !{!1}
24+
!opencl.cxx.version = !{!2}
25+
!opencl.spir.version = !{!1}
26+
!llvm.ident = !{!3}
27+
28+
!0 = !{i32 1, !"wchar_size", i32 4}
29+
!1 = !{i32 2, i32 0}
30+
!2 = !{i32 1, i32 0}
31+
!3 = !{!"clang version 20.0.0git"}
32+
!4 = !{}
33+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Basic test checking that update_test_checks.py --check-globals none works correctly
2+
# RUN: cp -f %S/Inputs/global_none_meta.ll %t.ll && %update_test_checks %t.ll --check-globals none
3+
# RUN: diff -u %t.ll %S/Inputs/global_none_meta.ll.expected

llvm/utils/UpdateTestChecks/common.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ def get_failed_prefixes(self):
983983
##### Generator of LLVM IR CHECK lines
984984

985985
SCRUB_IR_COMMENT_RE = re.compile(r"\s*;.*")
986+
SCRUB_IR_FUNC_META_RE = re.compile(r"((?:\!(?!dbg\b)[a-zA-Z_]\w*(?:\s+![0-9]+)?)\s*)+")
986987

987988
# TODO: We should also derive check lines for global, debug, loop declarations, etc..
988989

@@ -1087,13 +1088,15 @@ def __init__(
10871088
nameless_values: List[NamelessValue],
10881089
regexp_prefix,
10891090
regexp_suffix,
1091+
no_meta_details=False,
10901092
):
10911093
self._version = version
10921094
self._mode = mode
10931095
self._nameless_values = nameless_values
10941096

10951097
self._regexp_prefix = regexp_prefix
10961098
self._regexp_suffix = regexp_suffix
1099+
self._no_meta_details = no_meta_details
10971100

10981101
self._regexp, _ = self._build_regexp(False, False)
10991102
(
@@ -1147,6 +1150,9 @@ def get_regexp(self):
11471150
def get_unstable_globals_regexp(self):
11481151
return self._unstable_globals_regexp
11491152

1153+
def no_meta_details(self):
1154+
return self._no_meta_details
1155+
11501156
# The entire match is group 0, the prefix has one group (=1), the entire
11511157
# IR_VALUE_REGEXP_STRING is one group (=2), and then the nameless values start.
11521158
FIRST_NAMELESS_GROUP_IN_MATCH = 3
@@ -1175,7 +1181,7 @@ def get_nameless_value_from_match(self, match) -> NamelessValue:
11751181
return self.get_match_info(match)[1]
11761182

11771183

1178-
def make_ir_generalizer(version):
1184+
def make_ir_generalizer(version, no_meta_details):
11791185
values = []
11801186

11811187
if version >= 5:
@@ -1224,7 +1230,9 @@ def make_ir_generalizer(version):
12241230
# not (unstable_ids_only and nameless_value.match_literally)
12251231
# ]
12261232

1227-
return GeneralizerInfo(version, GeneralizerInfo.MODE_IR, values, prefix, suffix)
1233+
return GeneralizerInfo(
1234+
version, GeneralizerInfo.MODE_IR, values, prefix, suffix, no_meta_details
1235+
)
12281236

12291237

12301238
def make_asm_generalizer(version):
@@ -1726,6 +1734,7 @@ def generalize_check_lines(
17261734
original_check_lines=None,
17271735
*,
17281736
unstable_globals_only=False,
1737+
no_meta_details=False,
17291738
):
17301739
if unstable_globals_only:
17311740
regexp = ginfo.get_unstable_globals_regexp()
@@ -1755,6 +1764,9 @@ def escape_braces(match_obj):
17551764
break
17561765
# Ignore any comments, since the check lines will too.
17571766
scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r"", line)
1767+
# Ignore the metadata details if check global is none
1768+
if no_meta_details:
1769+
scrubbed_line = SCRUB_IR_FUNC_META_RE.sub(r"{{.*}}", scrubbed_line)
17581770
lines[i] = scrubbed_line
17591771

17601772
if not preserve_names:
@@ -1986,6 +1998,7 @@ def add_checks(
19861998
global_vars_seen,
19871999
preserve_names,
19882000
original_check_lines=[],
2001+
no_meta_details=ginfo.no_meta_details(),
19892002
)[0]
19902003
func_name_separator = func_dict[checkprefix][func_name].func_name_separator
19912004
if "[[" in args_and_sig:

llvm/utils/update_cc_test_checks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ def main():
368368

369369
# Store only filechecked runlines.
370370
filecheck_run_list = [i for i in run_list if i[0]]
371-
ginfo = common.make_ir_generalizer(version=ti.args.version)
371+
ginfo = common.make_ir_generalizer(
372+
ti.args.version, ti.args.check_globals == "none"
373+
)
372374
builder = common.FunctionTestBuilder(
373375
run_list=filecheck_run_list,
374376
flags=ti.args,

llvm/utils/update_test_checks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ def main():
153153
# now, we just ignore all but the last.
154154
prefix_list.append((check_prefixes, tool_cmd_args, preprocess_cmd))
155155

156-
ginfo = common.make_ir_generalizer(ti.args.version)
156+
ginfo = common.make_ir_generalizer(
157+
ti.args.version, ti.args.check_globals == "none"
158+
)
157159
global_vars_seen_dict = {}
158160
builder = common.FunctionTestBuilder(
159161
run_list=prefix_list,

0 commit comments

Comments
 (0)