Skip to content

Commit

Permalink
[LTO] Use DenseSet in computeLTOCacheKey (NFC) (#105466)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kazutakahirata authored Aug 21, 2024
1 parent bccb227 commit d6d8243
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/LTO/LTO.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ std::string computeLTOCacheKey(
const FunctionImporter::ExportSetTy &ExportList,
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
const GVSummaryMapTy &DefinedGlobals,
const std::set<GlobalValue::GUID> &CfiFunctionDefs = {},
const std::set<GlobalValue::GUID> &CfiFunctionDecls = {});
const DenseSet<GlobalValue::GUID> &CfiFunctionDefs = {},
const DenseSet<GlobalValue::GUID> &CfiFunctionDecls = {});

namespace lto {

Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ std::string llvm::computeLTOCacheKey(
const FunctionImporter::ExportSetTy &ExportList,
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
const GVSummaryMapTy &DefinedGlobals,
const std::set<GlobalValue::GUID> &CfiFunctionDefs,
const std::set<GlobalValue::GUID> &CfiFunctionDecls) {
const DenseSet<GlobalValue::GUID> &CfiFunctionDefs,
const DenseSet<GlobalValue::GUID> &CfiFunctionDecls) {
// Compute the unique hash for this entry.
// This is based on the current compiler version, the module itself, the
// export list, the hash for every single module in the import list, the
Expand Down Expand Up @@ -237,9 +237,9 @@ std::string llvm::computeLTOCacheKey(
std::set<GlobalValue::GUID> UsedTypeIds;

auto AddUsedCfiGlobal = [&](GlobalValue::GUID ValueGUID) {
if (CfiFunctionDefs.count(ValueGUID))
if (CfiFunctionDefs.contains(ValueGUID))
UsedCfiDefs.insert(ValueGUID);
if (CfiFunctionDecls.count(ValueGUID))
if (CfiFunctionDecls.contains(ValueGUID))
UsedCfiDecls.insert(ValueGUID);
};

Expand Down Expand Up @@ -1429,8 +1429,8 @@ class InProcessThinBackend : public ThinBackendProc {
DefaultThreadPool BackendThreadPool;
AddStreamFn AddStream;
FileCache Cache;
std::set<GlobalValue::GUID> CfiFunctionDefs;
std::set<GlobalValue::GUID> CfiFunctionDecls;
DenseSet<GlobalValue::GUID> CfiFunctionDefs;
DenseSet<GlobalValue::GUID> CfiFunctionDecls;

std::optional<Error> Err;
std::mutex ErrMu;
Expand Down

0 comments on commit d6d8243

Please sign in to comment.