[llvm] [MemProf] Simplify unittest save and restore of options (PR #139117)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 10:52:56 PDT 2025
https://github.com/teresajohnson created https://github.com/llvm/llvm-project/pull/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.
>From 3484ac517e2e153e465d07766d5133b016c6cda3 Mon Sep 17 00:00:00 2001
From: Teresa Johnson <tejohnson at google.com>
Date: Thu, 8 May 2025 10:49:42 -0700
Subject: [PATCH] [MemProf] Simplify unittest save and restore of options
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.
---
llvm/unittests/Analysis/MemoryProfileInfoTest.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
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