xref: /llvm-project/llvm/tools/opt-viewer/extract-reproducers.py (revision b71edfaa4ec3c998aadb35255ce2f60bba2940b0)
1#!/usr/bin/env python
2
3desc = """
4A script to extract ConstraintElimination's reproducer remarks. The extracted
5modules are written as textual LLVM IR to files named reproducerXXXX.ll in the
6current directory.
7"""
8
9import optrecord
10import argparse
11
12if __name__ == "__main__":
13    parser = argparse.ArgumentParser(description=desc)
14    parser.add_argument(
15        "yaml_dirs_or_files",
16        nargs="+",
17        help="List of optimization record files or directories searched "
18        "for optimization record files.",
19    )
20
21    args = parser.parse_args()
22
23    print_progress = False
24    jobs = 1
25
26    files = optrecord.find_opt_files(*args.yaml_dirs_or_files)
27    if not files:
28        parser.error("No *.opt.yaml files found")
29        sys.exit(1)
30
31    all_remarks, file_remarks, _ = optrecord.gather_results(files, jobs, True)
32
33    i = 0
34    for r in all_remarks:
35        if r[1] != "constraint-elimination" or r[2] != "Reproducer":
36            continue
37        with open("reproducer{}.ll".format(i), "wt") as f:
38            f.write(r[7][1][0][1])
39        i += 1
40