This is an archive of the discontinued LLVM Phabricator instance.

[NewPM] Clear abandoned analyses set when preserveSet is called
Needs RevisionPublic

Authored by ychen on Aug 3 2020, 12:36 AM.

Details

Summary

Fix the extra invalidation issue found in D84959. The issue was exposed when
PreservedAnalyses::abandon was first used in a regular pass.

The extra invalidation was due to the module analysis manager
calling its invalidate with a PreservedAnalyses which contains the
abandoned LVI. The abandoned LVI is returned to outer pass manager
because PreservedAnalyses::intersect unions all the abandoned analyses.

We should not return abandoned analyses to outer pass manager because
the necessary invalidation has already happened in the current pass
manager, which indicated by things like
PA.preserveSet<AllAnalysesOn<IRUnitT>>().

preserveSet<CFGAnalyses> is an exception to this so I propose to
rename it to preserve<CFGAnalyses> in order to make the usage of
preserveSet very specific.

This association of abandon with preserveSet is intended. It does
get tricky because the order of calls to abandon and preserveSet
become relevant but IMHO this association is helpful for reasoning the
code.

Diff Detail

Event Timeline

ychen created this revision.Aug 3 2020, 12:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2020, 12:36 AM
ychen requested review of this revision.Aug 3 2020, 12:36 AM
ychen updated this revision to Diff 282514.Aug 3 2020, 12:43 AM
  • update test
asbirlea added inline comments.Aug 3 2020, 11:07 AM
llvm/include/llvm/IR/PassManager.h
192

I'd be fine with renaming this with this mouthful name. Not just because it's more informative, but it's more likely to remain internally used, or easy to catch if it's not. I don't see how we can assert/enforce this easily.

asbirlea requested changes to this revision.Aug 6 2020, 4:48 PM
asbirlea added inline comments.
llvm/include/llvm/IR/PassManager.h
192

Actually this doesn't look quite right. It's clearing all analyses, for all IR units.
After talking with chandlerc@, a better approach would be clearing in invalidate. I'm looking into the alternative approach.

This revision now requires changes to proceed.Aug 6 2020, 4:48 PM
ychen added inline comments.Aug 6 2020, 4:55 PM
llvm/include/llvm/IR/PassManager.h
192

Agree. Doing it in invalidate works too. Any reason clearing all analyses, for all IR units is wrong?

The scenario I was thinking are

/// - (abandoned inner analyses) the invalidation has happened in inner IR
///   manager, no need to let the outer manager know and they should not care.
///   If abandoned inner analyses were returned, it may trigger another round
///   of inner analyses invalidation from outer manager through the proxy
///   (InnerAnalysisManagerProxy).
/// - (abandoned outer analyses) abandoning has the same effect of not
///   preserving it.