LLVM  8.0.1
DIBuilder.cpp
Go to the documentation of this file.
1 //===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the DIBuilder.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/IR/DIBuilder.h"
15 #include "llvm/IR/IRBuilder.h"
16 #include "LLVMContextImpl.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DebugInfo.h"
22 #include "llvm/IR/IntrinsicInst.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/Support/Debug.h"
25 
26 using namespace llvm;
27 using namespace llvm::dwarf;
28 
30  UseDbgAddr("use-dbg-addr",
31  llvm::cl::desc("Use llvm.dbg.addr for all local variables"),
32  cl::init(false), cl::Hidden);
33 
34 DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
35  : M(m), VMContext(M.getContext()), CUNode(CU),
36  DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr),
37  AllowUnresolvedNodes(AllowUnresolvedNodes) {}
38 
39 void DIBuilder::trackIfUnresolved(MDNode *N) {
40  if (!N)
41  return;
42  if (N->isResolved())
43  return;
44 
45  assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
46  UnresolvedNodes.emplace_back(N);
47 }
48 
50  MDTuple *Temp = SP->getRetainedNodes().get();
51  if (!Temp || !Temp->isTemporary())
52  return;
53 
54  SmallVector<Metadata *, 16> RetainedNodes;
55 
56  auto PV = PreservedVariables.find(SP);
57  if (PV != PreservedVariables.end())
58  RetainedNodes.append(PV->second.begin(), PV->second.end());
59 
60  auto PL = PreservedLabels.find(SP);
61  if (PL != PreservedLabels.end())
62  RetainedNodes.append(PL->second.begin(), PL->second.end());
63 
64  DINodeArray Node = getOrCreateArray(RetainedNodes);
65 
66  TempMDTuple(Temp)->replaceAllUsesWith(Node.get());
67 }
68 
70  if (!CUNode) {
71  assert(!AllowUnresolvedNodes &&
72  "creating type nodes without a CU is not supported");
73  return;
74  }
75 
76  CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
77 
78  SmallVector<Metadata *, 16> RetainValues;
79  // Declarations and definitions of the same type may be retained. Some
80  // clients RAUW these pairs, leaving duplicates in the retained types
81  // list. Use a set to remove the duplicates while we transform the
82  // TrackingVHs back into Values.
84  for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
85  if (RetainSet.insert(AllRetainTypes[I]).second)
86  RetainValues.push_back(AllRetainTypes[I]);
87 
88  if (!RetainValues.empty())
89  CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
90 
91  DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
92  for (auto *SP : SPs)
94  for (auto *N : RetainValues)
95  if (auto *SP = dyn_cast<DISubprogram>(N))
97 
98  if (!AllGVs.empty())
99  CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
100 
101  if (!AllImportedModules.empty())
103  VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
104  AllImportedModules.end())));
105 
106  for (const auto &I : AllMacrosPerParent) {
107  // DIMacroNode's with nullptr parent are DICompileUnit direct children.
108  if (!I.first) {
109  CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
110  continue;
111  }
112  // Otherwise, it must be a temporary DIMacroFile that need to be resolved.
113  auto *TMF = cast<DIMacroFile>(I.first);
114  auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file,
115  TMF->getLine(), TMF->getFile(),
116  getOrCreateMacroArray(I.second.getArrayRef()));
117  replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
118  }
119 
120  // Now that all temp nodes have been replaced or deleted, resolve remaining
121  // cycles.
122  for (const auto &N : UnresolvedNodes)
123  if (N && !N->isResolved())
124  N->resolveCycles();
125  UnresolvedNodes.clear();
126 
127  // Can't handle unresolved nodes anymore.
128  AllowUnresolvedNodes = false;
129 }
130 
131 /// If N is compile unit return NULL otherwise return N.
133  if (!N || isa<DICompileUnit>(N))
134  return nullptr;
135  return cast<DIScope>(N);
136 }
137 
139  unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
140  StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
141  DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
142  bool SplitDebugInlining, bool DebugInfoForProfiling,
143  DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress) {
144 
145  assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
146  (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
147  "Invalid Language tag");
148 
149  assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
151  VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
152  SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
153  SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
154  RangesBaseAddress);
155 
156  // Create a named metadata so that it is easier to find cu in a module.
157  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
158  NMD->addOperand(CUNode);
159  trackIfUnresolved(CUNode);
160  return CUNode;
161 }
162 
163 static DIImportedEntity *
165  Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
166  SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
167  if (Line)
168  assert(File && "Source location has line number but no file");
169  unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
170  auto *M =
171  DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name);
172  if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
173  // A new Imported Entity was just added to the context.
174  // Add it to the Imported Modules list.
175  AllImportedModules.emplace_back(M);
176  return M;
177 }
178 
180  DINamespace *NS, DIFile *File,
181  unsigned Line) {
182  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
183  Context, NS, File, Line, StringRef(),
184  AllImportedModules);
185 }
186 
188  DIImportedEntity *NS,
189  DIFile *File, unsigned Line) {
190  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
191  Context, NS, File, Line, StringRef(),
192  AllImportedModules);
193 }
194 
196  DIFile *File, unsigned Line) {
197  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
198  Context, M, File, Line, StringRef(),
199  AllImportedModules);
200 }
201 
203  DINode *Decl,
204  DIFile *File,
205  unsigned Line,
206  StringRef Name) {
207  // Make sure to use the unique identifier based metadata reference for
208  // types that have one.
209  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
210  Context, Decl, File, Line, Name,
211  AllImportedModules);
212 }
213 
217  return DIFile::get(VMContext, Filename, Directory, CS, Source);
218 }
219 
220 DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
221  unsigned MacroType, StringRef Name,
222  StringRef Value) {
223  assert(!Name.empty() && "Unable to create macro without name");
224  assert((MacroType == dwarf::DW_MACINFO_undef ||
225  MacroType == dwarf::DW_MACINFO_define) &&
226  "Unexpected macro type");
227  auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
228  AllMacrosPerParent[Parent].insert(M);
229  return M;
230 }
231 
233  unsigned LineNumber, DIFile *File) {
235  LineNumber, File, DIMacroNodeArray())
236  .release();
237  AllMacrosPerParent[Parent].insert(MF);
238  // Add the new temporary DIMacroFile to the macro per parent map as a parent.
239  // This is needed to assure DIMacroFile with no children to have an entry in
240  // the map. Otherwise, it will not be resolved in DIBuilder::finalize().
241  AllMacrosPerParent.insert({MF, {}});
242  return MF;
243 }
244 
246  bool IsUnsigned) {
247  assert(!Name.empty() && "Unable to create enumerator without name");
248  return DIEnumerator::get(VMContext, Val, IsUnsigned, Name);
249 }
250 
252  assert(!Name.empty() && "Unable to create type without name");
253  return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
254 }
255 
257  return createUnspecifiedType("decltype(nullptr)");
258 }
259 
261  unsigned Encoding,
262  DINode::DIFlags Flags) {
263  assert(!Name.empty() && "Unable to create type without name");
264  return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
265  0, Encoding, Flags);
266 }
267 
269  return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
270  0, 0, None, DINode::FlagZero);
271 }
272 
274  DIType *PointeeTy,
275  uint64_t SizeInBits,
276  uint32_t AlignInBits,
277  Optional<unsigned> DWARFAddressSpace,
278  StringRef Name) {
279  // FIXME: Why is there a name here?
280  return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
281  nullptr, 0, nullptr, PointeeTy, SizeInBits,
282  AlignInBits, 0, DWARFAddressSpace,
283  DINode::FlagZero);
284 }
285 
287  DIType *Base,
288  uint64_t SizeInBits,
289  uint32_t AlignInBits,
290  DINode::DIFlags Flags) {
291  return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
292  nullptr, 0, nullptr, PointeeTy, SizeInBits,
293  AlignInBits, 0, None, Flags, Base);
294 }
295 
297  unsigned Tag, DIType *RTy,
298  uint64_t SizeInBits,
299  uint32_t AlignInBits,
300  Optional<unsigned> DWARFAddressSpace) {
301  assert(RTy && "Unable to create reference type");
302  return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
303  SizeInBits, AlignInBits, 0, DWARFAddressSpace,
304  DINode::FlagZero);
305 }
306 
308  DIFile *File, unsigned LineNo,
309  DIScope *Context) {
310  return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
311  LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
312  0, None, DINode::FlagZero);
313 }
314 
316  assert(Ty && "Invalid type!");
317  assert(FriendTy && "Invalid friend type!");
318  return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
319  FriendTy, 0, 0, 0, None, DINode::FlagZero);
320 }
321 
323  uint64_t BaseOffset,
324  uint32_t VBPtrOffset,
325  DINode::DIFlags Flags) {
326  assert(Ty && "Unable to create inheritance");
327  Metadata *ExtraData = ConstantAsMetadata::get(
328  ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
329  return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
330  0, Ty, BaseTy, 0, 0, BaseOffset, None,
331  Flags, ExtraData);
332 }
333 
335  DIFile *File, unsigned LineNumber,
336  uint64_t SizeInBits,
337  uint32_t AlignInBits,
338  uint64_t OffsetInBits,
339  DINode::DIFlags Flags, DIType *Ty) {
340  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
341  LineNumber, getNonCompileUnitScope(Scope), Ty,
342  SizeInBits, AlignInBits, OffsetInBits, None, Flags);
343 }
344 
346  if (C)
347  return ConstantAsMetadata::get(C);
348  return nullptr;
349 }
350 
352  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
353  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
354  Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
355  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
356  LineNumber, getNonCompileUnitScope(Scope), Ty,
357  SizeInBits, AlignInBits, OffsetInBits, None, Flags,
358  getConstantOrNull(Discriminant));
359 }
360 
362  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
363  uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
364  DINode::DIFlags Flags, DIType *Ty) {
365  Flags |= DINode::FlagBitField;
366  return DIDerivedType::get(
367  VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
368  getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
369  OffsetInBits, None, Flags,
371  StorageOffsetInBits)));
372 }
373 
376  unsigned LineNumber, DIType *Ty,
377  DINode::DIFlags Flags, llvm::Constant *Val,
378  uint32_t AlignInBits) {
379  Flags |= DINode::FlagStaticMember;
380  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
381  LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
382  AlignInBits, 0, None, Flags,
383  getConstantOrNull(Val));
384 }
385 
388  uint64_t SizeInBits, uint32_t AlignInBits,
389  uint64_t OffsetInBits, DINode::DIFlags Flags,
390  DIType *Ty, MDNode *PropertyNode) {
391  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
392  LineNumber, getNonCompileUnitScope(File), Ty,
393  SizeInBits, AlignInBits, OffsetInBits, None, Flags,
394  PropertyNode);
395 }
396 
399  StringRef GetterName, StringRef SetterName,
400  unsigned PropertyAttributes, DIType *Ty) {
401  return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
402  SetterName, PropertyAttributes, Ty);
403 }
404 
407  DIType *Ty) {
408  assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
409  return DITemplateTypeParameter::get(VMContext, Name, Ty);
410 }
411 
415  Metadata *MD) {
416  assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
417  return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
418 }
419 
422  DIType *Ty, Constant *Val) {
424  VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
425  getConstantOrNull(Val));
426 }
427 
430  DIType *Ty, StringRef Val) {
432  VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
433  MDString::get(VMContext, Val));
434 }
435 
438  DIType *Ty, DINodeArray Val) {
440  VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
441  Val.get());
442 }
443 
445  DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
446  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
447  DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
448  DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
449  assert((!Context || isa<DIScope>(Context)) &&
450  "createClassType should be called with a valid Context");
451 
452  auto *R = DICompositeType::get(
453  VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
454  getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
455  OffsetInBits, Flags, Elements, 0, VTableHolder,
456  cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
457  trackIfUnresolved(R);
458  return R;
459 }
460 
462  DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
463  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
464  DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
465  DIType *VTableHolder, StringRef UniqueIdentifier) {
466  auto *R = DICompositeType::get(
467  VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
468  getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
469  Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
470  trackIfUnresolved(R);
471  return R;
472 }
473 
475  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
476  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
477  DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
478  auto *R = DICompositeType::get(
479  VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
480  getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
481  Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
482  trackIfUnresolved(R);
483  return R;
484 }
485 
487  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
488  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
489  DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) {
490  auto *R = DICompositeType::get(
491  VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
492  getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
493  Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator);
494  trackIfUnresolved(R);
495  return R;
496 }
497 
499  DINode::DIFlags Flags,
500  unsigned CC) {
501  return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
502 }
503 
505  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
506  uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
507  DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsScoped) {
508  auto *CTy = DICompositeType::get(
509  VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
510  getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
511  IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr,
512  nullptr, UniqueIdentifier);
513  AllEnumTypes.push_back(CTy);
514  trackIfUnresolved(CTy);
515  return CTy;
516 }
517 
519  uint32_t AlignInBits, DIType *Ty,
520  DINodeArray Subscripts) {
521  auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
522  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
523  DINode::FlagZero, Subscripts, 0, nullptr);
524  trackIfUnresolved(R);
525  return R;
526 }
527 
529  uint32_t AlignInBits, DIType *Ty,
530  DINodeArray Subscripts) {
531  auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
532  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
533  DINode::FlagVector, Subscripts, 0, nullptr);
534  trackIfUnresolved(R);
535  return R;
536 }
537 
539  auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
540  return MDNode::replaceWithDistinct(std::move(NewSP));
541 }
542 
544  DINode::DIFlags FlagsToSet) {
545  auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
546  return MDNode::replaceWithUniqued(std::move(NewTy));
547 }
548 
550  // FIXME: Restrict this to the nodes where it's valid.
551  if (Ty->isArtificial())
552  return Ty;
553  return createTypeWithFlags(Ty, DINode::FlagArtificial);
554 }
555 
557  // FIXME: Restrict this to the nodes where it's valid.
558  if (Ty->isObjectPointer())
559  return Ty;
560  DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
561  return createTypeWithFlags(Ty, Flags);
562 }
563 
565  assert(T && "Expected non-null type");
566  assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
567  cast<DISubprogram>(T)->isDefinition() == false)) &&
568  "Expected type or subprogram declaration");
569  AllRetainTypes.emplace_back(T);
570 }
571 
573 
576  DIFile *F, unsigned Line, unsigned RuntimeLang,
577  uint64_t SizeInBits, uint32_t AlignInBits,
578  StringRef UniqueIdentifier) {
579  // FIXME: Define in terms of createReplaceableForwardDecl() by calling
580  // replaceWithUniqued().
581  auto *RetTy = DICompositeType::get(
582  VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
583  SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
584  nullptr, nullptr, UniqueIdentifier);
585  trackIfUnresolved(RetTy);
586  return RetTy;
587 }
588 
590  unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
591  unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
592  DINode::DIFlags Flags, StringRef UniqueIdentifier) {
593  auto *RetTy =
595  VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
596  SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
597  nullptr, UniqueIdentifier)
598  .release();
599  trackIfUnresolved(RetTy);
600  return RetTy;
601 }
602 
604  return MDTuple::get(VMContext, Elements);
605 }
606 
607 DIMacroNodeArray
609  return MDTuple::get(VMContext, Elements);
610 }
611 
614  for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
615  if (Elements[i] && isa<MDNode>(Elements[i]))
616  Elts.push_back(cast<DIType>(Elements[i]));
617  else
618  Elts.push_back(Elements[i]);
619  }
620  return DITypeRefArray(MDNode::get(VMContext, Elts));
621 }
622 
623 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
624  return DISubrange::get(VMContext, Count, Lo);
625 }
626 
628  return DISubrange::get(VMContext, CountNode, Lo);
629 }
630 
632 #ifndef NDEBUG
633  if (auto *CT =
634  dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
635  assert(CT->getIdentifier().empty() &&
636  "Context of a global variable should not be a type with identifier");
637 #endif
638 }
639 
642  unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
643  MDNode *Decl, MDTuple *templateParams, uint32_t AlignInBits) {
644  checkGlobalVariableScope(Context);
645 
647  VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
648  LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
649  templateParams, AlignInBits);
650  if (!Expr)
651  Expr = createExpression();
652  auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
653  AllGVs.push_back(N);
654  return N;
655 }
656 
659  unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl,
660  MDTuple *templateParams, uint32_t AlignInBits) {
661  checkGlobalVariableScope(Context);
662 
664  VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
665  LineNumber, Ty, isLocalToUnit, false,
666  cast_or_null<DIDerivedType>(Decl), templateParams, AlignInBits)
667  .release();
668 }
669 
671  LLVMContext &VMContext,
672  DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
673  DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
674  unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
675  uint32_t AlignInBits) {
676  // FIXME: Why getNonCompileUnitScope()?
677  // FIXME: Why is "!Context" okay here?
678  // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
679  // the only valid scopes)?
681 
682  auto *Node =
683  DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
684  File, LineNo, Ty, ArgNo, Flags, AlignInBits);
685  if (AlwaysPreserve) {
686  // The optimizer may remove local variables. If there is an interest
687  // to preserve variable info in such situation then stash it in a
688  // named mdnode.
689  DISubprogram *Fn = getDISubprogram(Scope);
690  assert(Fn && "Missing subprogram for local variable");
691  PreservedVariables[Fn].emplace_back(Node);
692  }
693  return Node;
694 }
695 
697  DIFile *File, unsigned LineNo,
698  DIType *Ty, bool AlwaysPreserve,
699  DINode::DIFlags Flags,
700  uint32_t AlignInBits) {
701  return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
702  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
703  Flags, AlignInBits);
704 }
705 
707  DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
708  unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
709  assert(ArgNo && "Expected non-zero argument number for parameter");
710  return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
711  File, LineNo, Ty, AlwaysPreserve, Flags,
712  /* AlignInBits */0);
713 }
714 
716  DIScope *Scope, StringRef Name, DIFile *File,
717  unsigned LineNo, bool AlwaysPreserve) {
719 
720  auto *Node =
721  DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
722  File, LineNo);
723 
724  if (AlwaysPreserve) {
725  /// The optimizer may remove labels. If there is an interest
726  /// to preserve label info in such situation then append it to
727  /// the list of retained nodes of the DISubprogram.
728  DISubprogram *Fn = getDISubprogram(Scope);
729  assert(Fn && "Missing subprogram for label");
730  PreservedLabels[Fn].emplace_back(Node);
731  }
732  return Node;
733 }
734 
736  return DIExpression::get(VMContext, Addr);
737 }
738 
740  // TODO: Remove the callers of this signed version and delete.
741  SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
742  return createExpression(Addr);
743 }
744 
745 template <class... Ts>
746 static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
747  if (IsDistinct)
748  return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
749  return DISubprogram::get(std::forward<Ts>(Args)...);
750 }
751 
754  unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
756  DITemplateParameterArray TParams, DISubprogram *Decl,
757  DITypeArray ThrownTypes) {
758  bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
759  auto *Node = getSubprogram(
760  /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
761  Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
762  SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl,
763  MDTuple::getTemporary(VMContext, None).release(), ThrownTypes);
764 
765  if (IsDefinition)
766  AllSubprograms.push_back(Node);
767  trackIfUnresolved(Node);
768  return Node;
769 }
770 
773  unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
775  DITemplateParameterArray TParams, DISubprogram *Decl,
776  DITypeArray ThrownTypes) {
777  bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
778  return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
779  Name, LinkageName, File, LineNo, Ty,
780  ScopeLine, nullptr, 0, 0, Flags, SPFlags,
781  IsDefinition ? CUNode : nullptr, TParams,
782  Decl, nullptr, ThrownTypes)
783  .release();
784 }
785 
788  unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
789  DIType *VTableHolder, DINode::DIFlags Flags,
790  DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
791  DITypeArray ThrownTypes) {
792  assert(getNonCompileUnitScope(Context) &&
793  "Methods should have both a Context and a context that isn't "
794  "the compile unit.");
795  // FIXME: Do we want to use different scope/lines?
796  bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
797  auto *SP = getSubprogram(
798  /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
799  LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
800  Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
801  nullptr, ThrownTypes);
802 
803  if (IsDefinition)
804  AllSubprograms.push_back(SP);
805  trackIfUnresolved(SP);
806  return SP;
807 }
808 
810  bool ExportSymbols) {
811 
812  // It is okay to *not* make anonymous top-level namespaces distinct, because
813  // all nodes that have an anonymous namespace as their parent scope are
814  // guaranteed to be unique and/or are linked to their containing
815  // DICompileUnit. This decision is an explicit tradeoff of link time versus
816  // memory usage versus code simplicity and may get revisited in the future.
817  return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
818  ExportSymbols);
819 }
820 
822  StringRef ConfigurationMacros,
823  StringRef IncludePath,
824  StringRef ISysRoot) {
825  return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
826  ConfigurationMacros, IncludePath, ISysRoot);
827 }
828 
830  DIFile *File,
831  unsigned Discriminator) {
832  return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
833 }
834 
836  unsigned Line, unsigned Col) {
837  // Make these distinct, to avoid merging two lexical blocks on the same
838  // file/line/column.
839  return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
840  File, Line, Col);
841 }
842 
843 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
844  DIExpression *Expr, const DILocation *DL,
845  Instruction *InsertBefore) {
846  return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
847  InsertBefore);
848 }
849 
850 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
851  DIExpression *Expr, const DILocation *DL,
852  BasicBlock *InsertAtEnd) {
853  // If this block already has a terminator then insert this intrinsic before
854  // the terminator. Otherwise, put it at the end of the block.
855  Instruction *InsertBefore = InsertAtEnd->getTerminator();
856  return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
857 }
858 
859 Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
860  Instruction *InsertBefore) {
861  return insertLabel(
862  LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
863  InsertBefore);
864 }
865 
866 Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
867  BasicBlock *InsertAtEnd) {
868  return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr);
869 }
870 
871 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
872  DILocalVariable *VarInfo,
873  DIExpression *Expr,
874  const DILocation *DL,
875  Instruction *InsertBefore) {
876  return insertDbgValueIntrinsic(
877  V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
878  InsertBefore);
879 }
880 
881 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
882  DILocalVariable *VarInfo,
883  DIExpression *Expr,
884  const DILocation *DL,
885  BasicBlock *InsertAtEnd) {
886  return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
887 }
888 
889 /// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
890 /// abstracts over the various ways to specify an insert position.
892  BasicBlock *InsertBB,
893  Instruction *InsertBefore) {
894  IRBuilder<> B(DL->getContext());
895  if (InsertBefore)
896  B.SetInsertPoint(InsertBefore);
897  else if (InsertBB)
898  B.SetInsertPoint(InsertBB);
899  B.SetCurrentDebugLocation(DL);
900  return B;
901 }
902 
904  assert(V && "no value passed to dbg intrinsic");
905  return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
906 }
907 
911 }
912 
913 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
914  DIExpression *Expr, const DILocation *DL,
915  BasicBlock *InsertBB, Instruction *InsertBefore) {
916  assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
917  assert(DL && "Expected debug loc");
918  assert(DL->getScope()->getSubprogram() ==
919  VarInfo->getScope()->getSubprogram() &&
920  "Expected matching subprograms");
921  if (!DeclareFn)
922  DeclareFn = getDeclareIntrin(M);
923 
924  trackIfUnresolved(VarInfo);
925  trackIfUnresolved(Expr);
926  Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
927  MetadataAsValue::get(VMContext, VarInfo),
928  MetadataAsValue::get(VMContext, Expr)};
929 
930  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
931  return B.CreateCall(DeclareFn, Args);
932 }
933 
934 Instruction *DIBuilder::insertDbgValueIntrinsic(
935  Value *V, DILocalVariable *VarInfo, DIExpression *Expr,
936  const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
937  assert(V && "no value passed to dbg.value");
938  assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
939  assert(DL && "Expected debug loc");
940  assert(DL->getScope()->getSubprogram() ==
941  VarInfo->getScope()->getSubprogram() &&
942  "Expected matching subprograms");
943  if (!ValueFn)
945 
946  trackIfUnresolved(VarInfo);
947  trackIfUnresolved(Expr);
948  Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
949  MetadataAsValue::get(VMContext, VarInfo),
950  MetadataAsValue::get(VMContext, Expr)};
951 
952  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
953  return B.CreateCall(ValueFn, Args);
954 }
955 
956 Instruction *DIBuilder::insertLabel(
957  DILabel *LabelInfo, const DILocation *DL,
958  BasicBlock *InsertBB, Instruction *InsertBefore) {
959  assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
960  assert(DL && "Expected debug loc");
961  assert(DL->getScope()->getSubprogram() ==
962  LabelInfo->getScope()->getSubprogram() &&
963  "Expected matching subprograms");
964  if (!LabelFn)
966 
967  trackIfUnresolved(LabelInfo);
968  Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
969 
970  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
971  return B.CreateCall(LabelFn, Args);
972 }
973 
975  DIType *VTableHolder) {
976  {
978  N->replaceVTableHolder(VTableHolder);
979  T = N.get();
980  }
981 
982  // If this didn't create a self-reference, just return.
983  if (T != VTableHolder)
984  return;
985 
986  // Look for unresolved operands. T will drop RAUW support, orphaning any
987  // cycles underneath it.
988  if (T->isResolved())
989  for (const MDOperand &O : T->operands())
990  if (auto *N = dyn_cast_or_null<MDNode>(O))
991  trackIfUnresolved(N);
992 }
993 
994 void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
995  DINodeArray TParams) {
996  {
998  if (Elements)
999  N->replaceElements(Elements);
1000  if (TParams)
1001  N->replaceTemplateParams(DITemplateParameterArray(TParams));
1002  T = N.get();
1003  }
1004 
1005  // If T isn't resolved, there's no problem.
1006  if (!T->isResolved())
1007  return;
1008 
1009  // If T is resolved, it may be due to a self-reference cycle. Track the
1010  // arrays explicitly if they're unresolved, or else the cycles will be
1011  // orphaned.
1012  if (Elements)
1013  trackIfUnresolved(Elements.get());
1014  if (TParams)
1015  trackIfUnresolved(TParams.get());
1016 }
void finalize()
Construct any deferred debug info descriptors.
Definition: DIBuilder.cpp:69
DIFlags getFlags() const
bool isObjectPointer() const
uint64_t CallInst * C
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:711
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1133
DIDerivedType * createPointerType(DIType *PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits=0, Optional< unsigned > DWARFAddressSpace=None, StringRef Name="")
Create debugging information entry for a pointer.
Definition: DIBuilder.cpp:273
static Value * getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V)
Definition: DIBuilder.cpp:903
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
iterator begin() const
Definition: ArrayRef.h:137
void replaceTemplateParams(DITemplateParameterArray TemplateParams)
DINamespace * createNameSpace(DIScope *Scope, StringRef Name, bool ExportSymbols)
This creates new descriptor for a namespace with the specified parent scope.
Definition: DIBuilder.cpp:809
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:454
DIDerivedType * createBitFieldMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty)
Create debugging information entry for a bit field member.
Definition: DIBuilder.cpp:361
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.
Definition: DIBuilder.cpp:474
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...
Definition: DIBuilder.cpp:322
void addOperand(MDNode *M)
Definition: Metadata.cpp:1087
DICompositeType * createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts)
Create debugging information entry for an array.
Definition: DIBuilder.cpp:518
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="")
Create a temporary forward-declared type.
Definition: DIBuilder.cpp:589
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:261
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, DIType *VTableHolder=nullptr, MDNode *TemplateParms=nullptr, StringRef UniqueIdentifier="")
Create debugging information entry for a class.
Definition: DIBuilder.cpp:444
DISubrange * getOrCreateSubrange(int64_t Lo, int64_t Count)
Create a descriptor for a value range.
Definition: DIBuilder.cpp:623
Metadata node.
Definition: Metadata.h:864
F(f)
DIMacro * createMacro(DIMacroFile *Parent, unsigned Line, unsigned MacroType, StringRef Name, StringRef Value=StringRef())
Create debugging information entry for a macro.
Definition: DIBuilder.cpp:220
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)
Create a new descriptor for the specified subprogram.
Definition: DIBuilder.cpp:752
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:138
void replaceArrays(DICompositeType *&T, DINodeArray Elements, DINodeArray TParams=DINodeArray())
Replace arrays on a composite type.
Definition: DIBuilder.cpp:994
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="")
Create a permanent forward-declared type.
Definition: DIBuilder.cpp:575
DIDerivedType * createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, DIType *Ty, DINode::DIFlags Flags, Constant *Val, uint32_t AlignInBits=0)
Create debugging information entry for a C++ static data member.
Definition: DIBuilder.cpp:375
DILabel * createLabel(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, bool AlwaysPreserve=false)
Create a new descriptor for an label.
Definition: DIBuilder.cpp:715
static DIType * createObjectPointerType(DIType *Ty)
Create a uniqued clone of Ty with FlagObjectPointer and FlagArtificial set.
Definition: DIBuilder.cpp:556
DIImportedEntity * createImportedModule(DIScope *Context, DINamespace *NS, DIFile *File, unsigned Line)
Create a descriptor for an imported module.
Definition: DIBuilder.cpp:179
DIMacroNodeArray getOrCreateMacroArray(ArrayRef< Metadata *> Elements)
Get a DIMacroNodeArray, create one if required.
Definition: DIBuilder.cpp:608
DIDerivedType * createMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DINode::DIFlags Flags, DIType *Ty)
Create debugging information entry for a member.
Definition: DIBuilder.cpp:334
Tuple of metadata.
Definition: Metadata.h:1106
Tagged DWARF-like metadata node.
void replaceRetainedTypes(DITypeArray N)
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
Definition: Metadata.h:994
DILexicalBlockFile * createLexicalBlockFile(DIScope *Scope, DIFile *File, unsigned Discriminator=0)
This creates a descriptor for a lexical block with a new file attached.
Definition: DIBuilder.cpp:829
DIGlobalVariableExpression * createGlobalVariableExpression(DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DIType *Ty, bool isLocalToUnit, DIExpression *Expr=nullptr, MDNode *Decl=nullptr, MDTuple *templateParams=nullptr, uint32_t AlignInBits=0)
Create a new descriptor for the specified variable.
Definition: DIBuilder.cpp:640
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, SmallVectorImpl< TrackingMDNodeRef > &AllImportedModules)
Definition: DIBuilder.cpp:164
A tuple of MDNodes.
Definition: Metadata.h:1326
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static Function * getDeclareIntrin(Module &M)
Definition: DIBuilder.cpp:908
DITemplateTypeParameter * createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty)
Create debugging information for template type parameter.
Definition: DIBuilder.cpp:406
bool isResolved() const
Check if node is fully resolved.
Definition: Metadata.h:940
Array subrange.
DIDerivedType * createTypedef(DIType *Ty, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context)
Create debugging information entry for a typedef.
Definition: DIBuilder.cpp:307
DIBasicType * createUnspecifiedType(StringRef Name)
Create a DWARF unspecified type.
Definition: DIBuilder.cpp:251
DIMacroFile * createTempMacroFile(DIMacroFile *Parent, unsigned Line, DIFile *File)
Create debugging information temporary entry for a macro file.
Definition: DIBuilder.cpp:232
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
DISubroutineType * createSubroutineType(DITypeRefArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
Definition: DIBuilder.cpp:498
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:743
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1178
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:44
void resolveCycles()
Resolve cycles.
Definition: Metadata.cpp:621
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.
Definition: DIBuilder.cpp:351
Subprogram description.
op_range operands() const
Definition: Metadata.h:1067
LLVMContext & getContext() const
Definition: Metadata.h:924
Enumeration value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
DIEnumerator * createEnumerator(StringRef Name, int64_t Val, bool IsUnsigned=false)
Create a single enumerator value.
Definition: DIBuilder.cpp:245
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Debug location.
TempDIType cloneWithFlags(DIFlags NewFlags) const
Returns a new temporary DIType with updated Flags.
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:410
static IRBuilder getIRBForDbgInsertion(const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore)
Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics.
Definition: DIBuilder.cpp:891
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1020
DIBasicType * createNullPtrType()
Create C++11 nullptr type.
Definition: DIBuilder.cpp:256
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata *> Elements)
Get a DITypeRefArray, create one if required.
Definition: DIBuilder.cpp:612
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:106
void replaceVTableHolder(DITypeRef VTableHolder)
DICompositeType * createStructType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang=0, DIType *VTableHolder=nullptr, StringRef UniqueIdentifier="")
Create debugging information entry for a struct.
Definition: DIBuilder.cpp:461
DINodeArray getOrCreateArray(ArrayRef< Metadata *> Elements)
Get a DINodeArray, create one if required.
Definition: DIBuilder.cpp:603
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a temporary node.
Definition: Metadata.h:1153
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1166
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:423
static DIType * createArtificialType(DIType *Ty)
Create a uniqued clone of Ty with FlagArtificial set.
Definition: DIBuilder.cpp:549
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
Definition: Metadata.h:984
DIDerivedType * createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits=0, uint32_t AlignInBits=0, Optional< unsigned > DWARFAddressSpace=None)
Create debugging information entry for a c++ style reference or rvalue reference type.
Definition: DIBuilder.cpp:296
TypedDINodeRef< DINode > DINodeRef
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A single checksum, represented by a Kind and a Value (a string).
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
DICompositeType * createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, DIType *UnderlyingType, StringRef UniqueIdentifier="", bool IsScoped=false)
Create debugging information entry for an enumeration.
Definition: DIBuilder.cpp:504
static void checkGlobalVariableScope(DIScope *Context)
Definition: DIBuilder.cpp:631
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1174
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:371
DICompileUnit * createCompileUnit(unsigned 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)
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
Definition: DIBuilder.cpp:138
A pair of DIGlobalVariable and DIExpression.
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
static DIType * createTypeWithFlags(const DIType *Ty, DINode::DIFlags FlagsToSet)
Definition: DIBuilder.cpp:543
DIBasicType * createUnspecifiedParameter()
Create unspecified parameter type for a subroutine type.
Definition: DIBuilder.cpp:572
static DILocalVariable * createLocalVariable(LLVMContext &VMContext, DenseMap< MDNode *, SmallVector< TrackingMDNodeRef, 1 >> &PreservedVariables, DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, uint32_t AlignInBits)
Definition: DIBuilder.cpp:670
cl::opt< bool > UseDbgAddr("use-dbg-addr", llvm::cl::desc("Use llvm.dbg.addr for all local variables"), cl::init(false), cl::Hidden)
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Definition: DIBuilder.cpp:746
Typed tracking ref.
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:71
void retainType(DIScope *T)
Retain DIScope* in a module even if it is not referenced through debug info anchors.
Definition: DIBuilder.cpp:564
An imported module (C++ using directive or similar).
Base class for scope-like contexts.
DITemplateValueParameter * createTemplateValueParameter(DIScope *Scope, StringRef Name, DIType *Ty, Constant *Val)
Create debugging information for template value parameter.
Definition: DIBuilder.cpp:421
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:240
static DIScope * getNonCompileUnitScope(DIScope *N)
If N is compile unit return NULL otherwise return N.
Definition: DIBuilder.cpp:132
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
Base class for types.
DIFile * createFile(StringRef Filename, StringRef Directory, Optional< DIFile::ChecksumInfo< StringRef >> Checksum=None, Optional< StringRef > Source=None)
Create a file descriptor to hold debugging information for a file.
Definition: DIBuilder.cpp:214
static DISubprogram * createArtificialSubprogram(DISubprogram *SP)
Create a distinct clone of SP with FlagArtificial set.
Definition: DIBuilder.cpp:538
DITemplateValueParameter * createTemplateParameterPack(DIScope *Scope, StringRef Name, DIType *Ty, DINodeArray Val)
Create debugging information for a template parameter pack.
Definition: DIBuilder.cpp:437
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:349
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Module.h This file contains the declarations for the Module class.
iterator end() const
Definition: ArrayRef.h:138
DIExpression * createExpression(ArrayRef< uint64_t > Addr=None)
Create a new descriptor for the specified variable which has a complex address expression for its add...
Definition: DIBuilder.cpp:735
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.
Definition: DIBuilder.cpp:486
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:622
DWARF expression.
DIBuilder(Module &M, bool AllowUnresolved=true, DICompileUnit *CU=nullptr)
Construct a builder for a module.
Definition: DIBuilder.cpp:34
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
This file contains constants used for implementing Dwarf debug support.
A (clang) module that has been imported by the compile unit.
DIObjCProperty * createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, StringRef GetterName, StringRef SetterName, unsigned PropertyAttributes, DIType *Ty)
Create debugging information entry for Objective-C property.
Definition: DIBuilder.cpp:398
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:394
DITemplateValueParameter * createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty, StringRef Val)
Create debugging information for a template template parameter.
Definition: DIBuilder.cpp:429
Type array for a subprogram.
NodeTy * replaceTemporary(TempMDNode &&N, NodeTy *Replacement)
Replace a temporary node.
Definition: DIBuilder.h:867
DICompositeType * createVectorType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts)
Create debugging information entry for a vector type.
Definition: DIBuilder.cpp:528
DIFlags
Debug info flags.
bool isArtificial() const
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.
Definition: DIBuilder.cpp:387
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:56
DILexicalBlock * createLexicalBlock(DIScope *Scope, DIFile *File, unsigned Line, unsigned Col)
This creates a descriptor for a lexical block with the specified parent context.
Definition: DIBuilder.cpp:835
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.
Definition: DIBuilder.cpp:696
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
void replaceVTableHolder(DICompositeType *&T, DIType *VTableHolder)
Replace the vtable holder in the given type.
Definition: DIBuilder.cpp:974
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)
Create a new descriptor for the specified C++ method.
Definition: DIBuilder.cpp:786
uint32_t Size
Definition: Profile.cpp:47
static DITemplateValueParameter * createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, DIScope *Context, StringRef Name, DIType *Ty, Metadata *MD)
Definition: DIBuilder.cpp:413
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1974
DISPFlags
Debug info subprogram flags.
void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards...
Definition: DIBuilder.cpp:49
DIBasicType * createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding, DINode::DIFlags Flags=DINode::FlagZero)
Create debugging information entry for a basic type.
Definition: DIBuilder.cpp:260
const unsigned Kind
DILocalScope * getScope() const
Get the local scope for this label.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DIImportedEntity * createImportedDeclaration(DIScope *Context, DINode *Decl, DIFile *File, unsigned Line, StringRef Name="")
Create a descriptor for an imported function.
Definition: DIBuilder.cpp:202
static ConstantAsMetadata * getConstantOrNull(Constant *C)
Definition: DIBuilder.cpp:345
DIModule * createModule(DIScope *Scope, StringRef Name, StringRef ConfigurationMacros, StringRef IncludePath, StringRef ISysRoot)
This creates new descriptor for a module with the specified parent scope.
Definition: DIBuilder.cpp:821
LLVM Value Representation.
Definition: Value.h:73
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
bool isTemporary() const
Definition: Metadata.h:944
void replaceMacros(DIMacroNodeArray N)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
DIDerivedType * createQualifiedType(unsigned Tag, DIType *FromTy)
Create debugging information entry for a qualified type, e.g.
Definition: DIBuilder.cpp:268
DILocalScope * getScope() const
Get the local scope for this variable.
DILocalVariable * createParameterVariable(DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve=false, DINode::DIFlags Flags=DINode::FlagZero)
Create a new descriptor for a parameter variable.
Definition: DIBuilder.cpp:706
void replaceElements(DINodeArray Elements)
Replace operands.
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.
Definition: DIBuilder.cpp:286
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.
Definition: DIBuilder.cpp:771
Root of the metadata hierarchy.
Definition: Metadata.h:58
DIDerivedType * createFriend(DIType *Ty, DIType *FriendTy)
Create debugging information entry for a &#39;friend&#39;.
Definition: DIBuilder.cpp:315
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void replaceImportedEntities(DIImportedEntityArray N)
const BasicBlock * getParent() const
Definition: Instruction.h:67
Basic type, like &#39;int&#39; or &#39;float&#39;.
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...
Definition: DIBuilder.cpp:657