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
17 def add(instr
, model
, resource
=None):
20 entry
= table
.setdefault(instr
, dict())
21 entry
[model
] = resource
28 return filt
.search(m
) != None
36 # remove default and itinerary so we can control their sort order to make
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
)]
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
]))
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")
71 with
open(path
, "r") as f
:
72 for line
in f
.readlines():
73 match
= re_sched_default
.match(line
)
75 add(match
.group(1), "default", match
.group(2))
76 match
= re_sched_no_default
.match(line
)
78 add(match
.group(1), "default")
79 match
= re_sched_spec
.match(line
)
81 add(match
.group(2), match
.group(1), match
.group(3))
82 match
= re_sched_no_spec
.match(line
)
84 add(match
.group(1), match
.group(2))
85 match
= re_sched_itin
.match(line
)
87 add(match
.group(1), "itinerary", match
.group(2))
93 filt
= re
.compile(sys
.argv
[2], re
.IGNORECASE
)
94 machineModelCover(sys
.argv
[1])