Skip to content

Commit 039260c

Browse files
author
git apple-llvm automerger
committed
Merge commit '01e5d4609bed' from llvm.org/main into next
2 parents adf6b97 + 01e5d46 commit 039260c

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

llvm/docs/LangRef.rst

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,8 @@ Syntax::
908908

909909
A function definition contains a list of basic blocks, forming the CFG (Control
910910
Flow Graph) for the function. Each basic block may optionally start with a label
911-
(giving the basic block a symbol table entry), contains a list of instructions,
911+
(giving the basic block a symbol table entry), contains a list of instructions
912+
and :ref:`debug records <debugrecords>`,
912913
and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
913914
function return). If an explicit label name is not provided, a block is assigned
914915
an implicit numbered label, using the next value from the same counter as used
@@ -8595,7 +8596,10 @@ The LLVM instruction set consists of several different classifications
85958596
of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
85968597
instructions <binaryops>`, :ref:`bitwise binary
85978598
instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
8598-
:ref:`other instructions <otherops>`.
8599+
:ref:`other instructions <otherops>`. There are also :ref:`debug records
8600+
<debugrecords>`, which are not instructions themselves but are printed
8601+
interleaved with instructions to describe changes in the state of the program's
8602+
debug information at each position in the program's execution.
85998603

86008604
.. _terminators:
86018605

@@ -12749,6 +12753,29 @@ Example:
1274912753

1275012754
%tok = cleanuppad within %cs []
1275112755

12756+
.. _debugrecords:
12757+
12758+
Debug Records
12759+
-----------------------
12760+
12761+
Debug records appear interleaved with instructions, but are not instructions;
12762+
they are used only to define debug information, and have no effect on generated
12763+
code. They are distinguished from instructions by the use of a leading `#` and
12764+
an extra level of indentation. As an example:
12765+
12766+
.. code-block:: llvm
12767+
12768+
%inst1 = op1 %a, %b
12769+
#dbg_value(%inst1, !10, !DIExpression(), !11)
12770+
%inst2 = op2 %inst1, %c
12771+
12772+
These debug records are an optional replacement for
12773+
:ref:`debug intrinsics<dbg_intrinsics>`. Debug records will be output if the
12774+
``--write-experimental-debuginfo`` flag is passed to LLVM; it is an error for both
12775+
records and intrinsics to appear in the same module. More information about
12776+
debug records can be found in the `LLVM Source Level Debugging
12777+
<SourceLevelDebugging.html#format-common-intrinsics>`_ document.
12778+
1275212779
.. _intrinsics:
1275312780

1275412781
Intrinsic Functions

llvm/docs/SourceLevelDebugging.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ conventions used by the C and C++ front-ends.
167167
Debug information descriptors are `specialized metadata nodes
168168
<LangRef.html#specialized-metadata>`_, first-class subclasses of ``Metadata``.
169169

170+
There are two models for defining the values of source variables at different
171+
states of the program and tracking these values through optimization and code
172+
generation: :ref:`intrinsic function calls <format_common_intrinsics>`, the
173+
current default, and :ref:`debug records <debug_records>`, which are a new
174+
non-instruction-based model
175+
(for an explanation of how this works and why it is desirable, see the
176+
`RemoveDIs <RemoveDIsDebugInfo.html>`_ document). Each module must use one or
177+
the other; they may never be mixed within an IR module. To enable writing debug
178+
records instead of intrinsic calls, use the flag
179+
``--write-experimental-debuginfo``.
180+
170181
.. _format_common_intrinsics:
171182

172183
Debugger intrinsic functions
@@ -268,6 +279,61 @@ The formal LLVM-IR signature is:
268279
269280
See :doc:`AssignmentTracking` for more info.
270281

282+
.. _debug_records:
283+
284+
Debug Records
285+
----------------------------
286+
287+
LLVM also has an alternative to intrinsic functions, debug records, which
288+
function similarly but are not instructions. The basic syntax for debug records
289+
is:
290+
291+
.. code-block:: llvm
292+
293+
#dbg_<kind>([<arg>, ]* <DILocation>)
294+
; Using the intrinsic model, the above is equivalent to:
295+
call void llvm.dbg.<kind>([metadata <arg>, ]*), !dbg <DILocation>
296+
297+
A debug intrinsic function can be converted to a debug record with the
298+
following steps:
299+
300+
1. Add an extra level of indentation.
301+
2. Replace everything prior to the intrinsic kind (declare/value/assign) with
302+
``#dbg_``.
303+
3. Remove the leading ``metadata`` from the intrinsic's arguments.
304+
4. Transfer the ``!dbg`` attachment to be an argument, dropping the leading
305+
``!dbg``.
306+
307+
For each kind of intrinsic function, there is an equivalent debug record.
308+
309+
``#dbg_declare``
310+
^^^^^^^^^^^^^^^^
311+
312+
.. code-block:: llvm
313+
314+
#dbg_declare([Value|MDNode], DILocalVariable, DIExpression, DILocation)
315+
316+
Equivalent to the ``llvm.dbg.declare`` intrinsic.
317+
318+
``#dbg_value``
319+
^^^^^^^^^^^^^^
320+
321+
.. code-block:: llvm
322+
323+
#dbg_value([Value|DIArgList|MDNode], DILocalVariable, DIExpression, DILocation)
324+
325+
Equivalent to the ``llvm.dbg.value`` intrinsic.
326+
327+
``#dbg_assign``
328+
^^^^^^^^^^^^^^^
329+
330+
.. code-block:: llvm
331+
332+
#dbg_assign([Value|DIArgList|MDNode], DILocalVariable, DIExpression,
333+
DIAssignID, [Value|MDNode], DIExpression, DILocation)
334+
335+
Equivalent to the ``llvm.dbg.assign`` intrinsic.
336+
271337
Object lifetimes and scoping
272338
============================
273339

0 commit comments

Comments
 (0)