annotate llvm/utils/chunk-print-before-all.py @ 220:42394fc6a535

Added tag llvm12 for changeset 0572611fdcc8
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:13:43 +0900
parents 0572611fdcc8
children 1f2b6ac9f198
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 # Given a -print-before-all -print-module-scope log from an opt invocation,
anatofuz
parents:
diff changeset
3 # chunk it into a series of individual IR files, one for each pass invocation.
anatofuz
parents:
diff changeset
4 # If the log ends with an obvious stack trace, try to split off a separate
anatofuz
parents:
diff changeset
5 # "crashinfo.txt" file leaving only the valid input IR in the last chunk.
anatofuz
parents:
diff changeset
6 # Files are written to current working directory.
anatofuz
parents:
diff changeset
7
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
8 from __future__ import print_function
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
9
150
anatofuz
parents:
diff changeset
10 import sys
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 basename = "chunk-"
anatofuz
parents:
diff changeset
13 chunk_id = 0
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 def print_chunk(lines):
anatofuz
parents:
diff changeset
16 global chunk_id
anatofuz
parents:
diff changeset
17 global basename
anatofuz
parents:
diff changeset
18 fname = basename + str(chunk_id) + ".ll"
anatofuz
parents:
diff changeset
19 chunk_id = chunk_id + 1
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20 print("writing chunk " + fname + " (" + str(len(lines)) + " lines)")
150
anatofuz
parents:
diff changeset
21 with open(fname, "w") as f:
anatofuz
parents:
diff changeset
22 f.writelines(lines)
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 is_dump = False
anatofuz
parents:
diff changeset
25 cur = []
anatofuz
parents:
diff changeset
26 for line in sys.stdin:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
27 if line.startswith("*** IR Dump Before "):
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 if len(cur) != 0:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 print_chunk(cur);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
30 cur = []
150
anatofuz
parents:
diff changeset
31 cur.append("; " + line)
anatofuz
parents:
diff changeset
32 elif line.startswith("Stack dump:"):
anatofuz
parents:
diff changeset
33 print_chunk(cur);
anatofuz
parents:
diff changeset
34 cur = []
anatofuz
parents:
diff changeset
35 cur.append(line)
anatofuz
parents:
diff changeset
36 is_dump = True
anatofuz
parents:
diff changeset
37 else:
anatofuz
parents:
diff changeset
38 cur.append(line)
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 if is_dump:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
41 print("writing crashinfo.txt (" + str(len(cur)) + " lines)")
150
anatofuz
parents:
diff changeset
42 with open("crashinfo.txt", "w") as f:
anatofuz
parents:
diff changeset
43 f.writelines(cur)
anatofuz
parents:
diff changeset
44 else:
anatofuz
parents:
diff changeset
45 print_chunk(cur);