IR: Use DenseSet instead of DenseMap for ConstantUniqueMap; NFC
Use a DenseSet instead of a DenseMap for constants in LLVMContextImpl.
Last time I looked at this was some time before r223588, when
DenseSet<V> had no advantage over DenseMap<V,char>. After r223588,
there's a 50% memory savings.
This is all mechanical. There were little bits of missing API from
DenseSet so I added the trivial implementations:
- iterator::operator++(int)
- template <class LookupKeyT> insert_as(ValueTy, LookupKeyT)
There should be no functionality change, just reduced memory consumption
(this wasn't on a profile or anything; just a cleanup I stumbled on).
llvm-svn: 265577
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 9fe1893..d5d9038 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -48,26 +48,6 @@
NamedStructTypesUniqueID = 0;
}
-namespace {
-struct DropReferences {
- // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
- // is a Constant*.
- template <typename PairT> void operator()(const PairT &P) {
- P.second->dropAllReferences();
- }
-};
-
-// Temporary - drops pair.first instead of second.
-struct DropFirst {
- // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
- // is a Constant*.
- template<typename PairT>
- void operator()(const PairT &P) {
- P.first->dropAllReferences();
- }
-};
-}
-
LLVMContextImpl::~LLVMContextImpl() {
// NOTE: We need to delete the contents of OwnedModules, but Module's dtor
// will call LLVMContextImpl::removeModule, thus invalidating iterators into
@@ -99,14 +79,14 @@
#include "llvm/IR/Metadata.def"
// Free the constants.
- std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
- DropFirst());
- std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
- DropFirst());
- std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
- DropFirst());
- std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
- DropFirst());
+ for (auto *I : ExprConstants)
+ I->dropAllReferences();
+ for (auto *I : ArrayConstants)
+ I->dropAllReferences();
+ for (auto *I : StructConstants)
+ I->dropAllReferences();
+ for (auto *I : VectorConstants)
+ I->dropAllReferences();
ExprConstants.freeConstants();
ArrayConstants.freeConstants();
StructConstants.freeConstants();
@@ -165,10 +145,8 @@
do {
Changed = false;
- for (auto I = ArrayConstants.map_begin(), E = ArrayConstants.map_end();
- I != E; ) {
- auto *C = I->first;
- I++;
+ for (auto I = ArrayConstants.begin(), E = ArrayConstants.end(); I != E;) {
+ auto *C = *I++;
if (C->use_empty()) {
Changed = true;
C->destroyConstant();