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.
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
):
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
:
32 for line
in sys
.stdin
:
33 if line
.startswith("*** IR Dump Before "):
35 print_chunk(cur
, "before", pass_name
)
37 cur
.append("; " + line
)
38 pass_name
= get_pass_name(line
, "Before")
39 elif line
.startswith("*** IR Dump After "):
41 print_chunk(cur
, "after", pass_name
)
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
)
54 print("writing crashinfo.txt (" + str(len(cur
)) + " lines)")
55 with
open("crashinfo.txt", "w") as f
:
58 print_chunk(cur
, "last", pass_name
)