Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ThinLTO] Add lookup to ImportListsTy #109036

Merged

Conversation

kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 17, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/109036.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Transforms/IPO/FunctionImport.h (+10-2)
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;
   };

@kazutakahirata
Copy link
Contributor Author

Just for reference, this PR is in response to #106427 (comment).

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit 9c9a627 into llvm:main Sep 17, 2024
8 of 9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_ImportLists_lookup branch September 17, 2024 22:15
hamphet pushed a commit to hamphet/llvm-project that referenced this pull request Sep 18, 2024
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.
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants