Author: Jay Foad Date: 2021-01-22T09:48:54Z New Revision: 14eea6b0ecddfe7d1c68754a8bfb7c21cde82df8
URL: https://github.com/llvm/llvm-project/commit/14eea6b0ecddfe7d1c68754a8bfb7c21cde82df8 DIFF: https://github.com/llvm/llvm-project/commit/14eea6b0ecddfe7d1c68754a8bfb7c21cde82df8.diff LOG: [LegacyPM] Update InversedLastUser on the fly. NFC. This speeds up setLastUser enough to give a 5% to 10% speed up on trivial invocations of opt and llc, as measured by: perf stat -r 100 opt -S -o /dev/null -O3 /dev/null perf stat -r 100 llc -march=amdgcn /dev/null -filetype null Don't dump last use information unless -debug-pass=Details to avoid printing lots of spam that will break some existing lit tests. Before this patch, dumping last use information was broken anyway, because it used InversedLastUser before it had been populated. Differential Revision: https://reviews.llvm.org/D92309 Added: Modified: llvm/include/llvm/IR/LegacyPassManagers.h llvm/lib/IR/LegacyPassManager.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/IR/LegacyPassManagers.h b/llvm/include/llvm/IR/LegacyPassManagers.h index 498e736a0100..f4fae184e428 100644 --- a/llvm/include/llvm/IR/LegacyPassManagers.h +++ b/llvm/include/llvm/IR/LegacyPassManagers.h @@ -230,11 +230,11 @@ class PMTopLevelManager { // Map to keep track of last user of the analysis pass. // LastUser->second is the last user of Lastuser->first. + // This is kept in sync with InversedLastUser. DenseMap<Pass *, Pass *> LastUser; // Map to keep track of passes that are last used by a pass. - // This inverse map is initialized at PM->run() based on - // LastUser map. + // This is kept in sync with LastUser. DenseMap<Pass *, SmallPtrSet<Pass *, 8> > InversedLastUser; /// Immutable passes are managed by top level manager. diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp index 5575bc469a87..4547c3a01239 100644 --- a/llvm/lib/IR/LegacyPassManager.cpp +++ b/llvm/lib/IR/LegacyPassManager.cpp @@ -568,7 +568,12 @@ PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) { PDepth = P->getResolver()->getPMDataManager().getDepth(); for (Pass *AP : AnalysisPasses) { - LastUser[AP] = P; + // Record P as the new last user of AP. + auto &LastUserOfAP = LastUser[AP]; + if (LastUserOfAP) + InversedLastUser[LastUserOfAP].erase(AP); + LastUserOfAP = P; + InversedLastUser[P].insert(AP); if (P == AP) continue; @@ -598,13 +603,13 @@ PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) { if (P->getResolver()) setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass()); - // If AP is the last user of other passes then make P last user of // such passes. - for (auto &LU : LastUser) { - if (LU.second == AP) - LU.second = P; - } + auto &LastUsedByAP = InversedLastUser[AP]; + for (Pass *L : LastUsedByAP) + LastUser[L] = P; + InversedLastUser[P].insert(LastUsedByAP.begin(), LastUsedByAP.end()); + LastUsedByAP.clear(); } } @@ -850,11 +855,6 @@ void PMTopLevelManager::initializeAllAnalysisInfo() { // Initailize other pass managers for (PMDataManager *IPM : IndirectPassManagers) IPM->initializeAnalysisInfo(); - - for (auto LU : LastUser) { - SmallPtrSet<Pass *, 8> &L = InversedLastUser[LU.second]; - L.insert(LU.first); - } } /// Destructor @@ -1151,6 +1151,8 @@ Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) { // Print list of passes that are last used by P. void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{ + if (PassDebugging < Details) + return; SmallVector<Pass *, 12> LUses; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits