[Clang][ThinLTO] Wire up AllocToken pass to run in ThinLTO backend #169244
+82
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 seeit in the backend, preventing optimization.
Defer the execution of AllocTokenPass to the LTO Backend (Post-Link)
when ThinLTO is enabled by:
Adding a
PassBuilderCallbackhook tolto::Configand invoking itin
LTOBackend.cpp.Using this hook in
BackendUtil.cppto registerAllocTokenPassinto the LTO backend pipeline via
registerOptimizerLastEPCallback.Skipping
AllocTokenPassin the Pre-Link phase ifPrepareForThinLTOis set.This ensures PGHO optimization (in InstCombine) runs first in the
backend, followed by AllocToken instrumentation on hot/cold new.