[RISCV] Refactor predicates for rvv intrinsic patterns.
[llvm-project.git] / llvm / utils / chunk-print-before-all.py
blobb5756c59c27191b64e283e3f56ed89ecff5c92db
1 #!/usr/bin/env python
3 # Given a -print-before-all and/or -print-after-all -print-module-scope log from
4 # an opt invocation, chunk it into a series of individual IR files, one for each
5 # pass invocation. If the log ends with an obvious stack trace, try to split off
6 # a separate "crashinfo.txt" file leaving only the valid input IR in the last
7 # chunk. Files are written to current working directory.
9 import sys
10 import re
12 chunk_id = 0
14 # This function gets the pass name from the following line:
15 # *** IR Dump Before/After PASS_NAME... ***
16 def get_pass_name(line, prefix):
17 short_line = line[line.find(prefix) + len(prefix) + 1:]
18 return re.split(' |<', short_line)[0]
20 def print_chunk(lines, prefix, pass_name):
21 global chunk_id
22 fname = str(chunk_id).zfill(4) + "-" + prefix + "-" + pass_name + ".ll"
23 chunk_id = chunk_id + 1
24 print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")
25 with open(fname, "w") as f:
26 f.writelines(lines)
28 is_dump = False
29 cur = []
30 for line in sys.stdin:
31 if line.startswith("*** IR Dump Before "):
32 if len(cur) != 0:
33 print_chunk(cur, "before", pass_name)
34 cur = []
35 cur.append("; " + line)
36 pass_name = get_pass_name(line, "Before")
37 elif line.startswith("*** IR Dump After "):
38 if len(cur) != 0:
39 print_chunk(cur, "after", pass_name)
40 cur = []
41 cur.append("; " + line)
42 pass_name = get_pass_name(line, "After")
43 elif line.startswith("Stack dump:"):
44 print_chunk(cur, "crash", pass_name)
45 cur = []
46 cur.append(line)
47 is_dump = True
48 else:
49 cur.append(line)
51 if is_dump:
52 print("writing crashinfo.txt (" + str(len(cur)) + " lines)")
53 with open("crashinfo.txt", "w") as f:
54 f.writelines(cur)
55 else:
56 print_chunk(cur, "last", pass_name)