gn build: Merge r372706
[llvm-complete.git] / utils / schedcover.py
blob9532f1b554bd9726a0b37e47ad618841731652b2
1 #!/usr/bin/python
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
7 import os;
8 import sys;
9 import re;
10 import operator;
12 table = {}
13 models = set()
14 filt = None
16 def add(instr, model, resource=None):
17 global table, models
19 entry = table.setdefault(instr, dict())
20 entry[model] = resource
21 models.add(model)
23 def filter_model(m):
24 global filt
25 if m and filt:
26 return filt.search(m) != None
27 else:
28 return True
31 def display():
32 global table, models
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")
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)]
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)
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)
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")
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))
82 display()
84 if len(sys.argv) > 2:
85 filt = re.compile(sys.argv[2], re.IGNORECASE)
86 machineModelCover(sys.argv[1])