LLVM 23.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/IRBuilder.h"
21#include "llvm/IR/Module.h"
22#include <optional>
23
24using namespace llvm;
25using namespace llvm::dwarf;
26
27DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
28 : M(m), VMContext(M.getContext()), CUNode(CU),
29 AllowUnresolvedNodes(AllowUnresolvedNodes) {
30 if (CUNode) {
31 if (const auto &ETs = CUNode->getEnumTypes())
32 EnumTypes.assign(ETs.begin(), ETs.end());
33 if (const auto &RTs = CUNode->getRetainedTypes())
34 AllRetainTypes.assign(RTs.begin(), RTs.end());
35 if (const auto &GVs = CUNode->getGlobalVariables())
36 AllGVs.assign(GVs.begin(), GVs.end());
37 if (const auto &IMs = CUNode->getImportedEntities())
38 ImportedModules.assign(IMs.begin(), IMs.end());
39 if (const auto &MNs = CUNode->getMacros())
40 AllMacrosPerParent.insert({nullptr, {llvm::from_range, MNs}});
41 }
42}
43
44void DIBuilder::trackIfUnresolved(MDNode *N) {
45 if (!N)
46 return;
47 if (N->isResolved())
48 return;
49
50 assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
51 UnresolvedNodes.emplace_back(N);
52}
53
55 auto PN = SubprogramTrackedNodes.find(SP);
56 if (PN == SubprogramTrackedNodes.end())
57 return;
58
59 SmallVector<Metadata *, 16> RetainedNodes;
60 for (MDNode *N : PN->second) {
61 // If the tracked node N was temporary, and the DIBuilder user replaced it
62 // with a node that does not belong to SP or is non-local, do not add N to
63 // SP's retainedNodes list.
66 if (!Scope || Scope->getSubprogram() != SP)
67 continue;
68
69 RetainedNodes.push_back(N);
70 }
71
72 SP->replaceRetainedNodes(MDTuple::get(VMContext, RetainedNodes));
73}
74
76 if (!CUNode) {
77 assert(!AllowUnresolvedNodes &&
78 "creating type nodes without a CU is not supported");
79 return;
80 }
81
82 if (!EnumTypes.empty())
83 CUNode->replaceEnumTypes(
84 MDTuple::get(VMContext, SmallVector<Metadata *, 16>(EnumTypes.begin(),
85 EnumTypes.end())));
86
87 SmallVector<Metadata *, 16> RetainValues;
88 // Declarations and definitions of the same type may be retained. Some
89 // clients RAUW these pairs, leaving duplicates in the retained types
90 // list. Use a set to remove the duplicates while we transform the
91 // TrackingVHs back into Values.
93 for (const TrackingMDNodeRef &N : AllRetainTypes)
94 if (RetainSet.insert(N).second)
95 RetainValues.push_back(N);
96
97 if (!RetainValues.empty())
98 CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
99
100 for (auto *SP : AllSubprograms)
102 for (auto *N : RetainValues)
103 if (auto *SP = dyn_cast<DISubprogram>(N))
105
106 if (!AllGVs.empty())
107 CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
108
109 if (!ImportedModules.empty())
110 CUNode->replaceImportedEntities(MDTuple::get(
111 VMContext, SmallVector<Metadata *, 16>(ImportedModules.begin(),
112 ImportedModules.end())));
113
114 for (const auto &I : AllMacrosPerParent) {
115 // DIMacroNode's with nullptr parent are DICompileUnit direct children.
116 if (!I.first) {
117 CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
118 continue;
119 }
120 // Otherwise, it must be a temporary DIMacroFile that need to be resolved.
121 auto *TMF = cast<DIMacroFile>(I.first);
123 TMF->getLine(), TMF->getFile(),
124 getOrCreateMacroArray(I.second.getArrayRef()));
125 replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
126 }
127
128 // Now that all temp nodes have been replaced or deleted, resolve remaining
129 // cycles.
130 for (const auto &N : UnresolvedNodes)
131 if (N && !N->isResolved())
132 N->resolveCycles();
133 UnresolvedNodes.clear();
134
135 // Can't handle unresolved nodes anymore.
136 AllowUnresolvedNodes = false;
137}
138
139/// If N is compile unit return NULL otherwise return N.
141 if (!N || isa<DICompileUnit>(N))
142 return nullptr;
143 return cast<DIScope>(N);
144}
145
147 DISourceLanguageName Lang, DIFile *File, StringRef Producer,
148 bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
150 bool SplitDebugInlining, bool DebugInfoForProfiling,
151 DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress,
152 StringRef SysRoot, StringRef SDK) {
153
154 assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
156 VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
157 SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
158 SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
159 RangesBaseAddress, SysRoot, SDK);
160
161 // Create a named metadata so that it is easier to find cu in a module.
162 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
163 NMD->addOperand(CUNode);
164 trackIfUnresolved(CUNode);
165 return CUNode;
166}
167
168static DIImportedEntity *
170 Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
171 DINodeArray Elements,
172 SmallVectorImpl<TrackingMDNodeRef> &ImportedModules) {
173 if (Line)
174 assert(File && "Source location has line number but no file");
175 unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
176 auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null<DINode>(NS),
177 File, Line, Name, Elements);
178 if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
179 // A new Imported Entity was just added to the context.
180 // Add it to the Imported Modules list.
181 ImportedModules.emplace_back(M);
182 return M;
183}
184
186 DINamespace *NS, DIFile *File,
187 unsigned Line,
188 DINodeArray Elements) {
189 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
190 Context, NS, File, Line, StringRef(), Elements,
191 getImportTrackingVector(Context));
192}
193
196 DIFile *File, unsigned Line,
197 DINodeArray Elements) {
198 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
199 Context, NS, File, Line, StringRef(), Elements,
200 getImportTrackingVector(Context));
201}
202
204 DIFile *File, unsigned Line,
205 DINodeArray Elements) {
206 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
207 Context, M, File, Line, StringRef(), Elements,
208 getImportTrackingVector(Context));
209}
210
213 DIFile *File, unsigned Line,
214 StringRef Name, DINodeArray Elements) {
215 // Make sure to use the unique identifier based metadata reference for
216 // types that have one.
217 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
218 Context, Decl, File, Line, Name, Elements,
219 getImportTrackingVector(Context));
220}
221
223 std::optional<DIFile::ChecksumInfo<StringRef>> CS,
224 std::optional<StringRef> Source) {
225 return DIFile::get(VMContext, Filename, Directory, CS, Source);
226}
227
228DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
229 unsigned MacroType, StringRef Name,
231 assert(!Name.empty() && "Unable to create macro without name");
232 assert((MacroType == dwarf::DW_MACINFO_undef ||
233 MacroType == dwarf::DW_MACINFO_define) &&
234 "Unexpected macro type");
235 auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
236 AllMacrosPerParent[Parent].insert(M);
237 return M;
238}
239
241 unsigned LineNumber, DIFile *File) {
243 LineNumber, File, DIMacroNodeArray())
244 .release();
245 AllMacrosPerParent[Parent].insert(MF);
246 // Add the new temporary DIMacroFile to the macro per parent map as a parent.
247 // This is needed to assure DIMacroFile with no children to have an entry in
248 // the map. Otherwise, it will not be resolved in DIBuilder::finalize().
249 AllMacrosPerParent.insert({MF, {}});
250 return MF;
251}
252
254 bool IsUnsigned) {
255 assert(!Name.empty() && "Unable to create enumerator without name");
256 return DIEnumerator::get(VMContext, APInt(64, Val, !IsUnsigned), IsUnsigned,
257 Name);
258}
259
261 assert(!Name.empty() && "Unable to create enumerator without name");
262 return DIEnumerator::get(VMContext, APInt(Value), Value.isUnsigned(), Name);
263}
264
266 assert(!Name.empty() && "Unable to create type without name");
267 return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
268}
269
271 return createUnspecifiedType("decltype(nullptr)");
272}
273
275 unsigned Encoding,
276 DINode::DIFlags Flags,
277 uint32_t NumExtraInhabitants,
278 uint32_t DataSizeInBits) {
279 return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
280 0, Encoding, NumExtraInhabitants, DataSizeInBits,
281 Flags);
282}
283
286 uint32_t AlignInBits, unsigned Encoding,
287 DINode::DIFlags Flags, int Factor) {
288 return DIFixedPointType::get(VMContext, dwarf::DW_TAG_base_type, Name,
289 SizeInBits, AlignInBits, Encoding, Flags,
291 APInt(), APInt());
292}
293
296 uint32_t AlignInBits, unsigned Encoding,
297 DINode::DIFlags Flags, int Factor) {
298 return DIFixedPointType::get(VMContext, dwarf::DW_TAG_base_type, Name,
299 SizeInBits, AlignInBits, Encoding, Flags,
301 APInt(), APInt());
302}
303
306 uint32_t AlignInBits, unsigned Encoding,
307 DINode::DIFlags Flags, APInt Numerator,
308 APInt Denominator) {
309 return DIFixedPointType::get(VMContext, dwarf::DW_TAG_base_type, Name,
310 SizeInBits, AlignInBits, Encoding, Flags,
312 Numerator, Denominator);
313}
314
316 assert(!Name.empty() && "Unable to create type without name");
317 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
318 SizeInBits, 0);
319}
320
322 DIVariable *StringLength,
323 DIExpression *StrLocationExp) {
324 assert(!Name.empty() && "Unable to create type without name");
325 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
326 StringLength, nullptr, StrLocationExp, 0, 0, 0);
327}
328
330 DIExpression *StringLengthExp,
331 DIExpression *StrLocationExp) {
332 assert(!Name.empty() && "Unable to create type without name");
333 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name, nullptr,
334 StringLengthExp, StrLocationExp, 0, 0, 0);
335}
336
338 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy,
339 (uint64_t)0, 0, (uint64_t)0, std::nullopt,
340 std::nullopt, DINode::FlagZero);
341}
342
344 DIType *FromTy, unsigned Key, bool IsAddressDiscriminated,
345 unsigned ExtraDiscriminator, bool IsaPointer,
346 bool AuthenticatesNullValues) {
347 return DIDerivedType::get(
348 VMContext, dwarf::DW_TAG_LLVM_ptrauth_type, "", nullptr, 0, nullptr,
349 FromTy, (uint64_t)0, 0, (uint64_t)0, std::nullopt,
350 std::optional<DIDerivedType::PtrAuthData>(
351 std::in_place, Key, IsAddressDiscriminated, ExtraDiscriminator,
352 IsaPointer, AuthenticatesNullValues),
353 DINode::FlagZero);
354}
355
358 uint32_t AlignInBits,
359 std::optional<unsigned> DWARFAddressSpace,
360 StringRef Name, DINodeArray Annotations) {
361 // FIXME: Why is there a name here?
362 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
363 nullptr, 0, nullptr, PointeeTy, SizeInBits,
364 AlignInBits, 0, DWARFAddressSpace, std::nullopt,
365 DINode::FlagZero, nullptr, Annotations);
366}
367
369 DIType *Base,
370 uint64_t SizeInBits,
371 uint32_t AlignInBits,
372 DINode::DIFlags Flags) {
373 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
374 nullptr, 0, nullptr, PointeeTy, SizeInBits,
375 AlignInBits, 0, std::nullopt, std::nullopt, Flags,
376 Base);
377}
378
381 uint32_t AlignInBits,
382 std::optional<unsigned> DWARFAddressSpace) {
383 assert(RTy && "Unable to create reference type");
384 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
385 SizeInBits, AlignInBits, 0, DWARFAddressSpace, {},
386 DINode::FlagZero);
387}
388
390 DIFile *File, unsigned LineNo,
391 DIScope *Context, uint32_t AlignInBits,
392 DINode::DIFlags Flags,
393 DINodeArray Annotations) {
394 auto *T = DIDerivedType::get(
395 VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo,
396 getNonCompileUnitScope(Context), Ty, (uint64_t)0, AlignInBits,
397 (uint64_t)0, std::nullopt, std::nullopt, Flags, nullptr, Annotations);
399 getSubprogramNodesTrackingVector(Context).emplace_back(T);
400 return T;
401}
402
405 unsigned LineNo, DIScope *Context,
406 DINodeArray TParams, uint32_t AlignInBits,
407 DINode::DIFlags Flags, DINodeArray Annotations) {
408 auto *T =
409 DIDerivedType::get(VMContext, dwarf::DW_TAG_template_alias, Name, File,
410 LineNo, getNonCompileUnitScope(Context), Ty,
411 (uint64_t)0, AlignInBits, (uint64_t)0, std::nullopt,
412 std::nullopt, Flags, TParams.get(), Annotations);
414 getSubprogramNodesTrackingVector(Context).emplace_back(T);
415 return T;
416}
417
419 assert(Ty && "Invalid type!");
420 assert(FriendTy && "Invalid friend type!");
421 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
422 FriendTy, (uint64_t)0, 0, (uint64_t)0, std::nullopt,
423 std::nullopt, DINode::FlagZero);
424}
425
427 uint64_t BaseOffset,
428 uint32_t VBPtrOffset,
429 DINode::DIFlags Flags) {
430 assert(Ty && "Unable to create inheritance");
432 ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
433 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
434 0, Ty, BaseTy, 0, 0, BaseOffset, std::nullopt,
435 std::nullopt, Flags, ExtraData);
436}
437
439 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
440 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
441 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
442 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
443 LineNumber, getNonCompileUnitScope(Scope), Ty,
444 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
445 std::nullopt, Flags, nullptr, Annotations);
446}
447
449 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
450 Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits,
451 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
452 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
453 LineNumber, getNonCompileUnitScope(Scope), Ty,
454 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
455 std::nullopt, Flags, nullptr, Annotations);
456}
457
459 if (C)
461 return nullptr;
462}
463
465 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
466 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
467 Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
468 // "ExtraData" is overloaded for bit fields and for variants, so
469 // make sure to disallow this.
470 assert((Flags & DINode::FlagBitField) == 0);
471 return DIDerivedType::get(
472 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
473 getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits,
474 std::nullopt, std::nullopt, Flags, getConstantOrNull(Discriminant));
475}
476
478 DINodeArray Elements,
479 Constant *Discriminant,
480 DIType *Ty) {
481 auto *V = DICompositeType::get(VMContext, dwarf::DW_TAG_variant, {}, nullptr,
482 0, getNonCompileUnitScope(Scope), {},
483 (uint64_t)0, 0, (uint64_t)0, DINode::FlagZero,
484 Elements, 0, {}, nullptr);
485
486 trackIfUnresolved(V);
487 return createVariantMemberType(Scope, {}, nullptr, 0, 0, 0, 0, Discriminant,
488 DINode::FlagZero, V);
489}
490
492 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
493 Metadata *SizeInBits, Metadata *OffsetInBits, uint64_t StorageOffsetInBits,
494 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
495 Flags |= DINode::FlagBitField;
496 return DIDerivedType::get(
497 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
498 getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
499 OffsetInBits, std::nullopt, std::nullopt, Flags,
500 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
501 StorageOffsetInBits)),
503}
504
506 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
507 uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
508 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
509 Flags |= DINode::FlagBitField;
510 return DIDerivedType::get(
511 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
512 getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
513 OffsetInBits, std::nullopt, std::nullopt, Flags,
514 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
515 StorageOffsetInBits)),
517}
518
521 unsigned LineNumber, DIType *Ty,
523 unsigned Tag, uint32_t AlignInBits) {
524 Flags |= DINode::FlagStaticMember;
525 return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
526 getNonCompileUnitScope(Scope), Ty, (uint64_t)0,
527 AlignInBits, (uint64_t)0, std::nullopt,
528 std::nullopt, Flags, getConstantOrNull(Val));
529}
530
532DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber,
533 uint64_t SizeInBits, uint32_t AlignInBits,
534 uint64_t OffsetInBits, DINode::DIFlags Flags,
535 DIType *Ty, MDNode *PropertyNode) {
536 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
537 LineNumber, getNonCompileUnitScope(File), Ty,
538 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
539 std::nullopt, Flags, PropertyNode);
540}
541
543DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
544 StringRef GetterName, StringRef SetterName,
545 unsigned PropertyAttributes, DIType *Ty) {
546 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
547 SetterName, PropertyAttributes, Ty);
548}
549
552 DIType *Ty, bool isDefault) {
553 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
554 return DITemplateTypeParameter::get(VMContext, Name, Ty, isDefault);
555}
556
559 DIScope *Context, StringRef Name, DIType *Ty,
560 bool IsDefault, Metadata *MD) {
561 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
562 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, IsDefault, MD);
563}
564
567 DIType *Ty, bool isDefault,
568 Constant *Val) {
570 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
571 isDefault, getConstantOrNull(Val));
572}
573
576 DIType *Ty, StringRef Val,
577 bool IsDefault) {
579 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
580 IsDefault, MDString::get(VMContext, Val));
581}
582
585 DIType *Ty, DINodeArray Val) {
587 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
588 false, Val.get());
589}
590
592 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
593 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
594 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
595 unsigned RunTimeLang, DIType *VTableHolder, MDNode *TemplateParams,
596 StringRef UniqueIdentifier) {
597 assert((!Context || isa<DIScope>(Context)) &&
598 "createClassType should be called with a valid Context");
599
600 auto *R = DICompositeType::get(
601 VMContext, dwarf::DW_TAG_class_type, Name, File, LineNumber,
602 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
603 OffsetInBits, Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt,
604 VTableHolder, cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
605 trackIfUnresolved(R);
607 getSubprogramNodesTrackingVector(Context).emplace_back(R);
608 return R;
609}
610
612 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
613 Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
614 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
615 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
616 uint32_t NumExtraInhabitants) {
617 auto *R = DICompositeType::get(
618 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
619 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
620 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
621 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
622 nullptr, Specification, NumExtraInhabitants);
623 trackIfUnresolved(R);
625 getSubprogramNodesTrackingVector(Context).emplace_back(R);
626 return R;
627}
628
630 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
631 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
632 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
633 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
634 uint32_t NumExtraInhabitants) {
635 auto *R = DICompositeType::get(
636 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
637 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
638 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
639 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
640 nullptr, Specification, NumExtraInhabitants);
641 trackIfUnresolved(R);
643 getSubprogramNodesTrackingVector(Context).emplace_back(R);
644 return R;
645}
646
648 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
649 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
650 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
651 auto *R = DICompositeType::get(
652 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
653 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
654 Elements, RunTimeLang, /*EnumKind=*/std::nullopt, nullptr, nullptr,
655 UniqueIdentifier);
656 trackIfUnresolved(R);
658 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
659 return R;
660}
661
664 unsigned LineNumber, uint64_t SizeInBits,
665 uint32_t AlignInBits, DINode::DIFlags Flags,
666 DIDerivedType *Discriminator, DINodeArray Elements,
667 StringRef UniqueIdentifier) {
668 auto *R = DICompositeType::get(
669 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
670 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
671 Elements, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr,
672 UniqueIdentifier, Discriminator);
673 trackIfUnresolved(R);
674 return R;
675}
676
678 DINode::DIFlags Flags,
679 unsigned CC) {
680 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
681}
682
684 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
685 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
686 DIType *UnderlyingType, unsigned RunTimeLang, StringRef UniqueIdentifier,
687 bool IsScoped, std::optional<uint32_t> EnumKind) {
688 auto *CTy = DICompositeType::get(
689 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
690 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
691 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
692 RunTimeLang, EnumKind, nullptr, nullptr, UniqueIdentifier);
694 getSubprogramNodesTrackingVector(Scope).emplace_back(CTy);
695 else
696 EnumTypes.emplace_back(CTy);
697 trackIfUnresolved(CTy);
698 return CTy;
699}
700
702 DIFile *File, unsigned LineNo,
703 uint64_t SizeInBits,
704 uint32_t AlignInBits, DIType *Ty) {
705 auto *R = DIDerivedType::get(VMContext, dwarf::DW_TAG_set_type, Name, File,
706 LineNo, getNonCompileUnitScope(Scope), Ty,
707 SizeInBits, AlignInBits, 0, std::nullopt,
708 std::nullopt, DINode::FlagZero);
709 trackIfUnresolved(R);
711 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
712 return R;
713}
714
717 DINodeArray Subscripts,
722 return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits,
723 Ty, Subscripts, DL, AS, AL, RK);
724}
725
727 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
728 uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
733 auto *R = DICompositeType::get(
734 VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
735 getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
736 Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
745 nullptr, nullptr, 0, BitStride);
746 trackIfUnresolved(R);
748 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
749 return R;
750}
751
753 uint32_t AlignInBits, DIType *Ty,
754 DINodeArray Subscripts,
755 Metadata *BitStride) {
756 auto *R = DICompositeType::get(
757 VMContext, dwarf::DW_TAG_array_type, /*Name=*/"",
758 /*File=*/nullptr, /*Line=*/0, /*Scope=*/nullptr, /*BaseType=*/Ty,
759 /*SizeInBits=*/Size, /*AlignInBits=*/AlignInBits, /*OffsetInBits=*/0,
760 /*Flags=*/DINode::FlagVector, /*Elements=*/Subscripts,
761 /*RuntimeLang=*/0, /*EnumKind=*/std::nullopt, /*VTableHolder=*/nullptr,
762 /*TemplateParams=*/nullptr, /*Identifier=*/"",
763 /*Discriminator=*/nullptr, /*DataLocation=*/nullptr,
764 /*Associated=*/nullptr, /*Allocated=*/nullptr, /*Rank=*/nullptr,
765 /*Annotations=*/nullptr, /*Specification=*/nullptr,
766 /*NumExtraInhabitants=*/0,
767 /*BitStride=*/BitStride);
768 trackIfUnresolved(R);
769 return R;
770}
771
773 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
774 return MDNode::replaceWithDistinct(std::move(NewSP));
775}
776
778 DINode::DIFlags FlagsToSet) {
779 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
780 return MDNode::replaceWithUniqued(std::move(NewTy));
781}
782
784 // FIXME: Restrict this to the nodes where it's valid.
785 if (Ty->isArtificial())
786 return Ty;
787 return createTypeWithFlags(Ty, DINode::FlagArtificial);
788}
789
791 // FIXME: Restrict this to the nodes where it's valid.
792 if (Ty->isObjectPointer())
793 return Ty;
794 DINode::DIFlags Flags = DINode::FlagObjectPointer;
795
796 if (Implicit)
797 Flags |= DINode::FlagArtificial;
798
799 return createTypeWithFlags(Ty, Flags);
800}
801
803 assert(T && "Expected non-null type");
805 cast<DISubprogram>(T)->isDefinition() == false)) &&
806 "Expected type or subprogram declaration");
807 if (!isa_and_nonnull<DILocalScope>(T->getScope()))
808 AllRetainTypes.emplace_back(T);
809}
810
812
814 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
815 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
816 StringRef UniqueIdentifier, std::optional<uint32_t> EnumKind) {
817 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
818 // replaceWithUniqued().
819 auto *RetTy = DICompositeType::get(
820 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
821 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
822 /*EnumKind=*/EnumKind, nullptr, nullptr, UniqueIdentifier);
823 trackIfUnresolved(RetTy);
825 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
826 return RetTy;
827}
828
830 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
831 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
832 DINode::DIFlags Flags, StringRef UniqueIdentifier, DINodeArray Annotations,
833 std::optional<uint32_t> EnumKind) {
834 auto *RetTy =
836 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
837 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, EnumKind,
838 nullptr, nullptr, UniqueIdentifier, nullptr, nullptr, nullptr,
839 nullptr, nullptr, Annotations)
840 .release();
841 trackIfUnresolved(RetTy);
843 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
844 return RetTy;
845}
846
848 return MDTuple::get(VMContext, Elements);
849}
850
851DIMacroNodeArray
853 return MDTuple::get(VMContext, Elements);
854}
855
858 for (Metadata *E : Elements) {
860 Elts.push_back(cast<DIType>(E));
861 else
862 Elts.push_back(E);
863 }
864 return DITypeArray(MDNode::get(VMContext, Elts));
865}
866
868 auto *LB = ConstantAsMetadata::get(
870 auto *CountNode = ConstantAsMetadata::get(
872 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
873}
874
876 auto *LB = ConstantAsMetadata::get(
878 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
879}
880
882 Metadata *UB, Metadata *Stride) {
883 return DISubrange::get(VMContext, CountNode, LB, UB, Stride);
884}
885
889 auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * {
890 return isa<DIExpression *>(Bound) ? (Metadata *)cast<DIExpression *>(Bound)
891 : (Metadata *)cast<DIVariable *>(Bound);
892 };
893 return DIGenericSubrange::get(VMContext, ConvToMetadata(CountNode),
894 ConvToMetadata(LB), ConvToMetadata(UB),
895 ConvToMetadata(Stride));
896}
897
899 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope,
900 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
901 DIType *Ty, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride,
902 Metadata *Bias) {
903 auto *T = DISubrangeType::get(VMContext, Name, File, LineNo, Scope,
904 SizeInBits, AlignInBits, Flags, Ty, LowerBound,
905 UpperBound, Stride, Bias);
907 getSubprogramNodesTrackingVector(Scope).emplace_back(T);
908 return T;
909}
910
911static void checkGlobalVariableScope(DIScope *Context) {
912#ifndef NDEBUG
913 if (auto *CT =
915 assert(CT->getIdentifier().empty() &&
916 "Context of a global variable should not be a type with identifier");
917#endif
918}
919
921 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
922 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined,
923 DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams,
924 uint32_t AlignInBits, DINodeArray Annotations) {
926
928 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
929 LineNumber, Ty, IsLocalToUnit, isDefined,
930 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
932 if (!Expr)
933 Expr = createExpression();
934 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
935 AllGVs.push_back(N);
936 return N;
937}
938
940 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
941 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, MDNode *Decl,
942 MDTuple *TemplateParams, uint32_t AlignInBits) {
944
946 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
947 LineNumber, Ty, IsLocalToUnit, false,
948 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
949 nullptr)
950 .release();
951}
952
954 LLVMContext &VMContext,
956 DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
957 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
958 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
959 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
960 // the only valid scopes)?
961 auto *Scope = cast<DILocalScope>(Context);
962 auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
963 ArgNo, Flags, AlignInBits, Annotations);
964 if (AlwaysPreserve) {
965 // The optimizer may remove local variables. If there is an interest
966 // to preserve variable info in such situation then stash it in a
967 // named mdnode.
968 PreservedNodes.emplace_back(Node);
969 }
970 return Node;
971}
972
974 DIFile *File, unsigned LineNo,
975 DIType *Ty, bool AlwaysPreserve,
976 DINode::DIFlags Flags,
977 uint32_t AlignInBits) {
978 assert(Scope && isa<DILocalScope>(Scope) &&
979 "Unexpected scope for a local variable.");
980 return createLocalVariable(
981 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
982 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
983}
984
986 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
987 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
988 DINodeArray Annotations) {
989 assert(ArgNo && "Expected non-zero argument number for parameter");
990 assert(Scope && isa<DILocalScope>(Scope) &&
991 "Unexpected scope for a local variable.");
992 return createLocalVariable(
993 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
994 File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
995}
996
998 unsigned LineNo, unsigned Column,
999 bool IsArtificial,
1000 std::optional<unsigned> CoroSuspendIdx,
1001 bool AlwaysPreserve) {
1002 auto *Scope = cast<DILocalScope>(Context);
1003 auto *Node = DILabel::get(VMContext, Scope, Name, File, LineNo, Column,
1004 IsArtificial, CoroSuspendIdx);
1005
1006 if (AlwaysPreserve) {
1007 /// The optimizer may remove labels. If there is an interest
1008 /// to preserve label info in such situation then append it to
1009 /// the list of retained nodes of the DISubprogram.
1010 getSubprogramNodesTrackingVector(Scope).emplace_back(Node);
1011 }
1012 return Node;
1013}
1014
1018
1019template <class... Ts>
1020static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) {
1021 if (IsDistinct)
1022 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
1023 return DISubprogram::get(std::forward<Ts>(Args)...);
1024}
1025
1027 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1028 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1030 DITemplateParameterArray TParams, DISubprogram *Decl,
1031 DITypeArray ThrownTypes, DINodeArray Annotations, StringRef TargetFuncName,
1032 bool UseKeyInstructions) {
1033 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1034 auto *Node = getSubprogram(
1035 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
1036 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
1037 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr,
1038 ThrownTypes, Annotations, TargetFuncName, UseKeyInstructions);
1039
1040 AllSubprograms.push_back(Node);
1041 trackIfUnresolved(Node);
1042 return Node;
1043}
1044
1046 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1047 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1049 DITemplateParameterArray TParams, DISubprogram *Decl,
1050 DITypeArray ThrownTypes) {
1051 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1052 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
1053 Name, LinkageName, File, LineNo, Ty,
1054 ScopeLine, nullptr, 0, 0, Flags, SPFlags,
1055 IsDefinition ? CUNode : nullptr, TParams,
1056 Decl, nullptr, ThrownTypes)
1057 .release();
1058}
1059
1061 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
1062 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
1063 DIType *VTableHolder, DINode::DIFlags Flags,
1064 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
1065 DITypeArray ThrownTypes, bool UseKeyInstructions) {
1066 assert(getNonCompileUnitScope(Context) &&
1067 "Methods should have both a Context and a context that isn't "
1068 "the compile unit.");
1069 // FIXME: Do we want to use different scope/lines?
1070 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1071 auto *SP = getSubprogram(
1072 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
1073 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
1074 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
1075 nullptr, ThrownTypes, nullptr, "", IsDefinition && UseKeyInstructions);
1076
1077 AllSubprograms.push_back(SP);
1078 trackIfUnresolved(SP);
1079 return SP;
1080}
1081
1083 DIGlobalVariable *Decl,
1084 StringRef Name, DIFile *File,
1085 unsigned LineNo) {
1086 return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo);
1087}
1088
1090 bool ExportSymbols) {
1091
1092 // It is okay to *not* make anonymous top-level namespaces distinct, because
1093 // all nodes that have an anonymous namespace as their parent scope are
1094 // guaranteed to be unique and/or are linked to their containing
1095 // DICompileUnit. This decision is an explicit tradeoff of link time versus
1096 // memory usage versus code simplicity and may get revisited in the future.
1097 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
1098 ExportSymbols);
1099}
1100
1102 StringRef ConfigurationMacros,
1103 StringRef IncludePath, StringRef APINotesFile,
1104 DIFile *File, unsigned LineNo, bool IsDecl) {
1105 return DIModule::get(VMContext, File, getNonCompileUnitScope(Scope), Name,
1106 ConfigurationMacros, IncludePath, APINotesFile, LineNo,
1107 IsDecl);
1108}
1109
1111 DIFile *File,
1112 unsigned Discriminator) {
1113 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
1114}
1115
1117 unsigned Line, unsigned Col) {
1118 // Make these distinct, to avoid merging two lexical blocks on the same
1119 // file/line/column.
1120 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
1121 File, Line, Col);
1122}
1123
1125 DIExpression *Expr, const DILocation *DL,
1126 BasicBlock *InsertAtEnd) {
1127 // If this block already has a terminator then insert this intrinsic before
1128 // the terminator. Otherwise, put it at the end of the block.
1129 Instruction *InsertBefore = InsertAtEnd->getTerminator();
1130 return insertDeclare(Storage, VarInfo, Expr, DL,
1131 InsertBefore ? InsertBefore->getIterator()
1132 : InsertAtEnd->end());
1133}
1134
1136 DILocalVariable *SrcVar,
1137 DIExpression *ValExpr, Value *Addr,
1138 DIExpression *AddrExpr,
1139 const DILocation *DL) {
1140 auto *Link = cast_or_null<DIAssignID>(
1141 LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
1142 assert(Link && "Linked instruction must have DIAssign metadata attached");
1143
1145 Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1146 // Insert after LinkedInstr.
1147 BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1148 NextIt.setHeadBit(true);
1149 insertDbgVariableRecord(DVR, NextIt);
1150 return DVR;
1151}
1152
1153/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
1154/// This abstracts over the various ways to specify an insert position.
1155static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
1156 InsertPosition InsertPt) {
1157 Builder.SetInsertPoint(InsertPt.getBasicBlock(), InsertPt);
1158 Builder.SetCurrentDebugLocation(DL);
1159}
1160
1162 assert(V && "no value passed to dbg intrinsic");
1163 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
1164}
1165
1167 DILocalVariable *VarInfo,
1168 DIExpression *Expr,
1169 const DILocation *DL,
1170 InsertPosition InsertPt) {
1171 DbgVariableRecord *DVR =
1173 insertDbgVariableRecord(DVR, InsertPt);
1174 return DVR;
1175}
1176
1178 DIExpression *Expr, const DILocation *DL,
1179 InsertPosition InsertPt) {
1180 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
1181 assert(DL && "Expected debug loc");
1182 assert(DL->getScope()->getSubprogram() ==
1183 VarInfo->getScope()->getSubprogram() &&
1184 "Expected matching subprograms");
1185
1186 DbgVariableRecord *DVR =
1187 DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1188 insertDbgVariableRecord(DVR, InsertPt);
1189 return DVR;
1190}
1191
1193 DILocalVariable *VarInfo,
1194 DIExpression *Expr,
1195 const DILocation *DL,
1196 InsertPosition InsertPt) {
1197 assert(VarInfo &&
1198 "empty or invalid DILocalVariable* passed to dbg.declare_value");
1199 assert(DL && "Expected debug loc");
1200 assert(DL->getScope()->getSubprogram() ==
1201 VarInfo->getScope()->getSubprogram() &&
1202 "Expected matching subprograms");
1203
1204 DbgVariableRecord *DVR =
1205 DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
1206 insertDbgVariableRecord(DVR, InsertPt);
1207 return DVR;
1208}
1209
1210void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
1211 InsertPosition InsertPt) {
1212 assert(InsertPt.isValid());
1213 trackIfUnresolved(DVR->getVariable());
1214 trackIfUnresolved(DVR->getExpression());
1215 if (DVR->isDbgAssign())
1216 trackIfUnresolved(DVR->getAddressExpression());
1217
1218 auto *BB = InsertPt.getBasicBlock();
1219 BB->insertDbgRecordBefore(DVR, InsertPt);
1220}
1221
1222Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
1223 Value *V, DILocalVariable *VarInfo,
1224 DIExpression *Expr,
1225 const DILocation *DL,
1226 InsertPosition InsertPt) {
1227 assert(IntrinsicFn && "must pass a non-null intrinsic function");
1228 assert(V && "must pass a value to a dbg intrinsic");
1229 assert(VarInfo &&
1230 "empty or invalid DILocalVariable* passed to debug intrinsic");
1231 assert(DL && "Expected debug loc");
1232 assert(DL->getScope()->getSubprogram() ==
1233 VarInfo->getScope()->getSubprogram() &&
1234 "Expected matching subprograms");
1235
1236 trackIfUnresolved(VarInfo);
1237 trackIfUnresolved(Expr);
1238 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
1239 MetadataAsValue::get(VMContext, VarInfo),
1240 MetadataAsValue::get(VMContext, Expr)};
1241
1242 IRBuilder<> B(DL->getContext());
1243 initIRBuilder(B, DL, InsertPt);
1244 return B.CreateCall(IntrinsicFn, Args);
1245}
1246
1248 InsertPosition InsertPt) {
1249 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
1250 assert(DL && "Expected debug loc");
1251 assert(DL->getScope()->getSubprogram() ==
1252 LabelInfo->getScope()->getSubprogram() &&
1253 "Expected matching subprograms");
1254
1255 trackIfUnresolved(LabelInfo);
1256 DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1257 if (InsertPt.isValid()) {
1258 auto *BB = InsertPt.getBasicBlock();
1259 BB->insertDbgRecordBefore(DLR, InsertPt);
1260 }
1261 return DLR;
1262}
1263
1265 {
1267 N->replaceVTableHolder(VTableHolder);
1268 T = N.get();
1269 }
1270
1271 // If this didn't create a self-reference, just return.
1272 if (T != VTableHolder)
1273 return;
1274
1275 // Look for unresolved operands. T will drop RAUW support, orphaning any
1276 // cycles underneath it.
1277 if (T->isResolved())
1278 for (const MDOperand &O : T->operands())
1279 if (auto *N = dyn_cast_or_null<MDNode>(O))
1280 trackIfUnresolved(N);
1281}
1282
1283void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
1284 DINodeArray TParams) {
1285 {
1287 if (Elements)
1288 N->replaceElements(Elements);
1289 if (TParams)
1290 N->replaceTemplateParams(DITemplateParameterArray(TParams));
1291 T = N.get();
1292 }
1293
1294 // If T isn't resolved, there's no problem.
1295 if (!T->isResolved())
1296 return;
1297
1298 // If T is resolved, it may be due to a self-reference cycle. Track the
1299 // arrays explicitly if they're unresolved, or else the cycles will be
1300 // orphaned.
1301 if (Elements)
1302 trackIfUnresolved(Elements.get());
1303 if (TParams)
1304 trackIfUnresolved(TParams.get());
1305}
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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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 void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL, InsertPosition InsertPt)
Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
static Value * getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V)
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
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:53
ArrayRef - 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:483
LLVM_ABI void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
const Instruction * getTerminator() 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:233
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:1214
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 void finalize()
Construct any deferred debug info descriptors.
Definition DIBuilder.cpp:75
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 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="")
Create debugging information entry for a class.
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:54
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 DIFixedPointType * createRationalFixedPointType(StringRef Name, 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 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 DbgInstPtr insertDbgAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *SrcVar, DIExpression *ValExpr, Value *Addr, DIExpression *AddrExpr, const DILocation *DL)
Insert a new llvm.dbg.assign intrinsic call.
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, InsertPosition InsertPt)
Insert a new llvm.dbg.declare_value intrinsic call.
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 * 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="")
Create debugging information entry for an union.
LLVM_ABI DIMacroNodeArray getOrCreateMacroArray(ArrayRef< Metadata * > Elements)
Get a DIMacroNodeArray, create one if required.
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 DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, BasicBlock *InsertAtEnd)
Insert a new llvm.dbg.declare intrinsic call.
LLVM_ABI DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, InsertPosition InsertPt)
Insert a new llvm.dbg.value intrinsic call.
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 * 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 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 * createDecimalFixedPointType(StringRef Name, 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 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 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)
Create debugging information entry for a struct.
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:27
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 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 DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL, InsertPosition InsertPt)
Insert a new llvm.dbg.label intrinsic call.
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 DIFixedPointType * createBinaryFixedPointType(StringRef Name, 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 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 a language name and its version.
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
static 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).
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
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2787
bool isValid() const
Definition Instruction.h:62
BasicBlock * getBasicBlock()
Definition Instruction.h:63
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:318
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1080
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1580
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1584
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1572
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:1329
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:1319
Tracking metadata reference owned by Metadata.
Definition Metadata.h:902
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:614
Tuple of metadata.
Definition Metadata.h:1500
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1529
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:110
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:1760
LLVM_ABI void addOperand(MDNode *M)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:297
Typed tracking ref.
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:509
LLVM Value Representation.
Definition Value.h:75
self_iterator getIterator()
Definition ilist_node.h:123
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
Calculates the starting offsets for various sections within the .debug_names section.
Definition Dwarf.h:35
@ DW_MACINFO_undef
Definition Dwarf.h:818
@ DW_MACINFO_start_file
Definition Dwarf.h:819
@ DW_MACINFO_define
Definition Dwarf.h:817
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
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
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
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
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
PointerUnion< Instruction *, DbgRecord * > DbgInstPtr
Definition DIBuilder.h:44
#define N
A single checksum, represented by a Kind and a Value (a string).