diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index e0f301aa06dc1..a7b77d6f776a7 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -908,7 +908,8 @@ Syntax:: A function definition contains a list of basic blocks, forming the CFG (Control Flow Graph) for the function. Each basic block may optionally start with a label -(giving the basic block a symbol table entry), contains a list of instructions, +(giving the basic block a symbol table entry), contains a list of instructions +and :ref:`debug records `, and ends with a :ref:`terminator ` instruction (such as a branch or function return). If an explicit label name is not provided, a block is assigned 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 of instructions: :ref:`terminator instructions `, :ref:`binary instructions `, :ref:`bitwise binary instructions `, :ref:`memory instructions `, and -:ref:`other instructions `. +:ref:`other instructions `. There are also :ref:`debug records +`, which are not instructions themselves but are printed +interleaved with instructions to describe changes in the state of the program's +debug information at each position in the program's execution. .. _terminators: @@ -12695,6 +12699,29 @@ Example: %tok = cleanuppad within %cs [] +.. _debugrecords: + +Debug Records +----------------------- + +Debug records appear interleaved with instructions, but are not instructions; +they are used only to define debug information, and have no effect on generated +code. They are distinguished from instructions by the use of a leading `#` and +an extra level of indentation. As an example: + +.. code-block:: llvm + + %inst1 = op1 %a, %b + #dbg_value(%inst1, !10, !DIExpression(), !11) + %inst2 = op2 %inst1, %c + +These debug records are an optional replacement for +:ref:`debug intrinsics`. Debug records will be output if the +``--write-experimental-debuginfo`` flag is passed to LLVM; it is an error for both +records and intrinsics to appear in the same module. More information about +debug records can be found in the `LLVM Source Level Debugging +`_ document. + .. _intrinsics: Intrinsic Functions diff --git a/llvm/docs/SourceLevelDebugging.rst b/llvm/docs/SourceLevelDebugging.rst index e1df7c355ee09..7f7e595eb14df 100644 --- a/llvm/docs/SourceLevelDebugging.rst +++ b/llvm/docs/SourceLevelDebugging.rst @@ -167,6 +167,17 @@ conventions used by the C and C++ front-ends. Debug information descriptors are `specialized metadata nodes `_, first-class subclasses of ``Metadata``. +There are two models for defining the values of source variables at different +states of the program and tracking these values through optimization and code +generation: :ref:`intrinsic function calls `, the +current default, and :ref:`debug records `, which are a new +non-instruction-based model +(for an explanation of how this works and why it is desirable, see the +`RemoveDIs `_ document). Each module must use one or +the other; they may never be mixed within an IR module. To enable writing debug +records instead of intrinsic calls, use the flag +``--write-experimental-debuginfo``. + .. _format_common_intrinsics: Debugger intrinsic functions @@ -268,6 +279,61 @@ The formal LLVM-IR signature is: See :doc:`AssignmentTracking` for more info. +.. _debug_records: + +Debug Records +---------------------------- + +LLVM also has an alternative to intrinsic functions, debug records, which +function similarly but are not instructions. The basic syntax for debug records +is: + +.. code-block:: llvm + + #dbg_([, ]* ) + ; Using the intrinsic model, the above is equivalent to: + call void llvm.dbg.([metadata , ]*), !dbg + +A debug intrinsic function can be converted to a debug record with the +following steps: + +1. Add an extra level of indentation. +2. Replace everything prior to the intrinsic kind (declare/value/assign) with + ``#dbg_``. +3. Remove the leading ``metadata`` from the intrinsic's arguments. +4. Transfer the ``!dbg`` attachment to be an argument, dropping the leading + ``!dbg``. + +For each kind of intrinsic function, there is an equivalent debug record. + +``#dbg_declare`` +^^^^^^^^^^^^^^^^ + +.. code-block:: llvm + + #dbg_declare([Value|MDNode], DILocalVariable, DIExpression, DILocation) + +Equivalent to the ``llvm.dbg.declare`` intrinsic. + +``#dbg_value`` +^^^^^^^^^^^^^^ + +.. code-block:: llvm + + #dbg_value([Value|DIArgList|MDNode], DILocalVariable, DIExpression, DILocation) + +Equivalent to the ``llvm.dbg.value`` intrinsic. + +``#dbg_assign`` +^^^^^^^^^^^^^^^ + +.. code-block:: llvm + + #dbg_assign([Value|DIArgList|MDNode], DILocalVariable, DIExpression, + DIAssignID, [Value|MDNode], DIExpression, DILocation) + +Equivalent to the ``llvm.dbg.assign`` intrinsic. + Object lifetimes and scoping ============================