Skip to content

Commit 3fa9e42

Browse files
committed
[RemoveDIs] Update all docs to use debug records
1 parent 8afa6cf commit 3fa9e42

9 files changed

+310
-296
lines changed

llvm/docs/AssignmentTracking.md

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The core idea is to track more information about source assignments in order
1111
and preserve enough information to be able to defer decisions about whether to
1212
use non-memory locations (register, constant) or memory locations until after
1313
middle end optimisations have run. This is in opposition to using
14-
`llvm.dbg.declare` and `llvm.dbg.value`, which is to make the decision for most
14+
`#dbg_declare` and `#dbg_value`, which is to make the decision for most
1515
variables early on, which can result in suboptimal variable locations that may
1616
be either incorrect or incomplete.
1717

@@ -26,19 +26,18 @@ except for development and testing.
2626
**Enable in Clang**: `-Xclang -fexperimental-assignment-tracking`
2727

2828
That causes Clang to get LLVM to run the pass `declare-to-assign`. The pass
29-
converts conventional debug intrinsics to assignment tracking metadata and sets
29+
converts conventional debug records to assignment tracking metadata and sets
3030
the module flag `debug-info-assignment-tracking` to the value `i1 true`. To
3131
check whether assignment tracking is enabled for a module call
3232
`isAssignmentTrackingEnabled(const Module &M)` (from `llvm/IR/DebugInfo.h`).
3333

3434
## Design and implementation
3535

36-
### Assignment markers: `llvm.dbg.assign`
36+
### Assignment markers: `#dbg_assign`
3737

38-
`llvm.dbg.value`, a conventional debug intrinsic, marks out a position in the
38+
`#dbg_value`, a conventional debug record, marks out a position in the
3939
IR where a variable takes a particular value. Similarly, Assignment Tracking
40-
marks out the position of assignments with a new intrinsic called
41-
`llvm.dbg.assign`.
40+
marks out the position of assignments with a record called `#dbg_assign`.
4241

4342
In order to know where in IR it is appropriate to use a memory location for a
4443
variable, each assignment marker must in some way refer to the store, if any
@@ -48,43 +47,37 @@ important benefit of referring to the store is that we can then build a two-way
4847
mapping of stores<->markers that can be used to find markers that need to be
4948
updated when stores are modified.
5049

51-
An `llvm.dbg.assign` marker that is not linked to any instruction signals that
50+
An `#dbg_assign` marker that is not linked to any instruction signals that
5251
the store that performed the assignment has been optimised out, and therefore
5352
the memory location will not be valid for at least some part of the program.
5453

55-
Here's the `llvm.dbg.assign` signature. Each parameter is wrapped in
56-
`MetadataAsValue`, and `Value *` type parameters are first wrapped in
57-
`ValueAsMetadata`:
54+
Here's the `#dbg_assign` signature. `Value *` type parameters are first wrapped
55+
in `ValueAsMetadata`:
5856

5957
```
60-
void @llvm.dbg.assign(Value *Value,
61-
DIExpression *ValueExpression,
62-
DILocalVariable *Variable,
63-
DIAssignID *ID,
64-
Value *Address,
65-
DIExpression *AddressExpression)
58+
#dbg_assign(Value *Value,
59+
DIExpression *ValueExpression,
60+
DILocalVariable *Variable,
61+
DIAssignID *ID,
62+
Value *Address,
63+
DIExpression *AddressExpression)
6664
```
6765

68-
The first three parameters look and behave like an `llvm.dbg.value`. `ID` is a
66+
The first three parameters look and behave like an `#dbg_value`. `ID` is a
6967
reference to a store (see next section). `Address` is the destination address
7068
of the store and it is modified by `AddressExpression`. An empty/undef/poison
7169
address means the address component has been killed (the memory address is no
7270
longer a valid location). LLVM currently encodes variable fragment information
7371
in `DIExpression`s, so as an implementation quirk the `FragmentInfo` for
7472
`Variable` is contained within `ValueExpression` only.
7573

76-
The formal LLVM-IR signature is:
77-
```
78-
void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
79-
```
80-
8174
### Instruction link: `DIAssignID`
8275

8376
`DIAssignID` metadata is the mechanism that is currently used to encode the
8477
store<->marker link. The metadata node has no operands and all instances are
8578
`distinct`; equality is checked for by comparing addresses.
8679

