Skip to content

Commit 01e5d46

Browse files
authored
[RemoveDIs] Add documentation for IR debug records (#81156)
This patch adds minimal documentation for the IR representation of the RemoveDIs model of debug info. This patch assumes that the default for all cases is still debug intrinsic functions, and so does not update all existing text to refer to debug records, but only adds a section in the LangRef and SourceLevelDebugging documents to explain the new format.
1 parent ba2236d commit 01e5d46

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
@@ -8541,7 +8542,10 @@ The LLVM instruction set consists of several different classifications
85418542
of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
85428543
instructions <binaryops>`, :ref:`bitwise binary
85438544
instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
8544-
:ref:`other instructions <otherops>`.
8545+
:ref:`other instructions <otherops>`. There are also :ref:`debug records
8546+
<debugrecords>`, which are not instructions themselves but are printed
8547+
interleaved with instructions to describe changes in the state of the program's
8548+
debug information at each position in the program's execution.
85458549

85468550
.. _terminators:
85478551

@@ -12695,6 +12699,29 @@ Example:
1269512699

1269612700
%tok = cleanuppad within %cs []
1269712701

12702+
.. _debugrecords:
12703+
12704+
Debug Records
12705+
-----------------------
12706+
12707+
Debug records appear interleaved with instructions, but are not instructions;
12708+
they are used only to define debug information, and have no effect on generated
12709+
code. They are distinguished from instructions by the use of a leading `#` and
12710+
an extra level of indentation. As an example:
12711+
12712+
.. code-block:: llvm
12713+
12714+
%inst1 = op1 %a, %b
12715+
#dbg_value(%inst1, !10, !DIExpression(), !11)
12716+
%inst2 = op2 %inst1, %c
12717+
12718+
These debug records are an optional replacement for
12719+
:ref:`debug intrinsics<dbg_intrinsics>`. Debug records will be output if the
12720+
``--write-experimental-debuginfo`` flag is passed to LLVM; it is an error for both
12721+
records and intrinsics to appear in the same module. More information about
12722+
debug records can be found in the `LLVM Source Level Debugging
12723+
<SourceLevelDebugging.html#format-common-intrinsics>`_ document.
12724+
1269812725
.. _intrinsics:
1269912726

1270012727
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)