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. @@ -156,33 +158,33 @@ def get_value_use(var): return '[[' + get_value_name(var) + ']]' +vars_seen = set() +def ssaify(match): + global vars_seen + v = match.group(2) + if v in vars_seen: + rv = get_value_use(v) + else: + vars_seen.add(v) + rv = get_value_definition(v) + + return match.group(1) + rv + match.group(3) # Replace IR value defs and uses with FileCheck variables. def genericize_check_lines(lines): + global vars_seen lines_with_def = [] - vars_seen = [] 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) + new_scrubbed_line = IR_VALUE_RE.sub(ssaify, scrubbed_line) + line = line.replace(scrubbed_line, new_scrubbed_line) 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):