[PATCH] D28384: Update update_test_checks to work properly with phi nodes and other fun things.

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 15:31:26 PST 2017


dberlin created this revision.
dberlin added reviewers: spatel, chandlerc.
dberlin added a subscriber: llvm-commits.

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. (This is n^2 due to python's mutable strings, but not a problem in practice so far).

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.


https://reviews.llvm.org/D28384

Files:
  utils/update_test_checks.py


Index: utils/update_test_checks.py
===================================================================
--- utils/update_test_checks.py
+++ utils/update_test_checks.py
@@ -68,7 +68,9 @@
     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.
@@ -160,29 +162,28 @@
 # Replace IR value defs and uses with FileCheck variables.
 def genericize_check_lines(lines):
   lines_with_def = []
-  vars_seen = []
+  vars_seen = set()
   for line in 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)))
-
+    # Ignore any comments, since the check lines will too. We don't
+    # delete them however.
+    scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r'', line)
+    matchiter = IR_VALUE_RE.finditer(scrubbed_line)
+    for match in matchiter:
+      # Vars we've already seen are uses
+      if match.group(1) in vars_seen:
+        line = line.replace('%' + match.group(1), get_value_use(match.group(1)), 1)
+        continue
+      # Vars we've not are defs
+      vars_seen.add(match.group(1))
+      line = line.replace('%' + match.group(1), get_value_definition(match.group(1)), 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
+  return lines_with_def
 
 
 def add_checks(output_lines, prefix_list, func_dict, func_name, tool_basename):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28384.83316.patch
Type: text/x-patch
Size: 2127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170105/281f9d3f/attachment.bin>


More information about the llvm-commits mailing list