Skip to content

Commit d6d8243

Browse files
[LTO] Use DenseSet in computeLTOCacheKey (NFC) (#105466)
The two instances of std::set are used only for membership checking purposes in computeLTOCacheKey. We do not need std::set's strengths like iterators staying valid or the ability to traverse in a sorted order. This patch changes them to DenseSet. While I am at it, this patch replaces count with contains for slightly increased readability.
1 parent bccb227 commit d6d8243

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/include/llvm/LTO/LTO.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ std::string computeLTOCacheKey(
6868
const FunctionImporter::ExportSetTy &ExportList,
6969
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
7070
const GVSummaryMapTy &DefinedGlobals,
71-
const std::set<GlobalValue::GUID> &CfiFunctionDefs = {},
72-
const std::set<GlobalValue::GUID> &CfiFunctionDecls = {});
71+
const DenseSet<GlobalValue::GUID> &CfiFunctionDefs = {},
72+
const DenseSet<GlobalValue::GUID> &CfiFunctionDecls = {});
7373

7474
namespace lto {
7575

llvm/lib/LTO/LTO.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ std::string llvm::computeLTOCacheKey(
9595
const FunctionImporter::ExportSetTy &ExportList,
9696
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
9797
const GVSummaryMapTy &DefinedGlobals,
98-
const std::set<GlobalValue::GUID> &CfiFunctionDefs,
99-
const std::set<GlobalValue::GUID> &CfiFunctionDecls) {
98+
const DenseSet<GlobalValue::GUID> &CfiFunctionDefs,
99+
const DenseSet<GlobalValue::GUID> &CfiFunctionDecls) {
100100
// Compute the unique hash for this entry.
101101
// This is based on the current compiler version, the module itself, the
102102
// export list, the hash for every single module in the import list, the
@@ -237,9 +237,9 @@ std::string llvm::computeLTOCacheKey(
237237
std::set<GlobalValue::GUID> UsedTypeIds;
238238

239239
auto AddUsedCfiGlobal = [&](GlobalValue::GUID ValueGUID) {
240-
if (CfiFunctionDefs.count(ValueGUID))
240+
if (CfiFunctionDefs.contains(ValueGUID))
241241
UsedCfiDefs.insert(ValueGUID);
242-
if (CfiFunctionDecls.count(ValueGUID))
242+
if (CfiFunctionDecls.contains(ValueGUID))
243243
UsedCfiDecls.insert(ValueGUID);
244244
};
245245

@@ -1429,8 +1429,8 @@ class InProcessThinBackend : public ThinBackendProc {
14291429
DefaultThreadPool BackendThreadPool;
14301430
AddStreamFn AddStream;
14311431
FileCache Cache;
1432-
std::set<GlobalValue::GUID> CfiFunctionDefs;
1433-
std::set<GlobalValue::GUID> CfiFunctionDecls;
1432+
DenseSet<GlobalValue::GUID> CfiFunctionDefs;
1433+
DenseSet<GlobalValue::GUID> CfiFunctionDecls;
14341434

14351435
std::optional<Error> Err;
14361436
std::mutex ErrMu;

0 commit comments

Comments
 (0)