LLVM 19.0.0git
DebugProgramInstruction.h
Go to the documentation of this file.
1//===-- llvm/DebugProgramInstruction.h - Stream of debug info ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Data structures for storing variable assignment information in LLVM. In the
10// dbg.value design, a dbg.value intrinsic specifies the position in a block
11// a source variable take on an LLVM Value:
12//
13// %foo = add i32 1, %0
14// dbg.value(metadata i32 %foo, ...)
15// %bar = void call @ext(%foo);
16//
17// and all information is stored in the Value / Metadata hierachy defined
18// elsewhere in LLVM. In the "DbgRecord" design, each instruction /may/ have a
19// connection with a DbgMarker, which identifies a position immediately before
20// the instruction, and each DbgMarker /may/ then have connections to DbgRecords
21// which record the variable assignment information. To illustrate:
22//
23// %foo = add i32 1, %0
24// ; foo->DebugMarker == nullptr
25// ;; There are no variable assignments / debug records "in front" of
26// ;; the instruction for %foo, therefore it has no DebugMarker.
27// %bar = void call @ext(%foo)
28// ; bar->DebugMarker = {
29// ; StoredDbgRecords = {
30// ; DbgVariableRecord(metadata i32 %foo, ...)
31// ; }
32// ; }
33// ;; There is a debug-info record in front of the %bar instruction,
34// ;; thus it points at a DbgMarker object. That DbgMarker contains a
35// ;; DbgVariableRecord in its ilist, storing the equivalent information
36// ;; to the dbg.value above: the Value, DILocalVariable, etc.
37//
38// This structure separates the two concerns of the position of the debug-info
39// in the function, and the Value that it refers to. It also creates a new
40// "place" in-between the Value / Metadata hierachy where we can customise
41// storage and allocation techniques to better suite debug-info workloads.
42// NB: as of the initial prototype, none of that has actually been attempted
43// yet.
44//
45//===----------------------------------------------------------------------===//
46
47#ifndef LLVM_IR_DEBUGPROGRAMINSTRUCTION_H
48#define LLVM_IR_DEBUGPROGRAMINSTRUCTION_H
49
50#include "llvm/ADT/ilist.h"
51#include "llvm/ADT/ilist_node.h"
52#include "llvm/ADT/iterator.h"
53#include "llvm/IR/DebugLoc.h"
54#include "llvm/IR/Instruction.h"
57
58namespace llvm {
59
60class Instruction;
61class BasicBlock;
62class MDNode;
63class Module;
64class DbgVariableIntrinsic;
65class DbgInfoIntrinsic;
66class DbgLabelInst;
67class DIAssignID;
68class DbgMarker;
69class DbgVariableRecord;
70class raw_ostream;
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.
75template <typename T> class DbgRecordParamRef {
77
78public:
79public:
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
119/// Base class for non-instruction debug metadata records that have positions
120/// within IR. Features various methods copied across from the Instruction
121/// class to aid ease-of-use. DbgRecords should always be linked into a
122/// DbgMarker's StoredDbgRecords list. The marker connects a DbgRecord back to
123/// its position in the BasicBlock.
124///
125/// We need a discriminator for dyn/isa casts. In order to avoid paying for a
126/// vtable for "virtual" functions too, subclasses must add a new discriminator
127/// value (RecordKind) and cases to a few functions in the base class:
128/// deleteRecord
129/// clone
130/// isIdenticalToWhenDefined
131/// both print methods
132/// createDebugIntrinsic
133class DbgRecord : public ilist_node<DbgRecord> {
134public:
135 /// Marker that this DbgRecord is linked into.
136 DbgMarker *Marker = nullptr;
137 /// Subclass discriminator.
138 enum Kind : uint8_t { ValueKind, LabelKind };
139
140protected:
142 Kind RecordKind; ///< Subclass discriminator.
143
144public:
147
148 /// Methods that dispatch to subclass implementations. These need to be
149 /// manually updated when a new subclass is added.
150 ///@{
151 void deleteRecord();
152 DbgRecord *clone() const;
153 void print(raw_ostream &O, bool IsForDebug = false) const;
154 void print(raw_ostream &O, ModuleSlotTracker &MST, bool IsForDebug) const;
155 bool isIdenticalToWhenDefined(const DbgRecord &R) const;
156 /// Convert this DbgRecord back into an appropriate llvm.dbg.* intrinsic.
157 /// \p InsertBefore Optional position to insert this intrinsic.
158 /// \returns A new llvm.dbg.* intrinsic representiung this DbgRecord.
160 Instruction *InsertBefore) const;
161 ///@}
162
163 /// Same as isIdenticalToWhenDefined but checks DebugLoc too.
164 bool isEquivalentTo(const DbgRecord &R) const;
165
166 Kind getRecordKind() const { return RecordKind; }
167
168 void setMarker(DbgMarker *M) { Marker = M; }
169
171 const DbgMarker *getMarker() const { return Marker; }
172
174 const BasicBlock *getBlock() const;
175
177 const Function *getFunction() const;
178
179 Module *getModule();
180 const Module *getModule() const;
181
183 const LLVMContext &getContext() const;
184
185 const Instruction *getInstruction() const;
186 const BasicBlock *getParent() const;
188
189 void removeFromParent();
190 void eraseFromParent();
191
192 DbgRecord *getNextNode() { return &*std::next(getIterator()); }
193 DbgRecord *getPrevNode() { return &*std::prev(getIterator()); }
194 void insertBefore(DbgRecord *InsertBefore);
195 void insertAfter(DbgRecord *InsertAfter);
196 void moveBefore(DbgRecord *MoveBefore);
197 void moveAfter(DbgRecord *MoveAfter);
198
199 DebugLoc getDebugLoc() const { return DbgLoc; }
200 void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
201
202 void dump() const;
203
206
207protected:
208 /// Similarly to Value, we avoid paying the cost of a vtable
209 /// by protecting the dtor and having deleteRecord dispatch
210 /// cleanup.
211 /// Use deleteRecord to delete a generic record.
212 ~DbgRecord() = default;
213};
214
216 R.print(OS);
217 return OS;
218}
219
220/// Records a position in IR for a source label (DILabel). Corresponds to the
221/// llvm.dbg.label intrinsic.
222class DbgLabelRecord : public DbgRecord {
224
225 /// This constructor intentionally left private, so that it is only called via
226 /// "createUnresolvedDbgLabelRecord", which clearly expresses that it is for
227 /// parsing only.
228 DbgLabelRecord(MDNode *Label, MDNode *DL);
229
230public:
232
233 /// For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved
234 /// MDNodes. Trying to access the resulting DbgLabelRecord's fields before
235 /// they are resolved, or if they resolve to the wrong type, will result in a
236 /// crash.
238 MDNode *DL);
239
240 DbgLabelRecord *clone() const;
241 void print(raw_ostream &O, bool IsForDebug = false) const;
242 void print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const;
244 Instruction *InsertBefore) const;
245
246 void setLabel(DILabel *NewLabel) { Label = NewLabel; }
247 DILabel *getLabel() const { return Label.get(); }
248 MDNode *getRawLabel() const { return Label.getAsMDNode(); };
249
250 /// Support type inquiry through isa, cast, and dyn_cast.
251 static bool classof(const DbgRecord *E) {
252 return E->getRecordKind() == LabelKind;
253 }
254};
255
256/// Record of a variable value-assignment, aka a non instruction representation
257/// of the dbg.value intrinsic.
258///
259/// This class inherits from DebugValueUser to allow LLVM's metadata facilities
260/// to update our references to metadata beneath our feet.
261class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
262 friend class DebugValueUser;
263
264public:
265 enum class LocationType : uint8_t {
266 Declare,
267 Value,
268 Assign,
269
270 End, ///< Marks the end of the concrete types.
271 Any, ///< To indicate all LocationTypes in searches.
272 };
273 /// Classification of the debug-info record that this DbgVariableRecord
274 /// represents. Essentially, "does this correspond to a dbg.value,
275 /// dbg.declare, or dbg.assign?".
276 /// FIXME: We could use spare padding bits from DbgRecord for this.
278
279 // NB: there is no explicit "Value" field in this class, it's effectively the
280 // DebugValueUser superclass instead. The referred to Value can either be a
281 // ValueAsMetadata or a DIArgList.
282
286
287public:
288 /// Create a new DbgVariableRecord representing the intrinsic \p DVI, for
289 /// example the assignment represented by a dbg.value.
292 /// Directly construct a new DbgVariableRecord representing a dbg.value
293 /// intrinsic assigning \p Location to the DV / Expr / DI variable.
295 const DILocation *DI,
300 const DILocation *DI);
301
302private:
303 /// Private constructor for creating new instances during parsing only. Only
304 /// called through `createUnresolvedDbgVariableRecord` below, which makes
305 /// clear that this is used for parsing only, and will later return a subclass
306 /// depending on which Type is passed.
310
311public:
312 /// Used to create DbgVariableRecords during parsing, where some metadata
313 /// references may still be unresolved. Although for some fields a generic
314 /// `Metadata*` argument is accepted for forward type-references, the verifier
315 /// and accessors will reject incorrect types later on. The function is used
316 /// for all types of DbgVariableRecords for simplicity while parsing, but
317 /// asserts if any necessary fields are empty or unused fields are not empty,
318 /// i.e. if the #dbg_assign fields are used for a non-dbg-assign type.
319 static DbgVariableRecord *
322 MDNode *AssignID, Metadata *Address,
324
325 static DbgVariableRecord *
329 const DILocation *DI);
330 static DbgVariableRecord *
331 createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val,
334 const DILocation *DI);
335
337 DILocalVariable *DV,
338 DIExpression *Expr,
339 const DILocation *DI);
340 static DbgVariableRecord *
342 DIExpression *Expr, const DILocation *DI,
343 DbgVariableRecord &InsertBefore);
345 DILocalVariable *DV,
346 DIExpression *Expr,
347 const DILocation *DI);
348 static DbgVariableRecord *
350 const DILocation *DI, DbgVariableRecord &InsertBefore);
351
352 /// Iterator for ValueAsMetadata that internally uses direct pointer iteration
353 /// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
354 /// ValueAsMetadata .
356 : public iterator_facade_base<location_op_iterator,
357 std::bidirectional_iterator_tag, Value *> {
359
360 public:
361 location_op_iterator(ValueAsMetadata *SingleIter) : I(SingleIter) {}
362 location_op_iterator(ValueAsMetadata **MultiIter) : I(MultiIter) {}
363
366 I = R.I;
367 return *this;
368 }
370 return I == RHS.I;
371 }
372 const Value *operator*() const {
373 ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
374 ? I.get<ValueAsMetadata *>()
375 : *I.get<ValueAsMetadata **>();
376 return VAM->getValue();
377 };
379 ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
380 ? I.get<ValueAsMetadata *>()
381 : *I.get<ValueAsMetadata **>();
382 return VAM->getValue();
383 }
385 if (I.is<ValueAsMetadata *>())
386 I = I.get<ValueAsMetadata *>() + 1;
387 else
388 I = I.get<ValueAsMetadata **>() + 1;
389 return *this;
390 }
392 if (I.is<ValueAsMetadata *>())
393 I = I.get<ValueAsMetadata *>() - 1;
394 else
395 I = I.get<ValueAsMetadata **>() - 1;
396 return *this;
397 }
398 };
399
401 bool isDbgValue() { return Type == LocationType::Value; }
402
403 /// Get the locations corresponding to the variable referenced by the debug
404 /// info intrinsic. Depending on the intrinsic, this could be the
405 /// variable's value or its address.
407
408 Value *getVariableLocationOp(unsigned OpIdx) const;
409
410 void replaceVariableLocationOp(Value *OldValue, Value *NewValue,
411 bool AllowEmpty = false);
412 void replaceVariableLocationOp(unsigned OpIdx, Value *NewValue);
413 /// Adding a new location operand will always result in this intrinsic using
414 /// an ArgList, and must always be accompanied by a new expression that uses
415 /// the new operand.
418
419 unsigned getNumVariableLocationOps() const;
420
421 bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
422 /// Returns true if this DbgVariableRecord has no empty MDNodes in its
423 /// location list.
424 bool hasValidLocation() const { return getVariableLocationOp(0) != nullptr; }
425
426 /// Does this describe the address of a local variable. True for dbg.addr
427 /// and dbg.declare, but not dbg.value, which describes its value.
429 LocationType getType() const { return Type; }
430
431 void setKillLocation();
432 bool isKillLocation() const;
433
434 void setVariable(DILocalVariable *NewVar) { Variable = NewVar; }
435 DILocalVariable *getVariable() const { return Variable.get(); };
436 MDNode *getRawVariable() const { return Variable.getAsMDNode(); }
437
439 DIExpression *getExpression() const { return Expression.get(); }
440 MDNode *getRawExpression() const { return Expression.getAsMDNode(); }
441
442 /// Returns the metadata operand for the first location description. i.e.,
443 /// dbg intrinsic dbg.value,declare operand and dbg.assign 1st location
444 /// operand (the "value componenet"). Note the operand (singular) may be
445 /// a DIArgList which is a list of values.
446 Metadata *getRawLocation() const { return DebugValues[0]; }
447
448 Value *getValue(unsigned OpIdx = 0) const {
449 return getVariableLocationOp(OpIdx);
450 }
451
452 /// Use of this should generally be avoided; instead,
453 /// replaceVariableLocationOp and addVariableLocationOps should be used where
454 /// possible to avoid creating invalid state.
455 void setRawLocation(Metadata *NewLocation) {
456 assert((isa<ValueAsMetadata>(NewLocation) || isa<DIArgList>(NewLocation) ||
457 isa<MDNode>(NewLocation)) &&
458 "Location for a DbgVariableRecord must be either ValueAsMetadata or "
459 "DIArgList");
460 resetDebugValue(0, NewLocation);
461 }
462
463 /// Get the size (in bits) of the variable, or fragment of the variable that
464 /// is described.
465 std::optional<uint64_t> getFragmentSizeInBits() const;
466
468 return DbgLoc == Other.DbgLoc && isIdenticalToWhenDefined(Other);
469 }
470 // Matches the definition of the Instruction version, equivalent to above but
471 // without checking DbgLoc.
473 return std::tie(Type, DebugValues, Variable, Expression,
475 std::tie(Other.Type, Other.DebugValues, Other.Variable,
476 Other.Expression, Other.AddressExpression);
477 }
478
479 /// @name DbgAssign Methods
480 /// @{
481 bool isDbgAssign() const { return getType() == LocationType::Assign; }
482
483 Value *getAddress() const;
485 return isDbgAssign() ? DebugValues[1] : DebugValues[0];
486 }
487 Metadata *getRawAssignID() const { return DebugValues[2]; }
488 DIAssignID *getAssignID() const;
491 return AddressExpression.getAsMDNode();
492 }
495 }
496 void setAssignId(DIAssignID *New);
498 /// Kill the address component.
499 void setKillAddress();
500 /// Check whether this kills the address component. This doesn't take into
501 /// account the position of the intrinsic, therefore a returned value of false
502 /// does not guarentee the address is a valid location for the variable at the
503 /// intrinsic's position in IR.
504 bool isKillAddress() const;
505
506 /// @}
507
508 DbgVariableRecord *clone() const;
509 /// Convert this DbgVariableRecord back into a dbg.value intrinsic.
510 /// \p InsertBefore Optional position to insert this intrinsic.
511 /// \returns A new dbg.value intrinsic representiung this DbgVariableRecord.
513 Instruction *InsertBefore) const;
514
515 /// Handle changes to the location of the Value(s) that we refer to happening
516 /// "under our feet".
517 void handleChangedLocation(Metadata *NewLocation);
518
519 void print(raw_ostream &O, bool IsForDebug = false) const;
520 void print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const;
521
522 /// Support type inquiry through isa, cast, and dyn_cast.
523 static bool classof(const DbgRecord *E) {
524 return E->getRecordKind() == ValueKind;
525 }
526};
527
528/// Filter the DbgRecord range to DbgVariableRecord types only and downcast.
529static inline auto
531 return map_range(
533 [](DbgRecord &E) { return isa<DbgVariableRecord>(E); }),
534 [](DbgRecord &E) { return std::ref(cast<DbgVariableRecord>(E)); });
535}
536
537/// Per-instruction record of debug-info. If an Instruction is the position of
538/// some debugging information, it points at a DbgMarker storing that info. Each
539/// marker points back at the instruction that owns it. Various utilities are
540/// provided for manipulating the DbgRecords contained within this marker.
541///
542/// This class has a rough surface area, because it's needed to preserve the
543/// one arefact that we can't yet eliminate from the intrinsic / dbg.value
544/// debug-info design: the order of records is significant, and duplicates can
545/// exist. Thus, if one has a run of debug-info records such as:
546/// dbg.value(...
547/// %foo = barinst
548/// dbg.value(...
549/// and remove barinst, then the dbg.values must be preserved in the correct
550/// order. Hence, the use of iterators to select positions to insert things
551/// into, or the occasional InsertAtHead parameter indicating that new records
552/// should go at the start of the list.
553///
554/// There are only five or six places in LLVM that truly rely on this ordering,
555/// which we can improve in the future. Additionally, many improvements in the
556/// way that debug-info is stored can be achieved in this class, at a future
557/// date.
559public:
561 /// Link back to the Instruction that owns this marker. Can be null during
562 /// operations that move a marker from one instruction to another.
564
565 /// List of DbgRecords, the non-instruction equivalent of llvm.dbg.*
566 /// intrinsics. There is a one-to-one relationship between each debug
567 /// intrinsic in a block and each DbgRecord once the representation has been
568 /// converted, and the ordering is meaningful in the same way.
570 bool empty() const { return StoredDbgRecords.empty(); }
571
572 const BasicBlock *getParent() const;
574
575 /// Handle the removal of a marker: the position of debug-info has gone away,
576 /// but the stored debug records should not. Drop them onto the next
577 /// instruction, or otherwise work out what to do with them.
578 void removeMarker();
579 void dump() const;
580
581 void removeFromParent();
582 void eraseFromParent();
583
584 /// Implement operator<< on DbgMarker.
585 void print(raw_ostream &O, bool IsForDebug = false) const;
586 void print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const;
587
588 /// Produce a range over all the DbgRecords in this Marker.
591 getDbgRecordRange() const;
592 /// Transfer any DbgRecords from \p Src into this DbgMarker. If \p
593 /// InsertAtHead is true, place them before existing DbgRecords, otherwise
594 /// afterwards.
595 void absorbDebugValues(DbgMarker &Src, bool InsertAtHead);
596 /// Transfer the DbgRecords in \p Range from \p Src into this DbgMarker. If
597 /// \p InsertAtHead is true, place them before existing DbgRecords, otherwise
598 // afterwards.
600 DbgMarker &Src, bool InsertAtHead);
601 /// Insert a DbgRecord into this DbgMarker, at the end of the list. If
602 /// \p InsertAtHead is true, at the start.
603 void insertDbgRecord(DbgRecord *New, bool InsertAtHead);
604 /// Insert a DbgRecord prior to a DbgRecord contained within this marker.
605 void insertDbgRecord(DbgRecord *New, DbgRecord *InsertBefore);
606 /// Insert a DbgRecord after a DbgRecord contained within this marker.
607 void insertDbgRecordAfter(DbgRecord *New, DbgRecord *InsertAfter);
608 /// Clone all DbgMarkers from \p From into this marker. There are numerous
609 /// options to customise the source/destination, due to gnarliness, see class
610 /// comment.
611 /// \p FromHere If non-null, copy from FromHere to the end of From's
612 /// DbgRecords
613 /// \p InsertAtHead Place the cloned DbgRecords at the start of
614 /// StoredDbgRecords
615 /// \returns Range over all the newly cloned DbgRecords
618 std::optional<simple_ilist<DbgRecord>::iterator> FromHere,
619 bool InsertAtHead = false);
620 /// Erase all DbgRecords in this DbgMarker.
621 void dropDbgRecords();
622 /// Erase a single DbgRecord from this marker. In an ideal future, we would
623 /// never erase an assignment in this way, but it's the equivalent to
624 /// erasing a debug intrinsic from a block.
625 void dropOneDbgRecord(DbgRecord *DR);
626
627 /// We generally act like all llvm Instructions have a range of DbgRecords
628 /// attached to them, but in reality sometimes we don't allocate the DbgMarker
629 /// to save time and memory, but still have to return ranges of DbgRecords.
630 /// When we need to describe such an unallocated DbgRecord range, use this
631 /// static markers range instead. This will bite us if someone tries to insert
632 /// a DbgRecord in that range, but they should be using the Official (TM) API
633 /// for that.
639 }
640};
641
643 Marker.print(OS);
644 return OS;
645}
646
647/// Inline helper to return a range of DbgRecords attached to a marker. It needs
648/// to be inlined as it's frequently called, but also come after the declaration
649/// of DbgMarker. Thus: it's pre-declared by users like Instruction, then an
650/// inlineable body defined here.
651inline iterator_range<simple_ilist<DbgRecord>::iterator>
653 if (!DebugMarker)
655 return DebugMarker->getDbgRecordRange();
656}
657
659
660/// Used to temporarily set the debug info format of a function, module, or
661/// basic block for the duration of this object's lifetime, after which the
662/// prior state will be restored.
663template <typename T> class ScopedDbgInfoFormatSetter {
664 T &Obj;
665 bool OldState;
666
667public:
668 ScopedDbgInfoFormatSetter(T &Obj, bool NewState)
669 : Obj(Obj), OldState(Obj.IsNewDbgInfoFormat) {
670 Obj.setIsNewDbgInfoFormat(NewState);
671 }
672 ~ScopedDbgInfoFormatSetter() { Obj.setIsNewDbgInfoFormat(OldState); }
673};
674
675template <typename T>
677 bool NewState) -> ScopedDbgInfoFormatSetter<T>;
678
679} // namespace llvm
680
681#endif // LLVM_IR_DEBUGPROGRAMINSTRUCTION_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
Assignment ID.
DWARF expression.
Debug location.
This is the common base class for debug info intrinsics.
This represents the llvm.dbg.label instruction.
Records a position in IR for a source label (DILabel).
DbgLabelRecord * clone() const
static bool classof(const DbgRecord *E)
Support type inquiry through isa, cast, and dyn_cast.
void print(raw_ostream &O, bool IsForDebug=false) const
Definition: AsmWriter.cpp:4957
static DbgLabelRecord * createUnresolvedDbgLabelRecord(MDNode *Label, MDNode *DL)
For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved MDNodes.
void setLabel(DILabel *NewLabel)
DbgLabelInst * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Per-instruction record of debug-info.
static iterator_range< simple_ilist< DbgRecord >::iterator > getEmptyDbgRecordRange()
void dump() const
Definition: AsmWriter.cpp:5243
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(DbgMarker *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere, bool InsertAtHead=false)
Clone all DbgMarkers from From into this marker.
void insertDbgRecordAfter(DbgRecord *New, DbgRecord *InsertAfter)
Insert a DbgRecord after a DbgRecord contained within this marker.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on DbgMarker.
Definition: AsmWriter.cpp:4930
void removeMarker()
Handle the removal of a marker: the position of debug-info has gone away, but the stored debug record...
void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange()
Produce a range over all the DbgRecords in this Marker.
void dropOneDbgRecord(DbgRecord *DR)
Erase a single DbgRecord from this marker.
const BasicBlock * getParent() const
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
void insertDbgRecord(DbgRecord *New, bool InsertAtHead)
Insert a DbgRecord into this DbgMarker, at the end of the list.
static DbgMarker EmptyDbgMarker
We generally act like all llvm Instructions have a range of DbgRecords attached to them,...
A typed tracking MDNode reference that does not require a definition for its parameter type.
T * get() const
Get the underlying type.
bool operator!=(const DbgRecordParamRef &Other) const
MDNode * getAsMDNode() const
Return this as a MDNode.
bool operator==(const DbgRecordParamRef &Other) const
Base class for non-instruction debug metadata records that have positions within IR.
void insertAfter(DbgRecord *InsertAfter)
void print(raw_ostream &O, bool IsForDebug=false) const
bool isEquivalentTo(const DbgRecord &R) const
Same as isIdenticalToWhenDefined but checks DebugLoc too.
DbgRecord(Kind RecordKind, DebugLoc DL)
simple_ilist< DbgRecord >::iterator self_iterator
DebugLoc getDebugLoc() const
void dump() const
Definition: AsmWriter.cpp:5250
DbgInfoIntrinsic * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Convert this DbgRecord back into an appropriate llvm.dbg.
Kind RecordKind
Subclass discriminator.
void deleteRecord()
Methods that dispatch to subclass implementations.
void insertBefore(DbgRecord *InsertBefore)
~DbgRecord()=default
Similarly to Value, we avoid paying the cost of a vtable by protecting the dtor and having deleteReco...
void moveBefore(DbgRecord *MoveBefore)
simple_ilist< DbgRecord >::const_iterator const_self_iterator
Kind
Subclass discriminator.
void setDebugLoc(DebugLoc Loc)
const Instruction * getInstruction() const
void moveAfter(DbgRecord *MoveAfter)
bool isIdenticalToWhenDefined(const DbgRecord &R) const
const DbgMarker * getMarker() const
DbgMarker * Marker
Marker that this DbgRecord is linked into.
void setMarker(DbgMarker *M)
DbgRecord * clone() const
const BasicBlock * getParent() const
This is the common base class for debug info intrinsics for variables.
Iterator for ValueAsMetadata that internally uses direct pointer iteration over either a ValueAsMetad...
bool operator==(const location_op_iterator &RHS) const
location_op_iterator & operator=(const location_op_iterator &R)
Record of a variable value-assignment, aka a non instruction representation of the dbg....
bool isEquivalentTo(const DbgVariableRecord &Other) const
DbgRecordParamRef< DIExpression > Expression
bool isKillAddress() const
Check whether this kills the address component.
void print(raw_ostream &O, bool IsForDebug=false) const
Definition: AsmWriter.cpp:4936
bool hasValidLocation() const
Returns true if this DbgVariableRecord has no empty MDNodes in its location list.
LocationType Type
Classification of the debug-info record that this DbgVariableRecord represents.
DbgRecordParamRef< DILocalVariable > Variable
void setAddressExpression(DIExpression *NewExpr)
MDNode * getRawAddressExpression() const
bool isAddressOfVariable() const
Does this describe the address of a local variable.
std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
Value * getValue(unsigned OpIdx=0) const
DbgVariableRecord * clone() const
static DbgVariableRecord * createUnresolvedDbgVariableRecord(LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, MDNode *AssignID, Metadata *Address, MDNode *AddressExpression, MDNode *DI)
Used to create DbgVariableRecords during parsing, where some metadata references may still be unresol...
void setRawLocation(Metadata *NewLocation)
Use of this should generally be avoided; instead, replaceVariableLocationOp and addVariableLocationOp...
static DbgVariableRecord * createDbgVariableRecord(Value *Location, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
static DbgVariableRecord * createDVRDeclare(Value *Address, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
void setVariable(DILocalVariable *NewVar)
void setExpression(DIExpression *NewExpr)
DIExpression * getExpression() const
void handleChangedLocation(Metadata *NewLocation)
Handle changes to the location of the Value(s) that we refer to happening "under our feet".
Value * getVariableLocationOp(unsigned OpIdx) const
void setKillAddress()
Kill the address component.
DILocalVariable * getVariable() const
static bool classof(const DbgRecord *E)
Support type inquiry through isa, cast, and dyn_cast.
void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
void setAssignId(DIAssignID *New)
static DbgVariableRecord * createDVRAssign(Value *Val, DILocalVariable *Variable, DIExpression *Expression, DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
unsigned getNumVariableLocationOps() const
DbgVariableIntrinsic * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Convert this DbgVariableRecord back into a dbg.value intrinsic.
void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
static DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
bool isIdenticalToWhenDefined(const DbgVariableRecord &Other) const
DbgRecordParamRef< DIExpression > AddressExpression
DIExpression * getAddressExpression() const
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
A debug info location.
Definition: DebugLoc.h:33
Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...
Definition: Metadata.h:212
std::array< Metadata *, 3 > DebugValues
Definition: Metadata.h:218
void resetDebugValue(size_t Idx, Metadata *DebugValue)
Definition: Metadata.h:273
Class representing an expression and its matching format.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1067
Root of the metadata hierarchy.
Definition: Metadata.h:62
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
Used to temporarily set the debug info format of a function, module, or basic block for the duration ...
ScopedDbgInfoFormatSetter(T &Obj, bool NewState)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:450
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:495
Value * getValue() const
Definition: Metadata.h:490
LLVM Value Representation.
Definition: Value.h:74
self_iterator getIterator()
Definition: ilist_node.h:109
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A simple intrusive list implementation.
Definition: simple_ilist.h:81
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator
Definition: simple_ilist.h:97
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, true >::type const_iterator
Definition: simple_ilist.h:100
struct LLVMOpaqueDbgRecord * LLVMDbgRecordRef
Definition: Types.h:175
This file defines classes to implement an intrusive doubly linked list class (i.e.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto map_range(ContainerTy &&C, FuncTy F)
Definition: STLExtras.h:377
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:572
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange(DbgMarker *DebugMarker)
Inline helper to return a range of DbgRecords attached to a marker.
@ Other
Any other memory.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:293
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.