Skip to content

Commit e61d606

Browse files
[LTO] Turn ImportListsTy into a proper class (NFC) (#106427)
This patch turns ImportListsTy into a class that wraps DenseMap<StringRef, ImportMapTy>. Here is the background. I'm planning to reduce the memory footprint of ThinLTO indexing. Specifically, ImportMapTy, the list of imports for a given destination module, will be a hash set of integer IDs indexing into a deduplication table of pairs (SourceModule, GUID), which is a lot like string interning. I'm planning to put this deduplication table as part of ImportListsTy and have each instance of ImportMapTy hold a reference to the deduplication table. Another reason to wrap the DenseMap is that I need to intercept operator[]() so that I can construct an instance of ImportMapTy with a reference to the deduplication table. Note that the default implementation of operator[]() would default-construct ImportMapTy, which I am going to disable.
1 parent 2d1fba6 commit e61d606

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

llvm/include/llvm/Transforms/IPO/FunctionImport.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,24 @@ class FunctionImporter {
150150
};
151151

152152
// A map from destination modules to lists of imports.
153-
using ImportListsTy = DenseMap<StringRef, ImportMapTy>;
153+
class ImportListsTy {
154+
public:
155+
ImportListsTy() = default;
156+
ImportListsTy(size_t Size) : ListsImpl(Size) {}
157+
158+
ImportMapTy &operator[](StringRef DestMod) {
159+
return ListsImpl.try_emplace(DestMod).first->second;
160+
}
161+
162+
size_t size() const { return ListsImpl.size(); }
163+
164+
using const_iterator = DenseMap<StringRef, ImportMapTy>::const_iterator;
165+
const_iterator begin() const { return ListsImpl.begin(); }
166+
const_iterator end() const { return ListsImpl.end(); }
167+
168+
private:
169+
DenseMap<StringRef, ImportMapTy> ListsImpl;
170+
};
154171

155172
/// The set contains an entry for every global value that the module exports.
156173
/// Depending on the user context, this container is allowed to contain

0 commit comments

Comments
 (0)