Skip to content

Commit 528e975

Browse files
authored
[AMDGPU][test]added unique and sort options for update_mc_test_check script (#111769)
add a unique and a sort option to the update_mc_test_check script. These mc asm/dasm files are usually large in number of lines, and these lines are mostly similar to each other. These options can be useful when maintainer is merging or resolving conflicts by making the file identifical Also fixed a small issue in asm/dasm such that the auto generated header line is 1. asm using ";" instead of "//" as comment marker 2. dasm using ";" instead of "#" as comment marker
1 parent 449523f commit 528e975

16 files changed

+170
-13
lines changed

llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm.s.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
1+
// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
22
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
33

44
v_bfrev_b32 v5, v1

llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
1+
// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
22
// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
33

44
v_bfrev_b32 v5, v299
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
2+
3+
v_bfrev_b32 v5, v1
4+
5+
v_bfrev_b32 v1, v1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort
2+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
3+
4+
v_bfrev_b32 v1, v1
5+
// CHECK: v_bfrev_b32_e32 v1, v1 ; encoding: [0x01,0x71,0x02,0x7e]
6+
7+
v_bfrev_b32 v5, v1
8+
// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
2+
3+
v_bfrev_b32 v5, v1 //This is comment A
4+
5+
v_bfrev_b32 v1, v1
6+
// This is comment B
7+
8+
// This is comment C
9+
v_bfrev_b32 v2, v1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort
2+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
3+
4+
v_bfrev_b32 v1, v1
5+
// CHECK: v_bfrev_b32_e32 v1, v1 ; encoding: [0x01,0x71,0x02,0x7e]
6+
// This is comment B
7+
8+
// This is comment C
9+
v_bfrev_b32 v2, v1
10+
// CHECK: v_bfrev_b32_e32 v2, v1 ; encoding: [0x01,0x71,0x04,0x7e]
11+
12+
v_bfrev_b32 v5, v1 //This is comment A
13+
// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
2+
3+
//this is commentA
4+
v_bfrev_b32 v5, v1
5+
6+
v_bfrev_b32 v5, v1
7+
8+
//this is commentB
9+
10+
//this is commentB
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --unique
2+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
3+
4+
//this is commentA
5+
v_bfrev_b32 v5, v1
6+
// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
7+
8+
//this is commentB
9+
10+
//this is commentB

llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm.txt.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
1+
# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
22
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
33

44
0x00,0x00,0x00,0x7e
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
2+
3+
0x00,0x00,0x00,0x7e
4+
5+
0x00,0x00,0x00,0x7e
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --unique
2+
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
3+
4+
0x00,0x00,0x00,0x7e
5+
# CHECK: v_nop ; encoding: [0x00,0x00,0x00,0x7e]

llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_multirun_dasm.txt.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
1+
# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
22
# RUN: llvm-mc -triple=amdgcn -mcpu=tonga -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK,CHECKA %s
33
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK,CHECKB %s
44

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# REQUIRES: amdgpu-registered-target
2+
## Check that sort is working
3+
4+
# RUN: cp -f %S/Inputs/amdgpu_asm_sort.s %t.s && %update_mc_test_checks --sort %t.s
5+
# RUN: diff -u %S/Inputs/amdgpu_asm_sort.s.expected %t.s
6+
# RUN: cp -f %S/Inputs/amdgpu_asm_sort_with_comment.s %t.s && %update_mc_test_checks --sort %t.s
7+
# RUN: diff -u %S/Inputs/amdgpu_asm_sort_with_comment.s.expected %t.s
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# REQUIRES: amdgpu-registered-target
2+
## Check that unique is working
3+
4+
# RUN: cp -f %S/Inputs/amdgpu_asm_unique.s %t.s && %update_mc_test_checks --unique %t.s
5+
# RUN: diff -u %S/Inputs/amdgpu_asm_unique.s.expected %t.s
6+
# RUN: cp -f %S/Inputs/amdgpu_dasm_unique.txt %t.txt && %update_mc_test_checks --unique %t.txt
7+
# RUN: diff -u %S/Inputs/amdgpu_dasm_unique.txt.expected %t.txt

llvm/utils/UpdateTestChecks/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ def __init__(
275275
self.run_lines = find_run_lines(test, self.input_lines)
276276
self.comment_prefix = comment_prefix
277277
if self.comment_prefix is None:
278-
if self.path.endswith(".mir"):
278+
if self.path.endswith(".mir") or self.path.endswith(".txt"):
279279
self.comment_prefix = "#"
280+
elif self.path.endswith(".s"):
281+
self.comment_prefix = "//"
280282
else:
281283
self.comment_prefix = ";"
282284
self.autogenerated_note_prefix = self.comment_prefix + " " + UTC_ADVERT

llvm/utils/update_mc_test_checks.py

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import print_function
77

88
import argparse
9+
import functools
910
import os # Used to advertise this file's name ("autogenerated_note").
1011

1112
from UpdateTestChecks import common
@@ -50,6 +51,10 @@ def isTestLine(input_line, mc_mode):
5051
return True
5152

5253

54+
def isRunLine(l):
55+
return common.RUN_LINE_RE.match(l)
56+
57+
5358
def hasErr(err):
5459
return err and ERROR_RE.search(err) is not None
5560

@@ -118,6 +123,19 @@ def main():
118123
default=None,
119124
help="Set a default -march for when neither triple nor arch are found in a RUN line",
120125
)
126+
parser.add_argument(
127+
"--unique",
128+
action="store_true",
129+
default=False,
130+
help="remove duplicated test line if found",
131+
)
132+
parser.add_argument(
133+
"--sort",
134+
action="store_true",
135+
default=False,
136+
help="sort testline in alphabetic order (keep run-lines on top), this option could be dangerous as it"
137+
"could change the order of lines that are not expected",
138+
)
121139
parser.add_argument("tests", nargs="+")
122140
initial_args = common.parse_commandline_args(parser)
123141

@@ -130,6 +148,11 @@ def main():
130148
mc_mode = "asm"
131149
elif ti.path.endswith(".txt"):
132150
mc_mode = "dasm"
151+
152+
if ti.args.sort:
153+
print("sorting with dasm(.txt) file is not supported!")
154+
return -1
155+
133156
else:
134157
common.warn("Expected .s and .txt, Skipping file : ", ti.path)
135158
continue
@@ -196,6 +219,10 @@ def main():
196219

197220
# find all test line from input
198221
testlines = [l for l in ti.input_lines if isTestLine(l, mc_mode)]
222+
# remove duplicated lines to save running time
223+
testlines = list(dict.fromkeys(testlines))
224+
common.debug("Valid test line found: ", len(testlines))
225+
199226
run_list_size = len(run_list)
200227
testnum = len(testlines)
201228

@@ -233,7 +260,7 @@ def main():
233260
raw_prefixes.append(prefixes)
234261

235262
output_lines = []
236-
generated_prefixes = []
263+
generated_prefixes = {}
237264
used_prefixes = set()
238265
prefix_set = set([prefix for p in run_list for prefix in p[0]])
239266
common.debug("Rewriting FileCheck prefixes:", str(prefix_set))
@@ -298,23 +325,72 @@ def main():
298325
else:
299326
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
300327

301-
generated_prefixes.append(gen_prefix.rstrip("\n"))
328+
generated_prefixes[input_line] = gen_prefix.rstrip("\n")
302329

303330
# write output
304-
prefix_id = 0
305331
for input_info in ti.iterlines(output_lines):
306332
input_line = input_info.line
307-
if isTestLine(input_line, mc_mode):
333+
if input_line in testlines:
308334
output_lines.append(input_line)
309-
output_lines.append(generated_prefixes[prefix_id])
310-
prefix_id += 1
335+
output_lines.append(generated_prefixes[input_line])
311336

312337
elif should_add_line_to_output(input_line, prefix_set, mc_mode):
313338
output_lines.append(input_line)
314339

315-
elif input_line in ti.run_lines or input_line == "":
316-
output_lines.append(input_line)
340+
if ti.args.unique or ti.args.sort:
341+
# split with double newlines
342+
test_units = "\n".join(output_lines).split("\n\n")
343+
344+
# select the key line for each test unit
345+
test_dic = {}
346+
for unit in test_units:
347+
lines = unit.split("\n")
348+
for l in lines:
349+
# if contains multiple lines, use
350+
# the first testline or runline as key
351+
if isTestLine(l, mc_mode):
352+
test_dic[unit] = l
353+
break
354+
if isRunLine(l):
355+
test_dic[unit] = l
356+
break
357+
358+
# unique
359+
if ti.args.unique:
360+
new_test_units = []
361+
written_lines = set()
362+
for unit in test_units:
363+
# if not testline/runline, we just add it
364+
if unit not in test_dic:
365+
new_test_units.append(unit)
366+
else:
367+
if test_dic[unit] in written_lines:
368+
common.debug("Duplicated test skipped: ", unit)
369+
continue
370+
371+
written_lines.add(test_dic[unit])
372+
new_test_units.append(unit)
373+
test_units = new_test_units
374+
375+
# sort
376+
if ti.args.sort:
377+
378+
def getkey(l):
379+
# find key of test unit, otherwise use first line
380+
if l in test_dic:
381+
line = test_dic[l]
382+
else:
383+
line = l.split("\n")[0]
384+
385+
# runline placed on the top
386+
return (not isRunLine(line), line)
387+
388+
test_units = sorted(test_units, key=getkey)
389+
390+
# join back to be output string
391+
output_lines = "\n\n".join(test_units).split("\n")
317392

393+
# output
318394
if ti.args.gen_unused_prefix_body:
319395
output_lines.extend(
320396
ti.get_checks_for_unused_prefixes(run_list, used_prefixes)

0 commit comments

Comments
 (0)