-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MemProf] Fix when CallStackTrie has a single chain to leaf with multi alloc type #79433
Conversation
@llvm/pr-subscribers-pgo @llvm/pr-subscribers-llvm-analysis Author: None (lifengxiang1025) ChangesFix one corner case when Full diff: https://github.com/llvm/llvm-project/pull/79433.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 7fbcffc6489dcfd..7fbbc280348c079 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -244,12 +244,14 @@ bool CallStackTrie::buildAndAttachMIBMetadata(CallBase *CI) {
MIBCallStack.push_back(AllocStackId);
std::vector<Metadata *> MIBNodes;
assert(!Alloc->Callers.empty() && "addCallStack has not been called yet");
- buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
- /*CalleeHasAmbiguousCallerContext=*/true);
- assert(MIBCallStack.size() == 1 &&
- "Should only be left with Alloc's location in stack");
- CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
- return true;
+ if (buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
+ Alloc->Callers.size() > 1)) {
+ assert(MIBCallStack.size() == 1 &&
+ "Should only be left with Alloc's location in stack");
+ CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
+ return true;
+ }
+ return false;
}
template <>
|
I met one coredump when I try memprof in our benchmark. After debugging, I found there exists three same callstack with different alloc type when build one AllocTrie. I don't know why there are same callstack. So I can't write test case now. |
311548f
to
9884c20
Compare
I think the reason is that the callstack's raw address is not same but the correspond function name, line offset and column are same. This happens when compiler unrolls the loop or does other similar optimization.
|
9884c20
to
962697e
Compare
Add test case. Please review. |
Sorry for the slow reply, I have been mostly OOO for the past week.
Interesting, I do agree that llvm-profdata should merge these. @snehasish is the person most familiar with the llvm-profdata code, but he is currently OOO as well.
|
@teresajohnson Thanks for reply. How about merging this PR to fix this corner case firstly? Or you want to modify llvm-profdata directly? |
I think we should put in a fix for it now until it can be fixed in llvm-profdata. I had a suggestion on the PR. |
Sorry, I don't quite understand. What is your suggestion? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow when I left my earlier comment it didn't actually send the inline review comments.
Woops, still getting used to the PR interface. The comment was left as pending and should have been sent now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, one minor fix below.
"Should only be left with Alloc's location in stack"); | ||
CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes)); | ||
return true; | ||
if (buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes, false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document const parameter (i.e. like it currently is at head but with false instead of true).
…i alloc type (llvm#79433) Fix one corner case when `CallStackTrie` has a single chain to leaf with multi alloc type. This will cause stackIds in function summary is empty.
Fix one corner case when
CallStackTrie
has a single chain to leaf with multi alloc type. This will cause stackIds in function summary is empty.