Skip to content

update_test_checks: keep names stable with generated functions #87988

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 1 commit into from
Apr 17, 2024
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
Expand Up @@ -16,9 +16,9 @@ define i32 @func({i32, i32} %x, i32 %y) {

; CHECK-LABEL: define i32 @func(
; CHECK-SAME: { i32, i32 } [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[X_I34:%.*]] = extractvalue { i32, i32 } [[X]], 0
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y]], 1
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_I34]], [[TMP1]]
; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], 3
; CHECK-NEXT: ret i32 [[TMP3]]
; CHECK-NEXT: [[X_I33:%.*]] = extractvalue { i32, i32 } [[X]], 0
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[Y]], 1
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X_I33]], [[TMP3]]
; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], 3
; CHECK-NEXT: ret i32 [[TMP2]]
;
59 changes: 35 additions & 24 deletions llvm/utils/UpdateTestChecks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,36 +430,47 @@ def collect_original_check_lines(ti: TestInfo, prefix_set: set):
result[func_name][prefix] is filled with a list of right-hand-sides of check
lines.
"""
result = {}
result = collections.defaultdict(lambda: {})

current_prefix = None
current_function = None
for input_line_info in ti.ro_iterlines():
input_line = input_line_info.line
if current_function is not None:
if input_line == "":
continue
if input_line.lstrip().startswith(";"):
m = CHECK_RE.match(input_line)
if (
m is not None
and m.group(1) in prefix_set
and m.group(2) not in ["LABEL", "SAME"]
):
if m.group(1) not in current_function:
current_function[m.group(1)] = []
current_function[m.group(1)].append(input_line[m.end() :].strip())
continue
current_function = None
if input_line.lstrip().startswith(";"):
m = CHECK_RE.match(input_line)
if m is not None:
prefix = m.group(1)
check_kind = m.group(2)
line = input_line[m.end() :].strip()

if prefix != current_prefix:
current_function = None
current_prefix = None

if check_kind not in ["LABEL", "SAME"]:
if current_function is not None:
current_function.append(line)
continue

m = IR_FUNCTION_RE.match(input_line)
if m is not None:
func_name = m.group(1)
if ti.args.function is not None and func_name != ti.args.function:
# When filtering on a specific function, skip all others.
continue
if check_kind == "SAME":
continue

if check_kind == "LABEL":
m = IR_FUNCTION_RE.match(line)
if m is not None:
func_name = m.group(1)
if (
ti.args.function is not None
and func_name != ti.args.function
):
# When filtering on a specific function, skip all others.
continue

current_prefix = prefix
current_function = result[func_name][prefix] = []
continue

assert func_name not in result
current_function = result[func_name] = {}
current_function = None

return result

Expand Down