[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / utils / schedcover.py
blobcaa73b6d6a7478c9e120870a24184d7cc8376d99
1 #!/usr/bin/env 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
17 def add(instr, model, resource=None):
18 global table, models
20 entry = table.setdefault(instr, dict())
21 entry[model] = resource
22 models.add(model)
25 def filter_model(m):
26 global filt
27 if m and filt:
28 return filt.search(m) is not None
29 else:
30 return True
33 def display():
34 global table, models
36 # remove default and itinerary so we can control their sort order to make
37 # them first
38 models.discard("default")
39 models.discard("itinerary")
41 ordered_table = sorted(table.items(), key=operator.itemgetter(0))
42 ordered_models = ["itinerary", "default"]
43 ordered_models.extend(sorted(models))
44 ordered_models = [m for m in ordered_models if filter_model(m)]
46 # print header
47 sys.stdout.write("instruction")
48 for model in ordered_models:
49 sys.stdout.write(", {}".format(model))
50 sys.stdout.write(os.linesep)
52 for (instr, mapping) in ordered_table:
53 sys.stdout.write(instr)
54 for model in ordered_models:
55 if model in mapping and mapping[model] is not None:
56 sys.stdout.write(", {}".format(mapping[model]))
57 else:
58 sys.stdout.write(", ")
59 sys.stdout.write(os.linesep)
62 def machineModelCover(path):
63 # The interesting bits
64 re_sched_default = re.compile("SchedRW machine model for ([^ ]*) (.*)\n")
65 re_sched_no_default = re.compile("No machine model for ([^ ]*)\n")
66 re_sched_spec = re.compile("InstRW on ([^ ]*) for ([^ ]*) (.*)\n")
67 re_sched_no_spec = re.compile("No machine model for ([^ ]*) on processor (.*)\n")
68 re_sched_itin = re.compile("Itinerary for ([^ ]*): ([^ ]*)\n")
70 # scan the file
71 with open(path, "r") as f:
72 for line in f.readlines():
73 match = re_sched_default.match(line)
74 if match:
75 add(match.group(1), "default", match.group(2))
76 match = re_sched_no_default.match(line)
77 if match:
78 add(match.group(1), "default")
79 match = re_sched_spec.match(line)
80 if match:
81 add(match.group(2), match.group(1), match.group(3))
82 match = re_sched_no_spec.match(line)
83 if match:
84 add(match.group(1), match.group(2))
85 match = re_sched_itin.match(line)
86 if match:
87 add(match.group(1), "itinerary", match.group(2))
89 display()
92 if len(sys.argv) > 2:
93 filt = re.compile(sys.argv[2], re.IGNORECASE)
94 machineModelCover(sys.argv[1])