[GlobalDCE] Use DenseMap instead of unordered_multimap for GVDependencies.

Summary:
std::unordered_multimap happens to be very slow when the number of elements
grows large. On one of our internal applications we observed a 17x compile time
improvement from changing it to DenseMap.

Reviewers: mehdi_amini, serge-sans-paille, davide

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D38916

llvm-svn: 316045
This commit is contained in:
Michael Zolotukhin 2017-10-17 23:47:06 +00:00
parent c03ceb92ca
commit c4fcc189d2
2 changed files with 4 additions and 4 deletions

View File

@ -35,7 +35,7 @@ private:
SmallPtrSet<GlobalValue*, 32> AliveGlobals;
/// Global -> Global that uses this global.
std::unordered_multimap<GlobalValue *, GlobalValue *> GVDependencies;
DenseMap<GlobalValue *, SmallPtrSet<GlobalValue *, 4>> GVDependencies;
/// Constant -> Globals that use this global cache.
std::unordered_map<Constant *, SmallPtrSet<GlobalValue *, 8>>

View File

@ -115,7 +115,7 @@ void GlobalDCEPass::UpdateGVDependencies(GlobalValue &GV) {
ComputeDependencies(User, Deps);
Deps.erase(&GV); // Remove self-reference.
for (GlobalValue *GVU : Deps) {
GVDependencies.insert(std::make_pair(GVU, &GV));
GVDependencies[GVU].insert(&GV);
}
}
@ -199,8 +199,8 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &MAM) {
AliveGlobals.end()};
while (!NewLiveGVs.empty()) {
GlobalValue *LGV = NewLiveGVs.pop_back_val();
for (auto &&GVD : make_range(GVDependencies.equal_range(LGV)))
MarkLive(*GVD.second, &NewLiveGVs);
for (auto *GVD : GVDependencies[LGV])
MarkLive(*GVD, &NewLiveGVs);
}
// Now that all globals which are needed are in the AliveGlobals set, we loop