87-
`llvm.dbg.assign` intrinsics use a `DIAssignID` metadata node instance as an
80+
`#dbg_assign` records use a `DIAssignID` metadata node instance as an
8881
operand. This way it refers to any store-like instruction that has the same
8982
`DIAssignID` attachment. E.g. For this test.cpp,
9083

@@ -102,9 +95,9 @@ we get:
10295
define dso_local noundef i32 @_Z3funi(i32 noundef %a) #0 !dbg !8 {
10396
entry:
10497
%a.addr = alloca i32, align 4, !DIAssignID !13
105-
call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(), metadata !13, metadata i32* %a.addr, metadata !DIExpression()), !dbg !15
98+
#dbg_assign(i1 undef, !14, !DIExpression(), !13, i32* %a.addr, !DIExpression(), !15)
10699
store i32 %a, i32* %a.addr, align 4, !DIAssignID !16
107-
call void @llvm.dbg.assign(metadata i32 %a, metadata !14, metadata !DIExpression(), metadata !16, metadata i32* %a.addr, metadata !DIExpression()), !dbg !15
100+
#dbg_assign(i32 %a, !14, !DIExpression(), !16, i32* %a.addr, !DIExpression(), !15)
108101
%0 = load i32, i32* %a.addr, align 4, !dbg !17
109102
ret i32 %0, !dbg !18
110103
}
@@ -116,16 +109,16 @@ entry:
116109
!16 = distinct !DIAssignID()
117110
```
118111

119-
The first `llvm.dbg.assign` refers to the `alloca` through `!DIAssignID !13`,
112+
The first `#dbg_assign` refers to the `alloca` through `!DIAssignID !13`,
120113
and the second refers to the `store` through `!DIAssignID !16`.
121114

122115
### Store-like instructions
123116

124-
In the absence of a linked `llvm.dbg.assign`, a store to an address that is
117+
In the absence of a linked `#dbg_assign`, a store to an address that is
125118
known to be the backing storage for a variable is considered to represent an
126119
assignment to that variable.
127120

128-
This gives us a safe fall-back in cases where `llvm.dbg.assign` intrinsics have
121+
This gives us a safe fall-back in cases where `#dbg_assign` records have
129122
been deleted, the `DIAssignID` attachment on the store has been dropped, or the
130123
optimiser has made a once-indirect store (not tracked with Assignment Tracking)
131124
direct.
@@ -139,61 +132,61 @@ direct.
139132
instruction. In this case, the assignment is considered to take place in
140133
multiple positions in the program.
141134

142-
**Moving** a non-debug instruction: nothing new to do. Instructions linked to an
143-
`llvm.dbg.assign` have their initial IR position marked by the position of the
144-
`llvm.dbg.assign`.
135+
**Moving** a non-debug instruction: nothing new to do. Instructions linked to a
136+
`#dbg_assign` have their initial IR position marked by the position of the
137+
`#dbg_assign`.
145138

146139
**Deleting** a non-debug instruction: nothing new to do. Simple DSE does not
147140
require any change; it’s safe to delete an instruction with a `DIAssignID`
148-
attachment. An `llvm.dbg.assign` that uses a `DIAssignID` that is not attached
141+
attachment. A `#dbg_assign` that uses a `DIAssignID` that is not attached
149142
to any instruction indicates that the memory location isn’t valid.
150143

151144
**Merging** stores: In many cases no change is required as `DIAssignID`
152145
attachments are automatically merged if `combineMetadata` is called. One way or
153146
another, the `DIAssignID` attachments must be merged such that new store
154-
becomes linked to all the `llvm.dbg.assign` intrinsics that the merged stores
147+
becomes linked to all the `#dbg_assign` records that the merged stores
155148
were linked to. This can be achieved simply by calling a helper function
156149
`Instruction::mergeDIAssignID`.
157150

158-
**Inlining** stores: As stores are inlined we generate `llvm.dbg.assign`
159-
intrinsics and `DIAssignID` attachments as if the stores represent source
151+
**Inlining** stores: As stores are inlined we generate `#dbg_assign`
152+
records and `DIAssignID` attachments as if the stores represent source
160153
assignments, just like the in frontend. This isn’t perfect, as stores may have
161154
been moved, modified or deleted before inlining, but it does at least keep the
162155
information about the variable correct within the non-inlined scope.
163156

