-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DebugInfo] Adding DIExpression into SIL #38378
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
I'll add test cases shortly |
I'll squash all the commits into one right before it's ready to merge (or I can do it right now if you prefer) |
@swift-ci test |
@swift-ci please test |
Build failed |
Build failed |
045a0ae
to
d8eef9e
Compare
@swift-ci please test |
6e7f798
to
bff2c61
Compare
Add documentations |
Thanks, this is looking great! It would be good to also have test cases for the Verifier assertions that are added by this patch. |
@jckarter Do you have any opinion on the proposed SIL syntax extension? |
Currently the debug info infrastructure inside SIL can only associate a source variable with a single (simple) SSA value. Which is insufficient to preserve (correct) debug info across SIL-level optimizations -- for example, SROA that decompose or even eliminate aggregate-type obejcts. By adding DIExpression into SIL, we are able to reconstruct the connection between a source variable and its SSA value counterpart, even across optimizations. This patch adds such support into in-memory representation for SIL instructions and the SILParser/Printer. The following patch will add changes for the IRGen part.
This patch is primarily doing two things: - Teach IRGen for some of the instructions to generate debug info based on SILDebugVariable rather than AST node, which is not always available when reading from SIL. - Generate corresponding `llvm.dbg.*` intrinsics and `!DIExpression` from the newly added SIL DIExpression.
bff2c61
to
b363bbd
Compare
Sorry I almost missed this comment. @swift-ci please test |
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.
This PR adds DIExpression infrastructure into SIL.
Previously, we can not use
debug_value
to mark the updated (SIL) SSA of a sub-field inside an aggregate-type source variable. For example:In this snippet we are not able to generate a correct LLVM debug info for
%5
usingdebug_value
ordebug_value_addr
. Because the current SIL debug infrastructure lacks the equivalent feature of LLVM's!DIExpression
. More specifically, theDW_OP_fragment
operator.This is not a problem in
-Onone
, but an outstanding one in optimized build where optimizations -- SROA for example -- might break an aggregate-type object apart or even eliminate the original aggregate type. In which case the debug info quality for variable values will degrade.This PR (when it's finished) essentially adds functionalities similar to
!DIExpression
at the SIL level. Take the code above as the example, we're now able to generate the following SIL:Here are the new parameters / features added to
debug_value
/debug_value_addr
:loc
andscope
directives inside the parens enclosingname
), which represents the source location where it was originally declared. If this extra info is absent, the instruction's source location will be used.type
directive can be used to indicate the type where the debug variable was originally declared. If this info is absent, the type of the SSA value (i.e.%5
in this case) will be used.expr
directive is used to carry the DIExpression that basically has a one-to-one mapping to LLVM's!DIExpression
. Currently we only haveop_fragment
andop_deref
operator, corresponding toDW_OP_LLVM_fragment
andDW_OP_deref
, respectively.The part that is slightly controversial is probably how we carry these extra information on in-memory representation for the affected SIL instructions. This change will make
SILDebugVariable
, the class that represents debug variable and used by all debug-info-carrying instructions (including thealloc_*
family), more expensive. Luckily most of the timeSILDebugVariable
is generated on-demand (it is actually not stored inside aforementioned SIL instructions) so hopefully it won't affect conventional SIL instruction transformations (like copying or moving SIL instructions).I'm splitting this PR into two commits: The first commit add DIExpression support into SIL instructions classes (e.g.
DebugValueInst
) and changes regarding SILParser / SILPrinter; The second one add IRGen support.