llvm.org GIT mirror llvm / 26df96a
[Util] Add a helper script for converting -print-before-all output into a file based equivelent Simple little utility which takes a opt logfile generated with "opt -print-before-all -print-module-scope -o /dev/null <args> 2&>1", and splits into a series of individual "chunk-X.ll" files. The intended purpose is to help automate one step in failure reduction. The imagined workflow is: New crasher bug reported against clang or other frontend Frontend run with -emit-llvm equivalent and manually confirmed that opt -O2 <emit.ll> crashes Run this splitter script Manually map pass name to invocation command (next on the to automate list) Run bugpoint on last chunk file + manual command I chose to dump every chunk rather than only the last since miscompile debugging frequently requires either manual step by step reduction, or cross feeding IR into different compiler versions. Not an immediate target, but there may be applications. Differential Revision: https://reviews.llvm.org/D63461 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363884 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 2 months ago
1 changed file(s) with 42 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/env python
1 # Given a -print-before-all -print-module-scope log from an opt invocation,
2 # chunk it into a series of individual IR files, one for each pass invocation.
3 # If the log ends with an obvious stack trace, try to split off a separate
4 # "crashinfo.txt" file leaving only the valid input IR in the last chunk.
5 # Files are written to current working directory.
6
7 import sys
8
9 basename = "chunk-"
10 chunk_id = 0
11
12 def print_chunk(lines):
13 global chunk_id
14 global basename
15 fname = basename + str(chunk_id) + ".ll"
16 chunk_id = chunk_id + 1
17 print "writing chunk " + fname + " (" + str(len(lines)) + " lines)"
18 with open(fname, "w") as f:
19 f.writelines(lines)
20
21 is_dump = False
22 cur = []
23 for line in sys.stdin:
24 if line.startswith("*** IR Dump Before ") and len(cur) != 0:
25 print_chunk(cur);
26 cur = []
27 cur.append("; " + line)
28 elif line.startswith("Stack dump:"):
29 print_chunk(cur);
30 cur = []
31 cur.append(line)
32 is_dump = True
33 else:
34 cur.append(line)
35
36 if is_dump:
37 print "writing crashinfo.txt (" + str(len(cur)) + " lines)"
38 with open("crashinfo.txt", "w") as f:
39 f.writelines(cur)
40 else:
41 print_chunk(cur);