LLVM 24.0.0git
DIBuilder.cpp
Go to the documentation of this file.
1//===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
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//
9// This file implements the DIBuilder.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/DIBuilder.h"
14#include "LLVMContextImpl.h"
15#include "llvm/ADT/APInt.h"
16#include "llvm/ADT/APSInt.h"
18#include "llvm/IR/Constants.h"
19#include "llvm/IR/DebugInfo.h"
20#include "llvm/IR/Module.h"
21#include <optional>
22
23using namespace llvm;
24using namespace llvm::dwarf;
25
26DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
27 : M(m), VMContext(M.getContext()), CUNode(CU),
28 AllowUnresolvedNodes(AllowUnresolvedNodes) {
29 if (CUNode) {
30 if (const auto &ETs = CUNode->getEnumTypes())
31 EnumTypes.assign(ETs.begin(), ETs.end());
32 if (const auto &RTs = CUNode->getRetainedTypes())
33 AllRetainTypes.assign(RTs.begin(), RTs.end());
34 if (const auto &GVs = CUNode->getGlobalVariables())
35 Globals.assign(GVs.begin(), GVs.end());
36 if (const auto &IMs = CUNode->getImportedEntities())
37 ImportedModules.assign(IMs.begin(), IMs.end());
38 if (const auto &MNs = CUNode->getMacros())
39 AllMacrosPerParent.insert({nullptr, {llvm::from_range, MNs}});
40 }
41}
42
43void DIBuilder::trackIfUnresolved(MDNode *N) {
44 if (!N)
45 return;
46 if (N->isResolved())
47 return;
48
49 assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
50 UnresolvedNodes.emplace_back(N);
51}
52
54 auto PN = SubprogramTrackedNodes.find(SP);
55 if (PN == SubprogramTrackedNodes.end())
56 return;
57
58 SetVector<Metadata *> RetainedNodes;
59 for (MDNode *N : llvm::concat<MDNode *>(SP->getRetainedNodes(), PN->second)) {
60 // If the tracked node N was temporary, and the DIBuilder user replaced it
61 // with a node that does not belong to SP or is non-local, do not add N to
62 // SP's retainedNodes list.
65 if (Scope && Scope->getSubprogram() == SP)
66 RetainedNodes.insert(N);
67 }
68
69 SP->replaceRetainedNodes(
70 MDTuple::get(VMContext, RetainedNodes.getArrayRef()));
71}
72
74 if (!CUNode) {
75 assert(!AllowUnresolvedNodes &&
76 "creating type nodes without a CU is not supported");
77 return;
78 }
79
80 if (!EnumTypes.empty())
81 CUNode->replaceEnumTypes(
82 MDTuple::get(VMContext, SmallVector<Metadata *, 16>(EnumTypes.begin(),
83 EnumTypes.end())));
84
85 SmallVector<Metadata *, 16> RetainValues;
86 // Declarations and definitions of the same type may be retained. Some
87 // clients RAUW these pairs, leaving duplicates in the retained types
88 // list. Use a set to remove the duplicates while we transform the
89 // TrackingVHs back into Values.
91 for (const TrackingMDNodeRef &N : AllRetainTypes)
92 if (RetainSet.insert(N).second)
93 RetainValues.push_back(N);
94
95 if (!RetainValues.empty())
96 CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
97
98 for (auto *SP : AllSubprograms)
100 for (auto *N : RetainValues)
101 if (auto *SP = dyn_cast<DISubprogram>(N))
103
104 if (!Globals.empty())
105 CUNode->replaceGlobalVariables(MDTuple::get(VMContext, Globals));
106
107 if (!ImportedModules.empty())
108 CUNode->replaceImportedEntities(MDTuple::get(
109 VMContext, SmallVector<Metadata *, 16>(ImportedModules.begin(),
110 ImportedModules.end())));
111
112 for (const auto &I : AllMacrosPerParent) {
113 // DIMacroNode's with nullptr parent are DICompileUnit direct children.
114 if (!I.first) {
115 CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
116 continue;
117 }
118 // Otherwise, it must be a temporary DIMacroFile that need to be resolved.
119 auto *TMF = cast<DIMacroFile>(I.first);
121 TMF->getLine(), TMF->getFile(),
122 getOrCreateMacroArray(I.second.getArrayRef()));
123 replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
124 }
125
126 // Now that all temp nodes have been replaced or deleted, resolve remaining
127 // cycles.
128 for (const auto &N : UnresolvedNodes)
129 if (N && !N->isResolved())
130 N->resolveCycles();
131 UnresolvedNodes.clear();
132
133 // Can't handle unresolved nodes anymore.
134 AllowUnresolvedNodes = false;
135}
136
137/// If N is compile unit return NULL otherwise return N.
139 if (!N || isa<DICompileUnit>(N))
140 return nullptr;
141 return cast<DIScope>(N);
142}
143
145 DISourceLanguageName Lang, DIFile *File, StringRef Producer,
146 bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
148 bool SplitDebugInlining, bool DebugInfoForProfiling,
149 DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress,
150 StringRef SysRoot, StringRef SDK) {
151
152 assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
154 VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
155 SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
156 SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
157 RangesBaseAddress, SysRoot, SDK);
158
159 // Create a named metadata so that it is easier to find cu in a module.
160 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
161 NMD->addOperand(CUNode);
162 trackIfUnresolved(CUNode);
163 return CUNode;
164}
165
166static DIImportedEntity *
168 Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
169 DINodeArray Elements,
170 SmallVectorImpl<TrackingMDNodeRef> &ImportedModules) {
171 if (Line)
172 assert(File && "Source location has line number but no file");
173 unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
174 auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null<DINode>(NS),
175 File, Line, Name, Elements);
176 if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
177 // A new Imported Entity was just added to the context.
178 // Add it to the Imported Modules list.
179 ImportedModules.emplace_back(M);
180 return M;
181}
182
184 DINamespace *NS, DIFile *File,
185 unsigned Line,
186 DINodeArray Elements) {
187 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
188 Context, NS, File, Line, StringRef(), Elements,
189 getImportTrackingVector(Context));
190}
191
194 DIFile *File, unsigned Line,
195 DINodeArray Elements) {
196 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
197 Context, NS, File, Line, StringRef(), Elements,
198 getImportTrackingVector(Context));
199}
200
202 DIFile *File, unsigned Line,
203 DINodeArray Elements) {
204 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
205 Context, M, File, Line, StringRef(), Elements,
206 getImportTrackingVector(Context));
207}
208
211 DIFile *File, unsigned Line,
212 StringRef Name, DINodeArray Elements) {
213 // Make sure to use the unique identifier based metadata reference for
214 // types that have one.
215 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
216 Context, Decl, File, Line, Name, Elements,
217 getImportTrackingVector(Context));
218}
219
221 std::optional<DIFile::ChecksumInfo<StringRef>> CS,
222 std::optional<StringRef> Source) {
223 return DIFile::get(VMContext, Filename, Directory, CS, Source);
224}
225
226DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
227 unsigned MacroType, StringRef Name,
229 assert(!Name.empty() && "Unable to create macro without name");
230 assert((MacroType == dwarf::DW_MACINFO_undef ||
231 MacroType == dwarf::DW_MACINFO_define) &&
232 "Unexpected macro type");
233 auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
234 AllMacrosPerParent[Parent].insert(M);
235 return M;
236}
237
239 unsigned LineNumber, DIFile *File) {
241 LineNumber, File, DIMacroNodeArray())
242 .release();
243 AllMacrosPerParent[Parent].insert(MF);
244 // Add the new temporary DIMacroFile to the macro per parent map as a parent.
245 // This is needed to assure DIMacroFile with no children to have an entry in
246 // the map. Otherwise, it will not be resolved in DIBuilder::finalize().
247 AllMacrosPerParent.insert({MF, {}});
248 return MF;
249}
250
252 bool IsUnsigned) {
253 assert(!Name.empty() && "Unable to create enumerator without name");
254 return DIEnumerator::get(VMContext, APInt(64, Val, !IsUnsigned), IsUnsigned,
255 Name);
256}
257
259 assert(!Name.empty() && "Unable to create enumerator without name");
260 return DIEnumerator::get(VMContext, APInt(Value), Value.isUnsigned(), Name);
261}
262
264 assert(!Name.empty() && "Unable to create type without name");
265 return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
266}
267
269 return createUnspecifiedType("decltype(nullptr)");
270}
271
273 unsigned Encoding,
274 DINode::DIFlags Flags,
275 uint32_t NumExtraInhabitants,
276 uint32_t DataSizeInBits) {
277 return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, nullptr, 0,
278 nullptr, SizeInBits, 0, Encoding, NumExtraInhabitants,
279 DataSizeInBits, Flags);
280}
281
283 unsigned LineNo, DIScope *Context,
284 uint64_t SizeInBits, unsigned Encoding,
285 DINode::DIFlags Flags,
286 uint32_t NumExtraInhabitants,
287 uint32_t DataSizeInBits) {
288 auto *R = DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, File,
289 LineNo, Context, SizeInBits, 0, Encoding,
290 NumExtraInhabitants, DataSizeInBits, Flags);
292 getSubprogramNodesTrackingVector(Context).emplace_back(R);
293 trackIfUnresolved(R);
294 return R;
295}
296
298 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context,
299 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
300 DINode::DIFlags Flags, int Factor) {
301 auto *R = DIFixedPointType::get(
302 VMContext, dwarf::DW_TAG_base_type, Name, File, LineNo, Context,
303 SizeInBits, AlignInBits, Encoding, Flags,
306 getSubprogramNodesTrackingVector(Context).emplace_back(R);
307 trackIfUnresolved(R);
308 return R;
309}
310
312 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context,
313 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
314 DINode::DIFlags Flags, int Factor) {
315 auto *R = DIFixedPointType::get(
316 VMContext, dwarf::DW_TAG_base_type, Name, File, LineNo, Context,
317 SizeInBits, AlignInBits, Encoding, Flags,
320 getSubprogramNodesTrackingVector(Context).emplace_back(R);
321 trackIfUnresolved(R);
322 return R;
323}
324
326 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context,
327 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
328 DINode::DIFlags Flags, APInt Numerator, APInt Denominator) {
329 auto *R = DIFixedPointType::get(
330 VMContext, dwarf::DW_TAG_base_type, Name, File, LineNo, Context,
331 SizeInBits, AlignInBits, Encoding, Flags,
332 DIFixedPointType::FixedPointRational, 0, Numerator, Denominator);
334 getSubprogramNodesTrackingVector(Context).emplace_back(R);
335 trackIfUnresolved(R);
336 return R;
337}
338
340 assert(!Name.empty() && "Unable to create type without name");
341 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
342 SizeInBits, 0);
343}
344
346 DIVariable *StringLength,
347 DIExpression *StrLocationExp) {
348 assert(!Name.empty() && "Unable to create type without name");
349 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
350 StringLength, nullptr, StrLocationExp, 0, 0, 0);
351}
352
354 DIExpression *StringLengthExp,
355 DIExpression *StrLocationExp) {
356 assert(!Name.empty() && "Unable to create type without name");
357 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name, nullptr,
358 StringLengthExp, StrLocationExp, 0, 0, 0);
359}
360
362 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy,
363 (uint64_t)0, 0, (uint64_t)0, std::nullopt,
364 std::nullopt, DINode::FlagZero);
365}
366
368 DIType *FromTy, unsigned Key, bool IsAddressDiscriminated,
369 unsigned ExtraDiscriminator, bool IsaPointer,
370 bool AuthenticatesNullValues) {
371 return DIDerivedType::get(
372 VMContext, dwarf::DW_TAG_LLVM_ptrauth_type, "", nullptr, 0, nullptr,
373 FromTy, (uint64_t)0, 0, (uint64_t)0, std::nullopt,
374 std::optional<DIDerivedType::PtrAuthData>(
375 std::in_place, Key, IsAddressDiscriminated, ExtraDiscriminator,
376 IsaPointer, AuthenticatesNullValues),
377 DINode::FlagZero);
378}
379
382 uint32_t AlignInBits,
383 std::optional<unsigned> DWARFAddressSpace,
384 StringRef Name, DINodeArray Annotations) {
385 // FIXME: Why is there a name here?
386 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
387 nullptr, 0, nullptr, PointeeTy, SizeInBits,
388 AlignInBits, 0, DWARFAddressSpace, std::nullopt,
389 DINode::FlagZero, nullptr, Annotations);
390}
391
393 DIType *Base,
394 uint64_t SizeInBits,
395 uint32_t AlignInBits,
396 DINode::DIFlags Flags) {
397 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
398 nullptr, 0, nullptr, PointeeTy, SizeInBits,
399 AlignInBits, 0, std::nullopt, std::nullopt, Flags,
400 Base);
401}
402
405 uint32_t AlignInBits,
406 std::optional<unsigned> DWARFAddressSpace) {
407 assert(RTy && "Unable to create reference type");
408 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
409 SizeInBits, AlignInBits, 0, DWARFAddressSpace, {},
410 DINode::FlagZero);
411}
412
414 DIFile *File, unsigned LineNo,
415 DIScope *Context, uint32_t AlignInBits,
416 DINode::DIFlags Flags,
417 DINodeArray Annotations) {
418 auto *T = DIDerivedType::get(
419 VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo,
420 getNonCompileUnitScope(Context), Ty, (uint64_t)0, AlignInBits,
421 (uint64_t)0, std::nullopt, std::nullopt, Flags, nullptr, Annotations);
423 getSubprogramNodesTrackingVector(Context).emplace_back(T);
424 return T;
425}
426
429 unsigned LineNo, DIScope *Context,
430 DINodeArray TParams, uint32_t AlignInBits,
431 DINode::DIFlags Flags, DINodeArray Annotations) {
432 auto *T =
433 DIDerivedType::get(VMContext, dwarf::DW_TAG_template_alias, Name, File,
434 LineNo, getNonCompileUnitScope(Context), Ty,
435 (uint64_t)0, AlignInBits, (uint64_t)0, std::nullopt,
436 std::nullopt, Flags, TParams.get(), Annotations);
438 getSubprogramNodesTrackingVector(Context).emplace_back(T);
439 return T;
440}
441
443 assert(Ty && "Invalid type!");
444 assert(FriendTy && "Invalid friend type!");
445 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
446 FriendTy, (uint64_t)0, 0, (uint64_t)0, std::nullopt,
447 std::nullopt, DINode::FlagZero);
448}
449
451 uint64_t BaseOffset,
452 uint32_t VBPtrOffset,
453 DINode::DIFlags Flags) {
454 assert(Ty && "Unable to create inheritance");
456 ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
457 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
458 0, Ty, BaseTy, 0, 0, BaseOffset, std::nullopt,
459 std::nullopt, Flags, ExtraData);
460}
461
463 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
464 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
465 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
466 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
467 LineNumber, getNonCompileUnitScope(Scope), Ty,
468 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
469 std::nullopt, Flags, nullptr, Annotations);
470}
471
473 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
474 Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits,
475 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
476 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
477 LineNumber, getNonCompileUnitScope(Scope), Ty,
478 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
479 std::nullopt, Flags, nullptr, Annotations);
480}
481
483 if (C)
485 return nullptr;
486}
487
489 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
490 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
491 Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
492 // "ExtraData" is overloaded for bit fields and for variants, so
493 // make sure to disallow this.
494 assert((Flags & DINode::FlagBitField) == 0);
495 return DIDerivedType::get(
496 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
497 getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits,
498 std::nullopt, std::nullopt, Flags, getConstantOrNull(Discriminant));
499}
500
502 DINodeArray Elements,
503 Constant *Discriminant,
504 DIType *Ty) {
505 auto *V = DICompositeType::get(VMContext, dwarf::DW_TAG_variant, {}, nullptr,
506 0, getNonCompileUnitScope(Scope), {},
507 (uint64_t)0, 0, (uint64_t)0, DINode::FlagZero,
508 Elements, 0, {}, nullptr);
509
510 trackIfUnresolved(V);
511 return createVariantMemberType(Scope, {}, nullptr, 0, 0, 0, 0, Discriminant,
512 DINode::FlagZero, V);
513}
514
516 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
517 Metadata *SizeInBits, Metadata *OffsetInBits, uint64_t StorageOffsetInBits,
518 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
519 Flags |= DINode::FlagBitField;
520 return DIDerivedType::get(
521 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
522 getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
523 OffsetInBits, std::nullopt, std::nullopt, Flags,
524 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
525 StorageOffsetInBits)),
527}
528
530 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
531 uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
532 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
533 Flags |= DINode::FlagBitField;
534 return DIDerivedType::get(
535 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
536 getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
537 OffsetInBits, std::nullopt, std::nullopt, Flags,
538 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
539 StorageOffsetInBits)),
541}
542
545 unsigned LineNumber, DIType *Ty,
547 unsigned Tag, uint32_t AlignInBits) {
548 Flags |= DINode::FlagStaticMember;
549 return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
550 getNonCompileUnitScope(Scope), Ty, (uint64_t)0,
551 AlignInBits, (uint64_t)0, std::nullopt,
552 std::nullopt, Flags, getConstantOrNull(Val));
553}
554
556DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber,
557 uint64_t SizeInBits, uint32_t AlignInBits,
558 uint64_t OffsetInBits, DINode::DIFlags Flags,
559 DIType *Ty, MDNode *PropertyNode) {
560 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
561 LineNumber, getNonCompileUnitScope(File), Ty,
562 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
563 std::nullopt, Flags, PropertyNode);
564}
565
567DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
568 StringRef GetterName, StringRef SetterName,
569 unsigned PropertyAttributes, DIType *Ty) {
570 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
571 SetterName, PropertyAttributes, Ty);
572}
573
576 DIType *Ty, bool isDefault) {
577 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
578 return DITemplateTypeParameter::get(VMContext, Name, Ty, isDefault);
579}
580
583 DIScope *Context, StringRef Name, DIType *Ty,
584 bool IsDefault, Metadata *MD) {
585 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
586 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, IsDefault, MD);
587}
588
591 DIType *Ty, bool isDefault,
592 Constant *Val) {
594 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
595 isDefault, getConstantOrNull(Val));
596}
597
600 DIType *Ty, StringRef Val,
601 bool IsDefault) {
603 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
604 IsDefault, MDString::get(VMContext, Val));
605}
606
609 DIType *Ty, DINodeArray Val) {
611 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
612 false, Val.get());
613}
614
616 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
617 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
618 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
619 unsigned RunTimeLang, DIType *VTableHolder, MDNode *TemplateParams,
620 StringRef UniqueIdentifier, DINodeArray Annotations) {
621 assert((!Context || isa<DIScope>(Context)) &&
622 "createClassType should be called with a valid Context");
623
624 auto *R = DICompositeType::get(
625 VMContext, dwarf::DW_TAG_class_type, Name, File, LineNumber,
626 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
627 OffsetInBits, Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt,
628 VTableHolder, cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier,
629 nullptr, nullptr, nullptr, nullptr, nullptr, Annotations);
630 trackIfUnresolved(R);
632 getSubprogramNodesTrackingVector(Context).emplace_back(R);
633 return R;
634}
635
637 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
638 Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
639 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
640 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
641 uint32_t NumExtraInhabitants, DINodeArray Annotations) {
642 auto *R = DICompositeType::get(
643 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
644 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
645 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
646 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
647 Annotations, Specification, NumExtraInhabitants);
648 trackIfUnresolved(R);
650 getSubprogramNodesTrackingVector(Context).emplace_back(R);
651 return R;
652}
653
655 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
656 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
657 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
658 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
659 uint32_t NumExtraInhabitants, DINodeArray Annotations) {
660 auto *R = DICompositeType::get(
661 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
662 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
663 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
664 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
665 Annotations, Specification, NumExtraInhabitants);
666 trackIfUnresolved(R);
668 getSubprogramNodesTrackingVector(Context).emplace_back(R);
669 return R;
670}
671
673 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
674 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
675 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier,
676 DINodeArray Annotations) {
677 auto *R = DICompositeType::get(
678 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
679 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
680 Elements, RunTimeLang, /*EnumKind=*/std::nullopt, nullptr, nullptr,
681 UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
683 trackIfUnresolved(R);
685 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
686 return R;
687}
688
691 unsigned LineNumber, uint64_t SizeInBits,
692 uint32_t AlignInBits, DINode::DIFlags Flags,
693 DIDerivedType *Discriminator, DINodeArray Elements,
694 StringRef UniqueIdentifier) {
695 auto *R = DICompositeType::get(
696 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
697 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
698 Elements, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr,
699 UniqueIdentifier, Discriminator);
700 trackIfUnresolved(R);
701 return R;
702}
703
705 DINode::DIFlags Flags,
706 unsigned CC) {
707 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
708}
709
711 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
712 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
713 DIType *UnderlyingType, unsigned RunTimeLang, StringRef UniqueIdentifier,
714 bool IsScoped, std::optional<uint32_t> EnumKind) {
715 auto *CTy = DICompositeType::get(
716 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
717 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
718 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
719 RunTimeLang, EnumKind, nullptr, nullptr, UniqueIdentifier);
721 getSubprogramNodesTrackingVector(Scope).emplace_back(CTy);
722 else
723 EnumTypes.emplace_back(CTy);
724 trackIfUnresolved(CTy);
725 return CTy;
726}
727
729 DIFile *File, unsigned LineNo,
730 uint64_t SizeInBits,
731 uint32_t AlignInBits, DIType *Ty) {
732 auto *R = DIDerivedType::get(VMContext, dwarf::DW_TAG_set_type, Name, File,
733 LineNo, getNonCompileUnitScope(Scope), Ty,
734 SizeInBits, AlignInBits, 0, std::nullopt,
735 std::nullopt, DINode::FlagZero);
736 trackIfUnresolved(R);
738 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
739 return R;
740}
741
744 DINodeArray Subscripts,
749 return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits,
750 Ty, Subscripts, DL, AS, AL, RK);
751}
752
754 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
755 uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
760 auto *R = DICompositeType::get(
761 VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
762 getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
763 Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
772 nullptr, nullptr, 0, BitStride);
773 trackIfUnresolved(R);
775 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
776 return R;
777}
778
780 uint32_t AlignInBits, DIType *Ty,
781 DINodeArray Subscripts,
782 Metadata *BitStride) {
783 auto *R = DICompositeType::get(
784 VMContext, dwarf::DW_TAG_array_type, /*Name=*/"",
785 /*File=*/nullptr, /*Line=*/0, /*Scope=*/nullptr, /*BaseType=*/Ty,
786 /*SizeInBits=*/Size, /*AlignInBits=*/AlignInBits, /*OffsetInBits=*/0,
787 /*Flags=*/DINode::FlagVector, /*Elements=*/Subscripts,
788 /*RuntimeLang=*/0, /*EnumKind=*/std::nullopt, /*VTableHolder=*/nullptr,
789 /*TemplateParams=*/nullptr, /*Identifier=*/"",
790 /*Discriminator=*/nullptr, /*DataLocation=*/nullptr,
791 /*Associated=*/nullptr, /*Allocated=*/nullptr, /*Rank=*/nullptr,
792 /*Annotations=*/nullptr, /*Specification=*/nullptr,
793 /*NumExtraInhabitants=*/0,
794 /*BitStride=*/BitStride);
795 trackIfUnresolved(R);
796 return R;
797}
798
800 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
801 return MDNode::replaceWithDistinct(std::move(NewSP));
802}
803
805 DINode::DIFlags FlagsToSet) {
806 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
807 return MDNode::replaceWithUniqued(std::move(NewTy));
808}
809
811 // FIXME: Restrict this to the nodes where it's valid.
812 if (Ty->isArtificial())
813 return Ty;
814 return createTypeWithFlags(Ty, DINode::FlagArtificial);
815}
816
818 // FIXME: Restrict this to the nodes where it's valid.
819 if (Ty->isObjectPointer())
820 return Ty;
821 DINode::DIFlags Flags = DINode::FlagObjectPointer;
822
823 if (Implicit)
824 Flags |= DINode::FlagArtificial;
825
826 return createTypeWithFlags(Ty, Flags);
827}
828
830 assert(T && "Expected non-null type");
832 cast<DISubprogram>(T)->isDefinition() == false)) &&
833 "Expected type or subprogram declaration");
834 if (!isa_and_nonnull<DILocalScope>(T->getScope()))
835 AllRetainTypes.emplace_back(T);
836}
837
839
841 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
842 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
843 StringRef UniqueIdentifier, std::optional<uint32_t> EnumKind) {
844 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
845 // replaceWithUniqued().
846 auto *RetTy = DICompositeType::get(
847 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
848 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
849 /*EnumKind=*/EnumKind, nullptr, nullptr, UniqueIdentifier);
850 trackIfUnresolved(RetTy);
852 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
853 return RetTy;
854}
855
857 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
858 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
859 DINode::DIFlags Flags, StringRef UniqueIdentifier, DINodeArray Annotations,
860 std::optional<uint32_t> EnumKind) {
861 auto *RetTy =
863 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
864 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, EnumKind,
865 nullptr, nullptr, UniqueIdentifier, nullptr, nullptr, nullptr,
866 nullptr, nullptr, Annotations)
867 .release();
868 trackIfUnresolved(RetTy);
870 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
871 return RetTy;
872}
873
875 return MDTuple::get(VMContext, Elements);
876}
877
878DIMacroNodeArray
880 return MDTuple::get(VMContext, Elements);
881}
882
885 for (Metadata *E : Elements) {
887 Elts.push_back(cast<DIType>(E));
888 else
889 Elts.push_back(E);
890 }
891 return DITypeArray(MDNode::get(VMContext, Elts));
892}
893
895 auto *LB = ConstantAsMetadata::get(
897 auto *CountNode = ConstantAsMetadata::get(
899 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
900}
901
903 auto *LB = ConstantAsMetadata::get(
905 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
906}
907
909 Metadata *UB, Metadata *Stride) {
910 return DISubrange::get(VMContext, CountNode, LB, UB, Stride);
911}
912
916 auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * {
917 return isa<DIExpression *>(Bound) ? (Metadata *)cast<DIExpression *>(Bound)
918 : (Metadata *)cast<DIVariable *>(Bound);
919 };
920 return DIGenericSubrange::get(VMContext, ConvToMetadata(CountNode),
921 ConvToMetadata(LB), ConvToMetadata(UB),
922 ConvToMetadata(Stride));
923}
924
926 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope,
927 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
928 DIType *Ty, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride,
929 Metadata *Bias) {
930 auto *T = DISubrangeType::get(VMContext, Name, File, LineNo, Scope,
931 SizeInBits, AlignInBits, Flags, Ty, LowerBound,
932 UpperBound, Stride, Bias);
934 getSubprogramNodesTrackingVector(Scope).emplace_back(T);
935 return T;
936}
937
938static void checkGlobalVariableScope(DIScope *Context) {
939#ifndef NDEBUG
940 if (auto *CT =
942 assert(CT->getIdentifier().empty() &&
943 "Context of a global variable should not be a type with identifier");
944#endif
945}
946
948 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
949 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined,
950 DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams,
951 uint32_t AlignInBits, DINodeArray Annotations) {
953
955 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
956 LineNumber, Ty, IsLocalToUnit, isDefined,
957 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
959 if (!Expr)
960 Expr = createExpression();
961 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
963 getSubprogramNodesTrackingVector(Context).emplace_back(N);
964 else
965 Globals.push_back(N);
966 return N;
967}
968
970 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
971 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, MDNode *Decl,
972 MDTuple *TemplateParams, uint32_t AlignInBits) {
974
976 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
977 LineNumber, Ty, IsLocalToUnit, false,
978 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
979 nullptr)
980 .release();
981}
982
984 LLVMContext &VMContext,
986 DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
987 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
988 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
989 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
990 // the only valid scopes)?
991 auto *Scope = cast<DILocalScope>(Context);
992 auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
993 ArgNo, Flags, AlignInBits, Annotations);
994 if (AlwaysPreserve) {
995 // The optimizer may remove local variables. If there is an interest
996 // to preserve variable info in such situation then stash it in a
997 // named mdnode.
998 PreservedNodes.emplace_back(Node);
999 }
1000 return Node;
1001}
1002
1004 DIFile *File, unsigned LineNo,
1005 DIType *Ty, bool AlwaysPreserve,
1006 DINode::DIFlags Flags,
1007 uint32_t AlignInBits) {
1008 assert(Scope && isa<DILocalScope>(Scope) &&
1009 "Unexpected scope for a local variable.");
1010 return createLocalVariable(
1011 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
1012 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
1013}
1014
1016 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
1017 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
1018 DINodeArray Annotations) {
1019 assert(ArgNo && "Expected non-zero argument number for parameter");
1020 assert(Scope && isa<DILocalScope>(Scope) &&
1021 "Unexpected scope for a local variable.");
1022 return createLocalVariable(
1023 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
1024 File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
1025}
1026
1028 unsigned LineNo, unsigned Column,
1029 bool IsArtificial,
1030 std::optional<unsigned> CoroSuspendIdx,
1031 bool AlwaysPreserve) {
1032 auto *Scope = cast<DILocalScope>(Context);
1033 auto *Node = DILabel::get(VMContext, Scope, Name, File, LineNo, Column,
1034 IsArtificial, CoroSuspendIdx);
1035
1036 if (AlwaysPreserve) {
1037 /// The optimizer may remove labels. If there is an interest
1038 /// to preserve label info in such situation then append it to
1039 /// the list of retained nodes of the DISubprogram.
1040 getSubprogramNodesTrackingVector(Scope).emplace_back(Node);
1041 }
1042 return Node;
1043}
1044
1048
1049template <class... Ts>
1050static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) {
1051 if (IsDistinct)
1052 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
1053 return DISubprogram::get(std::forward<Ts>(Args)...);
1054}
1055
1057 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1058 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1060 DITemplateParameterArray TParams, DISubprogram *Decl,
1061 DITypeArray ThrownTypes, DINodeArray Annotations, StringRef TargetFuncName,
1062 bool UseKeyInstructions) {
1063 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1064 auto *Node = getSubprogram(
1065 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
1066 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
1067 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr,
1068 ThrownTypes, Annotations, TargetFuncName, UseKeyInstructions);
1069
1070 AllSubprograms.push_back(Node);
1071 trackIfUnresolved(Node);
1072 return Node;
1073}
1074
1076 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1077 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1079 DITemplateParameterArray TParams, DISubprogram *Decl,
1080 DITypeArray ThrownTypes) {
1081 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1082 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
1083 Name, LinkageName, File, LineNo, Ty,
1084 ScopeLine, nullptr, 0, 0, Flags, SPFlags,
1085 IsDefinition ? CUNode : nullptr, TParams,
1086 Decl, nullptr, ThrownTypes)
1087 .release();
1088}
1089
1091 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
1092 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
1093 DIType *VTableHolder, DINode::DIFlags Flags,
1094 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
1095 DITypeArray ThrownTypes, bool UseKeyInstructions) {
1096 assert(getNonCompileUnitScope(Context) &&
1097 "Methods should have both a Context and a context that isn't "
1098 "the compile unit.");
1099 // FIXME: Do we want to use different scope/lines?
1100 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1101 auto *SP = getSubprogram(
1102 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
1103 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
1104 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
1105 nullptr, ThrownTypes, nullptr, "", IsDefinition && UseKeyInstructions);
1106
1107 AllSubprograms.push_back(SP);
1108 trackIfUnresolved(SP);
1109 return SP;
1110}
1111
1113 DIGlobalVariable *Decl,
1114 StringRef Name, DIFile *File,
1115 unsigned LineNo) {
1116 return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo);
1117}
1118
1120 bool ExportSymbols) {
1121
1122 // It is okay to *not* make anonymous top-level namespaces distinct, because
1123 // all nodes that have an anonymous namespace as their parent scope are
1124 // guaranteed to be unique and/or are linked to their containing
1125 // DICompileUnit. This decision is an explicit tradeoff of link time versus
1126 // memory usage versus code simplicity and may get revisited in the future.
1127 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
1128 ExportSymbols);
1129}
1130
1132 StringRef ConfigurationMacros,
1133 StringRef IncludePath, StringRef APINotesFile,
1134 DIFile *File, unsigned LineNo, bool IsDecl) {
1135 return DIModule::get(VMContext, File, getNonCompileUnitScope(Scope), Name,
1136 ConfigurationMacros, IncludePath, APINotesFile, LineNo,
1137 IsDecl);
1138}
1139
1141 DIFile *File,
1142 unsigned Discriminator) {
1143 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
1144}
1145
1147 unsigned Line, unsigned Col) {
1148 // Make these distinct, to avoid merging two lexical blocks on the same
1149 // file/line/column.
1150 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
1151 File, Line, Col);
1152}
1153
1155 DIExpression *Expr, const DILocation *DL,
1156 BasicBlock *InsertAtEnd) {
1157 // If this block already has a terminator then insert this record before
1158 // the terminator. Otherwise, put it at the end of the block.
1159 Instruction *InsertBefore = InsertAtEnd->getTerminatorOrNull();
1160 return insertDeclare(Storage, VarInfo, Expr, DL,
1161 InsertBefore ? InsertBefore->getIterator()
1162 : InsertAtEnd->end());
1163}
1164
1166 DILocalVariable *SrcVar,
1167 DIExpression *ValExpr, Value *Addr,
1168 DIExpression *AddrExpr,
1169 const DILocation *DL) {
1170 auto *Link = cast_or_null<DIAssignID>(
1171 LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
1172 assert(Link && "Linked instruction must have DIAssign metadata attached");
1173
1175 Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1176 // Insert after LinkedInstr.
1177 BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1178 NextIt.setHeadBit(true);
1179 insertDbgVariableRecord(DVR, NextIt);
1180 return DVR;
1181}
1182
1184 DIExpression *Expr, const DILocation *DL,
1185 InsertPosition InsertPt) {
1186 DbgVariableRecord *DVR =
1188 insertDbgVariableRecord(DVR, InsertPt);
1189 return DVR;
1190}
1191
1193 DIExpression *Expr, const DILocation *DL,
1194 InsertPosition InsertPt) {
1195 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
1196 assert(DL && "Expected debug loc");
1197 assert(DL->getScope()->getSubprogram() ==
1198 VarInfo->getScope()->getSubprogram() &&
1199 "Expected matching subprograms");
1200
1201 DbgVariableRecord *DVR =
1202 DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1203 insertDbgVariableRecord(DVR, InsertPt);
1204 return DVR;
1205}
1206
1208 DILocalVariable *VarInfo,
1209 DIExpression *Expr,
1210 const DILocation *DL,
1211 InsertPosition InsertPt) {
1212 assert(VarInfo &&
1213 "empty or invalid DILocalVariable* passed to dbg.declare_value");
1214 assert(DL && "Expected debug loc");
1215 assert(DL->getScope()->getSubprogram() ==
1216 VarInfo->getScope()->getSubprogram() &&
1217 "Expected matching subprograms");
1218
1219 DbgVariableRecord *DVR =
1220 DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
1221 insertDbgVariableRecord(DVR, InsertPt);
1222 return DVR;
1223}
1224
1225void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
1226 InsertPosition InsertPt) {
1227 assert(InsertPt.isValid());
1228 trackIfUnresolved(DVR->getVariable());
1229 trackIfUnresolved(DVR->getExpression());
1230 if (DVR->isDbgAssign())
1231 trackIfUnresolved(DVR->getAddressExpression());
1232
1233 auto *BB = InsertPt.getBasicBlock();
1234 BB->insertDbgRecordBefore(DVR, InsertPt);
1235}
1236
1238 InsertPosition InsertPt) {
1239 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
1240 assert(DL && "Expected debug loc");
1241 assert(DL->getScope()->getSubprogram() ==
1242 LabelInfo->getScope()->getSubprogram() &&
1243 "Expected matching subprograms");
1244
1245 trackIfUnresolved(LabelInfo);
1246 DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1247 if (InsertPt.isValid()) {
1248 auto *BB = InsertPt.getBasicBlock();
1249 BB->insertDbgRecordBefore(DLR, InsertPt);
1250 }
1251 return DLR;
1252}
1253
1255 {
1257 N->replaceVTableHolder(VTableHolder);
1258 T = N.get();
1259 }
1260
1261 // If this didn't create a self-reference, just return.
1262 if (T != VTableHolder)
1263 return;
1264
1265 // Look for unresolved operands. T will drop RAUW support, orphaning any
1266 // cycles underneath it.
1267 if (T->isResolved())
1268 for (const MDOperand &O : T->operands())
1269 if (auto *N = dyn_cast_or_null<MDNode>(O))
1270 trackIfUnresolved(N);
1271}
1272
1273void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
1274 DINodeArray TParams) {
1275 {
1277 if (Elements)
1278 N->replaceElements(Elements);
1279 if (TParams)
1280 N->replaceTemplateParams(DITemplateParameterArray(TParams));
1281 T = N.get();
1282 }
1283
1284 // If T isn't resolved, there's no problem.
1285 if (!T->isResolved())
1286 return;
1287
1288 // If T is resolved, it may be due to a self-reference cycle. Track the
1289 // arrays explicitly if they're unresolved, or else the cycles will be
1290 // orphaned.
1291 if (Elements)
1292 trackIfUnresolved(Elements.get());
1293 if (TParams)
1294 trackIfUnresolved(TParams.get());
1295}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DILocalVariable * createLocalVariable(LLVMContext &VMContext, SmallVectorImpl< TrackingMDNodeRef > &PreservedNodes, DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, uint32_t AlignInBits, DINodeArray Annotations=nullptr)
static DIType * createTypeWithFlags(const DIType *Ty, DINode::DIFlags FlagsToSet)
static DIScope * getNonCompileUnitScope(DIScope *N)
If N is compile unit return NULL otherwise return N.
static void checkGlobalVariableScope(DIScope *Context)
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
static ConstantAsMetadata * getConstantOrNull(Constant *C)
static DITemplateValueParameter * createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, DIScope *Context, StringRef Name, DIType *Ty, bool IsDefault, Metadata *MD)
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, DINodeArray Elements, SmallVectorImpl< TrackingMDNodeRef > &ImportedModules)
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
static constexpr StringLiteral Filename
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
Class for arbitrary precision integers.
Definition APInt.h:78
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
Annotations lets you mark points and ranges inside source code, for tests:
Definition Annotations.h:67
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:459
LLVM_ABI void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
const Instruction * getTerminatorOrNull() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition BasicBlock.h:248
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:537
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
Definition Constants.h:135
This is an important base class in LLVM.
Definition Constant.h:43
Basic type, like 'int' or 'float'.
static LLVM_ABI DIType * createObjectPointerType(DIType *Ty, bool Implicit)
Create a uniqued clone of Ty with FlagObjectPointer set.
LLVM_ABI DIBasicType * createUnspecifiedParameter()
Create unspecified parameter type for a subroutine type.
LLVM_ABI DIGlobalVariable * createTempGlobalVariableFwdDecl(DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DIType *Ty, bool IsLocalToUnit, MDNode *Decl=nullptr, MDTuple *TemplateParams=nullptr, uint32_t AlignInBits=0)
Identical to createGlobalVariable except that the resulting DbgNode is temporary and meant to be RAUW...
LLVM_ABI DITemplateValueParameter * createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty, StringRef Val, bool IsDefault=false)
Create debugging information for a template template parameter.
NodeTy * replaceTemporary(TempMDNode &&N, NodeTy *Replacement)
Replace a temporary node.
Definition DIBuilder.h:1246
LLVM_ABI DIDerivedType * createTypedef(DIType *Ty, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint32_t AlignInBits=0, DINode::DIFlags Flags=DINode::FlagZero, DINodeArray Annotations=nullptr)
Create debugging information entry for a typedef.
LLVM_ABI DbgRecord * insertDbgAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *SrcVar, DIExpression *ValExpr, Value *Addr, DIExpression *AddrExpr, const DILocation *DL)
Insert a new dbg_assign record.
LLVM_ABI void finalize()
Construct any deferred debug info descriptors.
Definition DIBuilder.cpp:73
LLVM_ABI DIMacro * createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType, StringRef Name, StringRef Value=StringRef())
Create debugging information entry for a macro.
LLVM_ABI DIDerivedType * createInheritance(DIType *Ty, DIType *BaseTy, uint64_t BaseOffset, uint32_t VBPtrOffset, DINode::DIFlags Flags)
Create debugging information entry to establish inheritance relationship between two types.
LLVM_ABI DICompositeType * createVectorType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts, Metadata *BitStride=nullptr)
Create debugging information entry for a vector type.
LLVM_ABI DIDerivedType * createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, DIType *Ty, DINode::DIFlags Flags, Constant *Val, unsigned Tag, uint32_t AlignInBits=0)
Create debugging information entry for a C++ static data member.
LLVM_ABI DIDerivedType * createVariantMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty)
Create debugging information entry for a variant.
LLVM_ABI DILexicalBlockFile * createLexicalBlockFile(DIScope *Scope, DIFile *File, unsigned Discriminator=0)
This creates a descriptor for a lexical block with a new file attached.
LLVM_ABI void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards.
Definition DIBuilder.cpp:53
LLVM_ABI DIDerivedType * createQualifiedType(unsigned Tag, DIType *FromTy)
Create debugging information entry for a qualified type, e.g.
LLVM_ABI DISubprogram * createTempFunctionFwdDecl(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, DINode::DIFlags Flags=DINode::FlagZero, DISubprogram::DISPFlags SPFlags=DISubprogram::SPFlagZero, DITemplateParameterArray TParams=nullptr, DISubprogram *Decl=nullptr, DITypeArray ThrownTypes=nullptr)
Identical to createFunction, except that the resulting DbgNode is meant to be RAUWed.
LLVM_ABI DIDerivedType * createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DINode::DIFlags Flags, DIType *Ty, MDNode *PropertyNode)
Create debugging information entry for Objective-C instance variable.
static LLVM_ABI DIType * createArtificialType(DIType *Ty)
Create a uniqued clone of Ty with FlagArtificial set.
LLVM_ABI DIDerivedType * createBitFieldMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, Metadata *SizeInBits, Metadata *OffsetInBits, uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations=nullptr)
Create debugging information entry for a bit field member.
LLVM_ABI DISubroutineType * createSubroutineType(DITypeArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
LLVM_ABI DICompositeType * createUnionType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DINodeArray Elements, unsigned RunTimeLang=0, StringRef UniqueIdentifier="", DINodeArray Annotations=nullptr)
Create debugging information entry for an union.
LLVM_ABI DISubprogram * createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, unsigned VTableIndex=0, int ThisAdjustment=0, DIType *VTableHolder=nullptr, DINode::DIFlags Flags=DINode::FlagZero, DISubprogram::DISPFlags SPFlags=DISubprogram::SPFlagZero, DITemplateParameterArray TParams=nullptr, DITypeArray ThrownTypes=nullptr, bool UseKeyInstructions=false)
Create a new descriptor for the specified C++ method.
LLVM_ABI DINamespace * createNameSpace(DIScope *Scope, StringRef Name, bool ExportSymbols)
This creates new descriptor for a namespace with the specified parent scope.
LLVM_ABI DIStringType * createStringType(StringRef Name, uint64_t SizeInBits)
Create debugging information entry for a string type.
LLVM_ABI DILexicalBlock * createLexicalBlock(DIScope *Scope, DIFile *File, unsigned Line, unsigned Col)
This creates a descriptor for a lexical block with the specified parent context.
LLVM_ABI DICompositeType * createStructType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang=0, DIType *VTableHolder=nullptr, StringRef UniqueIdentifier="", DIType *Specification=nullptr, uint32_t NumExtraInhabitants=0, DINodeArray Annotations=nullptr)
Create debugging information entry for a struct.
LLVM_ABI DIMacroNodeArray getOrCreateMacroArray(ArrayRef< Metadata * > Elements)
Get a DIMacroNodeArray, create one if required.
LLVM_ABI DbgRecord * insertDbgValue(llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, InsertPosition InsertPt)
Insert a new dbg_value record.
LLVM_ABI DIDerivedType * createMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits, DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations=nullptr)
Create debugging information entry for a member.
LLVM_ABI DIDerivedType * createSetType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, DIType *Ty)
Create debugging information entry for a set.
LLVM_ABI void replaceVTableHolder(DICompositeType *&T, DIType *VTableHolder)
Replace the vtable holder in the given type.
LLVM_ABI DIBasicType * createNullPtrType()
Create C++11 nullptr type.
LLVM_ABI DICommonBlock * createCommonBlock(DIScope *Scope, DIGlobalVariable *decl, StringRef Name, DIFile *File, unsigned LineNo)
Create common block entry for a Fortran common block.
LLVM_ABI DIDerivedType * createFriend(DIType *Ty, DIType *FriendTy)
Create debugging information entry for a 'friend'.
LLVM_ABI DILabel * createLabel(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, unsigned Column, bool IsArtificial, std::optional< unsigned > CoroSuspendIdx, bool AlwaysPreserve=false)
Create a new descriptor for an label.
LLVM_ABI void retainType(DIScope *T)
Retain DIScope* in a module even if it is not referenced through debug info anchors.
LLVM_ABI DIDerivedType * createTemplateAlias(DIType *Ty, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, DINodeArray TParams, uint32_t AlignInBits=0, DINode::DIFlags Flags=DINode::FlagZero, DINodeArray Annotations=nullptr)
Create debugging information entry for a template alias.
LLVM_ABI DISubprogram * createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, DINode::DIFlags Flags=DINode::FlagZero, DISubprogram::DISPFlags SPFlags=DISubprogram::SPFlagZero, DITemplateParameterArray TParams=nullptr, DISubprogram *Decl=nullptr, DITypeArray ThrownTypes=nullptr, DINodeArray Annotations=nullptr, StringRef TargetFuncName="", bool UseKeyInstructions=false)
Create a new descriptor for the specified subprogram.
LLVM_ABI DIDerivedType * createPointerType(DIType *PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits=0, std::optional< unsigned > DWARFAddressSpace=std::nullopt, StringRef Name="", DINodeArray Annotations=nullptr)
Create debugging information entry for a pointer.
LLVM_ABI DITemplateValueParameter * createTemplateParameterPack(DIScope *Scope, StringRef Name, DIType *Ty, DINodeArray Val)
Create debugging information for a template parameter pack.
LLVM_ABI DIGlobalVariableExpression * createGlobalVariableExpression(DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DIType *Ty, bool IsLocalToUnit, bool isDefined=true, DIExpression *Expr=nullptr, MDNode *Decl=nullptr, MDTuple *TemplateParams=nullptr, uint32_t AlignInBits=0, DINodeArray Annotations=nullptr)
Create a new descriptor for the specified variable.
LLVM_ABI DICompositeType * createClassType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang=0, DIType *VTableHolder=nullptr, MDNode *TemplateParms=nullptr, StringRef UniqueIdentifier="", DINodeArray Annotations=nullptr)
Create debugging information entry for a class.
LLVM_ABI DIFixedPointType * createRationalFixedPointType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DINode::DIFlags Flags, APInt Numerator, APInt Denominator)
Create debugging information entry for an arbitrary rational fixed-point type.
LLVM_ABI DICompositeType * createReplaceableCompositeType(unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, unsigned RuntimeLang=0, uint64_t SizeInBits=0, uint32_t AlignInBits=0, DINode::DIFlags Flags=DINode::FlagFwdDecl, StringRef UniqueIdentifier="", DINodeArray Annotations=nullptr, std::optional< uint32_t > EnumKind=std::nullopt)
Create a temporary forward-declared type.
LLVM_ABI DIFixedPointType * createDecimalFixedPointType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DINode::DIFlags Flags, int Factor)
Create debugging information entry for a decimal fixed-point type.
LLVM_ABI DITypeArray getOrCreateTypeArray(ArrayRef< Metadata * > Elements)
Get a DITypeArray, create one if required.
LLVM_ABI DICompositeType * createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, DIType *UnderlyingType, unsigned RunTimeLang=0, StringRef UniqueIdentifier="", bool IsScoped=false, std::optional< uint32_t > EnumKind=std::nullopt)
Create debugging information entry for an enumeration.
LLVM_ABI DIFixedPointType * createBinaryFixedPointType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DINode::DIFlags Flags, int Factor)
Create debugging information entry for a binary fixed-point type.
LLVM_ABI DbgRecord * insertDeclareValue(Value *Storage, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, InsertPosition InsertPt)
Insert a new dbg_declare_value record.
LLVM_ABI DIBasicType * createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding, DINode::DIFlags Flags=DINode::FlagZero, uint32_t NumExtraInhabitants=0, uint32_t DataSizeInBits=0)
Create debugging information entry for a basic type.
LLVM_ABI DISubrange * getOrCreateSubrange(int64_t Lo, int64_t Count)
Create a descriptor for a value range.
LLVM_ABI DISubrangeType * createSubrangeType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DIType *Ty, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride, Metadata *Bias)
Create a type describing a subrange of another type.
LLVM_ABI DIDerivedType * createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits=0, uint32_t AlignInBits=0, std::optional< unsigned > DWARFAddressSpace=std::nullopt)
Create debugging information entry for a c++ style reference or rvalue reference type.
LLVM_ABI DIMacroFile * createTempMacroFile(DIMacroFile *Parent, unsigned Line, DIFile *File)
Create debugging information temporary entry for a macro file.
LLVM_ABI DICompositeType * createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts, PointerUnion< DIExpression *, DIVariable * > DataLocation=nullptr, PointerUnion< DIExpression *, DIVariable * > Associated=nullptr, PointerUnion< DIExpression *, DIVariable * > Allocated=nullptr, PointerUnion< DIExpression *, DIVariable * > Rank=nullptr)
Create debugging information entry for an array.
LLVM_ABI DIDerivedType * createMemberPointerType(DIType *PointeeTy, DIType *Class, uint64_t SizeInBits, uint32_t AlignInBits=0, DINode::DIFlags Flags=DINode::FlagZero)
Create debugging information entry for a pointer to member.
LLVM_ABI DbgRecord * insertDeclare(Value *Storage, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, BasicBlock *InsertAtEnd)
Insert a new dbg_declare record.
LLVM_ABI DINodeArray getOrCreateArray(ArrayRef< Metadata * > Elements)
Get a DINodeArray, create one if required.
LLVM_ABI DICompileUnit * createCompileUnit(DISourceLanguageName Lang, DIFile *File, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RV, StringRef SplitName=StringRef(), DICompileUnit::DebugEmissionKind Kind=DICompileUnit::DebugEmissionKind::FullDebug, uint64_t DWOId=0, bool SplitDebugInlining=true, bool DebugInfoForProfiling=false, DICompileUnit::DebugNameTableKind NameTableKind=DICompileUnit::DebugNameTableKind::Default, bool RangesBaseAddress=false, StringRef SysRoot={}, StringRef SDK={})
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
LLVM_ABI DIEnumerator * createEnumerator(StringRef Name, const APSInt &Value)
Create a single enumerator value.
LLVM_ABI DITemplateTypeParameter * createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty, bool IsDefault)
Create debugging information for template type parameter.
LLVM_ABI DIBuilder(Module &M, bool AllowUnresolved=true, DICompileUnit *CU=nullptr)
Construct a builder for a module.
Definition DIBuilder.cpp:26
LLVM_ABI DIExpression * createExpression(ArrayRef< uint64_t > Addr={})
Create a new descriptor for the specified variable which has a complex address expression for its add...
LLVM_ABI DIDerivedType * createPtrAuthQualifiedType(DIType *FromTy, unsigned Key, bool IsAddressDiscriminated, unsigned ExtraDiscriminator, bool IsaPointer, bool authenticatesNullValues)
Create a __ptrauth qualifier.
LLVM_ABI DbgRecord * insertLabel(DILabel *LabelInfo, const DILocation *DL, InsertPosition InsertPt)
Insert a new dbg_label record.
LLVM_ABI DICompositeType * createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, unsigned RuntimeLang=0, uint64_t SizeInBits=0, uint32_t AlignInBits=0, StringRef UniqueIdentifier="", std::optional< uint32_t > EnumKind=std::nullopt)
Create a permanent forward-declared type.
LLVM_ABI DICompositeType * createVariantPart(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier="")
Create debugging information entry for a variant part.
LLVM_ABI DIImportedEntity * createImportedModule(DIScope *Context, DINamespace *NS, DIFile *File, unsigned Line, DINodeArray Elements=nullptr)
Create a descriptor for an imported module.
LLVM_ABI DIImportedEntity * createImportedDeclaration(DIScope *Context, DINode *Decl, DIFile *File, unsigned Line, StringRef Name="", DINodeArray Elements=nullptr)
Create a descriptor for an imported function.
LLVM_ABI DILocalVariable * createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve=false, DINode::DIFlags Flags=DINode::FlagZero, uint32_t AlignInBits=0)
Create a new descriptor for an auto variable.
static LLVM_ABI DISubprogram * createArtificialSubprogram(DISubprogram *SP)
Create a distinct clone of SP with FlagArtificial set.
LLVM_ABI DIGenericSubrange * getOrCreateGenericSubrange(DIGenericSubrange::BoundType Count, DIGenericSubrange::BoundType LowerBound, DIGenericSubrange::BoundType UpperBound, DIGenericSubrange::BoundType Stride)
LLVM_ABI DIBasicType * createUnspecifiedType(StringRef Name)
Create a DWARF unspecified type.
LLVM_ABI DIObjCProperty * createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, StringRef GetterName, StringRef SetterName, unsigned PropertyAttributes, DIType *Ty)
Create debugging information entry for Objective-C property.
LLVM_ABI DITemplateValueParameter * createTemplateValueParameter(DIScope *Scope, StringRef Name, DIType *Ty, bool IsDefault, Constant *Val)
Create debugging information for template value parameter.
LLVM_ABI DILocalVariable * createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve=false, DINode::DIFlags Flags=DINode::FlagZero, DINodeArray Annotations=nullptr)
Create a new descriptor for a parameter variable.
LLVM_ABI DIFile * createFile(StringRef Filename, StringRef Directory, std::optional< DIFile::ChecksumInfo< StringRef > > Checksum=std::nullopt, std::optional< StringRef > Source=std::nullopt)
Create a file descriptor to hold debugging information for a file.
LLVM_ABI void replaceArrays(DICompositeType *&T, DINodeArray Elements, DINodeArray TParams=DINodeArray())
Replace arrays on a composite type.
LLVM_ABI DIModule * createModule(DIScope *Scope, StringRef Name, StringRef ConfigurationMacros, StringRef IncludePath, StringRef APINotesFile={}, DIFile *File=nullptr, unsigned LineNo=0, bool IsDecl=false)
This creates new descriptor for a module with the specified parent scope.
Debug common block.
Enumeration value.
DWARF expression.
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
PointerUnion< DIVariable *, DIExpression * > BoundType
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
DILocalScope * getScope() const
Get the local scope for this label.
Debug lexical block.
A scope for locals.
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getScope() const
Get the local scope for this variable.
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Debug lexical block.
Tagged DWARF-like metadata node.
DIFlags
Debug info flags.
Base class for scope-like contexts.
Wrapper structure that holds source language identity metadata that includes language name,...
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
static LLVM_ABI const DIScope * getRawRetainedNodeScope(const MDNode *N)
DISPFlags
Debug info subprogram flags.
Array subrange.
Type array for a subprogram.
Base class for types.
TempDIType cloneWithFlags(DIFlags NewFlags) const
Returns a new temporary DIType with updated Flags.
Base class for variables.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
static LLVM_ABI DbgVariableRecord * createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr, const DILocation *DI)
static LLVM_ABI DbgVariableRecord * createDVRAssign(Value *Val, DILocalVariable *Variable, DIExpression *Expression, DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression, const DILocation *DI)
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)
DILocalVariable * getVariable() const
DIExpression * getAddressExpression() const
bool isValid() const
Definition Instruction.h:60
BasicBlock * getBasicBlock()
Definition Instruction.h:61
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:348
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1069
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1575
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1579
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1567
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
Definition Metadata.h:1311
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
Definition Metadata.h:1301
Tracking metadata reference owned by Metadata.
Definition Metadata.h:891
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:615
Tuple of metadata.
Definition Metadata.h:1484
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1513
Root of the metadata hierarchy.
Definition Metadata.h:64
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A tuple of MDNodes.
Definition Metadata.h:1755
LLVM_ABI void addOperand(MDNode *M)
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
A vector that has set insertion semantics.
Definition SetVector.h:57
ArrayRef< value_type > getArrayRef() const
Definition SetVector.h:91
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:310
Typed tracking ref.
LLVM Value Representation.
Definition Value.h:75
self_iterator getIterator()
Definition ilist_node.h:123
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
@ DW_MACINFO_undef
Definition Dwarf.h:901
@ DW_MACINFO_start_file
Definition Dwarf.h:902
@ DW_MACINFO_define
Definition Dwarf.h:900
This is an optimization pass for GlobalISel generic memory operations.
TypedTrackingMDRef< MDNode > TrackingMDNodeRef
@ Implicit
Not emitted register (e.g. carry, or temporary result).
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr from_range_t from_range
auto cast_or_null(const Y &Val)
Definition Casting.h:714
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:676
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition STLExtras.h:1151
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
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
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N
A single checksum, represented by a Kind and a Value (a string).