summaryrefslogtreecommitdiffstats
path: root/llvm/docs
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-09-20 21:52:33 +0000
committerReid Kleckner <rnk@google.com>2017-09-20 21:52:33 +0000
commit3f547e87b2cdd148c0429ddda48fdeeb111b527d (patch)
tree8eec0bb5535f40c9328bb90dc12844e56c31e8c2 /llvm/docs
parent047cbee1e77e545c0f1a32b7a1eae113f87deb71 (diff)
downloadbcm5719-llvm-3f547e87b2cdd148c0429ddda48fdeeb111b527d.tar.gz
bcm5719-llvm-3f547e87b2cdd148c0429ddda48fdeeb111b527d.zip
[IR] Add llvm.dbg.addr, a control-dependent version of llvm.dbg.declare
Summary: This implements the design discussed on llvm-dev for better tracking of variables that live in memory through optimizations: http://lists.llvm.org/pipermail/llvm-dev/2017-September/117222.html This is tracked as PR34136 llvm.dbg.addr is intended to be produced and used in almost precisely the same way as llvm.dbg.declare is today, with the exception that it is control-dependent. That means that dbg.addr should always have a position in the instruction stream, and it will allow passes that optimize memory operations on local variables to insert llvm.dbg.value calls to reflect deleted stores. See SourceLevelDebugging.rst for more details. The main drawback to generating DBG_VALUE machine instrs is that they usually cause LLVM to emit a location list for DW_AT_location. The next step will be to teach DwarfDebug.cpp how to recognize more DBG_VALUE ranges as not needing a location list, and possibly start setting DW_AT_start_offset for variables whose lifetimes begin mid-scope. Reviewers: aprantl, dblaikie, probinson Subscribers: eraman, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D37768 llvm-svn: 313825
Diffstat (limited to 'llvm/docs')
-rw-r--r--llvm/docs/SourceLevelDebugging.rst62
1 files changed, 47 insertions, 15 deletions
diff --git a/llvm/docs/SourceLevelDebugging.rst b/llvm/docs/SourceLevelDebugging.rst
index ee4c5ce8bce..c46b51c4d81 100644
--- a/llvm/docs/SourceLevelDebugging.rst
+++ b/llvm/docs/SourceLevelDebugging.rst
@@ -171,35 +171,64 @@ Debugger intrinsic functions
----------------------------
LLVM uses several intrinsic functions (name prefixed with "``llvm.dbg``") to
-provide debug information at various points in generated code.
+track source local variables through optimization and code generation.
-``llvm.dbg.declare``
+``llvm.dbg.addr``
^^^^^^^^^^^^^^^^^^^^
.. code-block:: llvm
- void @llvm.dbg.declare(metadata, metadata, metadata)
+ void @llvm.dbg.addr(metadata, metadata, metadata)
-This intrinsic provides information about a local element (e.g., variable). The
-first argument is metadata holding the alloca for the variable. The second
-argument is a `local variable <LangRef.html#dilocalvariable>`_ containing a
-description of the variable. The third argument is a `complex expression
-<LangRef.html#diexpression>`_. An `llvm.dbg.declare` instrinsic describes the
-*location* of a source variable.
+This intrinsic provides information about a local element (e.g., variable).
+The first argument is metadata holding the address of variable, typically a
+static alloca in the function entry block. The second argument is a
+`local variable <LangRef.html#dilocalvariable>`_ containing a description of
+the variable. The third argument is a `complex expression
+<LangRef.html#diexpression>`_. An `llvm.dbg.addr` intrinsic describes the
+*address* of a source variable.
.. code-block:: llvm
%i.addr = alloca i32, align 4
- call void @llvm.dbg.declare(metadata i32* %i.addr, metadata !1, metadata !2), !dbg !3
+ call void @llvm.dbg.addr(metadata i32* %i.addr, metadata !1,
+ metadata !DIExpression()), !dbg !2
!1 = !DILocalVariable(name: "i", ...) ; int i
- !2 = !DIExpression()
- !3 = !DILocation(...)
+ !2 = !DILocation(...)
...
%buffer = alloca [256 x i8], align 8
; The address of i is buffer+64.
- call void @llvm.dbg.declare(metadata [256 x i8]* %buffer, metadata !1, metadata !2)
- !1 = !DILocalVariable(name: "i", ...) ; int i
- !2 = !DIExpression(DW_OP_plus, 64)
+ call void @llvm.dbg.addr(metadata [256 x i8]* %buffer, metadata !3,
+ metadata !DIExpression(DW_OP_plus, 64)), !dbg !4
+ !3 = !DILocalVariable(name: "i", ...) ; int i
+ !4 = !DILocation(...)
+
+A frontend should generate exactly one call to ``llvm.dbg.addr`` at the point
+of declaration of a source variable. Optimization passes that fully promote the
+variable from memory to SSA values will replace this call with possibly
+multiple calls to `llvm.dbg.value`. Passes that delete stores are effectively
+partial promotion, and they will insert a mix of calls to ``llvm.dbg.value``
+and ``llvm.dbg.addr`` to track the source variable value when it is available.
+After optimization, there may be multiple calls to ``llvm.dbg.addr`` describing
+the program points where the variables lives in memory. All calls for the same
+concrete source variable must agree on the memory location.
+
+
+``llvm.dbg.declare``
+^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: llvm
+
+ void @llvm.dbg.declare(metadata, metadata, metadata)
+
+This intrinsic is identical to `llvm.dbg.addr`, except that there can only be
+one call to `llvm.dbg.declare` for a given concrete `local variable
+<LangRef.html#dilocalvariable>`_. It is not control-dependent, meaning that if
+a call to `llvm.dbg.declare` exists and has a valid location argument, that
+address is considered to be the true home of the variable across its entire
+lifetime. This makes it hard for optimizations to preserve accurate debug info
+in the presence of ``llvm.dbg.declare``, so we are transitioning away from it,
+and we plan to deprecate it in future LLVM releases.
``llvm.dbg.value``
@@ -242,6 +271,9 @@ following C fragment, for example:
8. X = Y;
9. }
+.. FIXME: Update the following example to use llvm.dbg.addr once that is the
+ default in clang.
+
Compiled to LLVM, this function would be represented like this:
.. code-block:: text
OpenPOWER on IntegriCloud