-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[KeyInstr][Clang] Ret atom #134652
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
[KeyInstr][Clang] Ret atom #134652
Conversation
Keeping in draft till the patches below this in the stack are merged, as this touches all their tests. Unfortunately the diff is going to be messed up till then too due to various branch retargeting and rebasing. |
CGDebugInfo::completeFunction was added previously but mistakenly not called (dropped through the cracks while putting together the patch stack). Moved out of llvm#134652 and llvm#134654.
CGDebugInfo::completeFunction was added previously but mistakenly not called (dropped through the cracks while putting together the patch stack). Moved out of #134652 and #134654. This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
a13e2d5
to
93a95dd
Compare
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.
Ready for review
- Add parameter
RetKeyInstructionsSourceAtom
inEmitFunctionEpilog
to request aret
gets a specific atomGroup number throughaddInstToSpecificSourceAtom
Most of the updated tests just check for any atom on the ret, but the two tests added in this PR check for specific atom numbers.
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.
If I understand correctly, most of the test changes are to ensure that return instructions get /an/ atom group, without being specific about which? IMO it'd be better to make that number explicit to avoid a return accidentally being part of the wrong atom group. It's necessary for it to be a distinct group, right? (A chore, but an important fact).
clang/lib/CodeGen/CGCleanup.cpp
Outdated
@@ -1118,6 +1118,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) { | ||
|
||
// Create the branch. | ||
llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock()); | ||
// This is the primary instruction for this atom, acting in place of a ret. |
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.
I think in isolation this comment will be hard to understand, particularly relating it to a ret
. Perhaps "this atom" -> "the source atom leaving this scope"?
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.
The code below has since been added in another patch that's already landed (without the comment) - rebased to remove from diff
__builtin_va_start(list, z); | ||
// CHECK: vaarg.end: | ||
// CHECK-NEXT: %vaarg.addr = phi ptr | ||
// CHECK-NEXT: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]] |
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.
Why's this memcpy getting the same atom group as the return?
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.
The comment from test return.c covers this case:
// Check the stores to `retval` allocas and branches to `return` block are in
// the same atom group. They are both rank 1, which could in theory introduce
// an extra step in some optimized code. This low risk currently feels an
// acceptable for keeping the code a bit simpler (as opposed to adding
// scaffolding to make the store rank 2).
(But in this case the "store to retval" is a memcpy).
We want them in the same group because these are all instructions generated from the source return some_value
.
// Also check that in the case of a single return (no control flow) the | ||
// return instruction inherits the atom group of the branch to the return | ||
// block when the blocks get folded togather. |
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.
Could you remark on which test function this is, as I couldn't spot it. Presumably the folding happens in clang, rather than being something done by LLVM?
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.
Yep in Clang - here
if (ReturnBlock.getBlock()->hasOneUse()) { |
This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. The Key Instructions project is introduced, including a "quick summary" section at the top which adds context for this PR, here: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed. The Clang-side work is demoed here: #130943
…d fixup some tests
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.
If I understand correctly, most of the test changes are to ensure that return instructions get /an/ atom group, without being specific about which? IMO it'd be better to make that number explicit to avoid a return accidentally being part of the wrong atom group. It's necessary for it to be a distinct group, right? (A chore, but an important fact).
Done. Rebased (to address an inline comment and capture since-merged tests).
clang/lib/CodeGen/CGCleanup.cpp
Outdated
@@ -1118,6 +1118,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) { | ||
|
||
// Create the branch. | ||
llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock()); | ||
// This is the primary instruction for this atom, acting in place of a ret. |
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.
The code below has since been added in another patch that's already landed (without the comment) - rebased to remove from diff
// Also check that in the case of a single return (no control flow) the | ||
// return instruction inherits the atom group of the branch to the return | ||
// block when the blocks get folded togather. |
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.
Yep in Clang - here
if (ReturnBlock.getBlock()->hasOneUse()) { |
__builtin_va_start(list, z); | ||
// CHECK: vaarg.end: | ||
// CHECK-NEXT: %vaarg.addr = phi ptr | ||
// CHECK-NEXT: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]] |
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.
The comment from test return.c covers this case:
// Check the stores to `retval` allocas and branches to `return` block are in
// the same atom group. They are both rank 1, which could in theory introduce
// an extra step in some optimized code. This low risk currently feels an
// acceptable for keeping the code a bit simpler (as opposed to adding
// scaffolding to make the store rank 2).
(But in this case the "store to retval" is a memcpy).
We want them in the same group because these are all instructions generated from the source return some_value
.
37c869a
to
689c1b1
Compare
CGDebugInfo::completeFunction was added previously but mistakenly not called (dropped through the cracks while putting together the patch stack). Moved out of llvm#134652 and llvm#134654. This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
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
[KeyInstr][Clang] Ret atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.
The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
The Clang-side work is demoed here:
#130943
[KeyInstr][Clang] Update tests with ret atoms