[llvm] update_test_checks: keep meta variables stable by default (PR #76748)
Jannik Silvanus via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 07:51:29 PST 2024
Nicolai =?utf-8?q?Hähnle?= <nicolai.haehnle at amd.com>,
Nicolai =?utf-8?q?Hähnle?= <nicolai.haehnle at amd.com>,
Nicolai =?utf-8?q?Hähnle?= <nicolai.haehnle at amd.com>,
Nicolai =?utf-8?q?Hähnle?= <nicolai.haehnle at amd.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/76748 at github.com>
================
@@ -1241,25 +1500,136 @@ def escape_braces(match_obj):
# Ignore any comments, since the check lines will too.
scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r"", line)
lines[i] = scrubbed_line
- if not preserve_names:
- # It can happen that two matches are back-to-back and for some reason sub
- # will not replace both of them. For now we work around this by
- # substituting until there is no more match.
- changed = True
- while changed:
- (lines[i], changed) = nameless_value_regex.subn(
- transform_line_vars, lines[i], count=1
- )
- if is_analyze:
+
+ if not preserve_names:
+ if is_asm:
+ for i, _ in enumerate(lines):
+ # It can happen that two matches are back-to-back and for some reason sub
+ # will not replace both of them. For now we work around this by
+ # substituting until there is no more match.
+ changed = True
+ while changed:
+ (lines[i], changed) = nameless_value_regex.subn(
+ transform_line_vars, lines[i], count=1
+ )
+ else:
+ # LLVM IR case. Start by handling global meta variables (global IR variables,
+ # metadata, attributes)
+ for i, _ in enumerate(lines):
+ start = 0
+ while True:
+ m = nameless_value_regex.search(lines[i][start:])
+ if m is None:
+ break
+ start += m.span()[0]
+ sub = transform_non_local_line_vars(m)
+ if sub is not None:
+ lines[i] = (
+ lines[i][:start] + sub + lines[i][start + len(m.group(0)) :]
+ )
+ start += 1
+
+ # Collect information about new check lines and original check lines (if any)
+ new_line_infos = []
+ for line in lines:
+ filtered_line = ""
+ values = []
+ while True:
+ m = nameless_value_regex.search(line)
+ if m is None:
+ filtered_line += line
+ break
+
+ var = get_name_from_ir_value_match(m)
+ nameless_value = get_nameless_value_from_match(m, nameless_values)
+ var = nameless_value.get_value_name(
+ var, nameless_value.check_prefix
+ )
+
+ # Replace with a [[@@]] tag, but be sure to keep the spaces and commas.
+ filtered_line += (
+ line[: m.span()[0]]
+ + m.group(1)
+ + VARIABLE_TAG
+ + m.group(m.lastindex)
+ )
+ line = line[m.span()[1] :]
+ values.append(
+ CheckValueInfo(
+ nameless_value=nameless_value,
+ var=var,
+ prefix=nameless_value.get_ir_prefix_from_ir_value_match(m)[
+ 0
+ ],
+ )
+ )
+ new_line_infos.append(CheckLineInfo(filtered_line, values))
+
+ orig_line_infos = []
+ for line in original_check_lines or []:
+ filtered_line = ""
+ values = []
+ while True:
+ m = METAVAR_RE.search(line)
+ if m is None:
+ filtered_line += line
+ break
+
+ # Replace with a [[@@]] tag, but be sure to keep the spaces and commas.
+ filtered_line += line[: m.span()[0]] + VARIABLE_TAG
+ line = line[m.span()[1] :]
+ values.append(
+ CheckValueInfo(
+ nameless_value=None,
+ var=m.group(1),
+ prefix=None,
+ )
+ )
+ orig_line_infos.append(CheckLineInfo(filtered_line, values))
+
+ # Compute the variable name mapping
+ committed_names = set(vars_seen)
+
+ mapping = remap_metavar_names(
+ orig_line_infos, new_line_infos, committed_names
+ )
+
+ for i, line_info in enumerate(new_line_infos):
+ line_template = line_info.line
+ line = ""
+
+ for value in line_info.values:
+ idx = line_template.find(VARIABLE_TAG)
+ line += line_template[:idx]
+ line_template = line_template[idx + len(VARIABLE_TAG) :]
+
+ key = (mapping[value.var], nameless_value.check_key)
+ is_local_def = nameless_value.is_local_def_ir_value()
+ if is_local_def:
+ if mapping[value.var] in vars_seen:
+ line += f"[[{mapping[value.var]}]]"
+ else:
+ line += f"[[{mapping[value.var]}:{value.prefix}{value.nameless_value.get_ir_regex()}]]"
+ vars_seen.add(mapping[value.var])
+ else:
+ todo("not implemented")
----------------
jasilvanus wrote:
Maybe raise a RuntimeError?
https://github.com/llvm/llvm-project/pull/76748
More information about the llvm-commits
mailing list