Skip to content

Commit 9884c20

Browse files
[MemProf] Fix when CallStackTrie is a single chain with multi alloc type
1 parent 480cc41 commit 9884c20

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

llvm/lib/Analysis/MemoryProfileInfo.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,16 @@ bool CallStackTrie::buildAndAttachMIBMetadata(CallBase *CI) {
244244
MIBCallStack.push_back(AllocStackId);
245245
std::vector<Metadata *> MIBNodes;
246246
assert(!Alloc->Callers.empty() && "addCallStack has not been called yet");
247-
buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
248-
/*CalleeHasAmbiguousCallerContext=*/true);
249-
assert(MIBCallStack.size() == 1 &&
250-
"Should only be left with Alloc's location in stack");
251-
CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
247+
if (buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
248+
Alloc->Callers.size() > 1)) {
249+
assert(MIBCallStack.size() == 1 &&
250+
"Should only be left with Alloc's location in stack");
251+
CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
252+
} else
253+
// If there exists corner case that CallStackTrie is one chain and all node
254+
// with multi alloc type, Conservatively give it non-cold allocation type.
255+
// FIXME: Avoid this case before memory profile created.
256+
addAllocTypeAttribute(Ctx, CI, AllocationType::NotCold);
252257
return true;
253258
}
254259

0 commit comments

Comments
 (0)