@@ -6752,161 +6752,23 @@ parameter, and it will be included in the ``retainedNodes:`` field of its
67526752 type: !3)
67536753 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
67546754
6755- .. _DIExpression:
6756-
67576755DIExpression
67586756""""""""""""
67596757
67606758``DIExpression`` nodes represent expressions that are inspired by the DWARF
6761- expression language. They are used in :ref:`debug records <debugrecords>`
6762- (such as ``#dbg_declare`` and ``#dbg_value``) to describe how the
6763- referenced LLVM variable relates to the source language variable. Debug
6764- expressions are interpreted left-to-right: start by pushing the value/address
6765- operand of the record onto a stack, then repeatedly push and evaluate
6766- opcodes from the ``DIExpression`` until the final variable description is produced.
6767-
6768- The current supported opcode vocabulary is limited:
6769-
6770- - ``DW_OP_deref`` dereferences the top of the expression stack.
6771- - ``DW_OP_plus`` pops the last two entries from the expression stack, adds
6772- them together and appends the result to the expression stack.
6773- - ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
6774- the last entry from the second last entry and appends the result to the
6775- expression stack.
6776- - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
6777- - ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
6778- here, respectively) of the variable fragment from the working expression. Note
6779- that contrary to ``DW_OP_bit_piece``, the offset is describing the location
6780- within the described source variable.
6781- - ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
6782- (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
6783- expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
6784- that references a base type constructed from the supplied values.
6785- - ``DW_OP_LLVM_extract_bits_sext, 16, 8,`` specifies the offset and size
6786- (``16`` and ``8`` here, respectively) of bits that are to be extracted and
6787- sign-extended from the value at the top of the expression stack. If the top of
6788- the expression stack is a memory location then these bits are extracted from
6789- the value pointed to by that memory location. Maps into a ``DW_OP_shl``
6790- followed by ``DW_OP_shra``.
6791- - ``DW_OP_LLVM_extract_bits_zext`` behaves similarly to
6792- ``DW_OP_LLVM_extract_bits_sext``, but zero-extends instead of sign-extending.
6793- Maps into a ``DW_OP_shl`` followed by ``DW_OP_shr``.
6794- - ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
6795- optionally applied to the pointer. The memory tag is derived from the
6796- given tag offset in an implementation-defined manner.
6797- - ``DW_OP_swap`` swaps top two stack entries.
6798- - ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
6799- of the stack is treated as an address. The second stack entry is treated as an
6800- address space identifier.
6801- - ``DW_OP_stack_value`` marks a constant value.
6802- - ``DW_OP_LLVM_entry_value, N`` refers to the value a register had upon
6803- function entry. When targeting DWARF, a ``DBG_VALUE(reg, ...,
6804- DIExpression(DW_OP_LLVM_entry_value, 1, ...)`` is lowered to
6805- ``DW_OP_entry_value [reg], ...``, which pushes the value ``reg`` had upon
6806- function entry onto the DWARF expression stack.
6807-
6808- The next ``(N - 1)`` operations will be part of the ``DW_OP_entry_value``
6809- block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 1,
6810- DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an expression where
6811- the entry value of ``reg`` is pushed onto the stack, and is added with 123.
6812- Due to framework limitations ``N`` must be 1, in other words,
6813- ``DW_OP_entry_value`` always refers to the value/address operand of the
6814- instruction.
6815-
6816- Because ``DW_OP_LLVM_entry_value`` is defined in terms of registers, it is
6817- usually used in MIR, but it is also allowed in LLVM IR when targeting a
6818- :ref:`swiftasync <swiftasync>` argument. The operation is introduced by:
6819-
6820- - ``LiveDebugValues`` pass, which applies it to function parameters that
6821- are unmodified throughout the function. Support is limited to simple
6822- register location descriptions, or as indirect locations (e.g.,
6823- parameters passed-by-value to a callee via a pointer to a temporary copy
6824- made in the caller).
6825- - ``AsmPrinter`` pass when a call site parameter value
6826- (``DW_AT_call_site_parameter_value``) is represented as entry value of
6827- the parameter.
6828- - ``CoroSplit`` pass, which may move variables from allocas into a
6829- coroutine frame. If the coroutine frame is a
6830- :ref:`swiftasync <swiftasync>` argument, the variable is described with
6831- an ``DW_OP_LLVM_entry_value`` operation.
6832-
6833- - ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one
6834- value, such as one that calculates the sum of two registers. This is always
6835- used in combination with an ordered list of values, such that
6836- ``DW_OP_LLVM_arg, N`` refers to the ``N``\ :sup:`th` element in that list. For
6837- example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
6838- DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to
6839- ``%reg1 - reg2``. This list of values should be provided by the containing
6840- intrinsic/instruction.
6841- - ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
6842- signed offset of the specified register. The opcode is only generated by the
6843- ``AsmPrinter`` pass to describe call site parameter value which requires an
6844- expression over two registers.
6845- - ``DW_OP_push_object_address`` pushes the address of the object which can then
6846- serve as a descriptor in subsequent calculation. This opcode can be used to
6847- calculate bounds of an Fortran allocatable array which has array descriptors.
6848- - ``DW_OP_over`` duplicates the entry currently second in the stack at the top
6849- of the stack. This opcode can be used to calculate bounds of a Fortran assumed
6850- rank array which has rank known at run time and current dimension number is
6851- implicitly first element of the stack.
6852- - ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can
6853- be used to represent pointer variables which are optimized out but the value
6854- it points to is known. This operator is required as it is different than DWARF
6855- operator ``DW_OP_implicit_pointer`` in representation and specification (number
6856- and types of operands) and later can not be used as multiple level.
6857-
6858- .. code-block:: text
6759+ expression language. They are used in :ref:`debug records <debug_records>`
6760+ (such as ``#dbg_declare`` and ``#dbg_value``) to describe how the referenced
6761+ LLVM variable relates to the source language variable.
68596762
6860- IR for "*ptr = 4;"
6861- --------------
6862- #dbg_value(i32 4, !17, !DIExpression(DW_OP_LLVM_implicit_pointer), !20)
6863- !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
6864- type: !18)
6865- !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
6866- !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6867- !20 = !DILocation(line: 10, scope: !12)
6868-
6869- IR for "**ptr = 4;"
6870- --------------
6871- #dbg_value(i32 4, !17,
6872- !DIExpression(DW_OP_LLVM_implicit_pointer, DW_OP_LLVM_implicit_pointer),
6873- !21)
6874- !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
6875- type: !18)
6876- !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
6877- !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
6878- !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6879- !21 = !DILocation(line: 10, scope: !12)
6880-
6881- DWARF specifies three kinds of simple location descriptions: Register, memory,
6882- and implicit location descriptions. Note that a location description is
6883- defined over certain ranges of a program, i.e the location of a variable may
6884- change over the course of the program. Register and memory location
6885- descriptions describe the *concrete location* of a source variable (in the
6886- sense that a debugger might modify its value), whereas *implicit locations*
6887- describe merely the actual *value* of a source variable which might not exist
6888- in registers or in memory (see ``DW_OP_stack_value``).
6889-
6890- A ``#dbg_declare`` record describes an indirect value (the address) of a
6891- source variable. The first operand of the record must be an address of some
6892- kind. A ``DIExpression`` operand to the record refines this address to produce a
6893- concrete location for the source variable.
6894-
6895- A ``#dbg_value`` record describes the direct value of a source variable.
6896- The first operand of the record may be a direct or indirect value. A
6897- ``DIExpression`` operand to the record refines the first operand to produce a
6898- direct value. For example, if the first operand is an indirect value, it may be
6899- necessary to insert ``DW_OP_deref`` into the ``DIExpression`` in order to produce a
6900- valid debug record.
6763+ See :ref:`diexpression` for details.
69016764
69026765.. note::
69036766
6904- A ``DIExpression`` is interpreted in the same way regardless of which kind of
6905- debug record it's attached to.
6906-
6907- ``DIExpressions`` are always printed and parsed inline; they can never be
6767+ ``DIExpression``\s are always printed and parsed inline; they can never be
69086768 referenced by an ID (e.g. ``!1``).
69096769
6770+ Some examples of expressions:
6771+
69106772.. code-block:: text
69116773
69126774 !DIExpression(DW_OP_deref)
0 commit comments