llvm.org GIT mirror llvm / e6e5fbb
McARM: Write a silly Python script to compute some hard coded info from the generated ARM match table, which is substantially more efficient than dealing with tblgen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123252 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 8 years ago
1 changed file(s) with 61 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/env python
1
2 def analyze_match_table(path):
3 # Extract the instruction table.
4 data = open(path).read()
5 start = data.index("static const MatchEntry MatchTable")
6 end = data.index("\n};\n", start)
7 lines = data[start:end].split("\n")[1:]
8
9 # Parse the instructions.
10 insns = []
11 for ln in lines:
12 ln = ln.split("{", 1)[1]
13 ln = ln.rsplit("}", 1)[0]
14 a,bc = ln.split("{", 1)
15 b,c = bc.split("}", 1)
16 code, string, converter, _ = [s.strip()
17 for s in a.split(",")]
18 items = [s.strip() for s in b.split(",")]
19 _,features = [s.strip() for s in c.split(",")]
20 assert string[0] == string[-1] == '"'
21 string = string[1:-1]
22 insns.append((code,string,converter,items,features))
23
24 # For every mnemonic, compute whether or not it can have a carry setting
25 # operand and whether or not it can have a predication code.
26 mnemonic_flags = {}
27 for insn in insns:
28 mnemonic = insn[1]
29 items = insn[3]
30 flags = mnemonic_flags[mnemonic] = mnemonic_flags.get(mnemonic, set())
31 flags.update(items)
32
33 mnemonics = set(mnemonic_flags)
34 ccout_mnemonics = set(m for m in mnemonics
35 if 'MCK_CCOut' in mnemonic_flags[m])
36 condcode_mnemonics = set(m for m in mnemonics
37 if 'MCK_CondCode' in mnemonic_flags[m])
38 noncondcode_mnemonics = mnemonics - condcode_mnemonics
39 print ' || '.join('Mnemonic == "%s"' % m
40 for m in ccout_mnemonics)
41 print ' || '.join('Mnemonic == "%s"' % m
42 for m in noncondcode_mnemonics)
43
44 def main():
45 import sys
46 if len(sys.argv) == 1:
47 import os
48 from lit.Util import capture
49 llvm_obj_root = capture(["llvm-config", "--obj-root"])
50 file = os.path.join(llvm_obj_root,
51 "lib/Target/ARM/ARMGenAsmMatcher.inc")
52 elif len(sys.argv) == 2:
53 file = sys.argv[1]
54 else:
55 raise NotImplementedError
56
57 analyze_match_table(file)
58
59 if __name__ == '__main__':
60 main()