[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
This commit is contained in:
Jay Foad 2020-11-27 17:32:01 +00:00
parent 2e080eb00a
commit 14eea6b0ec
2 changed files with 15 additions and 13 deletions

View File

@ -230,11 +230,11 @@ private:
// 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.

View File

@ -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;