[llvm] [ProfileData] Remove clear() from SampleProfileFuncOffsetTable (NFC) (PR #209301)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 13:50:00 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/209301.diff
2 Files Affected:
- (modified) llvm/include/llvm/ProfileData/SampleProfReader.h (+2-6)
- (modified) llvm/unittests/ProfileData/SampleProfTest.cpp (-8)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/209301
More information about the llvm-commits
mailing list