blob: 7027813b814dff5e79135476c6326674bf31eb30 [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,
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000620 TemplateParams,
621 NULL // Type Identifer
Eric Christopher87c06a82012-07-06 02:35:57 +0000622 };
David Blaikieca442a42013-03-26 23:46:39 +0000623 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000624 assert(R.isCompositeType() &&
625 "createClassType should return a DICompositeType");
David Blaikie66438682013-03-11 23:21:19 +0000626 return R;
Eric Christopher87c06a82012-07-06 02:35:57 +0000627}
628
Devang Patel50d280c2011-02-22 18:56:12 +0000629/// createStructType - Create debugging information entry for a struct.
David Blaikie6172f022013-02-25 01:07:18 +0000630DICompositeType DIBuilder::createStructType(DIDescriptor Context,
631 StringRef Name, DIFile File,
632 unsigned LineNumber,
633 uint64_t SizeInBits,
634 uint64_t AlignInBits,
635 unsigned Flags, DIType DerivedFrom,
636 DIArray Elements,
637 unsigned RunTimeLang,
638 MDNode *VTableHolder) {
Devang Patelfe58f952010-12-07 23:25:47 +0000639 // TAG_structure_type is encoded in DICompositeType format.
640 Value *Elts[] = {
641 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000642 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000643 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000644 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +0000645 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
646 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
647 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Devang Patel43c249c2010-12-08 01:50:15 +0000648 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelfe58f952010-12-07 23:25:47 +0000649 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
David Blaikie6172f022013-02-25 01:07:18 +0000650 DerivedFrom,
Devang Patelfe58f952010-12-07 23:25:47 +0000651 Elements,
652 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
David Blaikie6172f022013-02-25 01:07:18 +0000653 VTableHolder,
David Blaikied4f92fd2013-02-18 07:27:30 +0000654 NULL,
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000655 NULL // Type Identifer
Devang Patelfe58f952010-12-07 23:25:47 +0000656 };
David Blaikie66438682013-03-11 23:21:19 +0000657 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000658 assert(R.isCompositeType() &&
659 "createStructType should return a DICompositeType");
David Blaikie66438682013-03-11 23:21:19 +0000660 return R;
Devang Patelfe58f952010-12-07 23:25:47 +0000661}
662
Devang Patel50d280c2011-02-22 18:56:12 +0000663/// createUnionType - Create debugging information entry for an union.
Eric Christophercf0623b2013-04-02 22:55:52 +0000664DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
665 DIFile File, unsigned LineNumber,
666 uint64_t SizeInBits,
667 uint64_t AlignInBits, unsigned Flags,
668 DIArray Elements,
669 unsigned RunTimeLang) {
Devang Patel43c249c2010-12-08 01:50:15 +0000670 // TAG_union_type is encoded in DICompositeType format.
671 Value *Elts[] = {
672 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000673 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000674 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +0000675 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000676 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
677 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
678 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
679 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
680 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patelc104cf22011-12-16 17:51:31 +0000681 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000682 Elements,
683 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000684 NULL,
685 NULL,
686 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000687 };
David Blaikie72dfb052013-03-28 02:44:59 +0000688 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000689}
690
Devang Patel50d280c2011-02-22 18:56:12 +0000691/// createSubroutineType - Create subroutine type.
David Blaikied67c5ca2013-02-18 06:41:57 +0000692DICompositeType
693DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) {
Devang Patel43c249c2010-12-08 01:50:15 +0000694 // TAG_subroutine_type is encoded in DICompositeType format.
695 Value *Elts[] = {
696 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000697 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000698 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000699 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000700 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
701 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
702 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000703 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patel43c249c2010-12-08 01:50:15 +0000704 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000705 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000706 ParameterTypes,
707 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000708 NULL,
709 NULL,
710 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000711 };
David Blaikie72dfb052013-03-28 02:44:59 +0000712 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000713}
714
Eric Christopher6c0046f2011-08-26 21:02:40 +0000715/// createEnumerationType - Create debugging information entry for an
Devang Patel43c249c2010-12-08 01:50:15 +0000716/// enumeration.
David Blaikied67c5ca2013-02-18 06:41:57 +0000717DICompositeType DIBuilder::createEnumerationType(
718 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
719 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Adrian Prantl2f445be2013-04-19 19:56:02 +0000720 DIType UnderlyingType) {
Devang Patel43c249c2010-12-08 01:50:15 +0000721 // TAG_enumeration_type is encoded in DICompositeType format.
722 Value *Elts[] = {
723 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000724 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000725 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +0000726 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000727 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
728 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
729 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
730 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000731 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Adrian Prantl2f445be2013-04-19 19:56:02 +0000732 UnderlyingType,
Devang Patel43c249c2010-12-08 01:50:15 +0000733 Elements,
734 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000735 NULL,
736 NULL,
737 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000738 };
Devang Patel1f48a952011-04-18 23:51:03 +0000739 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000740 AllEnumTypes.push_back(Node);
David Blaikie72dfb052013-03-28 02:44:59 +0000741 return DICompositeType(Node);
Devang Patel43c249c2010-12-08 01:50:15 +0000742}
743
Devang Patel50d280c2011-02-22 18:56:12 +0000744/// createArrayType - Create debugging information entry for an array.
David Blaikied67c5ca2013-02-18 06:41:57 +0000745DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
746 DIType Ty, DIArray Subscripts) {
Devang Patel43c249c2010-12-08 01:50:15 +0000747 // TAG_array_type is encoded in DICompositeType format.
748 Value *Elts[] = {
749 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000750 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000751 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000752 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000753 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
754 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
755 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
756 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
757 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
758 Ty,
759 Subscripts,
760 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000761 NULL,
762 NULL,
763 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000764 };
David Blaikie72dfb052013-03-28 02:44:59 +0000765 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000766}
767
Devang Patel50d280c2011-02-22 18:56:12 +0000768/// createVectorType - Create debugging information entry for a vector.
Manman Ren37bfb182013-06-07 03:13:46 +0000769DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
770 DIType Ty, DIArray Subscripts) {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000771 // A vector is an array type with the FlagVector flag applied.
Devang Patel43c249c2010-12-08 01:50:15 +0000772 Value *Elts[] = {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000773 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000774 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000775 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000776 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000777 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
778 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
779 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
780 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000781 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
Devang Patel43c249c2010-12-08 01:50:15 +0000782 Ty,
783 Subscripts,
784 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000785 NULL,
786 NULL,
787 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000788 };
Manman Ren37bfb182013-06-07 03:13:46 +0000789 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000790}
Devang Patelfe58f952010-12-07 23:25:47 +0000791
Devang Patel50d280c2011-02-22 18:56:12 +0000792/// createArtificialType - Create a new DIType with "artificial" flag set.
793DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel35fcd652010-11-04 15:01:38 +0000794 if (Ty.isArtificial())
795 return Ty;
796
797 SmallVector<Value *, 9> Elts;
798 MDNode *N = Ty;
799 assert (N && "Unexpected input DIType!");
800 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
801 if (Value *V = N->getOperand(i))
802 Elts.push_back(V);
803 else
804 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
805 }
806
807 unsigned CurFlags = Ty.getFlags();
808 CurFlags = CurFlags | DIType::FlagArtificial;
809
810 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000811 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Devang Patel35fcd652010-11-04 15:01:38 +0000812
David Blaikie72dfb052013-03-28 02:44:59 +0000813 return DIType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000814}
Devang Patelfe58f952010-12-07 23:25:47 +0000815
Eric Christopher1f55eb42013-01-08 01:53:42 +0000816/// createObjectPointerType - Create a new type with both the object pointer
817/// and artificial flags set.
Eric Christophere5212782012-09-12 23:36:19 +0000818DIType DIBuilder::createObjectPointerType(DIType Ty) {
819 if (Ty.isObjectPointer())
820 return Ty;
821
822 SmallVector<Value *, 9> Elts;
823 MDNode *N = Ty;
824 assert (N && "Unexpected input DIType!");
825 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
826 if (Value *V = N->getOperand(i))
827 Elts.push_back(V);
828 else
829 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
830 }
831
832 unsigned CurFlags = Ty.getFlags();
833 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
834
835 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000836 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Eric Christophere5212782012-09-12 23:36:19 +0000837
David Blaikie72dfb052013-03-28 02:44:59 +0000838 return DIType(MDNode::get(VMContext, Elts));
Eric Christophere5212782012-09-12 23:36:19 +0000839}
840
Eric Christopher6c0046f2011-08-26 21:02:40 +0000841/// retainType - Retain DIType in a module even if it is not referenced
Devang Patel43c249c2010-12-08 01:50:15 +0000842/// through debug info anchors.
Devang Patel50d280c2011-02-22 18:56:12 +0000843void DIBuilder::retainType(DIType T) {
Devang Patel94c7ddb2011-08-16 22:09:43 +0000844 AllRetainTypes.push_back(T);
Devang Patel43c249c2010-12-08 01:50:15 +0000845}
846
Devang Patel50d280c2011-02-22 18:56:12 +0000847/// createUnspecifiedParameter - Create unspeicified type descriptor
Devang Patel43c249c2010-12-08 01:50:15 +0000848/// for the subroutine type.
Devang Patel50d280c2011-02-22 18:56:12 +0000849DIDescriptor DIBuilder::createUnspecifiedParameter() {
Eric Christopher6c0046f2011-08-26 21:02:40 +0000850 Value *Elts[] = {
851 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
Devang Patel43c249c2010-12-08 01:50:15 +0000852 };
Devang Patel1f48a952011-04-18 23:51:03 +0000853 return DIDescriptor(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000854}
855
Eric Christopher4fe34572012-02-08 00:22:26 +0000856/// createForwardDecl - Create a temporary forward-declared type that
857/// can be RAUW'd if the full type is seen.
David Blaikie692062f2013-08-16 20:42:14 +0000858DICompositeType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name,
Eric Christopher216432d2012-04-23 19:00:11 +0000859 DIDescriptor Scope, DIFile F,
Eli Friedmance3da6f2012-10-05 01:49:14 +0000860 unsigned Line, unsigned RuntimeLang,
861 uint64_t SizeInBits,
862 uint64_t AlignInBits) {
Eric Christopher4fe34572012-02-08 00:22:26 +0000863 // Create a temporary MDNode.
864 Value *Elts[] = {
865 GetTagConstant(VMContext, Tag),
David Blaikie4776bce2013-03-20 00:26:26 +0000866 F.getFileNode(),
Eric Christopher216432d2012-04-23 19:00:11 +0000867 getNonCompileUnitScope(Scope),
Eric Christopher4fe34572012-02-08 00:22:26 +0000868 MDString::get(VMContext, Name),
Eric Christopher4fe34572012-02-08 00:22:26 +0000869 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000870 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
871 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher4fe34572012-02-08 00:22:26 +0000872 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
873 ConstantInt::get(Type::getInt32Ty(VMContext),
Eric Christopher9f90e872012-02-20 18:04:14 +0000874 DIDescriptor::FlagFwdDecl),
875 NULL,
876 DIArray(),
David Blaikie692062f2013-08-16 20:42:14 +0000877 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000878 NULL,
879 NULL, //TemplateParams
880 NULL // Type Identifer
Eric Christopher4fe34572012-02-08 00:22:26 +0000881 };
882 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
David Blaikie692062f2013-08-16 20:42:14 +0000883 DICompositeType RetTy(Node);
884 assert(RetTy.isCompositeType() &&
Manman Ren89c83b72013-07-01 21:02:01 +0000885 "createForwardDecl result should be a DIType");
Manman Ren88328d22013-07-02 18:37:35 +0000886 return RetTy;
Eric Christopher4fe34572012-02-08 00:22:26 +0000887}
888
Devang Patel50d280c2011-02-22 18:56:12 +0000889/// getOrCreateArray - Get a DIArray, create one if required.
Jay Foad68550182011-04-24 10:11:03 +0000890DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
891 if (Elements.empty()) {
Bill Wendlingf46b4972012-07-06 17:47:36 +0000892 Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
Jay Foadec9186b2011-04-21 19:59:31 +0000893 return DIArray(MDNode::get(VMContext, Null));
Devang Patelfe58f952010-12-07 23:25:47 +0000894 }
Jay Foad68550182011-04-24 10:11:03 +0000895 return DIArray(MDNode::get(VMContext, Elements));
Devang Patelfe58f952010-12-07 23:25:47 +0000896}
897
Devang Patel50d280c2011-02-22 18:56:12 +0000898/// getOrCreateSubrange - Create a descriptor for a value range. This
Devang Patel43c249c2010-12-08 01:50:15 +0000899/// implicitly uniques the values returned.
Bill Wendling9493dae2012-12-04 21:34:03 +0000900DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Devang Patel43c249c2010-12-08 01:50:15 +0000901 Value *Elts[] = {
902 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
903 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
Bill Wendlinga7645a32012-12-04 06:20:49 +0000904 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
Devang Patel43c249c2010-12-08 01:50:15 +0000905 };
906
Devang Patel1f48a952011-04-18 23:51:03 +0000907 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000908}
909
David Blaikie3fac43d2013-03-20 17:49:48 +0000910/// \brief Create a new descriptor for the specified global.
Devang Patelfe58f952010-12-07 23:25:47 +0000911DIGlobalVariable DIBuilder::
David Blaikie3fac43d2013-03-20 17:49:48 +0000912createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F,
913 unsigned LineNumber, DIType Ty, bool isLocalToUnit,
914 Value *Val) {
Devang Patelfe58f952010-12-07 23:25:47 +0000915 Value *Elts[] = {
916 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000917 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000918 NULL, // TheCU,
Devang Patelfe58f952010-12-07 23:25:47 +0000919 MDString::get(VMContext, Name),
920 MDString::get(VMContext, Name),
David Blaikie3fac43d2013-03-20 17:49:48 +0000921 MDString::get(VMContext, LinkageName),
Devang Patelfe58f952010-12-07 23:25:47 +0000922 F,
923 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
924 Ty,
925 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
926 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000927 Val,
928 DIDescriptor()
Devang Patelfe58f952010-12-07 23:25:47 +0000929 };
Devang Patel1f48a952011-04-18 23:51:03 +0000930 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000931 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000932 return DIGlobalVariable(Node);
933}
934
David Blaikie3fac43d2013-03-20 17:49:48 +0000935/// \brief Create a new descriptor for the specified global.
936DIGlobalVariable DIBuilder::
937createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber,
938 DIType Ty, bool isLocalToUnit, Value *Val) {
939 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
940 Val);
941}
942
Devang Patel50d280c2011-02-22 18:56:12 +0000943/// createStaticVariable - Create a new descriptor for the specified static
Devang Patelfe58f952010-12-07 23:25:47 +0000944/// variable.
945DIGlobalVariable DIBuilder::
Eric Christopher6c0046f2011-08-26 21:02:40 +0000946createStaticVariable(DIDescriptor Context, StringRef Name,
947 StringRef LinkageName, DIFile F, unsigned LineNumber,
Eric Christopher6b6061f2013-01-16 01:22:23 +0000948 DIType Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) {
Devang Patelfe58f952010-12-07 23:25:47 +0000949 Value *Elts[] = {
950 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000951 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000952 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000953 MDString::get(VMContext, Name),
954 MDString::get(VMContext, Name),
955 MDString::get(VMContext, LinkageName),
956 F,
957 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
958 Ty,
959 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
960 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000961 Val,
962 DIDescriptor(Decl)
Devang Patelfe58f952010-12-07 23:25:47 +0000963 };
Devang Patel1f48a952011-04-18 23:51:03 +0000964 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000965 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000966 return DIGlobalVariable(Node);
967}
968
Devang Patel50d280c2011-02-22 18:56:12 +0000969/// createVariable - Create a new descriptor for the specified variable.
970DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel48f17ba2010-12-07 23:58:00 +0000971 StringRef Name, DIFile File,
Eric Christopher6c0046f2011-08-26 21:02:40 +0000972 unsigned LineNo, DIType Ty,
Devang Patele9e16c52011-03-01 22:58:13 +0000973 bool AlwaysPreserve, unsigned Flags,
974 unsigned ArgNo) {
David Blaikie66438682013-03-11 23:21:19 +0000975 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren89c83b72013-07-01 21:02:01 +0000976 assert((!Context || Context.isScope()) &&
David Blaikie66438682013-03-11 23:21:19 +0000977 "createLocalVariable should be called with a valid Context");
Manman Ren89c83b72013-07-01 21:02:01 +0000978 assert(Ty.isType() &&
David Blaikie66438682013-03-11 23:21:19 +0000979 "createLocalVariable should be called with a valid type");
Devang Patel48f17ba2010-12-07 23:58:00 +0000980 Value *Elts[] = {
981 GetTagConstant(VMContext, Tag),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000982 getNonCompileUnitScope(Scope),
Devang Patel48f17ba2010-12-07 23:58:00 +0000983 MDString::get(VMContext, Name),
984 File,
Devang Patele9e16c52011-03-01 22:58:13 +0000985 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
Devang Patel48f17ba2010-12-07 23:58:00 +0000986 Ty,
Devang Patel23336b42011-07-19 19:41:54 +0000987 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000988 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel48f17ba2010-12-07 23:58:00 +0000989 };
Devang Patel1f48a952011-04-18 23:51:03 +0000990 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel48f17ba2010-12-07 23:58:00 +0000991 if (AlwaysPreserve) {
992 // The optimizer may remove local variable. If there is an interest
993 // to preserve variable info in such situation then stash it in a
994 // named mdnode.
995 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel93d39be2011-08-19 23:28:12 +0000996 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel48f17ba2010-12-07 23:58:00 +0000997 FnLocals->addOperand(Node);
998 }
Manman Ren88328d22013-07-02 18:37:35 +0000999 DIVariable RetVar(Node);
1000 assert(RetVar.isVariable() &&
Manman Ren89c83b72013-07-01 21:02:01 +00001001 "createLocalVariable should return a valid DIVariable");
Manman Ren88328d22013-07-02 18:37:35 +00001002 return RetVar;
Devang Patel48f17ba2010-12-07 23:58:00 +00001003}
1004
Devang Patel50d280c2011-02-22 18:56:12 +00001005/// createComplexVariable - Create a new descriptor for the specified variable
Devang Patelfe58f952010-12-07 23:25:47 +00001006/// which has a complex address expression for its address.
Devang Patel50d280c2011-02-22 18:56:12 +00001007DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
Devang Patelfe58f952010-12-07 23:25:47 +00001008 StringRef Name, DIFile F,
1009 unsigned LineNo,
Jay Foad68550182011-04-24 10:11:03 +00001010 DIType Ty, ArrayRef<Value *> Addr,
1011 unsigned ArgNo) {
Devang Patelfe58f952010-12-07 23:25:47 +00001012 SmallVector<Value *, 15> Elts;
1013 Elts.push_back(GetTagConstant(VMContext, Tag));
Devang Patel94c7ddb2011-08-16 22:09:43 +00001014 Elts.push_back(getNonCompileUnitScope(Scope)),
Devang Patelfe58f952010-12-07 23:25:47 +00001015 Elts.push_back(MDString::get(VMContext, Name));
1016 Elts.push_back(F);
Eric Christopher6c0046f2011-08-26 21:02:40 +00001017 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
Devang Patel9f997212012-02-08 00:17:07 +00001018 (LineNo | (ArgNo << 24))));
Devang Patelfe58f952010-12-07 23:25:47 +00001019 Elts.push_back(Ty);
Bill Wendlingf46b4972012-07-06 17:47:36 +00001020 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1021 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
Jay Foad68550182011-04-24 10:11:03 +00001022 Elts.append(Addr.begin(), Addr.end());
Devang Patelfe58f952010-12-07 23:25:47 +00001023
Devang Patel1f48a952011-04-18 23:51:03 +00001024 return DIVariable(MDNode::get(VMContext, Elts));
Devang Patelfe58f952010-12-07 23:25:47 +00001025}
1026
Devang Patel50d280c2011-02-22 18:56:12 +00001027/// createFunction - Create a new descriptor for the specified function.
1028DISubprogram DIBuilder::createFunction(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001029 StringRef Name,
1030 StringRef LinkageName,
1031 DIFile File, unsigned LineNo,
David Blaikie3d331842013-05-22 23:22:18 +00001032 DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001033 bool isLocalToUnit, bool isDefinition,
Eric Christopher6126a1e2012-04-03 00:43:49 +00001034 unsigned ScopeLine,
Devang Patel44498a62010-12-08 20:42:44 +00001035 unsigned Flags, bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001036 Function *Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001037 MDNode *TParams,
1038 MDNode *Decl) {
David Blaikie3d331842013-05-22 23:22:18 +00001039 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1040 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001041 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001042 Value *Elts[] = {
1043 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001044 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001045 getNonCompileUnitScope(Context),
Devang Patel44498a62010-12-08 20:42:44 +00001046 MDString::get(VMContext, Name),
1047 MDString::get(VMContext, Name),
1048 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001049 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1050 Ty,
1051 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1052 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1053 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1054 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patel9642c572011-12-15 17:55:56 +00001055 NULL,
Devang Patel44498a62010-12-08 20:42:44 +00001056 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1057 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001058 Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001059 TParams,
Devang Patel93d39be2011-08-19 23:28:12 +00001060 Decl,
David Blaikief839eed2013-02-04 05:56:36 +00001061 MDNode::getTemporary(VMContext, TElts),
Eric Christopher6126a1e2012-04-03 00:43:49 +00001062 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
Devang Patel44498a62010-12-08 20:42:44 +00001063 };
Devang Patel1f48a952011-04-18 23:51:03 +00001064 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel44498a62010-12-08 20:42:44 +00001065
1066 // Create a named metadata so that we do not lose this mdnode.
David Blaikie139f7e52013-02-18 07:10:22 +00001067 if (isDefinition)
1068 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001069 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001070 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001071 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001072}
1073
Devang Patel50d280c2011-02-22 18:56:12 +00001074/// createMethod - Create a new descriptor for the specified C++ method.
1075DISubprogram DIBuilder::createMethod(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001076 StringRef Name,
1077 StringRef LinkageName,
1078 DIFile F,
David Blaikie3d331842013-05-22 23:22:18 +00001079 unsigned LineNo, DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001080 bool isLocalToUnit,
1081 bool isDefinition,
1082 unsigned VK, unsigned VIndex,
1083 MDNode *VTableHolder,
1084 unsigned Flags,
1085 bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001086 Function *Fn,
1087 MDNode *TParam) {
David Blaikie3d331842013-05-22 23:22:18 +00001088 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1089 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001090 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001091 Value *Elts[] = {
1092 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001093 F.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001094 getNonCompileUnitScope(Context),
Devang Patel44498a62010-12-08 20:42:44 +00001095 MDString::get(VMContext, Name),
1096 MDString::get(VMContext, Name),
1097 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001098 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1099 Ty,
1100 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1101 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1102 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
1103 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
1104 VTableHolder,
1105 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1106 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001107 Fn,
1108 TParam,
Bill Wendlingf46b4972012-07-06 17:47:36 +00001109 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikief839eed2013-02-04 05:56:36 +00001110 MDNode::getTemporary(VMContext, TElts),
Eric Christopher25016522012-05-18 00:16:22 +00001111 // FIXME: Do we want to use different scope/lines?
Eric Christopher6126a1e2012-04-03 00:43:49 +00001112 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
Devang Patel44498a62010-12-08 20:42:44 +00001113 };
Devang Patel1f48a952011-04-18 23:51:03 +00001114 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie139f7e52013-02-18 07:10:22 +00001115 if (isDefinition)
1116 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001117 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001118 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001119 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001120}
1121
Devang Patel50d280c2011-02-22 18:56:12 +00001122/// createNameSpace - This creates new descriptor for a namespace
Devang Patelfe58f952010-12-07 23:25:47 +00001123/// with the specified parent scope.
Devang Patel50d280c2011-02-22 18:56:12 +00001124DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patelfe58f952010-12-07 23:25:47 +00001125 DIFile File, unsigned LineNo) {
1126 Value *Elts[] = {
1127 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
David Blaikie6115ed02013-03-20 19:39:15 +00001128 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001129 getNonCompileUnitScope(Scope),
Devang Patelfe58f952010-12-07 23:25:47 +00001130 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +00001131 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1132 };
David Blaikie66438682013-03-11 23:21:19 +00001133 DINameSpace R(MDNode::get(VMContext, Elts));
1134 assert(R.Verify() &&
1135 "createNameSpace should return a verifiable DINameSpace");
1136 return R;
Devang Patelfe58f952010-12-07 23:25:47 +00001137}
1138
Eric Christopher6618a242011-10-11 22:59:11 +00001139/// createLexicalBlockFile - This creates a new MDNode that encapsulates
1140/// an existing scope with a new filename.
1141DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
Devang Patel9f997212012-02-08 00:17:07 +00001142 DIFile File) {
Eric Christopher6618a242011-10-11 22:59:11 +00001143 Value *Elts[] = {
1144 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie8faed272013-03-22 20:18:46 +00001145 File.getFileNode(),
David Blaikie7b246862013-03-22 19:13:22 +00001146 Scope
Eric Christopher6618a242011-10-11 22:59:11 +00001147 };
David Blaikie66438682013-03-11 23:21:19 +00001148 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1149 assert(
1150 R.Verify() &&
1151 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1152 return R;
Eric Christopher6618a242011-10-11 22:59:11 +00001153}
1154
Devang Patel50d280c2011-02-22 18:56:12 +00001155DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
Devang Patel43c249c2010-12-08 01:50:15 +00001156 unsigned Line, unsigned Col) {
Adrian Prantle06db0c2013-06-24 21:19:43 +00001157 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel43c249c2010-12-08 01:50:15 +00001158 static unsigned int unique_id = 0;
1159 Value *Elts[] = {
1160 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie4b52a882013-03-22 17:33:20 +00001161 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001162 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +00001163 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1164 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
Devang Patel43c249c2010-12-08 01:50:15 +00001165 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1166 };
David Blaikie66438682013-03-11 23:21:19 +00001167 DILexicalBlock R(MDNode::get(VMContext, Elts));
1168 assert(R.Verify() &&
1169 "createLexicalBlock should return a verifiable DILexicalBlock");
1170 return R;
Devang Patel43c249c2010-12-08 01:50:15 +00001171}
1172
Devang Patel50d280c2011-02-22 18:56:12 +00001173/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1174Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001175 Instruction *InsertBefore) {
1176 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001177 assert(VarInfo.isVariable() &&
1178 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001179 if (!DeclareFn)
1180 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1181
Jay Foadec9186b2011-04-21 19:59:31 +00001182 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001183 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001184}
1185
Devang Patel50d280c2011-02-22 18:56:12 +00001186/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1187Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001188 BasicBlock *InsertAtEnd) {
1189 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001190 assert(VarInfo.isVariable() &&
1191 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001192 if (!DeclareFn)
1193 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1194
Jay Foadec9186b2011-04-21 19:59:31 +00001195 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Devang Patelfe58f952010-12-07 23:25:47 +00001196
1197 // If this block already has a terminator then insert this intrinsic
1198 // before the terminator.
1199 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foada3efbb12011-07-15 08:37:34 +00001200 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patelfe58f952010-12-07 23:25:47 +00001201 else
Jay Foada3efbb12011-07-15 08:37:34 +00001202 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001203}
1204
Devang Patel50d280c2011-02-22 18:56:12 +00001205/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1206Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001207 DIVariable VarInfo,
1208 Instruction *InsertBefore) {
1209 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001210 assert(VarInfo.isVariable() &&
1211 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001212 if (!ValueFn)
1213 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1214
Jay Foadec9186b2011-04-21 19:59:31 +00001215 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001216 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1217 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001218 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001219}
1220
Devang Patel50d280c2011-02-22 18:56:12 +00001221/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1222Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001223 DIVariable VarInfo,
1224 BasicBlock *InsertAtEnd) {
1225 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001226 assert(VarInfo.isVariable() &&
1227 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001228 if (!ValueFn)
1229 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1230
Jay Foadec9186b2011-04-21 19:59:31 +00001231 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001232 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1233 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001234 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001235}