@@ -69,6 +69,53 @@ class DPMarker;
69
69
class DPValue ;
70
70
class raw_ostream ;
71
71
72
+ // / A typed tracking MDNode reference that does not require a definition for its
73
+ // / parameter type. Necessary to avoid including DebugInfoMetadata.h, which has
74
+ // / a significant impact on compile times if included in this file.
75
+ template <typename T> class DbgRecordParamRef {
76
+ TrackingMDNodeRef Ref;
77
+
78
+ public:
79
+ public:
80
+ DbgRecordParamRef () = default ;
81
+
82
+ // / Construct from the templated type.
83
+ DbgRecordParamRef (const T *Param);
84
+
85
+ // / Construct from an \a MDNode.
86
+ // /
87
+ // / Note: if \c Param does not have the template type, a verifier check will
88
+ // / fail, and accessors will crash. However, construction from other nodes
89
+ // / is supported in order to handle forward references when reading textual
90
+ // / IR.
91
+ explicit DbgRecordParamRef (const MDNode *Param);
92
+
93
+ // / Get the underlying type.
94
+ // /
95
+ // / \pre !*this or \c isa<T>(getAsMDNode()).
96
+ // / @{
97
+ T *get () const ;
98
+ operator T *() const { return get (); }
99
+ T *operator ->() const { return get (); }
100
+ T &operator *() const { return *get (); }
101
+ // / @}
102
+
103
+ // / Check for null.
104
+ // /
105
+ // / Check for null in a way that is safe with broken debug info.
106
+ explicit operator bool () const { return Ref; }
107
+
108
+ // / Return \c this as a \a MDNode.
109
+ MDNode *getAsMDNode () const { return Ref; }
110
+
111
+ bool operator ==(const DbgRecordParamRef &Other) const {
112
+ return Ref == Other.Ref ;
113
+ }
114
+ bool operator !=(const DbgRecordParamRef &Other) const {
115
+ return Ref != Other.Ref ;
116
+ }
117
+ };
118
+
72
119
// / Base class for non-instruction debug metadata records that have positions
73
120
// / within IR. Features various methods copied across from the Instruction
74
121
// / class to aid ease-of-use. DbgRecords should always be linked into a
@@ -174,13 +221,10 @@ inline raw_ostream &operator<<(raw_ostream &OS, const DbgRecord &R) {
174
221
// / llvm.dbg.label intrinsic.
175
222
// / FIXME: Rename DbgLabelRecord when DPValue is renamed to DbgVariableRecord.
176
223
class DPLabel : public DbgRecord {
177
- DILabel * Label;
224
+ DbgRecordParamRef< DILabel> Label;
178
225
179
226
public:
180
- DPLabel (DILabel *Label, DebugLoc DL)
181
- : DbgRecord(LabelKind, DL), Label(Label) {
182
- assert (Label && " Unexpected nullptr" );
183
- }
227
+ DPLabel (DILabel *Label, DebugLoc DL);
184
228
185
229
DPLabel *clone () const ;
186
230
void print (raw_ostream &O, bool IsForDebug = false ) const ;
@@ -189,7 +233,8 @@ class DPLabel : public DbgRecord {
189
233
Instruction *InsertBefore) const ;
190
234
191
235
void setLabel (DILabel *NewLabel) { Label = NewLabel; }
192
- DILabel *getLabel () const { return Label; }
236
+ DILabel *getLabel () const { return Label.get (); }
237
+ MDNode *getRawLabel () const { return Label.getAsMDNode (); };
193
238
194
239
// / Support type inquiry through isa, cast, and dyn_cast.
195
240
static bool classof (const DbgRecord *E) {
@@ -224,9 +269,9 @@ class DPValue : public DbgRecord, protected DebugValueUser {
224
269
// DebugValueUser superclass instead. The referred to Value can either be a
225
270
// ValueAsMetadata or a DIArgList.
226
271
227
- TrackingMDNodeRef Variable;
228
- DIExpression * Expression;
229
- DIExpression * AddressExpression;
272
+ DbgRecordParamRef<DILocalVariable> Variable;
273
+ DbgRecordParamRef< DIExpression> Expression;
274
+ DbgRecordParamRef< DIExpression> AddressExpression;
230
275
231
276
public:
232
277
// / Create a new DPValue representing the intrinsic \p DVI, for example the
@@ -331,10 +376,6 @@ class DPValue : public DbgRecord, protected DebugValueUser {
331
376
void addVariableLocationOps (ArrayRef<Value *> NewValues,
332
377
DIExpression *NewExpr);
333
378
334
- void setVariable (DILocalVariable *NewVar);
335
-
336
- void setExpression (DIExpression *NewExpr) { Expression = NewExpr; }
337
-
338
379
unsigned getNumVariableLocationOps () const ;
339
380
340
381
bool hasArgList () const { return isa<DIArgList>(getRawLocation ()); }
@@ -349,10 +390,13 @@ class DPValue : public DbgRecord, protected DebugValueUser {
349
390
void setKillLocation ();
350
391
bool isKillLocation () const ;
351
392
352
- DILocalVariable *getVariable () const ;
353
- MDNode *getRawVariable () const { return Variable; }
393
+ void setVariable (DILocalVariable *NewVar) { Variable = NewVar; }
394
+ DILocalVariable *getVariable () const { return Variable.get (); };
395
+ MDNode *getRawVariable () const { return Variable.getAsMDNode (); }
354
396
355
- DIExpression *getExpression () const { return Expression; }
397
+ void setExpression (DIExpression *NewExpr) { Expression = NewExpr; }
398
+ DIExpression *getExpression () const { return Expression.get (); }
399
+ MDNode *getRawExpression () const { return Expression.getAsMDNode (); }
356
400
357
401
// / Returns the metadata operand for the first location description. i.e.,
358
402
// / dbg intrinsic dbg.value,declare operand and dbg.assign 1st location
@@ -401,7 +445,10 @@ class DPValue : public DbgRecord, protected DebugValueUser {
401
445
}
402
446
Metadata *getRawAssignID () const { return DebugValues[2 ]; }
403
447
DIAssignID *getAssignID () const ;
404
- DIExpression *getAddressExpression () const { return AddressExpression; }
448
+ DIExpression *getAddressExpression () const { return AddressExpression.get (); }
449
+ MDNode *getRawAddressExpression () const {
450
+ return AddressExpression.getAsMDNode ();
451
+ }
405
452
void setAddressExpression (DIExpression *NewExpr) {
406
453
AddressExpression = NewExpr;
407
454
}
0 commit comments