[llvm] 9c9a627 - [ThinLTO] Add lookup to ImportListsTy (#109036)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 15:15:53 PDT 2024


Author: Kazu Hirata
Date: 2024-09-17T15:15:49-07:00
New Revision: 9c9a627190b67a435a9735ee1aead20cbb708f2b

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

LOG: [ThinLTO] Add lookup to ImportListsTy (#109036)

This is primarily to unblock Rust, which could potentially use
ImportListsTy::operator[] on a module that's not in ListsImpl and
cause concurrency problems.

This patch fixes a regression in the sense that it restores
ImportListsTy::lookup, which was available when ImportListsTy was just
a plain DenseMap.

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 70739709a810ab..4b29d3f40ab7b5 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -270,13 +270,20 @@ class FunctionImporter {
   // A map from destination modules to lists of imports.
   class ImportListsTy {
   public:
-    ImportListsTy() = default;
-    ImportListsTy(size_t Size) : ListsImpl(Size) {}
+    ImportListsTy() : EmptyList(ImportIDs) {}
+    ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {}
 
     ImportMapTy &operator[](StringRef DestMod) {
       return ListsImpl.try_emplace(DestMod, ImportIDs).first->second;
     }
 
+    const ImportMapTy &lookup(StringRef DestMod) const {
+      auto It = ListsImpl.find(DestMod);
+      if (It != ListsImpl.end())
+        return It->second;
+      return EmptyList;
+    }
+
     size_t size() const { return ListsImpl.size(); }
 
     using const_iterator = DenseMap<StringRef, ImportMapTy>::const_iterator;
@@ -284,6 +291,7 @@ class FunctionImporter {
     const_iterator end() const { return ListsImpl.end(); }
 
   private:
+    ImportMapTy EmptyList;
     DenseMap<StringRef, ImportMapTy> ListsImpl;
     ImportIDTable ImportIDs;
   };


        


More information about the llvm-commits mailing list