[llvm-branch-commits] [llvm] [lit] Add lit.llvm.fn_param shared helper for --param fn= substitutions (PR #200350)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 29 01:46:24 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-testing-tools
Author: jofrn
<details>
<summary>Changes</summary>
[lit] Add lit.llvm.fn_param shared helper for --param fn= substitutions
---
Full diff: https://github.com/llvm/llvm-project/pull/200350.diff
2 Files Affected:
- (modified) llvm/test/lit.cfg.py (+6)
- (added) llvm/utils/lit/lit/llvm/fn_param.py (+37)
``````````diff
diff --git a/llvm/test/lit.cfg.py b/llvm/test/lit.cfg.py
index 09df1e3fd6281..f4b9e8aaed6ef 100644
--- a/llvm/test/lit.cfg.py
+++ b/llvm/test/lit.cfg.py
@@ -39,6 +39,12 @@
)
config.test_format = lit.formats.ShTest(not use_lit_shell, extra_substitutions)
+# --param fn=NAMES narrows compilation to the named functions and their
+# transitive dependencies. See lit.llvm.fn_param.install for dispatch details.
+from lit.llvm import fn_param
+
+fn_param.install(config, lit_config)
+
# suffixes: A list of file extensions to treat as test files. This is overriden
# by individual lit.local.cfg files in the test subdirectories.
config.suffixes = [".ll", ".c", ".test", ".txt", ".s", ".mir", ".yaml", ".spv"]
diff --git a/llvm/utils/lit/lit/llvm/fn_param.py b/llvm/utils/lit/lit/llvm/fn_param.py
new file mode 100644
index 0000000000000..616f519c32c95
--- /dev/null
+++ b/llvm/utils/lit/lit/llvm/fn_param.py
@@ -0,0 +1,37 @@
+"""Shared building blocks for `--param fn=NAMES`-driven lit substitutions.
+
+Used by `lit.llvm.fn_selection` and `lit.llvm.fn_extract` to narrow compilation
+to a subset of functions. Kept here so the two helpers stay short and share
+parsing + capture-substitution wiring."""
+
+from lit.TestingConfig import SubstituteCaptures
+
+
+def parse_fn_names(lit_config, param="fn"):
+ """Return the comma-separated list passed via `--param <param>=NAMES`,
+ or an empty list when the param is absent or empty."""
+ val = lit_config.params.get(param)
+ if not val:
+ return []
+ return [n.strip() for n in val.split(",") if n.strip()]
+
+
+def add_capture_sub(config, pattern, replacement):
+ """Append a substitution that preserves regex backreferences in `replacement`."""
+ config.substitutions.append((pattern, SubstituteCaptures(replacement)))
+
+
+def install(config, lit_config):
+ """Dispatch `--param fn=NAMES` to the right helper.
+
+ `--param fn-pass=1` opts into `lit.llvm.fn_selection` (the select-function
+ pass, opt-only); otherwise `lit.llvm.fn_extract` is used (prepends
+ llvm-extract, tool-agnostic)."""
+ if lit_config.params.get("fn-pass"):
+ # from lit.llvm import fn_selection
+ # fn_selection.install(config, lit_config)
+ pass
+ else:
+ # from lit.llvm import fn_extract
+ # fn_extract.install(config, lit_config)
+ pass
``````````
</details>
https://github.com/llvm/llvm-project/pull/200350
More information about the llvm-branch-commits
mailing list