[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
Thu Oct 10 14:50:49 PDT 2024


https://github.com/broxigarchen updated https://github.com/llvm/llvm-project/pull/111769

>From e441d182708629605f2d70b238f163798092b174 Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Wed, 9 Oct 2024 18:12:01 -0400
Subject: [PATCH 1/2] added remove dup options

---
 .../Inputs/amdgpu_asm_remove_duplicates.s     |  5 ++++
 .../amdgpu_asm_remove_duplicates.s.expected   |  6 +++++
 .../Inputs/amdgpu_dasm_remove_duplicates.txt  |  5 ++++
 ...amdgpu_dasm_remove_duplicates.txt.expected |  6 +++++
 .../amdgpu-remove-duplicates.test             |  7 +++++
 llvm/utils/update_mc_test_checks.py           | 27 ++++++++++++++-----
 6 files changed, 50 insertions(+), 6 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_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/amdgpu-remove-duplicates.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..368143dd40af5b
--- /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
+// 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_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..0a299156e83ce4
--- /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
+# 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
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/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index f9f8cfdea418d0..0e92fefaeeefd8 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -118,6 +118,12 @@ 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=argparse.BooleanOptionalAction,
+        help="remove duplicated test line if found",
+    )
     parser.add_argument("tests", nargs="+")
     initial_args = common.parse_commandline_args(parser)
 
@@ -196,6 +202,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 +243,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 +308,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)

>From 9effb5ae4168e986d9f07334061b81895733f4a2 Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Thu, 10 Oct 2024 17:50:33 -0400
Subject: [PATCH 2/2] add a sort option

---
 .../amdgpu_asm_remove_duplicates.s.expected   |  2 +-
 .../Inputs/amdgpu_dasm.txt.expected           |  2 +-
 ...amdgpu_dasm_remove_duplicates.txt.expected |  2 +-
 .../Inputs/amdgpu_multirun_dasm.txt.expected  |  2 +-
 llvm/utils/UpdateTestChecks/common.py         |  2 +-
 llvm/utils/update_mc_test_checks.py           | 42 ++++++++++++++++++-
 6 files changed, 45 insertions(+), 7 deletions(-)

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
index 368143dd40af5b..57c572887e7eea 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_remove_duplicates.s.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 UTC_ARGS: --remove-duplicate
 // RUN: llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
 
 v_bfrev_b32 v5, v1
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.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_dasm_remove_duplicates.txt.expected
index 0a299156e83ce4..d81f3984696be3 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_remove_duplicates.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 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
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/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 0e92fefaeeefd8..8910e11d774fa3 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,12 +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=argparse.BooleanOptionalAction,
+        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, this option could be dangerous as it wipe"
+        "out lines that are not testline or runlines",
+    )
     parser.add_argument("tests", nargs="+")
     initial_args = common.parse_commandline_args(parser)
 
@@ -330,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)



More information about the llvm-commits mailing list