[llvm] 6b7b8d3 - [SampleProfile] Replace std::set with SmallVector in SortedCallTargetSet (NFC) (#208509)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 12:46:35 PDT 2026
Author: Kazu Hirata
Date: 2026-07-09T12:46:30-07:00
New Revision: 6b7b8d38d47f091d953080a354692cf4f70bfd17
URL: https://github.com/llvm/llvm-project/commit/6b7b8d38d47f091d953080a354692cf4f70bfd17
DIFF: https://github.com/llvm/llvm-project/commit/6b7b8d38d47f091d953080a354692cf4f70bfd17.diff
LOG: [SampleProfile] Replace std::set with SmallVector in SortedCallTargetSet (NFC) (#208509)
This patch replaces std::set with SmallVector and llvm::sort in
SortedCallTargetSet and sortCallTargets.
Since the keys in CallTargetMap are already guaranteed to be unique,
using std::set for sorting allocates unnecessary tree nodes on the
heap.
This patch also removes unnecessary const from return-by-value types
to enable move semantics.
Assisted-by: Antigravity
Added:
Modified:
llvm/include/llvm/ProfileData/SampleProf.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index e4f467c45c66a..b9eabcd661549 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -33,7 +33,6 @@
#include <cstdint>
#include <list>
#include <map>
-#include <set>
#include <sstream>
#include <string>
#include <system_error>
@@ -386,7 +385,7 @@ class SampleRecord {
}
};
- using SortedCallTargetSet = std::set<CallTarget, CallTargetComparator>;
+ using SortedCallTargetSet = SmallVector<CallTarget>;
using CallTargetMap = DenseMap<FunctionId, uint64_t>;
SampleRecord() = default;
@@ -443,7 +442,7 @@ class SampleRecord {
uint64_t getSamples() const { return NumSamples; }
const CallTargetMap &getCallTargets() const { return CallTargets; }
- const SortedCallTargetSet getSortedCallTargets() const {
+ SortedCallTargetSet getSortedCallTargets() const {
return sortCallTargets(CallTargets);
}
@@ -455,12 +454,9 @@ class SampleRecord {
}
/// Sort call targets in descending order of call frequency.
- static const SortedCallTargetSet
- sortCallTargets(const CallTargetMap &Targets) {
- SortedCallTargetSet SortedTargets;
- for (const auto &[Target, Frequency] : Targets) {
- SortedTargets.emplace(Target, Frequency);
- }
+ static SortedCallTargetSet sortCallTargets(const CallTargetMap &Targets) {
+ auto SortedTargets = llvm::to_vector_of<CallTarget>(Targets);
+ llvm::sort(SortedTargets, CallTargetComparator());
return SortedTargets;
}
More information about the llvm-commits
mailing list