[llvm] c526683 - [MemProf] Simplify unittest save and restore of options (#139117)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 10:57:23 PDT 2025
Author: Teresa Johnson
Date: 2025-05-08T10:57:20-07:00
New Revision: c526683c7f2cf94c9e3a55cc810a0bb90e68c646
URL: https://github.com/llvm/llvm-project/commit/c526683c7f2cf94c9e3a55cc810a0bb90e68c646
DIFF: https://github.com/llvm/llvm-project/commit/c526683c7f2cf94c9e3a55cc810a0bb90e68c646.diff
LOG: [MemProf] Simplify unittest save and restore of options (#139117)
Address post-commit review feedback for PR139092 (and fix another
instance of the same code). Save and restore option values via a saved
bool value, instead of invoking cl::ResetAllOptionOccurrences.
Added:
Modified:
llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp b/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
index 2943631150650..170dca0ebcc53 100644
--- a/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
+++ b/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
@@ -88,14 +88,17 @@ TEST_F(MemoryProfileInfoTest, GetAllocType) {
100);
// Make sure the option for detecting hot allocations is set.
+ bool OrigMemProfUseHotHints = MemProfUseHotHints;
MemProfUseHotHints = true;
+
// Test Hot
// More accesses per byte per sec than hot threshold is hot.
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
ColdTotalLifetimeThreshold + 1),
AllocationType::Hot);
- // Undo the manual set of the option above.
- cl::ResetAllOptionOccurrences();
+
+ // Restore original option value.
+ MemProfUseHotHints = OrigMemProfUseHotHints;
// Without MemProfUseHotHints (default) we should treat simply as NotCold.
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
@@ -590,12 +593,13 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
ASSERT_NE(Call, nullptr);
// Specify that all non-cold contexts should be kept.
+ bool OrigMemProfKeepAllNotColdContexts = MemProfKeepAllNotColdContexts;
MemProfKeepAllNotColdContexts = true;
Trie.buildAndAttachMIBMetadata(Call);
- // Undo the manual set of the MemProfKeepAllNotColdContexts above.
- cl::ResetAllOptionOccurrences();
+ // Restore original option value.
+ MemProfKeepAllNotColdContexts = OrigMemProfKeepAllNotColdContexts;
EXPECT_FALSE(Call->hasFnAttr("memprof"));
EXPECT_TRUE(Call->hasMetadata(LLVMContext::MD_memprof));
More information about the llvm-commits
mailing list