[llvm] [NewPM] LiveIntervals: Check dependencies for invalidation (PR #123563)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 11:31:07 PST 2025


================
@@ -127,6 +127,20 @@ LiveIntervalsWrapperPass::LiveIntervalsWrapperPass() : MachineFunctionPass(ID) {
 
 LiveIntervals::~LiveIntervals() { clear(); }
 
+bool LiveIntervals::invalidate(
+    MachineFunction &MF, const PreservedAnalyses &PA,
+    MachineFunctionAnalysisManager::Invalidator &Inv) {
+  auto PAC = PA.getChecker<LiveIntervalsAnalysis>();
+
+  if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<MachineFunction>>())
+    return true;
+
+  // LiveIntervals holds pointers to these results, so check for their
+  // invalidation.
+  return (Inv.invalidate<SlotIndexesAnalysis>(MF, PA) ||
+          Inv.invalidate<MachineDominatorTreeAnalysis>(MF, PA));
+}
----------------
aeubanks wrote:

> Then
> 
> ```c++
> PreservedAnalyses SomePass::run(IRUnitT &, AnalysisManager &) {
>   PreservedAnalyses PA;
>   PA.preserve<LiveIntervals>();
>   return PA;
> }
> ```
> 
> will no longer work, which is counter-intuitive... because it doesn't preserve `SlotIndexes` explicitly.

if `SlotIndexes` is invalidated, then `LiveIntervals` may reference an invalid `SlotIndexes`, so if we kept around `LiveIntervals` it may be invalid to use. so invalidating it regardless makes sense.

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


More information about the llvm-commits mailing list