[llvm] e61d606 - [LTO] Turn ImportListsTy into a proper class (NFC) (#106427)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 12:50:48 PDT 2024


Author: Kazu Hirata
Date: 2024-08-28T12:50:44-07:00
New Revision: e61d6066e2678b1244b1bcbd59a154a82acf1eb8

URL: https://github.com/llvm/llvm-project/commit/e61d6066e2678b1244b1bcbd59a154a82acf1eb8
DIFF: https://github.com/llvm/llvm-project/commit/e61d6066e2678b1244b1bcbd59a154a82acf1eb8.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
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


        


More information about the llvm-commits mailing list