[llvm] [MemProf] Print full context hash when reporting hinted bytes (PR #114465)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 11:33:29 PST 2024
================
@@ -181,21 +178,55 @@ void CallStackTrie::addCallStack(MDNode *MIB) {
assert(StackId);
CallStack.push_back(StackId->getZExtValue());
}
- addCallStack(getMIBAllocType(MIB), CallStack, getMIBTotalSize(MIB));
+ std::vector<ContextTotalSize> ContextSizeInfo;
+ // Collect the context size information if it exists.
+ if (MIB->getNumOperands() > 2) {
+ for (unsigned I = 2; I < MIB->getNumOperands(); I++) {
+ MDNode *ContextSizePair = dyn_cast<MDNode>(MIB->getOperand(I));
+ assert(ContextSizePair->getNumOperands() == 2);
+ uint64_t FullStackId =
+ mdconst::dyn_extract<ConstantInt>(ContextSizePair->getOperand(0))
+ ->getZExtValue();
+ uint64_t TotalSize =
+ mdconst::dyn_extract<ConstantInt>(ContextSizePair->getOperand(1))
+ ->getZExtValue();
+ ContextSizeInfo.push_back({FullStackId, TotalSize});
+ }
+ }
+ addCallStack(getMIBAllocType(MIB), CallStack, std::move(ContextSizeInfo));
}
static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
- AllocationType AllocType, uint64_t TotalSize) {
+ AllocationType AllocType,
+ ArrayRef<ContextTotalSize> ContextSizeInfo) {
SmallVector<Metadata *> MIBPayload(
{buildCallstackMetadata(MIBCallStack, Ctx)});
MIBPayload.push_back(
MDString::get(Ctx, getAllocTypeAttributeString(AllocType)));
- if (TotalSize)
- MIBPayload.push_back(ValueAsMetadata::get(
- ConstantInt::get(Type::getInt64Ty(Ctx), TotalSize)));
+ if (!ContextSizeInfo.empty()) {
+ for (auto Info : ContextSizeInfo) {
+ auto *FullStackIdMD = ValueAsMetadata::get(
+ ConstantInt::get(Type::getInt64Ty(Ctx), Info.FullStackId));
+ auto *TotalSizeMD = ValueAsMetadata::get(
+ ConstantInt::get(Type::getInt64Ty(Ctx), Info.TotalSize));
+ auto *ContextSizeMD = MDNode::get(Ctx, {FullStackIdMD, TotalSizeMD});
+ MIBPayload.push_back(ContextSizeMD);
+ }
+ }
return MDNode::get(Ctx, MIBPayload);
}
+void CallStackTrie::collectContextSizeInfo(
+ CallStackTrieNode *Node, std::vector<ContextTotalSize> &ContextSizeInfo) {
+ ContextSizeInfo.insert(ContextSizeInfo.end(), Node->ContextSizeInfo.begin(),
+ Node->ContextSizeInfo.end());
+ if (Node->Callers.empty())
+ return;
----------------
teresajohnson wrote:
removed, and removed extraneous braces below.
https://github.com/llvm/llvm-project/pull/114465
More information about the llvm-commits
mailing list