LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/DIBuilder.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/DebugInfo.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/Dwarf.h"
22 
23 using namespace llvm;
24 using namespace llvm::dwarf;
25 
26 static Constant *GetTagConstant(LLVMContext &VMContext, unsigned Tag) {
27  assert((Tag & LLVMDebugVersionMask) == 0 &&
28  "Tag too large for debug encoding!");
29  return ConstantInt::get(Type::getInt32Ty(VMContext), Tag | LLVMDebugVersion);
30 }
31 
32 DIBuilder::DIBuilder(Module &m)
33  : M(m), VMContext(M.getContext()), TempEnumTypes(0), TempRetainTypes(0),
34  TempSubprograms(0), TempGVs(0), DeclareFn(0), ValueFn(0) {}
35 
36 /// finalize - Construct any deferred debug info descriptors.
38  DIArray Enums = getOrCreateArray(AllEnumTypes);
39  DIType(TempEnumTypes).replaceAllUsesWith(Enums);
40 
41  SmallVector<Value *, 16> RetainValues;
42  // Declarations and definitions of the same type may be retained. Some
43  // clients RAUW these pairs, leaving duplicates in the retained types
44  // list. Use a set to remove the duplicates while we transform the
45  // TrackingVHs back into Values.
46  SmallPtrSet<Value *, 16> RetainSet;
47  for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
48  if (RetainSet.insert(AllRetainTypes[I]))
49  RetainValues.push_back(AllRetainTypes[I]);
50  DIArray RetainTypes = getOrCreateArray(RetainValues);
51  DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
52 
53  DIArray SPs = getOrCreateArray(AllSubprograms);
54  DIType(TempSubprograms).replaceAllUsesWith(SPs);
55  for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
56  DISubprogram SP(SPs.getElement(i));
57  SmallVector<Value *, 4> Variables;
58  if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
59  for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
60  Variables.push_back(NMD->getOperand(ii));
61  NMD->eraseFromParent();
62  }
63  if (MDNode *Temp = SP.getVariablesNodes()) {
64  DIArray AV = getOrCreateArray(Variables);
65  DIType(Temp).replaceAllUsesWith(AV);
66  }
67  }
68 
69  DIArray GVs = getOrCreateArray(AllGVs);
70  DIType(TempGVs).replaceAllUsesWith(GVs);
71 
72  DIArray IMs = getOrCreateArray(AllImportedModules);
73  DIType(TempImportedModules).replaceAllUsesWith(IMs);
74 }
75 
76 /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
77 /// N.
79  if (DIDescriptor(N).isCompileUnit())
80  return NULL;
81  return N;
82 }
83 
84 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
85  StringRef Directory) {
86  assert(!Filename.empty() && "Unable to create file without name");
87  Value *Pair[] = {
88  MDString::get(VMContext, Filename),
89  MDString::get(VMContext, Directory)
90  };
91  return MDNode::get(VMContext, Pair);
92 }
93 
94 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
95 /// information generated during this instance of compilation.
97  StringRef Directory,
98  StringRef Producer, bool isOptimized,
99  StringRef Flags, unsigned RunTimeVer,
100  StringRef SplitName) {
101  assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
102  (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
103  "Invalid Language tag");
104  assert(!Filename.empty() &&
105  "Unable to create compile unit without filename");
106  Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
107  TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
108 
109  TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
110 
111  TempSubprograms = MDNode::getTemporary(VMContext, TElts);
112 
113  TempGVs = MDNode::getTemporary(VMContext, TElts);
114 
115  TempImportedModules = MDNode::getTemporary(VMContext, TElts);
116 
117  Value *Elts[] = {
118  GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
119  createFilePathPair(VMContext, Filename, Directory),
120  ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
121  MDString::get(VMContext, Producer),
122  ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
123  MDString::get(VMContext, Flags),
124  ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
125  TempEnumTypes,
126  TempRetainTypes,
127  TempSubprograms,
128  TempGVs,
129  TempImportedModules,
130  MDString::get(VMContext, SplitName)
131  };
132 
133  MDNode *CUNode = MDNode::get(VMContext, Elts);
134 
135  // Create a named metadata so that it is easier to find cu in a module.
136  NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
137  NMD->addOperand(CUNode);
138 
139  return DICompileUnit(CUNode);
140 }
141 
142 static DIImportedEntity
144  unsigned Line, StringRef Name,
145  SmallVectorImpl<Value *> &AllImportedModules) {
146  const MDNode *R;
147  if (Name.empty()) {
148  Value *Elts[] = {
149  GetTagConstant(C, dwarf::DW_TAG_imported_module),
150  Context,
151  NS,
153  };
154  R = MDNode::get(C, Elts);
155  } else {
156  Value *Elts[] = {
157  GetTagConstant(C, dwarf::DW_TAG_imported_module),
158  Context,
159  NS,
161  MDString::get(C, Name)
162  };
163  R = MDNode::get(C, Elts);
164  }
165  DIImportedEntity M(R);
166  assert(M.Verify() && "Imported module should be valid");
167  AllImportedModules.push_back(M);
168  return M;
169 }
170 
172  DINameSpace NS, unsigned Line,
173  StringRef Name) {
174  return ::createImportedModule(VMContext, Context, NS, Line, Name,
175  AllImportedModules);
176 }
177 
179  DIImportedEntity NS,
180  unsigned Line,
181  StringRef Name) {
182  return ::createImportedModule(VMContext, Context, NS, Line, Name,
183  AllImportedModules);
184 }
185 
187  DIDescriptor Decl,
188  unsigned Line) {
189  Value *Elts[] = {
190  GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
191  Context,
192  Decl,
193  ConstantInt::get(Type::getInt32Ty(VMContext), Line),
194  };
195  DIImportedEntity M(MDNode::get(VMContext, Elts));
196  assert(M.Verify() && "Imported module should be valid");
197  AllImportedModules.push_back(M);
198  return M;
199 }
200 
201 /// createFile - Create a file descriptor to hold debugging information
202 /// for a file.
204  Value *Elts[] = {
205  GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
206  createFilePathPair(VMContext, Filename, Directory)
207  };
208  return DIFile(MDNode::get(VMContext, Elts));
209 }
210 
211 /// createEnumerator - Create a single enumerator value.
213  assert(!Name.empty() && "Unable to create enumerator without name");
214  Value *Elts[] = {
215  GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
216  MDString::get(VMContext, Name),
217  ConstantInt::get(Type::getInt64Ty(VMContext), Val)
218  };
219  return DIEnumerator(MDNode::get(VMContext, Elts));
220 }
221 
222 /// \brief Create a DWARF unspecified type.
224  assert(!Name.empty() && "Unable to create type without name");
225  // Unspecified types are encoded in DIBasicType format. Line number, filename,
226  // size, alignment, offset and flags are always empty here.
227  Value *Elts[] = {
228  GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
229  NULL, // Filename
230  NULL, // Unused
231  MDString::get(VMContext, Name),
232  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
233  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
234  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
235  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
236  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
237  ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
238  };
239  return DIBasicType(MDNode::get(VMContext, Elts));
240 }
241 
242 /// \brief Create C++11 nullptr type.
244  return createUnspecifiedType("decltype(nullptr)");
245 }
246 
247 /// createBasicType - Create debugging information entry for a basic
248 /// type, e.g 'char'.
251  uint64_t AlignInBits, unsigned Encoding) {
252  assert(!Name.empty() && "Unable to create type without name");
253  // Basic types are encoded in DIBasicType format. Line number, filename,
254  // offset and flags are always empty here.
255  Value *Elts[] = {
256  GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
257  NULL, // File/directory name
258  NULL, // Unused
259  MDString::get(VMContext, Name),
260  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
261  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
262  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
263  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
264  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
265  ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
266  };
267  return DIBasicType(MDNode::get(VMContext, Elts));
268 }
269 
270 /// createQualifiedType - Create debugging information entry for a qualified
271 /// type, e.g. 'const int'.
273  // Qualified types are encoded in DIDerivedType format.
274  Value *Elts[] = {
275  GetTagConstant(VMContext, Tag),
276  NULL, // Filename
277  NULL, // Unused
278  MDString::get(VMContext, StringRef()), // Empty name.
279  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
280  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
281  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
282  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
283  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
284  FromTy.getRef()
285  };
286  return DIDerivedType(MDNode::get(VMContext, Elts));
287 }
288 
289 /// createPointerType - Create debugging information entry for a pointer.
291 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
292  uint64_t AlignInBits, StringRef Name) {
293  // Pointer types are encoded in DIDerivedType format.
294  Value *Elts[] = {
295  GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
296  NULL, // Filename
297  NULL, // Unused
298  MDString::get(VMContext, Name),
299  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
300  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
301  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
302  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
303  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
304  PointeeTy.getRef()
305  };
306  return DIDerivedType(MDNode::get(VMContext, Elts));
307 }
308 
310  DIType Base) {
311  // Pointer types are encoded in DIDerivedType format.
312  Value *Elts[] = {
313  GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
314  NULL, // Filename
315  NULL, // Unused
316  NULL,
317  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
318  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
319  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
320  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
321  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
322  PointeeTy.getRef(),
323  Base.getRef()
324  };
325  return DIDerivedType(MDNode::get(VMContext, Elts));
326 }
327 
328 /// createReferenceType - Create debugging information entry for a reference
329 /// type.
331  assert(RTy.isType() && "Unable to create reference type");
332  // References are encoded in DIDerivedType format.
333  Value *Elts[] = {
334  GetTagConstant(VMContext, Tag),
335  NULL, // Filename
336  NULL, // TheCU,
337  NULL, // Name
338  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
339  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
340  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
341  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
342  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
343  RTy.getRef()
344  };
345  return DIDerivedType(MDNode::get(VMContext, Elts));
346 }
347 
348 /// createTypedef - Create debugging information entry for a typedef.
350  unsigned LineNo, DIDescriptor Context) {
351  // typedefs are encoded in DIDerivedType format.
352  assert(Ty.isType() && "Invalid typedef type!");
353  Value *Elts[] = {
354  GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
355  File.getFileNode(),
357  MDString::get(VMContext, Name),
358  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
359  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
360  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
361  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
362  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
363  Ty.getRef()
364  };
365  return DIDerivedType(MDNode::get(VMContext, Elts));
366 }
367 
368 /// createFriend - Create debugging information entry for a 'friend'.
370  // typedefs are encoded in DIDerivedType format.
371  assert(Ty.isType() && "Invalid type!");
372  assert(FriendTy.isType() && "Invalid friend type!");
373  Value *Elts[] = {
374  GetTagConstant(VMContext, dwarf::DW_TAG_friend),
375  NULL,
376  Ty.getRef(),
377  NULL, // Name
378  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
379  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
380  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
381  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
382  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
383  FriendTy.getRef()
384  };
385  return DIDerivedType(MDNode::get(VMContext, Elts));
386 }
387 
388 /// createInheritance - Create debugging information entry to establish
389 /// inheritance relationship between two types.
391  uint64_t BaseOffset,
392  unsigned Flags) {
393  assert(Ty.isType() && "Unable to create inheritance");
394  // TAG_inheritance is encoded in DIDerivedType format.
395  Value *Elts[] = {
396  GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
397  NULL,
398  Ty.getRef(),
399  NULL, // Name
400  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
401  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
402  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
403  ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
404  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
405  BaseTy.getRef()
406  };
407  return DIDerivedType(MDNode::get(VMContext, Elts));
408 }
409 
410 /// createMemberType - Create debugging information entry for a member.
412  DIFile File, unsigned LineNumber,
413  uint64_t SizeInBits,
414  uint64_t AlignInBits,
415  uint64_t OffsetInBits, unsigned Flags,
416  DIType Ty) {
417  // TAG_member is encoded in DIDerivedType format.
418  Value *Elts[] = {
419  GetTagConstant(VMContext, dwarf::DW_TAG_member),
420  File.getFileNode(),
422  MDString::get(VMContext, Name),
423  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
424  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
425  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
426  ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
427  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
428  Ty.getRef()
429  };
430  return DIDerivedType(MDNode::get(VMContext, Elts));
431 }
432 
433 /// createStaticMemberType - Create debugging information entry for a
434 /// C++ static data member.
437  DIFile File, unsigned LineNumber,
438  DIType Ty, unsigned Flags,
439  llvm::Value *Val) {
440  // TAG_member is encoded in DIDerivedType format.
442  Value *Elts[] = {
443  GetTagConstant(VMContext, dwarf::DW_TAG_member),
444  File.getFileNode(),
446  MDString::get(VMContext, Name),
447  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
448  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
449  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
450  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
451  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
452  Ty.getRef(),
453  Val
454  };
455  return DIDerivedType(MDNode::get(VMContext, Elts));
456 }
457 
458 /// createObjCIVar - Create debugging information entry for Objective-C
459 /// instance variable.
462  uint64_t SizeInBits, uint64_t AlignInBits,
463  uint64_t OffsetInBits, unsigned Flags, DIType Ty,
464  StringRef PropertyName, StringRef GetterName,
465  StringRef SetterName, unsigned PropertyAttributes) {
466  // TAG_member is encoded in DIDerivedType format.
467  Value *Elts[] = {
468  GetTagConstant(VMContext, dwarf::DW_TAG_member),
469  File.getFileNode(),
471  MDString::get(VMContext, Name),
472  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
473  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
474  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
475  ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
476  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
477  Ty,
478  MDString::get(VMContext, PropertyName),
479  MDString::get(VMContext, GetterName),
480  MDString::get(VMContext, SetterName),
481  ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
482  };
483  return DIDerivedType(MDNode::get(VMContext, Elts));
484 }
485 
486 /// createObjCIVar - Create debugging information entry for Objective-C
487 /// instance variable.
489  unsigned LineNumber,
490  uint64_t SizeInBits,
491  uint64_t AlignInBits,
492  uint64_t OffsetInBits, unsigned Flags,
493  DIType Ty, MDNode *PropertyNode) {
494  // TAG_member is encoded in DIDerivedType format.
495  Value *Elts[] = {
496  GetTagConstant(VMContext, dwarf::DW_TAG_member),
497  File.getFileNode(),
499  MDString::get(VMContext, Name),
500  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
501  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
502  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
503  ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
504  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
505  Ty,
506  PropertyNode
507  };
508  return DIDerivedType(MDNode::get(VMContext, Elts));
509 }
510 
511 /// createObjCProperty - Create debugging information entry for Objective-C
512 /// property.
515  StringRef GetterName, StringRef SetterName,
516  unsigned PropertyAttributes, DIType Ty) {
517  Value *Elts[] = {
518  GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
519  MDString::get(VMContext, Name),
520  File,
521  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
522  MDString::get(VMContext, GetterName),
523  MDString::get(VMContext, SetterName),
524  ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
525  Ty
526  };
527  return DIObjCProperty(MDNode::get(VMContext, Elts));
528 }
529 
530 /// createTemplateTypeParameter - Create debugging information for template
531 /// type parameter.
534  DIType Ty, MDNode *File, unsigned LineNo,
535  unsigned ColumnNo) {
536  Value *Elts[] = {
537  GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
539  MDString::get(VMContext, Name),
540  Ty.getRef(),
541  File,
542  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
543  ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
544  };
545  return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
546 }
547 
549 DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
550  StringRef Name, DIType Ty,
551  Value *Val, MDNode *File,
552  unsigned LineNo,
553  unsigned ColumnNo) {
554  Value *Elts[] = {
555  GetTagConstant(VMContext, Tag),
557  MDString::get(VMContext, Name),
558  Ty.getRef(),
559  Val,
560  File,
561  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
562  ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
563  };
564  return DITemplateValueParameter(MDNode::get(VMContext, Elts));
565 }
566 
567 /// createTemplateValueParameter - Create debugging information for template
568 /// value parameter.
570 DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
571  DIType Ty, Value *Val,
572  MDNode *File, unsigned LineNo,
573  unsigned ColumnNo) {
574  return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
575  Context, Name, Ty, Val, File, LineNo,
576  ColumnNo);
577 }
578 
581  DIType Ty, StringRef Val,
582  MDNode *File, unsigned LineNo,
583  unsigned ColumnNo) {
584  return createTemplateValueParameter(
585  dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
586  MDString::get(VMContext, Val), File, LineNo, ColumnNo);
587 }
588 
591  DIType Ty, DIArray Val,
592  MDNode *File, unsigned LineNo,
593  unsigned ColumnNo) {
594  return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
595  Context, Name, Ty, Val, File, LineNo,
596  ColumnNo);
597 }
598 
599 /// createClassType - Create debugging information entry for a class.
601  DIFile File, unsigned LineNumber,
602  uint64_t SizeInBits,
603  uint64_t AlignInBits,
604  uint64_t OffsetInBits,
605  unsigned Flags, DIType DerivedFrom,
606  DIArray Elements,
607  DIType VTableHolder,
608  MDNode *TemplateParams,
609  StringRef UniqueIdentifier) {
610  assert((!Context || Context.isScope() || Context.isType()) &&
611  "createClassType should be called with a valid Context");
612  // TAG_class_type is encoded in DICompositeType format.
613  Value *Elts[] = {
614  GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
615  File.getFileNode(),
617  MDString::get(VMContext, Name),
618  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
619  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
620  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
621  ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
622  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
623  DerivedFrom.getRef(),
624  Elements,
625  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
626  VTableHolder.getRef(),
627  TemplateParams,
628  UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
629  };
630  DICompositeType R(MDNode::get(VMContext, Elts));
631  assert(R.isCompositeType() &&
632  "createClassType should return a DICompositeType");
633  if (!UniqueIdentifier.empty())
634  retainType(R);
635  return R;
636 }
637 
638 /// createStructType - Create debugging information entry for a struct.
640  StringRef Name, DIFile File,
641  unsigned LineNumber,
642  uint64_t SizeInBits,
643  uint64_t AlignInBits,
644  unsigned Flags, DIType DerivedFrom,
645  DIArray Elements,
646  unsigned RunTimeLang,
647  DIType VTableHolder,
648  StringRef UniqueIdentifier) {
649  // TAG_structure_type is encoded in DICompositeType format.
650  Value *Elts[] = {
651  GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
652  File.getFileNode(),
654  MDString::get(VMContext, Name),
655  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
656  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
657  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
658  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
659  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
660  DerivedFrom.getRef(),
661  Elements,
662  ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
663  VTableHolder.getRef(),
664  NULL,
665  UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
666  };
667  DICompositeType R(MDNode::get(VMContext, Elts));
668  assert(R.isCompositeType() &&
669  "createStructType should return a DICompositeType");
670  if (!UniqueIdentifier.empty())
671  retainType(R);
672  return R;
673 }
674 
675 /// createUnionType - Create debugging information entry for an union.
677  DIFile File, unsigned LineNumber,
678  uint64_t SizeInBits,
679  uint64_t AlignInBits, unsigned Flags,
680  DIArray Elements,
681  unsigned RunTimeLang,
682  StringRef UniqueIdentifier) {
683  // TAG_union_type is encoded in DICompositeType format.
684  Value *Elts[] = {
685  GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
686  File.getFileNode(),
688  MDString::get(VMContext, Name),
689  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
690  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
691  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
692  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
693  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
694  NULL,
695  Elements,
696  ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
697  NULL,
698  NULL,
699  UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
700  };
701  DICompositeType R(MDNode::get(VMContext, Elts));
702  if (!UniqueIdentifier.empty())
703  retainType(R);
704  return R;
705 }
706 
707 /// createSubroutineType - Create subroutine type.
709  DIArray ParameterTypes) {
710  // TAG_subroutine_type is encoded in DICompositeType format.
711  Value *Elts[] = {
712  GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
714  NULL,
715  MDString::get(VMContext, ""),
716  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
717  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
718  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
719  ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
720  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
721  NULL,
722  ParameterTypes,
723  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
724  NULL,
725  NULL,
726  NULL // Type Identifer
727  };
728  return DICompositeType(MDNode::get(VMContext, Elts));
729 }
730 
731 /// createEnumerationType - Create debugging information entry for an
732 /// enumeration.
734  DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
735  uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
736  DIType UnderlyingType, StringRef UniqueIdentifier) {
737  // TAG_enumeration_type is encoded in DICompositeType format.
738  Value *Elts[] = {
739  GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
740  File.getFileNode(),
742  MDString::get(VMContext, Name),
743  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
744  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
745  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
746  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
747  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
748  UnderlyingType.getRef(),
749  Elements,
750  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
751  NULL,
752  NULL,
753  UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
754  };
755  DICompositeType CTy(MDNode::get(VMContext, Elts));
756  AllEnumTypes.push_back(CTy);
757  if (!UniqueIdentifier.empty())
758  retainType(CTy);
759  return CTy;
760 }
761 
762 /// createArrayType - Create debugging information entry for an array.
763 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
764  DIType Ty, DIArray Subscripts) {
765  // TAG_array_type is encoded in DICompositeType format.
766  Value *Elts[] = {
767  GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
768  NULL, // Filename/Directory,
769  NULL, // Unused
770  MDString::get(VMContext, ""),
771  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
772  ConstantInt::get(Type::getInt64Ty(VMContext), Size),
773  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
774  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
775  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
776  Ty.getRef(),
777  Subscripts,
778  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
779  NULL,
780  NULL,
781  NULL // Type Identifer
782  };
783  return DICompositeType(MDNode::get(VMContext, Elts));
784 }
785 
786 /// createVectorType - Create debugging information entry for a vector.
787 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
788  DIType Ty, DIArray Subscripts) {
789  // A vector is an array type with the FlagVector flag applied.
790  Value *Elts[] = {
791  GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
792  NULL, // Filename/Directory,
793  NULL, // Unused
794  MDString::get(VMContext, ""),
795  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
796  ConstantInt::get(Type::getInt64Ty(VMContext), Size),
797  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
798  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
800  Ty.getRef(),
801  Subscripts,
802  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
803  NULL,
804  NULL,
805  NULL // Type Identifer
806  };
807  return DICompositeType(MDNode::get(VMContext, Elts));
808 }
809 
810 /// createArtificialType - Create a new DIType with "artificial" flag set.
812  if (Ty.isArtificial())
813  return Ty;
814 
816  MDNode *N = Ty;
817  assert (N && "Unexpected input DIType!");
818  for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
819  Elts.push_back(N->getOperand(i));
820 
821  unsigned CurFlags = Ty.getFlags();
822  CurFlags = CurFlags | DIType::FlagArtificial;
823 
824  // Flags are stored at this slot.
825  // FIXME: Add an enum for this magic value.
826  Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
827 
828  return DIType(MDNode::get(VMContext, Elts));
829 }
830 
831 /// createObjectPointerType - Create a new type with both the object pointer
832 /// and artificial flags set.
834  if (Ty.isObjectPointer())
835  return Ty;
836 
838  MDNode *N = Ty;
839  assert (N && "Unexpected input DIType!");
840  for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
841  Elts.push_back(N->getOperand(i));
842 
843  unsigned CurFlags = Ty.getFlags();
844  CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
845 
846  // Flags are stored at this slot.
847  // FIXME: Add an enum for this magic value.
848  Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
849 
850  return DIType(MDNode::get(VMContext, Elts));
851 }
852 
853 /// retainType - Retain DIType in a module even if it is not referenced
854 /// through debug info anchors.
856  AllRetainTypes.push_back(TrackingVH<MDNode>(T));
857 }
858 
859 /// createUnspecifiedParameter - Create unspeicified type descriptor
860 /// for the subroutine type.
862  Value *Elts[] = {
863  GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
864  };
865  return DIDescriptor(MDNode::get(VMContext, Elts));
866 }
867 
868 /// createForwardDecl - Create a temporary forward-declared type that
869 /// can be RAUW'd if the full type is seen.
872  DIFile F, unsigned Line, unsigned RuntimeLang,
873  uint64_t SizeInBits, uint64_t AlignInBits,
874  StringRef UniqueIdentifier) {
875  // Create a temporary MDNode.
876  Value *Elts[] = {
877  GetTagConstant(VMContext, Tag),
878  F.getFileNode(),
880  MDString::get(VMContext, Name),
881  ConstantInt::get(Type::getInt32Ty(VMContext), Line),
882  ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
883  ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
884  ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
886  NULL,
887  DIArray(),
888  ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
889  NULL,
890  NULL, //TemplateParams
891  UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
892  };
893  MDNode *Node = MDNode::getTemporary(VMContext, Elts);
894  DICompositeType RetTy(Node);
895  assert(RetTy.isCompositeType() &&
896  "createForwardDecl result should be a DIType");
897  if (!UniqueIdentifier.empty())
898  retainType(RetTy);
899  return RetTy;
900 }
901 
902 /// getOrCreateArray - Get a DIArray, create one if required.
904  if (Elements.empty()) {
905  Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
906  return DIArray(MDNode::get(VMContext, Null));
907  }
908  return DIArray(MDNode::get(VMContext, Elements));
909 }
910 
911 /// getOrCreateSubrange - Create a descriptor for a value range. This
912 /// implicitly uniques the values returned.
914  Value *Elts[] = {
915  GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
916  ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
917  ConstantInt::get(Type::getInt64Ty(VMContext), Count)
918  };
919 
920  return DISubrange(MDNode::get(VMContext, Elts));
921 }
922 
923 /// \brief Create a new descriptor for the specified global.
925  StringRef LinkageName,
926  DIFile F, unsigned LineNumber,
927  DIType Ty, bool isLocalToUnit,
928  Value *Val) {
929  Value *Elts[] = {
930  GetTagConstant(VMContext, dwarf::DW_TAG_variable),
932  NULL, // TheCU,
933  MDString::get(VMContext, Name),
934  MDString::get(VMContext, Name),
935  MDString::get(VMContext, LinkageName),
936  F,
937  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
938  Ty,
939  ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
940  ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
941  Val,
942  DIDescriptor()
943  };
944  MDNode *Node = MDNode::get(VMContext, Elts);
945  AllGVs.push_back(Node);
946  return DIGlobalVariable(Node);
947 }
948 
949 /// \brief Create a new descriptor for the specified global.
951  unsigned LineNumber, DIType Ty,
952  bool isLocalToUnit,
953  Value *Val) {
954  return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
955  Val);
956 }
957 
958 /// createStaticVariable - Create a new descriptor for the specified static
959 /// variable.
961  StringRef Name,
962  StringRef LinkageName,
963  DIFile F, unsigned LineNumber,
964  DIType Ty, bool isLocalToUnit,
965  Value *Val, MDNode *Decl) {
966  Value *Elts[] = {
967  GetTagConstant(VMContext, dwarf::DW_TAG_variable),
969  getNonCompileUnitScope(Context),
970  MDString::get(VMContext, Name),
971  MDString::get(VMContext, Name),
972  MDString::get(VMContext, LinkageName),
973  F,
974  ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
975  Ty,
976  ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
977  ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
978  Val,
979  DIDescriptor(Decl)
980  };
981  MDNode *Node = MDNode::get(VMContext, Elts);
982  AllGVs.push_back(Node);
983  return DIGlobalVariable(Node);
984 }
985 
986 /// createVariable - Create a new descriptor for the specified variable.
988  StringRef Name, DIFile File,
989  unsigned LineNo, DIType Ty,
990  bool AlwaysPreserve, unsigned Flags,
991  unsigned ArgNo) {
992  DIDescriptor Context(getNonCompileUnitScope(Scope));
993  assert((!Context || Context.isScope()) &&
994  "createLocalVariable should be called with a valid Context");
995  assert(Ty.isType() &&
996  "createLocalVariable should be called with a valid type");
997  Value *Elts[] = {
998  GetTagConstant(VMContext, Tag),
999  getNonCompileUnitScope(Scope),
1000  MDString::get(VMContext, Name),
1001  File,
1002  ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
1003  Ty,
1004  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1006  };
1007  MDNode *Node = MDNode::get(VMContext, Elts);
1008  if (AlwaysPreserve) {
1009  // The optimizer may remove local variable. If there is an interest
1010  // to preserve variable info in such situation then stash it in a
1011  // named mdnode.
1012  DISubprogram Fn(getDISubprogram(Scope));
1013  NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
1014  FnLocals->addOperand(Node);
1015  }
1016  DIVariable RetVar(Node);
1017  assert(RetVar.isVariable() &&
1018  "createLocalVariable should return a valid DIVariable");
1019  return RetVar;
1020 }
1021 
1022 /// createComplexVariable - Create a new descriptor for the specified variable
1023 /// which has a complex address expression for its address.
1025  StringRef Name, DIFile F,
1026  unsigned LineNo,
1027  DIType Ty, ArrayRef<Value *> Addr,
1028  unsigned ArgNo) {
1030  Elts.push_back(GetTagConstant(VMContext, Tag));
1031  Elts.push_back(getNonCompileUnitScope(Scope)),
1032  Elts.push_back(MDString::get(VMContext, Name));
1033  Elts.push_back(F);
1035  (LineNo | (ArgNo << 24))));
1036  Elts.push_back(Ty);
1039  Elts.append(Addr.begin(), Addr.end());
1040 
1041  return DIVariable(MDNode::get(VMContext, Elts));
1042 }
1043 
1044 /// createFunction - Create a new descriptor for the specified function.
1045 /// FIXME: this is added for dragonegg. Once we update dragonegg
1046 /// to call resolve function, this will be removed.
1048  StringRef LinkageName, DIFile File,
1049  unsigned LineNo, DICompositeType Ty,
1050  bool isLocalToUnit, bool isDefinition,
1051  unsigned ScopeLine, unsigned Flags,
1052  bool isOptimized, Function *Fn,
1053  MDNode *TParams, MDNode *Decl) {
1054  // dragonegg does not generate identifier for types, so using an empty map
1055  // to resolve the context should be fine.
1056  DITypeIdentifierMap EmptyMap;
1057  return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1058  LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1059  Flags, isOptimized, Fn, TParams, Decl);
1060 }
1061 
1062 /// createFunction - Create a new descriptor for the specified function.
1064  StringRef LinkageName, DIFile File,
1065  unsigned LineNo, DICompositeType Ty,
1066  bool isLocalToUnit, bool isDefinition,
1067  unsigned ScopeLine, unsigned Flags,
1068  bool isOptimized, Function *Fn,
1069  MDNode *TParams, MDNode *Decl) {
1070  assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1071  "function types should be subroutines");
1072  Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1073  Value *Elts[] = {
1074  GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1075  File.getFileNode(),
1077  MDString::get(VMContext, Name),
1078  MDString::get(VMContext, Name),
1079  MDString::get(VMContext, LinkageName),
1080  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1081  Ty,
1082  ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1083  ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1084  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1085  ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1086  NULL,
1087  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1088  ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1089  Fn,
1090  TParams,
1091  Decl,
1092  MDNode::getTemporary(VMContext, TElts),
1093  ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
1094  };
1095  MDNode *Node = MDNode::get(VMContext, Elts);
1096 
1097  // Create a named metadata so that we do not lose this mdnode.
1098  if (isDefinition)
1099  AllSubprograms.push_back(Node);
1100  DISubprogram S(Node);
1101  assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
1102  return S;
1103 }
1104 
1105 /// createMethod - Create a new descriptor for the specified C++ method.
1107  StringRef LinkageName, DIFile F,
1108  unsigned LineNo, DICompositeType Ty,
1109  bool isLocalToUnit, bool isDefinition,
1110  unsigned VK, unsigned VIndex,
1111  DIType VTableHolder, unsigned Flags,
1112  bool isOptimized, Function *Fn,
1113  MDNode *TParam) {
1114  assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1115  "function types should be subroutines");
1116  assert(getNonCompileUnitScope(Context) &&
1117  "Methods should have both a Context and a context that isn't "
1118  "the compile unit.");
1119  Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
1120  Value *Elts[] = {
1121  GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
1122  F.getFileNode(),
1123  DIScope(Context).getRef(),
1124  MDString::get(VMContext, Name),
1125  MDString::get(VMContext, Name),
1126  MDString::get(VMContext, LinkageName),
1127  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1128  Ty,
1129  ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1130  ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1131  ConstantInt::get(Type::getInt32Ty(VMContext), VK),
1132  ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1133  VTableHolder.getRef(),
1134  ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1135  ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
1136  Fn,
1137  TParam,
1139  MDNode::getTemporary(VMContext, TElts),
1140  // FIXME: Do we want to use different scope/lines?
1141  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1142  };
1143  MDNode *Node = MDNode::get(VMContext, Elts);
1144  if (isDefinition)
1145  AllSubprograms.push_back(Node);
1146  DISubprogram S(Node);
1147  assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
1148  return S;
1149 }
1150 
1151 /// createNameSpace - This creates new descriptor for a namespace
1152 /// with the specified parent scope.
1154  DIFile File, unsigned LineNo) {
1155  Value *Elts[] = {
1156  GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
1157  File.getFileNode(),
1158  getNonCompileUnitScope(Scope),
1159  MDString::get(VMContext, Name),
1160  ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1161  };
1162  DINameSpace R(MDNode::get(VMContext, Elts));
1163  assert(R.Verify() &&
1164  "createNameSpace should return a verifiable DINameSpace");
1165  return R;
1166 }
1167 
1168 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
1169 /// an existing scope with a new filename.
1171  DIFile File) {
1172  Value *Elts[] = {
1173  GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1174  File.getFileNode(),
1175  Scope
1176  };
1177  DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1178  assert(
1179  R.Verify() &&
1180  "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1181  return R;
1182 }
1183 
1185  unsigned Line, unsigned Col) {
1186  // Defeat MDNode uniquing for lexical blocks by using unique id.
1187  static unsigned int unique_id = 0;
1188  Value *Elts[] = {
1189  GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
1190  File.getFileNode(),
1191  getNonCompileUnitScope(Scope),
1192  ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1193  ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1194  ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1195  };
1196  DILexicalBlock R(MDNode::get(VMContext, Elts));
1197  assert(R.Verify() &&
1198  "createLexicalBlock should return a verifiable DILexicalBlock");
1199  return R;
1200 }
1201 
1202 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1204  Instruction *InsertBefore) {
1205  assert(Storage && "no storage passed to dbg.declare");
1206  assert(VarInfo.isVariable() &&
1207  "empty or invalid DIVariable passed to dbg.declare");
1208  if (!DeclareFn)
1210 
1211  Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1212  return CallInst::Create(DeclareFn, Args, "", InsertBefore);
1213 }
1214 
1215 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1217  BasicBlock *InsertAtEnd) {
1218  assert(Storage && "no storage passed to dbg.declare");
1219  assert(VarInfo.isVariable() &&
1220  "empty or invalid DIVariable passed to dbg.declare");
1221  if (!DeclareFn)
1223 
1224  Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
1225 
1226  // If this block already has a terminator then insert this intrinsic
1227  // before the terminator.
1228  if (TerminatorInst *T = InsertAtEnd->getTerminator())
1229  return CallInst::Create(DeclareFn, Args, "", T);
1230  else
1231  return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
1232 }
1233 
1234 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1236  DIVariable VarInfo,
1237  Instruction *InsertBefore) {
1238  assert(V && "no value passed to dbg.value");
1239  assert(VarInfo.isVariable() &&
1240  "empty or invalid DIVariable passed to dbg.value");
1241  if (!ValueFn)
1243 
1244  Value *Args[] = { MDNode::get(V->getContext(), V),
1246  VarInfo };
1247  return CallInst::Create(ValueFn, Args, "", InsertBefore);
1248 }
1249 
1250 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1252  DIVariable VarInfo,
1253  BasicBlock *InsertAtEnd) {
1254  assert(V && "no value passed to dbg.value");
1255  assert(VarInfo.isVariable() &&
1256  "empty or invalid DIVariable passed to dbg.value");
1257  if (!ValueFn)
1259 
1260  Value *Args[] = { MDNode::get(V->getContext(), V),
1262  VarInfo };
1263  return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
1264 }
void finalize()
finalize - Construct any deferred debug info descriptors.
Definition: DIBuilder.cpp:37
DICompileUnit createCompileUnit(unsigned Lang, StringRef File, StringRef Dir, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RV, StringRef SplitName=StringRef())
Definition: DIBuilder.cpp:96
DITemplateTypeParameter - This is a wrapper for template type parameter.
Definition: DebugInfo.h:537
static MDNode * getTemporary(LLVMContext &Context, ArrayRef< Value * > Vals)
Definition: Metadata.cpp:282
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:238
DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File, unsigned Line, unsigned Col)
Definition: DIBuilder.cpp:1184
DICompositeType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line, unsigned RuntimeLang=0, uint64_t SizeInBits=0, uint64_t AlignInBits=0, StringRef UniqueIdentifier=StringRef())
createForwardDecl - Create a temporary forward-declared type.
Definition: DIBuilder.cpp:871
DIObjCProperty createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber, StringRef GetterName, StringRef SetterName, unsigned PropertyAttributes, DIType Ty)
Definition: DIBuilder.cpp:514
DITemplateValueParameter createTemplateParameterPack(DIDescriptor Scope, StringRef Name, DIType Ty, DIArray Val, MDNode *File=0, unsigned LineNo=0, unsigned ColumnNo=0)
Create debugging information for a template parameter pack.
Definition: DIBuilder.cpp:590
bool isArtificial() const
Definition: DebugInfo.h:309
bool isVariable() const
isVariable - Return true if the specified tag is legal for DIVariable.
Definition: DebugInfo.cpp:206
void replaceAllUsesWith(DIDescriptor &D)
Definition: DebugInfo.cpp:336
bool isSubprogram() const
Definition: DebugInfo.cpp:225
uint16_t getTag() const
Definition: DebugInfo.h:121
DIGlobalVariable createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo, DIType Ty, bool isLocalToUnit, llvm::Value *Val)
Create a new descriptor for the specified global.
Definition: DIBuilder.cpp:950
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:38
DICompositeType createClassType(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom, DIArray Elements, DIType VTableHolder=DIType(), MDNode *TemplateParms=0, StringRef UniqueIdentifier=StringRef())
createClassType - Create debugging information entry for a class.
Definition: DIBuilder.cpp:600
bool Verify() const
Verify that the imported module descriptor is well formed.
Definition: DebugInfo.cpp:613
unsigned getNumOperands() const
getNumOperands - Return number of MDNode operands.
Definition: Metadata.h:142
iterator end() const
Definition: ArrayRef.h:98
DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope, StringRef Name, DIFile F, unsigned LineNo, DIType Ty, ArrayRef< Value * > Addr, unsigned ArgNo=0)
Definition: DIBuilder.cpp:1024
void addOperand(MDNode *M)
addOperand - Add metadata operand.
Definition: Metadata.cpp:551
bool insert(PtrType Ptr)
Definition: SmallPtrSet.h:253
DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNo)
Definition: DIBuilder.cpp:1153
void retainType(DIType T)
Definition: DIBuilder.cpp:855
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Definition: Module.cpp:295
DIFile createFile(StringRef Filename, StringRef Directory)
Definition: DIBuilder.cpp:203
static MDNode * createFilePathPair(LLVMContext &VMContext, StringRef Filename, StringRef Directory)
Definition: DIBuilder.cpp:84
MDNode - a tuple of other values.
Definition: Metadata.h:69
static MDNode * getNonCompileUnitScope(MDNode *N)
Definition: DIBuilder.cpp:78
F(f)
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:242
DIBasicType createNullPtrType()
Create C++11 nullptr type.
Definition: DIBuilder.cpp:243
DICompositeType createVectorType(uint64_t Size, uint64_t AlignInBits, DIType Ty, DIArray Subscripts)
createVectorType - Create debugging information entry for a vector.
Definition: DIBuilder.cpp:787
static MDNode * get(LLVMContext &Context, ArrayRef< Value * > Vals)
Definition: Metadata.cpp:268
static Constant * getNullValue(Type *Ty)
Definition: Constants.cpp:111
Value * getOperand(unsigned i) const LLVM_READONLY
getOperand - Return specified operand.
Definition: Metadata.cpp:307
DIArray - This descriptor holds an array of descriptors.
Definition: DebugInfo.h:167
DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNo, DIType Ty, bool AlwaysPreserve=false, unsigned Flags=0, unsigned ArgNo=0)
createVariable - Create a new descriptor for the specified variable.
Definition: DIBuilder.cpp:987
DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope, DIFile File)
Definition: DIBuilder.cpp:1170
bool Verify() const
Verify that the lexical block descriptor is well formed.
Definition: DebugInfo.cpp:593
DISubprogram createMethod(DIDescriptor Scope, StringRef Name, StringRef LinkageName, DIFile File, unsigned LineNo, DICompositeType Ty, bool isLocalToUnit, bool isDefinition, unsigned Virtuality=0, unsigned VTableIndex=0, DIType VTableHolder=DIType(), unsigned Flags=0, bool isOptimized=false, Function *Fn=0, MDNode *TParam=0)
createMethod - Create a new descriptor for the specified C++ method.
Definition: DIBuilder.cpp:1106
DISubrange - This is used to represent ranges, for array bounds.
Definition: DebugInfo.h:154
DIScopeRef getRef() const
Definition: DebugInfo.cpp:676
DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Definition: DebugInfo.h:429
bool isScope() const
Definition: DebugInfo.cpp:244
DICompositeType createEnumerationType(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements, DIType UnderlyingType, StringRef UniqueIdentifier=StringRef())
Definition: DIBuilder.cpp:733
DIDescriptor createUnspecifiedParameter()
Definition: DIBuilder.cpp:861
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Definition: Function.cpp:683
DIImportedEntity createImportedDeclaration(DIScope Context, DIDescriptor Decl, unsigned Line)
Create a descriptor for an imported function.
Definition: DIBuilder.cpp:186
static Constant * GetTagConstant(LLVMContext &VMContext, unsigned Tag)
Definition: DIBuilder.cpp:26
DIFile - This is a wrapper for a file.
Definition: DebugInfo.h:392
DIDerivedType createFriend(DIType Ty, DIType FriendTy)
createFriend - Create debugging information entry for a 'friend'.
Definition: DIBuilder.cpp:369
DICompositeType createArrayType(uint64_t Size, uint64_t AlignInBits, DIType Ty, DIArray Subscripts)
createArrayType - Create debugging information entry for an array.
Definition: DIBuilder.cpp:763
bool isType() const
isType - Return true if the specified tag is legal for DIType.
Definition: DebugInfo.cpp:219
DILexicalBlock - This is a wrapper for a lexical block.
Definition: DebugInfo.h:498
DISubprogram getDISubprogram(const MDNode *Scope)
getDISubprogram - Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:885
DITemplateValueParameter - This is a wrapper for template value parameter.
Definition: DebugInfo.h:554
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
DIDerivedType createPointerType(DIType PointeeTy, uint64_t SizeInBits, uint64_t AlignInBits=0, StringRef Name=StringRef())
createPointerType - Create debugging information entry for a pointer.
Definition: DIBuilder.cpp:291
DIDescriptor getElement(unsigned Idx) const
Definition: DebugInfo.h:172
LLVM Constant Representation.
Definition: Constant.h:41
DIArray getOrCreateArray(ArrayRef< Value * > Elements)
getOrCreateArray - Get a DIArray, create one if required.
Definition: DIBuilder.cpp:903
Instruction * insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, DIVariable VarInfo, BasicBlock *InsertAtEnd)
insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Definition: DIBuilder.cpp:1251
DIType createObjectPointerType(DIType Ty)
Definition: DIBuilder.cpp:833
DIGlobalVariable - This is a wrapper for a global variable.
Definition: DebugInfo.h:572
iterator begin() const
Definition: ArrayRef.h:97
DIDerivedType createReferenceType(unsigned Tag, DIType RTy)
Definition: DIBuilder.cpp:330
bool Verify() const
Verify that the file-scoped lexical block descriptor is well formed.
Definition: DebugInfo.cpp:598
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:104
unsigned getNumElements() const
Definition: DebugInfo.cpp:328
void append(in_iter in_start, in_iter in_end)
Definition: SmallVector.h:445
bool isObjectPointer() const
Definition: DebugInfo.h:310
DIDerivedType createStaticMemberType(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNo, DIType Ty, unsigned Flags, llvm::Value *Val)
Definition: DIBuilder.cpp:436
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:517
Instruction * insertDeclare(llvm::Value *Storage, DIVariable VarInfo, BasicBlock *InsertAtEnd)
insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Definition: DIBuilder.cpp:1216
DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count)
Definition: DIBuilder.cpp:913
An imported module (C++ using directive or similar).
Definition: DebugInfo.h:716
DIScope - A base class for various scopes.
Definition: DebugInfo.h:197
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
DIDerivedType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNo, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType Ty)
createMemberType - Create debugging information entry for a member.
Definition: DIBuilder.cpp:411
T resolve(const DITypeIdentifierMap &Map) const
Definition: DebugInfo.h:238
DIBasicType createUnspecifiedType(StringRef Name)
Create a DWARF unspecified type.
Definition: DIBuilder.cpp:223
DINameSpace - A wrapper for a C++ style name space.
Definition: DebugInfo.h:524
NamedMDNode * getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP)
Definition: DebugInfo.cpp:855
DICompositeType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, DIArray Elements, unsigned RunTimeLang=0, StringRef UniqueIdentifier=StringRef())
createUnionType - Create debugging information entry for an union.
Definition: DIBuilder.cpp:676
DIImportedEntity createImportedModule(DIScope Context, DINameSpace NS, unsigned Line, StringRef Name=StringRef())
Create a descriptor for an imported module.
Definition: DIBuilder.cpp:171
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
Definition: Constants.cpp:492
DITemplateValueParameter createTemplateTemplateParameter(DIDescriptor Scope, StringRef Name, DIType Ty, StringRef Val, MDNode *File=0, unsigned LineNo=0, unsigned ColumnNo=0)
Create debugging information for a template template parameter.
Definition: DIBuilder.cpp:580
DIDerivedType createMemberPointerType(DIType PointeeTy, DIType Class)
Create debugging information entry for a pointer to member.
Definition: DIBuilder.cpp:309
DIDerivedType createQualifiedType(unsigned Tag, DIType FromTy)
Definition: DIBuilder.cpp:272
DIDerivedType createTypedef(DIType Ty, StringRef Name, DIFile File, unsigned LineNo, DIDescriptor Context)
createTypedef - Create debugging information entry for a typedef.
Definition: DIBuilder.cpp:349
static DIImportedEntity createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS, unsigned Line, StringRef Name, SmallVectorImpl< Value * > &AllImportedModules)
Definition: DIBuilder.cpp:143
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:241
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:120
bool isCompositeType() const
Definition: DebugInfo.cpp:189
unsigned getFlags() const
Definition: DebugInfo.h:297
DITemplateTypeParameter createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty, MDNode *File=0, unsigned LineNo=0, unsigned ColumnNo=0)
Definition: DIBuilder.cpp:533
LLVM Value Representation.
Definition: Value.h:66
DIGlobalVariable createStaticVariable(DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile File, unsigned LineNo, DIType Ty, bool isLocalToUnit, llvm::Value *Val, MDNode *Decl=NULL)
Definition: DIBuilder.cpp:960
DISubprogram createFunction(DIDescriptor Scope, StringRef Name, StringRef LinkageName, DIFile File, unsigned LineNo, DICompositeType Ty, bool isLocalToUnit, bool isDefinition, unsigned ScopeLine, unsigned Flags=0, bool isOptimized=false, Function *Fn=0, MDNode *TParam=0, MDNode *Decl=0)
createFunction - Create a new descriptor for the specified function.
Definition: DIBuilder.cpp:1063
DIDerivedType createObjCIVar(StringRef Name, DIFile File, unsigned LineNo, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType Ty, StringRef PropertyName=StringRef(), StringRef PropertyGetterName=StringRef(), StringRef PropertySetterName=StringRef(), unsigned PropertyAttributes=0)
Definition: DIBuilder.cpp:461
DIBasicType createBasicType(StringRef Name, uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding)
Definition: DIBuilder.cpp:250
DIDerivedType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset, unsigned Flags)
Definition: DIBuilder.cpp:390
DIEnumerator createEnumerator(StringRef Name, int64_t Val)
createEnumerator - Create a single enumerator value.
Definition: DIBuilder.cpp:212
bool Verify() const
Verify - Verify that a namespace descriptor is well formed.
Definition: DebugInfo.cpp:568
NamedMDNode * getFnSpecificMDNode(const Module &M, DISubprogram SP)
Definition: DebugInfo.cpp:847
DICompositeType createSubroutineType(DIFile File, DIArray ParameterTypes)
createSubroutineType - Create subroutine type.
Definition: DIBuilder.cpp:708
DICompileUnit - A wrapper for a compile unit.
Definition: DebugInfo.h:402
DICompositeType createStructType(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, DIType DerivedFrom, DIArray Elements, unsigned RunTimeLang=0, DIType VTableHolder=DIType(), StringRef UniqueIdentifier=StringRef())
createStructType - Create debugging information entry for a struct.
Definition: DIBuilder.cpp:639
DIType createArtificialType(DIType Ty)
createArtificialType - Create a new DIType with "artificial" flag set.
Definition: DIBuilder.cpp:811
MDNode * getFileNode() const
Retrieve the MDNode for the directory/file pair.
Definition: DebugInfo.cpp:575
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
DIBasicType - A basic type, like 'int' or 'float'.
Definition: DebugInfo.h:325