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, nullptr, 0,
280 nullptr, SizeInBits, 0, Encoding, NumExtraInhabitants,
281 DataSizeInBits, Flags);
282}
283
285 unsigned LineNo, DIScope *Context,
286 uint64_t SizeInBits, unsigned Encoding,
287 DINode::DIFlags Flags,
288 uint32_t NumExtraInhabitants,
289 uint32_t DataSizeInBits) {
290 auto *R = DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, File,
291 LineNo, Context, SizeInBits, 0, Encoding,
292 NumExtraInhabitants, DataSizeInBits, Flags);
294 getSubprogramNodesTrackingVector(Context).emplace_back(R);
295 trackIfUnresolved(R);
296 return R;
297}
298
300 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context,
301 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
302 DINode::DIFlags Flags, int Factor) {
303 auto *R = DIFixedPointType::get(
304 VMContext, dwarf::DW_TAG_base_type, Name, File, LineNo, Context,
305 SizeInBits, AlignInBits, Encoding, Flags,
308 getSubprogramNodesTrackingVector(Context).emplace_back(R);
309 trackIfUnresolved(R);
310 return R;
311}
312
314 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context,
315 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
316 DINode::DIFlags Flags, int Factor) {
317 auto *R = DIFixedPointType::get(
318 VMContext, dwarf::DW_TAG_base_type, Name, File, LineNo, Context,
319 SizeInBits, AlignInBits, Encoding, Flags,
322 getSubprogramNodesTrackingVector(Context).emplace_back(R);
323 trackIfUnresolved(R);
324 return R;
325}
326
328 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context,
329 uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding,
330 DINode::DIFlags Flags, APInt Numerator, APInt Denominator) {
331 auto *R = DIFixedPointType::get(
332 VMContext, dwarf::DW_TAG_base_type, Name, File, LineNo, Context,
333 SizeInBits, AlignInBits, Encoding, Flags,
334 DIFixedPointType::FixedPointRational, 0, Numerator, Denominator);
336 getSubprogramNodesTrackingVector(Context).emplace_back(R);
337 trackIfUnresolved(R);
338 return R;
339}
340
342 assert(!Name.empty() && "Unable to create type without name");
343 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
344 SizeInBits, 0);
345}
346
348 DIVariable *StringLength,
349 DIExpression *StrLocationExp) {
350 assert(!Name.empty() && "Unable to create type without name");
351 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
352 StringLength, nullptr, StrLocationExp, 0, 0, 0);
353}
354
356 DIExpression *StringLengthExp,
357 DIExpression *StrLocationExp) {
358 assert(!Name.empty() && "Unable to create type without name");
359 return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name, nullptr,
360 StringLengthExp, StrLocationExp, 0, 0, 0);
361}
362
364 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy,
365 (uint64_t)0, 0, (uint64_t)0, std::nullopt,
366 std::nullopt, DINode::FlagZero);
367}
368
370 DIType *FromTy, unsigned Key, bool IsAddressDiscriminated,
371 unsigned ExtraDiscriminator, bool IsaPointer,
372 bool AuthenticatesNullValues) {
373 return DIDerivedType::get(
374 VMContext, dwarf::DW_TAG_LLVM_ptrauth_type, "", nullptr, 0, nullptr,
375 FromTy, (uint64_t)0, 0, (uint64_t)0, std::nullopt,
376 std::optional<DIDerivedType::PtrAuthData>(
377 std::in_place, Key, IsAddressDiscriminated, ExtraDiscriminator,
378 IsaPointer, AuthenticatesNullValues),
379 DINode::FlagZero);
380}
381
384 uint32_t AlignInBits,
385 std::optional<unsigned> DWARFAddressSpace,
386 StringRef Name, DINodeArray Annotations) {
387 // FIXME: Why is there a name here?
388 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
389 nullptr, 0, nullptr, PointeeTy, SizeInBits,
390 AlignInBits, 0, DWARFAddressSpace, std::nullopt,
391 DINode::FlagZero, nullptr, Annotations);
392}
393
395 DIType *Base,
396 uint64_t SizeInBits,
397 uint32_t AlignInBits,
398 DINode::DIFlags Flags) {
399 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
400 nullptr, 0, nullptr, PointeeTy, SizeInBits,
401 AlignInBits, 0, std::nullopt, std::nullopt, Flags,
402 Base);
403}
404
407 uint32_t AlignInBits,
408 std::optional<unsigned> DWARFAddressSpace) {
409 assert(RTy && "Unable to create reference type");
410 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
411 SizeInBits, AlignInBits, 0, DWARFAddressSpace, {},
412 DINode::FlagZero);
413}
414
416 DIFile *File, unsigned LineNo,
417 DIScope *Context, uint32_t AlignInBits,
418 DINode::DIFlags Flags,
419 DINodeArray Annotations) {
420 auto *T = DIDerivedType::get(
421 VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo,
422 getNonCompileUnitScope(Context), Ty, (uint64_t)0, AlignInBits,
423 (uint64_t)0, std::nullopt, std::nullopt, Flags, nullptr, Annotations);
425 getSubprogramNodesTrackingVector(Context).emplace_back(T);
426 return T;
427}
428
431 unsigned LineNo, DIScope *Context,
432 DINodeArray TParams, uint32_t AlignInBits,
433 DINode::DIFlags Flags, DINodeArray Annotations) {
434 auto *T =
435 DIDerivedType::get(VMContext, dwarf::DW_TAG_template_alias, Name, File,
436 LineNo, getNonCompileUnitScope(Context), Ty,
437 (uint64_t)0, AlignInBits, (uint64_t)0, std::nullopt,
438 std::nullopt, Flags, TParams.get(), Annotations);
440 getSubprogramNodesTrackingVector(Context).emplace_back(T);
441 return T;
442}
443
445 assert(Ty && "Invalid type!");
446 assert(FriendTy && "Invalid friend type!");
447 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
448 FriendTy, (uint64_t)0, 0, (uint64_t)0, std::nullopt,
449 std::nullopt, DINode::FlagZero);
450}
451
453 uint64_t BaseOffset,
454 uint32_t VBPtrOffset,
455 DINode::DIFlags Flags) {
456 assert(Ty && "Unable to create inheritance");
458 ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
459 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
460 0, Ty, BaseTy, 0, 0, BaseOffset, std::nullopt,
461 std::nullopt, Flags, ExtraData);
462}
463
465 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
466 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
467 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
468 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
469 LineNumber, getNonCompileUnitScope(Scope), Ty,
470 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
471 std::nullopt, Flags, nullptr, Annotations);
472}
473
475 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
476 Metadata *SizeInBits, uint32_t AlignInBits, Metadata *OffsetInBits,
477 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
478 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
479 LineNumber, getNonCompileUnitScope(Scope), Ty,
480 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
481 std::nullopt, Flags, nullptr, Annotations);
482}
483
485 if (C)
487 return nullptr;
488}
489
491 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
492 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
493 Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
494 // "ExtraData" is overloaded for bit fields and for variants, so
495 // make sure to disallow this.
496 assert((Flags & DINode::FlagBitField) == 0);
497 return DIDerivedType::get(
498 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
499 getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits,
500 std::nullopt, std::nullopt, Flags, getConstantOrNull(Discriminant));
501}
502
504 DINodeArray Elements,
505 Constant *Discriminant,
506 DIType *Ty) {
507 auto *V = DICompositeType::get(VMContext, dwarf::DW_TAG_variant, {}, nullptr,
508 0, getNonCompileUnitScope(Scope), {},
509 (uint64_t)0, 0, (uint64_t)0, DINode::FlagZero,
510 Elements, 0, {}, nullptr);
511
512 trackIfUnresolved(V);
513 return createVariantMemberType(Scope, {}, nullptr, 0, 0, 0, 0, Discriminant,
514 DINode::FlagZero, V);
515}
516
518 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
519 Metadata *SizeInBits, Metadata *OffsetInBits, uint64_t StorageOffsetInBits,
520 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
521 Flags |= DINode::FlagBitField;
522 return DIDerivedType::get(
523 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
524 getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
525 OffsetInBits, std::nullopt, std::nullopt, Flags,
526 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
527 StorageOffsetInBits)),
529}
530
532 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
533 uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
534 DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) {
535 Flags |= DINode::FlagBitField;
536 return DIDerivedType::get(
537 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
538 getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0,
539 OffsetInBits, std::nullopt, std::nullopt, Flags,
540 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
541 StorageOffsetInBits)),
543}
544
547 unsigned LineNumber, DIType *Ty,
549 unsigned Tag, uint32_t AlignInBits) {
550 Flags |= DINode::FlagStaticMember;
551 return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
552 getNonCompileUnitScope(Scope), Ty, (uint64_t)0,
553 AlignInBits, (uint64_t)0, std::nullopt,
554 std::nullopt, Flags, getConstantOrNull(Val));
555}
556
558DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber,
559 uint64_t SizeInBits, uint32_t AlignInBits,
560 uint64_t OffsetInBits, DINode::DIFlags Flags,
561 DIType *Ty, MDNode *PropertyNode) {
562 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
563 LineNumber, getNonCompileUnitScope(File), Ty,
564 SizeInBits, AlignInBits, OffsetInBits, std::nullopt,
565 std::nullopt, Flags, PropertyNode);
566}
567
569DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
570 StringRef GetterName, StringRef SetterName,
571 unsigned PropertyAttributes, DIType *Ty) {
572 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
573 SetterName, PropertyAttributes, Ty);
574}
575
578 DIType *Ty, bool isDefault) {
579 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
580 return DITemplateTypeParameter::get(VMContext, Name, Ty, isDefault);
581}
582
585 DIScope *Context, StringRef Name, DIType *Ty,
586 bool IsDefault, Metadata *MD) {
587 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
588 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, IsDefault, MD);
589}
590
593 DIType *Ty, bool isDefault,
594 Constant *Val) {
596 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
597 isDefault, getConstantOrNull(Val));
598}
599
602 DIType *Ty, StringRef Val,
603 bool IsDefault) {
605 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
606 IsDefault, MDString::get(VMContext, Val));
607}
608
611 DIType *Ty, DINodeArray Val) {
613 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
614 false, Val.get());
615}
616
618 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
619 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
620 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
621 unsigned RunTimeLang, DIType *VTableHolder, MDNode *TemplateParams,
622 StringRef UniqueIdentifier) {
623 assert((!Context || isa<DIScope>(Context)) &&
624 "createClassType should be called with a valid Context");
625
626 auto *R = DICompositeType::get(
627 VMContext, dwarf::DW_TAG_class_type, Name, File, LineNumber,
628 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
629 OffsetInBits, Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt,
630 VTableHolder, cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
631 trackIfUnresolved(R);
633 getSubprogramNodesTrackingVector(Context).emplace_back(R);
634 return R;
635}
636
638 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
639 Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
640 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
641 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
642 uint32_t NumExtraInhabitants) {
643 auto *R = DICompositeType::get(
644 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
645 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
646 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
647 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
648 nullptr, Specification, NumExtraInhabitants);
649 trackIfUnresolved(R);
651 getSubprogramNodesTrackingVector(Context).emplace_back(R);
652 return R;
653}
654
656 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
657 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
658 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
659 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
660 uint32_t NumExtraInhabitants) {
661 auto *R = DICompositeType::get(
662 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
663 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
664 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
665 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
666 nullptr, Specification, NumExtraInhabitants);
667 trackIfUnresolved(R);
669 getSubprogramNodesTrackingVector(Context).emplace_back(R);
670 return R;
671}
672
674 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
675 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
676 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
677 auto *R = DICompositeType::get(
678 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
679 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
680 Elements, RunTimeLang, /*EnumKind=*/std::nullopt, nullptr, nullptr,
681 UniqueIdentifier);
682 trackIfUnresolved(R);
684 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
685 return R;
686}
687
690 unsigned LineNumber, uint64_t SizeInBits,
691 uint32_t AlignInBits, DINode::DIFlags Flags,
692 DIDerivedType *Discriminator, DINodeArray Elements,
693 StringRef UniqueIdentifier) {
694 auto *R = DICompositeType::get(
695 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
696 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
697 Elements, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr,
698 UniqueIdentifier, Discriminator);
699 trackIfUnresolved(R);
700 return R;
701}
702
704 DINode::DIFlags Flags,
705 unsigned CC) {
706 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
707}
708
710 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
711 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
712 DIType *UnderlyingType, unsigned RunTimeLang, StringRef UniqueIdentifier,
713 bool IsScoped, std::optional<uint32_t> EnumKind) {
714 auto *CTy = DICompositeType::get(
715 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
716 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
717 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
718 RunTimeLang, EnumKind, nullptr, nullptr, UniqueIdentifier);
720 getSubprogramNodesTrackingVector(Scope).emplace_back(CTy);
721 else
722 EnumTypes.emplace_back(CTy);
723 trackIfUnresolved(CTy);
724 return CTy;
725}
726
728 DIFile *File, unsigned LineNo,
729 uint64_t SizeInBits,
730 uint32_t AlignInBits, DIType *Ty) {
731 auto *R = DIDerivedType::get(VMContext, dwarf::DW_TAG_set_type, Name, File,
732 LineNo, getNonCompileUnitScope(Scope), Ty,
733 SizeInBits, AlignInBits, 0, std::nullopt,
734 std::nullopt, DINode::FlagZero);
735 trackIfUnresolved(R);
737 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
738 return R;
739}
740
743 DINodeArray Subscripts,
748 return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits,
749 Ty, Subscripts, DL, AS, AL, RK);
750}
751
753 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
754 uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
759 auto *R = DICompositeType::get(
760 VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
761 getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
762 Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
771 nullptr, nullptr, 0, BitStride);
772 trackIfUnresolved(R);
774 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
775 return R;
776}
777
779 uint32_t AlignInBits, DIType *Ty,
780 DINodeArray Subscripts,
781 Metadata *BitStride) {
782 auto *R = DICompositeType::get(
783 VMContext, dwarf::DW_TAG_array_type, /*Name=*/"",
784 /*File=*/nullptr, /*Line=*/0, /*Scope=*/nullptr, /*BaseType=*/Ty,
785 /*SizeInBits=*/Size, /*AlignInBits=*/AlignInBits, /*OffsetInBits=*/0,
786 /*Flags=*/DINode::FlagVector, /*Elements=*/Subscripts,
787 /*RuntimeLang=*/0, /*EnumKind=*/std::nullopt, /*VTableHolder=*/nullptr,
788 /*TemplateParams=*/nullptr, /*Identifier=*/"",
789 /*Discriminator=*/nullptr, /*DataLocation=*/nullptr,
790 /*Associated=*/nullptr, /*Allocated=*/nullptr, /*Rank=*/nullptr,
791 /*Annotations=*/nullptr, /*Specification=*/nullptr,
792 /*NumExtraInhabitants=*/0,
793 /*BitStride=*/BitStride);
794 trackIfUnresolved(R);
795 return R;
796}
797
799 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
800 return MDNode::replaceWithDistinct(std::move(NewSP));
801}
802
804 DINode::DIFlags FlagsToSet) {
805 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
806 return MDNode::replaceWithUniqued(std::move(NewTy));
807}
808
810 // FIXME: Restrict this to the nodes where it's valid.
811 if (Ty->isArtificial())
812 return Ty;
813 return createTypeWithFlags(Ty, DINode::FlagArtificial);
814}
815
817 // FIXME: Restrict this to the nodes where it's valid.
818 if (Ty->isObjectPointer())
819 return Ty;
820 DINode::DIFlags Flags = DINode::FlagObjectPointer;
821
822 if (Implicit)
823 Flags |= DINode::FlagArtificial;
824
825 return createTypeWithFlags(Ty, Flags);
826}
827
829 assert(T && "Expected non-null type");
831 cast<DISubprogram>(T)->isDefinition() == false)) &&
832 "Expected type or subprogram declaration");
833 if (!isa_and_nonnull<DILocalScope>(T->getScope()))
834 AllRetainTypes.emplace_back(T);
835}
836
838
840 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
841 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
842 StringRef UniqueIdentifier, std::optional<uint32_t> EnumKind) {
843 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
844 // replaceWithUniqued().
845 auto *RetTy = DICompositeType::get(
846 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
847 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
848 /*EnumKind=*/EnumKind, nullptr, nullptr, UniqueIdentifier);
849 trackIfUnresolved(RetTy);
851 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
852 return RetTy;
853}
854
856 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
857 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
858 DINode::DIFlags Flags, StringRef UniqueIdentifier, DINodeArray Annotations,
859 std::optional<uint32_t> EnumKind) {
860 auto *RetTy =
862 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
863 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, EnumKind,
864 nullptr, nullptr, UniqueIdentifier, nullptr, nullptr, nullptr,
865 nullptr, nullptr, Annotations)
866 .release();
867 trackIfUnresolved(RetTy);
869 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
870 return RetTy;
871}
872
874 return MDTuple::get(VMContext, Elements);
875}
876
877DIMacroNodeArray
879 return MDTuple::get(VMContext, Elements);
880}
881
884 for (Metadata *E : Elements) {
886 Elts.push_back(cast<DIType>(E));
887 else
888 Elts.push_back(E);
889 }
890 return DITypeArray(MDNode::get(VMContext, Elts));
891}
892
894 auto *LB = ConstantAsMetadata::get(
896 auto *CountNode = ConstantAsMetadata::get(
898 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
899}
900
902 auto *LB = ConstantAsMetadata::get(
904 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
905}
906
908 Metadata *UB, Metadata *Stride) {
909 return DISubrange::get(VMContext, CountNode, LB, UB, Stride);
910}
911
915 auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * {
916 return isa<DIExpression *>(Bound) ? (Metadata *)cast<DIExpression *>(Bound)
917 : (Metadata *)cast<DIVariable *>(Bound);
918 };
919 return DIGenericSubrange::get(VMContext, ConvToMetadata(CountNode),
920 ConvToMetadata(LB), ConvToMetadata(UB),
921 ConvToMetadata(Stride));
922}
923
925 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope,
926 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
927 DIType *Ty, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride,
928 Metadata *Bias) {
929 auto *T = DISubrangeType::get(VMContext, Name, File, LineNo, Scope,
930 SizeInBits, AlignInBits, Flags, Ty, LowerBound,
931 UpperBound, Stride, Bias);
933 getSubprogramNodesTrackingVector(Scope).emplace_back(T);
934 return T;
935}
936
937static void checkGlobalVariableScope(DIScope *Context) {
938#ifndef NDEBUG
939 if (auto *CT =
941 assert(CT->getIdentifier().empty() &&
942 "Context of a global variable should not be a type with identifier");
943#endif
944}
945
947 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
948 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined,
949 DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams,
950 uint32_t AlignInBits, DINodeArray Annotations) {
952
954 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
955 LineNumber, Ty, IsLocalToUnit, isDefined,
956 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
958 if (!Expr)
959 Expr = createExpression();
960 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
961 AllGVs.push_back(N);
962 return N;
963}
964
966 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
967 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, MDNode *Decl,
968 MDTuple *TemplateParams, uint32_t AlignInBits) {
970
972 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
973 LineNumber, Ty, IsLocalToUnit, false,
974 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
975 nullptr)
976 .release();
977}
978
980 LLVMContext &VMContext,
982 DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
983 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
984 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
985 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
986 // the only valid scopes)?
987 auto *Scope = cast<DILocalScope>(Context);
988 auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
989 ArgNo, Flags, AlignInBits, Annotations);
990 if (AlwaysPreserve) {
991 // The optimizer may remove local variables. If there is an interest
992 // to preserve variable info in such situation then stash it in a
993 // named mdnode.
994 PreservedNodes.emplace_back(Node);
995 }
996 return Node;
997}
998
1000 DIFile *File, unsigned LineNo,
1001 DIType *Ty, bool AlwaysPreserve,
1002 DINode::DIFlags Flags,
1003 uint32_t AlignInBits) {
1004 assert(Scope && isa<DILocalScope>(Scope) &&
1005 "Unexpected scope for a local variable.");
1006 return createLocalVariable(
1007 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
1008 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
1009}
1010
1012 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
1013 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
1014 DINodeArray Annotations) {
1015 assert(ArgNo && "Expected non-zero argument number for parameter");
1016 assert(Scope && isa<DILocalScope>(Scope) &&
1017 "Unexpected scope for a local variable.");
1018 return createLocalVariable(
1019 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
1020 File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
1021}
1022
1024 unsigned LineNo, unsigned Column,
1025 bool IsArtificial,
1026 std::optional<unsigned> CoroSuspendIdx,
1027 bool AlwaysPreserve) {
1028 auto *Scope = cast<DILocalScope>(Context);
1029 auto *Node = DILabel::get(VMContext, Scope, Name, File, LineNo, Column,
1030 IsArtificial, CoroSuspendIdx);
1031
1032 if (AlwaysPreserve) {
1033 /// The optimizer may remove labels. If there is an interest
1034 /// to preserve label info in such situation then append it to
1035 /// the list of retained nodes of the DISubprogram.
1036 getSubprogramNodesTrackingVector(Scope).emplace_back(Node);
1037 }
1038 return Node;
1039}
1040
1044
1045template <class... Ts>
1046static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) {
1047 if (IsDistinct)
1048 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
1049 return DISubprogram::get(std::forward<Ts>(Args)...);
1050}
1051
1053 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1054 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1056 DITemplateParameterArray TParams, DISubprogram *Decl,
1057 DITypeArray ThrownTypes, DINodeArray Annotations, StringRef TargetFuncName,
1058 bool UseKeyInstructions) {
1059 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1060 auto *Node = getSubprogram(
1061 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
1062 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
1063 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr,
1064 ThrownTypes, Annotations, TargetFuncName, UseKeyInstructions);
1065
1066 AllSubprograms.push_back(Node);
1067 trackIfUnresolved(Node);
1068 return Node;
1069}
1070
1072 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1073 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1075 DITemplateParameterArray TParams, DISubprogram *Decl,
1076 DITypeArray ThrownTypes) {
1077 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1078 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
1079 Name, LinkageName, File, LineNo, Ty,
1080 ScopeLine, nullptr, 0, 0, Flags, SPFlags,
1081 IsDefinition ? CUNode : nullptr, TParams,
1082 Decl, nullptr, ThrownTypes)
1083 .release();
1084}
1085
1087 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
1088 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
1089 DIType *VTableHolder, DINode::DIFlags Flags,
1090 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
1091 DITypeArray ThrownTypes, bool UseKeyInstructions) {
1092 assert(getNonCompileUnitScope(Context) &&
1093 "Methods should have both a Context and a context that isn't "
1094 "the compile unit.");
1095 // FIXME: Do we want to use different scope/lines?
1096 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1097 auto *SP = getSubprogram(
1098 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
1099 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
1100 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
1101 nullptr, ThrownTypes, nullptr, "", IsDefinition && UseKeyInstructions);
1102
1103 AllSubprograms.push_back(SP);
1104 trackIfUnresolved(SP);
1105 return SP;
1106}
1107
1109 DIGlobalVariable *Decl,
1110 StringRef Name, DIFile *File,
1111 unsigned LineNo) {
1112 return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo);
1113}
1114
1116 bool ExportSymbols) {
1117
1118 // It is okay to *not* make anonymous top-level namespaces distinct, because
1119 // all nodes that have an anonymous namespace as their parent scope are
1120 // guaranteed to be unique and/or are linked to their containing
1121 // DICompileUnit. This decision is an explicit tradeoff of link time versus
1122 // memory usage versus code simplicity and may get revisited in the future.
1123 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
1124 ExportSymbols);
1125}
1126
1128 StringRef ConfigurationMacros,
1129 StringRef IncludePath, StringRef APINotesFile,
1130 DIFile *File, unsigned LineNo, bool IsDecl) {
1131 return DIModule::get(VMContext, File, getNonCompileUnitScope(Scope), Name,
1132 ConfigurationMacros, IncludePath, APINotesFile, LineNo,
1133 IsDecl);
1134}
1135
1137 DIFile *File,
1138 unsigned Discriminator) {
1139 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
1140}
1141
1143 unsigned Line, unsigned Col) {
1144 // Make these distinct, to avoid merging two lexical blocks on the same
1145 // file/line/column.
1146 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
1147 File, Line, Col);
1148}
1149
1151 DIExpression *Expr, const DILocation *DL,
1152 BasicBlock *InsertAtEnd) {
1153 // If this block already has a terminator then insert this intrinsic before
1154 // the terminator. Otherwise, put it at the end of the block.
1155 Instruction *InsertBefore = InsertAtEnd->getTerminatorOrNull();
1156 return insertDeclare(Storage, VarInfo, Expr, DL,
1157 InsertBefore ? InsertBefore->getIterator()
1158 : InsertAtEnd->end());
1159}
1160
1162 DILocalVariable *SrcVar,
1163 DIExpression *ValExpr, Value *Addr,
1164 DIExpression *AddrExpr,
1165 const DILocation *DL) {
1166 auto *Link = cast_or_null<DIAssignID>(
1167 LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
1168 assert(Link && "Linked instruction must have DIAssign metadata attached");
1169
1171 Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1172 // Insert after LinkedInstr.
1173 BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1174 NextIt.setHeadBit(true);
1175 insertDbgVariableRecord(DVR, NextIt);
1176 return DVR;
1177}
1178
1179/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
1180/// This abstracts over the various ways to specify an insert position.
1181static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
1182 InsertPosition InsertPt) {
1183 Builder.SetInsertPoint(InsertPt.getBasicBlock(), InsertPt);
1184 Builder.SetCurrentDebugLocation(DL);
1185}
1186
1188 assert(V && "no value passed to dbg intrinsic");
1189 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
1190}
1191
1193 DILocalVariable *VarInfo,
1194 DIExpression *Expr,
1195 const DILocation *DL,
1196 InsertPosition InsertPt) {
1197 DbgVariableRecord *DVR =
1199 insertDbgVariableRecord(DVR, InsertPt);
1200 return DVR;
1201}
1202
1204 DIExpression *Expr, const DILocation *DL,
1205 InsertPosition InsertPt) {
1206 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
1207 assert(DL && "Expected debug loc");
1208 assert(DL->getScope()->getSubprogram() ==
1209 VarInfo->getScope()->getSubprogram() &&
1210 "Expected matching subprograms");
1211
1212 DbgVariableRecord *DVR =
1213 DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1214 insertDbgVariableRecord(DVR, InsertPt);
1215 return DVR;
1216}
1217
1219 DILocalVariable *VarInfo,
1220 DIExpression *Expr,
1221 const DILocation *DL,
1222 InsertPosition InsertPt) {
1223 assert(VarInfo &&
1224 "empty or invalid DILocalVariable* passed to dbg.declare_value");
1225 assert(DL && "Expected debug loc");
1226 assert(DL->getScope()->getSubprogram() ==
1227 VarInfo->getScope()->getSubprogram() &&
1228 "Expected matching subprograms");
1229
1230 DbgVariableRecord *DVR =
1231 DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
1232 insertDbgVariableRecord(DVR, InsertPt);
1233 return DVR;
1234}
1235
1236void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
1237 InsertPosition InsertPt) {
1238 assert(InsertPt.isValid());
1239 trackIfUnresolved(DVR->getVariable());
1240 trackIfUnresolved(DVR->getExpression());
1241 if (DVR->isDbgAssign())
1242 trackIfUnresolved(DVR->getAddressExpression());
1243
1244 auto *BB = InsertPt.getBasicBlock();
1245 BB->insertDbgRecordBefore(DVR, InsertPt);
1246}
1247
1248Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
1249 Value *V, DILocalVariable *VarInfo,
1250 DIExpression *Expr,
1251 const DILocation *DL,
1252 InsertPosition InsertPt) {
1253 assert(IntrinsicFn && "must pass a non-null intrinsic function");
1254 assert(V && "must pass a value to a dbg intrinsic");
1255 assert(VarInfo &&
1256 "empty or invalid DILocalVariable* passed to debug intrinsic");
1257 assert(DL && "Expected debug loc");
1258 assert(DL->getScope()->getSubprogram() ==
1259 VarInfo->getScope()->getSubprogram() &&
1260 "Expected matching subprograms");
1261
1262 trackIfUnresolved(VarInfo);
1263 trackIfUnresolved(Expr);
1264 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
1265 MetadataAsValue::get(VMContext, VarInfo),
1266 MetadataAsValue::get(VMContext, Expr)};
1267
1268 IRBuilder<> B(DL->getContext());
1269 initIRBuilder(B, DL, InsertPt);
1270 return B.CreateCall(IntrinsicFn, Args);
1271}
1272
1274 InsertPosition InsertPt) {
1275 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
1276 assert(DL && "Expected debug loc");
1277 assert(DL->getScope()->getSubprogram() ==
1278 LabelInfo->getScope()->getSubprogram() &&
1279 "Expected matching subprograms");
1280
1281 trackIfUnresolved(LabelInfo);
1282 DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1283 if (InsertPt.isValid()) {
1284 auto *BB = InsertPt.getBasicBlock();
1285 BB->insertDbgRecordBefore(DLR, InsertPt);
1286 }
1287 return DLR;
1288}
1289
1291 {
1293 N->replaceVTableHolder(VTableHolder);
1294 T = N.get();
1295 }
1296
1297 // If this didn't create a self-reference, just return.
1298 if (T != VTableHolder)
1299 return;
1300
1301 // Look for unresolved operands. T will drop RAUW support, orphaning any
1302 // cycles underneath it.
1303 if (T->isResolved())
1304 for (const MDOperand &O : T->operands())
1305 if (auto *N = dyn_cast_or_null<MDNode>(O))
1306 trackIfUnresolved(N);
1307}
1308
1309void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
1310 DINodeArray TParams) {
1311 {
1313 if (Elements)
1314 N->replaceElements(Elements);
1315 if (TParams)
1316 N->replaceTemplateParams(DITemplateParameterArray(TParams));
1317 T = N.get();
1318 }
1319
1320 // If T isn't resolved, there's no problem.
1321 if (!T->isResolved())
1322 return;
1323
1324 // If T is resolved, it may be due to a self-reference cycle. Track the
1325 // arrays explicitly if they're unresolved, or else the cycles will be
1326 // orphaned.
1327 if (Elements)
1328 trackIfUnresolved(Elements.get());
1329 if (TParams)
1330 trackIfUnresolved(TParams.get());
1331}
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:474
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:1247
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 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 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 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 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:2847
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:354
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 bits of the poi...
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:314
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.
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).