xref: /llvm-project/llvm/utils/UpdateTestChecks/isel.py (revision 597ac471cc7da97ccf957362a7e9f7a52d6910ee)
1import re
2from . import common
3import sys
4
5if sys.version_info[0] > 2:
6
7    class string:
8        expandtabs = str.expandtabs
9
10else:
11    import string
12
13# Support of isel debug checks
14# RegEx: this is where the magic happens.
15
16##### iSel parser
17
18# TODO: add function prefix
19ISEL_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),
24)
25
26
27def 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
36
37
38def 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
46
47    if handler is None:
48        common.debug("Using default handler.")
49        handler = (scrub_isel_default, ISEL_FUNCTION_DEFAULT_RE)
50
51    return handler
52
53
54##### Generator of iSel CHECK lines
55
56
57def add_checks(
58    output_lines,
59    comment_marker,
60    prefix_list,
61    func_dict,
62    func_name,
63    ginfo: common.GeneralizerInfo,
64    global_vars_seen_dict,
65    is_filtered,
66):
67    # Label format is based on iSel string.
68    check_label_format = "{} %s-LABEL: %s%s%s%s".format(comment_marker)
69    return common.add_checks(
70        output_lines,
71        comment_marker,
72        prefix_list,
73        func_dict,
74        func_name,
75        check_label_format,
76        ginfo,
77        global_vars_seen_dict,
78        is_filtered=is_filtered,
79    )
80