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
222
224 Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable,
226 const DILocation *DI) {
227 auto *Link = LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID);
228 assert(Link && "Linked instruction must have DIAssign metadata attached");
229 auto *NewDVRAssign = DbgVariableRecord::createDVRAssign(
232 LinkedInstr->getParent()->insertDbgRecordAfter(NewDVRAssign, LinkedInstr);
233 return NewDVRAssign;
234}
235
238 auto *MD = getRawLocation();
239 // If a Value has been deleted, the "location" for this DbgVariableRecord will
240 // be replaced by nullptr. Return an empty range.
241 if (!MD)
242 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
243 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
244
245 // If operand is ValueAsMetadata, return a range over just that operand.
246 if (auto *VAM = dyn_cast<ValueAsMetadata>(MD))
247 return {location_op_iterator(VAM), location_op_iterator(VAM + 1)};
248
249 // If operand is DIArgList, return a range over its args.
250 if (auto *AL = dyn_cast<DIArgList>(MD))
251 return {location_op_iterator(AL->args_begin()),
252 location_op_iterator(AL->args_end())};
253
254 // Operand is an empty metadata tuple, so return empty iterator.
255 assert(cast<MDNode>(MD)->getNumOperands() == 0);
256 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
257 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
258}
259
261 if (hasArgList())
262 return cast<DIArgList>(getRawLocation())->getArgs().size();
263 return 1;
264}
265
267 auto *MD = getRawLocation();
268 if (!MD)
269 return nullptr;
270
271 if (auto *AL = dyn_cast<DIArgList>(MD))
272 return AL->getArgs()[OpIdx]->getValue();
273 if (isa<MDNode>(MD))
274 return nullptr;
276 "Attempted to get location operand from DbgVariableRecord with none.");
277 auto *V = cast<ValueAsMetadata>(MD);
278 assert(OpIdx == 0 && "Operand Index must be 0 for a debug intrinsic with a "
279 "single location operand.");
280 return V->getValue();
281}
282
288
290 Value *NewValue,
291 bool AllowEmpty) {
292 assert(NewValue && "Values must be non-null");
293
294 bool DbgAssignAddrReplaced = isDbgAssign() && OldValue == getAddress();
295 if (DbgAssignAddrReplaced)
296 setAddress(NewValue);
297
298 auto Locations = location_ops();
299 auto OldIt = find(Locations, OldValue);
300 if (OldIt == Locations.end()) {
301 if (AllowEmpty || DbgAssignAddrReplaced)
302 return;
303 llvm_unreachable("OldValue must be a current location");
304 }
305
306 if (!hasArgList()) {
307 // Set our location to be the MAV wrapping the new Value.
309 ? cast<MetadataAsValue>(NewValue)->getMetadata()
310 : ValueAsMetadata::get(NewValue));
311 return;
312 }
313
314 // We must be referring to a DIArgList, produce a new operands vector with the
315 // old value replaced, generate a new DIArgList and set it as our location.
317 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
318 for (auto *VMD : Locations)
319 MDs.push_back(VMD == *OldIt ? NewOperand : getAsMetadata(VMD));
321}
322
324 Value *NewValue) {
325 assert(OpIdx < getNumVariableLocationOps() && "Invalid Operand Index");
326
327 if (!hasArgList()) {
329 ? cast<MetadataAsValue>(NewValue)->getMetadata()
330 : ValueAsMetadata::get(NewValue));
331 return;
332 }
333
335 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
336 for (unsigned Idx = 0; Idx < getNumVariableLocationOps(); ++Idx)
337 MDs.push_back(Idx == OpIdx ? NewOperand
339
341}
342
345 assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
346 NewValues.size()) &&
347 "NewExpr for debug variable intrinsic does not reference every "
348 "location operand.");
349 assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
352 for (auto *VMD : location_ops())
353 MDs.push_back(getAsMetadata(VMD));
354 for (auto *VMD : NewValues)
355 MDs.push_back(getAsMetadata(VMD));
357}
358
360 // TODO: When/if we remove duplicate values from DIArgLists, we don't need
361 // this set anymore.
362 SmallPtrSet<Value *, 4> RemovedValues;
363 for (Value *OldValue : location_ops()) {
364 if (!RemovedValues.insert(OldValue).second)
365 continue;
366 Value *Poison = PoisonValue::get(OldValue->getType());
368 }
369}
370
372 return (!hasArgList() && isa<MDNode>(getRawLocation())) ||
374 any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
375}
376
377std::optional<DbgVariableFragmentInfo> DbgVariableRecord::getFragment() const {
378 return getExpression()->getFragmentInfo();
379}
380
381std::optional<uint64_t> DbgVariableRecord::getFragmentSizeInBits() const {
382 if (auto Fragment = getExpression()->getFragmentInfo())
383 return Fragment->SizeInBits;
384 return getVariable()->getSizeInBits();
385}
386
388 switch (RecordKind) {
389 case ValueKind:
390 return cast<DbgVariableRecord>(this)->clone();
391 case LabelKind:
392 return cast<DbgLabelRecord>(this)->clone();
393 };
394 llvm_unreachable("unsupported DbgRecord kind");
395}
396
398 return new DbgVariableRecord(*this);
399}
400
401DbgLabelRecord *DbgLabelRecord::clone() const {
402 return new DbgLabelRecord(getLabel(), getDebugLoc());
403}
404
407 Instruction *InsertBefore) const {
408 [[maybe_unused]] DICompileUnit *Unit =
409 getDebugLoc()->getScope()->getSubprogram()->getUnit();
410 assert(M && Unit &&
411 "Cannot clone from BasicBlock that is not part of a Module or "
412 "DICompileUnit!");
413 LLVMContext &Context = getDebugLoc()->getContext();
414 Function *IntrinsicFn;
415
416 // Work out what sort of intrinsic we're going to produce.
417 switch (getType()) {
419 IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_declare);
420 break;
422 IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_value);
423 break;
425 IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_assign);
426 break;
429 llvm_unreachable("Invalid LocationType");
430 }
431
432 // Create the intrinsic from this DbgVariableRecord's information, optionally
433 // insert into the target location.
436 "DbgVariableRecord's RawLocation should be non-null.");
437 if (isDbgAssign()) {
438 Value *AssignArgs[] = {
446 IntrinsicFn->getFunctionType(), IntrinsicFn, AssignArgs));
447 } else {
448 Value *Args[] = {MetadataAsValue::get(Context, getRawLocation()),
452 CallInst::Create(IntrinsicFn->getFunctionType(), IntrinsicFn, Args));
453 }
454 DVI->setTailCall();
455 DVI->setDebugLoc(getDebugLoc());
456 if (InsertBefore)
457 DVI->insertBefore(InsertBefore->getIterator());
458
459 return DVI;
460}
461
464 Instruction *InsertBefore) const {
465 auto *LabelFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_label);
466 Value *Args[] = {
469 CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
470 DbgLabel->setTailCall();
471 DbgLabel->setDebugLoc(getDebugLoc());
472 if (InsertBefore)
473 DbgLabel->insertBefore(InsertBefore->getIterator());
474 return DbgLabel;
475}
476
478 auto *MD = getRawAddress();
479 if (auto *V = dyn_cast_or_null<ValueAsMetadata>(MD))
480 return V->getValue();
481
482 // When the value goes to null, it gets replaced by an empty MDNode.
483 assert((!MD || !cast<MDNode>(MD)->getNumOperands()) &&
484 "Expected an empty MDNode");
485 return nullptr;
486}
487
491
495
500
502 Value *Addr = getAddress();
503 return !Addr || isa<UndefValue>(Addr);
504}
505
507 return Marker->MarkedInstr;
508}
509
511 return Marker->MarkedInstr->getParent();
512}
513
514BasicBlock *DbgRecord::getParent() { return Marker->MarkedInstr->getParent(); }
515
516BasicBlock *DbgRecord::getBlock() { return Marker->getParent(); }
517
518const BasicBlock *DbgRecord::getBlock() const { return Marker->getParent(); }
519
521
523 return getBlock()->getParent();
524}
525
527
529 return getFunction()->getParent();
530}
531
533
535 return getBlock()->getContext();
536}
537
539 assert(!getMarker() &&
540 "Cannot insert a DbgRecord that is already has a DbgMarker!");
541 assert(InsertBefore->getMarker() &&
542 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
543 "DbgMarker!");
544 InsertBefore->getMarker()->insertDbgRecord(this, InsertBefore);
545}
547 assert(!getMarker() &&
548 "Cannot insert a DbgRecord that is already has a DbgMarker!");
549 assert(InsertAfter->getMarker() &&
550 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
551 "DbgMarker!");
552 InsertAfter->getMarker()->insertDbgRecordAfter(this, InsertAfter);
553}
554
556 assert(!getMarker() &&
557 "Cannot insert a DbgRecord that is already has a DbgMarker!");
558 assert(InsertBefore->getMarker() &&
559 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
560 "DbgMarker!");
561 InsertBefore->getMarker()->insertDbgRecord(this, &*InsertBefore);
562}
564 assert(!getMarker() &&
565 "Cannot insert a DbgRecord that is already has a DbgMarker!");
566 assert(InsertAfter->getMarker() &&
567 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
568 "DbgMarker!");
569 InsertAfter->getMarker()->insertDbgRecordAfter(this, &*InsertAfter);
570}
571
573 assert(getMarker() &&
574 "Canot move a DbgRecord that does not currently have a DbgMarker!");
576 insertBefore(MoveBefore);
577}
579 assert(getMarker() &&
580 "Canot move a DbgRecord that does not currently have a DbgMarker!");
582 insertAfter(MoveAfter);
583}
584
586 assert(getMarker() &&
587 "Canot move a DbgRecord that does not currently have a DbgMarker!");
589 insertBefore(MoveBefore);
590}
592 assert(getMarker() &&
593 "Canot move a DbgRecord that does not currently have a DbgMarker!");
595 insertAfter(MoveAfter);
596}
597
598///////////////////////////////////////////////////////////////////////////////
599
600// An empty, global, DbgMarker for the purpose of describing empty ranges of
601// DbgRecords.
603
605 while (!StoredDbgRecords.empty()) {
606 auto It = StoredDbgRecords.begin();
607 DbgRecord *DR = &*It;
608 StoredDbgRecords.erase(It);
609 DR->deleteRecord();
610 }
611}
612
614 assert(DR->getMarker() == this);
615 StoredDbgRecords.erase(DR->getIterator());
616 DR->deleteRecord();
617}
618
620 return MarkedInstr->getParent();
621}
622
623BasicBlock *DbgMarker::getParent() { return MarkedInstr->getParent(); }
624
626 // Are there any DbgRecords in this DbgMarker? If not, nothing to preserve.
627 Instruction *Owner = MarkedInstr;
628 if (StoredDbgRecords.empty()) {
630 Owner->DebugMarker = nullptr;
631 return;
632 }
633
634 // The attached DbgRecords need to be preserved; attach them to the next
635 // instruction. If there isn't a next instruction, put them on the
636 // "trailing" list.
637 DbgMarker *NextMarker = Owner->getParent()->getNextMarker(Owner);
638 if (NextMarker) {
639 NextMarker->absorbDebugValues(*this, true);
641 } else {
642 // We can avoid a deallocation -- just store this marker onto the next
643 // instruction. Unless we're at the end of the block, in which case this
644 // marker becomes the trailing marker of a degenerate block.
645 BasicBlock::iterator NextIt = std::next(Owner->getIterator());
646 if (NextIt == getParent()->end()) {
648 MarkedInstr = nullptr;
649 } else {
650 NextIt->DebugMarker = this;
651 MarkedInstr = &*NextIt;
652 }
653 }
654 Owner->DebugMarker = nullptr;
655}
656
658 MarkedInstr->DebugMarker = nullptr;
659 MarkedInstr = nullptr;
660}
661
663 if (MarkedInstr)
666 delete this;
667}
668
676
679 Marker = nullptr;
680}
681
686
687void DbgMarker::insertDbgRecord(DbgRecord *New, bool InsertAtHead) {
688 auto It = InsertAtHead ? StoredDbgRecords.begin() : StoredDbgRecords.end();
689 StoredDbgRecords.insert(It, *New);
690 New->setMarker(this);
691}
693 assert(InsertBefore->getMarker() == this &&
694 "DbgRecord 'InsertBefore' must be contained in this DbgMarker!");
695 StoredDbgRecords.insert(InsertBefore->getIterator(), *New);
696 New->setMarker(this);
697}
699 assert(InsertAfter->getMarker() == this &&
700 "DbgRecord 'InsertAfter' must be contained in this DbgMarker!");
701 StoredDbgRecords.insert(++(InsertAfter->getIterator()), *New);
702 New->setMarker(this);
703}
704
705void DbgMarker::absorbDebugValues(DbgMarker &Src, bool InsertAtHead) {
706 auto It = InsertAtHead ? StoredDbgRecords.begin() : StoredDbgRecords.end();
707 for (DbgRecord &DVR : Src.StoredDbgRecords)
708 DVR.setMarker(this);
709
710 StoredDbgRecords.splice(It, Src.StoredDbgRecords);
711}
712
715 bool InsertAtHead) {
716 for (DbgRecord &DR : Range)
717 DR.setMarker(this);
718
719 auto InsertPos =
720 (InsertAtHead) ? StoredDbgRecords.begin() : StoredDbgRecords.end();
721
722 StoredDbgRecords.splice(InsertPos, Src.StoredDbgRecords, Range.begin(),
723 Range.end());
724}
725
727 DbgMarker *From, std::optional<simple_ilist<DbgRecord>::iterator> from_here,
728 bool InsertAtHead) {
729 DbgRecord *First = nullptr;
730 // Work out what range of DbgRecords to clone: normally all the contents of
731 // the "From" marker, optionally we can start from the from_here position down
732 // to end().
733 auto Range =
734 make_range(From->StoredDbgRecords.begin(), From->StoredDbgRecords.end());
735 if (from_here.has_value())
736 Range = make_range(*from_here, From->StoredDbgRecords.end());
737
738 // Clone each DbgVariableRecord and insert into StoreDbgVariableRecords;
739 // optionally place them at the start or the end of the list.
740 auto Pos = (InsertAtHead) ? StoredDbgRecords.begin() : StoredDbgRecords.end();
741 for (DbgRecord &DR : Range) {
742 DbgRecord *New = DR.clone();
743 New->setMarker(this);
744 StoredDbgRecords.insert(Pos, *New);
745 if (!First)
746 First = New;
747 }
748
749 if (!First)
750 return {StoredDbgRecords.end(), StoredDbgRecords.end()};
751
752 if (InsertAtHead)
753 // If InsertAtHead is set, we cloned a range onto the front of of the
754 // StoredDbgRecords collection, return that range.
755 return {StoredDbgRecords.begin(), Pos};
756 else
757 // We inserted a block at the end, return that range.
758 return {First->getIterator(), StoredDbgRecords.end()};
759}
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:41
size_t size() const
size - Get the array size.
Definition ArrayRef.h:143
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 * 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:71
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