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]
20 def print_chunk(lines
, prefix
, pass_name
):
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
:
30 for line
in sys
.stdin
:
31 if line
.startswith("*** IR Dump Before "):
33 print_chunk(cur
, "before", pass_name
)
35 cur
.append("; " + line
)
36 pass_name
= get_pass_name(line
, "Before")
37 elif line
.startswith("*** IR Dump After "):
39 print_chunk(cur
, "after", pass_name
)
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
)
52 print("writing crashinfo.txt (" + str(len(cur
)) + " lines)")
53 with
open("crashinfo.txt", "w") as f
:
56 print_chunk(cur
, "last", pass_name
)