LLVM 22.0.0git
DebugProgramInstruction.cpp
Go to the documentation of this file.
1//=====-- DebugProgramInstruction.cpp - Implement DbgRecords/DbgMarkers --====//
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
10#include "llvm/IR/DIBuilder.h"
14
15using namespace llvm;
16
17namespace llvm {
18template <typename T>
20 : Ref(const_cast<T *>(Param)) {}
21template <typename T>
23 : Ref(const_cast<MDNode *>(Param)) {}
24
25template <typename T> T *DbgRecordParamRef<T>::get() const {
26 return cast<T>(Ref);
27}
28
32} // namespace llvm
33
36 DebugValueUser({DVI->getRawLocation(), nullptr, nullptr}),
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;
48 const DbgAssignIntrinsic *Assign =
49 static_cast<const DbgAssignIntrinsic *>(DVI);
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
68 DIExpression *Expr, const DILocation *DI,
70 : DbgRecord(ValueKind, DI), DebugValueUser({Location, nullptr, nullptr}),
71 Type(Type), Variable(DV), Expression(Expr) {}
72
75 DIAssignID *AssignID, Metadata *Address,
77 const DILocation *DI)
78 : DbgRecord(ValueKind, DI), DebugValueUser({Value, Address, AssignID}),
79 Type(LocationType::Assign), Variable(Variable), Expression(Expression),
80 AddressExpression(AddressExpression) {}
81
83 switch (RecordKind) {
84 case ValueKind:
85 delete cast<DbgVariableRecord>(this);
86 return;
87 case LabelKind:
88 delete cast<DbgLabelRecord>(this);
89 return;
90 }
91 llvm_unreachable("unsupported DbgRecord kind");
92}
93
94void DbgRecord::print(raw_ostream &O, bool IsForDebug) const {
95 switch (RecordKind) {
96 case ValueKind:
97 cast<DbgVariableRecord>(this)->print(O, IsForDebug);
98 return;
100 cast<DbgLabelRecord>(this)->print(O, IsForDebug);
101 return;
102 };
103 llvm_unreachable("unsupported DbgRecord kind");
104}
105
107 bool IsForDebug) const {
108 switch (RecordKind) {
109 case ValueKind:
110 cast<DbgVariableRecord>(this)->print(O, MST, IsForDebug);
111 return;
112 case LabelKind:
113 cast<DbgLabelRecord>(this)->print(O, MST, IsForDebug);
114 return;
115 };
116 llvm_unreachable("unsupported DbgRecord kind");
117}
118
120 if (RecordKind != R.RecordKind)
121 return false;
122 switch (RecordKind) {
123 case ValueKind:
124 return cast<DbgVariableRecord>(this)->isIdenticalToWhenDefined(
126 case LabelKind:
127 return cast<DbgLabelRecord>(this)->getLabel() ==
128 cast<DbgLabelRecord>(R).getLabel();
129 };
130 llvm_unreachable("unsupported DbgRecord kind");
131}
132
134 return getDebugLoc() == R.getDebugLoc() && isIdenticalToWhenDefined(R);
135}
136
139 switch (RecordKind) {
140 case ValueKind:
141 return cast<DbgVariableRecord>(this)->createDebugIntrinsic(M, InsertBefore);
142 case LabelKind:
143 return cast<DbgLabelRecord>(this)->createDebugIntrinsic(M, InsertBefore);
144 };
145 llvm_unreachable("unsupported DbgRecord kind");
146}
147
148DbgLabelRecord::DbgLabelRecord(MDNode *Label, MDNode *DL)
149 : DbgRecord(LabelKind, DebugLoc(DL)), Label(Label) {
150 assert(Label && "Unexpected nullptr");
151 assert((isa<DILabel>(Label) || Label->isTemporary()) &&
152 "Label type must be or resolve to a DILabel");
153}
154DbgLabelRecord::DbgLabelRecord(DILabel *Label, DebugLoc DL)
155 : DbgRecord(LabelKind, DL), Label(Label) {
156 assert(Label && "Unexpected nullptr");
157}
158
160 MDNode *DL) {
161 return new DbgLabelRecord(Label, DL);
162}
163
165 Metadata *Val, MDNode *Variable,
166 MDNode *Expression, MDNode *AssignID,
168 MDNode *AddressExpression, MDNode *DI)
169 : DbgRecord(ValueKind, DebugLoc(DI)),
170 DebugValueUser({Val, Address, AssignID}), Type(Type), Variable(Variable),
171 Expression(Expression), AddressExpression(AddressExpression) {}
172
180
183 DIExpression *Expr,
184 const DILocation *DI) {
185 return new DbgVariableRecord(ValueAsMetadata::get(Location), DV, Expr, DI,
187}
188
190 Value *Location, DILocalVariable *DV, DIExpression *Expr,
191 const DILocation *DI, DbgVariableRecord &InsertBefore) {
192 auto *NewDbgVariableRecord = createDbgVariableRecord(Location, DV, Expr, DI);
193 NewDbgVariableRecord->insertBefore(&InsertBefore);
194 return NewDbgVariableRecord;
195}
196
204
207 DIExpression *Expr, const DILocation *DI,
208 DbgVariableRecord &InsertBefore) {
209 auto *NewDVRDeclare = createDVRDeclare(Address, DV, Expr, DI);
210 NewDVRDeclare->insertBefore(&InsertBefore);
211 return NewDVRDeclare;
212}
213
221
224 const DILocation *DI, DbgVariableRecord &InsertBefore) {
225 auto *NewDVRCoro = createDVRDeclareValue(Address, DV, Expr, DI);
226 NewDVRCoro->insertBefore(&InsertBefore);
227 return NewDVRCoro;
228}
229
238
240 Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable,
242 const DILocation *DI) {
243 auto *Link = LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID);
244 assert(Link && "Linked instruction must have DIAssign metadata attached");
245 auto *NewDVRAssign = DbgVariableRecord::createDVRAssign(
248 LinkedInstr->getParent()->insertDbgRecordAfter(NewDVRAssign, LinkedInstr);
249 return NewDVRAssign;
250}
251
254 auto *MD = getRawLocation();
255 // If a Value has been deleted, the "location" for this DbgVariableRecord will
256 // be replaced by nullptr. Return an empty range.
257 if (!MD)
258 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
259 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
260
261 // If operand is ValueAsMetadata, return a range over just that operand.
262 if (auto *VAM = dyn_cast<ValueAsMetadata>(MD))
263 return {location_op_iterator(VAM), location_op_iterator(VAM + 1)};
264
265 // If operand is DIArgList, return a range over its args.
266 if (auto *AL = dyn_cast<DIArgList>(MD))
267 return {location_op_iterator(AL->args_begin()),
268 location_op_iterator(AL->args_end())};
269
270 // Operand is an empty metadata tuple, so return empty iterator.
271 assert(cast<MDNode>(MD)->getNumOperands() == 0);
272 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
273 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
274}
275
277 if (hasArgList())
278 return cast<DIArgList>(getRawLocation())->getArgs().size();
279 return 1;
280}
281
283 auto *MD = getRawLocation();
284 if (!MD)
285 return nullptr;
286
287 if (auto *AL = dyn_cast<DIArgList>(MD))
288 return AL->getArgs()[OpIdx]->getValue();
289 if (isa<MDNode>(MD))
290 return nullptr;
292 "Attempted to get location operand from DbgVariableRecord with none.");
293 auto *V = cast<ValueAsMetadata>(MD);
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
306 Value *NewValue,
307 bool AllowEmpty) {
308 assert(NewValue && "Values must be non-null");
309
310 bool DbgAssignAddrReplaced = isDbgAssign() && OldValue == getAddress();
311 if (DbgAssignAddrReplaced)
312 setAddress(NewValue);
313
314 auto Locations = location_ops();
315 auto OldIt = find(Locations, OldValue);
316 if (OldIt == Locations.end()) {
317 if (AllowEmpty || DbgAssignAddrReplaced)
318 return;
319 llvm_unreachable("OldValue must be a current location");
320 }
321
322 if (!hasArgList()) {
323 // Set our location to be the MAV wrapping the new Value.
325 ? cast<MetadataAsValue>(NewValue)->getMetadata()
326 : ValueAsMetadata::get(NewValue));
327 return;
328 }
329
330 // We must be referring to a DIArgList, produce a new operands vector with the
331 // old value replaced, generate a new DIArgList and set it as our location.
333 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
334 for (auto *VMD : Locations)
335 MDs.push_back(VMD == *OldIt ? NewOperand : getAsMetadata(VMD));
337}
338
340 Value *NewValue) {
341 assert(OpIdx < getNumVariableLocationOps() && "Invalid Operand Index");
342
343 if (!hasArgList()) {
345 ? cast<MetadataAsValue>(NewValue)->getMetadata()
346 : ValueAsMetadata::get(NewValue));
347 return;
348 }
349
351 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
352 for (unsigned Idx = 0; Idx < getNumVariableLocationOps(); ++Idx)
353 MDs.push_back(Idx == OpIdx ? NewOperand
355
357}
358
361 assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
362 NewValues.size()) &&
363 "NewExpr for debug variable intrinsic does not reference every "
364 "location operand.");
365 assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
368 for (auto *VMD : location_ops())
369 MDs.push_back(getAsMetadata(VMD));
370 for (auto *VMD : NewValues)
371 MDs.push_back(getAsMetadata(VMD));
373}
374
376 // TODO: When/if we remove duplicate values from DIArgLists, we don't need
377 // this set anymore.
378 SmallPtrSet<Value *, 4> RemovedValues;
379 for (Value *OldValue : location_ops()) {
380 if (!RemovedValues.insert(OldValue).second)
381 continue;
382 Value *Poison = PoisonValue::get(OldValue->getType());
384 }
385}
386
388 return (!hasArgList() && isa<MDNode>(getRawLocation())) ||
390 any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
391}
392
393std::optional<DbgVariableFragmentInfo> DbgVariableRecord::getFragment() const {
394 return getExpression()->getFragmentInfo();
395}
396
397std::optional<uint64_t> DbgVariableRecord::getFragmentSizeInBits() const {
398 if (auto Fragment = getExpression()->getFragmentInfo())
399 return Fragment->SizeInBits;
400 return getVariable()->getSizeInBits();
401}
402
404 switch (RecordKind) {
405 case ValueKind:
406 return cast<DbgVariableRecord>(this)->clone();
407 case LabelKind:
408 return cast<DbgLabelRecord>(this)->clone();
409 };
410 llvm_unreachable("unsupported DbgRecord kind");
411}
412
414 return new DbgVariableRecord(*this);
415}
416
417DbgLabelRecord *DbgLabelRecord::clone() const {
418 return new DbgLabelRecord(getLabel(), getDebugLoc());
419}
420
423 Instruction *InsertBefore) const {
424 [[maybe_unused]] DICompileUnit *Unit =
425 getDebugLoc()->getScope()->getSubprogram()->getUnit();
426 assert(M && Unit &&
427 "Cannot clone from BasicBlock that is not part of a Module or "
428 "DICompileUnit!");
429 LLVMContext &Context = getDebugLoc()->getContext();
430 Function *IntrinsicFn;
431
432 // Work out what sort of intrinsic we're going to produce.
433 switch (getType()) {
435 IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_declare);
436 break;
438 IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_value);
439 break;
441 IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_assign);
442 break;
445 llvm_unreachable("Invalid LocationType");
446 break;
449 "#dbg_declare_value should never be converted to an intrinsic");
450 }
451
452 // Create the intrinsic from this DbgVariableRecord's information, optionally
453 // insert into the target location.
456 "DbgVariableRecord's RawLocation should be non-null.");
457 if (isDbgAssign()) {
458 Value *AssignArgs[] = {
466 IntrinsicFn->getFunctionType(), IntrinsicFn, AssignArgs));
467 } else {
468 Value *Args[] = {MetadataAsValue::get(Context, getRawLocation()),
472 CallInst::Create(IntrinsicFn->getFunctionType(), IntrinsicFn, Args));
473 }
474 DVI->setTailCall();
475 DVI->setDebugLoc(getDebugLoc());
476 if (InsertBefore)
477 DVI->insertBefore(InsertBefore->getIterator());
478
479 return DVI;
480}
481
484 Instruction *InsertBefore) const {
485 auto *LabelFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_label);
486 Value *Args[] = {
489 CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
490 DbgLabel->setTailCall();
491 DbgLabel->setDebugLoc(getDebugLoc());
492 if (InsertBefore)
493 DbgLabel->insertBefore(InsertBefore->getIterator());
494 return DbgLabel;
495}
496
498 auto *MD = getRawAddress();
499 if (auto *V = dyn_cast_or_null<ValueAsMetadata>(MD))
500 return V->getValue();
501
502 // When the value goes to null, it gets replaced by an empty MDNode.
503 assert((!MD || !cast<MDNode>(MD)->getNumOperands()) &&
504 "Expected an empty MDNode");
505 return nullptr;
506}
507
511
515
520
522 Value *Addr = getAddress();
523 return !Addr || isa<UndefValue>(Addr);
524}
525
527 return Marker->MarkedInstr;
528}
529
531 return Marker->MarkedInstr->getParent();
532}
533
534BasicBlock *DbgRecord::getParent() { return Marker->MarkedInstr->getParent(); }
535
536BasicBlock *DbgRecord::getBlock() { return Marker->getParent(); }
537
538const BasicBlock *DbgRecord::getBlock() const { return Marker->getParent(); }
539
541
543 return getBlock()->getParent();
544}
545
547
549 return getFunction()->getParent();
550}
551
553
555 return getBlock()->getContext();
556}
557
559 assert(!getMarker() &&
560 "Cannot insert a DbgRecord that is already has a DbgMarker!");
561 assert(InsertBefore->getMarker() &&
562 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
563 "DbgMarker!");
564 InsertBefore->getMarker()->insertDbgRecord(this, InsertBefore);
565}
567 assert(!getMarker() &&
568 "Cannot insert a DbgRecord that is already has a DbgMarker!");
569 assert(InsertAfter->getMarker() &&
570 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
571 "DbgMarker!");
572 InsertAfter->getMarker()->insertDbgRecordAfter(this, InsertAfter);
573}
574
576 assert(!getMarker() &&
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}
584 assert(!getMarker() &&
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
593 assert(getMarker() &&
594 "Canot move a DbgRecord that does not currently have a DbgMarker!");
596 insertBefore(MoveBefore);
597}
599 assert(getMarker() &&
600 "Canot move a DbgRecord that does not currently have a DbgMarker!");
602 insertAfter(MoveAfter);
603}
604
606 assert(getMarker() &&
607 "Canot move a DbgRecord that does not currently have a DbgMarker!");
609 insertBefore(MoveBefore);
610}
612 assert(getMarker() &&
613 "Canot move a DbgRecord that does not currently have a DbgMarker!");
615 insertAfter(MoveAfter);
616}
617
618///////////////////////////////////////////////////////////////////////////////
619
620// An empty, global, DbgMarker for the purpose of describing empty ranges of
621// DbgRecords.
623
625 while (!StoredDbgRecords.empty()) {
626 auto It = StoredDbgRecords.begin();
627 DbgRecord *DR = &*It;
628 StoredDbgRecords.erase(It);
629 DR->deleteRecord();
630 }
631}
632
634 assert(DR->getMarker() == this);
635 StoredDbgRecords.erase(DR->getIterator());
636 DR->deleteRecord();
637}
638
640 return MarkedInstr->getParent();
641}
642
643BasicBlock *DbgMarker::getParent() { return MarkedInstr->getParent(); }
644
646 // Are there any DbgRecords in this DbgMarker? If not, nothing to preserve.
647 Instruction *Owner = MarkedInstr;
648 if (StoredDbgRecords.empty()) {
650 Owner->DebugMarker = nullptr;
651 return;
652 }
653
654 // The attached DbgRecords need to be preserved; attach them to the next
655 // instruction. If there isn't a next instruction, put them on the
656 // "trailing" list.
657 DbgMarker *NextMarker = Owner->getParent()->getNextMarker(Owner);
658 if (NextMarker) {
659 NextMarker->absorbDebugValues(*this, true);
661 } else {
662 // We can avoid a deallocation -- just store this marker onto the next
663 // instruction. Unless we're at the end of the block, in which case this
664 // marker becomes the trailing marker of a degenerate block.
665 BasicBlock::iterator NextIt = std::next(Owner->getIterator());
666 if (NextIt == getParent()->end()) {
668 MarkedInstr = nullptr;
669 } else {
670 NextIt->DebugMarker = this;
671 MarkedInstr = &*NextIt;
672 }
673 }
674 Owner->DebugMarker = nullptr;
675}
676
678 MarkedInstr->DebugMarker = nullptr;
679 MarkedInstr = nullptr;
680}
681
683 if (MarkedInstr)
686 delete this;
687}
688
696
699 Marker = nullptr;
700}
701
706
707void DbgMarker::insertDbgRecord(DbgRecord *New, bool InsertAtHead) {
708 auto It = InsertAtHead ? StoredDbgRecords.begin() : StoredDbgRecords.end();
709 StoredDbgRecords.insert(It, *New);
710 New->setMarker(this);
711}
713 assert(InsertBefore->getMarker() == this &&
714 "DbgRecord 'InsertBefore' must be contained in this DbgMarker!");
715 StoredDbgRecords.insert(InsertBefore->getIterator(), *New);
716 New->setMarker(this);
717}
719 assert(InsertAfter->getMarker() == this &&
720 "DbgRecord 'InsertAfter' must be contained in this DbgMarker!");
721 StoredDbgRecords.insert(++(InsertAfter->getIterator()), *New);
722 New->setMarker(this);
723}
724
725void DbgMarker::absorbDebugValues(DbgMarker &Src, bool InsertAtHead) {
726 auto It = InsertAtHead ? StoredDbgRecords.begin() : StoredDbgRecords.end();
727 for (DbgRecord &DVR : Src.StoredDbgRecords)
728 DVR.setMarker(this);
729
730 StoredDbgRecords.splice(It, Src.StoredDbgRecords);
731}
732
735 bool InsertAtHead) {
736 for (DbgRecord &DR : Range)
737 DR.setMarker(this);
738
739 auto InsertPos =
740 (InsertAtHead) ? StoredDbgRecords.begin() : StoredDbgRecords.end();
741
742 StoredDbgRecords.splice(InsertPos, Src.StoredDbgRecords, Range.begin(),
743 Range.end());
744}
745
747 DbgMarker *From, std::optional<simple_ilist<DbgRecord>::iterator> from_here,
748 bool InsertAtHead) {
749 DbgRecord *First = nullptr;
750 // Work out what range of DbgRecords to clone: normally all the contents of
751 // the "From" marker, optionally we can start from the from_here position down
752 // to end().
753 auto Range =
754 make_range(From->StoredDbgRecords.begin(), From->StoredDbgRecords.end());
755 if (from_here.has_value())
756 Range = make_range(*from_here, From->StoredDbgRecords.end());
757
758 // Clone each DbgVariableRecord and insert into StoreDbgVariableRecords;
759 // optionally place them at the start or the end of the list.
760 auto Pos = (InsertAtHead) ? StoredDbgRecords.begin() : StoredDbgRecords.end();
761 for (DbgRecord &DR : Range) {
762 DbgRecord *New = DR.clone();
763 New->setMarker(this);
764 StoredDbgRecords.insert(Pos, *New);
765 if (!First)
766 First = New;
767 }
768
769 if (!First)
770 return {StoredDbgRecords.end(), StoredDbgRecords.end()};
771
772 if (InsertAtHead)
773 // If InsertAtHead is set, we cloned a range onto the front of of the
774 // StoredDbgRecords collection, return that range.
775 return {StoredDbgRecords.begin(), Pos};
776 else
777 // We inserted a block at the end, return that range.
778 return {First->getIterator(), StoredDbgRecords.end()};
779}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_EXPORT_TEMPLATE
Definition Compiler.h:215
static ValueAsMetadata * getAsMetadata(Value *V)
#define T
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),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
LLVM Basic Block Representation.
Definition BasicBlock.h:62
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.
Definition BasicBlock.h:213
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
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)
DWARF expression.
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
LLVM_ABI DbgLabelRecord * clone() const
static LLVM_ABI DbgLabelRecord * createUnresolvedDbgLabelRecord(MDNode *Label, MDNode *DL)
For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved MDNodes.
This class is used to track label information.
Definition DwarfDebug.h:289
Per-instruction record of debug-info.
LLVM_ABI void insertDbgRecordAfter(DbgRecord *New, DbgRecord *InsertAfter)
Insert a DbgRecord after a DbgRecord contained within this marker.
LLVM_ABI void removeFromParent()
LLVM_ABI void dropOneDbgRecord(DbgRecord *DR)
Erase a single DbgRecord from this marker.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
LLVM_ABI void eraseFromParent()
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.
LLVM_ABI const BasicBlock * getParent() const
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.
LLVM_ABI void insertDbgRecord(DbgRecord *New, bool InsertAtHead)
Insert a DbgRecord into this DbgMarker, at the end of the list.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
DbgMarker()=default
LLVM_ABI void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
LLVM_ABI void removeMarker()
Handle the removal of a marker: the position of debug-info has gone away, but the stored debug record...
LLVM_ABI void dropDbgRecords()
Erase all DbgRecords in this DbgMarker.
A typed tracking MDNode reference that does not require a definition for its parameter type.
T * get() const
Get the underlying type.
Base class for non-instruction debug metadata records that have positions within IR.
LLVM_ABI LLVMContext & getContext()
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
LLVM_ABI void insertAfter(DbgRecord *InsertAfter)
LLVM_ABI void moveAfter(DbgRecord *MoveAfter)
LLVM_ABI void insertBefore(DbgRecord *InsertBefore)
LLVM_ABI bool isEquivalentTo(const DbgRecord &R) const
Same as isIdenticalToWhenDefined but checks DebugLoc too.
LLVM_ABI void removeFromParent()
DbgRecord(Kind RecordKind, DebugLoc DL)
LLVM_ABI void moveBefore(DbgRecord *MoveBefore)
simple_ilist< DbgRecord >::iterator self_iterator
DebugLoc getDebugLoc() const
LLVM_ABI void eraseFromParent()
Kind RecordKind
Subclass discriminator.
LLVM_ABI bool isIdenticalToWhenDefined(const DbgRecord &R) const
LLVM_ABI DbgRecord * clone() const
LLVM_ABI void deleteRecord()
Methods that dispatch to subclass implementations.
LLVM_ABI Module * getModule()
LLVM_ABI BasicBlock * getBlock()
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.
LLVM_ABI const BasicBlock * getParent() const
LLVM_ABI const Instruction * getInstruction() const
LLVM_ABI Function * getFunction()
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.
LLVM_ABI bool isKillLocation() const
LLVM_ABI std::optional< DbgVariableFragmentInfo > getFragment() const
LLVM_ABI void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
DbgRecordParamRef< DIExpression > Expression
LLVM_ABI Value * getAddress() const
LocationType Type
Classification of the debug-info record that this DbgVariableRecord represents.
LLVM_ABI bool isKillAddress() const
Check whether this kills the address component.
DbgRecordParamRef< DILocalVariable > Variable
LLVM_ABI void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
LLVM_ABI unsigned getNumVariableLocationOps() const
LLVM_ABI DbgVariableRecord * clone() const
LLVM_ABI DIAssignID * getAssignID() const
static LLVM_ABI DbgVariableRecord * createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
static LLVM_ABI DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
LLVM_ABI void setAssignId(DIAssignID *New)
static LLVM_ABI DbgVariableRecord * createDVRAssign(Value *Val, DILocalVariable *Variable, DIExpression *Expression, DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
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)
static LLVM_ABI DbgVariableRecord * createDbgVariableRecord(Value *Location, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
LLVM_ABI std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
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...
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
LLVM_ABI DbgVariableRecord(const DbgVariableIntrinsic *DVI)
Create a new DbgVariableRecord representing the intrinsic DVI, for example the assignment represented...
LLVM_ABI iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
@ 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.
A debug info location.
Definition DebugLoc.h:124
Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...
Definition Metadata.h:220
std::array< Metadata *, 3 > DebugValues
Definition Metadata.h:226
void resetDebugValue(size_t Idx, Metadata *DebugValue)
Definition Metadata.h:281
Class representing an expression and its matching format.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:209
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...
Definition Instruction.h:85
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.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1078
LLVMContext & getContext() const
Definition Metadata.h:1242
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:104
Root of the metadata hierarchy.
Definition Metadata.h:64
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:67
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.
Definition Type.h:45
Value wrapper in the Metadata hierarchy.
Definition Metadata.h:458
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:503
LLVM Value Representation.
Definition Value.h:75
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
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:53
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.
Definition STLExtras.h:1751
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1732
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1897