LLVM: lib/IR/DebugProgramInstruction.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
13
14namespace llvm {
15
16template
18 : Ref(const_cast<T *>(Param)) {}
19template
21 : Ref(const_cast<MDNode *>(Param)) {}
22
24 return cast(Ref);
25}
26
30
34 Variable(DVI->getVariable()), Expression(DVI->getExpression()),
35 AddressExpression() {
36 switch (DVI->getIntrinsicID()) {
37 case Intrinsic::dbg_value:
39 break;
40 case Intrinsic::dbg_declare:
42 break;
43 case Intrinsic::dbg_assign: {
50 break;
51 }
52 default:
54 "Trying to create a DbgVariableRecord with an invalid intrinsic type!");
55 }
56}
57
60 Type(DVR.getType()), Variable(DVR.getVariable()),
62 AddressExpression(DVR.AddressExpression) {}
63
69
77 AddressExpression(AddressExpression) {}
78
82 delete cast(this);
83 return;
85 delete cast(this);
86 return;
87 }
89}
90
94 cast(this)->print(O, IsForDebug);
95 return;
97 cast(this)->print(O, IsForDebug);
98 return;
99 };
101}
102
104 bool IsForDebug) const {
107 cast(this)->print(O, MST, IsForDebug);
108 return;
110 cast(this)->print(O, MST, IsForDebug);
111 return;
112 };
114}
115
118 return false;
121 return cast(this)->isIdenticalToWhenDefined(
122 *cast(&R));
124 return cast(this)->getLabel() ==
125 cast(R).getLabel();
126 };
128}
129
132}
133
138 return cast(this)->createDebugIntrinsic(M, InsertBefore);
140 return cast(this)->createDebugIntrinsic(M, InsertBefore);
141 };
143}
144
145DbgLabelRecord::DbgLabelRecord(MDNode *Label, MDNode *DL)
147 assert(Label && "Unexpected nullptr");
148 assert((isa(Label) || Label->isTemporary()) &&
149 "Label type must be or resolve to a DILabel");
150}
152 : DbgRecord(LabelKind, DL), Label(Label) {
153 assert(Label && "Unexpected nullptr");
154}
155
159}
160
168 Expression(Expression), AddressExpression(AddressExpression) {}
169
176}
177
184}
185
190 NewDbgVariableRecord->insertBefore(&InsertBefore);
191 return NewDbgVariableRecord;
192}
193
200}
201
207 NewDVRDeclare->insertBefore(&InsertBefore);
208 return NewDVRDeclare;
209}
210
218}
219
224 auto *Link = LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID);
225 assert(Link && "Linked instruction must have DIAssign metadata attached");
229 LinkedInstr->getParent()->insertDbgRecordAfter(NewDVRAssign, LinkedInstr);
230 return NewDVRAssign;
231}
232
236
237
238 if (!MD)
241
242
243 if (auto *VAM = dyn_cast(MD))
245
246
247 if (auto *AL = dyn_cast(MD))
250
251
252 assert(cast(MD)->getNumOperands() == 0);
255}
256
259 return cast(getRawLocation())->getArgs().size();
260 return 1;
261}
262
265 if (!MD)
266 return nullptr;
267
268 if (auto *AL = dyn_cast(MD))
269 return AL->getArgs()[OpIdx]->getValue();
270 if (isa(MD))
271 return nullptr;
272 assert(isa(MD) &&
273 "Attempted to get location operand from DbgVariableRecord with none.");
274 auto *V = cast(MD);
275 assert(OpIdx == 0 && "Operand Index must be 0 for a debug intrinsic with a "
276 "single location operand.");
277 return V->getValue();
278}
279
281 return isa(V) ? dyn_cast(
282 cast(V)->getMetadata())
284}
285
288 bool AllowEmpty) {
289 assert(NewValue && "Values must be non-null");
290
292 if (DbgAssignAddrReplaced)
294
296 auto OldIt = find(Locations, OldValue);
297 if (OldIt == Locations.end()) {
298 if (AllowEmpty || DbgAssignAddrReplaced)
299 return;
301 }
302
304
306 ? cast(NewValue)->getMetadata()
308 return;
309 }
310
311
312
315 for (auto *VMD : Locations)
318}
319
321 Value *NewValue) {
323
326 ? cast(NewValue)->getMetadata()
328 return;
329 }
330
336
338}
339
343 NewValues.size()) &&
344 "NewExpr for debug variable intrinsic does not reference every "
345 "location operand.");
346 assert((NewValues, nullptr) && "New values must be non-null");
351 for (auto *VMD : NewValues)
354}
355
357
358
361 if (!RemovedValues.insert(OldValue).second)
362 continue;
365 }
366}
367
372}
373
376}
377
379 if (auto Fragment = getExpression()->getFragmentInfo())
380 return Fragment->SizeInBits;
382}
383
387 return cast(this)->clone();
389 return cast(this)->clone();
390 };
392}
393
396}
397
400}
401
406 getDebugLoc()->getScope()->getSubprogram()->getUnit();
408 "Cannot clone from BasicBlock that is not part of a Module or "
409 "DICompileUnit!");
412
413
417 break;
420 break;
423 break;
427 }
428
429
430
433 "DbgVariableRecord's RawLocation should be non-null.");
435 Value *AssignArgs[] = {
443 IntrinsicFn->getFunctionType(), IntrinsicFn, AssignArgs));
444 } else {
448 DVI = cast(
450 }
453 if (InsertBefore)
455
456 return DVI;
457}
458
463 Value *Args[] = {
466 CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
469 if (InsertBefore)
470 DbgLabel->insertBefore(InsertBefore);
472}
473
476 if (auto *V = dyn_cast_or_null(MD))
477 return V->getValue();
478
479
480 assert((!MD || !cast(MD)->getNumOperands()) &&
481 "Expected an empty MDNode");
482 return nullptr;
483}
484
487}
488
491}
492
496}
497
500 return || isa(Addr);
501}
502
505}
506
509}
510
512
514
516
518
521}
522
524
527}
528
530
533}
534
537 "Cannot insert a DbgRecord that is already has a DbgMarker!");
539 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
540 "DbgMarker!");
542}
545 "Cannot insert a DbgRecord that is already has a DbgMarker!");
547 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
548 "DbgMarker!");
550}
553 "Canot move a DbgRecord that does not currently have a DbgMarker!");
556}
559 "Canot move a DbgRecord that does not currently have a DbgMarker!");
562}
563
564
565
566
567
569
576 }
577}
578
583}
584
587}
588
590
592
597 return;
598 }
599
600
601
602
604 if (NextMarker) {
607 } else {
608
609
610
612 if (NextIt == getParent()->end()) {
615 } else {
618 }
619 }
621}
622
626}
627
632 delete this;
633}
634
637}
641}
642
646}
647
651}
652
656 New->setMarker(this);
657}
660 "DbgRecord 'InsertBefore' must be contained in this DbgMarker!");
662 New->setMarker(this);
663}
666 "DbgRecord 'InsertAfter' must be contained in this DbgMarker!");
668 New->setMarker(this);
669}
670
673 for (DbgRecord &DVR : Src.StoredDbgRecords)
675
677}
678
681 bool InsertAtHead) {
683 DR.setMarker(this);
684
685 auto InsertPos =
687
690}
691
694 bool InsertAtHead) {
696
697
698
700 make_range(From->StoredDbgRecords.begin(), From->StoredDbgRecords.end());
701 if (from_here.has_value())
703
704
705
709 New->setMarker(this);
713 }
714
717
718 if (InsertAtHead)
719
720
722 else
723
725}
726
727}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SymbolRef::Type getType(const Symbol *Sym)
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.
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...
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 DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
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.
Records a position in IR for a source label (DILabel).
DbgLabelRecord * clone() const
static DbgLabelRecord * createUnresolvedDbgLabelRecord(MDNode *Label, MDNode *DL)
For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved MDNodes.
DILabel * getLabel() const
DbgLabelInst * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
This class is used to track label information.
Per-instruction record of debug-info.
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 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.
DbgRecordParamRef()=default
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.
DebugLoc getDebugLoc() const
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)
void moveBefore(DbgRecord *MoveBefore)
const Instruction * getInstruction() const
void moveAfter(DbgRecord *MoveAfter)
bool isIdenticalToWhenDefined(const DbgRecord &R) const
DbgMarker * Marker
Marker that this DbgRecord is linked into.
void setMarker(DbgMarker *M)
DbgRecord * clone() const
LLVMContext & getContext()
const BasicBlock * getParent() const
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....
DbgVariableRecord(const DbgVariableIntrinsic *DVI)
Create a new DbgVariableRecord representing the intrinsic DVI, for example the assignment represented...
LocationType getType() const
bool isKillAddress() const
Check whether this kills the address component.
DbgRecordParamRef< DILocalVariable > Variable
bool isKillLocation() const
DIAssignID * getAssignID() const
std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
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)
Value * getAddress() const
void setExpression(DIExpression *NewExpr)
DIExpression * getExpression() const
Value * getVariableLocationOp(unsigned OpIdx) const
void setKillAddress()
Kill the address component.
DILocalVariable * getVariable() const
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)
void setAddress(Value *V)
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.
Metadata * getRawAddress() const
void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
std::optional< DbgVariableFragmentInfo > getFragment() const
static DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
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.
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...
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
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 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.
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
static ValueAsMetadata * getAsMetadata(Value *V)
@ Ref
The access may reference the value stored in memory.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.