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