[PATCH] D38916: [GlobalDCE] Use DenseMap instead of unordered_multimap for GVDependencies.
Michael Zolotukhin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 13 17:54:21 PDT 2017
mzolotukhin created this revision.
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.
https://reviews.llvm.org/D38916
Files:
include/llvm/Transforms/IPO/GlobalDCE.h
lib/Transforms/IPO/GlobalDCE.cpp
Index: lib/Transforms/IPO/GlobalDCE.cpp
===================================================================
--- lib/Transforms/IPO/GlobalDCE.cpp
+++ lib/Transforms/IPO/GlobalDCE.cpp
@@ -115,7 +115,7 @@
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 @@
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
Index: include/llvm/Transforms/IPO/GlobalDCE.h
===================================================================
--- include/llvm/Transforms/IPO/GlobalDCE.h
+++ include/llvm/Transforms/IPO/GlobalDCE.h
@@ -35,7 +35,7 @@
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>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38916.119002.patch
Type: text/x-patch
Size: 1456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171014/6a431caf/attachment.bin>
More information about the llvm-commits
mailing list