LLVM  7.0.0svn
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/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),
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->getVariables().get();
50  if (!Temp || !Temp->isTemporary())
51  return;
52 
54 
55  auto PV = PreservedVariables.find(SP);
56  if (PV != PreservedVariables.end())
57  Variables.append(PV->second.begin(), PV->second.end());
58 
59  DINodeArray AV = getOrCreateArray(Variables);
60  TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
61 }
62 
64  if (!CUNode) {
65  assert(!AllowUnresolvedNodes &&
66  "creating type nodes without a CU is not supported");
67  return;
68  }
69 
70  CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
71 
72  SmallVector<Metadata *, 16> RetainValues;
73  // Declarations and definitions of the same type may be retained. Some
74  // clients RAUW these pairs, leaving duplicates in the retained types
75  // list. Use a set to remove the duplicates while we transform the
76  // TrackingVHs back into Values.
78  for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
79  if (RetainSet.insert(AllRetainTypes[I]).second)
80  RetainValues.push_back(AllRetainTypes[I]);
81 
82  if (!RetainValues.empty())
83  CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
84 
85  DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
86  for (auto *SP : SPs)
88  for (auto *N : RetainValues)
89  if (auto *SP = dyn_cast<DISubprogram>(N))
91 
92  if (!AllGVs.empty())
93  CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
94 
95  if (!AllImportedModules.empty())
97  VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
98  AllImportedModules.end())));
99 
100  for (const auto &I : AllMacrosPerParent) {
101  // DIMacroNode's with nullptr parent are DICompileUnit direct children.
102  if (!I.first) {
103  CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
104  continue;
105  }
106  // Otherwise, it must be a temporary DIMacroFile that need to be resolved.
107  auto *TMF = cast<DIMacroFile>(I.first);
108  auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file,
109  TMF->getLine(), TMF->getFile(),
110  getOrCreateMacroArray(I.second.getArrayRef()));
111  replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
112  }
113 
114  // Now that all temp nodes have been replaced or deleted, resolve remaining
115  // cycles.
116  for (const auto &N : UnresolvedNodes)
117  if (N && !N->isResolved())
118  N->resolveCycles();
119  UnresolvedNodes.clear();
120 
121  // Can't handle unresolved nodes anymore.
122  AllowUnresolvedNodes = false;
123 }
124 
125 /// If N is compile unit return NULL otherwise return N.
127  if (!N || isa<DICompileUnit>(N))
128  return nullptr;
129  return cast<DIScope>(N);
130 }
131 
133  unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
134  StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
135  DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
136  bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) {
137 
138  assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
139  (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
140  "Invalid Language tag");
141 
142  assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
144  VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
145  SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
146  SplitDebugInlining, DebugInfoForProfiling, GnuPubnames);
147 
148  // Create a named metadata so that it is easier to find cu in a module.
149  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
150  NMD->addOperand(CUNode);
151  trackIfUnresolved(CUNode);
152  return CUNode;
153 }
154 
155 static DIImportedEntity *
157  Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
158  SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
159  if (Line)
160  assert(File && "Source location has line number but no file");
161  unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
162  auto *M =
163  DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name);
164  if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
165  // A new Imported Entity was just added to the context.
166  // Add it to the Imported Modules list.
167  AllImportedModules.emplace_back(M);
168  return M;
169 }
170 
172  DINamespace *NS, DIFile *File,
173  unsigned Line) {
174  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
175  Context, NS, File, Line, StringRef(),
176  AllImportedModules);
177 }
178 
180  DIImportedEntity *NS,
181  DIFile *File, unsigned Line) {
182  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
183  Context, NS, File, Line, StringRef(),
184  AllImportedModules);
185 }
186 
188  DIFile *File, unsigned Line) {
189  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
190  Context, M, File, Line, StringRef(),
191  AllImportedModules);
192 }
193 
195  DINode *Decl,
196  DIFile *File,
197  unsigned Line,
198  StringRef Name) {
199  // Make sure to use the unique identifier based metadata reference for
200  // types that have one.
201  return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
202  Context, Decl, File, Line, Name,
203  AllImportedModules);
204 }
205 
208  return DIFile::get(VMContext, Filename, Directory, CS);
209 }
210 
211 DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
212  unsigned MacroType, StringRef Name,
213  StringRef Value) {
214  assert(!Name.empty() && "Unable to create macro without name");
215  assert((MacroType == dwarf::DW_MACINFO_undef ||
216  MacroType == dwarf::DW_MACINFO_define) &&
217  "Unexpected macro type");
218  auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
219  AllMacrosPerParent[Parent].insert(M);
220  return M;
221 }
222 
224  unsigned LineNumber, DIFile *File) {
226  LineNumber, File, DIMacroNodeArray())
227  .release();
228  AllMacrosPerParent[Parent].insert(MF);
229  // Add the new temporary DIMacroFile to the macro per parent map as a parent.
230  // This is needed to assure DIMacroFile with no children to have an entry in
231  // the map. Otherwise, it will not be resolved in DIBuilder::finalize().
232  AllMacrosPerParent.insert({MF, {}});
233  return MF;
234 }
235 
237  bool IsUnsigned) {
238  assert(!Name.empty() && "Unable to create enumerator without name");
239  return DIEnumerator::get(VMContext, Val, IsUnsigned, Name);
240 }
241 
243  assert(!Name.empty() && "Unable to create type without name");
244  return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
245 }
246 
248  return createUnspecifiedType("decltype(nullptr)");
249 }
250 
252  unsigned Encoding) {
253  assert(!Name.empty() && "Unable to create type without name");
254  return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
255  0, Encoding);
256 }
257 
259  return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
260  0, 0, None, DINode::FlagZero);
261 }
262 
264  DIType *PointeeTy,
265  uint64_t SizeInBits,
266  uint32_t AlignInBits,
267  Optional<unsigned> DWARFAddressSpace,
268  StringRef Name) {
269  // FIXME: Why is there a name here?
270  return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
271  nullptr, 0, nullptr, PointeeTy, SizeInBits,
272  AlignInBits, 0, DWARFAddressSpace,
273  DINode::FlagZero);
274 }
275 
277  DIType *Base,
278  uint64_t SizeInBits,
279  uint32_t AlignInBits,
280  DINode::DIFlags Flags) {
281  return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
282  nullptr, 0, nullptr, PointeeTy, SizeInBits,
283  AlignInBits, 0, None, Flags, Base);
284 }
285 
287  unsigned Tag, DIType *RTy,
288  uint64_t SizeInBits,
289  uint32_t AlignInBits,
290  Optional<unsigned> DWARFAddressSpace) {
291  assert(RTy && "Unable to create reference type");
292  return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
293  SizeInBits, AlignInBits, 0, DWARFAddressSpace,
294  DINode::FlagZero);
295 }
296 
298  DIFile *File, unsigned LineNo,
299  DIScope *Context) {
300  return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
301  LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
302  0, None, DINode::FlagZero);
303 }
304 
306  assert(Ty && "Invalid type!");
307  assert(FriendTy && "Invalid friend type!");
308  return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
309  FriendTy, 0, 0, 0, None, DINode::FlagZero);
310 }
311 
313  uint64_t BaseOffset,
314  DINode::DIFlags Flags) {
315  assert(Ty && "Unable to create inheritance");
316  return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
317  0, Ty, BaseTy, 0, 0, BaseOffset, None, Flags);
318 }
319 
321  DIFile *File, unsigned LineNumber,
322  uint64_t SizeInBits,
323  uint32_t AlignInBits,
324  uint64_t OffsetInBits,
325  DINode::DIFlags Flags, DIType *Ty) {
326  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
327  LineNumber, getNonCompileUnitScope(Scope), Ty,
328  SizeInBits, AlignInBits, OffsetInBits, None, Flags);
329 }
330 
332  if (C)
333  return ConstantAsMetadata::get(C);
334  return nullptr;
335 }
336 
338  DIFile *File, unsigned LineNumber,
339  uint64_t SizeInBits,
340  uint32_t AlignInBits,
341  uint64_t OffsetInBits,
342  Constant *Discriminant,
343  DINode::DIFlags Flags, DIType *Ty) {
344  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
345  LineNumber, getNonCompileUnitScope(Scope), Ty,
346  SizeInBits, AlignInBits, OffsetInBits, None, Flags,
347  getConstantOrNull(Discriminant));
348 }
349 
351  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
352  uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
353  DINode::DIFlags Flags, DIType *Ty) {
354  Flags |= DINode::FlagBitField;
355  return DIDerivedType::get(
356  VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
357  getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
358  OffsetInBits, None, Flags,
360  StorageOffsetInBits)));
361 }
362 
365  unsigned LineNumber, DIType *Ty,
366  DINode::DIFlags Flags, llvm::Constant *Val,
367  uint32_t AlignInBits) {
368  Flags |= DINode::FlagStaticMember;
369  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
370  LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
371  AlignInBits, 0, None, Flags,
372  getConstantOrNull(Val));
373 }
374 
377  uint64_t SizeInBits, uint32_t AlignInBits,
378  uint64_t OffsetInBits, DINode::DIFlags Flags,
379  DIType *Ty, MDNode *PropertyNode) {
380  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
381  LineNumber, getNonCompileUnitScope(File), Ty,
382  SizeInBits, AlignInBits, OffsetInBits, None, Flags,
383  PropertyNode);
384 }
385 
388  StringRef GetterName, StringRef SetterName,
389  unsigned PropertyAttributes, DIType *Ty) {
390  return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
391  SetterName, PropertyAttributes, Ty);
392 }
393 
396  DIType *Ty) {
397  assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
398  return DITemplateTypeParameter::get(VMContext, Name, Ty);
399 }
400 
404  Metadata *MD) {
405  assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
406  return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
407 }
408 
411  DIType *Ty, Constant *Val) {
413  VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
414  getConstantOrNull(Val));
415 }
416 
419  DIType *Ty, StringRef Val) {
421  VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
422  MDString::get(VMContext, Val));
423 }
424 
427  DIType *Ty, DINodeArray Val) {
429  VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
430  Val.get());
431 }
432 
434  DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
435  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
436  DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
437  DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
438  assert((!Context || isa<DIScope>(Context)) &&
439  "createClassType should be called with a valid Context");
440 
441  auto *R = DICompositeType::get(
442  VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
443  getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
444  OffsetInBits, Flags, Elements, 0, VTableHolder,
445  cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
446  trackIfUnresolved(R);
447  return R;
448 }
449 
451  DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
452  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
453  DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
454  DIType *VTableHolder, StringRef UniqueIdentifier) {
455  auto *R = DICompositeType::get(
456  VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
457  getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
458  Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
459  trackIfUnresolved(R);
460  return R;
461 }
462 
464  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
465  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
466  DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
467  auto *R = DICompositeType::get(
468  VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
469  getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
470  Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
471  trackIfUnresolved(R);
472  return R;
473 }
474 
476  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
477  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
478  DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) {
479  auto *R = DICompositeType::get(
480  VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
481  getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
482  Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator);
483  trackIfUnresolved(R);
484  return R;
485 }
486 
488  DINode::DIFlags Flags,
489  unsigned CC) {
490  return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
491 }
492 
494  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
495  uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
496  DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsFixed) {
497  auto *CTy = DICompositeType::get(
498  VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
499  getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
500  IsFixed ? DINode::FlagFixedEnum : DINode::FlagZero, Elements, 0, nullptr,
501  nullptr, UniqueIdentifier);
502  AllEnumTypes.push_back(CTy);
503  trackIfUnresolved(CTy);
504  return CTy;
505 }
506 
508  uint32_t AlignInBits, DIType *Ty,
509  DINodeArray Subscripts) {
510  auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
511  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
512  DINode::FlagZero, Subscripts, 0, nullptr);
513  trackIfUnresolved(R);
514  return R;
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::FlagVector, Subscripts, 0, nullptr);
523  trackIfUnresolved(R);
524  return R;
525 }
526 
528  DINode::DIFlags FlagsToSet) {
529  auto NewTy = Ty->clone();
530  NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
531  return MDNode::replaceWithUniqued(std::move(NewTy));
532 }
533 
535  // FIXME: Restrict this to the nodes where it's valid.
536  if (Ty->isArtificial())
537  return Ty;
538  return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial);
539 }
540 
542  // FIXME: Restrict this to the nodes where it's valid.
543  if (Ty->isObjectPointer())
544  return Ty;
545  DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
546  return createTypeWithFlags(VMContext, Ty, Flags);
547 }
548 
550  assert(T && "Expected non-null type");
551  assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
552  cast<DISubprogram>(T)->isDefinition() == false)) &&
553  "Expected type or subprogram declaration");
554  AllRetainTypes.emplace_back(T);
555 }
556 
558 
561  DIFile *F, unsigned Line, unsigned RuntimeLang,
562  uint64_t SizeInBits, uint32_t AlignInBits,
563  StringRef UniqueIdentifier) {
564  // FIXME: Define in terms of createReplaceableForwardDecl() by calling
565  // replaceWithUniqued().
566  auto *RetTy = DICompositeType::get(
567  VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
568  SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
569  nullptr, nullptr, UniqueIdentifier);
570  trackIfUnresolved(RetTy);
571  return RetTy;
572 }
573 
575  unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
576  unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
577  DINode::DIFlags Flags, StringRef UniqueIdentifier) {
578  auto *RetTy =
580  VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
581  SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
582  nullptr, UniqueIdentifier)
583  .release();
584  trackIfUnresolved(RetTy);
585  return RetTy;
586 }
587 
589  return MDTuple::get(VMContext, Elements);
590 }
591 
592 DIMacroNodeArray
594  return MDTuple::get(VMContext, Elements);
595 }
596 
599  for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
600  if (Elements[i] && isa<MDNode>(Elements[i]))
601  Elts.push_back(cast<DIType>(Elements[i]));
602  else
603  Elts.push_back(Elements[i]);
604  }
605  return DITypeRefArray(MDNode::get(VMContext, Elts));
606 }
607 
608 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
609  return DISubrange::get(VMContext, Count, Lo);
610 }
611 
613  return DISubrange::get(VMContext, CountNode, Lo);
614 }
615 
617 #ifndef NDEBUG
618  if (auto *CT =
619  dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
620  assert(CT->getIdentifier().empty() &&
621  "Context of a global variable should not be a type with identifier");
622 #endif
623 }
624 
627  unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
628  MDNode *Decl, uint32_t AlignInBits) {
629  checkGlobalVariableScope(Context);
630 
632  VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
633  LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
634  AlignInBits);
635  if (!Expr)
636  Expr = createExpression();
637  auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
638  AllGVs.push_back(N);
639  return N;
640 }
641 
644  unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl,
645  uint32_t AlignInBits) {
646  checkGlobalVariableScope(Context);
647 
649  VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
650  LineNumber, Ty, isLocalToUnit, false,
651  cast_or_null<DIDerivedType>(Decl), AlignInBits)
652  .release();
653 }
654 
656  LLVMContext &VMContext,
657  DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
658  DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
659  unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
660  uint32_t AlignInBits) {
661  // FIXME: Why getNonCompileUnitScope()?
662  // FIXME: Why is "!Context" okay here?
663  // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
664  // the only valid scopes)?
666 
667  auto *Node =
668  DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
669  File, LineNo, Ty, ArgNo, Flags, AlignInBits);
670  if (AlwaysPreserve) {
671  // The optimizer may remove local variables. If there is an interest
672  // to preserve variable info in such situation then stash it in a
673  // named mdnode.
674  DISubprogram *Fn = getDISubprogram(Scope);
675  assert(Fn && "Missing subprogram for local variable");
676  PreservedVariables[Fn].emplace_back(Node);
677  }
678  return Node;
679 }
680 
682  DIFile *File, unsigned LineNo,
683  DIType *Ty, bool AlwaysPreserve,
684  DINode::DIFlags Flags,
685  uint32_t AlignInBits) {
686  return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
687  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
688  Flags, AlignInBits);
689 }
690 
692  DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
693  unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
694  assert(ArgNo && "Expected non-zero argument number for parameter");
695  return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
696  File, LineNo, Ty, AlwaysPreserve, Flags,
697  /* AlignInBits */0);
698 }
699 
701  return DIExpression::get(VMContext, Addr);
702 }
703 
705  // TODO: Remove the callers of this signed version and delete.
706  SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
707  return createExpression(Addr);
708 }
709 
710 template <class... Ts>
711 static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
712  if (IsDistinct)
713  return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
714  return DISubprogram::get(std::forward<Ts>(Args)...);
715 }
716 
719  unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
720  bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
721  bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
722  DITypeArray ThrownTypes) {
723  auto *Node = getSubprogram(
724  /* IsDistinct = */ isDefinition, VMContext,
725  getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty,
726  isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags,
727  isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
728  MDTuple::getTemporary(VMContext, None).release(), ThrownTypes);
729 
730  if (isDefinition)
731  AllSubprograms.push_back(Node);
732  trackIfUnresolved(Node);
733  return Node;
734 }
735 
738  unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
739  bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
740  bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
741  DITypeArray ThrownTypes) {
743  VMContext, getNonCompileUnitScope(Context), Name, LinkageName,
744  File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr,
745  0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr,
746  TParams, Decl, nullptr, ThrownTypes)
747  .release();
748 }
749 
752  unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
753  bool isDefinition, unsigned VK, unsigned VIndex, int ThisAdjustment,
754  DIType *VTableHolder, DINode::DIFlags Flags, bool isOptimized,
755  DITemplateParameterArray TParams, DITypeArray ThrownTypes) {
756  assert(getNonCompileUnitScope(Context) &&
757  "Methods should have both a Context and a context that isn't "
758  "the compile unit.");
759  // FIXME: Do we want to use different scope/lines?
760  auto *SP = getSubprogram(
761  /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name,
762  LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
763  VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized,
764  isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr, ThrownTypes);
765 
766  if (isDefinition)
767  AllSubprograms.push_back(SP);
768  trackIfUnresolved(SP);
769  return SP;
770 }
771 
773  bool ExportSymbols) {
774 
775  // It is okay to *not* make anonymous top-level namespaces distinct, because
776  // all nodes that have an anonymous namespace as their parent scope are
777  // guaranteed to be unique and/or are linked to their containing
778  // DICompileUnit. This decision is an explicit tradeoff of link time versus
779  // memory usage versus code simplicity and may get revisited in the future.
780  return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
781  ExportSymbols);
782 }
783 
785  StringRef ConfigurationMacros,
786  StringRef IncludePath,
787  StringRef ISysRoot) {
788  return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
789  ConfigurationMacros, IncludePath, ISysRoot);
790 }
791 
793  DIFile *File,
794  unsigned Discriminator) {
795  return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
796 }
797 
799  unsigned Line, unsigned Col) {
800  // Make these distinct, to avoid merging two lexical blocks on the same
801  // file/line/column.
802  return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
803  File, Line, Col);
804 }
805 
806 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
807  DIExpression *Expr, const DILocation *DL,
808  Instruction *InsertBefore) {
809  return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
810  InsertBefore);
811 }
812 
813 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
814  DIExpression *Expr, const DILocation *DL,
815  BasicBlock *InsertAtEnd) {
816  // If this block already has a terminator then insert this intrinsic before
817  // the terminator. Otherwise, put it at the end of the block.
818  Instruction *InsertBefore = InsertAtEnd->getTerminator();
819  return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
820 }
821 
822 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
823  DILocalVariable *VarInfo,
824  DIExpression *Expr,
825  const DILocation *DL,
826  Instruction *InsertBefore) {
827  return insertDbgValueIntrinsic(
828  V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
829  InsertBefore);
830 }
831 
832 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
833  DILocalVariable *VarInfo,
834  DIExpression *Expr,
835  const DILocation *DL,
836  BasicBlock *InsertAtEnd) {
837  return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
838 }
839 
840 /// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
841 /// abstracts over the various ways to specify an insert position.
843  BasicBlock *InsertBB,
844  Instruction *InsertBefore) {
845  IRBuilder<> B(DL->getContext());
846  if (InsertBefore)
847  B.SetInsertPoint(InsertBefore);
848  else if (InsertBB)
849  B.SetInsertPoint(InsertBB);
850  B.SetCurrentDebugLocation(DL);
851  return B;
852 }
853 
855  assert(V && "no value passed to dbg intrinsic");
856  return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
857 }
858 
860  return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
861  : Intrinsic::dbg_declare);
862 }
863 
864 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
865  DIExpression *Expr, const DILocation *DL,
866  BasicBlock *InsertBB, Instruction *InsertBefore) {
867  assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
868  assert(DL && "Expected debug loc");
869  assert(DL->getScope()->getSubprogram() ==
870  VarInfo->getScope()->getSubprogram() &&
871  "Expected matching subprograms");
872  if (!DeclareFn)
873  DeclareFn = getDeclareIntrin(M);
874 
875  trackIfUnresolved(VarInfo);
876  trackIfUnresolved(Expr);
877  Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
878  MetadataAsValue::get(VMContext, VarInfo),
879  MetadataAsValue::get(VMContext, Expr)};
880 
881  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
882  return B.CreateCall(DeclareFn, Args);
883 }
884 
885 Instruction *DIBuilder::insertDbgValueIntrinsic(
886  Value *V, DILocalVariable *VarInfo, DIExpression *Expr,
887  const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
888  assert(V && "no value passed to dbg.value");
889  assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
890  assert(DL && "Expected debug loc");
891  assert(DL->getScope()->getSubprogram() ==
892  VarInfo->getScope()->getSubprogram() &&
893  "Expected matching subprograms");
894  if (!ValueFn)
895  ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
896 
897  trackIfUnresolved(VarInfo);
898  trackIfUnresolved(Expr);
899  Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
900  MetadataAsValue::get(VMContext, VarInfo),
901  MetadataAsValue::get(VMContext, Expr)};
902 
903  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
904  return B.CreateCall(ValueFn, Args);
905 }
906 
908  DIType *VTableHolder) {
909  {
911  N->replaceVTableHolder(VTableHolder);
912  T = N.get();
913  }
914 
915  // If this didn't create a self-reference, just return.
916  if (T != VTableHolder)
917  return;
918 
919  // Look for unresolved operands. T will drop RAUW support, orphaning any
920  // cycles underneath it.
921  if (T->isResolved())
922  for (const MDOperand &O : T->operands())
923  if (auto *N = dyn_cast_or_null<MDNode>(O))
924  trackIfUnresolved(N);
925 }
926 
927 void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
928  DINodeArray TParams) {
929  {
931  if (Elements)
932  N->replaceElements(Elements);
933  if (TParams)
934  N->replaceTemplateParams(DITemplateParameterArray(TParams));
935  T = N.get();
936  }
937 
938  // If T isn't resolved, there's no problem.
939  if (!T->isResolved())
940  return;
941 
942  // If T is resolved, it may be due to a self-reference cycle. Track the
943  // arrays explicitly if they're unresolved, or else the cycles will be
944  // orphaned.
945  if (Elements)
946  trackIfUnresolved(Elements.get());
947  if (TParams)
948  trackIfUnresolved(TParams.get());
949 }
void finalize()
Construct any deferred debug info descriptors.
Definition: DIBuilder.cpp:63
DISubprogram * createTempFunctionFwdDecl(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags=DINode::FlagZero, bool isOptimized=false, 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:736
bool isObjectPointer() const
uint64_t CallInst * C
DISubprogram * createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags=DINode::FlagZero, bool isOptimized=false, DITemplateParameterArray TParams=nullptr, DISubprogram *Decl=nullptr, DITypeArray ThrownTypes=nullptr)
Create a new descriptor for the specified subprogram.
Definition: DIBuilder.cpp:717
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:709
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1131
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:263
static Value * getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V)
Definition: DIBuilder.cpp:854
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
DIGlobalVariableExpression * createGlobalVariableExpression(DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DIType *Ty, bool isLocalToUnit, DIExpression *Expr=nullptr, MDNode *Decl=nullptr, uint32_t AlignInBits=0)
Create a new descriptor for the specified variable.
Definition: DIBuilder.cpp:625
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
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:772
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:350
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:463
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:507
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:574
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:251
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:433
DICompositeType * createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, DIType *UnderlyingType, StringRef UniqueIdentifier="", bool IsFixed=false)
Create debugging information entry for an enumeration.
Definition: DIBuilder.cpp:493
DIGlobalVariable * createTempGlobalVariableFwdDecl(DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DIType *Ty, bool isLocalToUnit, MDNode *Decl=nullptr, uint32_t AlignInBits=0)
Identical to createGlobalVariable except that the resulting DbgNode is temporary and meant to be RAUW...
Definition: DIBuilder.cpp:642
DISubrange * getOrCreateSubrange(int64_t Lo, int64_t Count)
Create a descriptor for a value range.
Definition: DIBuilder.cpp:608
Metadata node.
Definition: Metadata.h:862
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:211
void replaceArrays(DICompositeType *&T, DINodeArray Elements, DINodeArray TParams=DINodeArray())
Replace arrays on a composite type.
Definition: DIBuilder.cpp:927
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:560
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:364
TempDIType clone() const
DISubprogram * createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, bool isDefinition, unsigned Virtuality=0, unsigned VTableIndex=0, int ThisAdjustment=0, DIType *VTableHolder=nullptr, DINode::DIFlags Flags=DINode::FlagZero, bool isOptimized=false, DITemplateParameterArray TParams=nullptr, DITypeArray ThrownTypes=nullptr)
Create a new descriptor for the specified C++ method.
Definition: DIBuilder.cpp:750
DIType * createObjectPointerType(DIType *Ty)
Create a new DIType* with the "object pointer" flag set.
Definition: DIBuilder.cpp:541
DIImportedEntity * createImportedModule(DIScope *Context, DINamespace *NS, DIFile *File, unsigned Line)
Create a descriptor for an imported module.
Definition: DIBuilder.cpp:171
DIMacroNodeArray getOrCreateMacroArray(ArrayRef< Metadata *> Elements)
Get a DIMacroNodeArray, create one if required.
Definition: DIBuilder.cpp:593
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:320
Tuple of metadata.
Definition: Metadata.h:1104
Tagged DWARF-like metadata node.
void replaceRetainedTypes(DITypeArray N)
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:792
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, SmallVectorImpl< TrackingMDNodeRef > &AllImportedModules)
Definition: DIBuilder.cpp:156
A tuple of MDNodes.
Definition: Metadata.h:1323
static Function * getDeclareIntrin(Module &M)
Definition: DIBuilder.cpp:859
DITemplateTypeParameter * createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty)
Create debugging information for template type parameter.
Definition: DIBuilder.cpp:395
bool isResolved() const
Check if node is fully resolved.
Definition: Metadata.h:938
Array subrange.
DIDerivedType * createTypedef(DIType *Ty, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context)
Create debugging information entry for a typedef.
Definition: DIBuilder.cpp:297
DIBasicType * createUnspecifiedType(StringRef Name)
Create a DWARF unspecified type.
Definition: DIBuilder.cpp:242
DIMacroFile * createTempMacroFile(DIMacroFile *Parent, unsigned Line, DIFile *File)
Create debugging information temporary entry for a macro file.
Definition: DIBuilder.cpp:223
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:487
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:707
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1176
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:337
Subprogram description.
op_range operands() const
Definition: Metadata.h:1065
LLVMContext & getContext() const
Definition: Metadata.h:922
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:236
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Debug location.
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:408
static IRBuilder getIRBForDbgInsertion(const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore)
Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics.
Definition: DIBuilder.cpp:842
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:980
DIBasicType * createNullPtrType()
Create C++11 nullptr type.
Definition: DIBuilder.cpp:247
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata *> Elements)
Get a DITypeRefArray, create one if required.
Definition: DIBuilder.cpp:597
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:450
DINodeArray getOrCreateArray(ArrayRef< Metadata *> Elements)
Get a DINodeArray, create one if required.
Definition: DIBuilder.cpp:588
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a temporary node.
Definition: Metadata.h:1151
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1164
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:406
DIType * createArtificialType(DIType *Ty)
Create a new DIType* with "artificial" flag set.
Definition: DIBuilder.cpp:534
DIFile * createFile(StringRef Filename, StringRef Directory, Optional< DIFile::ChecksumInfo< StringRef >> Checksum=None)
Create a file descriptor to hold debugging information for a file.
Definition: DIBuilder.cpp:206
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:982
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:286
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:59
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
static void checkGlobalVariableScope(DIScope *Context)
Definition: DIBuilder.cpp:616
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:1172
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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, bool GnuPubnames=false)
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
Definition: DIBuilder.cpp:132
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
A pair of DIGlobalVariable and DIExpression.
void replaceEnumTypes(DICompositeTypeArray N)
Replace arrays.
DIBasicType * createUnspecifiedParameter()
Create unspecified parameter type for a subroutine type.
Definition: DIBuilder.cpp:557
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:655
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:711
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:549
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:410
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:126
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
Base class for types.
DITemplateValueParameter * createTemplateParameterPack(DIScope *Scope, StringRef Name, DIType *Ty, DINodeArray Val)
Create debugging information for a template parameter pack.
Definition: DIBuilder.cpp:426
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:862
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:700
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:475
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:585
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:387
DIBasicType * createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding)
Create debugging information entry for a basic type.
Definition: DIBuilder.cpp:251
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:396
DITemplateValueParameter * createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty, StringRef Val)
Create debugging information for a template template parameter.
Definition: DIBuilder.cpp:418
Type array for a subprogram.
NodeTy * replaceTemporary(TempMDNode &&N, NodeTy *Replacement)
Replace a temporary node.
Definition: DIBuilder.h:830
DICompositeType * createVectorType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts)
Create debugging information entry for a vector type.
Definition: DIBuilder.cpp:517
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:376
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:654
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
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:798
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:681
#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:907
static DITemplateValueParameter * createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, DIScope *Context, StringRef Name, DIType *Ty, Metadata *MD)
Definition: DIBuilder.cpp:402
void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards...
Definition: DIBuilder.cpp:48
DIDerivedType * createInheritance(DIType *Ty, DIType *BaseTy, uint64_t BaseOffset, DINode::DIFlags Flags)
Create debugging information entry to establish inheritance relationship between two types...
Definition: DIBuilder.cpp:312
const unsigned Kind
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:194
static ConstantAsMetadata * getConstantOrNull(Constant *C)
Definition: DIBuilder.cpp:331
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:784
LLVM Value Representation.
Definition: Value.h:73
void replaceGlobalVariables(DIGlobalVariableExpressionArray N)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool isTemporary() const
Definition: Metadata.h:942
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:258
const TerminatorInst * 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:120
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:691
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:276
static DIType * createTypeWithFlags(LLVMContext &Context, DIType *Ty, DINode::DIFlags FlagsToSet)
Definition: DIBuilder.cpp:527
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:305
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;.
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1702