annotate llvm/utils/chunk-print-before-all.py @ 252:1f2b6ac9f198 llvm-original

LLVM16-1
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 18 Aug 2023 09:04:13 +0900
parents 0572611fdcc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 #!/usr/bin/env python
anatofuz
parents:
diff changeset
2
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
3 # Given a -print-before-all and/or -print-after-all -print-module-scope log from
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
4 # an opt invocation, chunk it into a series of individual IR files, one for each
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
5 # pass invocation. If the log ends with an obvious stack trace, try to split off
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
6 # a separate "crashinfo.txt" file leaving only the valid input IR in the last
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
7 # chunk. Files are written to current working directory.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
8
150
anatofuz
parents:
diff changeset
9 import sys
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
10 import re
150
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 chunk_id = 0
anatofuz
parents:
diff changeset
13
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
14 # This function gets the pass name from the following line:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
15 # *** IR Dump Before/After PASS_NAME... ***
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
16 def get_pass_name(line, prefix):
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
17 short_line = line[line.find(prefix) + len(prefix) + 1 :]
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
18 return re.split(" |<", short_line)[0]
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
19
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
20
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
21 def print_chunk(lines, prefix, pass_name):
150
anatofuz
parents:
diff changeset
22 global chunk_id
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
23 fname = str(chunk_id).zfill(4) + "-" + prefix + "-" + pass_name + ".ll"
150
anatofuz
parents:
diff changeset
24 chunk_id = chunk_id + 1
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
25 print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")
150
anatofuz
parents:
diff changeset
26 with open(fname, "w") as f:
anatofuz
parents:
diff changeset
27 f.writelines(lines)
anatofuz
parents:
diff changeset
28
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
29
150
anatofuz
parents:
diff changeset
30 is_dump = False
anatofuz
parents:
diff changeset
31 cur = []
anatofuz
parents:
diff changeset
32 for line in sys.stdin:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
33 if line.startswith("*** IR Dump Before "):
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
34 if len(cur) != 0:
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
35 print_chunk(cur, "before", pass_name)
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
36 cur = []
150
anatofuz
parents:
diff changeset
37 cur.append("; " + line)
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
38 pass_name = get_pass_name(line, "Before")
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
39 elif line.startswith("*** IR Dump After "):
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
40 if len(cur) != 0:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
41 print_chunk(cur, "after", pass_name)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
42 cur = []
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
43 cur.append("; " + line)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
44 pass_name = get_pass_name(line, "After")
150
anatofuz
parents:
diff changeset
45 elif line.startswith("Stack dump:"):
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
46 print_chunk(cur, "crash", pass_name)
150
anatofuz
parents:
diff changeset
47 cur = []
anatofuz
parents:
diff changeset
48 cur.append(line)
anatofuz
parents:
diff changeset
49 is_dump = True
anatofuz
parents:
diff changeset
50 else:
anatofuz
parents:
diff changeset
51 cur.append(line)
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 if is_dump:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
54 print("writing crashinfo.txt (" + str(len(cur)) + " lines)")
150
anatofuz
parents:
diff changeset
55 with open("crashinfo.txt", "w") as f:
anatofuz
parents:
diff changeset
56 f.writelines(cur)
anatofuz
parents:
diff changeset
57 else:
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
58 print_chunk(cur, "last", pass_name)