Skip to content

Commit 456f03f

Browse files
authored
Merge pull request #39123 from mshockwave/dev-debug-inst-doc-update
[doc] Update SIL.rst to reflect debug_value_addr deprecation
2 parents 0ef4bcd + f97ef0b commit 456f03f

File tree

1 file changed

+65
-49
lines changed

1 file changed

+65
-49
lines changed

docs/SIL.rst

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,11 +3493,10 @@ debug_value
34933493

34943494
debug_value %1 : $Int
34953495

3496-
This indicates that the value of a declaration with loadable type has changed
3497-
value to the specified operand. The declaration in question is identified by
3498-
the SILLocation attached to the debug_value instruction.
3499-
3500-
The operand must have loadable type.
3496+
This indicates that the value of a declaration has changed value to the
3497+
specified operand. The declaration in question is identified by either the
3498+
SILLocation attached to the debug_value instruction or the SILLocation specified
3499+
in the advanced debug variable attributes.
35013500

35023501
::
35033502

@@ -3507,47 +3506,74 @@ The operand must have loadable type.
35073506
debug-var-attr ::= 'argno' integer-literal
35083507
debug-var-attr ::= 'implicit'
35093508

3510-
::
3511-
3512-
advanced-debug-var-attr ::= '(' 'name' string-literal (',' sil-instruction-source-info)? ')'
3513-
advanced-debug-var-attr ::= 'type' sil-type
3514-
3515-
::
3516-
3517-
debug-info-expr ::= di-expr-operand (':' di-expr-operand)*
3518-
di-expr-operand ::= di-expr-operator (':' sil-operand)*
3519-
di-expr-operator ::= 'op_fragment'
3520-
35213509
There are a number of attributes that provide details about the source
35223510
variable that is being described, including the name of the
35233511
variable. For function and closure arguments ``argno`` is the number
35243512
of the function argument starting with 1. A compiler-generated source
35253513
variable will be marked ``implicit`` and optimizers are free to remove
3526-
it even in -Onone. The advanced debug variable attributes represent source
3527-
locations and type of the source variable when it was originally declared.
3528-
It is useful when we're indirectly associating the SSA value with the
3529-
source variable (via di-expression, for example) in which case SSA value's
3530-
type is different from that of source variable.
3514+
it even in -Onone.
35313515

35323516
If the '[poison]' flag is set, then all references within this debug
35333517
value will be overwritten with a sentinel at this point in the
35343518
program. This is used in debug builds when shortening non-trivial
35353519
value lifetimes to ensure the debugger cannot inspect invalid
3536-
memory. `debug_value` instructions with the poison flag are not
3537-
generated until OSSA islowered. They are not expected to be serialized
3520+
memory. ``debug_value`` instructions with the poison flag are not
3521+
generated until OSSA is lowered. They are not expected to be serialized
35383522
within the module, and the pipeline is not expected to do any
35393523
significant code motion after lowering.
35403524

