blob: e36d0288992a553efda619c04fe756b4d9ded043 [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,
602 MDNode *TemplateParams) {
Manman Ren89c83b72013-07-01 21:02:01 +0000603 assert((!Context || Context.isScope() || Context.isType()) &&
David Blaikie66438682013-03-11 23:21:19 +0000604 "createClassType should be called with a valid Context");
605 // TAG_class_type is encoded in DICompositeType format.
Eric Christopher87c06a82012-07-06 02:35:57 +0000606 Value *Elts[] = {
607 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000608 File.getFileNode(),
Eric Christopher87c06a82012-07-06 02:35:57 +0000609 getNonCompileUnitScope(Context),
610 MDString::get(VMContext, Name),
Eric Christopher87c06a82012-07-06 02:35:57 +0000611 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
612 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
613 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
614 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
615 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
616 DerivedFrom,
617 Elements,
618 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
619 VTableHolder,
620 TemplateParams
621 };
David Blaikieca442a42013-03-26 23:46:39 +0000622 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000623 assert(R.isCompositeType() &&
624 "createClassType should return a DICompositeType");
David Blaikie66438682013-03-11 23:21:19 +0000625 return R;
Eric Christopher87c06a82012-07-06 02:35:57 +0000626}
627
Devang Patel50d280c2011-02-22 18:56:12 +0000628/// createStructType - Create debugging information entry for a struct.
David Blaikie6172f022013-02-25 01:07:18 +0000629DICompositeType DIBuilder::createStructType(DIDescriptor Context,
630 StringRef Name, DIFile File,
631 unsigned LineNumber,
632 uint64_t SizeInBits,
633 uint64_t AlignInBits,
634 unsigned Flags, DIType DerivedFrom,
635 DIArray Elements,
636 unsigned RunTimeLang,
637 MDNode *VTableHolder) {
Devang Patelfe58f952010-12-07 23:25:47 +0000638 // TAG_structure_type is encoded in DICompositeType format.
639 Value *Elts[] = {
640 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000641 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000642 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000643 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +0000644 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
645 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
646 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Devang Patel43c249c2010-12-08 01:50:15 +0000647 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelfe58f952010-12-07 23:25:47 +0000648 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
David Blaikie6172f022013-02-25 01:07:18 +0000649 DerivedFrom,
Devang Patelfe58f952010-12-07 23:25:47 +0000650 Elements,
651 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
David Blaikie6172f022013-02-25 01:07:18 +0000652 VTableHolder,
David Blaikied4f92fd2013-02-18 07:27:30 +0000653 NULL,
Devang Patelfe58f952010-12-07 23:25:47 +0000654 };
David Blaikie66438682013-03-11 23:21:19 +0000655 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000656 assert(R.isCompositeType() &&
657 "createStructType should return a DICompositeType");
David Blaikie66438682013-03-11 23:21:19 +0000658 return R;
Devang Patelfe58f952010-12-07 23:25:47 +0000659}
660
Devang Patel50d280c2011-02-22 18:56:12 +0000661/// createUnionType - Create debugging information entry for an union.
Eric Christophercf0623b2013-04-02 22:55:52 +0000662DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
663 DIFile File, unsigned LineNumber,
664 uint64_t SizeInBits,
665 uint64_t AlignInBits, unsigned Flags,
666 DIArray Elements,
667 unsigned RunTimeLang) {
Devang Patel43c249c2010-12-08 01:50:15 +0000668 // TAG_union_type is encoded in DICompositeType format.
669 Value *Elts[] = {
670 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000671 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000672 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +0000673 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000674 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
675 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
676 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
677 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
678 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patelc104cf22011-12-16 17:51:31 +0000679 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000680 Elements,
681 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Eric Christopherc656fda2013-04-02 22:55:56 +0000682 Constant::getNullValue(Type::getInt32Ty(VMContext)),
683 NULL
Devang Patel43c249c2010-12-08 01:50:15 +0000684 };
David Blaikie72dfb052013-03-28 02:44:59 +0000685 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000686}
687
Devang Patel50d280c2011-02-22 18:56:12 +0000688/// createSubroutineType - Create subroutine type.
David Blaikied67c5ca2013-02-18 06:41:57 +0000689DICompositeType
690DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) {
Devang Patel43c249c2010-12-08 01:50:15 +0000691 // TAG_subroutine_type is encoded in DICompositeType format.
692 Value *Elts[] = {
693 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000694 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000695 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000696 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000697 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
698 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
699 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000700 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patel43c249c2010-12-08 01:50:15 +0000701 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000702 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000703 ParameterTypes,
704 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000705 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel43c249c2010-12-08 01:50:15 +0000706 };
David Blaikie72dfb052013-03-28 02:44:59 +0000707 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000708}
709
Eric Christopher6c0046f2011-08-26 21:02:40 +0000710/// createEnumerationType - Create debugging information entry for an
Devang Patel43c249c2010-12-08 01:50:15 +0000711/// enumeration.
David Blaikied67c5ca2013-02-18 06:41:57 +0000712DICompositeType DIBuilder::createEnumerationType(
713 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
714 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Adrian Prantl2f445be2013-04-19 19:56:02 +0000715 DIType UnderlyingType) {
Devang Patel43c249c2010-12-08 01:50:15 +0000716 // TAG_enumeration_type is encoded in DICompositeType format.
717 Value *Elts[] = {
718 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000719 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000720 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +0000721 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000722 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
723 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
724 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
725 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000726 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Adrian Prantl2f445be2013-04-19 19:56:02 +0000727 UnderlyingType,
Devang Patel43c249c2010-12-08 01:50:15 +0000728 Elements,
729 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000730 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel43c249c2010-12-08 01:50:15 +0000731 };
Devang Patel1f48a952011-04-18 23:51:03 +0000732 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000733 AllEnumTypes.push_back(Node);
David Blaikie72dfb052013-03-28 02:44:59 +0000734 return DICompositeType(Node);
Devang Patel43c249c2010-12-08 01:50:15 +0000735}
736
Devang Patel50d280c2011-02-22 18:56:12 +0000737/// createArrayType - Create debugging information entry for an array.
David Blaikied67c5ca2013-02-18 06:41:57 +0000738DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
739 DIType Ty, DIArray Subscripts) {
Devang Patel43c249c2010-12-08 01:50:15 +0000740 // TAG_array_type is encoded in DICompositeType format.
741 Value *Elts[] = {
742 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000743 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000744 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000745 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000746 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
747 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
748 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
749 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
750 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
751 Ty,
752 Subscripts,
753 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000754 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel43c249c2010-12-08 01:50:15 +0000755 };
David Blaikie72dfb052013-03-28 02:44:59 +0000756 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000757}
758
Devang Patel50d280c2011-02-22 18:56:12 +0000759/// createVectorType - Create debugging information entry for a vector.
Manman Ren37bfb182013-06-07 03:13:46 +0000760DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
761 DIType Ty, DIArray Subscripts) {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000762 // A vector is an array type with the FlagVector flag applied.
Devang Patel43c249c2010-12-08 01:50:15 +0000763 Value *Elts[] = {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000764 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000765 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000766 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000767 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000768 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
769 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
770 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
771 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000772 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
Devang Patel43c249c2010-12-08 01:50:15 +0000773 Ty,
774 Subscripts,
775 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000776 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel43c249c2010-12-08 01:50:15 +0000777 };
Manman Ren37bfb182013-06-07 03:13:46 +0000778 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000779}
Devang Patelfe58f952010-12-07 23:25:47 +0000780
Devang Patel50d280c2011-02-22 18:56:12 +0000781/// createArtificialType - Create a new DIType with "artificial" flag set.
782DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel35fcd652010-11-04 15:01:38 +0000783 if (Ty.isArtificial())
784 return Ty;
785
786 SmallVector<Value *, 9> Elts;
787 MDNode *N = Ty;
788 assert (N && "Unexpected input DIType!");
789 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
790 if (Value *V = N->getOperand(i))
791 Elts.push_back(V);
792 else
793 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
794 }
795
796 unsigned CurFlags = Ty.getFlags();
797 CurFlags = CurFlags | DIType::FlagArtificial;
798
799 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000800 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Devang Patel35fcd652010-11-04 15:01:38 +0000801
David Blaikie72dfb052013-03-28 02:44:59 +0000802 return DIType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000803}
Devang Patelfe58f952010-12-07 23:25:47 +0000804
Eric Christopher1f55eb42013-01-08 01:53:42 +0000805/// createObjectPointerType - Create a new type with both the object pointer
806/// and artificial flags set.
Eric Christophere5212782012-09-12 23:36:19 +0000807DIType DIBuilder::createObjectPointerType(DIType Ty) {
808 if (Ty.isObjectPointer())
809 return Ty;
810
811 SmallVector<Value *, 9> Elts;
812 MDNode *N = Ty;
813 assert (N && "Unexpected input DIType!");
814 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
815 if (Value *V = N->getOperand(i))
816 Elts.push_back(V);
817 else
818 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
819 }
820
821 unsigned CurFlags = Ty.getFlags();
822 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
823
824 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000825 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Eric Christophere5212782012-09-12 23:36:19 +0000826
David Blaikie72dfb052013-03-28 02:44:59 +0000827 return DIType(MDNode::get(VMContext, Elts));
Eric Christophere5212782012-09-12 23:36:19 +0000828}
829
Eric Christopher6c0046f2011-08-26 21:02:40 +0000830/// retainType - Retain DIType in a module even if it is not referenced
Devang Patel43c249c2010-12-08 01:50:15 +0000831/// through debug info anchors.
Devang Patel50d280c2011-02-22 18:56:12 +0000832void DIBuilder::retainType(DIType T) {
Devang Patel94c7ddb2011-08-16 22:09:43 +0000833 AllRetainTypes.push_back(T);
Devang Patel43c249c2010-12-08 01:50:15 +0000834}
835
Devang Patel50d280c2011-02-22 18:56:12 +0000836/// createUnspecifiedParameter - Create unspeicified type descriptor
Devang Patel43c249c2010-12-08 01:50:15 +0000837/// for the subroutine type.
Devang Patel50d280c2011-02-22 18:56:12 +0000838DIDescriptor DIBuilder::createUnspecifiedParameter() {
Eric Christopher6c0046f2011-08-26 21:02:40 +0000839 Value *Elts[] = {
840 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
Devang Patel43c249c2010-12-08 01:50:15 +0000841 };
Devang Patel1f48a952011-04-18 23:51:03 +0000842 return DIDescriptor(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000843}
844
Eric Christopher4fe34572012-02-08 00:22:26 +0000845/// createForwardDecl - Create a temporary forward-declared type that
846/// can be RAUW'd if the full type is seen.
Eric Christopher216432d2012-04-23 19:00:11 +0000847DIType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name,
848 DIDescriptor Scope, DIFile F,
Eli Friedmance3da6f2012-10-05 01:49:14 +0000849 unsigned Line, unsigned RuntimeLang,
850 uint64_t SizeInBits,
851 uint64_t AlignInBits) {
Eric Christopher4fe34572012-02-08 00:22:26 +0000852 // Create a temporary MDNode.
853 Value *Elts[] = {
854 GetTagConstant(VMContext, Tag),
David Blaikie4776bce2013-03-20 00:26:26 +0000855 F.getFileNode(),
Eric Christopher216432d2012-04-23 19:00:11 +0000856 getNonCompileUnitScope(Scope),
Eric Christopher4fe34572012-02-08 00:22:26 +0000857 MDString::get(VMContext, Name),
Eric Christopher4fe34572012-02-08 00:22:26 +0000858 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000859 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
860 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher4fe34572012-02-08 00:22:26 +0000861 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
862 ConstantInt::get(Type::getInt32Ty(VMContext),
Eric Christopher9f90e872012-02-20 18:04:14 +0000863 DIDescriptor::FlagFwdDecl),
864 NULL,
865 DIArray(),
866 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
Eric Christopher4fe34572012-02-08 00:22:26 +0000867 };
868 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
Manman Ren88328d22013-07-02 18:37:35 +0000869 DIType RetTy(Node);
870 assert(RetTy.isType() &&
Manman Ren89c83b72013-07-01 21:02:01 +0000871 "createForwardDecl result should be a DIType");
Manman Ren88328d22013-07-02 18:37:35 +0000872 return RetTy;
Eric Christopher4fe34572012-02-08 00:22:26 +0000873}
874
Devang Patel50d280c2011-02-22 18:56:12 +0000875/// getOrCreateArray - Get a DIArray, create one if required.
Jay Foad68550182011-04-24 10:11:03 +0000876DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
877 if (Elements.empty()) {
Bill Wendlingf46b4972012-07-06 17:47:36 +0000878 Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
Jay Foadec9186b2011-04-21 19:59:31 +0000879 return DIArray(MDNode::get(VMContext, Null));
Devang Patelfe58f952010-12-07 23:25:47 +0000880 }
Jay Foad68550182011-04-24 10:11:03 +0000881 return DIArray(MDNode::get(VMContext, Elements));
Devang Patelfe58f952010-12-07 23:25:47 +0000882}
883
Devang Patel50d280c2011-02-22 18:56:12 +0000884/// getOrCreateSubrange - Create a descriptor for a value range. This
Devang Patel43c249c2010-12-08 01:50:15 +0000885/// implicitly uniques the values returned.
Bill Wendling9493dae2012-12-04 21:34:03 +0000886DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Devang Patel43c249c2010-12-08 01:50:15 +0000887 Value *Elts[] = {
888 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
889 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
Bill Wendlinga7645a32012-12-04 06:20:49 +0000890 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
Devang Patel43c249c2010-12-08 01:50:15 +0000891 };
892
Devang Patel1f48a952011-04-18 23:51:03 +0000893 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000894}
895
David Blaikie3fac43d2013-03-20 17:49:48 +0000896/// \brief Create a new descriptor for the specified global.
Devang Patelfe58f952010-12-07 23:25:47 +0000897DIGlobalVariable DIBuilder::
David Blaikie3fac43d2013-03-20 17:49:48 +0000898createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F,
899 unsigned LineNumber, DIType Ty, bool isLocalToUnit,
900 Value *Val) {
Devang Patelfe58f952010-12-07 23:25:47 +0000901 Value *Elts[] = {
902 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000903 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000904 NULL, // TheCU,
Devang Patelfe58f952010-12-07 23:25:47 +0000905 MDString::get(VMContext, Name),
906 MDString::get(VMContext, Name),
David Blaikie3fac43d2013-03-20 17:49:48 +0000907 MDString::get(VMContext, LinkageName),
Devang Patelfe58f952010-12-07 23:25:47 +0000908 F,
909 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
910 Ty,
911 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
912 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000913 Val,
914 DIDescriptor()
Devang Patelfe58f952010-12-07 23:25:47 +0000915 };
Devang Patel1f48a952011-04-18 23:51:03 +0000916 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000917 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000918 return DIGlobalVariable(Node);
919}
920
David Blaikie3fac43d2013-03-20 17:49:48 +0000921/// \brief Create a new descriptor for the specified global.
922DIGlobalVariable DIBuilder::
923createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber,
924 DIType Ty, bool isLocalToUnit, Value *Val) {
925 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
926 Val);
927}
928
Devang Patel50d280c2011-02-22 18:56:12 +0000929/// createStaticVariable - Create a new descriptor for the specified static
Devang Patelfe58f952010-12-07 23:25:47 +0000930/// variable.
931DIGlobalVariable DIBuilder::
Eric Christopher6c0046f2011-08-26 21:02:40 +0000932createStaticVariable(DIDescriptor Context, StringRef Name,
933 StringRef LinkageName, DIFile F, unsigned LineNumber,
Eric Christopher6b6061f2013-01-16 01:22:23 +0000934 DIType Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) {
Devang Patelfe58f952010-12-07 23:25:47 +0000935 Value *Elts[] = {
936 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000937 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000938 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000939 MDString::get(VMContext, Name),
940 MDString::get(VMContext, Name),
941 MDString::get(VMContext, LinkageName),
942 F,
943 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
944 Ty,
945 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
946 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000947 Val,
948 DIDescriptor(Decl)
Devang Patelfe58f952010-12-07 23:25:47 +0000949 };
Devang Patel1f48a952011-04-18 23:51:03 +0000950 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000951 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000952 return DIGlobalVariable(Node);
953}
954
Devang Patel50d280c2011-02-22 18:56:12 +0000955/// createVariable - Create a new descriptor for the specified variable.
956DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel48f17ba2010-12-07 23:58:00 +0000957 StringRef Name, DIFile File,
Eric Christopher6c0046f2011-08-26 21:02:40 +0000958 unsigned LineNo, DIType Ty,
Devang Patele9e16c52011-03-01 22:58:13 +0000959 bool AlwaysPreserve, unsigned Flags,
960 unsigned ArgNo) {
David Blaikie66438682013-03-11 23:21:19 +0000961 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren89c83b72013-07-01 21:02:01 +0000962 assert((!Context || Context.isScope()) &&
David Blaikie66438682013-03-11 23:21:19 +0000963 "createLocalVariable should be called with a valid Context");
Manman Ren89c83b72013-07-01 21:02:01 +0000964 assert(Ty.isType() &&
David Blaikie66438682013-03-11 23:21:19 +0000965 "createLocalVariable should be called with a valid type");
Devang Patel48f17ba2010-12-07 23:58:00 +0000966 Value *Elts[] = {
967 GetTagConstant(VMContext, Tag),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000968 getNonCompileUnitScope(Scope),
Devang Patel48f17ba2010-12-07 23:58:00 +0000969 MDString::get(VMContext, Name),
970 File,
Devang Patele9e16c52011-03-01 22:58:13 +0000971 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
Devang Patel48f17ba2010-12-07 23:58:00 +0000972 Ty,
Devang Patel23336b42011-07-19 19:41:54 +0000973 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000974 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel48f17ba2010-12-07 23:58:00 +0000975 };
Devang Patel1f48a952011-04-18 23:51:03 +0000976 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel48f17ba2010-12-07 23:58:00 +0000977 if (AlwaysPreserve) {
978 // The optimizer may remove local variable. If there is an interest
979 // to preserve variable info in such situation then stash it in a
980 // named mdnode.
981 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel93d39be2011-08-19 23:28:12 +0000982 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel48f17ba2010-12-07 23:58:00 +0000983 FnLocals->addOperand(Node);
984 }
Manman Ren88328d22013-07-02 18:37:35 +0000985 DIVariable RetVar(Node);
986 assert(RetVar.isVariable() &&
Manman Ren89c83b72013-07-01 21:02:01 +0000987 "createLocalVariable should return a valid DIVariable");
Manman Ren88328d22013-07-02 18:37:35 +0000988 return RetVar;
Devang Patel48f17ba2010-12-07 23:58:00 +0000989}
990
Devang Patel50d280c2011-02-22 18:56:12 +0000991/// createComplexVariable - Create a new descriptor for the specified variable
Devang Patelfe58f952010-12-07 23:25:47 +0000992/// which has a complex address expression for its address.
Devang Patel50d280c2011-02-22 18:56:12 +0000993DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
Devang Patelfe58f952010-12-07 23:25:47 +0000994 StringRef Name, DIFile F,
995 unsigned LineNo,
Jay Foad68550182011-04-24 10:11:03 +0000996 DIType Ty, ArrayRef<Value *> Addr,
997 unsigned ArgNo) {
Devang Patelfe58f952010-12-07 23:25:47 +0000998 SmallVector<Value *, 15> Elts;
999 Elts.push_back(GetTagConstant(VMContext, Tag));
Devang Patel94c7ddb2011-08-16 22:09:43 +00001000 Elts.push_back(getNonCompileUnitScope(Scope)),
Devang Patelfe58f952010-12-07 23:25:47 +00001001 Elts.push_back(MDString::get(VMContext, Name));
1002 Elts.push_back(F);
Eric Christopher6c0046f2011-08-26 21:02:40 +00001003 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
Devang Patel9f997212012-02-08 00:17:07 +00001004 (LineNo | (ArgNo << 24))));
Devang Patelfe58f952010-12-07 23:25:47 +00001005 Elts.push_back(Ty);
Bill Wendlingf46b4972012-07-06 17:47:36 +00001006 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1007 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
Jay Foad68550182011-04-24 10:11:03 +00001008 Elts.append(Addr.begin(), Addr.end());
Devang Patelfe58f952010-12-07 23:25:47 +00001009
Devang Patel1f48a952011-04-18 23:51:03 +00001010 return DIVariable(MDNode::get(VMContext, Elts));
Devang Patelfe58f952010-12-07 23:25:47 +00001011}
1012
Devang Patel50d280c2011-02-22 18:56:12 +00001013/// createFunction - Create a new descriptor for the specified function.
1014DISubprogram DIBuilder::createFunction(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001015 StringRef Name,
1016 StringRef LinkageName,
1017 DIFile File, unsigned LineNo,
David Blaikie3d331842013-05-22 23:22:18 +00001018 DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001019 bool isLocalToUnit, bool isDefinition,
Eric Christopher6126a1e2012-04-03 00:43:49 +00001020 unsigned ScopeLine,
Devang Patel44498a62010-12-08 20:42:44 +00001021 unsigned Flags, bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001022 Function *Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001023 MDNode *TParams,
1024 MDNode *Decl) {
David Blaikie3d331842013-05-22 23:22:18 +00001025 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1026 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001027 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001028 Value *Elts[] = {
1029 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001030 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001031 getNonCompileUnitScope(Context),
Devang Patel44498a62010-12-08 20:42:44 +00001032 MDString::get(VMContext, Name),
1033 MDString::get(VMContext, Name),
1034 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001035 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1036 Ty,
1037 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1038 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1039 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1040 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patel9642c572011-12-15 17:55:56 +00001041 NULL,
Devang Patel44498a62010-12-08 20:42:44 +00001042 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1043 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001044 Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001045 TParams,
Devang Patel93d39be2011-08-19 23:28:12 +00001046 Decl,
David Blaikief839eed2013-02-04 05:56:36 +00001047 MDNode::getTemporary(VMContext, TElts),
Eric Christopher6126a1e2012-04-03 00:43:49 +00001048 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
Devang Patel44498a62010-12-08 20:42:44 +00001049 };
Devang Patel1f48a952011-04-18 23:51:03 +00001050 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel44498a62010-12-08 20:42:44 +00001051
1052 // Create a named metadata so that we do not lose this mdnode.
David Blaikie139f7e52013-02-18 07:10:22 +00001053 if (isDefinition)
1054 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001055 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001056 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001057 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001058}
1059
Devang Patel50d280c2011-02-22 18:56:12 +00001060/// createMethod - Create a new descriptor for the specified C++ method.
1061DISubprogram DIBuilder::createMethod(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001062 StringRef Name,
1063 StringRef LinkageName,
1064 DIFile F,
David Blaikie3d331842013-05-22 23:22:18 +00001065 unsigned LineNo, DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001066 bool isLocalToUnit,
1067 bool isDefinition,
1068 unsigned VK, unsigned VIndex,
1069 MDNode *VTableHolder,
1070 unsigned Flags,
1071 bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001072 Function *Fn,
1073 MDNode *TParam) {
David Blaikie3d331842013-05-22 23:22:18 +00001074 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1075 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001076 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001077 Value *Elts[] = {
1078 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001079 F.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001080 getNonCompileUnitScope(Context),
Devang Patel44498a62010-12-08 20:42:44 +00001081 MDString::get(VMContext, Name),
1082 MDString::get(VMContext, Name),
1083 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001084 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1085 Ty,
1086 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1087 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1088 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
1089 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1090 VTableHolder,
1091 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1092 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001093 Fn,
1094 TParam,
Bill Wendlingf46b4972012-07-06 17:47:36 +00001095 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikief839eed2013-02-04 05:56:36 +00001096 MDNode::getTemporary(VMContext, TElts),
Eric Christopher25016522012-05-18 00:16:22 +00001097 // FIXME: Do we want to use different scope/lines?
Eric Christopher6126a1e2012-04-03 00:43:49 +00001098 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
Devang Patel44498a62010-12-08 20:42:44 +00001099 };
Devang Patel1f48a952011-04-18 23:51:03 +00001100 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie139f7e52013-02-18 07:10:22 +00001101 if (isDefinition)
1102 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001103 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001104 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001105 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001106}
1107
Devang Patel50d280c2011-02-22 18:56:12 +00001108/// createNameSpace - This creates new descriptor for a namespace
Devang Patelfe58f952010-12-07 23:25:47 +00001109/// with the specified parent scope.
Devang Patel50d280c2011-02-22 18:56:12 +00001110DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patelfe58f952010-12-07 23:25:47 +00001111 DIFile File, unsigned LineNo) {
1112 Value *Elts[] = {
1113 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
David Blaikie6115ed02013-03-20 19:39:15 +00001114 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001115 getNonCompileUnitScope(Scope),
Devang Patelfe58f952010-12-07 23:25:47 +00001116 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +00001117 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1118 };
David Blaikie66438682013-03-11 23:21:19 +00001119 DINameSpace R(MDNode::get(VMContext, Elts));
1120 assert(R.Verify() &&
1121 "createNameSpace should return a verifiable DINameSpace");
1122 return R;
Devang Patelfe58f952010-12-07 23:25:47 +00001123}
1124
Eric Christopher6618a242011-10-11 22:59:11 +00001125/// createLexicalBlockFile - This creates a new MDNode that encapsulates
1126/// an existing scope with a new filename.
1127DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
Devang Patel9f997212012-02-08 00:17:07 +00001128 DIFile File) {
Eric Christopher6618a242011-10-11 22:59:11 +00001129 Value *Elts[] = {
1130 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie8faed272013-03-22 20:18:46 +00001131 File.getFileNode(),
David Blaikie7b246862013-03-22 19:13:22 +00001132 Scope
Eric Christopher6618a242011-10-11 22:59:11 +00001133 };
David Blaikie66438682013-03-11 23:21:19 +00001134 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1135 assert(
1136 R.Verify() &&
1137 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1138 return R;
Eric Christopher6618a242011-10-11 22:59:11 +00001139}
1140
Devang Patel50d280c2011-02-22 18:56:12 +00001141DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
Devang Patel43c249c2010-12-08 01:50:15 +00001142 unsigned Line, unsigned Col) {
Adrian Prantle06db0c2013-06-24 21:19:43 +00001143 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel43c249c2010-12-08 01:50:15 +00001144 static unsigned int unique_id = 0;
1145 Value *Elts[] = {
1146 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie4b52a882013-03-22 17:33:20 +00001147 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001148 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +00001149 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1150 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
Devang Patel43c249c2010-12-08 01:50:15 +00001151 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1152 };
David Blaikie66438682013-03-11 23:21:19 +00001153 DILexicalBlock R(MDNode::get(VMContext, Elts));
1154 assert(R.Verify() &&
1155 "createLexicalBlock should return a verifiable DILexicalBlock");
1156 return R;
Devang Patel43c249c2010-12-08 01:50:15 +00001157}
1158
Devang Patel50d280c2011-02-22 18:56:12 +00001159/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1160Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001161 Instruction *InsertBefore) {
1162 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001163 assert(VarInfo.isVariable() &&
1164 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001165 if (!DeclareFn)
1166 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1167
Jay Foadec9186b2011-04-21 19:59:31 +00001168 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001169 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001170}
1171
Devang Patel50d280c2011-02-22 18:56:12 +00001172/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1173Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001174 BasicBlock *InsertAtEnd) {
1175 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001176 assert(VarInfo.isVariable() &&
1177 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001178 if (!DeclareFn)
1179 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1180
Jay Foadec9186b2011-04-21 19:59:31 +00001181 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Devang Patelfe58f952010-12-07 23:25:47 +00001182
1183 // If this block already has a terminator then insert this intrinsic
1184 // before the terminator.
1185 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foada3efbb12011-07-15 08:37:34 +00001186 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patelfe58f952010-12-07 23:25:47 +00001187 else
Jay Foada3efbb12011-07-15 08:37:34 +00001188 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001189}
1190
Devang Patel50d280c2011-02-22 18:56:12 +00001191/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1192Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001193 DIVariable VarInfo,
1194 Instruction *InsertBefore) {
1195 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001196 assert(VarInfo.isVariable() &&
1197 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001198 if (!ValueFn)
1199 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1200
Jay Foadec9186b2011-04-21 19:59:31 +00001201 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001202 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1203 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001204 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001205}
1206
Devang Patel50d280c2011-02-22 18:56:12 +00001207/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1208Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001209 DIVariable VarInfo,
1210 BasicBlock *InsertAtEnd) {
1211 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001212 assert(VarInfo.isVariable() &&
1213 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001214 if (!ValueFn)
1215 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1216
Jay Foadec9186b2011-04-21 19:59:31 +00001217 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001218 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1219 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001220 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001221}