Skip to content

Commit

Permalink
[UpdateTestChecks] Fix update_*_test_checks.py to add "unused" pref…
Browse files Browse the repository at this point in the history
…ixes

The support introduced in D124306 was only added to
update_llc_test_checks.py, but the motivating usecases (see
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
cover update_test_checks.py, update_cc_test_checks.py, and
update_analyze_test_checks.py, too.

Issue #59220.

Differential Revision: https://reviews.llvm.org/D138836
  • Loading branch information
mtrofin committed Nov 28, 2022
1 parent 5611bf6 commit 255e7e1
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O0 -o - %s | FileCheck %s -check-prefix=A
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O3 -o - %s | FileCheck %s -check-prefix=A

int foo(int i ) {
return 1;
}
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
// A: {{.*}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# RUN: cp -f %S/Inputs/prefix-never-matches.cpp %t.cpp
# RUN: %update_cc_test_checks %t.cpp 2>&1 | FileCheck %s
# RUN: FileCheck --input-file=%t.cpp %s --check-prefix=OUTPUT

# CHECK: WARNING: Prefix A had conflicting output
# OUTPUT-NOT: A:
# RUN: %update_cc_test_checks %t.cpp
# RUN: diff -u %t.cpp %S/Inputs/prefix-never-matches.cpp.expected
17 changes: 13 additions & 4 deletions llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=instcombine -data-layout="e-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
; RUN: opt -passes=instcombine -data-layout="e-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
; RUN: opt -passes=instcombine -data-layout="E-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
; RUN: opt -passes=instcombine -data-layout="E-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
; RUN: opt -passes=instcombine -data-layout="e-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-64,CHECK-LE-64
; RUN: opt -passes=instcombine -data-layout="e-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-32,CHECK-LE-32
; RUN: opt -passes=instcombine -data-layout="E-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-64,CHECK-BE-64
; RUN: opt -passes=instcombine -data-layout="E-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-32,CHECK-BE-32

define void @load-1byte-chunk-of-1byte-alloca(ptr %src, i64 %byteOff, ptr %escape) {
; CHECK-ALL-LABEL: @load-1byte-chunk-of-1byte-alloca(
Expand Down Expand Up @@ -607,3 +607,12 @@ declare void @use.v4i8(<4 x i8>)
declare void @use.v8i8(<8 x i8>)
declare void @use.v16i8(<16 x i8>)
declare void @use.v32i8(<32 x i8>)
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK-ALL: {{.*}}
; CHECK-BE-32: {{.*}}
; CHECK-BE-64: {{.*}}
; CHECK-LE-32: {{.*}}
; CHECK-LE-64: {{.*}}
; CHECK-SCALAR: {{.*}}
; CHECK-SCALAR-32: {{.*}}
; CHECK-SCALAR-64: {{.*}}
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ for.body:
for.cond.cleanup:
ret void
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; AVX512: {{.*}}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ entry:
%arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
ret i32* %arrayidx
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; IS__CGSCC____: {{.*}}
; IS__TUNIT____: {{.*}}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ entry:
%arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
ret i32* %arrayidx
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; IS__CGSCC____: {{.*}}
; IS__TUNIT____: {{.*}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ define hidden i32 @"_Z54bar$ompvariant$bar"() {
entry:
ret i32 2
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -O0 -S < %s | FileCheck %s -check-prefix=A
; RUN: opt -O3 -S < %s | FileCheck %s -check-prefix=A

define i32 @foo(i32 %i) {
%r = add i32 1, 1
ret i32 %r
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; A: {{.*}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ define void @always_here() {
;
ret void
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; ALL_BUT_FOUR: {{.*}}
; ALL_BUT_ONE: {{.*}}
; ALL_BUT_THREE: {{.*}}
; ALL_BUT_TWO: {{.*}}
; FOUR: {{.*}}
; ONE: {{.*}}
; ONE_AND_THREE: {{.*}}
; ONE_AND_TWO: {{.*}}
; THREE_AND_FOUR: {{.*}}
; TWO: {{.*}}
; TWO_AND_FOUR: {{.*}}
; TWO_AND_THREE: {{.*}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# RUN: cp -f %S/Inputs/prefix-never-matches.ll %t.ll
# RUN: %update_test_checks %t.ll 2>&1 | FileCheck %s
# RUN: FileCheck --input-file=%t.ll %s --check-prefix=OUTPUT

# CHECK: WARNING: Prefix A had conflicting output
# OUTPUT-NOT: A:
# RUN: %update_test_checks %t.ll
# RUN: diff -u %t.ll %S/Inputs/prefix-never-matches.ll.expected
17 changes: 10 additions & 7 deletions llvm/utils/UpdateTestChecks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ def iterlines(self, output_lines):
yield line_info

def get_checks_for_unused_prefixes(self, run_list, used_prefixes: List[str]) -> List[str]:
unused_prefixes = set(
[prefix for sublist in run_list for prefix in sublist[0]]).difference(set(used_prefixes))
run_list = [element for element in run_list if element[0] is not None]
unused_prefixes = set([
prefix for sublist in run_list for prefix in sublist[0]
]).difference(set(used_prefixes))

ret = []
if not unused_prefixes:
Expand Down Expand Up @@ -499,9 +501,9 @@ def __init__(self, run_list, flags, scrubber_args, path):
self._processed_prefixes = set()
for tuple in run_list:
for prefix in tuple[0]:
self._func_dict.update({prefix:dict()})
self._func_dict.update({prefix: dict()})
self._func_order.update({prefix: []})
self._global_var_dict.update({prefix:dict()})
self._global_var_dict.update({prefix: dict()})

def finish_and_get_func_dict(self):
for prefix in self.get_failed_prefixes():
Expand Down Expand Up @@ -1123,6 +1125,7 @@ def add_global_checks(glob_val_dict, comment_marker, prefix_list, output_lines,

if printed_prefixes:
output_lines.append(comment_marker + SEPARATOR)
return printed_prefixes


def check_prefix(prefix):
Expand Down Expand Up @@ -1245,7 +1248,7 @@ def add_checks_at_end(output_lines, prefix_list, func_order,
# The func order can contain the same functions multiple times.
# If we see one again we are done.
if (func, prefix) in added:
continue
continue
if added:
output_lines.append(comment_string)

Expand All @@ -1265,6 +1268,6 @@ def add_checks_at_end(output_lines, prefix_list, func_order,
# mode.
for generated_prefix in check_generator(output_lines,
[([prefix], tool_args)], func):
added.add((func, generated_prefix))
generated_prefixes.add(generated_prefix)
added.add((func, generated_prefix))
generated_prefixes.add(generated_prefix)
return generated_prefixes
15 changes: 13 additions & 2 deletions llvm/utils/update_analyze_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def main():
common.debug('Rewriting FileCheck prefixes:', str(prefix_set), file=sys.stderr)
output_lines = []

generated_prefixes = []
for input_info in ti.iterlines(output_lines):
input_line = input_info.line
args = input_info.args
Expand All @@ -146,8 +147,14 @@ def main():
continue

# Print out the various check lines here.
common.add_analyze_checks(output_lines, ';', prefix_list, func_dict, func_name,
is_filtered=builder.is_filtered())
generated_prefixes.extend(
common.add_analyze_checks(
output_lines,
';',
prefix_list,
func_dict,
func_name,
is_filtered=builder.is_filtered()))
is_in_function_start = False

if is_in_function:
Expand All @@ -174,6 +181,10 @@ def main():
continue
is_in_function = is_in_function_start = True

if ti.args.gen_unused_prefix_body:
output_lines.extend(
ti.get_checks_for_unused_prefixes(prefix_list, generated_prefixes))

common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))

with open(ti.path, 'wb') as f:
Expand Down
48 changes: 32 additions & 16 deletions llvm/utils/update_cc_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def main():
lambda args: ti.args.include_generated_funcs,
'--include-generated-funcs',
True)

generated_prefixes = []
if include_generated_funcs:
# Generate the appropriate checks for each function. We need to emit
# these in the order according to the generated output so that CHECK-LABEL
Expand Down Expand Up @@ -362,13 +362,15 @@ def check_generator(my_output_lines, prefixes, func):
is_filtered=builder.is_filtered())

if ti.args.check_globals:
common.add_global_checks(builder.global_var_dict(), '//', run_list,
output_lines, global_vars_seen_dict, True,
True)
common.add_checks_at_end(output_lines, filecheck_run_list, builder.func_order(),
'//', lambda my_output_lines, prefixes, func:
check_generator(my_output_lines,
prefixes, func))
generated_prefixes.extend(
common.add_global_checks(builder.global_var_dict(), '//', run_list,
output_lines, global_vars_seen_dict, True,
True))
generated_prefixes.extend(
common.add_checks_at_end(
output_lines, filecheck_run_list, builder.func_order(), '//',
lambda my_output_lines, prefixes, func: check_generator(
my_output_lines, prefixes, func)))
else:
# Normal mode. Put checks before each source function.
for line_info in ti.iterlines(output_lines):
Expand Down Expand Up @@ -401,25 +403,39 @@ def check_generator(my_output_lines, prefixes, func):
output_lines.pop()
last_line = output_lines[-1].strip()
if ti.args.check_globals and not has_checked_pre_function_globals:
common.add_global_checks(builder.global_var_dict(), '//',
run_list, output_lines,
global_vars_seen_dict, True, True)
generated_prefixes.extend(
common.add_global_checks(builder.global_var_dict(), '//',
run_list, output_lines,
global_vars_seen_dict, True, True))
has_checked_pre_function_globals = True
if added:
output_lines.append('//')
added.add(mangled)
common.add_ir_checks(output_lines, '//', filecheck_run_list, func_dict, mangled,
False, args.function_signature, global_vars_seen_dict,
is_filtered=builder.is_filtered())
generated_prefixes.extend(
common.add_ir_checks(
output_lines,
'//',
filecheck_run_list,
func_dict,
mangled,
False,
args.function_signature,
global_vars_seen_dict,
is_filtered=builder.is_filtered()))
if line.rstrip('\n') == '//':
include_line = False

if include_line:
output_lines.append(line.rstrip('\n'))

if ti.args.check_globals:
common.add_global_checks(builder.global_var_dict(), '//', run_list,
output_lines, global_vars_seen_dict, True, False)
generated_prefixes.extend(
common.add_global_checks(builder.global_var_dict(), '//', run_list,
output_lines, global_vars_seen_dict, True,
False))
if ti.args.gen_unused_prefix_body:
output_lines.extend(
ti.get_checks_for_unused_prefixes(run_list, generated_prefixes))
common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
with open(ti.path, 'wb') as f:
f.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines])
Expand Down
78 changes: 52 additions & 26 deletions llvm/utils/update_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def main():
lambda args: ti.args.include_generated_funcs,
'--include-generated-funcs',
True)

generated_prefixes = []
if include_generated_funcs:
# Generate the appropriate checks for each function. We need to emit
# these in the order according to the generated output so that CHECK-LABEL
Expand All @@ -163,17 +163,26 @@ def main():

args = ti.args
if args.check_globals:
common.add_global_checks(builder.global_var_dict(), ';', prefix_list, output_lines, global_vars_seen_dict, args.preserve_names, True)
generated_prefixes.extend(
common.add_global_checks(builder.global_var_dict(), ';',
prefix_list, output_lines,
global_vars_seen_dict, args.preserve_names,
True))

# Now generate all the checks.
common.add_checks_at_end(output_lines, prefix_list, builder.func_order(),
';', lambda my_output_lines, prefixes, func:
common.add_ir_checks(my_output_lines, ';',
prefixes,
func_dict, func, False,
args.function_signature,
global_vars_seen_dict,
is_filtered=builder.is_filtered()))
generated_prefixes.extend(
common.add_checks_at_end(
output_lines, prefix_list, builder.func_order(), ';',
lambda my_output_lines, prefixes, func: common.add_ir_checks(
my_output_lines,
';',
prefixes,
func_dict,
func,
False,
args.function_signature,
global_vars_seen_dict,
is_filtered=builder.is_filtered())))
else:
# "Normal" mode.
for input_line_info in ti.iterlines(output_lines):
Expand All @@ -189,29 +198,40 @@ def main():
continue

# Print out the various check lines here.
common.add_ir_checks(output_lines, ';', prefix_list, func_dict,
func_name, args.preserve_names, args.function_signature,
global_vars_seen_dict,
is_filtered=builder.is_filtered())
generated_prefixes.extend(
common.add_ir_checks(
output_lines,
';',
prefix_list,
func_dict,
func_name,
args.preserve_names,
args.function_signature,
global_vars_seen_dict,
is_filtered=builder.is_filtered()))
is_in_function_start = False

m = common.IR_FUNCTION_RE.match(input_line)
if m and not has_checked_pre_function_globals:
if args.check_globals:
common.add_global_checks(builder.global_var_dict(), ';', prefix_list, output_lines, global_vars_seen_dict, args.preserve_names, True)
has_checked_pre_function_globals = True
if args.check_globals:
generated_prefixes.extend(
common.add_global_checks(builder.global_var_dict(), ';',
prefix_list, output_lines,
global_vars_seen_dict,
args.preserve_names, True))
has_checked_pre_function_globals = True

if common.should_add_line_to_output(input_line, prefix_set, not is_in_function):
# This input line of the function body will go as-is into the output.
# Except make leading whitespace uniform: 2 spaces.
input_line = common.SCRUB_LEADING_WHITESPACE_RE.sub(r' ', input_line)
output_lines.append(input_line)
if input_line.strip() == '}':
is_in_function = False
continue
# This input line of the function body will go as-is into the output.
# Except make leading whitespace uniform: 2 spaces.
input_line = common.SCRUB_LEADING_WHITESPACE_RE.sub(r' ', input_line)
output_lines.append(input_line)
if input_line.strip() == '}':
is_in_function = False
continue

if is_in_function:
continue
continue

m = common.IR_FUNCTION_RE.match(input_line)
if not m:
Expand All @@ -223,7 +243,13 @@ def main():
is_in_function = is_in_function_start = True

if args.check_globals:
common.add_global_checks(builder.global_var_dict(), ';', prefix_list, output_lines, global_vars_seen_dict, args.preserve_names, False)
generated_prefixes.extend(
common.add_global_checks(builder.global_var_dict(), ';', prefix_list,
output_lines, global_vars_seen_dict,
args.preserve_names, False))
if ti.args.gen_unused_prefix_body:
output_lines.extend(ti.get_checks_for_unused_prefixes(
prefix_list, generated_prefixes))
common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))

with open(ti.path, 'wb') as f:
Expand Down

0 comments on commit 255e7e1

Please sign in to comment.