[PM] Widen the interface for invalidate on an analysis result now that

it is completely optional, and sink the logic for handling the preserved
analysis set into it.

This allows us to implement the delegation logic desired in the proxy
module analysis for the function analysis manager where if the proxy
itself is preserved we assume the set of functions hasn't changed and we
do a fine grained invalidation by walking the functions in the module
and running the invalidate for them all at the manager level and letting
it try to invalidate any passes.

This in turn makes it blindingly obvious why we should hoist the
invalidate trait and have two collections of results. That allows
handling invalidation for almost all analyses without indirect calls and
it allows short circuiting when the preserved set is all.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195338 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth
2013-11-21 10:53:05 +00:00
parent 0bafaacfc9
commit edd2b49134
3 changed files with 89 additions and 22 deletions

View File

@@ -29,7 +29,7 @@ void ModuleAnalysisManager::invalidate(Module *M, const PreservedAnalyses &PA) {
for (ModuleAnalysisResultMapT::iterator I = ModuleAnalysisResults.begin(),
E = ModuleAnalysisResults.end();
I != E; ++I)
if (!PA.preserved(I->first) && I->second->invalidate(M))
if (I->second->invalidate(M, PA))
ModuleAnalysisResults.erase(I);
}
@@ -76,7 +76,7 @@ void FunctionAnalysisManager::invalidate(Function *F, const PreservedAnalyses &P
for (FunctionAnalysisResultListT::iterator I = ResultsList.begin(),
E = ResultsList.end();
I != E;)
if (!PA.preserved(I->first) && I->second->invalidate(F)) {
if (I->second->invalidate(F, PA)) {
InvalidatedPassIDs.push_back(I->first);
I = ResultsList.erase(I);
} else {
@@ -145,11 +145,19 @@ FunctionAnalysisModuleProxy::Result::~Result() {
FAM.clear();
}
bool FunctionAnalysisModuleProxy::Result::invalidate(Module *M) {
// FIXME: We should pull the preserved analysis set into the invalidation
// handler so that we can detect when there is no need to clear the entire
// function analysis manager.
FAM.clear();
bool FunctionAnalysisModuleProxy::Result::invalidate(Module *M, const PreservedAnalyses &PA) {
// If this proxy isn't marked as preserved, then it is has an invalid set of
// Function objects in the cache making it impossible to incrementally
// preserve them. Just clear the entire manager.
if (!PA.preserved(ID())) {
FAM.clear();
return false;
}
// The set of functions was preserved some how, so just directly invalidate
// any analysis results not preserved.
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
FAM.invalidate(I, PA);
// Return false to indicate that this result is still a valid proxy.
return false;