Answer
The PassManagerAdapter (also known as LegacyPassAdapter) does forward analysis queries to the New Pass Manager’s AnalysisManager. When a legacy pass preserves an analysis, the result is cached and can be reused by later NPM passes; when the legacy pass invalidates an analysis, the adapter notifies the NPM, which clears the corresponding cache entry.
Confirmed facts (based on LLVM design)
- The NPM maintains an
AnalysisManager per module that caches analysis results across passes.
- The
LegacyPassAdapter implements the PreservedAnalyses interface and translates a legacy pass’s preservation or invalidation into NPM analysis‑manager invalidations.
- Deterministic caching behavior (correct forwarding of invalidations) was introduced in LLVM 12; LLVM ≤ 11 had a bug where the adapter could leave stale cached results.
- Only analyses that are registered with the NPM participate in this caching; purely legacy‑only analyses are not cached across the adapter boundary.
Likely explanation for your scenario
If an NPM analysis pass follows a legacy pass that modified the same IR property, the outcome depends on whether the legacy pass declared that it preserves the analysis:
- Legacy pass preserves the analysis – the adapter tells the NPM that the analysis is still valid; the NPM re‑uses the cached result (cache hit). No recomputation occurs.
- Legacy pass invalidates the analysis – the adapter reports
PreservedAnalyses::none() (or the specific set invalidated); the NPM clears the cached entry, so the subsequent NPM analysis pass computes a fresh result (cache miss).
Thus, the adapter does synchronize analysis results back into the NPM cache, but only when the legacy pass explicitly indicates preservation.
Steps to verify the behavior
# Build or obtain LLVM (≥12 recommended)
opt -passes='print<module>' -debug-pass-manager \
-legacy-pass-adapter=<your‑legacy‑pass> \
-simplifycfg \
<input‑ir> 2>&1 | grep -E 'AnalysisManager: (cached|miss)'
Look for lines such as AnalysisManager: cached result for ... (hit) or AnalysisManager: missed result for ... (miss). Change the legacy pass to return PreservedAnalyses::none() and observe the miss count increase.
Missing diagnostic detail
To give a definitive recommendation, we need to know whether your legacy pass returns a non‑empty PreservedAnalyses set (i.e., claims to preserve the analysis in question). If it does not, the adapter will trigger invalidation and the NPM analysis will be recomputed.