summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDaniel Berlin <dberlin@dberlin.org>2017-01-07 19:04:59 +0000
committerDaniel Berlin <dberlin@dberlin.org>2017-01-07 19:04:59 +0000
commitfe4e7d0c94efef838d26e907411058dee1abc72b (patch)
tree8e731dffc7ef773a0cd8b9dd165fefa64d09bc9e /llvm
parent42ef199058972bb2c5df7f46b44218a6838e49c2 (diff)
downloadbcm5719-llvm-fe4e7d0c94efef838d26e907411058dee1abc72b.tar.gz
bcm5719-llvm-fe4e7d0c94efef838d26e907411058dee1abc72b.zip
Update update_test_checks to work properly with phi nodes and other fun things.
Summary: Prior to this change, phi nodes were never considered defs, and so we ended up with undefined variables for any loop. Now, instead of trying to find just defs, we iterate over each actual IR value in the line, and replace them one by one with either a definition or a use. We also don't try to match anything in the comment portions of the line. I've tested it even on things like function pointer calls, etc, and against existing test cases uses update_test_checks With this change, we are able to use update_tests on the cyclic cases in newgvn. The only case i'm aware of that will misfire is if you have a string with which contains a valid token. However, this is the same as it is now, with a slightly larger set of strings that may misfire. Prior to this change, a test with the string " %a =" would be replaced. Reviewers: spatel, chandlerc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28384 llvm-svn: 291357
Diffstat (limited to 'llvm')
-rwxr-xr-xllvm/utils/update_test_checks.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index a7529af0109..5b4449702cc 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -68,7 +68,9 @@ OPT_FUNCTION_RE = re.compile(
flags=(re.M | re.S))
CHECK_PREFIX_RE = re.compile('--check-prefix=(\S+)')
CHECK_RE = re.compile(r'^\s*;\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL)?:')
-IR_VALUE_DEF_RE = re.compile(r'\s+%(.*) =')
+# Match things that look at identifiers, but only if they are followed by
+# spaces, commas, paren, or end of the string
+IR_VALUE_RE = re.compile(r'(\s+)%(.+?)([,\s\(\)]|\Z)')
# Invoke the tool that is being tested.
@@ -156,33 +158,34 @@ def get_value_definition(var):
def get_value_use(var):
return '[[' + get_value_name(var) + ']]'
-
# Replace IR value defs and uses with FileCheck variables.
def genericize_check_lines(lines):
+ # This gets called for each match that occurs in
+ # a line. We transform variables we haven't seen
+ # into defs, and variables we have seen into uses.
+ def transform_line_vars(match):
+ var = match.group(2)
+ if var in vars_seen:
+ rv = get_value_use(var)
+ else:
+ vars_seen.add(var)
+ rv = get_value_definition(var)
+ # re.sub replaces the entire regex match
+ # with whatever you return, so we have
+ # to make sure to hand it back everything
+ # including the commas and spaces.
+ return match.group(1) + rv + match.group(3)
+
+ vars_seen = set()
lines_with_def = []
- vars_seen = []
- for line in lines:
+
+ for i, line in enumerate(lines):
# An IR variable named '%.' matches the FileCheck regex string.
line = line.replace('%.', '%dot')
- m = IR_VALUE_DEF_RE.match(line)
- if m:
- vars_seen.append(m.group(1))
- line = line.replace('%' + m.group(1), get_value_definition(m.group(1)))
-
- lines_with_def.append(line)
-
- # A single def isn't worth replacing?
- #if len(vars_seen) < 2:
- # return lines
-
- output_lines = []
- vars_seen.sort(key=len, reverse=True)
- for line in lines_with_def:
- for var in vars_seen:
- line = line.replace('%' + var, get_value_use(var))
- output_lines.append(line)
-
- return output_lines
+ # Ignore any comments, since the check lines will too.
+ scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r'', line)
+ lines[i] = IR_VALUE_RE.sub(transform_line_vars, scrubbed_line)
+ return lines
def add_checks(output_lines, prefix_list, func_dict, func_name, tool_basename):
OpenPOWER on IntegriCloud