[llvm] [LTO] Use DenseSet in computeLTOCacheKey (NFC) (PR #105466)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 21:14:35 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From 9b040155fc425ce5a0a1d8ce39c05514f4456841 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 20 Aug 2024 13:23:11 -0700
Subject: [PATCH] [LTO] Use DenseSet in computeLTOCacheKey (NFC)
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.
---
llvm/include/llvm/LTO/LTO.h | 4 ++--
llvm/lib/LTO/LTO.cpp | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index 0781d57feb5a6..949e80a43f0e8 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -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 {
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index f69e089edf42e..cb3369d93754d 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -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
@@ -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);
};
@@ -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;
More information about the llvm-commits
mailing list