-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILOptimizer][DebugInfo] Preliminary support for DIExpression in SROA and Mem2Reg #38736
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
Conversation
@swift-ci please test |
Build failed |
@@ -76,6 +81,7 @@ eraseFromParentWithDebugInsts(SILInstruction *inst, | |||
// Just matching what eraseFromParentWithDebugInsts is today. | |||
if (nextII == inst->getIterator()) | |||
++nextII; | |||
swift::salvageDebugInfo(inst); |
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.
Does this need to be part of the SROA PR or should this be in its own patch?
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.
My original thought was that if salvageDebugInfo is put in a separate patch (or PR), there will be no use case or test there, which is a little weird. What do you think?
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 we write a standalone test using sil-opt that runs exactly one pass that would delete an instruction? If the answer is no, then let's just keep it.
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.
Currently we're calling salvageDebugInfo inside InstructionDeleter, which will affect multiple Passes. We can first create a PR that only calls salvageDebugInfo in a single Pass then revise it to use InstructionDeleter in later PR...but I feel like it will be a little over-engineering
Build failed |
The `alloc_stack` instruction now can carry advanced debug info like source-variable-specific SIL location, type, and SIL DIExpression.
Debug variables that are marked 'implicit' on its `debug_value` instruction mean that they were generated by compiler. Optimizers are free to remove them (if it becomes a dead code, for instance) even in -Onone. Since they are barely used by users and keeping them might lead to incorrect IRGen results.
I just found that I might can split the changes regarding debug scope here to a separate PR. I'll update this accordingly later |
cd762e6
to
0dc20ba
Compare
Since that part of changes don't really affect the feature here, I'll put it in another PR that is not depending on the current series of patches |
0dc20ba
to
e9db7d7
Compare
@swift-ci please test |
Build failed |
Build failed |
e9db7d7
to
ab126dd
Compare
I was wrong about that: Without the debug scope changes it will fail on a pretty common optimization pattern (specialization on implicit-generated enum functions) despite passing all tests, so I'm bringing them back and add corresponding test cases. I've also addressed all the feedbacks on that part before they were previously detached from this PR. @swift-ci please test |
Build failed |
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.
Great, I think you've addressed all my concerns.
Build failed |
Build failed |
…A and Mem2Reg SROA and Mem2Reg now can leverage DIExpression -- op_fragment, more specifically -- to generate correct debug info for optimized SIL. Some important highlights: - The new swift::salvageDebugInfo, similar to llvm::salvageDebugInfo, tries to restore / transfer debug info from a deleted instruction. Currently I only implemented this for store instruction whose destination is an alloc_stack value. - Since we now have source-variable-specific SIL location inside a `debug_value` instruction (and its friends), this patch teaches SILCloner and SILInliner to remap the debug scope there in addition to debug scope of the instruction. - DCE now does not remove `debug_value` instruction whose associating with a function argument SSA value that is not used elsewhere. Since that SSA value will not disappear so we should keep the debug info.
ab126dd
to
9a8f2ed
Compare
So the failure on Linux buildbot was caused by uninitialized struct type information during IRGen. I think it only happens if a debug_value instruction is the first ever SIL instruction that references a certain struct type, in which case IRGen hasn't translated that type into its internal representation (e.g. RecordTypeInfo). A more sophisticated solution will be asking IRGen to resolve the type when this happens. But since this scenario is pretty rare and I don't want to add more complexity into this PR, for now I simply bails out the (LLVM) debug intrinsic generation process if this occurs, similar to our current resolution on non-fixed type. @swift-ci please test |
Thanks for adding the comment explaining this to IRGenDebugInfo. LGTM! |
Don't let debug_value instructions bail the optimization. This fixes a couple of performance regressions, which were introduced by adding more debug_value instructions (swiftlang#38736). rdar://82327743
SROA and Mem2Reg now can leverage DIExpression -- op_fragment, more
specifically -- to generate correct debug info for optimized SIL. Some
important highlights:
tries to restore / transfer debug info from a deleted instruction.
Currently I only implemented this for store instruction whose
destination is an alloc_stack value.
debug_value
instruction whose associatingwith a function argument SSA value that is not used elsewhere. Since
that SSA value will not disappear so we should keep the debug info.
NOTE: This PR is only for code review. It depends on and includes #38734 #38735 . Please merge this PR instead of the previous two.