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,
147 DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
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
381DIBuilder::createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
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
404DIBuilder::createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits,
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
575 unsigned LineNumber, DIType *Ty,
576 DIDerivedType *BackingStorage) {
577 return DIProperty::get(VMContext, Name, File, LineNumber, Ty, BackingStorage);
578}
579
582 DIType *Ty, bool isDefault) {
583 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
584 return DITemplateTypeParameter::get(VMContext, Name, Ty, isDefault);
585}
586
589 DIScope *Context, StringRef Name, DIType *Ty,
590 bool IsDefault, Metadata *MD) {
591 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
592 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, IsDefault, MD);
593}
594
597 DIType *Ty, bool isDefault,
598 Constant *Val) {
600 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
601 isDefault, getConstantOrNull(Val));
602}
603
606 DIType *Ty, StringRef Val,
607 bool IsDefault) {
609 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
610 IsDefault, MDString::get(VMContext, Val));
611}
612
615 DIType *Ty, DINodeArray Val) {
617 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
618 false, Val.get());
619}
620
622 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
623 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
624 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
625 unsigned RunTimeLang, DIType *VTableHolder, MDNode *TemplateParams,
626 StringRef UniqueIdentifier, DINodeArray Annotations) {
627 assert((!Context || isa<DIScope>(Context)) &&
628 "createClassType should be called with a valid Context");
629
630 auto *R = DICompositeType::get(
631 VMContext, dwarf::DW_TAG_class_type, Name, File, LineNumber,
632 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
633 OffsetInBits, Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt,
634 VTableHolder, cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier,
635 nullptr, nullptr, nullptr, nullptr, nullptr, Annotations);
636 trackIfUnresolved(R);
638 getSubprogramNodesTrackingVector(Context).emplace_back(R);
639 return R;
640}
641
643 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
644 Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
645 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
646 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
647 uint32_t NumExtraInhabitants, DINodeArray Annotations) {
648 auto *R = DICompositeType::get(
649 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
650 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
651 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
652 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
653 Annotations, Specification, NumExtraInhabitants);
654 trackIfUnresolved(R);
656 getSubprogramNodesTrackingVector(Context).emplace_back(R);
657 return R;
658}
659
661 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
662 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
663 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
664 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
665 uint32_t NumExtraInhabitants, DINodeArray Annotations) {
666 auto *R = DICompositeType::get(
667 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
668 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
669 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
670 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
671 Annotations, Specification, NumExtraInhabitants);
672 trackIfUnresolved(R);
674 getSubprogramNodesTrackingVector(Context).emplace_back(R);
675 return R;
676}
677
679 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
680 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
681 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier,
682 DINodeArray Annotations) {
683 auto *R = DICompositeType::get(
684 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
685 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
686 Elements, RunTimeLang, /*EnumKind=*/std::nullopt, nullptr, nullptr,
687 UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
689 trackIfUnresolved(R);
691 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
692 return R;
693}
694
697 unsigned LineNumber, uint64_t SizeInBits,
698 uint32_t AlignInBits, DINode::DIFlags Flags,
699 DIDerivedType *Discriminator, DINodeArray Elements,
700 StringRef UniqueIdentifier) {
701 auto *R = DICompositeType::get(
702 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
703 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
704 Elements, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr,
705 UniqueIdentifier, Discriminator);
706 trackIfUnresolved(R);
707 return R;
708}
709
711 DINode::DIFlags Flags,
712 unsigned CC) {
713 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
714}
715
717 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
718 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
719 DIType *UnderlyingType, unsigned RunTimeLang, StringRef UniqueIdentifier,
720 bool IsScoped, std::optional<uint32_t> EnumKind) {
721 auto *CTy = DICompositeType::get(
722 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
723 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
724 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
725 RunTimeLang, EnumKind, nullptr, nullptr, UniqueIdentifier);
727 getSubprogramNodesTrackingVector(Scope).emplace_back(CTy);
728 else
729 EnumTypes.emplace_back(CTy);
730 trackIfUnresolved(CTy);
731 return CTy;
732}
733
735 DIFile *File, unsigned LineNo,
736 uint64_t SizeInBits,
737 uint32_t AlignInBits, DIType *Ty) {
738 auto *R = DIDerivedType::get(VMContext, dwarf::DW_TAG_set_type, Name, File,
739 LineNo, getNonCompileUnitScope(Scope), Ty,
740 SizeInBits, AlignInBits, 0, std::nullopt,
741 std::nullopt, DINode::FlagZero);
742 trackIfUnresolved(R);
744 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
745 return R;
746}
747
750 DINodeArray Subscripts,
755 return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits,
756 Ty, Subscripts, DL, AS, AL, RK);
757}
758
760 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
761 uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
766 auto *R = DICompositeType::get(
767 VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
768 getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
769 Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
778 nullptr, nullptr, 0, BitStride);
779 trackIfUnresolved(R);
781 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
782 return R;
783}
784
786 uint32_t AlignInBits, DIType *Ty,
787 DINodeArray Subscripts,
788 Metadata *BitStride) {
789 auto *R = DICompositeType::get(
790 VMContext, dwarf::DW_TAG_array_type, /*Name=*/"",
791 /*File=*/nullptr, /*Line=*/0, /*Scope=*/nullptr, /*BaseType=*/Ty,
792 /*SizeInBits=*/Size, /*AlignInBits=*/AlignInBits, /*OffsetInBits=*/0,
793 /*Flags=*/DINode::FlagVector, /*Elements=*/Subscripts,
794 /*RuntimeLang=*/0, /*EnumKind=*/std::nullopt, /*VTableHolder=*/nullptr,
795 /*TemplateParams=*/nullptr, /*Identifier=*/"",
796 /*Discriminator=*/nullptr, /*DataLocation=*/nullptr,
797 /*Associated=*/nullptr, /*Allocated=*/nullptr, /*Rank=*/nullptr,
798 /*Annotations=*/nullptr, /*Specification=*/nullptr,
799 /*NumExtraInhabitants=*/0,
800 /*BitStride=*/BitStride);
801 trackIfUnresolved(R);
802 return R;
803}
804
806 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
807 return MDNode::replaceWithDistinct(std::move(NewSP));
808}
809
811 DINode::DIFlags FlagsToSet) {
812 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
813 return MDNode::replaceWithUniqued(std::move(NewTy));
814}
815
817 // FIXME: Restrict this to the nodes where it's valid.
818 if (Ty->isArtificial())
819 return Ty;
820 return createTypeWithFlags(Ty, DINode::FlagArtificial);
821}
822
824 // FIXME: Restrict this to the nodes where it's valid.
825 if (Ty->isObjectPointer())
826 return Ty;
827 DINode::DIFlags Flags = DINode::FlagObjectPointer;
828
829 if (Implicit)
830 Flags |= DINode::FlagArtificial;
831
832 return createTypeWithFlags(Ty, Flags);
833}
834
836 assert(T && "Expected non-null type");
838 cast<DISubprogram>(T)->isDefinition() == false)) &&
839 "Expected type or subprogram declaration");
840 if (!isa_and_nonnull<DILocalScope>(T->getScope()))
841 AllRetainTypes.emplace_back(T);
842}
843
845
847 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
848 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
849 StringRef UniqueIdentifier, std::optional<uint32_t> EnumKind) {
850 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
851 // replaceWithUniqued().
852 auto *RetTy = DICompositeType::get(
853 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
854 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
855 /*EnumKind=*/EnumKind, nullptr, nullptr, UniqueIdentifier);
856 trackIfUnresolved(RetTy);
858 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
859 return RetTy;
860}
861
863 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
864 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
865 DINode::DIFlags Flags, StringRef UniqueIdentifier, DINodeArray Annotations,
866 std::optional<uint32_t> EnumKind) {
867 auto *RetTy =
869 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
870 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, EnumKind,
871 nullptr, nullptr, UniqueIdentifier, nullptr, nullptr, nullptr,
872 nullptr, nullptr, Annotations)
873 .release();
874 trackIfUnresolved(RetTy);
876 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
877 return RetTy;
878}
879
881 return MDTuple::get(VMContext, Elements);
882}
883
884DIMacroNodeArray
886 return MDTuple::get(VMContext, Elements);
887}
888
891 for (Metadata *E : Elements) {
893 Elts.push_back(cast<DIType>(E));
894 else
895 Elts.push_back(E);
896 }
897 return DITypeArray(MDNode::get(VMContext, Elts));
898}
899
901 auto *LB = ConstantAsMetadata::get(
903 auto *CountNode = ConstantAsMetadata::get(
905 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
906}
907
909 auto *LB = ConstantAsMetadata::get(
911 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
912}
913
915 Metadata *UB, Metadata *Stride) {
916 return DISubrange::get(VMContext, CountNode, LB, UB, Stride);
917}
918
922 auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * {
923 return isa<DIExpression *>(Bound) ? (Metadata *)cast<DIExpression *>(Bound)
924 : (Metadata *)cast<DIVariable *>(Bound);
925 };
926 return DIGenericSubrange::get(VMContext, ConvToMetadata(CountNode),
927 ConvToMetadata(LB), ConvToMetadata(UB),
928 ConvToMetadata(Stride));
929}
930
932 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope,
933 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
934 DIType *Ty, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride,
935 Metadata *Bias) {
936 auto *T = DISubrangeType::get(VMContext, Name, File, LineNo, Scope,
937 SizeInBits, AlignInBits, Flags, Ty, LowerBound,
938 UpperBound, Stride, Bias);
940 getSubprogramNodesTrackingVector(Scope).emplace_back(T);
941 return T;
942}
943
944static void checkGlobalVariableScope(DIScope *Context) {
945#ifndef NDEBUG
946 if (auto *CT =
948 assert(CT->getIdentifier().empty() &&
949 "Context of a global variable should not be a type with identifier");
950#endif
951}
952
954 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
955 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined,
956 DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams,
957 uint32_t AlignInBits, DINodeArray Annotations) {
959
961 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
962 LineNumber, Ty, IsLocalToUnit, isDefined,
963 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
965 if (!Expr)
966 Expr = createExpression();
967 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
969 getSubprogramNodesTrackingVector(Context).emplace_back(N);
970 else
971 Globals.push_back(N);
972 return N;
973}
974
976 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
977 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, MDNode *Decl,
978 MDTuple *TemplateParams, uint32_t AlignInBits) {
980
982 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
983 LineNumber, Ty, IsLocalToUnit, false,
984 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
985 nullptr)
986 .release();
987}
988
990 LLVMContext &VMContext,
992 DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
993 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
994 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
995 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
996 // the only valid scopes)?
997 auto *Scope = cast<DILocalScope>(Context);
998 auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
999 ArgNo, Flags, AlignInBits, Annotations);
1000 if (AlwaysPreserve) {
1001 // The optimizer may remove local variables. If there is an interest
1002 // to preserve variable info in such situation then stash it in a
1003 // named mdnode.
1004 PreservedNodes.emplace_back(Node);
1005 }
1006 return Node;
1007}
1008
1010 DIFile *File, unsigned LineNo,
1011 DIType *Ty, bool AlwaysPreserve,
1012 DINode::DIFlags Flags,
1013 uint32_t AlignInBits) {
1014 assert(Scope && isa<DILocalScope>(Scope) &&
1015 "Unexpected scope for a local variable.");
1016 return createLocalVariable(
1017 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
1018 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
1019}
1020
1022 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
1023 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
1024 DINodeArray Annotations) {
1025 assert(ArgNo && "Expected non-zero argument number for parameter");
1026 assert(Scope && isa<DILocalScope>(Scope) &&
1027 "Unexpected scope for a local variable.");
1028 return createLocalVariable(
1029 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
1030 File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
1031}
1032
1034 unsigned LineNo, unsigned Column,
1035 bool IsArtificial,
1036 std::optional<unsigned> CoroSuspendIdx,
1037 bool AlwaysPreserve) {
1038 auto *Scope = cast<DILocalScope>(Context);
1039 auto *Node = DILabel::get(VMContext, Scope, Name, File, LineNo, Column,
1040 IsArtificial, CoroSuspendIdx);
1041
1042 if (AlwaysPreserve) {
1043 /// The optimizer may remove labels. If there is an interest
1044 /// to preserve label info in such situation then append it to
1045 /// the list of retained nodes of the DISubprogram.
1046 getSubprogramNodesTrackingVector(Scope).emplace_back(Node);
1047 }
1048 return Node;
1049}
1050
1054
1055template <class... Ts>
1056static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) {
1057 if (IsDistinct)
1058 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
1059 return DISubprogram::get(std::forward<Ts>(Args)...);
1060}
1061
1063 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1064 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1066 DITemplateParameterArray TParams, DISubprogram *Decl,
1067 DITypeArray ThrownTypes, DINodeArray Annotations, StringRef TargetFuncName,
1068 bool UseKeyInstructions) {
1069 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1070 auto *Node = getSubprogram(
1071 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
1072 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
1073 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr,
1074 ThrownTypes, Annotations, TargetFuncName, UseKeyInstructions);
1075
1076 AllSubprograms.push_back(Node);
1077 trackIfUnresolved(Node);
1078 return Node;
1079}
1080
1082 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1083 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1085 DITemplateParameterArray TParams, DISubprogram *Decl,
1086 DITypeArray ThrownTypes) {
1087 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1088 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
1089 Name, LinkageName, File, LineNo, Ty,
1090 ScopeLine, nullptr, 0, 0, Flags, SPFlags,
1091 IsDefinition ? CUNode : nullptr, TParams,
1092 Decl, nullptr, ThrownTypes)
1093 .release();
1094}
1095
1097 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
1098 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
1099 DIType *VTableHolder, DINode::DIFlags Flags,
1100 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
1101 DITypeArray ThrownTypes, bool UseKeyInstructions) {
1102 assert(getNonCompileUnitScope(Context) &&
1103 "Methods should have both a Context and a context that isn't "
1104 "the compile unit.");
1105 // FIXME: Do we want to use different scope/lines?
1106 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1107 auto *SP = getSubprogram(
1108 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
1109 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
1110 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
1111 nullptr, ThrownTypes, nullptr, "", IsDefinition && UseKeyInstructions);
1112
1113 AllSubprograms.push_back(SP);
1114 trackIfUnresolved(SP);
1115 return SP;
1116}
1117
1119 DIGlobalVariable *Decl,
1120 StringRef Name, DIFile *File,
1121 unsigned LineNo) {
1122 return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo);
1123}
1124
1126 bool ExportSymbols) {
1127
1128 // It is okay to *not* make anonymous top-level namespaces distinct, because
1129 // all nodes that have an anonymous namespace as their parent scope are
1130 // guaranteed to be unique and/or are linked to their containing
1131 // DICompileUnit. This decision is an explicit tradeoff of link time versus
1132 // memory usage versus code simplicity and may get revisited in the future.
1133 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
1134 ExportSymbols);
1135}
1136
1138 StringRef ConfigurationMacros,
1139 StringRef IncludePath, StringRef APINotesFile,
1140 DIFile *File, unsigned LineNo, bool IsDecl) {
1141 return DIModule::get(VMContext, File, getNonCompileUnitScope(Scope), Name,
1142 ConfigurationMacros, IncludePath, APINotesFile, LineNo,
1143 IsDecl);
1144}
1145
1147 DIFile *File,
1148 unsigned Discriminator) {
1149 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
1150}
1151
1153 unsigned Line, unsigned Col) {
1154 // Make these distinct, to avoid merging two lexical blocks on the same
1155 // file/line/column.
1156 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
1157 File, Line, Col);
1158}
1159
1161 DIExpression *Expr, const DILocation *DL,
1162 BasicBlock *InsertAtEnd) {
1163 // If this block already has a terminator then insert this record before
1164 // the terminator. Otherwise, put it at the end of the block.
1165 Instruction *InsertBefore = InsertAtEnd->getTerminatorOrNull();
1166 return insertDeclare(Storage, VarInfo, Expr, DL,
1167 InsertBefore ? InsertBefore->getIterator()
1168 : InsertAtEnd->end());
1169}
1170
1172 DILocalVariable *SrcVar,
1173 DIExpression *ValExpr, Value *Addr,
1174 DIExpression *AddrExpr,
1175 const DILocation *DL) {
1176 auto *Link = cast_or_null<DIAssignID>(
1177 LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
1178 assert(Link && "Linked instruction must have DIAssign metadata attached");
1179
1181 Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1182 // Insert after LinkedInstr.
1183 BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1184 NextIt.setHeadBit(true);
1185 insertDbgVariableRecord(DVR, NextIt);
1186 return DVR;
1187}
1188
1190 DIExpression *Expr, const DILocation *DL,
1191 InsertPosition InsertPt) {
1192 DbgVariableRecord *DVR =
1194 insertDbgVariableRecord(DVR, InsertPt);
1195 return DVR;
1196}
1197
1199 DIExpression *Expr, const DILocation *DL,
1200 InsertPosition InsertPt) {
1201 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
1202 assert(DL && "Expected debug loc");
1203 assert(DL->getScope()->getSubprogram() ==
1204 VarInfo->getScope()->getSubprogram() &&
1205 "Expected matching subprograms");
1206
1207 DbgVariableRecord *DVR =
1208 DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1209 insertDbgVariableRecord(DVR, InsertPt);
1210 return DVR;
1211}
1212
1214 DILocalVariable *VarInfo,
1215 DIExpression *Expr,
1216 const DILocation *DL,
1217 InsertPosition InsertPt) {
1218 assert(VarInfo &&
1219 "empty or invalid DILocalVariable* passed to dbg.declare_value");
1220 assert(DL && "Expected debug loc");
1221 assert(DL->getScope()->getSubprogram() ==
1222 VarInfo->getScope()->getSubprogram() &&
1223 "Expected matching subprograms");
1224
1225 DbgVariableRecord *DVR =
1226 DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
1227 insertDbgVariableRecord(DVR, InsertPt);
1228 return DVR;
1229}
1230
1231void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
1232 InsertPosition InsertPt) {
1233 assert(InsertPt.isValid());
1234 trackIfUnresolved(DVR->getVariable());
1235 trackIfUnresolved(DVR->getExpression());
1236 if (DVR->isDbgAssign())
1237 trackIfUnresolved(DVR->getAddressExpression());
1238
1239 auto *BB = InsertPt.getBasicBlock();
1240 BB->insertDbgRecordBefore(DVR, InsertPt);
1241}
1242
1244 InsertPosition InsertPt) {
1245 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
1246 assert(DL && "Expected debug loc");
1247 assert(DL->getScope()->getSubprogram() ==
1248 LabelInfo->getScope()->getSubprogram() &&
1249 "Expected matching subprograms");
1250
1251 trackIfUnresolved(LabelInfo);
1252 DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1253 if (InsertPt.isValid()) {
1254 auto *BB = InsertPt.getBasicBlock();
1255 BB->insertDbgRecordBefore(DLR, InsertPt);
1256 }
1257 return DLR;
1258}
1259
1261 {
1263 N->replaceVTableHolder(VTableHolder);
1264 T = N.get();
1265 }
1266
1267 // If this didn't create a self-reference, just return.
1268 if (T != VTableHolder)
1269 return;
1270
1271 // Look for unresolved operands. T will drop RAUW support, orphaning any
1272 // cycles underneath it.
1273 if (T->isResolved())
1274 for (const MDOperand &O : T->operands())
1275 if (auto *N = dyn_cast_or_null<MDNode>(O))
1276 trackIfUnresolved(N);
1277}
1278
1279void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
1280 DINodeArray TParams) {
1281 {
1283 if (Elements)
1284 N->replaceElements(Elements);
1285 if (TParams)
1286 N->replaceTemplateParams(DITemplateParameterArray(TParams));
1287 T = N.get();
1288 }
1289
1290 // If T isn't resolved, there's no problem.
1291 if (!T->isResolved())
1292 return;
1293
1294 // If T is resolved, it may be due to a self-reference cycle. Track the
1295 // arrays explicitly if they're unresolved, or else the cycles will be
1296 // orphaned.
1297 if (Elements)
1298 trackIfUnresolved(Elements.get());
1299 if (TParams)
1300 trackIfUnresolved(TParams.get());
1301}
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:1259
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 DIProperty * createProperty(StringRef Name, DIFile *File, unsigned LineNumber, DIType *Ty, DIDerivedType *BackingStorage)
Create debugging information entry for a property, i.e.
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.
A property of a class or structure.
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).