[llvm] [bazel] Update tblgen rules to support path-mapping (PR #158354)

Aaron Siddhartha Mondal via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 14 13:02:20 PDT 2025


================
@@ -234,15 +222,16 @@ def _gentbl_test_impl(ctx):
     # workspace is not the main workspace. Therefore it is not included in the
     # _resolve_includes call that prepends this prefix.
     trans_includes = _get_transitive_includes(
-        _resolve_includes(ctx, ctx.attr.includes + ["/"]) +
-        _prefix_roots(ctx, [td_file.dirname]),
+        _resolve_includes(ctx, ctx.attr.includes + ["/"]) + [td_file.dirname],
         ctx.attr.deps,
     )
 
     test_args = [ctx.executable.tblgen.short_path]
     test_args.extend(ctx.attr.opts)
     test_args.append(td_file.path)
-    test_args.extend(["-I " + include for include in trans_includes.to_list()])
+    for include in trans_includes.to_list():
+        test_args.extend(["-I", include])
+        test_args.extend(["-I", paths.join(ctx.bin_dir.path, include)])
----------------
aaronmondal wrote:

nit: I believe it would be slightly more efficient to do

```python
    for include in trans_includes.to_list():
        test_args.extend(["-I", include, "-I", paths.join(ctx.bin_dir.path, include)])
```

Because this way we access `extend` half as often.

Thinking about it, this variant would access it just once which should be even better (and is roughly the same as what we previously had):

```python
test_args.extend([
    arg
    for include in trans_includes.to_list()
    for arg in ["-I", include, "-I", paths.join(ctx.bin_dir.path, include)]
])
```

I tested this with some python benchmarks and while it's not exactly comparable to the starlark interpreter this last version seems to be ~8% - 12% faster across various input sizes.

https://github.com/llvm/llvm-project/pull/158354


More information about the llvm-commits mailing list