summaryrefslogtreecommitdiffstats
path: root/llvm/utils/UpdateTestChecks/common.py
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-01-30 00:40:05 +0000
committerFangrui Song <maskray@google.com>2018-01-30 00:40:05 +0000
commitee4e2e718d00a44c9ac4e663534a0391d72a3549 (patch)
tree6870c5f91733a78679383f68b4fbf4117775f8c2 /llvm/utils/UpdateTestChecks/common.py
parent96f8c5c420df383e61fe61bf67fc73a3ef8aab75 (diff)
downloadbcm5719-llvm-ee4e2e718d00a44c9ac4e663534a0391d72a3549.tar.gz
bcm5719-llvm-ee4e2e718d00a44c9ac4e663534a0391d72a3549.zip
[utils] De-duplicate utils/update_{llc_,}test_checks.py
Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42654 llvm-svn: 323718
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
-rw-r--r--llvm/utils/UpdateTestChecks/common.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
new file mode 100644
index 00000000000..f8f75c8b712
--- /dev/null
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -0,0 +1,65 @@
+import re
+import subprocess
+
+RUN_LINE_RE = re.compile('^\s*;\s*RUN:\s*(.*)$')
+CHECK_PREFIX_RE = re.compile('--?check-prefix(?:es)?=(\S+)')
+CHECK_RE = re.compile(r'^\s*;\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL)?:')
+
+IR_FUNCTION_RE = re.compile('^\s*define\s+(?:internal\s+)?[^@]*@(\w+)\s*\(')
+TRIPLE_IR_RE = re.compile(r'^target\s+triple\s*=\s*"([^"]+)"$')
+TRIPLE_ARG_RE = re.compile(r'-mtriple=([^ ]+)')
+
+SCRUB_LEADING_WHITESPACE_RE = re.compile(r'^(\s+)')
+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)
+
+def should_add_line_to_output(input_line, prefix_set):
+ # Skip any blank comment lines in the IR.
+ if input_line.strip() == ';':
+ return False
+ # Skip any blank lines in the IR.
+ #if input_line.strip() == '':
+ # return False
+ # And skip any CHECK lines. We're building our own.
+ m = CHECK_RE.match(input_line)
+ if m and m.group(1) in prefix_set:
+ return False
+
+ return True
+
+# Invoke the tool that is being tested.
+def invoke_tool(exe, cmd_args, ir):
+ with open(ir) as ir_file:
+ stdout = subprocess.check_output(exe + ' ' + cmd_args,
+ shell=True, stdin=ir_file)
+ # Fix line endings to unix CR style.
+ stdout = stdout.replace('\r\n', '\n')
+ return stdout
+
+# Build up a dictionary of all the function bodies.
+def build_function_body_dictionary(function_re, scrubber, scrubber_args, raw_tool_output, prefixes, func_dict, verbose):
+ for m in function_re.finditer(raw_tool_output):
+ if not m:
+ continue
+ func = m.group('func')
+ scrubbed_body = scrubber(m.group('body'), *scrubber_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:
+ print >>sys.stderr, 'Processing function: ' + func
+ for l in scrubbed_body.splitlines():
+ print >>sys.stderr, ' ' + l
+ for prefix in prefixes:
+ if func in func_dict[prefix] and func_dict[prefix][func] != scrubbed_body:
+ if prefix == prefixes[-1]:
+ print >>sys.stderr, ('WARNING: Found conflicting asm under the '
+ 'same prefix: %r!' % (prefix,))
+ else:
+ func_dict[prefix][func] = None
+ continue
+
+ func_dict[prefix][func] = scrubbed_body
OpenPOWER on IntegriCloud