[AMDGPU] prevent shrinking udiv/urem if either operand is in (SignedMax,UnsignedMax...
[llvm-project.git] / llvm / utils / Target / ARM / analyze-match-table.py
blobc14b1a19fe39ee34e350142709cdaae78f4c93fe
1 #!/usr/bin/env python
3 from __future__ import print_function
6 def analyze_match_table(path):
7 # Extract the instruction table.
8 data = open(path).read()
9 start = data.index("static const MatchEntry MatchTable")
10 end = data.index("\n};\n", start)
11 lines = data[start:end].split("\n")[1:]
13 # Parse the instructions.
14 insns = []
15 for ln in lines:
16 ln = ln.split("{", 1)[1]
17 ln = ln.rsplit("}", 1)[0]
18 a, bc = ln.split("{", 1)
19 b, c = bc.split("}", 1)
20 code, string, converter, _ = [s.strip() 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 if "MCK_CCOut" in mnemonic_flags[m])
38 condcode_mnemonics = set(
39 m for m in mnemonics if "MCK_CondCode" in mnemonic_flags[m]
41 noncondcode_mnemonics = mnemonics - condcode_mnemonics
42 print(" || ".join('Mnemonic == "%s"' % m for m in ccout_mnemonics))
43 print(" || ".join('Mnemonic == "%s"' % m for m in noncondcode_mnemonics))
46 def main():
47 import sys
49 if len(sys.argv) == 1:
50 import os
51 from lit.Util import capture
53 llvm_obj_root = capture(["llvm-config", "--obj-root"])
54 file = os.path.join(llvm_obj_root, "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)
63 if __name__ == "__main__":
64 main()