[llvm-branch-commits] [Clang][LTO] Wire up AllocToken pass to run in LTO backend (PR #169244)

Marco Elver via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 23 13:16:42 PST 2025


https://github.com/melver created https://github.com/llvm/llvm-project/pull/169244

The AllocToken pass was running in the Pre-Link pipeline, which caused a
conflict with PGHO in ThinLTO builds because AllocToken rewrites
allocations (e.g. `_Znam` -> `__alloc_token__Znam`) before PGHO can see
it in the backend, preventing optimization.

Defer the execution of AllocTokenPass to the LTO Backend (Post-Link)
when ThinLTO is enabled by:

1. Adding a `PassBuilderCallback` hook to `lto::Config` and invoking it
   in `LTOBackend.cpp`.

2. Using this hook in `BackendUtil.cpp` to register `AllocTokenPass`
   into the LTO backend pipeline via `registerOptimizerLastEPCallback`.

3. Skipping `AllocTokenPass` in the Pre-Link phase if
   `PrepareForThinLTO` is set.

This ensures PGHO optimization (in InstCombine) runs first in the
backend, followed by AllocToken instrumentation on hot/cold new.





More information about the llvm-branch-commits mailing list