Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / chunk-print-before-all.py
blobfe0eaaea1c20dae100e142621e51f93a52150476
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]
21 def print_chunk(lines, prefix, pass_name):
22 global chunk_id
23 fname = str(chunk_id).zfill(4) + "-" + prefix + "-" + pass_name + ".ll"
24 chunk_id = chunk_id + 1
25 print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")
26 with open(fname, "w") as f:
27 f.writelines(lines)
30 is_dump = False
31 cur = []
32 for line in sys.stdin:
33 if line.startswith("*** IR Dump Before "):
34 if len(cur) != 0:
35 print_chunk(cur, "before", pass_name)
36 cur = []
37 cur.append("; " + line)
38 pass_name = get_pass_name(line, "Before")
39 elif line.startswith("*** IR Dump After "):
40 if len(cur) != 0:
41 print_chunk(cur, "after", pass_name)
42 cur = []
43 cur.append("; " + line)
44 pass_name = get_pass_name(line, "After")
45 elif line.startswith("Stack dump:"):
46 print_chunk(cur, "crash", pass_name)
47 cur = []
48 cur.append(line)
49 is_dump = True
50 else:
51 cur.append(line)
53 if is_dump:
54 print("writing crashinfo.txt (" + str(len(cur)) + " lines)")
55 with open("crashinfo.txt", "w") as f:
56 f.writelines(cur)
57 else:
58 print_chunk(cur, "last", pass_name)