LLVM 19.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
11#include "llvm/IR/DIBuilder.h"
13
14namespace llvm {
15
16template <typename T>
18 : Ref(const_cast<T *>(Param)) {}
19template <typename T>
21 : Ref(const_cast<MDNode *>(Param)) {}
22
23template <typename T> T *DbgRecordParamRef<T>::get() const {
24 return cast<T>(Ref);
25}
26
28template class DbgRecordParamRef<DILabel>;
30
32 : DbgRecord(ValueKind, DVI->getDebugLoc()),
33 DebugValueUser({DVI->getRawLocation(), nullptr, nullptr}),
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: {
46 static_cast<const DbgAssignIntrinsic *>(DVI);
47 resetDebugValue(1, Assign->getRawAddress());
48 AddressExpression = Assign->getAddressExpression();
49 setAssignId(Assign->getAssignID());
50 break;
51 }
52 default:
54 "Trying to create a DbgVariableRecord with an invalid intrinsic type!");
55 }
56}
57
59 : DbgRecord(ValueKind, DVR.getDebugLoc()), DebugValueUser(DVR.DebugValues),
60 Type(DVR.getType()), Variable(DVR.getVariable()),
61 Expression(DVR.getExpression()),
62 AddressExpression(DVR.AddressExpression) {}
63
65 DIExpression *Expr, const DILocation *DI,
67 : DbgRecord(ValueKind, DI), DebugValueUser({Location, nullptr, nullptr}),
68 Type(Type), Variable(DV), Expression(Expr) {}
69
72 DIAssignID *AssignID, Metadata *Address,
73 DIExpression *AddressExpression,
74 const DILocation *DI)
75 : DbgRecord(ValueKind, DI), DebugValueUser({Value, Address, AssignID}),
76 Type(LocationType::Assign), Variable(Variable), Expression(Expression),
77 AddressExpression(AddressExpression) {}
78
80 switch (RecordKind) {
81 case ValueKind:
82 delete cast<DbgVariableRecord>(this);
83 return;
84 case LabelKind:
85 delete cast<DbgLabelRecord>(this);
86 return;
87 }
88 llvm_unreachable("unsupported DbgRecord kind");
89}
90
91void DbgRecord::print(raw_ostream &O, bool IsForDebug) const {
92 switch (RecordKind) {
93 case ValueKind:
94 cast<DbgVariableRecord>(this)->print(O, IsForDebug);
95 return;
96 case LabelKind:
97 cast<DbgLabelRecord>(this)->print(O, IsForDebug);
98 return;
99 };
100 llvm_unreachable("unsupported DbgRecord kind");
101}
102
104 bool IsForDebug) const {
105 switch (RecordKind) {
106 case ValueKind:
107 cast<DbgVariableRecord>(this)->print(O, MST, IsForDebug);
108 return;
109 case LabelKind:
110 cast<DbgLabelRecord>(this)->print(O, MST, IsForDebug);
111 return;
112 };
113 llvm_unreachable("unsupported DbgRecord kind");
114}
115
117 if (RecordKind != R.RecordKind)
118 return false;
119 switch (RecordKind) {
120 case ValueKind:
121 return cast<DbgVariableRecord>(this)->isIdenticalToWhenDefined(
122 *cast<DbgVariableRecord>(&R));
123 case LabelKind:
124 return cast<DbgLabelRecord>(this)->getLabel() ==
125 cast<DbgLabelRecord>(R).getLabel();
126 };
127 llvm_unreachable("unsupported DbgRecord kind");
128}
129
131 return getDebugLoc() == R.getDebugLoc() && isIdenticalToWhenDefined(R);
132}
133
136 switch (RecordKind) {
137 case ValueKind:
138 return cast<DbgVariableRecord>(this)->createDebugIntrinsic(M, InsertBefore);
139 case LabelKind:
140 return cast<DbgLabelRecord>(this)->createDebugIntrinsic(M, InsertBefore);
141 };
142 llvm_unreachable("unsupported DbgRecord kind");
143}
144
145DbgLabelRecord::DbgLabelRecord(MDNode *Label, MDNode *DL)
146 : DbgRecord(LabelKind, DebugLoc(DL)), Label(Label) {
147 assert(Label && "Unexpected nullptr");
148 assert((isa<DILabel>(Label) || Label->isTemporary()) &&
149 "Label type must be or resolve to a DILabel");
150}
151DbgLabelRecord::DbgLabelRecord(DILabel *Label, DebugLoc DL)
152 : DbgRecord(LabelKind, DL), Label(Label) {
153 assert(Label && "Unexpected nullptr");
154}
155
157 MDNode *DL) {
158 return new DbgLabelRecord(Label, DL);
159}
160
162 Metadata *Val, MDNode *Variable,
163 MDNode *Expression, MDNode *AssignID,
165 MDNode *AddressExpression, MDNode *DI)
166 : DbgRecord(ValueKind, DebugLoc(DI)),
167 DebugValueUser({Val, Address, AssignID}), Type(Type), Variable(Variable),
168 Expression(Expression), AddressExpression(AddressExpression) {}
169
173 MDNode *AddressExpression, MDNode *DI) {
174 return new DbgVariableRecord(Type, Val, Variable, Expression, AssignID,
176}
177
180 DIExpression *Expr,
181 const DILocation *DI) {
182 return new DbgVariableRecord(ValueAsMetadata::get(Location), DV, Expr, DI,
184}
185
187 Value *Location, DILocalVariable *DV, DIExpression *Expr,
188 const DILocation *DI, DbgVariableRecord &InsertBefore) {
189 auto *NewDbgVariableRecord = createDbgVariableRecord(Location, DV, Expr, DI);
190 NewDbgVariableRecord->insertBefore(&InsertBefore);
191 return NewDbgVariableRecord;
192}
193
195 DILocalVariable *DV,
196 DIExpression *Expr,
197 const DILocation *DI) {
198 return new DbgVariableRecord(ValueAsMetadata::get(Address), DV, Expr, DI,
200}
201
204 DIExpression *Expr, const DILocation *DI,
205 DbgVariableRecord &InsertBefore) {
206 auto *NewDVRDeclare = createDVRDeclare(Address, DV, Expr, DI);
207 NewDVRDeclare->insertBefore(&InsertBefore);
208 return NewDVRDeclare;
209}
210
213 DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression,
214 const DILocation *DI) {
216 AssignID, ValueAsMetadata::get(Address),
218}
219
221 Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable,
222 DIExpression *Expression, Value *Address, DIExpression *AddressExpression,
223 const DILocation *DI) {
224 auto *Link = LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID);
225 assert(Link && "Linked instruction must have DIAssign metadata attached");
226 auto *NewDVRAssign = DbgVariableRecord::createDVRAssign(
227 Val, Variable, Expression, cast<DIAssignID>(Link), Address,
229 LinkedInstr->getParent()->insertDbgRecordAfter(NewDVRAssign, LinkedInstr);
230 return NewDVRAssign;
231}
232
235 auto *MD = getRawLocation();
236 // If a Value has been deleted, the "location" for this DbgVariableRecord will
237 // be replaced by nullptr. Return an empty range.
238 if (!MD)
239 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
240 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
241
242 // If operand is ValueAsMetadata, return a range over just that operand.
243 if (auto *VAM = dyn_cast<ValueAsMetadata>(MD))
244 return {location_op_iterator(VAM), location_op_iterator(VAM + 1)};
245
246 // If operand is DIArgList, return a range over its args.
247 if (auto *AL = dyn_cast<DIArgList>(MD))
248 return {location_op_iterator(AL->args_begin()),
249 location_op_iterator(AL->args_end())};
250
251 // Operand is an empty metadata tuple, so return empty iterator.
252 assert(cast<MDNode>(MD)->getNumOperands() == 0);
253 return {location_op_iterator(static_cast<ValueAsMetadata *>(nullptr)),
254 location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
255}
256
258 if (hasArgList())
259 return cast<DIArgList>(getRawLocation())->getArgs().size();
260 return 1;
261}
262
264 auto *MD = getRawLocation();
265 if (!MD)
266 return nullptr;
267
268 if (auto *AL = dyn_cast<DIArgList>(MD))
269 return AL->getArgs()[OpIdx]->getValue();
270 if (isa<MDNode>(MD))
271 return nullptr;
272 assert(isa<ValueAsMetadata>(MD) &&
273 "Attempted to get location operand from DbgVariableRecord with none.");
274 auto *V = cast<ValueAsMetadata>(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<MetadataAsValue>(V) ? dyn_cast<ValueAsMetadata>(
282 cast<MetadataAsValue>(V)->getMetadata())
284}
285
287 Value *NewValue,
288 bool AllowEmpty) {
289 assert(NewValue && "Values must be non-null");
290
291 bool DbgAssignAddrReplaced = isDbgAssign() && OldValue == getAddress();
292 if (DbgAssignAddrReplaced)
293 setAddress(NewValue);
294
295 auto Locations = location_ops();
296 auto OldIt = find(Locations, OldValue);
297 if (OldIt == Locations.end()) {
298 if (AllowEmpty || DbgAssignAddrReplaced)
299 return;
300 llvm_unreachable("OldValue must be a current location");
301 }
302
303 if (!hasArgList()) {
304 // Set our location to be the MAV wrapping the new Value.
305 setRawLocation(isa<MetadataAsValue>(NewValue)
306 ? cast<MetadataAsValue>(NewValue)->getMetadata()
307 : ValueAsMetadata::get(NewValue));
308 return;
309 }
310
311 // We must be referring to a DIArgList, produce a new operands vector with the
312 // old value replaced, generate a new DIArgList and set it as our location.
314 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
315 for (auto *VMD : Locations)
316 MDs.push_back(VMD == *OldIt ? NewOperand : getAsMetadata(VMD));
318}
319
321 Value *NewValue) {
322 assert(OpIdx < getNumVariableLocationOps() && "Invalid Operand Index");
323
324 if (!hasArgList()) {
325 setRawLocation(isa<MetadataAsValue>(NewValue)
326 ? cast<MetadataAsValue>(NewValue)->getMetadata()
327 : ValueAsMetadata::get(NewValue));
328 return;
329 }
330
332 ValueAsMetadata *NewOperand = getAsMetadata(NewValue);
333 for (unsigned Idx = 0; Idx < getNumVariableLocationOps(); ++Idx)
334 MDs.push_back(Idx == OpIdx ? NewOperand
336
338}
339
342 assert(NewExpr->hasAllLocationOps(getNumVariableLocationOps() +
343 NewValues.size()) &&
344 "NewExpr for debug variable intrinsic does not reference every "
345 "location operand.");
346 assert(!is_contained(NewValues, nullptr) && "New values must be non-null");
349 for (auto *VMD : location_ops())
350 MDs.push_back(getAsMetadata(VMD));
351 for (auto *VMD : NewValues)
352 MDs.push_back(getAsMetadata(VMD));
354}
355
357 // TODO: When/if we remove duplicate values from DIArgLists, we don't need
358 // this set anymore.
359 SmallPtrSet<Value *, 4> RemovedValues;
360 for (Value *OldValue : location_ops()) {
361 if (!RemovedValues.insert(OldValue).second)
362 continue;
363 Value *Poison = PoisonValue::get(OldValue->getType());
364 replaceVariableLocationOp(OldValue, Poison);
365 }
366}
367
369 return (!hasArgList() && isa<MDNode>(getRawLocation())) ||
371 any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
372}
373
374std::optional<uint64_t> DbgVariableRecord::getFragmentSizeInBits() const {
375 if (auto Fragment = getExpression()->getFragmentInfo())
376 return Fragment->SizeInBits;
377 return getVariable()->getSizeInBits();
378}
379
381 switch (RecordKind) {
382 case ValueKind:
383 return cast<DbgVariableRecord>(this)->clone();
384 case LabelKind:
385 return cast<DbgLabelRecord>(this)->clone();
386 };
387 llvm_unreachable("unsupported DbgRecord kind");
388}
389
391 return new DbgVariableRecord(*this);
392}
393
395 return new DbgLabelRecord(getLabel(), getDebugLoc());
396}
397
400 Instruction *InsertBefore) const {
401 [[maybe_unused]] DICompileUnit *Unit =
402 getDebugLoc().get()->getScope()->getSubprogram()->getUnit();
403 assert(M && Unit &&
404 "Cannot clone from BasicBlock that is not part of a Module or "
405 "DICompileUnit!");
406 LLVMContext &Context = getDebugLoc()->getContext();
407 Function *IntrinsicFn;
408
409 // Work out what sort of intrinsic we're going to produce.
410 switch (getType()) {
412 IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_declare);
413 break;
415 IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_value);
416 break;
418 IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_assign);
419 break;
422 llvm_unreachable("Invalid LocationType");
423 }
424
425 // Create the intrinsic from this DbgVariableRecord's information, optionally
426 // insert into the target location.
429 "DbgVariableRecord's RawLocation should be non-null.");
430 if (isDbgAssign()) {
431 Value *AssignArgs[] = {
438 DVI = cast<DbgVariableIntrinsic>(CallInst::Create(
439 IntrinsicFn->getFunctionType(), IntrinsicFn, AssignArgs));
440 } else {
441 Value *Args[] = {MetadataAsValue::get(Context, getRawLocation()),
444 DVI = cast<DbgVariableIntrinsic>(
445 CallInst::Create(IntrinsicFn->getFunctionType(), IntrinsicFn, Args));
446 }
447 DVI->setTailCall();
448 DVI->setDebugLoc(getDebugLoc());
449 if (InsertBefore)
450 DVI->insertBefore(InsertBefore);
451
452 return DVI;
453}
454
457 Instruction *InsertBefore) const {
458 auto *LabelFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_label);
459 Value *Args[] = {
461 DbgLabelInst *DbgLabel = cast<DbgLabelInst>(
462 CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
463 DbgLabel->setTailCall();
464 DbgLabel->setDebugLoc(getDebugLoc());
465 if (InsertBefore)
466 DbgLabel->insertBefore(InsertBefore);
467 return DbgLabel;
468}
469
471 auto *MD = getRawAddress();
472 if (auto *V = dyn_cast<ValueAsMetadata>(MD))
473 return V->getValue();
474
475 // When the value goes to null, it gets replaced by an empty MDNode.
476 assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
477 return nullptr;
478}
479
481 return cast<DIAssignID>(DebugValues[2]);
482}
483
485 resetDebugValue(2, New);
486}
487
491}
492
494 Value *Addr = getAddress();
495 return !Addr || isa<UndefValue>(Addr);
496}
497
499 return Marker->MarkedInstr;
500}
501
503 return Marker->MarkedInstr->getParent();
504}
505
507
509
510const BasicBlock *DbgRecord::getBlock() const { return Marker->getParent(); }
511
513
515 return getBlock()->getParent();
516}
517
519
521 return getFunction()->getParent();
522}
523
525
527 return getBlock()->getContext();
528}
529
531 assert(!getMarker() &&
532 "Cannot insert a DbgRecord that is already has a DbgMarker!");
533 assert(InsertBefore->getMarker() &&
534 "Cannot insert a DbgRecord before a DbgRecord that does not have a "
535 "DbgMarker!");
536 InsertBefore->getMarker()->insertDbgRecord(this, InsertBefore);
537}
539 assert(!getMarker() &&
540 "Cannot insert a DbgRecord that is already has a DbgMarker!");
541 assert(InsertAfter->getMarker() &&
542 "Cannot insert a DbgRecord after a DbgRecord that does not have a "
543 "DbgMarker!");
544 InsertAfter->getMarker()->insertDbgRecordAfter(this, InsertAfter);
545}
547 assert(getMarker() &&
548 "Canot move a DbgRecord that does not currently have a DbgMarker!");
550 insertBefore(MoveBefore);
551}
553 assert(getMarker() &&
554 "Canot move a DbgRecord that does not currently have a DbgMarker!");
556 insertAfter(MoveAfter);
557}
558
559///////////////////////////////////////////////////////////////////////////////
560
561// An empty, global, DbgMarker for the purpose of describing empty ranges of
562// DbgRecords.
564
566 while (!StoredDbgRecords.empty()) {
567 auto It = StoredDbgRecords.begin();
568 DbgRecord *DR = &*It;
569 StoredDbgRecords.erase(It);
570 DR->deleteRecord();
571 }
572}
573
575 assert(DR->getMarker() == this);
576 StoredDbgRecords.erase(DR->getIterator());
577 DR->deleteRecord();
578}
579
581 return MarkedInstr->getParent();
582}
583
585
587 // Are there any DbgRecords in this DbgMarker? If not, nothing to preserve.
588 Instruction *Owner = MarkedInstr;
589 if (StoredDbgRecords.empty()) {
591 Owner->DebugMarker = nullptr;
592 return;
593 }
594
595 // The attached DbgRecords need to be preserved; attach them to the next
596 // instruction. If there isn't a next instruction, put them on the
597 // "trailing" list.
598 DbgMarker *NextMarker = Owner->getParent()->getNextMarker(Owner);
599 if (NextMarker) {
600 NextMarker->absorbDebugValues(*this, true);
602 } else {
603 // We can avoid a deallocation -- just store this marker onto the next
604 // instruction. Unless we're at the end of the block, in which case this
605 // marker becomes the trailing marker of a degenerate block.
606 BasicBlock::iterator NextIt = std::next(Owner->getIterator());
607 if (NextIt == getParent()->end()) {
609 MarkedInstr = nullptr;
610 } else {
611 NextIt->DebugMarker = this;
612 MarkedInstr = &*NextIt;
613 }
614 }
615 Owner->DebugMarker = nullptr;
616}
617
619 MarkedInstr->DebugMarker = nullptr;
620 MarkedInstr = nullptr;
621}
622
624 if (MarkedInstr)
627 delete this;
628}
629
631 return make_range(StoredDbgRecords.begin(), StoredDbgRecords.end());
632}
635 return make_range(StoredDbgRecords.begin(), StoredDbgRecords.end());
636}
637
640 Marker = nullptr;
641}
642
645 deleteRecord();
646}
647
648void DbgMarker::insertDbgRecord(DbgRecord *New, bool InsertAtHead) {
649 auto It = InsertAtHead ? StoredDbgRecords.begin() : StoredDbgRecords.end();
650 StoredDbgRecords.insert(It, *New);
651 New->setMarker(this);
652}
654 assert(InsertBefore->getMarker() == this &&
655 "DbgRecord 'InsertBefore' must be contained in this DbgMarker!");
656 StoredDbgRecords.insert(InsertBefore->getIterator(), *New);
657 New->setMarker(this);
658}
660 assert(InsertAfter->getMarker() == this &&
661 "DbgRecord 'InsertAfter' must be contained in this DbgMarker!");
662 StoredDbgRecords.insert(++(InsertAfter->getIterator()), *New);
663 New->setMarker(this);
664}
665
666void DbgMarker::absorbDebugValues(DbgMarker &Src, bool InsertAtHead) {
667 auto It = InsertAtHead ? StoredDbgRecords.begin() : StoredDbgRecords.end();
668 for (DbgRecord &DVR : Src.StoredDbgRecords)
669 DVR.setMarker(this);
670
671 StoredDbgRecords.splice(It, Src.StoredDbgRecords);
672}
673
676 bool InsertAtHead) {
677 for (DbgRecord &DR : Range)
678 DR.setMarker(this);
679
680 auto InsertPos =
681 (InsertAtHead) ? StoredDbgRecords.begin() : StoredDbgRecords.end();
682
683 StoredDbgRecords.splice(InsertPos, Src.StoredDbgRecords, Range.begin(),
684 Range.end());
685}
686
688 DbgMarker *From, std::optional<simple_ilist<DbgRecord>::iterator> from_here,
689 bool InsertAtHead) {
690 DbgRecord *First = nullptr;
691 // Work out what range of DbgRecords to clone: normally all the contents of
692 // the "From" marker, optionally we can start from the from_here position down
693 // to end().
694 auto Range =
695 make_range(From->StoredDbgRecords.begin(), From->StoredDbgRecords.end());
696 if (from_here.has_value())
697 Range = make_range(*from_here, From->StoredDbgRecords.end());
698
699 // Clone each DbgVariableRecord and insert into StoreDbgVariableRecords;
700 // optionally place them at the start or the end of the list.
701 auto Pos = (InsertAtHead) ? StoredDbgRecords.begin() : StoredDbgRecords.end();
702 for (DbgRecord &DR : Range) {
703 DbgRecord *New = DR.clone();
704 New->setMarker(this);
705 StoredDbgRecords.insert(Pos, *New);
706 if (!First)
707 First = New;
708 }
709
710 if (!First)
711 return {StoredDbgRecords.end(), StoredDbgRecords.end()};
712
713 if (InsertAtHead)
714 // If InsertAtHead is set, we cloned a range onto the front of of the
715 // StoredDbgRecords collection, return that range.
716 return {StoredDbgRecords.begin(), Pos};
717 else
718 // We inserted a block at the end, return that range.
719 return {First->getIterator(), StoredDbgRecords.end()};
720}
721
722} // end namespace llvm
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
uint64_t Addr
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)
Definition: TapiFile.cpp:40
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:165
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
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:206
void insertDbgRecordAfter(DbgRecord *DR, Instruction *I)
Insert a DbgRecord into a block at the position given by I.
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:165
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:168
DbgMarker * getNextMarker(Instruction *I)
Return the DbgMarker for the position that comes after I.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr, BasicBlock::iterator InsertBefore)
void setTailCall(bool IsTc=true)
static DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
Assignment ID.
DWARF expression.
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
Debug location.
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.
DbgLabelInst * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
This class is used to track label information.
Definition: DwarfDebug.h:289
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.
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
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...
bool isKillAddress() const
Check whether this kills the address component.
DbgRecordParamRef< DILocalVariable > Variable
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)
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)
static DbgVariableRecord * createDVRAssign(Value *Val, DILocalVariable *Variable, DIExpression *Expression, DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
unsigned getNumVariableLocationOps() const
DbgVariableIntrinsic * createDebugIntrinsic(Module *M, Instruction *InsertBefore) const
Convert this DbgVariableRecord back into a dbg.value intrinsic.
void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
static DbgVariableRecord * createLinkedDVRAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *Variable, DIExpression *Expression, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
DbgRecordParamRef< DIExpression > AddressExpression
DIExpression * getAddressExpression() const
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
A debug info location.
Definition: DebugLoc.h:33
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:20
Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...
Definition: Metadata.h:212
std::array< Metadata *, 3 > DebugValues
Definition: Metadata.h:218
void resetDebugValue(size_t Idx, Metadata *DebugValue)
Definition: Metadata.h:273
Class representing an expression and its matching format.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:202
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:655
DbgMarker * DebugMarker
Optional marker recording the position for debugging information that takes effect immediately before...
Definition: Instruction.h:64
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const BasicBlock * getParent() const
Definition: Instruction.h:152
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:359
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:451
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1067
LLVMContext & getContext() const
Definition: Metadata.h:1231
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:103
Root of the metadata hierarchy.
Definition: Metadata.h:62
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1814
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1795
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:450
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:495
LLVM Value Representation.
Definition: Value.h:74
self_iterator getIterator()
Definition: ilist_node.h:109
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator
Definition: simple_ilist.h:97
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1474
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1742
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.
Definition: STLExtras.h:1729
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.
Definition: STLExtras.h:1879