[RISCV] Eliminate dead li after emitting VSETVLIs (#65934)
[llvm-project.git] / llvm / utils / update_any_test_checks.py
blob2ad852d710c07af885bafcd07ff4a7025d504423
1 #!/usr/bin/env python3
3 """Dispatch to update_*_test_checks.py scripts automatically in bulk
5 Given a list of test files, this script will invoke the correct
6 update_test_checks-style script, skipping any tests which have not previously
7 had assertions autogenerated.
8 """
10 from __future__ import print_function
12 import argparse
13 import os
14 import re
15 import subprocess
16 import sys
17 from concurrent.futures import ThreadPoolExecutor
19 RE_ASSERTIONS = re.compile(
20 r"NOTE: Assertions have been autogenerated by ([^\s]+)( UTC_ARGS:.*)?$"
24 def find_utc_tool(search_path, utc_name):
25 """
26 Return the path to the given UTC tool in the search path, or None if not
27 found.
28 """
29 for path in search_path:
30 candidate = os.path.join(path, utc_name)
31 if os.path.isfile(candidate):
32 return candidate
33 return None
36 def run_utc_tool(utc_name, utc_tool, testname):
37 result = subprocess.run(
38 [utc_tool, testname], stdout=subprocess.PIPE, stderr=subprocess.PIPE
40 return (result.returncode, result.stdout, result.stderr)
43 def main():
44 from argparse import RawTextHelpFormatter
46 parser = argparse.ArgumentParser(
47 description=__doc__, formatter_class=RawTextHelpFormatter
49 parser.add_argument(
50 "--jobs",
51 "-j",
52 default=1,
53 type=int,
54 help="Run the given number of jobs in parallel",
56 parser.add_argument(
57 "--utc-dir",
58 nargs="*",
59 help="Additional directories to scan for update_*_test_checks scripts",
61 parser.add_argument("tests", nargs="+")
62 config = parser.parse_args()
64 if config.utc_dir:
65 utc_search_path = config.utc_dir[:]
66 else:
67 utc_search_path = []
68 script_name = os.path.abspath(__file__)
69 utc_search_path.append(os.path.join(os.path.dirname(script_name), os.path.pardir))
71 not_autogenerated = []
72 utc_tools = {}
73 have_error = False
75 with ThreadPoolExecutor(max_workers=config.jobs) as executor:
76 jobs = []
78 for testname in config.tests:
79 with open(testname, "r") as f:
80 header = f.readline().strip()
81 m = RE_ASSERTIONS.search(header)
82 if m is None:
83 not_autogenerated.append(testname)
84 continue
86 utc_name = m.group(1)
87 if utc_name not in utc_tools:
88 utc_tools[utc_name] = find_utc_tool(utc_search_path, utc_name)
89 if not utc_tools[utc_name]:
90 print(
91 f"{utc_name}: not found (used in {testname})",
92 file=sys.stderr,
94 have_error = True
95 continue
97 future = executor.submit(
98 run_utc_tool, utc_name, utc_tools[utc_name], testname
100 jobs.append((testname, future))
102 for testname, future in jobs:
103 return_code, stdout, stderr = future.result()
105 print(f"Update {testname}")
106 stdout = stdout.decode(errors="replace")
107 if stdout:
108 print(stdout, end="")
109 if not stdout.endswith("\n"):
110 print()
112 stderr = stderr.decode(errors="replace")
113 if stderr:
114 print(stderr, end="")
115 if not stderr.endswith("\n"):
116 print()
117 if return_code != 0:
118 print(f"Return code: {return_code}")
119 have_error = True
121 if have_error:
122 sys.exit(1)
124 if not_autogenerated:
125 print("Tests without autogenerated assertions:")
126 for testname in not_autogenerated:
127 print(f" {testname}")
130 if __name__ == "__main__":
131 main()