From 9c9a627190b67a435a9735ee1aead20cbb708f2b Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 17 Sep 2024 15:15:49 -0700 Subject: [PATCH] [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. --- llvm/include/llvm/Transforms/IPO/FunctionImport.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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::const_iterator; @@ -284,6 +291,7 @@ class FunctionImporter { const_iterator end() const { return ListsImpl.end(); } private: + ImportMapTy EmptyList; DenseMap ListsImpl; ImportIDTable ImportIDs; };