LLVM  6.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));
32 
33 DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
34  : M(m), VMContext(M.getContext()), CUNode(nullptr),
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 
207  DIFile::ChecksumKind CSKind, StringRef Checksum) {
208  return DIFile::get(VMContext, Filename, Directory, CSKind, Checksum);
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  assert(!Name.empty() && "Unable to create enumerator without name");
238  return DIEnumerator::get(VMContext, Val, Name);
239 }
240 
242  assert(!Name.empty() && "Unable to create type without name");
243  return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
244 }
245 
247  return createUnspecifiedType("decltype(nullptr)");
248 }
249 
251  unsigned Encoding) {
252  assert(!Name.empty() && "Unable to create type without name");
253  return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
254  0, Encoding);
255 }
256 
258  return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
259  0, 0, None, DINode::FlagZero);
260 }
261 
263  DIType *PointeeTy,
264  uint64_t SizeInBits,
265  uint32_t AlignInBits,
266  Optional<unsigned> DWARFAddressSpace,
267  StringRef Name) {
268  // FIXME: Why is there a name here?
269  return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
270  nullptr, 0, nullptr, PointeeTy, SizeInBits,
271  AlignInBits, 0, DWARFAddressSpace,
272  DINode::FlagZero);
273 }
274 
276  DIType *Base,
277  uint64_t SizeInBits,
278  uint32_t AlignInBits,
279  DINode::DIFlags Flags) {
280  return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
281  nullptr, 0, nullptr, PointeeTy, SizeInBits,
282  AlignInBits, 0, None, Flags, Base);
283 }
284 
286  unsigned Tag, DIType *RTy,
287  uint64_t SizeInBits,
288  uint32_t AlignInBits,
289  Optional<unsigned> DWARFAddressSpace) {
290  assert(RTy && "Unable to create reference type");
291  return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
292  SizeInBits, AlignInBits, 0, DWARFAddressSpace,
293  DINode::FlagZero);
294 }
295 
297  DIFile *File, unsigned LineNo,
298  DIScope *Context) {
299  return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
300  LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
301  0, None, DINode::FlagZero);
302 }
303 
305  assert(Ty && "Invalid type!");
306  assert(FriendTy && "Invalid friend type!");
307  return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
308  FriendTy, 0, 0, 0, None, DINode::FlagZero);
309 }
310 
312  uint64_t BaseOffset,
313  DINode::DIFlags Flags) {
314  assert(Ty && "Unable to create inheritance");
315  return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
316  0, Ty, BaseTy, 0, 0, BaseOffset, None, Flags);
317 }
318 
320  DIFile *File, unsigned LineNumber,
321  uint64_t SizeInBits,
322  uint32_t AlignInBits,
323  uint64_t OffsetInBits,
324  DINode::DIFlags Flags, DIType *Ty) {
325  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
326  LineNumber, getNonCompileUnitScope(Scope), Ty,
327  SizeInBits, AlignInBits, OffsetInBits, None, Flags);
328 }
329 
331  if (C)
332  return ConstantAsMetadata::get(C);
333  return nullptr;
334 }
335 
337  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
338  uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
339  DINode::DIFlags Flags, DIType *Ty) {
340  Flags |= DINode::FlagBitField;
341  return DIDerivedType::get(
342  VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
343  getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
344  OffsetInBits, None, Flags,
346  StorageOffsetInBits)));
347 }
348 
351  unsigned LineNumber, DIType *Ty,
352  DINode::DIFlags Flags, llvm::Constant *Val,
353  uint32_t AlignInBits) {
354  Flags |= DINode::FlagStaticMember;
355  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
356  LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
357  AlignInBits, 0, None, Flags,
358  getConstantOrNull(Val));
359 }
360 
363  uint64_t SizeInBits, uint32_t AlignInBits,
364  uint64_t OffsetInBits, DINode::DIFlags Flags,
365  DIType *Ty, MDNode *PropertyNode) {
366  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
367  LineNumber, getNonCompileUnitScope(File), Ty,
368  SizeInBits, AlignInBits, OffsetInBits, None, Flags,
369  PropertyNode);
370 }
371 
374  StringRef GetterName, StringRef SetterName,
375  unsigned PropertyAttributes, DIType *Ty) {
376  return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
377  SetterName, PropertyAttributes, Ty);
378 }
379 
382  DIType *Ty) {
383  assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
384  return DITemplateTypeParameter::get(VMContext, Name, Ty);
385 }
386 
390  Metadata *MD) {
391  assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
392  return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
393 }
394 
397  DIType *Ty, Constant *Val) {
399  VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
400  getConstantOrNull(Val));
401 }
402 
405  DIType *Ty, StringRef Val) {
407  VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
408  MDString::get(VMContext, Val));
409 }
410 
413  DIType *Ty, DINodeArray Val) {
415  VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
416  Val.get());
417 }
418 
420  DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
421  uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
422  DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
423  DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
424  assert((!Context || isa<DIScope>(Context)) &&
425  "createClassType should be called with a valid Context");
426 
427  auto *R = DICompositeType::get(
428  VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
429  getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
430  OffsetInBits, Flags, Elements, 0, VTableHolder,
431  cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
432  trackIfUnresolved(R);
433  return R;
434 }
435 
437  DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
438  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
439  DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
440  DIType *VTableHolder, StringRef UniqueIdentifier) {
441  auto *R = DICompositeType::get(
442  VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
443  getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
444  Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
445  trackIfUnresolved(R);
446  return R;
447 }
448 
450  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
451  uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
452  DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
453  auto *R = DICompositeType::get(
454  VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
455  getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
456  Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
457  trackIfUnresolved(R);
458  return R;
459 }
460 
462  DINode::DIFlags Flags,
463  unsigned CC) {
464  return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
465 }
466 
468  DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
469  uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
470  DIType *UnderlyingType, StringRef UniqueIdentifier) {
471  auto *CTy = DICompositeType::get(
472  VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
473  getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
474  DINode::FlagZero, Elements, 0, nullptr, nullptr, UniqueIdentifier);
475  AllEnumTypes.push_back(CTy);
476  trackIfUnresolved(CTy);
477  return CTy;
478 }
479 
481  uint32_t AlignInBits, DIType *Ty,
482  DINodeArray Subscripts) {
483  auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
484  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
485  DINode::FlagZero, Subscripts, 0, nullptr);
486  trackIfUnresolved(R);
487  return R;
488 }
489 
491  uint32_t AlignInBits, DIType *Ty,
492  DINodeArray Subscripts) {
493  auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
494  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
495  DINode::FlagVector, Subscripts, 0, nullptr);
496  trackIfUnresolved(R);
497  return R;
498 }
499 
501  DINode::DIFlags FlagsToSet) {
502  auto NewTy = Ty->clone();
503  NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
504  return MDNode::replaceWithUniqued(std::move(NewTy));
505 }
506 
508  // FIXME: Restrict this to the nodes where it's valid.
509  if (Ty->isArtificial())
510  return Ty;
511  return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial);
512 }
513 
515  // FIXME: Restrict this to the nodes where it's valid.
516  if (Ty->isObjectPointer())
517  return Ty;
518  DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
519  return createTypeWithFlags(VMContext, Ty, Flags);
520 }
521 
523  assert(T && "Expected non-null type");
524  assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
525  cast<DISubprogram>(T)->isDefinition() == false)) &&
526  "Expected type or subprogram declaration");
527  AllRetainTypes.emplace_back(T);
528 }
529 
531 
534  DIFile *F, unsigned Line, unsigned RuntimeLang,
535  uint64_t SizeInBits, uint32_t AlignInBits,
536  StringRef UniqueIdentifier) {
537  // FIXME: Define in terms of createReplaceableForwardDecl() by calling
538  // replaceWithUniqued().
539  auto *RetTy = DICompositeType::get(
540  VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
541  SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
542  nullptr, nullptr, UniqueIdentifier);
543  trackIfUnresolved(RetTy);
544  return RetTy;
545 }
546 
548  unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
549  unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
550  DINode::DIFlags Flags, StringRef UniqueIdentifier) {
551  auto *RetTy =
553  VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
554  SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
555  nullptr, UniqueIdentifier)
556  .release();
557  trackIfUnresolved(RetTy);
558  return RetTy;
559 }
560 
562  return MDTuple::get(VMContext, Elements);
563 }
564 
565 DIMacroNodeArray
567  return MDTuple::get(VMContext, Elements);
568 }
569 
572  for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
573  if (Elements[i] && isa<MDNode>(Elements[i]))
574  Elts.push_back(cast<DIType>(Elements[i]));
575  else
576  Elts.push_back(Elements[i]);
577  }
578  return DITypeRefArray(MDNode::get(VMContext, Elts));
579 }
580 
581 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
582  return DISubrange::get(VMContext, Count, Lo);
583 }
584 
586 #ifndef NDEBUG
587  if (auto *CT =
588  dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
589  assert(CT->getIdentifier().empty() &&
590  "Context of a global variable should not be a type with identifier");
591 #endif
592 }
593 
596  unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
597  MDNode *Decl, uint32_t AlignInBits) {
598  checkGlobalVariableScope(Context);
599 
601  VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
602  LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
603  AlignInBits);
604  if (!Expr)
605  Expr = createExpression();
606  auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
607  AllGVs.push_back(N);
608  return N;
609 }
610 
613  unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl,
614  uint32_t AlignInBits) {
615  checkGlobalVariableScope(Context);
616 
618  VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
619  LineNumber, Ty, isLocalToUnit, false,
620  cast_or_null<DIDerivedType>(Decl), AlignInBits)
621  .release();
622 }
623 
625  LLVMContext &VMContext,
626  DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
627  DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
628  unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
629  uint32_t AlignInBits) {
630  // FIXME: Why getNonCompileUnitScope()?
631  // FIXME: Why is "!Context" okay here?
632  // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
633  // the only valid scopes)?
635 
636  auto *Node =
637  DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
638  File, LineNo, Ty, ArgNo, Flags, AlignInBits);
639  if (AlwaysPreserve) {
640  // The optimizer may remove local variables. If there is an interest
641  // to preserve variable info in such situation then stash it in a
642  // named mdnode.
643  DISubprogram *Fn = getDISubprogram(Scope);
644  assert(Fn && "Missing subprogram for local variable");
645  PreservedVariables[Fn].emplace_back(Node);
646  }
647  return Node;
648 }
649 
651  DIFile *File, unsigned LineNo,
652  DIType *Ty, bool AlwaysPreserve,
653  DINode::DIFlags Flags,
654  uint32_t AlignInBits) {
655  return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
656  /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
657  Flags, AlignInBits);
658 }
659 
661  DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
662  unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
663  assert(ArgNo && "Expected non-zero argument number for parameter");
664  return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
665  File, LineNo, Ty, AlwaysPreserve, Flags,
666  /* AlignInBits */0);
667 }
668 
670  return DIExpression::get(VMContext, Addr);
671 }
672 
674  // TODO: Remove the callers of this signed version and delete.
675  SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
676  return createExpression(Addr);
677 }
678 
679 template <class... Ts>
680 static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
681  if (IsDistinct)
682  return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
683  return DISubprogram::get(std::forward<Ts>(Args)...);
684 }
685 
688  unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
689  bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
690  bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
691  DITypeArray ThrownTypes) {
692  auto *Node = getSubprogram(
693  /* IsDistinct = */ isDefinition, VMContext,
694  getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty,
695  isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags,
696  isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
697  MDTuple::getTemporary(VMContext, None).release(), ThrownTypes);
698 
699  if (isDefinition)
700  AllSubprograms.push_back(Node);
701  trackIfUnresolved(Node);
702  return Node;
703 }
704 
707  unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
708  bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
709  bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
710  DITypeArray ThrownTypes) {
712  VMContext, getNonCompileUnitScope(Context), Name, LinkageName,
713  File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr,
714  0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr,
715  TParams, Decl, nullptr, ThrownTypes)
716  .release();
717 }
718 
721  unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
722  bool isDefinition, unsigned VK, unsigned VIndex, int ThisAdjustment,
723  DIType *VTableHolder, DINode::DIFlags Flags, bool isOptimized,
724  DITemplateParameterArray TParams, DITypeArray ThrownTypes) {
725  assert(getNonCompileUnitScope(Context) &&
726  "Methods should have both a Context and a context that isn't "
727  "the compile unit.");
728  // FIXME: Do we want to use different scope/lines?
729  auto *SP = getSubprogram(
730  /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name,
731  LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
732  VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized,
733  isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr, ThrownTypes);
734 
735  if (isDefinition)
736  AllSubprograms.push_back(SP);
737  trackIfUnresolved(SP);
738  return SP;
739 }
740 
742  bool ExportSymbols) {
743 
744  // It is okay to *not* make anonymous top-level namespaces distinct, because
745  // all nodes that have an anonymous namespace as their parent scope are
746  // guaranteed to be unique and/or are linked to their containing
747  // DICompileUnit. This decision is an explicit tradeoff of link time versus
748  // memory usage versus code simplicity and may get revisited in the future.
749  return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
750  ExportSymbols);
751 }
752 
754  StringRef ConfigurationMacros,
755  StringRef IncludePath,
756  StringRef ISysRoot) {
757  return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
758  ConfigurationMacros, IncludePath, ISysRoot);
759 }
760 
762  DIFile *File,
763  unsigned Discriminator) {
764  return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
765 }
766 
768  unsigned Line, unsigned Col) {
769  // Make these distinct, to avoid merging two lexical blocks on the same
770  // file/line/column.
771  return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
772  File, Line, Col);
773 }
774 
775 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
776  DIExpression *Expr, const DILocation *DL,
777  Instruction *InsertBefore) {
778  return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
779  InsertBefore);
780 }
781 
782 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
783  DIExpression *Expr, const DILocation *DL,
784  BasicBlock *InsertAtEnd) {
785  // If this block already has a terminator then insert this intrinsic before
786  // the terminator. Otherwise, put it at the end of the block.
787  Instruction *InsertBefore = InsertAtEnd->getTerminator();
788  return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
789 }
790 
791 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
792  DILocalVariable *VarInfo,
793  DIExpression *Expr,
794  const DILocation *DL,
795  Instruction *InsertBefore) {
796  return insertDbgValueIntrinsic(
797  V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
798  InsertBefore);
799 }
800 
801 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
802  DILocalVariable *VarInfo,
803  DIExpression *Expr,
804  const DILocation *DL,
805  BasicBlock *InsertAtEnd) {
806  return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
807 }
808 
809 /// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
810 /// abstracts over the various ways to specify an insert position.
812  BasicBlock *InsertBB,
813  Instruction *InsertBefore) {
814  IRBuilder<> B(DL->getContext());
815  if (InsertBefore)
816  B.SetInsertPoint(InsertBefore);
817  else if (InsertBB)
818  B.SetInsertPoint(InsertBB);
819  B.SetCurrentDebugLocation(DL);
820  return B;
821 }
822 
824  assert(V && "no value passed to dbg intrinsic");
825  return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
826 }
827 
829  return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
830  : Intrinsic::dbg_declare);
831 }
832 
833 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
834  DIExpression *Expr, const DILocation *DL,
835  BasicBlock *InsertBB, Instruction *InsertBefore) {
836  assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
837  assert(DL && "Expected debug loc");
838  assert(DL->getScope()->getSubprogram() ==
839  VarInfo->getScope()->getSubprogram() &&
840  "Expected matching subprograms");
841  if (!DeclareFn)
842  DeclareFn = getDeclareIntrin(M);
843 
844  trackIfUnresolved(VarInfo);
845  trackIfUnresolved(Expr);
846  Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
847  MetadataAsValue::get(VMContext, VarInfo),
848  MetadataAsValue::get(VMContext, Expr)};
849 
850  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
851  return B.CreateCall(DeclareFn, Args);
852 }
853 
854 Instruction *DIBuilder::insertDbgValueIntrinsic(
855  Value *V, DILocalVariable *VarInfo, DIExpression *Expr,
856  const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
857  assert(V && "no value passed to dbg.value");
858  assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
859  assert(DL && "Expected debug loc");
860  assert(DL->getScope()->getSubprogram() ==
861  VarInfo->getScope()->getSubprogram() &&
862  "Expected matching subprograms");
863  if (!ValueFn)
864  ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
865 
866  trackIfUnresolved(VarInfo);
867  trackIfUnresolved(Expr);
868  Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
869  MetadataAsValue::get(VMContext, VarInfo),
870  MetadataAsValue::get(VMContext, Expr)};
871 
872  IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
873  return B.CreateCall(ValueFn, Args);
874 }
875 
877  DIType *VTableHolder) {
878  {
880  N->replaceVTableHolder(VTableHolder);
881  T = N.get();
882  }
883 
884  // If this didn't create a self-reference, just return.
885  if (T != VTableHolder)
886  return;
887 
888  // Look for unresolved operands. T will drop RAUW support, orphaning any
889  // cycles underneath it.
890  if (T->isResolved())
891  for (const MDOperand &O : T->operands())
892  if (auto *N = dyn_cast_or_null<MDNode>(O))
893  trackIfUnresolved(N);
894 }
895 
896 void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
897  DINodeArray TParams) {
898  {
900  if (Elements)
901  N->replaceElements(Elements);
902  if (TParams)
903  N->replaceTemplateParams(DITemplateParameterArray(TParams));
904  T = N.get();
905  }
906 
907  // If T isn't resolved, there's no problem.
908  if (!T->isResolved())
909  return;
910 
911  // If T is resolved, it may be due to a self-reference cycle. Track the
912  // arrays explicitly if they're unresolved, or else the cycles will be
913  // orphaned.
914  if (Elements)
915  trackIfUnresolved(Elements.get());
916  if (TParams)
917  trackIfUnresolved(TParams.get());
918 }
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:705
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:686
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:262
static Value * getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V)
Definition: DIBuilder.cpp:823
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:594
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:741
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:446
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:336
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:449
void addOperand(MDNode *M)
Definition: Metadata.cpp:1079
DICompositeType * createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts)
Create debugging information entry for an array.
Definition: DIBuilder.cpp:480
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:547
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:419
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:611
DISubrange * getOrCreateSubrange(int64_t Lo, int64_t Count)
Create a descriptor for a value range.
Definition: DIBuilder.cpp:581
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:896
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:533
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:350
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:719
DIType * createObjectPointerType(DIType *Ty)
Create a new DIType* with the "object pointer" flag set.
Definition: DIBuilder.cpp:514
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:566
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:319
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:761
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:828
DITemplateTypeParameter * createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty)
Create debugging information for template type parameter.
Definition: DIBuilder.cpp:381
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:296
DIBasicType * createUnspecifiedType(StringRef Name)
Create a DWARF unspecified type.
Definition: DIBuilder.cpp:241
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:461
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:668
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:45
void resolveCycles()
Resolve cycles.
Definition: Metadata.cpp:613
DIEnumerator * createEnumerator(StringRef Name, int64_t Val)
Create a single enumerator value.
Definition: DIBuilder.cpp:236
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
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:811
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:246
DICompositeType * createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, DIType *UnderlyingType, StringRef UniqueIdentifier="")
Create debugging information entry for an enumeration.
Definition: DIBuilder.cpp:467
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata *> Elements)
Get a DITypeRefArray, create one if required.
Definition: DIBuilder.cpp:570
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:436
DINodeArray getOrCreateArray(ArrayRef< Metadata *> Elements)
Get a DINodeArray, create one if required.
Definition: DIBuilder.cpp:561
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:507
DIFile * createFile(StringRef Filename, StringRef Directory, DIFile::ChecksumKind CSKind=DIFile::CSK_None, StringRef Checksum=StringRef())
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:285
TypedDINodeRef< DINode > DINodeRef
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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:585
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:530
DIBuilder(Module &M, bool AllowUnresolved=true)
Construct a builder for a module.
Definition: DIBuilder.cpp:33
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:624
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Definition: DIBuilder.cpp:680
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:522
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:396
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:412
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:341
cl::opt< bool > UseDbgAddr("use-dbg-addr", llvm::cl::desc("Use llvm.dbg.addr for all local variables"), cl::init(false))
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
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:669
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:560
DWARF expression.
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:373
DIBasicType * createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding)
Create debugging information entry for a basic type.
Definition: DIBuilder.cpp:250
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:398
DITemplateValueParameter * createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty, StringRef Val)
Create debugging information for a template template parameter.
Definition: DIBuilder.cpp:404
Type array for a subprogram.
NodeTy * replaceTemporary(TempMDNode &&N, NodeTy *Replacement)
Replace a temporary node.
Definition: DIBuilder.h:784
DICompositeType * createVectorType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts)
Create debugging information entry for a vector type.
Definition: DIBuilder.cpp:490
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:362
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:656
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:767
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:650
#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:876
static DITemplateValueParameter * createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, DIScope *Context, StringRef Name, DIType *Ty, Metadata *MD)
Definition: DIBuilder.cpp:388
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:311
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:330
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:753
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:257
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:660
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:275
static DIType * createTypeWithFlags(LLVMContext &Context, DIType *Ty, DINode::DIFlags FlagsToSet)
Definition: DIBuilder.cpp:500
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:304
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;.
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1663