New Pass Manager: PreservedAnalyses and Analysis Cache Invalidation
0 reputation · 07 Nov 2023, 11:25 UTC
Analysis Result Persistence in the New Pass Manager
The LLVM New Pass Manager (NPM) utilizes a caching mechanism for analysis results to optimize the pipeline. To maintain correctness, passes must explicitly specify which analyses remain valid after an IR transformation by returning a PreservedAnalyses object.
When a pass modifies the IR but fails to correctly invalidate a dependent analysis, the pipeline may reuse stale cached data. This behavior can lead to inconsistent optimization results or miscompiles that are difficult to trace, as they often depend on the specific sequence of passes executed in the pipeline.
Given the transition to the NPM in recent LLVM releases (v17+), there is uncertainty regarding the most reliable way to verify that a custom pass is not inadvertently preserving an analysis that should be invalidated.
- How can a developer programmatically verify that a specific analysis is being re-run rather than retrieved from the cache after a custom pass executes?
- Are there diagnostic flags available in the NPM to trace the invalidation and reuse of cached analysis results during a
-O2or-O3pipeline?