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.
13 pass_regex
= re
.compile(r
"\(([\w-]+)\)")
15 # This function gets the pass name from the following line:
16 # *** IR Dump Before/After PASS_NAME... ***
17 def get_pass_name(line
, prefix
):
18 # avoid accidentally parsing function name in e.g.
19 # "*** IR Dump Before InlinerPass on (foo) ***"
20 line
= line
.split(" on ")[0]
21 non_pretty_pass_name
= pass_regex
.search(line
)
22 # machine function pass names can contain spaces,
23 # but have a CLI friendly name also, e.g.:
24 # "*** IR Dump Before Stack Frame Layout Analysis (stack-frame-layout) ***"
25 if non_pretty_pass_name
:
26 return non_pretty_pass_name
.group(1)
27 short_line
= line
[line
.find(prefix
) + len(prefix
) + 1 :]
28 return re
.split(" |<", short_line
)[0]
31 def print_chunk(lines
, prefix
, pass_name
):
33 fname
= str(chunk_id
).zfill(4) + "-" + prefix
+ "-" + pass_name
+ ".ll"
34 chunk_id
= chunk_id
+ 1
35 print("writing chunk " + fname
+ " (" + str(len(lines
)) + " lines)")
36 with
open(fname
, "w") as f
:
42 for line
in sys
.stdin
:
43 if "*** IR Dump Before " in line
:
45 print_chunk(cur
, "before", pass_name
)
47 cur
.append("; " + line
)
48 pass_name
= get_pass_name(line
, "Before")
49 elif "*** IR Dump After " in line
:
51 print_chunk(cur
, "after", pass_name
)
53 cur
.append("; " + line
)
54 pass_name
= get_pass_name(line
, "After")
55 elif line
.startswith("Stack dump:"):
56 print_chunk(cur
, "crash", pass_name
)
64 print("writing crashinfo.txt (" + str(len(cur
)) + " lines)")
65 with
open("crashinfo.txt", "w") as f
:
68 print_chunk(cur
, "last", pass_name
)