diff options
author | Kazu Hirata <kazu@google.com> | 2024-09-17 15:15:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-17 15:15:49 -0700 |
commit | 9c9a627190b67a435a9735ee1aead20cbb708f2b (patch) | |
tree | 3c642ee4f2ac83b1648334ef6db55a50c50ea1cd | |
parent | 04575dce434de38e0b28a2b71dd44e29caaee685 (diff) | |
download | llvm-9c9a627190b67a435a9735ee1aead20cbb708f2b.zip llvm-9c9a627190b67a435a9735ee1aead20cbb708f2b.tar.gz llvm-9c9a627190b67a435a9735ee1aead20cbb708f2b.tar.bz2 |
[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.
-rw-r--r-- | llvm/include/llvm/Transforms/IPO/FunctionImport.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h index 7073970..4b29d3f 100644 --- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h +++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h @@ -270,13 +270,20 @@ public: // 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 @@ public: const_iterator end() const { return ListsImpl.end(); } private: + ImportMapTy EmptyList; DenseMap<StringRef, ImportMapTy> ListsImpl; ImportIDTable ImportIDs; }; |