164-
**Splitting** stores: SROA and passes that split stores treat `llvm.dbg.assign`
165-
intrinsics similarly to `llvm.dbg.declare` intrinsics. Clone the
166-
`llvm.dbg.assign` intrinsics linked to the store, update the FragmentInfo in
167-
the `ValueExpression`, and give the split stores (and cloned intrinsics) new
157+
**Splitting** stores: SROA and passes that split stores treat `#dbg_assign`
158+
records similarly to `#dbg_declare` records. Clone the
159+
`#dbg_assign` records linked to the store, update the FragmentInfo in
160+
the `ValueExpression`, and give the split stores (and cloned records) new
168161
`DIAssignID` attachments each. In other words, treat the split stores as
169162
separate assignments. For partial DSE (e.g. shortening a memset), we do the
170-
same except that `llvm.dbg.assign` for the dead fragment gets an `Undef`
163+
same except that `#dbg_assign` for the dead fragment gets an `Undef`
171164
`Address`.
172165

173-
**Promoting** allocas and store/loads: `llvm.dbg.assign` intrinsics implicitly
166+
**Promoting** allocas and store/loads: `#dbg_assign` records implicitly
174167
describe joined values in memory locations at CFG joins, but this is not
175168
necessarily the case after promoting (or partially promoting) the
176169
variable. Passes that promote variables are responsible for inserting
177-
`llvm.dbg.assign` intrinsics after the resultant PHIs generated during
178-
promotion. `mem2reg` already has to do this (with `llvm.dbg.value`) for
179-
`llvm.dbg.declare`s. Where a store has no linked intrinsic, the store is
170+
`#dbg_assign` records after the resultant PHIs generated during
171+
promotion. `mem2reg` already has to do this (with `#dbg_value`) for
172+
`#dbg_declare`s. Where a store has no linked record, the store is
180173
assumed to represent an assignment for variables stored at the destination
181174
address.
182175

183-
#### Debug intrinsic updates
176+
#### Debug record updates
184177

185-
**Moving** a debug intrinsic: avoid moving `llvm.dbg.assign` intrinsics where
178+
**Moving** a debug record: avoid moving `#dbg_assign` records where
186179
possible, as they represent a source-level assignment, whose position in the
187180
program should not be affected by optimization passes.
188181

189-
**Deleting** a debug intrinsic: Nothing new to do. Just like for conventional
190-
debug intrinsics, unless it is unreachable, it’s almost always incorrect to
191-
delete a `llvm.dbg.assign` intrinsic.
182+
**Deleting** a debug record: Nothing new to do. Just like for conventional
183+
debug records, unless it is unreachable, it’s almost always incorrect to
184+
delete a `#dbg_assign` record.
192185

193-
### Lowering `llvm.dbg.assign` to MIR
186+
### Lowering `#dbg_assign` to MIR
194187

195-
To begin with only SelectionDAG ISel will be supported. `llvm.dbg.assign`
196-
intrinsics are lowered to MIR `DBG_INSTR_REF` instructions. Before this happens
188+
To begin with only SelectionDAG ISel will be supported. `#dbg_assign`
189+
records are lowered to MIR `DBG_INSTR_REF` instructions. Before this happens
197190
we need to decide where it is appropriate to use memory locations and where we
198191
must use a non-memory location (or no location) for each variable. In order to
199192
make those decisions we run a standard fixed-point dataflow analysis that makes
@@ -214,9 +207,9 @@ to tackle:
214207
clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp for examples.
215208

216209
* `trackAssignments` doesn't yet work for variables that have their
217-
`llvm.dbg.declare` location modified by a `DIExpression`, e.g. when the
210+
`#dbg_declare` location modified by a `DIExpression`, e.g. when the
218211
address of the variable is itself stored in an `alloca` with the
219-
`llvm.dbg.declare` using `DIExpression(DW_OP_deref)`. See `indirectReturn` in
212+
`#dbg_declare` using `DIExpression(DW_OP_deref)`. See `indirectReturn` in
220213
llvm/test/DebugInfo/Generic/assignment-tracking/track-assignments.ll and in
221214
clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp for an
222215
example.
@@ -225,13 +218,13 @@ to tackle:
225218
memory location is available without using a `DIAssignID`. This is because
226219
the storage address is not computed by an instruction (it's an argument
227220
value) and therefore we have nowhere to put the metadata attachment. To solve
228-
this we probably need another marker intrinsic to denote "the variable's
229-
stack home is X address" - similar to `llvm.dbg.declare` except that it needs
230-
to compose with `llvm.dbg.assign` intrinsics such that the stack home address
231-
is only selected as a location for the variable when the `llvm.dbg.assign`
232-
intrinsics agree it should be.
221+
this we probably need another marker record to denote "the variable's
222+
stack home is X address" - similar to `#dbg_declare` except that it needs
223+
to compose with `#dbg_assign` records such that the stack home address
224+
is only selected as a location for the variable when the `#dbg_assign`
225+
records agree it should be.
233226

