[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / llvm / utils / add_argument_names.py
blob2860dd4b90bcb5bce70654d7137485a929ceeb0f
1 #!/usr/bin/env python3
2 import re, sys
5 def fix_string(s):
6 TYPE = re.compile(
7 '\s*(i[0-9]+|float|double|x86_fp80|fp128|ppc_fp128|\[\[.*?\]\]|\[2 x \[\[[A-Z_0-9]+\]\]\]|<.*?>|{.*?}|\[[0-9]+ x .*?\]|%["a-z:A-Z0-9._]+({{.*?}})?|%{{.*?}}|{{.*?}}|\[\[.*?\]\])(\s*(\*|addrspace\(.*?\)|dereferenceable\(.*?\)|byval\(.*?\)|sret|zeroext|inreg|returned|signext|nocapture|align \d+|swiftself|swifterror|readonly|noalias|inalloca|nocapture))*\s*'
10 counter = 0
11 if "i32{{.*}}" in s:
12 counter = 1
14 at_pos = s.find("@")
15 if at_pos == -1:
16 at_pos = 0
18 annoying_pos = s.find("{{[^(]+}}")
19 if annoying_pos != -1:
20 at_pos = annoying_pos + 9
22 paren_pos = s.find("(", at_pos)
23 if paren_pos == -1:
24 return s
26 res = s[: paren_pos + 1]
27 s = s[paren_pos + 1 :]
29 m = TYPE.match(s)
30 while m:
31 res += m.group()
32 s = s[m.end() :]
33 if s.startswith(",") or s.startswith(")"):
34 res += f" %{counter}"
35 counter += 1
37 next_arg = s.find(",")
38 if next_arg == -1:
39 break
41 res += s[: next_arg + 1]
42 s = s[next_arg + 1 :]
43 m = TYPE.match(s)
45 return res + s
48 def process_file(contents):
49 PREFIX = re.compile(r"check-prefix(es)?(=|\s+)([a-zA-Z0-9,]+)")
50 check_prefixes = ["CHECK"]
51 result = ""
52 for line in contents.split("\n"):
53 if "FileCheck" in line:
54 m = PREFIX.search(line)
55 if m:
56 check_prefixes.extend(m.group(3).split(","))
58 found_check = False
59 for prefix in check_prefixes:
60 if prefix in line:
61 found_check = True
62 break
64 if not found_check or "define" not in line:
65 result += line + "\n"
66 continue
68 # We have a check for a function definition. Number the args.
69 line = fix_string(line)
70 result += line + "\n"
71 return result
74 def main():
75 print(f"Processing {sys.argv[1]}")
76 f = open(sys.argv[1])
77 content = f.read()
78 f.close()
80 content = process_file(content)
82 f = open(sys.argv[1], "w")
83 f.write(content)
84 f.close()
87 if __name__ == "__main__":
88 main()