blob: 505e5659f9a5dc5558caa22cca7c60c3a5dc8e24 [file] [log] [blame]
Devang Patel35fcd652010-11-04 15:01:38 +00001//===--- 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
Bill Wendling16eeb6f2012-06-29 08:32:07 +000014#include "llvm/DIBuilder.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000015#include "llvm/ADT/STLExtras.h"
Bill Wendling0bcbd1d2012-06-28 00:05:13 +000016#include "llvm/DebugInfo.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000017#include "llvm/IR/Constants.h"
18#include "llvm/IR/IntrinsicInst.h"
19#include "llvm/IR/Module.h"
Eric Christopher6126a1e2012-04-03 00:43:49 +000020#include "llvm/Support/Debug.h"
Devang Patel35fcd652010-11-04 15:01:38 +000021#include "llvm/Support/Dwarf.h"
22
23using namespace llvm;
24using namespace llvm::dwarf;
25
26static 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}
Devang Patel48f17ba2010-12-07 23:58:00 +000031
Devang Patel35fcd652010-11-04 15:01:38 +000032DIBuilder::DIBuilder(Module &m)
Eric Christopher1fe3f9a2013-07-19 00:51:47 +000033 : M(m), VMContext(M.getContext()), TempEnumTypes(0),
Eric Christopher6c0046f2011-08-26 21:02:40 +000034 TempRetainTypes(0), TempSubprograms(0), TempGVs(0), DeclareFn(0),
35 ValueFn(0)
Devang Patel94c7ddb2011-08-16 22:09:43 +000036{}
Devang Patel35fcd652010-11-04 15:01:38 +000037
Devang Patel6326a422011-08-15 23:00:00 +000038/// finalize - Construct any deferred debug info descriptors.
39void DIBuilder::finalize() {
Devang Patel94c7ddb2011-08-16 22:09:43 +000040 DIArray Enums = getOrCreateArray(AllEnumTypes);
41 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
42
43 DIArray RetainTypes = getOrCreateArray(AllRetainTypes);
44 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
45
46 DIArray SPs = getOrCreateArray(AllSubprograms);
47 DIType(TempSubprograms).replaceAllUsesWith(SPs);
Devang Patel93d39be2011-08-19 23:28:12 +000048 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
49 DISubprogram SP(SPs.getElement(i));
Eric Christopher216432d2012-04-23 19:00:11 +000050 SmallVector<Value *, 4> Variables;
Devang Patel93d39be2011-08-19 23:28:12 +000051 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
Devang Patel93d39be2011-08-19 23:28:12 +000052 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
53 Variables.push_back(NMD->getOperand(ii));
Devang Patel93d39be2011-08-19 23:28:12 +000054 NMD->eraseFromParent();
55 }
Eric Christopher216432d2012-04-23 19:00:11 +000056 if (MDNode *Temp = SP.getVariablesNodes()) {
57 DIArray AV = getOrCreateArray(Variables);
58 DIType(Temp).replaceAllUsesWith(AV);
59 }
Devang Patel93d39be2011-08-19 23:28:12 +000060 }
Devang Patel94c7ddb2011-08-16 22:09:43 +000061
62 DIArray GVs = getOrCreateArray(AllGVs);
63 DIType(TempGVs).replaceAllUsesWith(GVs);
David Blaikiec462db62013-04-22 06:12:31 +000064
65 DIArray IMs = getOrCreateArray(AllImportedModules);
66 DIType(TempImportedModules).replaceAllUsesWith(IMs);
Devang Patel94c7ddb2011-08-16 22:09:43 +000067}
68
Eric Christopher6c0046f2011-08-26 21:02:40 +000069/// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
70/// N.
Devang Patel94c7ddb2011-08-16 22:09:43 +000071static MDNode *getNonCompileUnitScope(MDNode *N) {
72 if (DIDescriptor(N).isCompileUnit())
73 return NULL;
74 return N;
Devang Patel6326a422011-08-15 23:00:00 +000075}
76
David Blaikie00c5c5d2013-03-20 23:58:12 +000077static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
78 StringRef Directory) {
79 assert(!Filename.empty() && "Unable to create file without name");
80 Value *Pair[] = {
81 MDString::get(VMContext, Filename),
82 MDString::get(VMContext, Directory),
83 };
84 return MDNode::get(VMContext, Pair);
85}
86
Devang Patel50d280c2011-02-22 18:56:12 +000087/// createCompileUnit - A CompileUnit provides an anchor for all debugging
Devang Patel35fcd652010-11-04 15:01:38 +000088/// information generated during this instance of compilation.
Eric Christopher1fe3f9a2013-07-19 00:51:47 +000089DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
90 StringRef Directory,
91 StringRef Producer, bool isOptimized,
92 StringRef Flags, unsigned RunTimeVer,
93 StringRef SplitName) {
Chandler Carruthb0dc4d92012-01-10 18:18:52 +000094 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
95 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
96 "Invalid Language tag");
97 assert(!Filename.empty() &&
98 "Unable to create compile unit without filename");
Devang Patel94c7ddb2011-08-16 22:09:43 +000099 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
100 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000101
102 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000103
104 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000105
106 TempGVs = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000107
David Blaikiec462db62013-04-22 06:12:31 +0000108 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
109
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000110 Value *Elts[] = {
111 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
David Blaikie00c5c5d2013-03-20 23:58:12 +0000112 createFilePathPair(VMContext, Filename, Directory),
David Blaikie162c8002013-03-20 22:52:54 +0000113 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000114 MDString::get(VMContext, Producer),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000115 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
116 MDString::get(VMContext, Flags),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000117 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
David Blaikiea8eefc72013-02-02 05:56:24 +0000118 TempEnumTypes,
119 TempRetainTypes,
120 TempSubprograms,
Eric Christophere4b67902013-02-22 23:50:04 +0000121 TempGVs,
David Blaikiec462db62013-04-22 06:12:31 +0000122 TempImportedModules,
Eric Christophere4b67902013-02-22 23:50:04 +0000123 MDString::get(VMContext, SplitName)
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000124 };
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000125
126 MDNode *CUNode = MDNode::get(VMContext, Elts);
Devang Patel464f4ef2011-05-03 16:18:28 +0000127
128 // Create a named metadata so that it is easier to find cu in a module.
129 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000130 NMD->addOperand(CUNode);
131
132 return DICompileUnit(CUNode);
Devang Patel35fcd652010-11-04 15:01:38 +0000133}
134
David Blaikie7b72cc72013-05-20 22:50:35 +0000135static DIImportedEntity
136createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
137 unsigned Line, StringRef Name,
138 SmallVectorImpl<Value *> &AllImportedModules) {
139 const MDNode *R;
140 if (Name.empty()) {
141 Value *Elts[] = {
142 GetTagConstant(C, dwarf::DW_TAG_imported_module),
143 Context,
144 NS,
145 ConstantInt::get(Type::getInt32Ty(C), Line),
146 };
147 R = MDNode::get(C, Elts);
148 } else {
149 Value *Elts[] = {
150 GetTagConstant(C, dwarf::DW_TAG_imported_module),
151 Context,
152 NS,
153 ConstantInt::get(Type::getInt32Ty(C), Line),
154 MDString::get(C, Name)
155 };
156 R = MDNode::get(C, Elts);
157 }
158 DIImportedEntity M(R);
David Blaikie20d9e412013-05-07 21:35:53 +0000159 assert(M.Verify() && "Imported module should be valid");
160 AllImportedModules.push_back(M);
161 return M;
162}
163
David Blaikie7b72cc72013-05-20 22:50:35 +0000164DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
165 DINameSpace NS, unsigned Line,
166 StringRef Name) {
167 return ::createImportedModule(VMContext, Context, NS, Line, Name,
168 AllImportedModules);
169}
170
171DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
172 DIImportedEntity NS,
173 unsigned Line,
174 StringRef Name) {
175 return ::createImportedModule(VMContext, Context, NS, Line, Name,
176 AllImportedModules);
177}
178
David Blaikie20d9e412013-05-07 21:35:53 +0000179DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
180 DIDescriptor Decl,
181 unsigned Line) {
182 Value *Elts[] = {
183 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
184 Context,
185 Decl,
186 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
187 };
188 DIImportedEntity M(MDNode::get(VMContext, Elts));
David Blaikiec462db62013-04-22 06:12:31 +0000189 assert(M.Verify() && "Imported module should be valid");
190 AllImportedModules.push_back(M);
191 return M;
192}
193
Devang Patel50d280c2011-02-22 18:56:12 +0000194/// createFile - Create a file descriptor to hold debugging information
Devang Patel35fcd652010-11-04 15:01:38 +0000195/// for a file.
Devang Patel50d280c2011-02-22 18:56:12 +0000196DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
David Blaikieb4cf0ab2013-03-17 21:13:55 +0000197 Value *Elts[] = {
198 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
David Blaikie72dfb052013-03-28 02:44:59 +0000199 createFilePathPair(VMContext, Filename, Directory)
David Blaikieb4cf0ab2013-03-17 21:13:55 +0000200 };
David Blaikie72dfb052013-03-28 02:44:59 +0000201 return DIFile(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000202}
203
Devang Patel50d280c2011-02-22 18:56:12 +0000204/// createEnumerator - Create a single enumerator value.
David Blaikie8de0a462013-06-24 17:34:33 +0000205DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
Devang Patel811ae5b2011-09-12 18:26:08 +0000206 assert(!Name.empty() && "Unable to create enumerator without name");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000207 Value *Elts[] = {
208 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
209 MDString::get(VMContext, Name),
210 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
211 };
David Blaikie72dfb052013-03-28 02:44:59 +0000212 return DIEnumerator(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000213}
214
Peter Collingbourne03ccdb52013-06-27 22:50:59 +0000215/// \brief Create a DWARF unspecified type.
216DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel734a67c2011-09-14 23:13:28 +0000217 assert(!Name.empty() && "Unable to create type without name");
Peter Collingbourne03ccdb52013-06-27 22:50:59 +0000218 // Unspecified types are encoded in DIBasicType format. Line number, filename,
219 // size, alignment, offset and flags are always empty here.
Devang Patel734a67c2011-09-14 23:13:28 +0000220 Value *Elts[] = {
221 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000222 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000223 NULL, // Unused
Devang Patel734a67c2011-09-14 23:13:28 +0000224 MDString::get(VMContext, Name),
Devang Patel734a67c2011-09-14 23:13:28 +0000225 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
226 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
227 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
228 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
229 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000230 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
Devang Patel734a67c2011-09-14 23:13:28 +0000231 };
Manman Ren576d49a2013-06-07 18:35:53 +0000232 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel734a67c2011-09-14 23:13:28 +0000233}
234
Peter Collingbourne03ccdb52013-06-27 22:50:59 +0000235/// \brief Create C++11 nullptr type.
236DIBasicType DIBuilder::createNullPtrType() {
237 return createUnspecifiedType("decltype(nullptr)");
238}
239
Eric Christopher6c0046f2011-08-26 21:02:40 +0000240/// createBasicType - Create debugging information entry for a basic
Devang Patel35fcd652010-11-04 15:01:38 +0000241/// type, e.g 'char'.
David Blaikie2ce067a2013-02-12 00:40:41 +0000242DIBasicType
243DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
244 uint64_t AlignInBits, unsigned Encoding) {
Devang Patel811ae5b2011-09-12 18:26:08 +0000245 assert(!Name.empty() && "Unable to create type without name");
Devang Patel35fcd652010-11-04 15:01:38 +0000246 // Basic types are encoded in DIBasicType format. Line number, filename,
247 // offset and flags are always empty here.
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000248 Value *Elts[] = {
249 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000250 NULL, // File/directory name
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000251 NULL, // Unused
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000252 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000253 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
254 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
255 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
256 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
257 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
258 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
259 };
David Blaikie72dfb052013-03-28 02:44:59 +0000260 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000261}
262
Nick Lewyckyffab7d02011-11-09 22:45:04 +0000263/// createQualifiedType - Create debugging information entry for a qualified
Devang Patel35fcd652010-11-04 15:01:38 +0000264/// type, e.g. 'const int'.
David Blaikied67c5ca2013-02-18 06:41:57 +0000265DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000266 // Qualified types are encoded in DIDerivedType format.
267 Value *Elts[] = {
268 GetTagConstant(VMContext, Tag),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000269 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000270 NULL, // Unused
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000271 MDString::get(VMContext, StringRef()), // Empty name.
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000272 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
273 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
274 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
275 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
276 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
277 FromTy
278 };
David Blaikie72dfb052013-03-28 02:44:59 +0000279 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000280}
281
Devang Patel50d280c2011-02-22 18:56:12 +0000282/// createPointerType - Create debugging information entry for a pointer.
David Blaikied67c5ca2013-02-18 06:41:57 +0000283DIDerivedType
284DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
285 uint64_t AlignInBits, StringRef Name) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000286 // Pointer types are encoded in DIDerivedType format.
287 Value *Elts[] = {
288 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000289 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000290 NULL, // Unused
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000291 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000292 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
293 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
294 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
295 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
296 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
297 PointeeTy
298 };
David Blaikie72dfb052013-03-28 02:44:59 +0000299 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000300}
301
Eric Christopher09b79812013-04-19 20:37:12 +0000302DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
303 DIType Base) {
David Blaikie62fdfb52013-01-07 05:51:15 +0000304 // Pointer types are encoded in DIDerivedType format.
305 Value *Elts[] = {
306 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000307 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000308 NULL, // Unused
David Blaikie62fdfb52013-01-07 05:51:15 +0000309 NULL,
David Blaikie62fdfb52013-01-07 05:51:15 +0000310 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
311 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
312 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
313 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
314 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
315 PointeeTy,
316 Base
317 };
David Blaikie72dfb052013-03-28 02:44:59 +0000318 return DIDerivedType(MDNode::get(VMContext, Elts));
David Blaikie62fdfb52013-01-07 05:51:15 +0000319}
320
Eric Christopher791e6292012-05-19 01:36:37 +0000321/// createReferenceType - Create debugging information entry for a reference
322/// type.
David Blaikied67c5ca2013-02-18 06:41:57 +0000323DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
Manman Ren89c83b72013-07-01 21:02:01 +0000324 assert(RTy.isType() && "Unable to create reference type");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000325 // References are encoded in DIDerivedType format.
326 Value *Elts[] = {
Eric Christopher791e6292012-05-19 01:36:37 +0000327 GetTagConstant(VMContext, Tag),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000328 NULL, // Filename
Eric Christopher6c0046f2011-08-26 21:02:40 +0000329 NULL, // TheCU,
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000330 NULL, // Name
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000331 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
332 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
333 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
334 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
335 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
336 RTy
337 };
David Blaikie72dfb052013-03-28 02:44:59 +0000338 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000339}
340
Devang Patel50d280c2011-02-22 18:56:12 +0000341/// createTypedef - Create debugging information entry for a typedef.
David Blaikied67c5ca2013-02-18 06:41:57 +0000342DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
343 unsigned LineNo, DIDescriptor Context) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000344 // typedefs are encoded in DIDerivedType format.
Manman Ren89c83b72013-07-01 21:02:01 +0000345 assert(Ty.isType() && "Invalid typedef type!");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000346 Value *Elts[] = {
347 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
David Blaikie4776bce2013-03-20 00:26:26 +0000348 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000349 getNonCompileUnitScope(Context),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000350 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000351 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
352 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
353 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
354 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
355 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
356 Ty
357 };
David Blaikie72dfb052013-03-28 02:44:59 +0000358 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000359}
360
Devang Patel50d280c2011-02-22 18:56:12 +0000361/// createFriend - Create debugging information entry for a 'friend'.
Manman Ren576d49a2013-06-07 18:35:53 +0000362DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000363 // typedefs are encoded in DIDerivedType format.
Manman Ren89c83b72013-07-01 21:02:01 +0000364 assert(Ty.isType() && "Invalid type!");
365 assert(FriendTy.isType() && "Invalid friend type!");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000366 Value *Elts[] = {
367 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000368 NULL,
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000369 Ty,
370 NULL, // Name
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000371 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
372 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
373 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
374 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
375 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
376 FriendTy
377 };
Manman Ren576d49a2013-06-07 18:35:53 +0000378 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000379}
380
Devang Patel50d280c2011-02-22 18:56:12 +0000381/// createInheritance - Create debugging information entry to establish
Eric Christopherc27c7342011-09-12 19:58:22 +0000382/// inheritance relationship between two types.
David Blaikied67c5ca2013-02-18 06:41:57 +0000383DIDerivedType DIBuilder::createInheritance(
384 DIType Ty, DIType BaseTy, uint64_t BaseOffset, unsigned Flags) {
Manman Ren89c83b72013-07-01 21:02:01 +0000385 assert(Ty.isType() && "Unable to create inheritance");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000386 // TAG_inheritance is encoded in DIDerivedType format.
387 Value *Elts[] = {
388 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000389 NULL,
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000390 Ty,
391 NULL, // Name
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000392 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
393 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
394 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
395 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
396 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
397 BaseTy
398 };
David Blaikie72dfb052013-03-28 02:44:59 +0000399 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000400}
401
Devang Patel50d280c2011-02-22 18:56:12 +0000402/// createMemberType - Create debugging information entry for a member.
David Blaikied67c5ca2013-02-18 06:41:57 +0000403DIDerivedType DIBuilder::createMemberType(
404 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
405 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
406 unsigned Flags, DIType Ty) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000407 // TAG_member is encoded in DIDerivedType format.
408 Value *Elts[] = {
409 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000410 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000411 getNonCompileUnitScope(Scope),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000412 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000413 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
414 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
415 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
416 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
417 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
418 Ty
419 };
David Blaikie72dfb052013-03-28 02:44:59 +0000420 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000421}
422
Eric Christopher6b6061f2013-01-16 01:22:23 +0000423/// createStaticMemberType - Create debugging information entry for a
424/// C++ static data member.
Manman Ren576d49a2013-06-07 18:35:53 +0000425DIDerivedType
426DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
427 DIFile File, unsigned LineNumber,
428 DIType Ty, unsigned Flags,
429 llvm::Value *Val) {
Eric Christopher6b6061f2013-01-16 01:22:23 +0000430 // TAG_member is encoded in DIDerivedType format.
431 Flags |= DIDescriptor::FlagStaticMember;
432 Value *Elts[] = {
433 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000434 File.getFileNode(),
Eric Christopher6b6061f2013-01-16 01:22:23 +0000435 getNonCompileUnitScope(Scope),
436 MDString::get(VMContext, Name),
Eric Christopher6b6061f2013-01-16 01:22:23 +0000437 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
438 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*SizeInBits*/),
439 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*AlignInBits*/),
440 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*OffsetInBits*/),
441 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
442 Ty,
443 Val
444 };
Manman Ren576d49a2013-06-07 18:35:53 +0000445 return DIDerivedType(MDNode::get(VMContext, Elts));
Eric Christopher6b6061f2013-01-16 01:22:23 +0000446}
447
Devang Patele9db5e22011-04-16 00:11:51 +0000448/// createObjCIVar - Create debugging information entry for Objective-C
449/// instance variable.
Manman Ren576d49a2013-06-07 18:35:53 +0000450DIDerivedType
451DIBuilder::createObjCIVar(StringRef Name,
452 DIFile File, unsigned LineNumber,
453 uint64_t SizeInBits, uint64_t AlignInBits,
454 uint64_t OffsetInBits, unsigned Flags,
455 DIType Ty, StringRef PropertyName,
456 StringRef GetterName, StringRef SetterName,
457 unsigned PropertyAttributes) {
Devang Patele9db5e22011-04-16 00:11:51 +0000458 // TAG_member is encoded in DIDerivedType format.
459 Value *Elts[] = {
460 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000461 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000462 getNonCompileUnitScope(File),
Devang Patele9db5e22011-04-16 00:11:51 +0000463 MDString::get(VMContext, Name),
Devang Patele9db5e22011-04-16 00:11:51 +0000464 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
465 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
466 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
467 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
468 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
469 Ty,
470 MDString::get(VMContext, PropertyName),
471 MDString::get(VMContext, GetterName),
472 MDString::get(VMContext, SetterName),
473 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
474 };
Manman Ren576d49a2013-06-07 18:35:53 +0000475 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patele9db5e22011-04-16 00:11:51 +0000476}
477
Devang Patel6588abf2012-02-06 17:49:43 +0000478/// createObjCIVar - Create debugging information entry for Objective-C
479/// instance variable.
Manman Ren576d49a2013-06-07 18:35:53 +0000480DIDerivedType
481DIBuilder::createObjCIVar(StringRef Name,
482 DIFile File, unsigned LineNumber,
483 uint64_t SizeInBits, uint64_t AlignInBits,
484 uint64_t OffsetInBits, unsigned Flags,
485 DIType Ty, MDNode *PropertyNode) {
Devang Patel6588abf2012-02-06 17:49:43 +0000486 // TAG_member is encoded in DIDerivedType format.
487 Value *Elts[] = {
488 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000489 File.getFileNode(),
Devang Patel6588abf2012-02-06 17:49:43 +0000490 getNonCompileUnitScope(File),
491 MDString::get(VMContext, Name),
Devang Patel6588abf2012-02-06 17:49:43 +0000492 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
493 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
494 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
495 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
496 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
497 Ty,
498 PropertyNode
499 };
Manman Ren576d49a2013-06-07 18:35:53 +0000500 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel6588abf2012-02-06 17:49:43 +0000501}
502
Devang Patel1ea02d42012-02-04 00:59:25 +0000503/// createObjCProperty - Create debugging information entry for Objective-C
504/// property.
Eric Christopherb8ca9882012-03-29 08:42:56 +0000505DIObjCProperty DIBuilder::createObjCProperty(StringRef Name,
Eric Christopher87c06a82012-07-06 02:35:57 +0000506 DIFile File, unsigned LineNumber,
Devang Patel1ea02d42012-02-04 00:59:25 +0000507 StringRef GetterName,
Adrian Prantl2f445be2013-04-19 19:56:02 +0000508 StringRef SetterName,
Eric Christopherb8ca9882012-03-29 08:42:56 +0000509 unsigned PropertyAttributes,
Eric Christopher87c06a82012-07-06 02:35:57 +0000510 DIType Ty) {
Devang Patel1ea02d42012-02-04 00:59:25 +0000511 Value *Elts[] = {
Eric Christopher6c31ee22012-03-29 21:35:05 +0000512 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
Devang Patel1ea02d42012-02-04 00:59:25 +0000513 MDString::get(VMContext, Name),
Eric Christopherb8ca9882012-03-29 08:42:56 +0000514 File,
515 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Devang Patel1ea02d42012-02-04 00:59:25 +0000516 MDString::get(VMContext, GetterName),
517 MDString::get(VMContext, SetterName),
Eric Christopherb8ca9882012-03-29 08:42:56 +0000518 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
519 Ty
Devang Patel1ea02d42012-02-04 00:59:25 +0000520 };
David Blaikie72dfb052013-03-28 02:44:59 +0000521 return DIObjCProperty(MDNode::get(VMContext, Elts));
Devang Patel1ea02d42012-02-04 00:59:25 +0000522}
523
Devang Patel50d280c2011-02-22 18:56:12 +0000524/// createTemplateTypeParameter - Create debugging information for template
Devang Patel7e2cb112011-02-02 21:38:25 +0000525/// type parameter.
Eric Christopher6c0046f2011-08-26 21:02:40 +0000526DITemplateTypeParameter
Devang Patel50d280c2011-02-22 18:56:12 +0000527DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
Devang Patel7e2cb112011-02-02 21:38:25 +0000528 DIType Ty, MDNode *File, unsigned LineNo,
529 unsigned ColumnNo) {
530 Value *Elts[] = {
531 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000532 getNonCompileUnitScope(Context),
Devang Patel7e2cb112011-02-02 21:38:25 +0000533 MDString::get(VMContext, Name),
534 Ty,
535 File,
536 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
537 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
538 };
David Blaikie72dfb052013-03-28 02:44:59 +0000539 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
Devang Patel7e2cb112011-02-02 21:38:25 +0000540}
541
Eric Christopher6c0046f2011-08-26 21:02:40 +0000542DITemplateValueParameter
David Blaikiee88939c2013-06-22 18:59:11 +0000543DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
544 StringRef Name, DIType Ty,
545 Value *Val, MDNode *File,
546 unsigned LineNo,
Devang Patele7d93872011-02-02 22:35:53 +0000547 unsigned ColumnNo) {
548 Value *Elts[] = {
David Blaikiee88939c2013-06-22 18:59:11 +0000549 GetTagConstant(VMContext, Tag),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000550 getNonCompileUnitScope(Context),
Devang Patele7d93872011-02-02 22:35:53 +0000551 MDString::get(VMContext, Name),
552 Ty,
David Blaikie4de9d722013-05-10 21:52:07 +0000553 Val,
Devang Patele7d93872011-02-02 22:35:53 +0000554 File,
555 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
556 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
557 };
David Blaikie72dfb052013-03-28 02:44:59 +0000558 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
Devang Patele7d93872011-02-02 22:35:53 +0000559}
560
David Blaikiee88939c2013-06-22 18:59:11 +0000561/// createTemplateValueParameter - Create debugging information for template
562/// value parameter.
563DITemplateValueParameter
564DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
565 DIType Ty, Value *Val,
566 MDNode *File, unsigned LineNo,
567 unsigned ColumnNo) {
568 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
569 Context, Name, Ty, Val, File, LineNo,
570 ColumnNo);
571}
572
573DITemplateValueParameter
574DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
575 DIType Ty, StringRef Val,
576 MDNode *File, unsigned LineNo,
577 unsigned ColumnNo) {
578 return createTemplateValueParameter(
579 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
580 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
581}
582
583DITemplateValueParameter
584DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
585 DIType Ty, DIArray Val,
586 MDNode *File, unsigned LineNo,
587 unsigned ColumnNo) {
588 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
589 Context, Name, Ty, Val, File, LineNo,
590 ColumnNo);
591}
592
Eric Christopher87c06a82012-07-06 02:35:57 +0000593/// createClassType - Create debugging information entry for a class.
David Blaikieca442a42013-03-26 23:46:39 +0000594DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
595 DIFile File, unsigned LineNumber,
596 uint64_t SizeInBits,
597 uint64_t AlignInBits,
598 uint64_t OffsetInBits,
599 unsigned Flags, DIType DerivedFrom,
600 DIArray Elements,
601 MDNode *VTableHolder,
Manman Ren23f84cb2013-08-27 23:06:40 +0000602 MDNode *TemplateParams,
603 StringRef UniqueIdentifier) {
Manman Ren89c83b72013-07-01 21:02:01 +0000604 assert((!Context || Context.isScope() || Context.isType()) &&
David Blaikie66438682013-03-11 23:21:19 +0000605 "createClassType should be called with a valid Context");
606 // TAG_class_type is encoded in DICompositeType format.
Eric Christopher87c06a82012-07-06 02:35:57 +0000607 Value *Elts[] = {
608 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000609 File.getFileNode(),
Eric Christopher87c06a82012-07-06 02:35:57 +0000610 getNonCompileUnitScope(Context),
611 MDString::get(VMContext, Name),
Eric Christopher87c06a82012-07-06 02:35:57 +0000612 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
613 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
614 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
615 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
616 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
617 DerivedFrom,
618 Elements,
619 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
620 VTableHolder,
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000621 TemplateParams,
Manman Ren23f84cb2013-08-27 23:06:40 +0000622 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Eric Christopher87c06a82012-07-06 02:35:57 +0000623 };
David Blaikieca442a42013-03-26 23:46:39 +0000624 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000625 assert(R.isCompositeType() &&
626 "createClassType should return a DICompositeType");
David Blaikie66438682013-03-11 23:21:19 +0000627 return R;
Eric Christopher87c06a82012-07-06 02:35:57 +0000628}
629
Devang Patel50d280c2011-02-22 18:56:12 +0000630/// createStructType - Create debugging information entry for a struct.
David Blaikie6172f022013-02-25 01:07:18 +0000631DICompositeType DIBuilder::createStructType(DIDescriptor Context,
632 StringRef Name, DIFile File,
633 unsigned LineNumber,
634 uint64_t SizeInBits,
635 uint64_t AlignInBits,
636 unsigned Flags, DIType DerivedFrom,
637 DIArray Elements,
638 unsigned RunTimeLang,
Manman Ren23f84cb2013-08-27 23:06:40 +0000639 MDNode *VTableHolder,
640 StringRef UniqueIdentifier) {
Devang Patelfe58f952010-12-07 23:25:47 +0000641 // TAG_structure_type is encoded in DICompositeType format.
642 Value *Elts[] = {
643 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000644 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000645 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000646 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +0000647 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
648 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
649 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Devang Patel43c249c2010-12-08 01:50:15 +0000650 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelfe58f952010-12-07 23:25:47 +0000651 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
David Blaikie6172f022013-02-25 01:07:18 +0000652 DerivedFrom,
Devang Patelfe58f952010-12-07 23:25:47 +0000653 Elements,
654 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
David Blaikie6172f022013-02-25 01:07:18 +0000655 VTableHolder,
David Blaikied4f92fd2013-02-18 07:27:30 +0000656 NULL,
Manman Ren23f84cb2013-08-27 23:06:40 +0000657 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patelfe58f952010-12-07 23:25:47 +0000658 };
David Blaikie66438682013-03-11 23:21:19 +0000659 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000660 assert(R.isCompositeType() &&
661 "createStructType should return a DICompositeType");
David Blaikie66438682013-03-11 23:21:19 +0000662 return R;
Devang Patelfe58f952010-12-07 23:25:47 +0000663}
664
Devang Patel50d280c2011-02-22 18:56:12 +0000665/// createUnionType - Create debugging information entry for an union.
Eric Christophercf0623b2013-04-02 22:55:52 +0000666DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
667 DIFile File, unsigned LineNumber,
668 uint64_t SizeInBits,
669 uint64_t AlignInBits, unsigned Flags,
670 DIArray Elements,
Manman Ren23f84cb2013-08-27 23:06:40 +0000671 unsigned RunTimeLang,
672 StringRef UniqueIdentifier) {
Devang Patel43c249c2010-12-08 01:50:15 +0000673 // TAG_union_type is encoded in DICompositeType format.
674 Value *Elts[] = {
675 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000676 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000677 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +0000678 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000679 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
680 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
681 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
682 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
683 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patelc104cf22011-12-16 17:51:31 +0000684 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000685 Elements,
686 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000687 NULL,
688 NULL,
Manman Ren23f84cb2013-08-27 23:06:40 +0000689 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel43c249c2010-12-08 01:50:15 +0000690 };
David Blaikie72dfb052013-03-28 02:44:59 +0000691 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000692}
693
Devang Patel50d280c2011-02-22 18:56:12 +0000694/// createSubroutineType - Create subroutine type.
David Blaikied67c5ca2013-02-18 06:41:57 +0000695DICompositeType
696DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) {
Devang Patel43c249c2010-12-08 01:50:15 +0000697 // TAG_subroutine_type is encoded in DICompositeType format.
698 Value *Elts[] = {
699 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000700 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000701 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000702 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000703 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
704 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
705 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000706 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patel43c249c2010-12-08 01:50:15 +0000707 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000708 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000709 ParameterTypes,
710 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000711 NULL,
712 NULL,
713 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000714 };
David Blaikie72dfb052013-03-28 02:44:59 +0000715 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000716}
717
Eric Christopher6c0046f2011-08-26 21:02:40 +0000718/// createEnumerationType - Create debugging information entry for an
Devang Patel43c249c2010-12-08 01:50:15 +0000719/// enumeration.
David Blaikied67c5ca2013-02-18 06:41:57 +0000720DICompositeType DIBuilder::createEnumerationType(
721 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
722 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Manman Ren23f84cb2013-08-27 23:06:40 +0000723 DIType UnderlyingType, StringRef UniqueIdentifier) {
Devang Patel43c249c2010-12-08 01:50:15 +0000724 // TAG_enumeration_type is encoded in DICompositeType format.
725 Value *Elts[] = {
726 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000727 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000728 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +0000729 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000730 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
731 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
732 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
733 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000734 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Adrian Prantl2f445be2013-04-19 19:56:02 +0000735 UnderlyingType,
Devang Patel43c249c2010-12-08 01:50:15 +0000736 Elements,
737 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000738 NULL,
739 NULL,
Manman Ren23f84cb2013-08-27 23:06:40 +0000740 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel43c249c2010-12-08 01:50:15 +0000741 };
Devang Patel1f48a952011-04-18 23:51:03 +0000742 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000743 AllEnumTypes.push_back(Node);
David Blaikie72dfb052013-03-28 02:44:59 +0000744 return DICompositeType(Node);
Devang Patel43c249c2010-12-08 01:50:15 +0000745}
746
Devang Patel50d280c2011-02-22 18:56:12 +0000747/// createArrayType - Create debugging information entry for an array.
David Blaikied67c5ca2013-02-18 06:41:57 +0000748DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
749 DIType Ty, DIArray Subscripts) {
Devang Patel43c249c2010-12-08 01:50:15 +0000750 // TAG_array_type is encoded in DICompositeType format.
751 Value *Elts[] = {
752 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000753 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000754 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000755 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000756 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
757 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
758 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
759 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
760 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
761 Ty,
762 Subscripts,
763 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000764 NULL,
765 NULL,
766 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000767 };
David Blaikie72dfb052013-03-28 02:44:59 +0000768 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000769}
770
Devang Patel50d280c2011-02-22 18:56:12 +0000771/// createVectorType - Create debugging information entry for a vector.
Manman Ren37bfb182013-06-07 03:13:46 +0000772DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
773 DIType Ty, DIArray Subscripts) {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000774 // A vector is an array type with the FlagVector flag applied.
Devang Patel43c249c2010-12-08 01:50:15 +0000775 Value *Elts[] = {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000776 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000777 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000778 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000779 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000780 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
781 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
782 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
783 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000784 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
Devang Patel43c249c2010-12-08 01:50:15 +0000785 Ty,
786 Subscripts,
787 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000788 NULL,
789 NULL,
790 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000791 };
Manman Ren37bfb182013-06-07 03:13:46 +0000792 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000793}
Devang Patelfe58f952010-12-07 23:25:47 +0000794
Devang Patel50d280c2011-02-22 18:56:12 +0000795/// createArtificialType - Create a new DIType with "artificial" flag set.
796DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel35fcd652010-11-04 15:01:38 +0000797 if (Ty.isArtificial())
798 return Ty;
799
800 SmallVector<Value *, 9> Elts;
801 MDNode *N = Ty;
802 assert (N && "Unexpected input DIType!");
803 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
804 if (Value *V = N->getOperand(i))
805 Elts.push_back(V);
806 else
807 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
808 }
809
810 unsigned CurFlags = Ty.getFlags();
811 CurFlags = CurFlags | DIType::FlagArtificial;
812
813 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000814 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Devang Patel35fcd652010-11-04 15:01:38 +0000815
David Blaikie72dfb052013-03-28 02:44:59 +0000816 return DIType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000817}
Devang Patelfe58f952010-12-07 23:25:47 +0000818
Eric Christopher1f55eb42013-01-08 01:53:42 +0000819/// createObjectPointerType - Create a new type with both the object pointer
820/// and artificial flags set.
Eric Christophere5212782012-09-12 23:36:19 +0000821DIType DIBuilder::createObjectPointerType(DIType Ty) {
822 if (Ty.isObjectPointer())
823 return Ty;
824
825 SmallVector<Value *, 9> Elts;
826 MDNode *N = Ty;
827 assert (N && "Unexpected input DIType!");
828 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
829 if (Value *V = N->getOperand(i))
830 Elts.push_back(V);
831 else
832 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
833 }
834
835 unsigned CurFlags = Ty.getFlags();
836 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
837
838 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000839 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Eric Christophere5212782012-09-12 23:36:19 +0000840
David Blaikie72dfb052013-03-28 02:44:59 +0000841 return DIType(MDNode::get(VMContext, Elts));
Eric Christophere5212782012-09-12 23:36:19 +0000842}
843
Eric Christopher6c0046f2011-08-26 21:02:40 +0000844/// retainType - Retain DIType in a module even if it is not referenced
Devang Patel43c249c2010-12-08 01:50:15 +0000845/// through debug info anchors.
Devang Patel50d280c2011-02-22 18:56:12 +0000846void DIBuilder::retainType(DIType T) {
Devang Patel94c7ddb2011-08-16 22:09:43 +0000847 AllRetainTypes.push_back(T);
Devang Patel43c249c2010-12-08 01:50:15 +0000848}
849
Devang Patel50d280c2011-02-22 18:56:12 +0000850/// createUnspecifiedParameter - Create unspeicified type descriptor
Devang Patel43c249c2010-12-08 01:50:15 +0000851/// for the subroutine type.
Devang Patel50d280c2011-02-22 18:56:12 +0000852DIDescriptor DIBuilder::createUnspecifiedParameter() {
Eric Christopher6c0046f2011-08-26 21:02:40 +0000853 Value *Elts[] = {
854 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
Devang Patel43c249c2010-12-08 01:50:15 +0000855 };
Devang Patel1f48a952011-04-18 23:51:03 +0000856 return DIDescriptor(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000857}
858
Eric Christopher4fe34572012-02-08 00:22:26 +0000859/// createForwardDecl - Create a temporary forward-declared type that
860/// can be RAUW'd if the full type is seen.
David Blaikie692062f2013-08-16 20:42:14 +0000861DICompositeType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name,
Eric Christopher216432d2012-04-23 19:00:11 +0000862 DIDescriptor Scope, DIFile F,
Eli Friedmance3da6f2012-10-05 01:49:14 +0000863 unsigned Line, unsigned RuntimeLang,
864 uint64_t SizeInBits,
Manman Ren23f84cb2013-08-27 23:06:40 +0000865 uint64_t AlignInBits,
866 StringRef UniqueIdentifier) {
Eric Christopher4fe34572012-02-08 00:22:26 +0000867 // Create a temporary MDNode.
868 Value *Elts[] = {
869 GetTagConstant(VMContext, Tag),
David Blaikie4776bce2013-03-20 00:26:26 +0000870 F.getFileNode(),
Eric Christopher216432d2012-04-23 19:00:11 +0000871 getNonCompileUnitScope(Scope),
Eric Christopher4fe34572012-02-08 00:22:26 +0000872 MDString::get(VMContext, Name),
Eric Christopher4fe34572012-02-08 00:22:26 +0000873 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000874 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
875 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher4fe34572012-02-08 00:22:26 +0000876 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
877 ConstantInt::get(Type::getInt32Ty(VMContext),
Eric Christopher9f90e872012-02-20 18:04:14 +0000878 DIDescriptor::FlagFwdDecl),
879 NULL,
880 DIArray(),
David Blaikie692062f2013-08-16 20:42:14 +0000881 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000882 NULL,
883 NULL, //TemplateParams
Manman Ren23f84cb2013-08-27 23:06:40 +0000884 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Eric Christopher4fe34572012-02-08 00:22:26 +0000885 };
886 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
David Blaikie692062f2013-08-16 20:42:14 +0000887 DICompositeType RetTy(Node);
888 assert(RetTy.isCompositeType() &&
Manman Ren89c83b72013-07-01 21:02:01 +0000889 "createForwardDecl result should be a DIType");
Manman Ren88328d22013-07-02 18:37:35 +0000890 return RetTy;
Eric Christopher4fe34572012-02-08 00:22:26 +0000891}
892
Devang Patel50d280c2011-02-22 18:56:12 +0000893/// getOrCreateArray - Get a DIArray, create one if required.
Jay Foad68550182011-04-24 10:11:03 +0000894DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
895 if (Elements.empty()) {
Bill Wendlingf46b4972012-07-06 17:47:36 +0000896 Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
Jay Foadec9186b2011-04-21 19:59:31 +0000897 return DIArray(MDNode::get(VMContext, Null));
Devang Patelfe58f952010-12-07 23:25:47 +0000898 }
Jay Foad68550182011-04-24 10:11:03 +0000899 return DIArray(MDNode::get(VMContext, Elements));
Devang Patelfe58f952010-12-07 23:25:47 +0000900}
901
Devang Patel50d280c2011-02-22 18:56:12 +0000902/// getOrCreateSubrange - Create a descriptor for a value range. This
Devang Patel43c249c2010-12-08 01:50:15 +0000903/// implicitly uniques the values returned.
Bill Wendling9493dae2012-12-04 21:34:03 +0000904DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Devang Patel43c249c2010-12-08 01:50:15 +0000905 Value *Elts[] = {
906 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
907 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
Bill Wendlinga7645a32012-12-04 06:20:49 +0000908 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
Devang Patel43c249c2010-12-08 01:50:15 +0000909 };
910
Devang Patel1f48a952011-04-18 23:51:03 +0000911 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000912}
913
David Blaikie3fac43d2013-03-20 17:49:48 +0000914/// \brief Create a new descriptor for the specified global.
Devang Patelfe58f952010-12-07 23:25:47 +0000915DIGlobalVariable DIBuilder::
David Blaikie3fac43d2013-03-20 17:49:48 +0000916createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F,
917 unsigned LineNumber, DIType Ty, bool isLocalToUnit,
918 Value *Val) {
Devang Patelfe58f952010-12-07 23:25:47 +0000919 Value *Elts[] = {
920 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000921 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000922 NULL, // TheCU,
Devang Patelfe58f952010-12-07 23:25:47 +0000923 MDString::get(VMContext, Name),
924 MDString::get(VMContext, Name),
David Blaikie3fac43d2013-03-20 17:49:48 +0000925 MDString::get(VMContext, LinkageName),
Devang Patelfe58f952010-12-07 23:25:47 +0000926 F,
927 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
928 Ty,
929 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
930 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000931 Val,
932 DIDescriptor()
Devang Patelfe58f952010-12-07 23:25:47 +0000933 };
Devang Patel1f48a952011-04-18 23:51:03 +0000934 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000935 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000936 return DIGlobalVariable(Node);
937}
938
David Blaikie3fac43d2013-03-20 17:49:48 +0000939/// \brief Create a new descriptor for the specified global.
940DIGlobalVariable DIBuilder::
941createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber,
942 DIType Ty, bool isLocalToUnit, Value *Val) {
943 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
944 Val);
945}
946
Devang Patel50d280c2011-02-22 18:56:12 +0000947/// createStaticVariable - Create a new descriptor for the specified static
Devang Patelfe58f952010-12-07 23:25:47 +0000948/// variable.
949DIGlobalVariable DIBuilder::
Eric Christopher6c0046f2011-08-26 21:02:40 +0000950createStaticVariable(DIDescriptor Context, StringRef Name,
951 StringRef LinkageName, DIFile F, unsigned LineNumber,
Eric Christopher6b6061f2013-01-16 01:22:23 +0000952 DIType Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) {
Devang Patelfe58f952010-12-07 23:25:47 +0000953 Value *Elts[] = {
954 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000955 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000956 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000957 MDString::get(VMContext, Name),
958 MDString::get(VMContext, Name),
959 MDString::get(VMContext, LinkageName),
960 F,
961 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
962 Ty,
963 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
964 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000965 Val,
966 DIDescriptor(Decl)
Devang Patelfe58f952010-12-07 23:25:47 +0000967 };
Devang Patel1f48a952011-04-18 23:51:03 +0000968 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000969 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000970 return DIGlobalVariable(Node);
971}
972
Devang Patel50d280c2011-02-22 18:56:12 +0000973/// createVariable - Create a new descriptor for the specified variable.
974DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel48f17ba2010-12-07 23:58:00 +0000975 StringRef Name, DIFile File,
Eric Christopher6c0046f2011-08-26 21:02:40 +0000976 unsigned LineNo, DIType Ty,
Devang Patele9e16c52011-03-01 22:58:13 +0000977 bool AlwaysPreserve, unsigned Flags,
978 unsigned ArgNo) {
David Blaikie66438682013-03-11 23:21:19 +0000979 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren89c83b72013-07-01 21:02:01 +0000980 assert((!Context || Context.isScope()) &&
David Blaikie66438682013-03-11 23:21:19 +0000981 "createLocalVariable should be called with a valid Context");
Manman Ren89c83b72013-07-01 21:02:01 +0000982 assert(Ty.isType() &&
David Blaikie66438682013-03-11 23:21:19 +0000983 "createLocalVariable should be called with a valid type");
Devang Patel48f17ba2010-12-07 23:58:00 +0000984 Value *Elts[] = {
985 GetTagConstant(VMContext, Tag),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000986 getNonCompileUnitScope(Scope),
Devang Patel48f17ba2010-12-07 23:58:00 +0000987 MDString::get(VMContext, Name),
988 File,
Devang Patele9e16c52011-03-01 22:58:13 +0000989 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
Devang Patel48f17ba2010-12-07 23:58:00 +0000990 Ty,
Devang Patel23336b42011-07-19 19:41:54 +0000991 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000992 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel48f17ba2010-12-07 23:58:00 +0000993 };
Devang Patel1f48a952011-04-18 23:51:03 +0000994 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel48f17ba2010-12-07 23:58:00 +0000995 if (AlwaysPreserve) {
996 // The optimizer may remove local variable. If there is an interest
997 // to preserve variable info in such situation then stash it in a
998 // named mdnode.
999 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel93d39be2011-08-19 23:28:12 +00001000 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel48f17ba2010-12-07 23:58:00 +00001001 FnLocals->addOperand(Node);
1002 }
Manman Ren88328d22013-07-02 18:37:35 +00001003 DIVariable RetVar(Node);
1004 assert(RetVar.isVariable() &&
Manman Ren89c83b72013-07-01 21:02:01 +00001005 "createLocalVariable should return a valid DIVariable");
Manman Ren88328d22013-07-02 18:37:35 +00001006 return RetVar;
Devang Patel48f17ba2010-12-07 23:58:00 +00001007}
1008
Devang Patel50d280c2011-02-22 18:56:12 +00001009/// createComplexVariable - Create a new descriptor for the specified variable
Devang Patelfe58f952010-12-07 23:25:47 +00001010/// which has a complex address expression for its address.
Devang Patel50d280c2011-02-22 18:56:12 +00001011DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
Devang Patelfe58f952010-12-07 23:25:47 +00001012 StringRef Name, DIFile F,
1013 unsigned LineNo,
Jay Foad68550182011-04-24 10:11:03 +00001014 DIType Ty, ArrayRef<Value *> Addr,
1015 unsigned ArgNo) {
Devang Patelfe58f952010-12-07 23:25:47 +00001016 SmallVector<Value *, 15> Elts;
1017 Elts.push_back(GetTagConstant(VMContext, Tag));
Devang Patel94c7ddb2011-08-16 22:09:43 +00001018 Elts.push_back(getNonCompileUnitScope(Scope)),
Devang Patelfe58f952010-12-07 23:25:47 +00001019 Elts.push_back(MDString::get(VMContext, Name));
1020 Elts.push_back(F);
Eric Christopher6c0046f2011-08-26 21:02:40 +00001021 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
Devang Patel9f997212012-02-08 00:17:07 +00001022 (LineNo | (ArgNo << 24))));
Devang Patelfe58f952010-12-07 23:25:47 +00001023 Elts.push_back(Ty);
Bill Wendlingf46b4972012-07-06 17:47:36 +00001024 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1025 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
Jay Foad68550182011-04-24 10:11:03 +00001026 Elts.append(Addr.begin(), Addr.end());
Devang Patelfe58f952010-12-07 23:25:47 +00001027
Devang Patel1f48a952011-04-18 23:51:03 +00001028 return DIVariable(MDNode::get(VMContext, Elts));
Devang Patelfe58f952010-12-07 23:25:47 +00001029}
1030
Devang Patel50d280c2011-02-22 18:56:12 +00001031/// createFunction - Create a new descriptor for the specified function.
1032DISubprogram DIBuilder::createFunction(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001033 StringRef Name,
1034 StringRef LinkageName,
1035 DIFile File, unsigned LineNo,
David Blaikie3d331842013-05-22 23:22:18 +00001036 DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001037 bool isLocalToUnit, bool isDefinition,
Eric Christopher6126a1e2012-04-03 00:43:49 +00001038 unsigned ScopeLine,
Devang Patel44498a62010-12-08 20:42:44 +00001039 unsigned Flags, bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001040 Function *Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001041 MDNode *TParams,
1042 MDNode *Decl) {
David Blaikie3d331842013-05-22 23:22:18 +00001043 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1044 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001045 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001046 Value *Elts[] = {
1047 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001048 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001049 getNonCompileUnitScope(Context),
Devang Patel44498a62010-12-08 20:42:44 +00001050 MDString::get(VMContext, Name),
1051 MDString::get(VMContext, Name),
1052 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001053 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1054 Ty,
1055 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1056 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1057 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1058 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patel9642c572011-12-15 17:55:56 +00001059 NULL,
Devang Patel44498a62010-12-08 20:42:44 +00001060 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1061 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001062 Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001063 TParams,
Devang Patel93d39be2011-08-19 23:28:12 +00001064 Decl,
David Blaikief839eed2013-02-04 05:56:36 +00001065 MDNode::getTemporary(VMContext, TElts),
Eric Christopher6126a1e2012-04-03 00:43:49 +00001066 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
Devang Patel44498a62010-12-08 20:42:44 +00001067 };
Devang Patel1f48a952011-04-18 23:51:03 +00001068 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel44498a62010-12-08 20:42:44 +00001069
1070 // Create a named metadata so that we do not lose this mdnode.
David Blaikie139f7e52013-02-18 07:10:22 +00001071 if (isDefinition)
1072 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001073 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001074 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001075 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001076}
1077
Devang Patel50d280c2011-02-22 18:56:12 +00001078/// createMethod - Create a new descriptor for the specified C++ method.
1079DISubprogram DIBuilder::createMethod(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001080 StringRef Name,
1081 StringRef LinkageName,
1082 DIFile F,
David Blaikie3d331842013-05-22 23:22:18 +00001083 unsigned LineNo, DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001084 bool isLocalToUnit,
1085 bool isDefinition,
1086 unsigned VK, unsigned VIndex,
1087 MDNode *VTableHolder,
1088 unsigned Flags,
1089 bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001090 Function *Fn,
1091 MDNode *TParam) {
David Blaikie3d331842013-05-22 23:22:18 +00001092 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1093 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001094 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001095 Value *Elts[] = {
1096 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001097 F.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001098 getNonCompileUnitScope(Context),
Devang Patel44498a62010-12-08 20:42:44 +00001099 MDString::get(VMContext, Name),
1100 MDString::get(VMContext, Name),
1101 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001102 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1103 Ty,
1104 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1105 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1106 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
1107 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1108 VTableHolder,
1109 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1110 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001111 Fn,
1112 TParam,
Bill Wendlingf46b4972012-07-06 17:47:36 +00001113 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikief839eed2013-02-04 05:56:36 +00001114 MDNode::getTemporary(VMContext, TElts),
Eric Christopher25016522012-05-18 00:16:22 +00001115 // FIXME: Do we want to use different scope/lines?
Eric Christopher6126a1e2012-04-03 00:43:49 +00001116 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
Devang Patel44498a62010-12-08 20:42:44 +00001117 };
Devang Patel1f48a952011-04-18 23:51:03 +00001118 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie139f7e52013-02-18 07:10:22 +00001119 if (isDefinition)
1120 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001121 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001122 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001123 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001124}
1125
Devang Patel50d280c2011-02-22 18:56:12 +00001126/// createNameSpace - This creates new descriptor for a namespace
Devang Patelfe58f952010-12-07 23:25:47 +00001127/// with the specified parent scope.
Devang Patel50d280c2011-02-22 18:56:12 +00001128DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patelfe58f952010-12-07 23:25:47 +00001129 DIFile File, unsigned LineNo) {
1130 Value *Elts[] = {
1131 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
David Blaikie6115ed02013-03-20 19:39:15 +00001132 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001133 getNonCompileUnitScope(Scope),
Devang Patelfe58f952010-12-07 23:25:47 +00001134 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +00001135 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1136 };
David Blaikie66438682013-03-11 23:21:19 +00001137 DINameSpace R(MDNode::get(VMContext, Elts));
1138 assert(R.Verify() &&
1139 "createNameSpace should return a verifiable DINameSpace");
1140 return R;
Devang Patelfe58f952010-12-07 23:25:47 +00001141}
1142
Eric Christopher6618a242011-10-11 22:59:11 +00001143/// createLexicalBlockFile - This creates a new MDNode that encapsulates
1144/// an existing scope with a new filename.
1145DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
Devang Patel9f997212012-02-08 00:17:07 +00001146 DIFile File) {
Eric Christopher6618a242011-10-11 22:59:11 +00001147 Value *Elts[] = {
1148 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie8faed272013-03-22 20:18:46 +00001149 File.getFileNode(),
David Blaikie7b246862013-03-22 19:13:22 +00001150 Scope
Eric Christopher6618a242011-10-11 22:59:11 +00001151 };
David Blaikie66438682013-03-11 23:21:19 +00001152 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1153 assert(
1154 R.Verify() &&
1155 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1156 return R;
Eric Christopher6618a242011-10-11 22:59:11 +00001157}
1158
Devang Patel50d280c2011-02-22 18:56:12 +00001159DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
Devang Patel43c249c2010-12-08 01:50:15 +00001160 unsigned Line, unsigned Col) {
Adrian Prantle06db0c2013-06-24 21:19:43 +00001161 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel43c249c2010-12-08 01:50:15 +00001162 static unsigned int unique_id = 0;
1163 Value *Elts[] = {
1164 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie4b52a882013-03-22 17:33:20 +00001165 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001166 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +00001167 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1168 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
Devang Patel43c249c2010-12-08 01:50:15 +00001169 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1170 };
David Blaikie66438682013-03-11 23:21:19 +00001171 DILexicalBlock R(MDNode::get(VMContext, Elts));
1172 assert(R.Verify() &&
1173 "createLexicalBlock should return a verifiable DILexicalBlock");
1174 return R;
Devang Patel43c249c2010-12-08 01:50:15 +00001175}
1176
Devang Patel50d280c2011-02-22 18:56:12 +00001177/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1178Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001179 Instruction *InsertBefore) {
1180 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001181 assert(VarInfo.isVariable() &&
1182 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001183 if (!DeclareFn)
1184 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1185
Jay Foadec9186b2011-04-21 19:59:31 +00001186 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001187 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001188}
1189
Devang Patel50d280c2011-02-22 18:56:12 +00001190/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1191Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001192 BasicBlock *InsertAtEnd) {
1193 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001194 assert(VarInfo.isVariable() &&
1195 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001196 if (!DeclareFn)
1197 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1198
Jay Foadec9186b2011-04-21 19:59:31 +00001199 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Devang Patelfe58f952010-12-07 23:25:47 +00001200
1201 // If this block already has a terminator then insert this intrinsic
1202 // before the terminator.
1203 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foada3efbb12011-07-15 08:37:34 +00001204 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patelfe58f952010-12-07 23:25:47 +00001205 else
Jay Foada3efbb12011-07-15 08:37:34 +00001206 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001207}
1208
Devang Patel50d280c2011-02-22 18:56:12 +00001209/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1210Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001211 DIVariable VarInfo,
1212 Instruction *InsertBefore) {
1213 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001214 assert(VarInfo.isVariable() &&
1215 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001216 if (!ValueFn)
1217 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1218
Jay Foadec9186b2011-04-21 19:59:31 +00001219 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001220 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1221 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001222 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001223}
1224
Devang Patel50d280c2011-02-22 18:56:12 +00001225/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1226Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001227 DIVariable VarInfo,
1228 BasicBlock *InsertAtEnd) {
1229 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001230 assert(VarInfo.isVariable() &&
1231 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001232 if (!ValueFn)
1233 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1234
Jay Foadec9186b2011-04-21 19:59:31 +00001235 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001236 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1237 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001238 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001239}