LLVM: lib/IR/DebugProgramInstruction.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14
15using namespace llvm;
16
17namespace llvm {
18template
20 : Ref(const_cast<T *>(Param)) {}
21template
23 : Ref(const_cast<MDNode *>(Param)) {}
24
28
32}
33
37 Variable(DVI->getVariable()), Expression(DVI->getExpression()),
38 AddressExpression() {
39 switch (DVI->getIntrinsicID()) {
40 case Intrinsic::dbg_value:
41 Type = LocationType::Value;
42 break;
43 case Intrinsic::dbg_declare:
44 Type = LocationType::Declare;
45 break;
46 case Intrinsic::dbg_assign: {
47 Type = LocationType::Assign;
50 resetDebugValue(1, Assign->getRawAddress());
51 AddressExpression = Assign->getAddressExpression();
52 setAssignId(Assign->getAssignID());
53 break;
54 }
55 default:
57 "Trying to create a DbgVariableRecord with an invalid intrinsic type!");
58 }
59}
60
66
72
80 AddressExpression(AddressExpression) {}
81
86 return;
89 return;
90 }
92}
93
98 return;
101 return;
102 };
104}
105
107 bool IsForDebug) const {
111 return;
114 return;
115 };
117}
118
121 return false;
129 };
131}
132
136
147
148DbgLabelRecord::DbgLabelRecord(MDNode *Label, MDNode *DL)
150 assert(Label && "Unexpected nullptr");
152 "Label type must be or resolve to a DILabel");
153}
156 assert(Label && "Unexpected nullptr");
157}
158
161 return new DbgLabelRecord(Label, DL);
162}
163
172
180
188
193 NewDbgVariableRecord->insertBefore(&InsertBefore);
194 return NewDbgVariableRecord;
195}
196
204
210 NewDVRDeclare->insertBefore(&InsertBefore);
211 return NewDVRDeclare;
212}
213
221
226 NewDVRCoro->insertBefore(&InsertBefore);
227 return NewDVRCoro;
228}
229
238
243 auto *Link = LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID);
244 assert(Link && "Linked instruction must have DIAssign metadata attached");
248 LinkedInstr->getParent()->insertDbgRecordAfter(NewDVRAssign, LinkedInstr);
249 return NewDVRAssign;
250}
251
255
256
257 if (!MD)
260
261
264
265
269
270
274}
275
281
284 if (!MD)
285 return nullptr;
286
288 return AL->getArgs()[OpIdx]->getValue();
290 return nullptr;
292 "Attempted to get location operand from DbgVariableRecord with none.");
294 assert(OpIdx == 0 && "Operand Index must be 0 for a debug intrinsic with a "
295 "single location operand.");
296 return V->getValue();
297}
298
304
307 bool AllowEmpty) {
308 assert(NewValue && "Values must be non-null");
309
311 if (DbgAssignAddrReplaced)
313
315 auto OldIt = find(Locations, OldValue);
316 if (OldIt == Locations.end()) {
317 if (AllowEmpty || DbgAssignAddrReplaced)
318 return;
320 }
321
323
327 return;
328 }
329
330
331
334 for (auto *VMD : Locations)
337}
338
340 Value *NewValue) {
342
347 return;
348 }
349
355
357}
358
362 NewValues.size()) &&
363 "NewExpr for debug variable intrinsic does not reference every "
364 "location operand.");
365 assert((NewValues, nullptr) && "New values must be non-null");
370 for (auto *VMD : NewValues)
373}
374
376
377
380 if (!RemovedValues.insert(OldValue).second)
381 continue;
384 }
385}
386
392
396
398 if (auto Fragment = getExpression()->getFragmentInfo())
399 return Fragment->SizeInBits;
401}
402
412
416
420
425 getDebugLoc()->getScope()->getSubprogram()->getUnit();
427 "Cannot clone from BasicBlock that is not part of a Module or "
428 "DICompileUnit!");
431
432
436 break;
439 break;
442 break;
446 break;
449 "#dbg_declare_value should never be converted to an intrinsic");
450 }
451
452
453
456 "DbgVariableRecord's RawLocation should be non-null.");
458 Value *AssignArgs[] = {
466 IntrinsicFn->getFunctionType(), IntrinsicFn, AssignArgs));
467 } else {
473 }
476 if (InsertBefore)
478
479 return DVI;
480}
481
486 Value *Args[] = {
489 CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
492 if (InsertBefore)
495}
496
500 return V->getValue();
501
502
504 "Expected an empty MDNode");
505 return nullptr;
506}
507
511
515
520
525
527 return Marker->MarkedInstr;
528}
529
531 return Marker->MarkedInstr->getParent();
532}
533
535
537
539
541
545
547
551
553
557
560 "Cannot insert a DbgRecord that is already has a DbgMarker!");
562 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
563 "DbgMarker!");
565}
568 "Cannot insert a DbgRecord that is already has a DbgMarker!");
570 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
571 "DbgMarker!");
573}
574
577 "Cannot insert a DbgRecord that is already has a DbgMarker!");
578 assert(InsertBefore->getMarker() &&
579 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
580 "DbgMarker!");
581 InsertBefore->getMarker()->insertDbgRecord(this, &*InsertBefore);
582}
585 "Cannot insert a DbgRecord that is already has a DbgMarker!");
586 assert(InsertAfter->getMarker() &&
587 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
588 "DbgMarker!");
589 InsertAfter->getMarker()->insertDbgRecordAfter(this, &*InsertAfter);
590}
591
594 "Canot move a DbgRecord that does not currently have a DbgMarker!");
597}
600 "Canot move a DbgRecord that does not currently have a DbgMarker!");
603}
604
607 "Canot move a DbgRecord that does not currently have a DbgMarker!");
610}
613 "Canot move a DbgRecord that does not currently have a DbgMarker!");
616}
617
618
619
620
621
623
632
638
642
644
646
650 Owner->DebugMarker = nullptr;
651 return;
652 }
653
654
655
656
658 if (NextMarker) {
661 } else {
662
663
664
666 if (NextIt == getParent()->end()) {
669 } else {
670 NextIt->DebugMarker = this;
672 }
673 }
674 Owner->DebugMarker = nullptr;
675}
676
681
688
696
701
706
710 New->setMarker(this);
711}
714 "DbgRecord 'InsertBefore' must be contained in this DbgMarker!");
716 New->setMarker(this);
717}
720 "DbgRecord 'InsertAfter' must be contained in this DbgMarker!");
722 New->setMarker(this);
723}
724
727 for (DbgRecord &DVR : Src.StoredDbgRecords)
729
731}
732
735 bool InsertAtHead) {
737 DR.setMarker(this);
738
739 auto InsertPos =
741
744}
745
748 bool InsertAtHead) {
750
751
752
755 if (from_here.has_value())
757
758
759
763 New->setMarker(this);
767 }
768
771
772 if (InsertAtHead)
773
774
776 else
777
779}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_EXPORT_TEMPLATE
static ManagedStatic< DebugCounterOwner > Owner
static ValueAsMetadata * getAsMetadata(Value *V)
Definition DebugProgramInstruction.cpp:299
MachineInstr unsigned OpIdx
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
LLVM Basic Block Representation.
LLVM_ABI void setTrailingDbgRecords(DbgMarker *M)
Record that the collection of DbgRecords in M "trails" after the last instruction of this block.
const Function * getParent() const
Return the enclosing method, or null if none.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setTailCall(bool IsTc=true)
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
LLVM_ABI bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
static LLVM_ABI std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
LLVM_ABI std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
This represents the llvm.dbg.assign instruction.
This is the common base class for debug info intrinsics.
This represents the llvm.dbg.label instruction.
LLVM_ABI DbgLabelInst * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Definition DebugProgramInstruction.cpp:483
LLVM_ABI DbgLabelRecord * clone() const
Definition DebugProgramInstruction.cpp:417
static LLVM_ABI DbgLabelRecord * createUnresolvedDbgLabelRecord(MDNode *Label, MDNode *DL)
For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved MDNodes.
Definition DebugProgramInstruction.cpp:159
DILabel * getLabel() const
This class is used to track label information.
Per-instruction record of debug-info.
LLVM_ABI void insertDbgRecordAfter(DbgRecord *New, DbgRecord *InsertAfter)
Insert a DbgRecord after a DbgRecord contained within this marker.
Definition DebugProgramInstruction.cpp:718
LLVM_ABI void removeFromParent()
Definition DebugProgramInstruction.cpp:677
LLVM_ABI void dropOneDbgRecord(DbgRecord *DR)
Erase a single DbgRecord from this marker.
Definition DebugProgramInstruction.cpp:633
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
LLVM_ABI void eraseFromParent()
Definition DebugProgramInstruction.cpp:682
static LLVM_ABI DbgMarker EmptyDbgMarker
We generally act like all llvm Instructions have a range of DbgRecords attached to them,...
LLVM_ABI iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange()
Produce a range over all the DbgRecords in this Marker.
Definition DebugProgramInstruction.cpp:689
LLVM_ABI const BasicBlock * getParent() const
Definition DebugProgramInstruction.cpp:639
LLVM_ABI 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.
Definition DebugProgramInstruction.cpp:746
LLVM_ABI void insertDbgRecord(DbgRecord *New, bool InsertAtHead)
Insert a DbgRecord into this DbgMarker, at the end of the list.
Definition DebugProgramInstruction.cpp:707
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
LLVM_ABI void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
Definition DebugProgramInstruction.cpp:725
LLVM_ABI void removeMarker()
Handle the removal of a marker: the position of debug-info has gone away, but the stored debug record...
Definition DebugProgramInstruction.cpp:645
LLVM_ABI void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
Definition DebugProgramInstruction.cpp:624
A typed tracking MDNode reference that does not require a definition for its parameter type.
T * get() const
Get the underlying type.
Definition DebugProgramInstruction.cpp:25
DbgRecordParamRef()=default
Base class for non-instruction debug metadata records that have positions within IR.
LLVM_ABI LLVMContext & getContext()
Definition DebugProgramInstruction.cpp:552
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Definition DebugProgramInstruction.cpp:94
LLVM_ABI void insertAfter(DbgRecord *InsertAfter)
Definition DebugProgramInstruction.cpp:566
LLVM_ABI void moveAfter(DbgRecord *MoveAfter)
Definition DebugProgramInstruction.cpp:598
LLVM_ABI void insertBefore(DbgRecord *InsertBefore)
Definition DebugProgramInstruction.cpp:558
LLVM_ABI bool isEquivalentTo(const DbgRecord &R) const
Same as isIdenticalToWhenDefined but checks DebugLoc too.
Definition DebugProgramInstruction.cpp:133
LLVM_ABI void removeFromParent()
Definition DebugProgramInstruction.cpp:697
DbgRecord(Kind RecordKind, DebugLoc DL)
LLVM_ABI void moveBefore(DbgRecord *MoveBefore)
Definition DebugProgramInstruction.cpp:592
simple_ilist< DbgRecord >::iterator self_iterator
DebugLoc getDebugLoc() const
LLVM_ABI void eraseFromParent()
Definition DebugProgramInstruction.cpp:702
Kind RecordKind
Subclass discriminator.
LLVM_ABI bool isIdenticalToWhenDefined(const DbgRecord &R) const
Definition DebugProgramInstruction.cpp:119
LLVM_ABI DbgRecord * clone() const
Definition DebugProgramInstruction.cpp:403
LLVM_ABI void deleteRecord()
Methods that dispatch to subclass implementations.
Definition DebugProgramInstruction.cpp:82
LLVM_ABI Module * getModule()
Definition DebugProgramInstruction.cpp:546
LLVM_ABI BasicBlock * getBlock()
Definition DebugProgramInstruction.cpp:536
DbgMarker * Marker
Marker that this DbgRecord is linked into.
void setMarker(DbgMarker *M)
LLVM_ABI DbgInfoIntrinsic * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Convert this DbgRecord back into an appropriate llvm.dbg.
Definition DebugProgramInstruction.cpp:138
LLVM_ABI const BasicBlock * getParent() const
Definition DebugProgramInstruction.cpp:530
LLVM_ABI const Instruction * getInstruction() const
Definition DebugProgramInstruction.cpp:526
LLVM_ABI Function * getFunction()
Definition DebugProgramInstruction.cpp:540
This is the common base class for debug info intrinsics for variables.
Metadata * getRawLocation() const
Iterator for ValueAsMetadata that internally uses direct pointer iteration over either a ValueAsMetad...
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LLVM_ABI void setKillAddress()
Kill the address component.
Definition DebugProgramInstruction.cpp:516
LLVM_ABI bool isKillLocation() const
Definition DebugProgramInstruction.cpp:387
LLVM_ABI std::optional< DbgVariableFragmentInfo > getFragment() const
Definition DebugProgramInstruction.cpp:393
LLVM_ABI void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
Definition DebugProgramInstruction.cpp:359
LocationType getType() const
DbgRecordParamRef< DIExpression > Expression
LLVM_ABI Value * getAddress() const
Definition DebugProgramInstruction.cpp:497
LocationType Type
Classification of the debug-info record that this DbgVariableRecord represents.
LLVM_ABI bool isKillAddress() const
Check whether this kills the address component.
Definition DebugProgramInstruction.cpp:521
DbgRecordParamRef< DILocalVariable > Variable
LLVM_ABI void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
Definition DebugProgramInstruction.cpp:305
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
Definition DebugProgramInstruction.cpp:282
LLVM_ABI unsigned getNumVariableLocationOps() const
Definition DebugProgramInstruction.cpp:276
LLVM_ABI DbgVariableRecord * clone() const
Definition DebugProgramInstruction.cpp:413
LLVM_ABI DIAssignID * getAssignID() const
Definition DebugProgramInstruction.cpp:508
static LLVM_ABI DbgVariableRecord * createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
Definition DebugProgramInstruction.cpp:215
static LLVM_ABI DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
Definition DebugProgramInstruction.cpp:239
LLVM_ABI void setAssignId(DIAssignID *New)
Definition DebugProgramInstruction.cpp:512
static LLVM_ABI DbgVariableRecord * createDVRAssign(Value *Val, DILocalVariable *Variable, DIExpression *Expression, DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
Definition DebugProgramInstruction.cpp:230
void setRawLocation(Metadata *NewLocation)
Use of this should generally be avoided; instead, replaceVariableLocationOp and addVariableLocationOp...
void setExpression(DIExpression *NewExpr)
DIExpression * getExpression() const
static LLVM_ABI DbgVariableRecord * createDVRDeclare(Value *Address, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
Definition DebugProgramInstruction.cpp:197
static LLVM_ABI DbgVariableRecord * createDbgVariableRecord(Value *Location, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
Definition DebugProgramInstruction.cpp:182
LLVM_ABI std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
Definition DebugProgramInstruction.cpp:397
DILocalVariable * getVariable() const
static LLVM_ABI 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...
Definition DebugProgramInstruction.cpp:173
LLVM_ABI void setKillLocation()
Definition DebugProgramInstruction.cpp:375
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
void setAddress(Value *V)
Metadata * getRawAddress() const
friend class DebugValueUser
LLVM_ABI DbgVariableRecord(const DbgVariableIntrinsic *DVI)
Create a new DbgVariableRecord representing the intrinsic DVI, for example the assignment represented...
Definition DebugProgramInstruction.cpp:34
LLVM_ABI iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
Definition DebugProgramInstruction.cpp:253
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
DbgRecordParamRef< DIExpression > AddressExpression
DIExpression * getAddressExpression() const
LLVM_ABI DbgVariableIntrinsic * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Convert this DbgVariableRecord back into a dbg.value intrinsic.
Definition DebugProgramInstruction.cpp:422
Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...
std::array< Metadata *, 3 > DebugValues
void resetDebugValue(size_t Idx, Metadata *DebugValue)
Class representing an expression and its matching format.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
This is an important class for using LLVM in a threaded context.
LLVMContext & getContext() const
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
const ParentTy * getParent() const
self_iterator getIterator()
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
ilist_select_iterator_type< OptionsT, false, false > iterator
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.