[llvm] [LTO] Turn ImportListsTy into a proper class (NFC) (PR #106427)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 10:56:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/106427.diff
1 Files Affected:
- (modified) llvm/include/llvm/Transforms/IPO/FunctionImport.h (+18-1)
``````````diff
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
index c06d96bbe62e22..78932c12e76ff8 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -150,7 +150,24 @@ class FunctionImporter {
};
// A map from destination modules to lists of imports.
- using ImportListsTy = DenseMap<StringRef, ImportMapTy>;
+ class ImportListsTy {
+ public:
+ ImportListsTy() = default;
+ ImportListsTy(size_t Size) : ListsImpl(Size) {}
+
+ ImportMapTy &operator[](StringRef DestMod) {
+ return ListsImpl.try_emplace(DestMod).first->second;
+ }
+
+ size_t size() const { return ListsImpl.size(); }
+
+ using const_iterator = DenseMap<StringRef, ImportMapTy>::const_iterator;
+ const_iterator begin() const { return ListsImpl.begin(); }
+ const_iterator end() const { return ListsImpl.end(); }
+
+ private:
+ DenseMap<StringRef, ImportMapTy> ListsImpl;
+ };
/// The set contains an entry for every global value that the module exports.
/// Depending on the user context, this container is allowed to contain
``````````
</details>
https://github.com/llvm/llvm-project/pull/106427
More information about the llvm-commits
mailing list