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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 = !{}

Original file line number Diff line number Diff line change
@@ -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 = !{}

Original file line number Diff line number Diff line change
@@ -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
17 changes: 15 additions & 2 deletions llvm/utils/UpdateTestChecks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..

Expand Down Expand Up @@ -1086,13 +1087,15 @@ def __init__(
nameless_values: List[NamelessValue],
regexp_prefix,
regexp_suffix,
no_meta_details=False,
):
self._version = version
self._mode = mode
self._nameless_values = nameless_values

self._regexp_prefix = regexp_prefix
self._regexp_suffix = regexp_suffix
self._no_meta_details = no_meta_details

self._regexp, _ = self._build_regexp(False, False)
(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1223,7 +1229,9 @@ 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):
Expand Down Expand Up @@ -1725,6 +1733,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()
Expand Down Expand Up @@ -1754,6 +1763,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:
Expand Down Expand Up @@ -1985,6 +1997,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:
Expand Down
4 changes: 3 additions & 1 deletion llvm/utils/update_cc_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ 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,
Expand Down
4 changes: 3 additions & 1 deletion llvm/utils/update_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ 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,
Expand Down
Loading