[PATCH] D144318: [MemProf] Make hasSingleAllocType helper non-static
Teresa Johnson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 18:48:33 PST 2023
tejohnson created this revision.
tejohnson added reviewers: snehasish, davidxl.
Herald added a subscriber: hiraditya.
Herald added a project: All.
tejohnson requested review of this revision.
Herald added a project: LLVM.
As suggested in D140908 <https://reviews.llvm.org/D140908>, make the hasSingleAllocType helper non-static
so that it can be used in other files. Add unit testing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144318
Files:
llvm/include/llvm/Analysis/MemoryProfileInfo.h
llvm/lib/Analysis/MemoryProfileInfo.cpp
llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
Index: llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
===================================================================
--- llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
+++ llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
@@ -86,6 +86,15 @@
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;
Index: llvm/lib/Analysis/MemoryProfileInfo.cpp
===================================================================
--- llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -91,7 +91,7 @@
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;
Index: llvm/include/llvm/Analysis/MemoryProfileInfo.h
===================================================================
--- llvm/include/llvm/Analysis/MemoryProfileInfo.h
+++ llvm/include/llvm/Analysis/MemoryProfileInfo.h
@@ -37,6 +37,9 @@
/// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144318.498552.patch
Type: text/x-patch
Size: 1912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230218/c92f199c/attachment.bin>
More information about the llvm-commits
mailing list