3541-
Debug info expression (di-expression) is a powerful method to connect SSA
3542-
value with the source variable in an indirect fashion. For example,
3543-
we can use the ``op_fragment`` operator to specify that the SSA value
3544-
is originated from a struct field inside the source variable (which has
3545-
an aggregate data type). Di-expression in SIL works similarly to LLVM's
3546-
``!DIExpression`` metadata. Where both of them adopt a stack based
3547-
execution model to evaluate the expression. The biggest difference between
3548-
them is that LLVM always represent ``!DIExpression`` elements as 64-bit
3549-
integers, while SIL's di-expression can have elements with various types,
3550-
like AST nodes or strings. Here is an example::
3525+
::
3526+
3527+
advanced-debug-var-attr ::= '(' 'name' string-literal (',' sil-instruction-source-info)? ')'
3528+
advanced-debug-var-attr ::= 'type' sil-type
3529+
3530+
Advanced debug variable attributes represent source locations and the type of
3531+
the source variable when it was originally declared. It is useful when
3532+
we're indirectly associating the SSA value with the source variable
3533+
(via SIL DIExpression, for example) in which case SSA value's type is different
3534+
from that of source variable.
3535+
3536+
::
3537+
3538+
debug-info-expr ::= di-expr-operand (':' di-expr-operand)*
3539+
di-expr-operand ::= di-expr-operator (':' sil-operand)*
3540+
di-expr-operator ::= 'op_fragment'
3541+
di-expr-operator ::= 'op_deref'
3542+
3543+
SIL debug info expression (SIL DIExpression) is a powerful method to connect SSA
3544+
value with the source variable in an indirect fashion. Di-expression in SIL
3545+
uses a stack based execution model to evaluate the expression and apply on
3546+
the associated (SIL) SSA value before connecting it with the debug variable.
3547+
For instance, given the following SIL code::
3548+
3549+
debug_value %a : $*Int, name "x", expr op_deref
3550+
3551+
It means: "You can get the value of source variable 'x' by *dereferencing*
3552+
SSA value ``%a``". The ``op_deref`` is a SIL DIExpression operator that represents
3553+
"dereference". If there are multiple SIL DIExpression operators (or arguments), they
3554+
are evaluated from left to right::
3555+
3556+
debug_value %b : $**Int, name "y", expr op_deref:op_deref
3557+
3558+
In the snippet above, two ``op_deref`` operators will be applied on SSA value
3559+
``%b`` sequentially.
3560+
3561+
Note that normally when the SSA value has an address type, there will be a ``op_deref``
3562+
in the SIL DIExpression. Because there is no pointer in Swift so you always need to
3563+
dereference an address-type SSA value to get the value of a source variable.
3564+
However, if the SSA value is a ``alloc_stack``, the ``debug_value`` is used to indicate
3565+
the *declaration* of a source variable. Or, you can say, used to specify the location
3566+
(memory address) of the source variable. Therefore, we don't need to add a ``op_deref``
3567+
in this case::
3568+
3569+
%a = alloc_stack $Int, ...
3570+
debug_value %a : $*Int, name "my_var"
3571+
3572+
3573+
The ``op_fragment`` operator is used to specify the SSA value of a specific
3574+
field in an aggregate-type source variable. This SIL DIExpression operator takes
3575+
a field declaration -- which references the desired sub-field in source variable
3576+
-- as its argument. Here is an example::
35513577

35523578
struct MyStruct {
35533579
var x: Int
@@ -3556,23 +3582,13 @@ like AST nodes or strings. Here is an example::
35563582
...
35573583
debug_value %1 : $Int, var, (name "the_struct", loc "file.swift":8:7), type $MyStruct, expr op_fragment:#MyStruct.y, loc "file.swift":9:4
35583584

3559-
In the snippet above, source variable "the_struct" has an aggregate type ``$MyStruct`` and we use di-expression with ``op_fragment`` operator to associate ``%1`` to the ``y`` member variable inside "the_struct". Note that the extra source location directive follows rigt after ``name "the_struct"`` indicate that "the_struct" was originally declared in line 8, but not until line 9, the current ``debug_value`` instruction's source location, does member ``y`` got updated with SSA value ``%1``.
3560-
3561-
debug_value_addr
3562-
````````````````
3563-
3564-
::
3565-
3566-
sil-instruction ::= debug_value_addr sil-operand (',' debug-var-attr)* advanced-debug-var-attr* (',' 'expr' debug-info-expr)?
3567-
3568-
debug_value_addr %7 : $*SomeProtocol
3569-
3570-
This indicates that the value of a declaration with address-only type
3571-
has changed value to the specified operand. The declaration in
3572-
question is identified by the SILLocation attached to the
3573-
debug_value_addr instruction.
3585+
In the snippet above, source variable "the_struct" has an aggregate type ``$MyStruct`` and we use a SIL DIExpression with ``op_fragment`` operator to associate ``%1`` to the ``y`` member variable (via the ``#MyStruct.y`` directive) inside "the_struct".
3586+
Note that the extra source location directive follows rigt after ``name "the_struct"`` indicate that "the_struct" was originally declared in line 8, but not until line 9 -- the current ``debug_value`` instruction's source location -- does member ``y`` got updated with SSA value ``%1``.
35743587

3575-
Note that this instruction can be replaced by ``debug_value`` + di-expression operator that is equivalent to LLVM's ``DW_OP_deref``.
3588+
It is worth noting that a SIL DIExpression is similar to
3589+
`!DIExpression <https://www.llvm.org/docs/LangRef.html#diexpression>`_ in LLVM debug
3590+
info metadata. While LLVM represents ``!DIExpression`` are a list of 64-bit integers,
3591+
SIL DIExpression can have elements with various types, like AST nodes or strings.
35763592

35773593
Accessing Memory
35783594
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)