47
47
#ifndef LLVM_IR_DEBUGPROGRAMINSTRUCTION_H
48
48
#define LLVM_IR_DEBUGPROGRAMINSTRUCTION_H
49
49
50
- #include " llvm/ADT/ilist_node.h"
51
50
#include " llvm/ADT/ilist.h"
51
+ #include " llvm/ADT/ilist_node.h"
52
52
#include " llvm/ADT/iterator.h"
53
53
#include " llvm/IR/DebugLoc.h"
54
+ #include " llvm/IR/Instruction.h"
55
+ #include " llvm/IR/SymbolTableListTraits.h"
54
56
55
57
namespace llvm {
56
58
@@ -91,6 +93,9 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
91
93
void removeFromParent ();
92
94
void eraseFromParent ();
93
95
96
+ DPValue *getNextNode () { return &*std::next (getIterator ()); }
97
+ DPValue *getPrevNode () { return &*std::prev (getIterator ()); }
98
+
94
99
using self_iterator = simple_ilist<DPValue>::iterator;
95
100
using const_self_iterator = simple_ilist<DPValue>::const_iterator;
96
101
@@ -118,6 +123,17 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
118
123
DPValue (Metadata *Location, DILocalVariable *DV, DIExpression *Expr,
119
124
const DILocation *DI, LocationType Type = LocationType::Value);
120
125
126
+ static DPValue *createDPValue (Value *Location, DILocalVariable *DV,
127
+ DIExpression *Expr, const DILocation *DI);
128
+ static DPValue *createDPValue (Value *Location, DILocalVariable *DV,
129
+ DIExpression *Expr, const DILocation *DI,
130
+ DPValue &InsertBefore);
131
+ static DPValue *createDPVDeclare (Value *Address, DILocalVariable *DV,
132
+ DIExpression *Expr, const DILocation *DI);
133
+ static DPValue *createDPVDeclare (Value *Address, DILocalVariable *DV,
134
+ DIExpression *Expr, const DILocation *DI,
135
+ DPValue &InsertBefore);
136
+
121
137
// / Iterator for ValueAsMetadata that internally uses direct pointer iteration
122
138
// / over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
123
139
// / ValueAsMetadata .
@@ -166,6 +182,9 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
166
182
}
167
183
};
168
184
185
+ bool isDbgDeclare () { return Type == LocationType::Declare; }
186
+ bool isDbgValue () { return Type == LocationType::Value; }
187
+
169
188
// / Get the locations corresponding to the variable referenced by the debug
170
189
// / info intrinsic. Depending on the intrinsic, this could be the
171
190
// / variable's value or its address.
@@ -209,6 +228,10 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
209
228
210
229
Metadata *getRawLocation () const { return DebugValue; }
211
230
231
+ Value *getValue (unsigned OpIdx = 0 ) const {
232
+ return getVariableLocationOp (OpIdx);
233
+ }
234
+
212
235
// / Use of this should generally be avoided; instead,
213
236
// / replaceVariableLocationOp and addVariableLocationOps should be used where
214
237
// / possible to avoid creating invalid state.
@@ -224,6 +247,19 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
224
247
// / is described.
225
248
std::optional<uint64_t > getFragmentSizeInBits () const ;
226
249
250
+ bool isEquivalentTo (const DPValue &Other) {
251
+ return std::tie (Type, DebugValue, Variable, Expression, DbgLoc) ==
252
+ std::tie (Other.Type , Other.DebugValue , Other.Variable ,
253
+ Other.Expression , Other.DbgLoc );
254
+ }
255
+ // Matches the definition of the Instruction version, equivalent to above but
256
+ // without checking DbgLoc.
257
+ bool isIdenticalToWhenDefined (const DPValue &Other) {
258
+ return std::tie (Type, DebugValue, Variable, Expression) ==
259
+ std::tie (Other.Type , Other.DebugValue , Other.Variable ,
260
+ Other.Expression );
261
+ }
262
+
227
263
DPValue *clone () const ;
228
264
// / Convert this DPValue back into a dbg.value intrinsic.
229
265
// / \p InsertBefore Optional position to insert this intrinsic.
@@ -251,6 +287,13 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
251
287
LLVMContext &getContext ();
252
288
const LLVMContext &getContext () const ;
253
289
290
+ // / Insert this DPValue prior to \p InsertBefore. Must not be called if this
291
+ // / is already contained in a DPMarker.
292
+ void insertBefore (DPValue *InsertBefore);
293
+ void insertAfter (DPValue *InsertAfter);
294
+ void moveBefore (DPValue *MoveBefore);
295
+ void moveAfter (DPValue *MoveAfter);
296
+
254
297
void print (raw_ostream &O, bool IsForDebug = false ) const ;
255
298
void print (raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const ;
256
299
};
@@ -309,6 +352,8 @@ class DPMarker {
309
352
310
353
// / Produce a range over all the DPValues in this Marker.
311
354
iterator_range<simple_ilist<DPValue>::iterator> getDbgValueRange ();
355
+ iterator_range<simple_ilist<DPValue>::const_iterator>
356
+ getDbgValueRange () const ;
312
357
// / Transfer any DPValues from \p Src into this DPMarker. If \p InsertAtHead
313
358
// / is true, place them before existing DPValues, otherwise afterwards.
314
359
void absorbDebugValues (DPMarker &Src, bool InsertAtHead);
@@ -320,6 +365,10 @@ class DPMarker {
320
365
// / Insert a DPValue into this DPMarker, at the end of the list. If
321
366
// / \p InsertAtHead is true, at the start.
322
367
void insertDPValue (DPValue *New, bool InsertAtHead);
368
+ // / Insert a DPValue prior to a DPValue contained within this marker.
369
+ void insertDPValue (DPValue *New, DPValue *InsertBefore);
370
+ // / Insert a DPValue after a DPValue contained within this marker.
371
+ void insertDPValueAfter (DPValue *New, DPValue *InsertAfter);
323
372
// / Clone all DPMarkers from \p From into this marker. There are numerous
324
373
// / options to customise the source/destination, due to gnarliness, see class
325
374
// / comment.
0 commit comments