Skip to content

Commit 26f9d92

Browse files
committed
add a remove-duplicate and sort option to update_mc_test script
1 parent 35684fa commit 26f9d92

14 files changed

+124
-9
lines changed
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 v5, v1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --remove-duplicate
2+
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
3+
4+
v_bfrev_b32 v5, v1
5+
// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
6+
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]

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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --remove-duplicate
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]
6+
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+
0xfd,0xb8,0x0a,0x7f
4+
5+
0x00,0x00,0x00,0x7e
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 -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]
6+
7+
0xfd,0xb8,0x0a,0x7f
8+
# CHECK: :[[@LINE-1]]:1: warning: invalid instruction encoding

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 remove duplicate is working
3+
4+
# RUN: cp -f %S/Inputs/amdgpu_asm_remove_duplicates.s %t.s && %update_mc_test_checks --remove-duplicate %t.s
5+
# RUN: diff -u %S/Inputs/amdgpu_asm_remove_duplicates.s.expected %t.s
6+
# RUN: cp -f %S/Inputs/amdgpu_dasm_remove_duplicates.txt %t.txt && %update_mc_test_checks --remove-duplicate %t.txt
7+
# RUN: diff -u %S/Inputs/amdgpu_dasm_remove_duplicates.txt.expected %t.txt
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_dasm_sort.txt %t.txt && %update_mc_test_checks --sort %t.txt
7+
# RUN: diff -u %S/Inputs/amdgpu_dasm_sort.txt.expected %t.txt

llvm/utils/UpdateTestChecks/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ 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 = "#"
280280
else:
281281
self.comment_prefix = ";"

llvm/utils/update_mc_test_checks.py

Lines changed: 59 additions & 6 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
@@ -118,6 +119,19 @@ def main():
118119
default=None,
119120
help="Set a default -march for when neither triple nor arch are found in a RUN line",
120121
)
122+
parser.add_argument(
123+
"--remove-duplicate",
124+
action="store_true",
125+
default=False,
126+
help="remove duplicated test line if found",
127+
)
128+
parser.add_argument(
129+
"--sort",
130+
action="store_true",
131+
default=False,
132+
help="sort testline in alphabetic order (keep run-lines on top), this option could be dangerous as it"
133+
"could change the order of lines that are not expected",
134+
)
121135
parser.add_argument("tests", nargs="+")
122136
initial_args = common.parse_commandline_args(parser)
123137

@@ -196,6 +210,10 @@ def main():
196210

197211
# find all test line from input
198212
testlines = [l for l in ti.input_lines if isTestLine(l, mc_mode)]
213+
# remove duplicated lines to save running time
214+
testlines = list(dict.fromkeys(testlines))
215+
common.debug("Valid test line found: ", len(testlines))
216+
199217
run_list_size = len(run_list)
200218
testnum = len(testlines)
201219

@@ -233,7 +251,7 @@ def main():
233251
raw_prefixes.append(prefixes)
234252

235253
output_lines = []
236-
generated_prefixes = []
254+
generated_prefixes = {}
237255
used_prefixes = set()
238256
prefix_set = set([prefix for p in run_list for prefix in p[0]])
239257
common.debug("Rewriting FileCheck prefixes:", str(prefix_set))
@@ -298,23 +316,58 @@ def main():
298316
else:
299317
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
300318

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

303321
# write output
304-
prefix_id = 0
322+
written_lines = set()
305323
for input_info in ti.iterlines(output_lines):
306324
input_line = input_info.line
307-
if isTestLine(input_line, mc_mode):
325+
if input_line in testlines:
326+
if ti.args.remove_duplicate:
327+
if input_line in written_lines:
328+
common.debug("Duplicated line skipped: ", input_line)
329+
continue
330+
else:
331+
written_lines.add(input_line)
308332
output_lines.append(input_line)
309-
output_lines.append(generated_prefixes[prefix_id])
310-
prefix_id += 1
333+
output_lines.append(generated_prefixes[input_line])
311334

312335
elif should_add_line_to_output(input_line, prefix_set, mc_mode):
313336
output_lines.append(input_line)
314337

315338
elif input_line in ti.run_lines or input_line == "":
316339
output_lines.append(input_line)
317340

341+
# sort
342+
if ti.args.sort:
343+
# split with double newlines
344+
lines = "\n".join(output_lines)
345+
lines = lines.split("\n\n")
346+
347+
def compare(l1, l2):
348+
# if contains multiple lines, just compare first line
349+
l1 = l1.split("\n")[0]
350+
l2 = l2.split("\n")[0]
351+
352+
isl1_runline = l1 in ti.run_lines
353+
isl2_runline = l2 in ti.run_lines
354+
355+
if isl1_runline and not isl2_runline:
356+
return -1
357+
elif not isl1_runline and isl2_runline:
358+
return 1
359+
else:
360+
if l1 < l2:
361+
return -1
362+
elif l1 > l2:
363+
return 1
364+
else:
365+
return 0
366+
367+
lines = sorted(lines, key=functools.cmp_to_key(compare))
368+
output_lines = "\n\n".join(lines).split("\n")
369+
370+
# output
318371
if ti.args.gen_unused_prefix_body:
319372
output_lines.extend(
320373
ti.get_checks_for_unused_prefixes(run_list, used_prefixes)

0 commit comments

Comments
 (0)