Skip to content

Commit

Permalink
[ThinLTO] Add lookup to ImportListsTy (llvm#109036)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kazutakahirata authored and tmsri committed Sep 19, 2024
1 parent 19ff2ad commit a7e2133
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions llvm/include/llvm/Transforms/IPO/FunctionImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,28 @@ 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;
const_iterator begin() const { return ListsImpl.begin(); }
const_iterator end() const { return ListsImpl.end(); }

private:
ImportMapTy EmptyList;
DenseMap<StringRef, ImportMapTy> ListsImpl;
ImportIDTable ImportIDs;
};
Expand Down

0 comments on commit a7e2133

Please sign in to comment.