Mercurial > hg > CbC > CbC_llvm
comparison utils/schedcover.py @ 171:66f3bfe93da9
git version 2c4ca6832fa6b306ee6a7010bfb80a3f2596f824
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:07:02 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
150:1d019706d866 | 171:66f3bfe93da9 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 # This creates a CSV file from the output of the debug output of subtarget: | |
4 # llvm-tblgen --gen-subtarget --debug-only=subtarget-emitter | |
5 # With thanks to Dave Estes for mentioning the idea at 2014 LLVM Developers' Meeting | |
6 | |
7 import os; | |
8 import sys; | |
9 import re; | |
10 import operator; | |
11 | |
12 table = {} | |
13 models = set() | |
14 filt = None | |
15 | |
16 def add(instr, model, resource=None): | |
17 global table, models | |
18 | |
19 entry = table.setdefault(instr, dict()) | |
20 entry[model] = resource | |
21 models.add(model) | |
22 | |
23 def filter_model(m): | |
24 global filt | |
25 if m and filt: | |
26 return filt.search(m) != None | |
27 else: | |
28 return True | |
29 | |
30 | |
31 def display(): | |
32 global table, models | |
33 | |
34 # remove default and itinerary so we can control their sort order to make | |
35 # them first | |
36 models.discard("default") | |
37 models.discard("itinerary") | |
38 | |
39 ordered_table = sorted(table.items(), key=operator.itemgetter(0)) | |
40 ordered_models = ["itinerary", "default"] | |
41 ordered_models.extend(sorted(models)) | |
42 ordered_models = [m for m in ordered_models if filter_model(m)] | |
43 | |
44 # print header | |
45 sys.stdout.write("instruction") | |
46 for model in ordered_models: | |
47 sys.stdout.write(", {}".format(model)) | |
48 sys.stdout.write(os.linesep) | |
49 | |
50 for (instr, mapping) in ordered_table: | |
51 sys.stdout.write(instr) | |
52 for model in ordered_models: | |
53 if model in mapping and mapping[model] is not None: | |
54 sys.stdout.write(", {}".format(mapping[model])) | |
55 else: | |
56 sys.stdout.write(", ") | |
57 sys.stdout.write(os.linesep) | |
58 | |
59 | |
60 def machineModelCover(path): | |
61 # The interesting bits | |
62 re_sched_default = re.compile("SchedRW machine model for ([^ ]*) (.*)\n"); | |
63 re_sched_no_default = re.compile("No machine model for ([^ ]*)\n"); | |
64 re_sched_spec = re.compile("InstRW on ([^ ]*) for ([^ ]*) (.*)\n"); | |
65 re_sched_no_spec = re.compile("No machine model for ([^ ]*) on processor (.*)\n"); | |
66 re_sched_itin = re.compile("Itinerary for ([^ ]*): ([^ ]*)\n") | |
67 | |
68 # scan the file | |
69 with open(path, 'r') as f: | |
70 for line in f.readlines(): | |
71 match = re_sched_default.match(line) | |
72 if match: add(match.group(1), "default", match.group(2)) | |
73 match = re_sched_no_default.match(line) | |
74 if match: add(match.group(1), "default") | |
75 match = re_sched_spec.match(line) | |
76 if match: add(match.group(2), match.group(1), match.group(3)) | |
77 match = re_sched_no_spec.match(line) | |
78 if match: add(match.group(1), match.group(2)) | |
79 match = re_sched_itin.match(line) | |
80 if match: add(match.group(1), "itinerary", match.group(2)) | |
81 | |
82 display() | |
83 | |
84 if len(sys.argv) > 2: | |
85 filt = re.compile(sys.argv[2], re.IGNORECASE) | |
86 machineModelCover(sys.argv[1]) |