[InstCombine] Signed saturation patterns
[llvm-core.git] / utils / Target / ARM / analyze-match-table.py
blobd4e158d9e1d80347b47db044bcb7dbe017c88cd6
1 #!/usr/bin/env python
3 from __future__ import print_function
5 def analyze_match_table(path):
6 # Extract the instruction table.
7 data = open(path).read()
8 start = data.index("static const MatchEntry MatchTable")
9 end = data.index("\n};\n", start)
10 lines = data[start:end].split("\n")[1:]
12 # Parse the instructions.
13 insns = []
14 for ln in lines:
15 ln = ln.split("{", 1)[1]
16 ln = ln.rsplit("}", 1)[0]
17 a,bc = ln.split("{", 1)
18 b,c = bc.split("}", 1)
19 code, string, converter, _ = [s.strip()
20 for s in a.split(",")]
21 items = [s.strip() for s in b.split(",")]
22 _,features = [s.strip() for s in c.split(",")]
23 assert string[0] == string[-1] == '"'
24 string = string[1:-1]
25 insns.append((code,string,converter,items,features))
27 # For every mnemonic, compute whether or not it can have a carry setting
28 # operand and whether or not it can have a predication code.
29 mnemonic_flags = {}
30 for insn in insns:
31 mnemonic = insn[1]
32 items = insn[3]
33 flags = mnemonic_flags[mnemonic] = mnemonic_flags.get(mnemonic, set())
34 flags.update(items)
36 mnemonics = set(mnemonic_flags)
37 ccout_mnemonics = set(m for m in mnemonics
38 if 'MCK_CCOut' in mnemonic_flags[m])
39 condcode_mnemonics = set(m for m in mnemonics
40 if 'MCK_CondCode' in mnemonic_flags[m])
41 noncondcode_mnemonics = mnemonics - condcode_mnemonics
42 print(' || '.join('Mnemonic == "%s"' % m
43 for m in ccout_mnemonics))
44 print(' || '.join('Mnemonic == "%s"' % m
45 for m in noncondcode_mnemonics))
47 def main():
48 import sys
49 if len(sys.argv) == 1:
50 import os
51 from lit.Util import capture
52 llvm_obj_root = capture(["llvm-config", "--obj-root"])
53 file = os.path.join(llvm_obj_root,
54 "lib/Target/ARM/ARMGenAsmMatcher.inc")
55 elif len(sys.argv) == 2:
56 file = sys.argv[1]
57 else:
58 raise NotImplementedError
60 analyze_match_table(file)
62 if __name__ == '__main__':
63 main()