[llvm] [AMDGPU][test]added remove duplicate options for update_mc_test_check script (PR #111769)
Brox Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 16:57:21 PDT 2024
https://github.com/broxigarchen updated https://github.com/llvm/llvm-project/pull/111769
>From 98ece714f7e886c16a8edc9465b5b2bf101f2c0e Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Thu, 10 Oct 2024 17:55:15 -0400
Subject: [PATCH 1/2] add a remove-duplicate and sort option to update_mc_test
script
---
.../Inputs/amdgpu_asm_remove_duplicates.s | 5 ++
.../amdgpu_asm_remove_duplicates.s.expected | 6 ++
.../Inputs/amdgpu_asm_sort.s | 5 ++
.../Inputs/amdgpu_asm_sort.s.expected | 8 +++
.../Inputs/amdgpu_asm_sort_with_comment.s | 6 ++
.../amdgpu_asm_sort_with_comment.s.expected | 9 +++
.../Inputs/amdgpu_dasm.txt.expected | 2 +-
.../Inputs/amdgpu_dasm_remove_duplicates.txt | 5 ++
...amdgpu_dasm_remove_duplicates.txt.expected | 6 ++
.../Inputs/amdgpu_dasm_sort.txt | 5 ++
.../Inputs/amdgpu_dasm_sort.txt.expected | 8 +++
.../Inputs/amdgpu_multirun_dasm.txt.expected | 2 +-
.../amdgpu-remove-duplicates.test | 7 ++
.../update_mc_test_checks/amdgpu-sort.test | 9 +++
llvm/utils/UpdateTestChecks/common.py | 2 +-
llvm/utils/update_mc_test_checks.py | 65 +++++++++++++++++--
16 files changed, 141 insertions(+), 9 deletions(-)
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt.expected
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-sort.test
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
new file mode 100644
index 00000000000000..49f02cb5cb89c7
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
@@ -0,0 +1,5 @@
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v5, v1
+
+v_bfrev_b32 v5, v1
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
new file mode 100644
index 00000000000000..57c572887e7eea
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
@@ -0,0 +1,6 @@
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --remove-duplicate
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v5, v1
+// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
+
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s
new file mode 100644
index 00000000000000..ea03c5a6911fad
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s
@@ -0,0 +1,5 @@
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v5, v1
+
+v_bfrev_b32 v1, v1
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s.expected
new file mode 100644
index 00000000000000..23afc95d6ae031
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort.s.expected
@@ -0,0 +1,8 @@
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v1, v1
+// CHECK: v_bfrev_b32_e32 v1, v1 ; encoding: [0x01,0x71,0x02,0x7e]
+
+v_bfrev_b32 v5, v1
+// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s
new file mode 100644
index 00000000000000..a1ad81142efd2a
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s
@@ -0,0 +1,6 @@
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v5, v1 //This is comment A
+
+v_bfrev_b32 v1, v1
+// This is comment B
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected
new file mode 100644
index 00000000000000..24834d2b65f73d
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected
@@ -0,0 +1,9 @@
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort --version 5
+// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+
+v_bfrev_b32 v1, v1
+// CHECK: v_bfrev_b32_e32 v1, v1 ; encoding: [0x01,0x71,0x02,0x7e]
+// This is comment B
+
+v_bfrev_b32 v5, v1 //This is comment A
+// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm.txt.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm.txt.expected
index 1b64695fc29408..f37c8064713f1a 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm.txt.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm.txt.expected
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
+# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
0x00,0x00,0x00,0x7e
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
new file mode 100644
index 00000000000000..3d0d49ddeea425
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+0x00,0x00,0x00,0x7e
+
+0x00,0x00,0x00,0x7e
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
new file mode 100644
index 00000000000000..d81f3984696be3
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
@@ -0,0 +1,6 @@
+# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --remove-duplicate
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+0x00,0x00,0x00,0x7e
+# CHECK: v_nop ; encoding: [0x00,0x00,0x00,0x7e]
+
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt
new file mode 100644
index 00000000000000..5e60bf1b7ef66d
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+0xfd,0xb8,0x0a,0x7f
+
+0x00,0x00,0x00,0x7e
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt.expected
new file mode 100644
index 00000000000000..875126c13fe3e4
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_sort.txt.expected
@@ -0,0 +1,8 @@
+# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
+
+0x00,0x00,0x00,0x7e
+# CHECK: v_nop ; encoding: [0x00,0x00,0x00,0x7e]
+
+0xfd,0xb8,0x0a,0x7f
+# CHECK: :[[@LINE-1]]:1: warning: invalid instruction encoding
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_multirun_dasm.txt.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_multirun_dasm.txt.expected
index 03a5ec3c559dbf..7b6b832801625b 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_multirun_dasm.txt.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_multirun_dasm.txt.expected
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
+# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
# RUN: llvm-mc -triple=amdgcn -mcpu=tonga -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK,CHECKA %s
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK,CHECKB %s
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
new file mode 100644
index 00000000000000..df7d56a460f45e
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
@@ -0,0 +1,7 @@
+# REQUIRES: amdgpu-registered-target
+## Check that remove duplicate is working
+
+# RUN: cp -f %S/Inputs/amdgpu_asm_remove_duplicates.s %t.s && %update_mc_test_checks --remove-duplicate %t.s
+# RUN: diff -u %S/Inputs/amdgpu_asm_remove_duplicates.s.expected %t.s
+# RUN: cp -f %S/Inputs/amdgpu_dasm_remove_duplicates.txt %t.txt && %update_mc_test_checks --remove-duplicate %t.txt
+# RUN: diff -u %S/Inputs/amdgpu_dasm_remove_duplicates.txt.expected %t.txt
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-sort.test b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-sort.test
new file mode 100644
index 00000000000000..b1c9af2c78c918
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-sort.test
@@ -0,0 +1,9 @@
+# REQUIRES: amdgpu-registered-target
+## Check that sort is working
+
+# RUN: cp -f %S/Inputs/amdgpu_asm_sort.s %t.s && %update_mc_test_checks --sort %t.s
+# RUN: diff -u %S/Inputs/amdgpu_asm_sort.s.expected %t.s
+# RUN: cp -f %S/Inputs/amdgpu_asm_sort_with_comment.s %t.s && %update_mc_test_checks --sort %t.s
+# RUN: diff -u %S/Inputs/amdgpu_asm_sort_with_comment.s.expected %t.s
+# RUN: cp -f %S/Inputs/amdgpu_dasm_sort.txt %t.txt && %update_mc_test_checks --sort %t.txt
+# RUN: diff -u %S/Inputs/amdgpu_dasm_sort.txt.expected %t.txt
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 0fbb73431d2cfb..3408293560ee21 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -275,7 +275,7 @@ def __init__(
self.run_lines = find_run_lines(test, self.input_lines)
self.comment_prefix = comment_prefix
if self.comment_prefix is None:
- if self.path.endswith(".mir"):
+ if self.path.endswith(".mir") or self.path.endswith(".txt"):
self.comment_prefix = "#"
else:
self.comment_prefix = ";"
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index f9f8cfdea418d0..463f3d98093137 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -6,6 +6,7 @@
from __future__ import print_function
import argparse
+import functools
import os # Used to advertise this file's name ("autogenerated_note").
from UpdateTestChecks import common
@@ -118,6 +119,19 @@ def main():
default=None,
help="Set a default -march for when neither triple nor arch are found in a RUN line",
)
+ parser.add_argument(
+ "--remove-duplicate",
+ action="store_true",
+ default=False,
+ help="remove duplicated test line if found",
+ )
+ parser.add_argument(
+ "--sort",
+ action="store_true",
+ default=False,
+ help="sort testline in alphabetic order (keep run-lines on top), this option could be dangerous as it"
+ "could change the order of lines that are not expected",
+ )
parser.add_argument("tests", nargs="+")
initial_args = common.parse_commandline_args(parser)
@@ -196,6 +210,10 @@ def main():
# find all test line from input
testlines = [l for l in ti.input_lines if isTestLine(l, mc_mode)]
+ # remove duplicated lines to save running time
+ testlines = list(dict.fromkeys(testlines))
+ common.debug("Valid test line found: ", len(testlines))
+
run_list_size = len(run_list)
testnum = len(testlines)
@@ -233,7 +251,7 @@ def main():
raw_prefixes.append(prefixes)
output_lines = []
- generated_prefixes = []
+ generated_prefixes = {}
used_prefixes = set()
prefix_set = set([prefix for p in run_list for prefix in p[0]])
common.debug("Rewriting FileCheck prefixes:", str(prefix_set))
@@ -298,16 +316,21 @@ def main():
else:
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
- generated_prefixes.append(gen_prefix.rstrip("\n"))
+ generated_prefixes[input_line] = gen_prefix.rstrip("\n")
# write output
- prefix_id = 0
+ written_lines = set()
for input_info in ti.iterlines(output_lines):
input_line = input_info.line
- if isTestLine(input_line, mc_mode):
+ if input_line in testlines:
+ if ti.args.remove_duplicate:
+ if input_line in written_lines:
+ common.debug("Duplicated line skipped: ", input_line)
+ continue
+ else:
+ written_lines.add(input_line)
output_lines.append(input_line)
- output_lines.append(generated_prefixes[prefix_id])
- prefix_id += 1
+ output_lines.append(generated_prefixes[input_line])
elif should_add_line_to_output(input_line, prefix_set, mc_mode):
output_lines.append(input_line)
@@ -315,6 +338,36 @@ def main():
elif input_line in ti.run_lines or input_line == "":
output_lines.append(input_line)
+ # sort
+ if ti.args.sort:
+ # split with double newlines
+ lines = "\n".join(output_lines)
+ lines = lines.split("\n\n")
+
+ def compare(l1, l2):
+ # if contains multiple lines, just compare first line
+ l1 = l1.split("\n")[0]
+ l2 = l2.split("\n")[0]
+
+ isl1_runline = l1 in ti.run_lines
+ isl2_runline = l2 in ti.run_lines
+
+ if isl1_runline and not isl2_runline:
+ return -1
+ elif not isl1_runline and isl2_runline:
+ return 1
+ else:
+ if l1 < l2:
+ return -1
+ elif l1 > l2:
+ return 1
+ else:
+ return 0
+
+ lines = sorted(lines, key=functools.cmp_to_key(compare))
+ output_lines = "\n\n".join(lines).split("\n")
+
+ # output
if ti.args.gen_unused_prefix_body:
output_lines.extend(
ti.get_checks_for_unused_prefixes(run_list, used_prefixes)
>From 8a61029d48a6148747f69e4d624a8dd6796189f7 Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Wed, 16 Oct 2024 19:56:21 -0400
Subject: [PATCH 2/2] update code and test, using unique
---
.../Inputs/amdgpu_asm_sort_with_comment.s | 3 +
.../amdgpu_asm_sort_with_comment.s.expected | 6 +-
...emove_duplicates.s => amdgpu_asm_unique.s} | 3 +
....expected => amdgpu_asm_unique.s.expected} | 4 +-
..._duplicates.txt => amdgpu_dasm_unique.txt} | 0
...pected => amdgpu_dasm_unique.txt.expected} | 3 +-
.../amdgpu-remove-duplicates.test | 7 --
.../update_mc_test_checks/amdgpu-unique.test | 7 ++
llvm/utils/update_mc_test_checks.py | 85 ++++++++++++-------
9 files changed, 76 insertions(+), 42 deletions(-)
rename llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/{amdgpu_asm_remove_duplicates.s => amdgpu_asm_unique.s} (77%)
rename llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/{amdgpu_asm_remove_duplicates.s.expected => amdgpu_asm_unique.s.expected} (78%)
rename llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/{amdgpu_dasm_remove_duplicates.txt => amdgpu_dasm_unique.txt} (100%)
rename llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/{amdgpu_dasm_remove_duplicates.txt.expected => amdgpu_dasm_unique.txt.expected} (86%)
delete mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
create mode 100644 llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-unique.test
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s
index a1ad81142efd2a..d60b3bda29eda2 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s
@@ -4,3 +4,6 @@ v_bfrev_b32 v5, v1 //This is comment A
v_bfrev_b32 v1, v1
// This is comment B
+
+// This is comment C
+v_bfrev_b32 v2, v1
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected
index 24834d2b65f73d..94b07cd2e35334 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_sort_with_comment.s.expected
@@ -1,9 +1,13 @@
-; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort --version 5
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --sort
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
v_bfrev_b32 v1, v1
// CHECK: v_bfrev_b32_e32 v1, v1 ; encoding: [0x01,0x71,0x02,0x7e]
// This is comment B
+// This is comment C
+v_bfrev_b32 v2, v1
+// CHECK: v_bfrev_b32_e32 v2, v1 ; encoding: [0x01,0x71,0x04,0x7e]
+
v_bfrev_b32 v5, v1 //This is comment A
// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_unique.s
similarity index 77%
rename from llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
rename to llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_unique.s
index 49f02cb5cb89c7..0adf7f0dc215da 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_unique.s
@@ -1,5 +1,8 @@
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+//this is commentA
v_bfrev_b32 v5, v1
v_bfrev_b32 v5, v1
+
+//this is commentB
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_unique.s.expected
similarity index 78%
rename from llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
rename to llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_unique.s.expected
index 57c572887e7eea..c4c2bfd15f33f2 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_remove_duplicates.s.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_unique.s.expected
@@ -1,6 +1,8 @@
-; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --remove-duplicate
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --unique
// RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+//this is commentA
v_bfrev_b32 v5, v1
// CHECK: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
+//this is commentB
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_unique.txt
similarity index 100%
rename from llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt
rename to llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_unique.txt
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_unique.txt.expected
similarity index 86%
rename from llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
rename to llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_unique.txt.expected
index d81f3984696be3..32bddb20628dad 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_unique.txt.expected
@@ -1,6 +1,5 @@
-# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --remove-duplicate
+# NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py UTC_ARGS: --unique
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1100 -disassemble -show-encoding %s 2>&1 | FileCheck -check-prefixes=CHECK %s
0x00,0x00,0x00,0x7e
# CHECK: v_nop ; encoding: [0x00,0x00,0x00,0x7e]
-
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
deleted file mode 100644
index df7d56a460f45e..00000000000000
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-remove-duplicates.test
+++ /dev/null
@@ -1,7 +0,0 @@
-# REQUIRES: amdgpu-registered-target
-## Check that remove duplicate is working
-
-# RUN: cp -f %S/Inputs/amdgpu_asm_remove_duplicates.s %t.s && %update_mc_test_checks --remove-duplicate %t.s
-# RUN: diff -u %S/Inputs/amdgpu_asm_remove_duplicates.s.expected %t.s
-# RUN: cp -f %S/Inputs/amdgpu_dasm_remove_duplicates.txt %t.txt && %update_mc_test_checks --remove-duplicate %t.txt
-# RUN: diff -u %S/Inputs/amdgpu_dasm_remove_duplicates.txt.expected %t.txt
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-unique.test b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-unique.test
new file mode 100644
index 00000000000000..8a5d83462cad73
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/amdgpu-unique.test
@@ -0,0 +1,7 @@
+# REQUIRES: amdgpu-registered-target
+## Check that unique is working
+
+# RUN: cp -f %S/Inputs/amdgpu_asm_unique.s %t.s && %update_mc_test_checks --unique %t.s
+# RUN: diff -u %S/Inputs/amdgpu_asm_unique.s.expected %t.s
+# RUN: cp -f %S/Inputs/amdgpu_dasm_unique.txt %t.txt && %update_mc_test_checks --unique %t.txt
+# RUN: diff -u %S/Inputs/amdgpu_dasm_unique.txt.expected %t.txt
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index 463f3d98093137..dda739cb18171f 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -50,6 +50,8 @@ def isTestLine(input_line, mc_mode):
return False
return True
+def isRunLine(l):
+ return common.RUN_LINE_RE.match(l)
def hasErr(err):
return err and ERROR_RE.search(err) is not None
@@ -120,7 +122,7 @@ def main():
help="Set a default -march for when neither triple nor arch are found in a RUN line",
)
parser.add_argument(
- "--remove-duplicate",
+ "--unique",
action="store_true",
default=False,
help="remove duplicated test line if found",
@@ -319,53 +321,74 @@ def main():
generated_prefixes[input_line] = gen_prefix.rstrip("\n")
# write output
- written_lines = set()
for input_info in ti.iterlines(output_lines):
input_line = input_info.line
if input_line in testlines:
- if ti.args.remove_duplicate:
- if input_line in written_lines:
- common.debug("Duplicated line skipped: ", input_line)
- continue
- else:
- written_lines.add(input_line)
output_lines.append(input_line)
output_lines.append(generated_prefixes[input_line])
elif should_add_line_to_output(input_line, prefix_set, mc_mode):
output_lines.append(input_line)
- elif input_line in ti.run_lines or input_line == "":
- output_lines.append(input_line)
-
- # sort
- if ti.args.sort:
+ if ti.args.unique or ti.args.sort:
# split with double newlines
- lines = "\n".join(output_lines)
- lines = lines.split("\n\n")
+ test_units = "\n".join(output_lines).split("\n\n")
+
+ # select the key line for each test unit
+ test_dic = {}
+ for unit in test_units:
+ lines = unit.split('\n')
+ for l in lines:
+ # if contains multiple lines, use
+ # the first testline or runline as key
+ if isTestLine(l, mc_mode):
+ test_dic[unit] = l
+ break
+ elif isRunLine(l):
+ test_dic[unit] = l
+ break
+ if unit not in test_dic:
+ test_dic[unit] = lines[0]
+
+ # unique
+ if ti.args.unique:
+ new_test_units = []
+ written_lines = set()
+ for unit in test_units:
+ if test_dic[unit] in written_lines:
+ common.debug("Duplicated test skipped: ", unit)
+ continue
+ else:
+ written_lines.add(test_dic[unit])
+ new_test_units.append(unit)
+ test_units = new_test_units
- def compare(l1, l2):
- # if contains multiple lines, just compare first line
- l1 = l1.split("\n")[0]
- l2 = l2.split("\n")[0]
+ # sort
+ if ti.args.sort:
+ def compare(l1, l2):
+ # get key string to be compared
+ l1 = test_dic[l1]
+ l2 = test_dic[l2]
- isl1_runline = l1 in ti.run_lines
- isl2_runline = l2 in ti.run_lines
+ isl1_runline = isRunLine(l1)
+ isl2_runline = isRunLine(l2)
- if isl1_runline and not isl2_runline:
- return -1
- elif not isl1_runline and isl2_runline:
- return 1
- else:
- if l1 < l2:
+ if isl1_runline and not isl2_runline:
return -1
- elif l1 > l2:
+ elif not isl1_runline and isl2_runline:
return 1
else:
- return 0
+ if l1 < l2:
+ return -1
+ elif l1 > l2:
+ return 1
+ else:
+ return 0
+
+ test_units = sorted(test_units, key=functools.cmp_to_key(compare))
- lines = sorted(lines, key=functools.cmp_to_key(compare))
- output_lines = "\n\n".join(lines).split("\n")
+ # join back to be output string
+ output_lines = "\n\n".join(test_units).split("\n")
# output
if ti.args.gen_unused_prefix_body:
More information about the llvm-commits
mailing list