[NFC][Py Reformat] Reformat python files in llvm
[llvm-project.git] / llvm / utils / UpdateTestChecks / isel.py
blobbdb68e5815a33d53ddc9976caaa0863dc98c5ce3
1 import re
2 from . import common
3 import sys
5 if sys.version_info[0] > 2:
7 class string:
8 expandtabs = str.expandtabs
10 else:
11 import string
13 # Support of isel debug checks
14 # RegEx: this is where the magic happens.
16 ##### iSel parser
18 # TODO: add function prefix
19 ISEL_FUNCTION_DEFAULT_RE = re.compile(
20 r"Selected[\s]*selection[\s]*DAG:[\s]*%bb.0[\s]*\'(?P<func>.*?):[^\']*\'*\n"
21 r"(?P<body>.*?)\n"
22 r"Total[\s]*amount[\s]*of[\s]*phi[\s]*nodes[\s]*to[\s]*update:[\s]*[0-9]+",
23 flags=(re.M | re.S),
27 def scrub_isel_default(isel, args):
28 # Scrub runs of whitespace out of the iSel debug output, but leave the leading
29 # whitespace in place.
30 isel = common.SCRUB_WHITESPACE_RE.sub(r" ", isel)
31 # Expand the tabs used for indentation.
32 isel = string.expandtabs(isel, 2)
33 # Strip trailing whitespace.
34 isel = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", isel)
35 return isel
38 def get_run_handler(triple):
39 target_handlers = {}
40 handler = None
41 best_prefix = ""
42 for prefix, s in target_handlers.items():
43 if triple.startswith(prefix) and len(prefix) > len(best_prefix):
44 handler = s
45 best_prefix = prefix
47 if handler is None:
48 common.debug("Using default handler.")
49 handler = (scrub_isel_default, ISEL_FUNCTION_DEFAULT_RE)
51 return handler
54 ##### Generator of iSel CHECK lines
57 def add_checks(
58 output_lines,
59 comment_marker,
60 prefix_list,
61 func_dict,
62 func_name,
63 global_vars_seen_dict,
64 is_filtered,
66 # Label format is based on iSel string.
67 check_label_format = "{} %s-LABEL: %s%s%s%s".format(comment_marker)
68 return common.add_checks(
69 output_lines,
70 comment_marker,
71 prefix_list,
72 func_dict,
73 func_name,
74 check_label_format,
75 True,
76 False,
78 global_vars_seen_dict,
79 is_filtered=is_filtered,