[llvm] [ProfileData] Remove clear() from SampleProfileFuncOffsetTable (NFC) (PR #209301)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 13:49:17 PDT 2026
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/209301
This patch deletes the default constructor of
SampleProfileFuncOffsetTable and removes its clear() method.
SampleProfileFuncOffsetTable is designed to lock its operational mode
(in-memory or on-disk) strictly at construction time and remain valid
throughout its lifetime. By deleting the default constructor and
removing clear(), we ensure that an instance never enters an
uninitialized or cleared state while kept alive.
When SampleProfileReader needs to discard or reload the table, it
resets and replaces the wrapping std::optional directly instead of
clearing the table in-place.
Assisted-by: Antigravity
>From de52bd52ced3b49e6c2ee50724dd2d56113e3e92 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 13 Jul 2026 13:00:02 -0700
Subject: [PATCH] [ProfileData] Remove clear() from
SampleProfileFuncOffsetTable (NFC)
This patch deletes the default constructor of
SampleProfileFuncOffsetTable and removes its clear() method.
SampleProfileFuncOffsetTable is designed to lock its operational mode
(in-memory or on-disk) strictly at construction time and remain valid
throughout its lifetime. By deleting the default constructor and
removing clear(), we ensure that an instance never enters an
uninitialized or cleared state while kept alive.
When SampleProfileReader needs to discard or reload the table, it
resets and replaces the wrapping std::optional directly instead of
clearing the table in-place.
Assisted-by: Antigravity
---
llvm/include/llvm/ProfileData/SampleProfReader.h | 8 ++------
llvm/unittests/ProfileData/SampleProfTest.cpp | 8 --------
2 files changed, 2 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index 94ac079882582..826997ab71661 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -942,6 +942,8 @@ class SampleProfileFuncOffsetTable {
using OnDiskTableType =
llvm::OnDiskIterableChainedHashTable<FuncOffsetHashTableInfo>;
+ SampleProfileFuncOffsetTable() = delete;
+
explicit SampleProfileFuncOffsetTable(InMemoryModeT,
size_t InitialCapacity = 0) {
InMemoryTable.reserve(InitialCapacity);
@@ -976,12 +978,6 @@ class SampleProfileFuncOffsetTable {
return std::nullopt;
}
- /// Clear the in-memory map and release the on-disk table.
- void clear() {
- InMemoryTable.clear();
- OnDiskTable.reset();
- }
-
private:
llvm::DenseMap<hash_code, uint64_t> InMemoryTable;
std::unique_ptr<OnDiskTableType> OnDiskTable;
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp
index b874d9722c51e..e52bbdb069ff0 100644
--- a/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -608,10 +608,6 @@ TEST_F(SampleProfTest, SampleProfileFuncOffsetTableInMemory) {
EXPECT_EQ(Table.lookup(0x11112222ULL), 100);
EXPECT_EQ(Table.lookup(0x33334444ULL), 200);
EXPECT_EQ(Table.lookup(0x55556666ULL), std::nullopt);
-
- // Test clear
- Table.clear();
- EXPECT_EQ(Table.lookup(0x11112222ULL), std::nullopt);
}
TEST_F(SampleProfTest, SampleProfileFuncOffsetTableOnDisk) {
@@ -651,10 +647,6 @@ TEST_F(SampleProfTest, SampleProfileFuncOffsetTableOnDisk) {
// Test non-existent key
EXPECT_EQ(Table.lookup(0x9999999999999999ULL), std::nullopt);
-
- // Test clear
- Table.clear();
- EXPECT_EQ(Table.lookup(0x1111111122222222ULL), std::nullopt);
}
// Verify that requesting format version 103 results in a version 103 profile.
More information about the llvm-commits
mailing list