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, DINodeArray Annotations) {
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 nullptr, nullptr, nullptr, nullptr, nullptr, Annotations);
632 trackIfUnresolved(R);
634 getSubprogramNodesTrackingVector(Context).emplace_back(R);
635 return R;
636}
637
639 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
640 Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
641 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
642 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
643 uint32_t NumExtraInhabitants, DINodeArray Annotations) {
644 auto *R = DICompositeType::get(
645 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
646 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
647 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
648 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
649 Annotations, Specification, NumExtraInhabitants);
650 trackIfUnresolved(R);
652 getSubprogramNodesTrackingVector(Context).emplace_back(R);
653 return R;
654}
655
657 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
658 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
659 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
660 DIType *VTableHolder, StringRef UniqueIdentifier, DIType *Specification,
661 uint32_t NumExtraInhabitants, DINodeArray Annotations) {
662 auto *R = DICompositeType::get(
663 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
664 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
665 Flags, Elements, RunTimeLang, /*EnumKind=*/std::nullopt, VTableHolder,
666 nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
667 Annotations, Specification, NumExtraInhabitants);
668 trackIfUnresolved(R);
670 getSubprogramNodesTrackingVector(Context).emplace_back(R);
671 return R;
672}
673
675 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
676 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
677 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier,
678 DINodeArray Annotations) {
679 auto *R = DICompositeType::get(
680 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
681 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
682 Elements, RunTimeLang, /*EnumKind=*/std::nullopt, nullptr, nullptr,
683 UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, nullptr,
685 trackIfUnresolved(R);
687 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
688 return R;
689}
690
693 unsigned LineNumber, uint64_t SizeInBits,
694 uint32_t AlignInBits, DINode::DIFlags Flags,
695 DIDerivedType *Discriminator, DINodeArray Elements,
696 StringRef UniqueIdentifier) {
697 auto *R = DICompositeType::get(
698 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
699 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
700 Elements, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr,
701 UniqueIdentifier, Discriminator);
702 trackIfUnresolved(R);
703 return R;
704}
705
707 DINode::DIFlags Flags,
708 unsigned CC) {
709 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
710}
711
713 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
714 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
715 DIType *UnderlyingType, unsigned RunTimeLang, StringRef UniqueIdentifier,
716 bool IsScoped, std::optional<uint32_t> EnumKind) {
717 auto *CTy = DICompositeType::get(
718 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
719 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
720 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
721 RunTimeLang, EnumKind, nullptr, nullptr, UniqueIdentifier);
723 getSubprogramNodesTrackingVector(Scope).emplace_back(CTy);
724 else
725 EnumTypes.emplace_back(CTy);
726 trackIfUnresolved(CTy);
727 return CTy;
728}
729
731 DIFile *File, unsigned LineNo,
732 uint64_t SizeInBits,
733 uint32_t AlignInBits, DIType *Ty) {
734 auto *R = DIDerivedType::get(VMContext, dwarf::DW_TAG_set_type, Name, File,
735 LineNo, getNonCompileUnitScope(Scope), Ty,
736 SizeInBits, AlignInBits, 0, std::nullopt,
737 std::nullopt, DINode::FlagZero);
738 trackIfUnresolved(R);
740 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
741 return R;
742}
743
746 DINodeArray Subscripts,
751 return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits,
752 Ty, Subscripts, DL, AS, AL, RK);
753}
754
756 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
757 uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
762 auto *R = DICompositeType::get(
763 VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
764 getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
765 Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
774 nullptr, nullptr, 0, BitStride);
775 trackIfUnresolved(R);
777 getSubprogramNodesTrackingVector(Scope).emplace_back(R);
778 return R;
779}
780
782 uint32_t AlignInBits, DIType *Ty,
783 DINodeArray Subscripts,
784 Metadata *BitStride) {
785 auto *R = DICompositeType::get(
786 VMContext, dwarf::DW_TAG_array_type, /*Name=*/"",
787 /*File=*/nullptr, /*Line=*/0, /*Scope=*/nullptr, /*BaseType=*/Ty,
788 /*SizeInBits=*/Size, /*AlignInBits=*/AlignInBits, /*OffsetInBits=*/0,
789 /*Flags=*/DINode::FlagVector, /*Elements=*/Subscripts,
790 /*RuntimeLang=*/0, /*EnumKind=*/std::nullopt, /*VTableHolder=*/nullptr,
791 /*TemplateParams=*/nullptr, /*Identifier=*/"",
792 /*Discriminator=*/nullptr, /*DataLocation=*/nullptr,
793 /*Associated=*/nullptr, /*Allocated=*/nullptr, /*Rank=*/nullptr,
794 /*Annotations=*/nullptr, /*Specification=*/nullptr,
795 /*NumExtraInhabitants=*/0,
796 /*BitStride=*/BitStride);
797 trackIfUnresolved(R);
798 return R;
799}
800
802 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
803 return MDNode::replaceWithDistinct(std::move(NewSP));
804}
805
807 DINode::DIFlags FlagsToSet) {
808 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
809 return MDNode::replaceWithUniqued(std::move(NewTy));
810}
811
813 // FIXME: Restrict this to the nodes where it's valid.
814 if (Ty->isArtificial())
815 return Ty;
816 return createTypeWithFlags(Ty, DINode::FlagArtificial);
817}
818
820 // FIXME: Restrict this to the nodes where it's valid.
821 if (Ty->isObjectPointer())
822 return Ty;
823 DINode::DIFlags Flags = DINode::FlagObjectPointer;
824
825 if (Implicit)
826 Flags |= DINode::FlagArtificial;
827
828 return createTypeWithFlags(Ty, Flags);
829}
830
832 assert(T && "Expected non-null type");
834 cast<DISubprogram>(T)->isDefinition() == false)) &&
835 "Expected type or subprogram declaration");
836 if (!isa_and_nonnull<DILocalScope>(T->getScope()))
837 AllRetainTypes.emplace_back(T);
838}
839
841
843 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
844 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
845 StringRef UniqueIdentifier, std::optional<uint32_t> EnumKind) {
846 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
847 // replaceWithUniqued().
848 auto *RetTy = DICompositeType::get(
849 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
850 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
851 /*EnumKind=*/EnumKind, nullptr, nullptr, UniqueIdentifier);
852 trackIfUnresolved(RetTy);
854 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
855 return RetTy;
856}
857
859 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
860 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
861 DINode::DIFlags Flags, StringRef UniqueIdentifier, DINodeArray Annotations,
862 std::optional<uint32_t> EnumKind) {
863 auto *RetTy =
865 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
866 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, EnumKind,
867 nullptr, nullptr, UniqueIdentifier, nullptr, nullptr, nullptr,
868 nullptr, nullptr, Annotations)
869 .release();
870 trackIfUnresolved(RetTy);
872 getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
873 return RetTy;
874}
875
877 return MDTuple::get(VMContext, Elements);
878}
879
880DIMacroNodeArray
882 return MDTuple::get(VMContext, Elements);
883}
884
887 for (Metadata *E : Elements) {
889 Elts.push_back(cast<DIType>(E));
890 else
891 Elts.push_back(E);
892 }
893 return DITypeArray(MDNode::get(VMContext, Elts));
894}
895
897 auto *LB = ConstantAsMetadata::get(
899 auto *CountNode = ConstantAsMetadata::get(
901 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
902}
903
905 auto *LB = ConstantAsMetadata::get(
907 return DISubrange::get(VMContext, CountNode, LB, nullptr, nullptr);
908}
909
911 Metadata *UB, Metadata *Stride) {
912 return DISubrange::get(VMContext, CountNode, LB, UB, Stride);
913}
914
918 auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * {
919 return isa<DIExpression *>(Bound) ? (Metadata *)cast<DIExpression *>(Bound)
920 : (Metadata *)cast<DIVariable *>(Bound);
921 };
922 return DIGenericSubrange::get(VMContext, ConvToMetadata(CountNode),
923 ConvToMetadata(LB), ConvToMetadata(UB),
924 ConvToMetadata(Stride));
925}
926
928 StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope,
929 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
930 DIType *Ty, Metadata *LowerBound, Metadata *UpperBound, Metadata *Stride,
931 Metadata *Bias) {
932 auto *T = DISubrangeType::get(VMContext, Name, File, LineNo, Scope,
933 SizeInBits, AlignInBits, Flags, Ty, LowerBound,
934 UpperBound, Stride, Bias);
936 getSubprogramNodesTrackingVector(Scope).emplace_back(T);
937 return T;
938}
939
940static void checkGlobalVariableScope(DIScope *Context) {
941#ifndef NDEBUG
942 if (auto *CT =
944 assert(CT->getIdentifier().empty() &&
945 "Context of a global variable should not be a type with identifier");
946#endif
947}
948
950 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
951 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined,
952 DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams,
953 uint32_t AlignInBits, DINodeArray Annotations) {
955
957 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
958 LineNumber, Ty, IsLocalToUnit, isDefined,
959 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
961 if (!Expr)
962 Expr = createExpression();
963 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
964 AllGVs.push_back(N);
965 return N;
966}
967
969 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
970 unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, MDNode *Decl,
971 MDTuple *TemplateParams, uint32_t AlignInBits) {
973
975 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
976 LineNumber, Ty, IsLocalToUnit, false,
977 cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits,
978 nullptr)
979 .release();
980}
981
983 LLVMContext &VMContext,
985 DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
986 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
987 uint32_t AlignInBits, DINodeArray Annotations = nullptr) {
988 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
989 // the only valid scopes)?
990 auto *Scope = cast<DILocalScope>(Context);
991 auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
992 ArgNo, Flags, AlignInBits, Annotations);
993 if (AlwaysPreserve) {
994 // The optimizer may remove local variables. If there is an interest
995 // to preserve variable info in such situation then stash it in a
996 // named mdnode.
997 PreservedNodes.emplace_back(Node);
998 }
999 return Node;
1000}
1001
1003 DIFile *File, unsigned LineNo,
1004 DIType *Ty, bool AlwaysPreserve,
1005 DINode::DIFlags Flags,
1006 uint32_t AlignInBits) {
1007 assert(Scope && isa<DILocalScope>(Scope) &&
1008 "Unexpected scope for a local variable.");
1009 return createLocalVariable(
1010 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name,
1011 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits);
1012}
1013
1015 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
1016 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
1017 DINodeArray Annotations) {
1018 assert(ArgNo && "Expected non-zero argument number for parameter");
1019 assert(Scope && isa<DILocalScope>(Scope) &&
1020 "Unexpected scope for a local variable.");
1021 return createLocalVariable(
1022 VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo,
1023 File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations);
1024}
1025
1027 unsigned LineNo, unsigned Column,
1028 bool IsArtificial,
1029 std::optional<unsigned> CoroSuspendIdx,
1030 bool AlwaysPreserve) {
1031 auto *Scope = cast<DILocalScope>(Context);
1032 auto *Node = DILabel::get(VMContext, Scope, Name, File, LineNo, Column,
1033 IsArtificial, CoroSuspendIdx);
1034
1035 if (AlwaysPreserve) {
1036 /// The optimizer may remove labels. If there is an interest
1037 /// to preserve label info in such situation then append it to
1038 /// the list of retained nodes of the DISubprogram.
1039 getSubprogramNodesTrackingVector(Scope).emplace_back(Node);
1040 }
1041 return Node;
1042}
1043
1047
1048template <class... Ts>
1049static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) {
1050 if (IsDistinct)
1051 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
1052 return DISubprogram::get(std::forward<Ts>(Args)...);
1053}
1054
1056 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1057 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1059 DITemplateParameterArray TParams, DISubprogram *Decl,
1060 DITypeArray ThrownTypes, DINodeArray Annotations, StringRef TargetFuncName,
1061 bool UseKeyInstructions) {
1062 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1063 auto *Node = getSubprogram(
1064 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
1065 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
1066 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr,
1067 ThrownTypes, Annotations, TargetFuncName, UseKeyInstructions);
1068
1069 AllSubprograms.push_back(Node);
1070 trackIfUnresolved(Node);
1071 return Node;
1072}
1073
1075 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
1076 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
1078 DITemplateParameterArray TParams, DISubprogram *Decl,
1079 DITypeArray ThrownTypes) {
1080 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1081 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
1082 Name, LinkageName, File, LineNo, Ty,
1083 ScopeLine, nullptr, 0, 0, Flags, SPFlags,
1084 IsDefinition ? CUNode : nullptr, TParams,
1085 Decl, nullptr, ThrownTypes)
1086 .release();
1087}
1088
1090 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
1091 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
1092 DIType *VTableHolder, DINode::DIFlags Flags,
1093 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
1094 DITypeArray ThrownTypes, bool UseKeyInstructions) {
1095 assert(getNonCompileUnitScope(Context) &&
1096 "Methods should have both a Context and a context that isn't "
1097 "the compile unit.");
1098 // FIXME: Do we want to use different scope/lines?
1099 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
1100 auto *SP = getSubprogram(
1101 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
1102 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
1103 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
1104 nullptr, ThrownTypes, nullptr, "", IsDefinition && UseKeyInstructions);
1105
1106 AllSubprograms.push_back(SP);
1107 trackIfUnresolved(SP);
1108 return SP;
1109}
1110
1112 DIGlobalVariable *Decl,
1113 StringRef Name, DIFile *File,
1114 unsigned LineNo) {
1115 return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo);
1116}
1117
1119 bool ExportSymbols) {
1120
1121 // It is okay to *not* make anonymous top-level namespaces distinct, because
1122 // all nodes that have an anonymous namespace as their parent scope are
1123 // guaranteed to be unique and/or are linked to their containing
1124 // DICompileUnit. This decision is an explicit tradeoff of link time versus
1125 // memory usage versus code simplicity and may get revisited in the future.
1126 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
1127 ExportSymbols);
1128}
1129
1131 StringRef ConfigurationMacros,
1132 StringRef IncludePath, StringRef APINotesFile,
1133 DIFile *File, unsigned LineNo, bool IsDecl) {
1134 return DIModule::get(VMContext, File, getNonCompileUnitScope(Scope), Name,
1135 ConfigurationMacros, IncludePath, APINotesFile, LineNo,
1136 IsDecl);
1137}
1138
1140 DIFile *File,
1141 unsigned Discriminator) {
1142 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
1143}
1144
1146 unsigned Line, unsigned Col) {
1147 // Make these distinct, to avoid merging two lexical blocks on the same
1148 // file/line/column.
1149 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
1150 File, Line, Col);
1151}
1152
1154 DIExpression *Expr, const DILocation *DL,
1155 BasicBlock *InsertAtEnd) {
1156 // If this block already has a terminator then insert this intrinsic before
1157 // the terminator. Otherwise, put it at the end of the block.
1158 Instruction *InsertBefore = InsertAtEnd->getTerminatorOrNull();
1159 return insertDeclare(Storage, VarInfo, Expr, DL,
1160 InsertBefore ? InsertBefore->getIterator()
1161 : InsertAtEnd->end());
1162}
1163
1165 DILocalVariable *SrcVar,
1166 DIExpression *ValExpr, Value *Addr,
1167 DIExpression *AddrExpr,
1168 const DILocation *DL) {
1169 auto *Link = cast_or_null<DIAssignID>(
1170 LinkedInstr->getMetadata(LLVMContext::MD_DIAssignID));
1171 assert(Link && "Linked instruction must have DIAssign metadata attached");
1172
1174 Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1175 // Insert after LinkedInstr.
1176 BasicBlock::iterator NextIt = std::next(LinkedInstr->getIterator());
1177 NextIt.setHeadBit(true);
1178 insertDbgVariableRecord(DVR, NextIt);
1179 return DVR;
1180}
1181
1182/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
1183/// This abstracts over the various ways to specify an insert position.
1184static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
1185 InsertPosition InsertPt) {
1186 Builder.SetInsertPoint(InsertPt.getBasicBlock(), InsertPt);
1187 Builder.SetCurrentDebugLocation(DL);
1188}
1189
1191 assert(V && "no value passed to dbg intrinsic");
1192 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
1193}
1194
1196 DILocalVariable *VarInfo,
1197 DIExpression *Expr,
1198 const DILocation *DL,
1199 InsertPosition InsertPt) {
1200 DbgVariableRecord *DVR =
1202 insertDbgVariableRecord(DVR, InsertPt);
1203 return DVR;
1204}
1205
1207 DIExpression *Expr, const DILocation *DL,
1208 InsertPosition InsertPt) {
1209 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
1210 assert(DL && "Expected debug loc");
1211 assert(DL->getScope()->getSubprogram() ==
1212 VarInfo->getScope()->getSubprogram() &&
1213 "Expected matching subprograms");
1214
1215 DbgVariableRecord *DVR =
1216 DbgVariableRecord::createDVRDeclare(Storage, VarInfo, Expr, DL);
1217 insertDbgVariableRecord(DVR, InsertPt);
1218 return DVR;
1219}
1220
1222 DILocalVariable *VarInfo,
1223 DIExpression *Expr,
1224 const DILocation *DL,
1225 InsertPosition InsertPt) {
1226 assert(VarInfo &&
1227 "empty or invalid DILocalVariable* passed to dbg.declare_value");
1228 assert(DL && "Expected debug loc");
1229 assert(DL->getScope()->getSubprogram() ==
1230 VarInfo->getScope()->getSubprogram() &&
1231 "Expected matching subprograms");
1232
1233 DbgVariableRecord *DVR =
1234 DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
1235 insertDbgVariableRecord(DVR, InsertPt);
1236 return DVR;
1237}
1238
1239void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
1240 InsertPosition InsertPt) {
1241 assert(InsertPt.isValid());
1242 trackIfUnresolved(DVR->getVariable());
1243 trackIfUnresolved(DVR->getExpression());
1244 if (DVR->isDbgAssign())
1245 trackIfUnresolved(DVR->getAddressExpression());
1246
1247 auto *BB = InsertPt.getBasicBlock();
1248 BB->insertDbgRecordBefore(DVR, InsertPt);
1249}
1250
1251Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
1252 Value *V, DILocalVariable *VarInfo,
1253 DIExpression *Expr,
1254 const DILocation *DL,
1255 InsertPosition InsertPt) {
1256 assert(IntrinsicFn && "must pass a non-null intrinsic function");
1257 assert(V && "must pass a value to a dbg intrinsic");
1258 assert(VarInfo &&
1259 "empty or invalid DILocalVariable* passed to debug intrinsic");
1260 assert(DL && "Expected debug loc");
1261 assert(DL->getScope()->getSubprogram() ==
1262 VarInfo->getScope()->getSubprogram() &&
1263 "Expected matching subprograms");
1264
1265 trackIfUnresolved(VarInfo);
1266 trackIfUnresolved(Expr);
1267 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
1268 MetadataAsValue::get(VMContext, VarInfo),
1269 MetadataAsValue::get(VMContext, Expr)};
1270
1271 IRBuilder<> B(DL->getContext());
1272 initIRBuilder(B, DL, InsertPt);
1273 return B.CreateCall(IntrinsicFn, Args);
1274}
1275
1277 InsertPosition InsertPt) {
1278 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
1279 assert(DL && "Expected debug loc");
1280 assert(DL->getScope()->getSubprogram() ==
1281 LabelInfo->getScope()->getSubprogram() &&
1282 "Expected matching subprograms");
1283
1284 trackIfUnresolved(LabelInfo);
1285 DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
1286 if (InsertPt.isValid()) {
1287 auto *BB = InsertPt.getBasicBlock();
1288 BB->insertDbgRecordBefore(DLR, InsertPt);
1289 }
1290 return DLR;
1291}
1292
1294 {
1296 N->replaceVTableHolder(VTableHolder);
1297 T = N.get();
1298 }
1299
1300 // If this didn't create a self-reference, just return.
1301 if (T != VTableHolder)
1302 return;
1303
1304 // Look for unresolved operands. T will drop RAUW support, orphaning any
1305 // cycles underneath it.
1306 if (T->isResolved())
1307 for (const MDOperand &O : T->operands())
1308 if (auto *N = dyn_cast_or_null<MDNode>(O))
1309 trackIfUnresolved(N);
1310}
1311
1312void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
1313 DINodeArray TParams) {
1314 {
1316 if (Elements)
1317 N->replaceElements(Elements);
1318 if (TParams)
1319 N->replaceTemplateParams(DITemplateParameterArray(TParams));
1320 T = N.get();
1321 }
1322
1323 // If T isn't resolved, there's no problem.
1324 if (!T->isResolved())
1325 return;
1326
1327 // If T is resolved, it may be due to a self-reference cycle. Track the
1328 // arrays explicitly if they're unresolved, or else the cycles will be
1329 // orphaned.
1330 if (Elements)
1331 trackIfUnresolved(Elements.get());
1332 if (TParams)
1333 trackIfUnresolved(TParams.get());
1334}
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
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:1257
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 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 DICompositeType * createUnionType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DINodeArray Elements, unsigned RunTimeLang=0, StringRef UniqueIdentifier="", DINodeArray Annotations=nullptr)
Create debugging information entry for an union.
LLVM_ABI DISubprogram * createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, unsigned VTableIndex=0, int ThisAdjustment=0, DIType *VTableHolder=nullptr, DINode::DIFlags Flags=DINode::FlagZero, DISubprogram::DISPFlags SPFlags=DISubprogram::SPFlagZero, DITemplateParameterArray TParams=nullptr, DITypeArray ThrownTypes=nullptr, bool UseKeyInstructions=false)
Create a new descriptor for the specified C++ method.
LLVM_ABI DINamespace * createNameSpace(DIScope *Scope, StringRef Name, bool ExportSymbols)
This creates new descriptor for a namespace with the specified parent scope.
LLVM_ABI DIStringType * createStringType(StringRef Name, uint64_t SizeInBits)
Create debugging information entry for a string type.
LLVM_ABI 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 * createStructType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, Metadata *SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang=0, DIType *VTableHolder=nullptr, StringRef UniqueIdentifier="", DIType *Specification=nullptr, uint32_t NumExtraInhabitants=0, DINodeArray Annotations=nullptr)
Create debugging information entry for a struct.
LLVM_ABI DIMacroNodeArray getOrCreateMacroArray(ArrayRef< Metadata * > Elements)
Get a DIMacroNodeArray, create one if required.
LLVM_ABI 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 * createClassType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang=0, DIType *VTableHolder=nullptr, MDNode *TemplateParms=nullptr, StringRef UniqueIdentifier="", DINodeArray Annotations=nullptr)
Create debugging information entry for a class.
LLVM_ABI DIFixedPointType * createRationalFixedPointType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DINode::DIFlags Flags, APInt Numerator, APInt Denominator)
Create debugging information entry for an arbitrary rational fixed-point type.
LLVM_ABI DICompositeType * createReplaceableCompositeType(unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, unsigned RuntimeLang=0, uint64_t SizeInBits=0, uint32_t AlignInBits=0, DINode::DIFlags Flags=DINode::FlagFwdDecl, StringRef UniqueIdentifier="", DINodeArray Annotations=nullptr, std::optional< uint32_t > EnumKind=std::nullopt)
Create a temporary forward-declared type.
LLVM_ABI DIFixedPointType * createDecimalFixedPointType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DINode::DIFlags Flags, int Factor)
Create debugging information entry for a decimal fixed-point type.
LLVM_ABI DITypeArray getOrCreateTypeArray(ArrayRef< Metadata * > Elements)
Get a DITypeArray, create one if required.
LLVM_ABI DICompositeType * createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, DIType *UnderlyingType, unsigned RunTimeLang=0, StringRef UniqueIdentifier="", bool IsScoped=false, std::optional< uint32_t > EnumKind=std::nullopt)
Create debugging information entry for an enumeration.
LLVM_ABI DIFixedPointType * createBinaryFixedPointType(StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, DINode::DIFlags Flags, int Factor)
Create debugging information entry for a binary fixed-point type.
LLVM_ABI 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 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:2858
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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).