diff options
Diffstat (limited to 'utils/update_llc_test_checks.py')
| -rwxr-xr-x | utils/update_llc_test_checks.py | 133 | 
1 files changed, 103 insertions, 30 deletions
| diff --git a/utils/update_llc_test_checks.py b/utils/update_llc_test_checks.py index 3b3ff74d8633..57d6e578259c 100755 --- a/utils/update_llc_test_checks.py +++ b/utils/update_llc_test_checks.py @@ -26,38 +26,35 @@ def llc(args, cmd_args, ir):  # RegEx: this is where the magic happens. -SCRUB_WHITESPACE_RE = re.compile(r'(?!^(|  \w))[ \t]+', flags=re.M) -SCRUB_TRAILING_WHITESPACE_RE = re.compile(r'[ \t]+$', flags=re.M) -SCRUB_KILL_COMMENT_RE = re.compile(r'^ *#+ +kill:.*\n') -SCRUB_LOOP_COMMENT_RE = re.compile( -    r'# =>This Inner Loop Header:.*|# in Loop:.*', flags=re.M) -  ASM_FUNCTION_X86_RE = re.compile(      r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n[^:]*?'      r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' -    r'^\s*(?:[^:\n]+?:\s*\n\s*\.size|\.cfi_endproc|\.globl|\.comm|\.(?:sub)?section)', +    r'^\s*(?:[^:\n]+?:\s*\n\s*\.size|\.cfi_endproc|\.globl|\.comm|\.(?:sub)?section|#+ -- End function)',      flags=(re.M | re.S)) -SCRUB_X86_SHUFFLES_RE = ( -    re.compile( -        r'^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = .*)$', -        flags=re.M)) -SCRUB_X86_SP_RE = re.compile(r'\d+\(%(esp|rsp)\)') -SCRUB_X86_RIP_RE = re.compile(r'[.\w]+\(%rip\)') -SCRUB_X86_LCP_RE = re.compile(r'\.LCPI[0-9]+_[0-9]+')  ASM_FUNCTION_ARM_RE = re.compile(          r'^(?P<func>[0-9a-zA-Z_]+):\n' # f: (name of function)          r'\s+\.fnstart\n' # .fnstart          r'(?P<body>.*?)\n' # (body of the function) -        r'.Lfunc_end[0-9]+:\n', # .Lfunc_end0: +        r'.Lfunc_end[0-9]+:', # .Lfunc_end0: or # -- End function          flags=(re.M | re.S)) -RUN_LINE_RE = re.compile('^\s*;\s*RUN:\s*(.*)$') -TRIPLE_ARG_RE = re.compile(r'-mtriple=([^ ]+)') -TRIPLE_IR_RE = re.compile(r'^target\s+triple\s*=\s*"([^"]+)"$') -IR_FUNCTION_RE = re.compile('^\s*define\s+(?:internal\s+)?[^@]*@(\w+)\s*\(') -CHECK_PREFIX_RE = re.compile('--?check-prefix(?:es)?=(\S+)') -CHECK_RE = re.compile(r'^\s*;\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL)?:') +ASM_FUNCTION_AARCH64_RE = re.compile( +     r'^_?(?P<func>[^:]+):[ \t]*\/\/[ \t]*@(?P=func)\n' +     r'[ \t]+.cfi_startproc\n' +     r'(?P<body>.*?)\n' +     # This list is incomplete +     r'.Lfunc_end[0-9]+:\n', +     flags=(re.M | re.S)) + +ASM_FUNCTION_MIPS_RE = re.compile( +    r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n[^:]*?' # f: (name of func) +    r'(?:^[ \t]+\.(frame|f?mask|set).*?\n)+'  # Mips+LLVM standard asm prologue +    r'(?P<body>.*?)\n'                        # (body of the function) +    r'(?:^[ \t]+\.(set|end).*?\n)+'           # Mips+LLVM standard asm epilogue +    r'(\$|\.L)func_end[0-9]+:\n',             # $func_end0: (mips32 - O32) or +                                              # .Lfunc_end0: (mips64 - NewABI) +    flags=(re.M | re.S))  ASM_FUNCTION_PPC_RE = re.compile(      r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n' @@ -70,6 +67,12 @@ ASM_FUNCTION_PPC_RE = re.compile(      r'.Lfunc_end[0-9]+:\n',      flags=(re.M | re.S)) +ASM_FUNCTION_RISCV_RE = re.compile( +    r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n[^:]*?' +    r'(?P<body>^##?[ \t]+[^:]+:.*?)\s*' +    r'.Lfunc_end[0-9]+:\n', +    flags=(re.M | re.S)) +  ASM_FUNCTION_SYSTEMZ_RE = re.compile(      r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n'      r'[ \t]+.cfi_startproc\n' @@ -78,7 +81,29 @@ ASM_FUNCTION_SYSTEMZ_RE = re.compile(      flags=(re.M | re.S)) -def scrub_asm_x86(asm): +SCRUB_WHITESPACE_RE = re.compile(r'(?!^(|  \w))[ \t]+', flags=re.M) +SCRUB_TRAILING_WHITESPACE_RE = re.compile(r'[ \t]+$', flags=re.M) +SCRUB_KILL_COMMENT_RE = re.compile(r'^ *#+ +kill:.*\n') +SCRUB_LOOP_COMMENT_RE = re.compile( +    r'# =>This Inner Loop Header:.*|# in Loop:.*', flags=re.M) + +SCRUB_X86_SHUFFLES_RE = ( +    re.compile( +        r'^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = .*)$', +        flags=re.M)) +SCRUB_X86_SP_RE = re.compile(r'\d+\(%(esp|rsp)\)') +SCRUB_X86_RIP_RE = re.compile(r'[.\w]+\(%rip\)') +SCRUB_X86_LCP_RE = re.compile(r'\.LCPI[0-9]+_[0-9]+') +SCRUB_X86_RET_RE = re.compile(r'ret[l|q]') + +RUN_LINE_RE = re.compile('^\s*;\s*RUN:\s*(.*)$') +TRIPLE_ARG_RE = re.compile(r'-mtriple=([^ ]+)') +TRIPLE_IR_RE = re.compile(r'^target\s+triple\s*=\s*"([^"]+)"$') +IR_FUNCTION_RE = re.compile('^\s*define\s+(?:internal\s+)?[^@]*@(\w+)\s*\(') +CHECK_PREFIX_RE = re.compile('--?check-prefix(?:es)?=(\S+)') +CHECK_RE = re.compile(r'^\s*;\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL)?:') + +def scrub_asm_x86(asm, args):    # Scrub runs of whitespace out of the assembly, but leave the leading    # whitespace in place.    asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) @@ -92,13 +117,16 @@ def scrub_asm_x86(asm):    asm = SCRUB_X86_RIP_RE.sub(r'{{.*}}(%rip)', asm)    # Generically match a LCP symbol.    asm = SCRUB_X86_LCP_RE.sub(r'{{\.LCPI.*}}', asm) +  if args.x86_extra_scrub: +    # Avoid generating different checks for 32- and 64-bit because of 'retl' vs 'retq'. +    asm = SCRUB_X86_RET_RE.sub(r'ret{{[l|q]}}', asm)    # Strip kill operands inserted into the asm.    asm = SCRUB_KILL_COMMENT_RE.sub('', asm)    # Strip trailing whitespace.    asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)    return asm -def scrub_asm_arm_eabi(asm): +def scrub_asm_arm_eabi(asm, args):    # Scrub runs of whitespace out of the assembly, but leave the leading    # whitespace in place.    asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) @@ -110,7 +138,7 @@ def scrub_asm_arm_eabi(asm):    asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)    return asm -def scrub_asm_powerpc64le(asm): +def scrub_asm_powerpc64(asm, args):    # Scrub runs of whitespace out of the assembly, but leave the leading    # whitespace in place.    asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) @@ -122,7 +150,27 @@ def scrub_asm_powerpc64le(asm):    asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)    return asm -def scrub_asm_systemz(asm): +def scrub_asm_mips(asm, args): +  # Scrub runs of whitespace out of the assembly, but leave the leading +  # whitespace in place. +  asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) +  # Expand the tabs used for indentation. +  asm = string.expandtabs(asm, 2) +  # Strip trailing whitespace. +  asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) +  return asm + +def scrub_asm_riscv(asm, args): +  # Scrub runs of whitespace out of the assembly, but leave the leading +  # whitespace in place. +  asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) +  # Expand the tabs used for indentation. +  asm = string.expandtabs(asm, 2) +  # Strip trailing whitespace. +  asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) +  return asm + +def scrub_asm_systemz(asm, args):    # Scrub runs of whitespace out of the assembly, but leave the leading    # whitespace in place.    asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) @@ -135,17 +183,39 @@ def scrub_asm_systemz(asm):  # Build up a dictionary of all the function bodies.  def build_function_body_dictionary(raw_tool_output, triple, prefixes, func_dict, -                                   verbose): +                                   args):    target_handlers = {        'x86_64': (scrub_asm_x86, ASM_FUNCTION_X86_RE),        'i686': (scrub_asm_x86, ASM_FUNCTION_X86_RE),        'x86': (scrub_asm_x86, ASM_FUNCTION_X86_RE),        'i386': (scrub_asm_x86, ASM_FUNCTION_X86_RE), +      'aarch64': (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),        'arm-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),        'thumb-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv6': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv6-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv6t2': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv6t2-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv6m': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv6m-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv7': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv7-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv7m': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv7m-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),        'thumbv8-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv8m.base': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'thumbv8m.main': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'armv6': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'armv7': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'armv7-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),        'armeb-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), -      'powerpc64le': (scrub_asm_powerpc64le, ASM_FUNCTION_PPC_RE), +      'armv7eb-eabi': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'armv7eb': (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE), +      'mips': (scrub_asm_mips, ASM_FUNCTION_MIPS_RE), +      'powerpc64': (scrub_asm_powerpc64, ASM_FUNCTION_PPC_RE), +      'powerpc64le': (scrub_asm_powerpc64, ASM_FUNCTION_PPC_RE), +      'riscv32': (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE), +      'riscv64': (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE),        's390x': (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE),    }    handlers = None @@ -161,11 +231,11 @@ def build_function_body_dictionary(raw_tool_output, triple, prefixes, func_dict,      if not m:        continue      func = m.group('func') -    scrubbed_body = scrubber(m.group('body')) +    scrubbed_body = scrubber(m.group('body'), args)      if func.startswith('stress'):        # We only use the last line of the function body for stress tests.        scrubbed_body = '\n'.join(scrubbed_body.splitlines()[-1:]) -    if verbose: +    if args.verbose:        print >>sys.stderr, 'Processing function: ' + func        for l in scrubbed_body.splitlines():          print >>sys.stderr, '  ' + l @@ -228,6 +298,9 @@ def main():                        help='The "llc" binary to use to generate the test case')    parser.add_argument(        '--function', help='The function in the test file to update') +  parser.add_argument( +      '--x86_extra_scrub', action='store_true', +      help='Use more regex for x86 matching to reduce diffs between various subtargets')    parser.add_argument('tests', nargs='+')    args = parser.parse_args() @@ -309,7 +382,7 @@ def main():          print >>sys.stderr, "Cannot find a triple. Assume 'x86'"        build_function_body_dictionary(raw_tool_output, -          triple_in_cmd or triple_in_ir or 'x86', prefixes, func_dict, args.verbose) +          triple_in_cmd or triple_in_ir or 'x86', prefixes, func_dict, args)      is_in_function = False      is_in_function_start = False | 
