[llvm] 5fd82ca - [MemProf] Make hasSingleAllocType helper non-static
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 12:00:14 PST 2023
Author: Teresa Johnson
Date: 2023-02-21T12:00:03-08:00
New Revision: 5fd82ca05b46487dfc73ffc06153aa3886975727
URL: https://github.com/llvm/llvm-project/commit/5fd82ca05b46487dfc73ffc06153aa3886975727
DIFF: https://github.com/llvm/llvm-project/commit/5fd82ca05b46487dfc73ffc06153aa3886975727.diff
LOG: [MemProf] Make hasSingleAllocType helper non-static
As suggested in D140908, make the hasSingleAllocType helper non-static
so that it can be used in other files. Add unit testing.
Differential Revision: https://reviews.llvm.org/D144318
Added:
Modified:
llvm/include/llvm/Analysis/MemoryProfileInfo.h
llvm/lib/Analysis/MemoryProfileInfo.cpp
llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/MemoryProfileInfo.h b/llvm/include/llvm/Analysis/MemoryProfileInfo.h
index 2ca396bf1453f..51fc6e02788a8 100644
--- a/llvm/include/llvm/Analysis/MemoryProfileInfo.h
+++ b/llvm/include/llvm/Analysis/MemoryProfileInfo.h
@@ -37,6 +37,9 @@ MDNode *getMIBStackNode(const MDNode *MIB);
/// Returns the allocation type from an MIB metadata node.
AllocationType getMIBAllocType(const MDNode *MIB);
+/// True if the AllocTypes bitmask contains just a single type.
+bool hasSingleAllocType(uint8_t AllocTypes);
+
/// Class to build a trie of call stack contexts for a particular profiled
/// allocation call, along with their associated allocation types.
/// The allocation will be at the root of the trie, which is then used to
diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 2f36ece35195c..e7284da2163b8 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -91,7 +91,7 @@ static void addAllocTypeAttribute(LLVMContext &Ctx, CallBase *CI,
CI->addFnAttr(A);
}
-static bool hasSingleAllocType(uint8_t AllocTypes) {
+bool llvm::memprof::hasSingleAllocType(uint8_t AllocTypes) {
const unsigned NumAllocTypes = llvm::popcount(AllocTypes);
assert(NumAllocTypes != 0);
return NumAllocTypes == 1;
diff --git a/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp b/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
index 096295eb3f2d6..ff07666ef8325 100644
--- a/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
+++ b/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
@@ -86,6 +86,15 @@ TEST_F(MemoryProfileInfoTest, GetAllocType) {
AllocationType::NotCold);
}
+// Test the hasSingleAllocType helper.
+TEST_F(MemoryProfileInfoTest, SingleAllocType) {
+ uint8_t NotCold = (uint8_t)AllocationType::NotCold;
+ uint8_t Cold = (uint8_t)AllocationType::Cold;
+ EXPECT_TRUE(hasSingleAllocType(NotCold));
+ EXPECT_TRUE(hasSingleAllocType(Cold));
+ EXPECT_FALSE(hasSingleAllocType(NotCold | Cold));
+}
+
// Test buildCallstackMetadata helper.
TEST_F(MemoryProfileInfoTest, BuildCallStackMD) {
LLVMContext C;
More information about the llvm-commits
mailing list