234-
* Given the above (a special "the stack home is X" intrinsic), and the fact
227+
* Given the above (a special "the stack home is X" record), and the fact
235228
that we can only track assignments with fixed offsets and sizes, I think we
236229
can probably get rid of the address and address-expression part, since it
237230
will always be computable with the info we have.

llvm/docs/HowToUpdateDebugInfo.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Deleting an IR-level Instruction
151151

152152
When an ``Instruction`` is deleted, its debug uses change to ``undef``. This is
153153
a loss of debug info: the value of one or more source variables becomes
154-
unavailable, starting with the ``llvm.dbg.value(undef, ...)``. When there is no
154+
unavailable, starting with the ``#dbg_value(undef, ...)``. When there is no
155155
way to reconstitute the value of the lost instruction, this is the best
156156
possible outcome. However, it's often possible to do better:
157157

@@ -172,7 +172,7 @@ possible outcome. However, it's often possible to do better:
172172
define i16 @foo(i16 %a) {
173173
%b = sext i16 %a to i32
174174
%c = and i32 %b, 15
175-
call void @llvm.dbg.value(metadata i32 %c, ...)
175+
#dbg_value(i32 %c, ...)
176176
%d = trunc i32 %c to i16
177177
ret i16 %d
178178
}
@@ -183,7 +183,7 @@ replaced with a simplified instruction:
183183
.. code-block:: llvm
184184
185185
define i16 @foo(i16 %a) {
186-
call void @llvm.dbg.value(metadata i32 undef, ...)
186+
#dbg_value(i32 undef, ...)
187187
%simplified = and i16 %a, 15
188188
ret i16 %simplified
189189
}
@@ -204,7 +204,7 @@ This results in better debug info because the debug use of ``%c`` is preserved:
204204
205205
define i16 @foo(i16 %a) {
206206
%simplified = and i16 %a, 15
207-
call void @llvm.dbg.value(metadata i16 %simplified, ...)
207+
#dbg_value(i16 %simplified, ...)
208208
ret i16 %simplified
209209
}
210210
@@ -249,7 +249,7 @@ module, and the second checks that this DI is still available after an
249249
optimization has occurred, reporting any errors/warnings while doing so.
250250

251251
The instructions are assigned sequentially increasing line locations, and are
252-
immediately used by debug value intrinsics everywhere possible.
252+
immediately used by debug value records everywhere possible.
253253

254254
For example, here is a module before:
255255

@@ -271,10 +271,10 @@ and after running ``opt -debugify``:
271271
define void @f(i32* %x) !dbg !6 {
272272
entry:
273273
%x.addr = alloca i32*, align 8, !dbg !12
274-
call void @llvm.dbg.value(metadata i32** %x.addr, metadata !9, metadata !DIExpression()), !dbg !12
274+
#dbg_value(i32** %x.addr, !9, !DIExpression(), !12)
275275
store i32* %x, i32** %x.addr, align 8, !dbg !13
276276
%0 = load i32*, i32** %x.addr, align 8, !dbg !14
277-
call void @llvm.dbg.value(metadata i32* %0, metadata !11, metadata !DIExpression()), !dbg !14
277+
#dbg_value(i32* %0, !11, !DIExpression(), !14)
278278
store i32 10, i32* %0, align 4, !dbg !15
279279
ret void, !dbg !16
280280
}
@@ -409,7 +409,7 @@ as follows:
409409
$ clang -Xclang -fverify-debuginfo-preserve -Xclang -fverify-debuginfo-preserve-export=sample.json -g -O2 sample.c
410410
411411
Please do note that there are some known false positives, for source locations
412-
and debug intrinsic checking, so that will be addressed as a future work.
412+
and debug reecord checking, so that will be addressed as a future work.
413413

414414
Mutation testing for MIR-level transformations
415415
----------------------------------------------

llvm/docs/InstrRefDebugInfo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ referring to instruction values:
2424

2525
```llvm
2626
%2 = add i32 %0, %1
27-
call void @llvm.dbg.value(metadata i32 %2,
27+
#dbg_value(metadata i32 %2,
2828
```
2929

3030
In LLVM IR, the IR Value is synonymous with the instruction that computes the

0 commit comments

Comments
 (0)