-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[ThinLTO] Add lookup to ImportListsTy #109036
Conversation
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.
@llvm/pr-subscribers-llvm-transforms Author: Kazu Hirata (kazutakahirata) ChangesThis is primarily to unblock Rust, which could potentially use This patch fixes a regression in the sense that it restores Full diff: https://github.com/llvm/llvm-project/pull/109036.diff 1 Files Affected:
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;
};
|
Just for reference, this PR is in response to #106427 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
ImportListsTy() = default; | ||
ImportListsTy(size_t Size) : ListsImpl(Size) {} | ||
ImportListsTy() : EmptyList(ImportIDs) {} | ||
ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When compiling with GCC (13, in Ubuntu 24.04), this change added a rather noisy warning; as this issue is in a header, it gets printed a large number of times while building:
In file included from ../include/llvm/LTO/LTO.h:31,
from ../lib/LTO/LTO.cpp:13:
../include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy()’:
../include/llvm/Transforms/IPO/FunctionImport.h:273:33: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized]
273 | ImportListsTy() : EmptyList(ImportIDs) {}
| ^~~~~~~~~
../include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy(size_t)’:
../include/llvm/Transforms/IPO/FunctionImport.h:274:44: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized]
274 | ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {}
| ^~~~~~~~~
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.