| OLD | NEW |
| 1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
| 2 | 2 |
| 3 import argparse | 3 import argparse |
| 4 import itertools | 4 import itertools |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 if __name__ == '__main__': | 7 if __name__ == '__main__': |
| 8 """Compares a LLVM file with a subzero file for differences. | 8 """Compares a LLVM file with a subzero file for differences. |
| 9 | 9 |
| 10 Before comparing, the LLVM file is massaged to remove comments, | 10 Before comparing, the LLVM file is massaged to remove comments, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 args = argparser.parse_args() | 36 args = argparser.parse_args() |
| 37 bitcode = args.llfile[0].readlines() | 37 bitcode = args.llfile[0].readlines() |
| 38 sz_out = [ line.rstrip() for line in args.szfile.readlines()] | 38 sz_out = [ line.rstrip() for line in args.szfile.readlines()] |
| 39 | 39 |
| 40 # Filter certain lines and patterns from the input, and collect | 40 # Filter certain lines and patterns from the input, and collect |
| 41 # the remainder into llc_out. | 41 # the remainder into llc_out. |
| 42 llc_out = [] | 42 llc_out = [] |
| 43 tail_call = re.compile(' tail call '); | 43 tail_call = re.compile(' tail call '); |
| 44 trailing_comment = re.compile(';.*') | 44 trailing_comment = re.compile(';.*') |
| 45 ignore_pattern = re.compile('^ *$|^declare|^@') | 45 ignore_pattern = re.compile('^ *$|^declare|^@') |
| 46 prev_line = None |
| 46 for line in bitcode: | 47 for line in bitcode: |
| 48 if prev_line: |
| 49 line = prev_line + line |
| 50 prev_line = None |
| 47 # Convert tail call into regular (non-tail) call. | 51 # Convert tail call into regular (non-tail) call. |
| 48 line = tail_call.sub(' call ', line) | 52 line = tail_call.sub(' call ', line) |
| 49 # Remove trailing comments and spaces. | 53 # Remove trailing comments and spaces. |
| 50 line = trailing_comment.sub('', line).rstrip() | 54 line = trailing_comment.sub('', line).rstrip() |
| 51 # Ignore blanks lines, forward declarations, and variable definitions. | 55 # Ignore blanks lines, forward declarations, and variable definitions. |
| 52 if not ignore_pattern.search(line): | 56 if ignore_pattern.search(line): |
| 53 llc_out.append(line) | 57 continue |
| 58 # SZ doesn't break up long lines, but LLVM does. Normalize to SZ. |
| 59 if line.endswith(','): |
| 60 prev_line = line |
| 61 continue |
| 62 llc_out.append(line) |
| 54 | 63 |
| 55 # Compare sz_out and llc_out line by line, but ignore pairs of | 64 # Compare sz_out and llc_out line by line, but ignore pairs of |
| 56 # lines where the llc line matches a certain pattern. | 65 # lines where the llc line matches a certain pattern. |
| 57 return_code = 0 | 66 return_code = 0 |
| 58 lines_total = 0 | 67 lines_total = 0 |
| 59 lines_diff = 0 | 68 lines_diff = 0 |
| 60 ignore_pattern = re.compile( | 69 ignore_pattern = re.compile( |
| 61 '|'.join([' -[0-9]', # negative constants | 70 '|'.join([' -[0-9]', # negative constants |
| 62 ' (float|double) [-0-9]', # FP constants | 71 ' (float|double) [-0-9]', # FP constants |
| 63 ' (float|double) %\w+, [-0-9]', | 72 ' (float|double) %\w+, [-0-9]', |
| 73 ' @llvm\..*i\d+\*', # intrinsic calls w/ pointer args |
| 74 ' i\d+\* @llvm\.', # intrinsic calls w/ pointer ret |
| 64 ' inttoptr ', # inttoptr pointer types | 75 ' inttoptr ', # inttoptr pointer types |
| 65 ' ptrtoint ', # ptrtoint pointer types | 76 ' ptrtoint ', # ptrtoint pointer types |
| 66 ' bitcast .*\* .* to .*\*' # bitcast pointer types | 77 ' bitcast .*\* .* to .*\*' # bitcast pointer types |
| 67 ])) | 78 ])) |
| 68 for (sz_line, llc_line) in itertools.izip_longest(sz_out, llc_out): | 79 for (sz_line, llc_line) in itertools.izip_longest(sz_out, llc_out): |
| 69 lines_total += 1 | 80 lines_total += 1 |
| 70 if sz_line == llc_line: | 81 if sz_line == llc_line: |
| 71 continue | 82 continue |
| 72 if llc_line and ignore_pattern.search(llc_line): | 83 if llc_line and ignore_pattern.search(llc_line): |
| 73 lines_diff += 1 | 84 lines_diff += 1 |
| 74 continue | 85 continue |
| 75 if sz_line: print 'SZ>' + sz_line | 86 if sz_line: print 'SZ (%d)> %s' % (lines_total, sz_line) |
| 76 if llc_line: print 'LL>' + llc_line | 87 if llc_line: print 'LL (%d)> %s' % (lines_total, llc_line) |
| 77 return_code = 1 | 88 return_code = 1 |
| 78 | 89 |
| 79 if return_code == 0: | 90 if return_code == 0: |
| 80 message = 'Success (ignored %d diffs out of %d lines)' | 91 message = 'Success (ignored %d diffs out of %d lines)' |
| 81 print message % (lines_diff, lines_total) | 92 print message % (lines_diff, lines_total) |
| 82 exit(return_code) | 93 exit(return_code) |
| OLD | NEW |