blob: 199476f7144be31b74da1128a1285a19c1e70b4e [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
Manman Ren3a0e9b52013-08-29 23:17:54 +000043 SmallVector<Value *, 16> RetainValues;
44 // Declarations and definitions of the same type may be retained. Some
45 // clients RAUW these pairs, leaving duplicates in the retained types
46 // list. Use a set to remove the duplicates while we transform the
47 // TrackingVHs back into Values.
48 SmallPtrSet<Value *, 16> RetainSet;
49 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
50 if (RetainSet.insert(AllRetainTypes[I]))
51 RetainValues.push_back(AllRetainTypes[I]);
52 DIArray RetainTypes = getOrCreateArray(RetainValues);
Devang Patel94c7ddb2011-08-16 22:09:43 +000053 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
54
55 DIArray SPs = getOrCreateArray(AllSubprograms);
56 DIType(TempSubprograms).replaceAllUsesWith(SPs);
Devang Patel93d39be2011-08-19 23:28:12 +000057 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
58 DISubprogram SP(SPs.getElement(i));
Eric Christopher216432d2012-04-23 19:00:11 +000059 SmallVector<Value *, 4> Variables;
Devang Patel93d39be2011-08-19 23:28:12 +000060 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
Devang Patel93d39be2011-08-19 23:28:12 +000061 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
62 Variables.push_back(NMD->getOperand(ii));
Devang Patel93d39be2011-08-19 23:28:12 +000063 NMD->eraseFromParent();
64 }
Eric Christopher216432d2012-04-23 19:00:11 +000065 if (MDNode *Temp = SP.getVariablesNodes()) {
66 DIArray AV = getOrCreateArray(Variables);
67 DIType(Temp).replaceAllUsesWith(AV);
68 }
Devang Patel93d39be2011-08-19 23:28:12 +000069 }
Devang Patel94c7ddb2011-08-16 22:09:43 +000070
71 DIArray GVs = getOrCreateArray(AllGVs);
72 DIType(TempGVs).replaceAllUsesWith(GVs);
David Blaikiec462db62013-04-22 06:12:31 +000073
74 DIArray IMs = getOrCreateArray(AllImportedModules);
75 DIType(TempImportedModules).replaceAllUsesWith(IMs);
Devang Patel94c7ddb2011-08-16 22:09:43 +000076}
77
Eric Christopher6c0046f2011-08-26 21:02:40 +000078/// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
79/// N.
Devang Patel94c7ddb2011-08-16 22:09:43 +000080static MDNode *getNonCompileUnitScope(MDNode *N) {
81 if (DIDescriptor(N).isCompileUnit())
82 return NULL;
83 return N;
Devang Patel6326a422011-08-15 23:00:00 +000084}
85
David Blaikie00c5c5d2013-03-20 23:58:12 +000086static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
87 StringRef Directory) {
88 assert(!Filename.empty() && "Unable to create file without name");
89 Value *Pair[] = {
90 MDString::get(VMContext, Filename),
91 MDString::get(VMContext, Directory),
92 };
93 return MDNode::get(VMContext, Pair);
94}
95
Devang Patel50d280c2011-02-22 18:56:12 +000096/// createCompileUnit - A CompileUnit provides an anchor for all debugging
Devang Patel35fcd652010-11-04 15:01:38 +000097/// information generated during this instance of compilation.
Eric Christopher1fe3f9a2013-07-19 00:51:47 +000098DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
99 StringRef Directory,
100 StringRef Producer, bool isOptimized,
101 StringRef Flags, unsigned RunTimeVer,
102 StringRef SplitName) {
Chandler Carruthb0dc4d92012-01-10 18:18:52 +0000103 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
104 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
105 "Invalid Language tag");
106 assert(!Filename.empty() &&
107 "Unable to create compile unit without filename");
Devang Patel94c7ddb2011-08-16 22:09:43 +0000108 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
109 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000110
111 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000112
113 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000114
115 TempGVs = MDNode::getTemporary(VMContext, TElts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000116
David Blaikiec462db62013-04-22 06:12:31 +0000117 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
118
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000119 Value *Elts[] = {
120 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
David Blaikie00c5c5d2013-03-20 23:58:12 +0000121 createFilePathPair(VMContext, Filename, Directory),
David Blaikie162c8002013-03-20 22:52:54 +0000122 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000123 MDString::get(VMContext, Producer),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000124 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
125 MDString::get(VMContext, Flags),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000126 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
David Blaikiea8eefc72013-02-02 05:56:24 +0000127 TempEnumTypes,
128 TempRetainTypes,
129 TempSubprograms,
Eric Christophere4b67902013-02-22 23:50:04 +0000130 TempGVs,
David Blaikiec462db62013-04-22 06:12:31 +0000131 TempImportedModules,
Eric Christophere4b67902013-02-22 23:50:04 +0000132 MDString::get(VMContext, SplitName)
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000133 };
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000134
135 MDNode *CUNode = MDNode::get(VMContext, Elts);
Devang Patel464f4ef2011-05-03 16:18:28 +0000136
137 // Create a named metadata so that it is easier to find cu in a module.
138 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000139 NMD->addOperand(CUNode);
140
141 return DICompileUnit(CUNode);
Devang Patel35fcd652010-11-04 15:01:38 +0000142}
143
David Blaikie7b72cc72013-05-20 22:50:35 +0000144static DIImportedEntity
145createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
146 unsigned Line, StringRef Name,
147 SmallVectorImpl<Value *> &AllImportedModules) {
148 const MDNode *R;
149 if (Name.empty()) {
150 Value *Elts[] = {
151 GetTagConstant(C, dwarf::DW_TAG_imported_module),
152 Context,
153 NS,
154 ConstantInt::get(Type::getInt32Ty(C), Line),
155 };
156 R = MDNode::get(C, Elts);
157 } else {
158 Value *Elts[] = {
159 GetTagConstant(C, dwarf::DW_TAG_imported_module),
160 Context,
161 NS,
162 ConstantInt::get(Type::getInt32Ty(C), Line),
163 MDString::get(C, Name)
164 };
165 R = MDNode::get(C, Elts);
166 }
167 DIImportedEntity M(R);
David Blaikie20d9e412013-05-07 21:35:53 +0000168 assert(M.Verify() && "Imported module should be valid");
169 AllImportedModules.push_back(M);
170 return M;
171}
172
David Blaikie7b72cc72013-05-20 22:50:35 +0000173DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
174 DINameSpace NS, unsigned Line,
175 StringRef Name) {
176 return ::createImportedModule(VMContext, Context, NS, Line, Name,
177 AllImportedModules);
178}
179
180DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
181 DIImportedEntity NS,
182 unsigned Line,
183 StringRef Name) {
184 return ::createImportedModule(VMContext, Context, NS, Line, Name,
185 AllImportedModules);
186}
187
David Blaikie20d9e412013-05-07 21:35:53 +0000188DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
189 DIDescriptor Decl,
190 unsigned Line) {
191 Value *Elts[] = {
192 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
193 Context,
194 Decl,
195 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
196 };
197 DIImportedEntity M(MDNode::get(VMContext, Elts));
David Blaikiec462db62013-04-22 06:12:31 +0000198 assert(M.Verify() && "Imported module should be valid");
199 AllImportedModules.push_back(M);
200 return M;
201}
202
Devang Patel50d280c2011-02-22 18:56:12 +0000203/// createFile - Create a file descriptor to hold debugging information
Devang Patel35fcd652010-11-04 15:01:38 +0000204/// for a file.
Devang Patel50d280c2011-02-22 18:56:12 +0000205DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
David Blaikieb4cf0ab2013-03-17 21:13:55 +0000206 Value *Elts[] = {
207 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
David Blaikie72dfb052013-03-28 02:44:59 +0000208 createFilePathPair(VMContext, Filename, Directory)
David Blaikieb4cf0ab2013-03-17 21:13:55 +0000209 };
David Blaikie72dfb052013-03-28 02:44:59 +0000210 return DIFile(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000211}
212
Devang Patel50d280c2011-02-22 18:56:12 +0000213/// createEnumerator - Create a single enumerator value.
David Blaikie8de0a462013-06-24 17:34:33 +0000214DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
Devang Patel811ae5b2011-09-12 18:26:08 +0000215 assert(!Name.empty() && "Unable to create enumerator without name");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000216 Value *Elts[] = {
217 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
218 MDString::get(VMContext, Name),
219 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
220 };
David Blaikie72dfb052013-03-28 02:44:59 +0000221 return DIEnumerator(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000222}
223
Peter Collingbourne03ccdb52013-06-27 22:50:59 +0000224/// \brief Create a DWARF unspecified type.
225DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel734a67c2011-09-14 23:13:28 +0000226 assert(!Name.empty() && "Unable to create type without name");
Peter Collingbourne03ccdb52013-06-27 22:50:59 +0000227 // Unspecified types are encoded in DIBasicType format. Line number, filename,
228 // size, alignment, offset and flags are always empty here.
Devang Patel734a67c2011-09-14 23:13:28 +0000229 Value *Elts[] = {
230 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000231 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000232 NULL, // Unused
Devang Patel734a67c2011-09-14 23:13:28 +0000233 MDString::get(VMContext, Name),
Devang Patel734a67c2011-09-14 23:13:28 +0000234 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
235 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
236 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
237 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
238 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
Bill Wendling9fdb7c02012-07-06 17:49:19 +0000239 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
Devang Patel734a67c2011-09-14 23:13:28 +0000240 };
Manman Ren576d49a2013-06-07 18:35:53 +0000241 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel734a67c2011-09-14 23:13:28 +0000242}
243
Peter Collingbourne03ccdb52013-06-27 22:50:59 +0000244/// \brief Create C++11 nullptr type.
245DIBasicType DIBuilder::createNullPtrType() {
246 return createUnspecifiedType("decltype(nullptr)");
247}
248
Eric Christopher6c0046f2011-08-26 21:02:40 +0000249/// createBasicType - Create debugging information entry for a basic
Devang Patel35fcd652010-11-04 15:01:38 +0000250/// type, e.g 'char'.
David Blaikie2ce067a2013-02-12 00:40:41 +0000251DIBasicType
252DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
253 uint64_t AlignInBits, unsigned Encoding) {
Devang Patel811ae5b2011-09-12 18:26:08 +0000254 assert(!Name.empty() && "Unable to create type without name");
Devang Patel35fcd652010-11-04 15:01:38 +0000255 // Basic types are encoded in DIBasicType format. Line number, filename,
256 // offset and flags are always empty here.
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000257 Value *Elts[] = {
258 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000259 NULL, // File/directory name
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000260 NULL, // Unused
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000261 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000262 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
263 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
264 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
265 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
266 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
267 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
268 };
David Blaikie72dfb052013-03-28 02:44:59 +0000269 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000270}
271
Nick Lewyckyffab7d02011-11-09 22:45:04 +0000272/// createQualifiedType - Create debugging information entry for a qualified
Devang Patel35fcd652010-11-04 15:01:38 +0000273/// type, e.g. 'const int'.
David Blaikied67c5ca2013-02-18 06:41:57 +0000274DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000275 // Qualified types are encoded in DIDerivedType format.
276 Value *Elts[] = {
277 GetTagConstant(VMContext, Tag),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000278 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000279 NULL, // Unused
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000280 MDString::get(VMContext, StringRef()), // Empty name.
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000281 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
282 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
283 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
284 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
285 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Ren78c2f9b2013-10-08 22:56:31 +0000286 FromTy.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000287 };
David Blaikie72dfb052013-03-28 02:44:59 +0000288 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000289}
290
Devang Patel50d280c2011-02-22 18:56:12 +0000291/// createPointerType - Create debugging information entry for a pointer.
David Blaikied67c5ca2013-02-18 06:41:57 +0000292DIDerivedType
293DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
294 uint64_t AlignInBits, StringRef Name) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000295 // Pointer types are encoded in DIDerivedType format.
296 Value *Elts[] = {
297 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000298 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000299 NULL, // Unused
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000300 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000301 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
302 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
303 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
304 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
305 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renc664d762013-10-05 01:43:03 +0000306 PointeeTy.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000307 };
David Blaikie72dfb052013-03-28 02:44:59 +0000308 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000309}
310
Eric Christopher09b79812013-04-19 20:37:12 +0000311DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
312 DIType Base) {
David Blaikie62fdfb52013-01-07 05:51:15 +0000313 // Pointer types are encoded in DIDerivedType format.
314 Value *Elts[] = {
315 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000316 NULL, // Filename
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000317 NULL, // Unused
David Blaikie62fdfb52013-01-07 05:51:15 +0000318 NULL,
David Blaikie62fdfb52013-01-07 05:51:15 +0000319 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
320 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
321 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
322 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
323 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Ren78c2f9b2013-10-08 22:56:31 +0000324 PointeeTy.getRef(),
Manman Rene5388392013-09-30 19:42:10 +0000325 Base.getRef()
David Blaikie62fdfb52013-01-07 05:51:15 +0000326 };
David Blaikie72dfb052013-03-28 02:44:59 +0000327 return DIDerivedType(MDNode::get(VMContext, Elts));
David Blaikie62fdfb52013-01-07 05:51:15 +0000328}
329
Eric Christopher791e6292012-05-19 01:36:37 +0000330/// createReferenceType - Create debugging information entry for a reference
331/// type.
David Blaikied67c5ca2013-02-18 06:41:57 +0000332DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
Manman Ren89c83b72013-07-01 21:02:01 +0000333 assert(RTy.isType() && "Unable to create reference type");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000334 // References are encoded in DIDerivedType format.
335 Value *Elts[] = {
Eric Christopher791e6292012-05-19 01:36:37 +0000336 GetTagConstant(VMContext, Tag),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000337 NULL, // Filename
Eric Christopher6c0046f2011-08-26 21:02:40 +0000338 NULL, // TheCU,
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000339 NULL, // Name
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000340 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
341 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
342 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
343 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
344 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Ren78c2f9b2013-10-08 22:56:31 +0000345 RTy.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000346 };
David Blaikie72dfb052013-03-28 02:44:59 +0000347 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000348}
349
Devang Patel50d280c2011-02-22 18:56:12 +0000350/// createTypedef - Create debugging information entry for a typedef.
David Blaikied67c5ca2013-02-18 06:41:57 +0000351DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
352 unsigned LineNo, DIDescriptor Context) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000353 // typedefs are encoded in DIDerivedType format.
Manman Ren89c83b72013-07-01 21:02:01 +0000354 assert(Ty.isType() && "Invalid typedef type!");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000355 Value *Elts[] = {
356 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
David Blaikie4776bce2013-03-20 00:26:26 +0000357 File.getFileNode(),
Manman Renb6f74f02013-10-08 23:49:38 +0000358 DIScope(getNonCompileUnitScope(Context)).getRef(),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000359 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000360 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
361 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
362 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
363 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
364 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Ren78c2f9b2013-10-08 22:56:31 +0000365 Ty.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000366 };
David Blaikie72dfb052013-03-28 02:44:59 +0000367 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000368}
369
Devang Patel50d280c2011-02-22 18:56:12 +0000370/// createFriend - Create debugging information entry for a 'friend'.
Manman Ren576d49a2013-06-07 18:35:53 +0000371DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000372 // typedefs are encoded in DIDerivedType format.
Manman Ren89c83b72013-07-01 21:02:01 +0000373 assert(Ty.isType() && "Invalid type!");
374 assert(FriendTy.isType() && "Invalid friend type!");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000375 Value *Elts[] = {
376 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000377 NULL,
Manman Rene5388392013-09-30 19:42:10 +0000378 Ty.getRef(),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000379 NULL, // Name
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000380 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
381 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
382 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
383 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
384 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Ren78c2f9b2013-10-08 22:56:31 +0000385 FriendTy.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000386 };
Manman Ren576d49a2013-06-07 18:35:53 +0000387 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000388}
389
Devang Patel50d280c2011-02-22 18:56:12 +0000390/// createInheritance - Create debugging information entry to establish
Eric Christopherc27c7342011-09-12 19:58:22 +0000391/// inheritance relationship between two types.
David Blaikied67c5ca2013-02-18 06:41:57 +0000392DIDerivedType DIBuilder::createInheritance(
393 DIType Ty, DIType BaseTy, uint64_t BaseOffset, unsigned Flags) {
Manman Ren89c83b72013-07-01 21:02:01 +0000394 assert(Ty.isType() && "Unable to create inheritance");
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000395 // TAG_inheritance is encoded in DIDerivedType format.
396 Value *Elts[] = {
397 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000398 NULL,
Manman Rene5388392013-09-30 19:42:10 +0000399 Ty.getRef(),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000400 NULL, // Name
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000401 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
402 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
403 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
404 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
405 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Ren78c2f9b2013-10-08 22:56:31 +0000406 BaseTy.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000407 };
David Blaikie72dfb052013-03-28 02:44:59 +0000408 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000409}
410
Devang Patel50d280c2011-02-22 18:56:12 +0000411/// createMemberType - Create debugging information entry for a member.
David Blaikied67c5ca2013-02-18 06:41:57 +0000412DIDerivedType DIBuilder::createMemberType(
Manman Renc7a25ac2013-09-08 06:02:56 +0000413 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
David Blaikied67c5ca2013-02-18 06:41:57 +0000414 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
415 unsigned Flags, DIType Ty) {
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000416 // TAG_member is encoded in DIDerivedType format.
417 Value *Elts[] = {
418 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000419 File.getFileNode(),
Manman Rene5388392013-09-30 19:42:10 +0000420 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000421 MDString::get(VMContext, Name),
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000422 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
423 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
424 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
425 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
426 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Ren78c2f9b2013-10-08 22:56:31 +0000427 Ty.getRef()
Benjamin Kramer42c9b252010-11-04 18:45:27 +0000428 };
David Blaikie72dfb052013-03-28 02:44:59 +0000429 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000430}
431
Eric Christopher6b6061f2013-01-16 01:22:23 +0000432/// createStaticMemberType - Create debugging information entry for a
433/// C++ static data member.
Manman Ren576d49a2013-06-07 18:35:53 +0000434DIDerivedType
435DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
436 DIFile File, unsigned LineNumber,
437 DIType Ty, unsigned Flags,
438 llvm::Value *Val) {
Eric Christopher6b6061f2013-01-16 01:22:23 +0000439 // TAG_member is encoded in DIDerivedType format.
440 Flags |= DIDescriptor::FlagStaticMember;
441 Value *Elts[] = {
442 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000443 File.getFileNode(),
Manman Renb6f74f02013-10-08 23:49:38 +0000444 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Eric Christopher6b6061f2013-01-16 01:22:23 +0000445 MDString::get(VMContext, Name),
Eric Christopher6b6061f2013-01-16 01:22:23 +0000446 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
447 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*SizeInBits*/),
448 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*AlignInBits*/),
449 ConstantInt::get(Type::getInt64Ty(VMContext), 0/*OffsetInBits*/),
450 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Ren78c2f9b2013-10-08 22:56:31 +0000451 Ty.getRef(),
Eric Christopher6b6061f2013-01-16 01:22:23 +0000452 Val
453 };
Manman Ren576d49a2013-06-07 18:35:53 +0000454 return DIDerivedType(MDNode::get(VMContext, Elts));
Eric Christopher6b6061f2013-01-16 01:22:23 +0000455}
456
Devang Patele9db5e22011-04-16 00:11:51 +0000457/// createObjCIVar - Create debugging information entry for Objective-C
458/// instance variable.
Manman Ren576d49a2013-06-07 18:35:53 +0000459DIDerivedType
460DIBuilder::createObjCIVar(StringRef Name,
461 DIFile File, unsigned LineNumber,
462 uint64_t SizeInBits, uint64_t AlignInBits,
463 uint64_t OffsetInBits, unsigned Flags,
464 DIType Ty, StringRef PropertyName,
465 StringRef GetterName, StringRef SetterName,
466 unsigned PropertyAttributes) {
Devang Patele9db5e22011-04-16 00:11:51 +0000467 // TAG_member is encoded in DIDerivedType format.
468 Value *Elts[] = {
469 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000470 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000471 getNonCompileUnitScope(File),
Devang Patele9db5e22011-04-16 00:11:51 +0000472 MDString::get(VMContext, Name),
Devang Patele9db5e22011-04-16 00:11:51 +0000473 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
474 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
475 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
476 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
477 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
478 Ty,
479 MDString::get(VMContext, PropertyName),
480 MDString::get(VMContext, GetterName),
481 MDString::get(VMContext, SetterName),
482 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
483 };
Manman Ren576d49a2013-06-07 18:35:53 +0000484 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patele9db5e22011-04-16 00:11:51 +0000485}
486
Devang Patel6588abf2012-02-06 17:49:43 +0000487/// createObjCIVar - Create debugging information entry for Objective-C
488/// instance variable.
Manman Ren576d49a2013-06-07 18:35:53 +0000489DIDerivedType
490DIBuilder::createObjCIVar(StringRef Name,
491 DIFile File, unsigned LineNumber,
492 uint64_t SizeInBits, uint64_t AlignInBits,
493 uint64_t OffsetInBits, unsigned Flags,
494 DIType Ty, MDNode *PropertyNode) {
Devang Patel6588abf2012-02-06 17:49:43 +0000495 // TAG_member is encoded in DIDerivedType format.
496 Value *Elts[] = {
497 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie4776bce2013-03-20 00:26:26 +0000498 File.getFileNode(),
Devang Patel6588abf2012-02-06 17:49:43 +0000499 getNonCompileUnitScope(File),
500 MDString::get(VMContext, Name),
Devang Patel6588abf2012-02-06 17:49:43 +0000501 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
502 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
503 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
504 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
505 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
506 Ty,
507 PropertyNode
508 };
Manman Ren576d49a2013-06-07 18:35:53 +0000509 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel6588abf2012-02-06 17:49:43 +0000510}
511
Devang Patel1ea02d42012-02-04 00:59:25 +0000512/// createObjCProperty - Create debugging information entry for Objective-C
513/// property.
Eric Christopherb8ca9882012-03-29 08:42:56 +0000514DIObjCProperty DIBuilder::createObjCProperty(StringRef Name,
Eric Christopher87c06a82012-07-06 02:35:57 +0000515 DIFile File, unsigned LineNumber,
Devang Patel1ea02d42012-02-04 00:59:25 +0000516 StringRef GetterName,
Adrian Prantl2f445be2013-04-19 19:56:02 +0000517 StringRef SetterName,
Eric Christopherb8ca9882012-03-29 08:42:56 +0000518 unsigned PropertyAttributes,
Eric Christopher87c06a82012-07-06 02:35:57 +0000519 DIType Ty) {
Devang Patel1ea02d42012-02-04 00:59:25 +0000520 Value *Elts[] = {
Eric Christopher6c31ee22012-03-29 21:35:05 +0000521 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
Devang Patel1ea02d42012-02-04 00:59:25 +0000522 MDString::get(VMContext, Name),
Eric Christopherb8ca9882012-03-29 08:42:56 +0000523 File,
524 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Devang Patel1ea02d42012-02-04 00:59:25 +0000525 MDString::get(VMContext, GetterName),
526 MDString::get(VMContext, SetterName),
Eric Christopherb8ca9882012-03-29 08:42:56 +0000527 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
528 Ty
Devang Patel1ea02d42012-02-04 00:59:25 +0000529 };
David Blaikie72dfb052013-03-28 02:44:59 +0000530 return DIObjCProperty(MDNode::get(VMContext, Elts));
Devang Patel1ea02d42012-02-04 00:59:25 +0000531}
532
Devang Patel50d280c2011-02-22 18:56:12 +0000533/// createTemplateTypeParameter - Create debugging information for template
Devang Patel7e2cb112011-02-02 21:38:25 +0000534/// type parameter.
Eric Christopher6c0046f2011-08-26 21:02:40 +0000535DITemplateTypeParameter
Devang Patel50d280c2011-02-22 18:56:12 +0000536DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
Devang Patel7e2cb112011-02-02 21:38:25 +0000537 DIType Ty, MDNode *File, unsigned LineNo,
538 unsigned ColumnNo) {
539 Value *Elts[] = {
540 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
Manman Renb4d9c112013-10-09 19:46:28 +0000541 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel7e2cb112011-02-02 21:38:25 +0000542 MDString::get(VMContext, Name),
Manman Renb4d9c112013-10-09 19:46:28 +0000543 Ty.getRef(),
Devang Patel7e2cb112011-02-02 21:38:25 +0000544 File,
545 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
546 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
547 };
David Blaikie72dfb052013-03-28 02:44:59 +0000548 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
Devang Patel7e2cb112011-02-02 21:38:25 +0000549}
550
Eric Christopher6c0046f2011-08-26 21:02:40 +0000551DITemplateValueParameter
David Blaikiee88939c2013-06-22 18:59:11 +0000552DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
553 StringRef Name, DIType Ty,
554 Value *Val, MDNode *File,
555 unsigned LineNo,
Devang Patele7d93872011-02-02 22:35:53 +0000556 unsigned ColumnNo) {
557 Value *Elts[] = {
David Blaikiee88939c2013-06-22 18:59:11 +0000558 GetTagConstant(VMContext, Tag),
Manman Renb4d9c112013-10-09 19:46:28 +0000559 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patele7d93872011-02-02 22:35:53 +0000560 MDString::get(VMContext, Name),
Manman Renb4d9c112013-10-09 19:46:28 +0000561 Ty.getRef(),
David Blaikie4de9d722013-05-10 21:52:07 +0000562 Val,
Devang Patele7d93872011-02-02 22:35:53 +0000563 File,
564 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
565 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
566 };
David Blaikie72dfb052013-03-28 02:44:59 +0000567 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
Devang Patele7d93872011-02-02 22:35:53 +0000568}
569
David Blaikiee88939c2013-06-22 18:59:11 +0000570/// createTemplateValueParameter - Create debugging information for template
571/// value parameter.
572DITemplateValueParameter
573DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
574 DIType Ty, Value *Val,
575 MDNode *File, unsigned LineNo,
576 unsigned ColumnNo) {
577 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
578 Context, Name, Ty, Val, File, LineNo,
579 ColumnNo);
580}
581
582DITemplateValueParameter
583DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
584 DIType Ty, StringRef Val,
585 MDNode *File, unsigned LineNo,
586 unsigned ColumnNo) {
587 return createTemplateValueParameter(
588 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
589 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
590}
591
592DITemplateValueParameter
593DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
594 DIType Ty, DIArray Val,
595 MDNode *File, unsigned LineNo,
596 unsigned ColumnNo) {
597 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
598 Context, Name, Ty, Val, File, LineNo,
599 ColumnNo);
600}
601
Eric Christopher87c06a82012-07-06 02:35:57 +0000602/// createClassType - Create debugging information entry for a class.
David Blaikieca442a42013-03-26 23:46:39 +0000603DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
604 DIFile File, unsigned LineNumber,
605 uint64_t SizeInBits,
606 uint64_t AlignInBits,
607 uint64_t OffsetInBits,
608 unsigned Flags, DIType DerivedFrom,
609 DIArray Elements,
Manman Ren8b56ca62013-09-06 23:54:23 +0000610 DIType VTableHolder,
Manman Ren23f84cb2013-08-27 23:06:40 +0000611 MDNode *TemplateParams,
612 StringRef UniqueIdentifier) {
Manman Ren89c83b72013-07-01 21:02:01 +0000613 assert((!Context || Context.isScope() || Context.isType()) &&
David Blaikie66438682013-03-11 23:21:19 +0000614 "createClassType should be called with a valid Context");
615 // TAG_class_type is encoded in DICompositeType format.
Eric Christopher87c06a82012-07-06 02:35:57 +0000616 Value *Elts[] = {
617 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000618 File.getFileNode(),
Manman Ren456e5e52013-10-09 00:17:04 +0000619 DIScope(getNonCompileUnitScope(Context)).getRef(),
Eric Christopher87c06a82012-07-06 02:35:57 +0000620 MDString::get(VMContext, Name),
Eric Christopher87c06a82012-07-06 02:35:57 +0000621 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
622 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
623 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
624 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
625 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renc1e2b252013-10-08 23:28:51 +0000626 DerivedFrom.getRef(),
Eric Christopher87c06a82012-07-06 02:35:57 +0000627 Elements,
628 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Rene5388392013-09-30 19:42:10 +0000629 VTableHolder.getRef(),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000630 TemplateParams,
Manman Ren23f84cb2013-08-27 23:06:40 +0000631 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Eric Christopher87c06a82012-07-06 02:35:57 +0000632 };
David Blaikieca442a42013-03-26 23:46:39 +0000633 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000634 assert(R.isCompositeType() &&
635 "createClassType should return a DICompositeType");
Manman Ren3a0e9b52013-08-29 23:17:54 +0000636 if (!UniqueIdentifier.empty())
637 retainType(R);
David Blaikie66438682013-03-11 23:21:19 +0000638 return R;
Eric Christopher87c06a82012-07-06 02:35:57 +0000639}
640
Devang Patel50d280c2011-02-22 18:56:12 +0000641/// createStructType - Create debugging information entry for a struct.
David Blaikie6172f022013-02-25 01:07:18 +0000642DICompositeType DIBuilder::createStructType(DIDescriptor Context,
643 StringRef Name, DIFile File,
644 unsigned LineNumber,
645 uint64_t SizeInBits,
646 uint64_t AlignInBits,
647 unsigned Flags, DIType DerivedFrom,
648 DIArray Elements,
649 unsigned RunTimeLang,
Manman Ren8b56ca62013-09-06 23:54:23 +0000650 DIType VTableHolder,
Manman Ren23f84cb2013-08-27 23:06:40 +0000651 StringRef UniqueIdentifier) {
Devang Patelfe58f952010-12-07 23:25:47 +0000652 // TAG_structure_type is encoded in DICompositeType format.
653 Value *Elts[] = {
654 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000655 File.getFileNode(),
Manman Ren456e5e52013-10-09 00:17:04 +0000656 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patelfe58f952010-12-07 23:25:47 +0000657 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +0000658 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
659 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
660 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Devang Patel43c249c2010-12-08 01:50:15 +0000661 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelfe58f952010-12-07 23:25:47 +0000662 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renc1e2b252013-10-08 23:28:51 +0000663 DerivedFrom.getRef(),
Devang Patelfe58f952010-12-07 23:25:47 +0000664 Elements,
665 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Rene5388392013-09-30 19:42:10 +0000666 VTableHolder.getRef(),
David Blaikied4f92fd2013-02-18 07:27:30 +0000667 NULL,
Manman Ren23f84cb2013-08-27 23:06:40 +0000668 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patelfe58f952010-12-07 23:25:47 +0000669 };
David Blaikie66438682013-03-11 23:21:19 +0000670 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren89c83b72013-07-01 21:02:01 +0000671 assert(R.isCompositeType() &&
672 "createStructType should return a DICompositeType");
Manman Ren3a0e9b52013-08-29 23:17:54 +0000673 if (!UniqueIdentifier.empty())
674 retainType(R);
David Blaikie66438682013-03-11 23:21:19 +0000675 return R;
Devang Patelfe58f952010-12-07 23:25:47 +0000676}
677
Devang Patel50d280c2011-02-22 18:56:12 +0000678/// createUnionType - Create debugging information entry for an union.
Eric Christophercf0623b2013-04-02 22:55:52 +0000679DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
680 DIFile File, unsigned LineNumber,
681 uint64_t SizeInBits,
682 uint64_t AlignInBits, unsigned Flags,
683 DIArray Elements,
Manman Ren23f84cb2013-08-27 23:06:40 +0000684 unsigned RunTimeLang,
685 StringRef UniqueIdentifier) {
Devang Patel43c249c2010-12-08 01:50:15 +0000686 // TAG_union_type is encoded in DICompositeType format.
687 Value *Elts[] = {
688 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000689 File.getFileNode(),
Manman Ren456e5e52013-10-09 00:17:04 +0000690 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Devang Patel43c249c2010-12-08 01:50:15 +0000691 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000692 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
693 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
694 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
695 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
696 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patelc104cf22011-12-16 17:51:31 +0000697 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000698 Elements,
699 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000700 NULL,
701 NULL,
Manman Ren23f84cb2013-08-27 23:06:40 +0000702 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel43c249c2010-12-08 01:50:15 +0000703 };
Manman Ren3a0e9b52013-08-29 23:17:54 +0000704 DICompositeType R(MDNode::get(VMContext, Elts));
705 if (!UniqueIdentifier.empty())
706 retainType(R);
707 return R;
Devang Patel43c249c2010-12-08 01:50:15 +0000708}
709
Devang Patel50d280c2011-02-22 18:56:12 +0000710/// createSubroutineType - Create subroutine type.
David Blaikied67c5ca2013-02-18 06:41:57 +0000711DICompositeType
712DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) {
Devang Patel43c249c2010-12-08 01:50:15 +0000713 // TAG_subroutine_type is encoded in DICompositeType format.
714 Value *Elts[] = {
715 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000716 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Manman Ren4fa214b2013-09-08 06:00:42 +0000717 NULL,
David Blaikiea13f3cd2013-03-19 23:25:22 +0000718 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000719 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
720 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
721 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000722 ConstantInt::get(Type::getInt64Ty(VMContext), 0),
Devang Patel43c249c2010-12-08 01:50:15 +0000723 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelc104cf22011-12-16 17:51:31 +0000724 NULL,
Devang Patel43c249c2010-12-08 01:50:15 +0000725 ParameterTypes,
726 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000727 NULL,
728 NULL,
729 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000730 };
David Blaikie72dfb052013-03-28 02:44:59 +0000731 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000732}
733
Eric Christopher6c0046f2011-08-26 21:02:40 +0000734/// createEnumerationType - Create debugging information entry for an
Devang Patel43c249c2010-12-08 01:50:15 +0000735/// enumeration.
David Blaikied67c5ca2013-02-18 06:41:57 +0000736DICompositeType DIBuilder::createEnumerationType(
737 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
738 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Manman Ren23f84cb2013-08-27 23:06:40 +0000739 DIType UnderlyingType, StringRef UniqueIdentifier) {
Devang Patel43c249c2010-12-08 01:50:15 +0000740 // TAG_enumeration_type is encoded in DICompositeType format.
741 Value *Elts[] = {
742 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
David Blaikie4776bce2013-03-20 00:26:26 +0000743 File.getFileNode(),
Manman Ren456e5e52013-10-09 00:17:04 +0000744 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Devang Patel43c249c2010-12-08 01:50:15 +0000745 MDString::get(VMContext, Name),
Devang Patel43c249c2010-12-08 01:50:15 +0000746 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
747 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
748 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
749 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000750 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Renc1e2b252013-10-08 23:28:51 +0000751 UnderlyingType.getRef(),
Devang Patel43c249c2010-12-08 01:50:15 +0000752 Elements,
753 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000754 NULL,
755 NULL,
Manman Ren23f84cb2013-08-27 23:06:40 +0000756 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel43c249c2010-12-08 01:50:15 +0000757 };
Devang Patel1f48a952011-04-18 23:51:03 +0000758 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000759 AllEnumTypes.push_back(Node);
Manman Ren3a0e9b52013-08-29 23:17:54 +0000760 if (!UniqueIdentifier.empty())
761 retainType(Node);
David Blaikie72dfb052013-03-28 02:44:59 +0000762 return DICompositeType(Node);
Devang Patel43c249c2010-12-08 01:50:15 +0000763}
764
Devang Patel50d280c2011-02-22 18:56:12 +0000765/// createArrayType - Create debugging information entry for an array.
David Blaikied67c5ca2013-02-18 06:41:57 +0000766DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
767 DIType Ty, DIArray Subscripts) {
Devang Patel43c249c2010-12-08 01:50:15 +0000768 // TAG_array_type is encoded in DICompositeType format.
769 Value *Elts[] = {
770 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000771 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000772 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000773 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000774 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
775 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
776 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
777 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
778 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Renc1e2b252013-10-08 23:28:51 +0000779 Ty.getRef(),
Devang Patel43c249c2010-12-08 01:50:15 +0000780 Subscripts,
781 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000782 NULL,
783 NULL,
784 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000785 };
David Blaikie72dfb052013-03-28 02:44:59 +0000786 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000787}
788
Devang Patel50d280c2011-02-22 18:56:12 +0000789/// createVectorType - Create debugging information entry for a vector.
Manman Ren37bfb182013-06-07 03:13:46 +0000790DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
791 DIType Ty, DIArray Subscripts) {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000792 // A vector is an array type with the FlagVector flag applied.
Devang Patel43c249c2010-12-08 01:50:15 +0000793 Value *Elts[] = {
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000794 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikiea13f3cd2013-03-19 23:25:22 +0000795 NULL, // Filename/Directory,
Eric Christopher1fe3f9a2013-07-19 00:51:47 +0000796 NULL, // Unused
Devang Patel43c249c2010-12-08 01:50:15 +0000797 MDString::get(VMContext, ""),
Devang Patel43c249c2010-12-08 01:50:15 +0000798 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
799 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
800 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
801 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000802 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
Manman Renc1e2b252013-10-08 23:28:51 +0000803 Ty.getRef(),
Devang Patel43c249c2010-12-08 01:50:15 +0000804 Subscripts,
805 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000806 NULL,
807 NULL,
808 NULL // Type Identifer
Devang Patel43c249c2010-12-08 01:50:15 +0000809 };
Manman Ren37bfb182013-06-07 03:13:46 +0000810 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000811}
Devang Patelfe58f952010-12-07 23:25:47 +0000812
Devang Patel50d280c2011-02-22 18:56:12 +0000813/// createArtificialType - Create a new DIType with "artificial" flag set.
814DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel35fcd652010-11-04 15:01:38 +0000815 if (Ty.isArtificial())
816 return Ty;
817
818 SmallVector<Value *, 9> Elts;
819 MDNode *N = Ty;
820 assert (N && "Unexpected input DIType!");
Manman Ren4fa214b2013-09-08 06:00:42 +0000821 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
822 Elts.push_back(N->getOperand(i));
Devang Patel35fcd652010-11-04 15:01:38 +0000823
824 unsigned CurFlags = Ty.getFlags();
825 CurFlags = CurFlags | DIType::FlagArtificial;
826
827 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000828 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Devang Patel35fcd652010-11-04 15:01:38 +0000829
David Blaikie72dfb052013-03-28 02:44:59 +0000830 return DIType(MDNode::get(VMContext, Elts));
Devang Patel35fcd652010-11-04 15:01:38 +0000831}
Devang Patelfe58f952010-12-07 23:25:47 +0000832
Eric Christopher1f55eb42013-01-08 01:53:42 +0000833/// createObjectPointerType - Create a new type with both the object pointer
834/// and artificial flags set.
Eric Christophere5212782012-09-12 23:36:19 +0000835DIType DIBuilder::createObjectPointerType(DIType Ty) {
836 if (Ty.isObjectPointer())
837 return Ty;
838
839 SmallVector<Value *, 9> Elts;
840 MDNode *N = Ty;
841 assert (N && "Unexpected input DIType!");
Manman Ren4fa214b2013-09-08 06:00:42 +0000842 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
843 Elts.push_back(N->getOperand(i));
Eric Christophere5212782012-09-12 23:36:19 +0000844
845 unsigned CurFlags = Ty.getFlags();
846 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
847
848 // Flags are stored at this slot.
David Blaikie72dfb052013-03-28 02:44:59 +0000849 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Eric Christophere5212782012-09-12 23:36:19 +0000850
David Blaikie72dfb052013-03-28 02:44:59 +0000851 return DIType(MDNode::get(VMContext, Elts));
Eric Christophere5212782012-09-12 23:36:19 +0000852}
853
Eric Christopher6c0046f2011-08-26 21:02:40 +0000854/// retainType - Retain DIType in a module even if it is not referenced
Devang Patel43c249c2010-12-08 01:50:15 +0000855/// through debug info anchors.
Devang Patel50d280c2011-02-22 18:56:12 +0000856void DIBuilder::retainType(DIType T) {
Manman Ren3a0e9b52013-08-29 23:17:54 +0000857 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
Devang Patel43c249c2010-12-08 01:50:15 +0000858}
859
Devang Patel50d280c2011-02-22 18:56:12 +0000860/// createUnspecifiedParameter - Create unspeicified type descriptor
Devang Patel43c249c2010-12-08 01:50:15 +0000861/// for the subroutine type.
Devang Patel50d280c2011-02-22 18:56:12 +0000862DIDescriptor DIBuilder::createUnspecifiedParameter() {
Eric Christopher6c0046f2011-08-26 21:02:40 +0000863 Value *Elts[] = {
864 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
Devang Patel43c249c2010-12-08 01:50:15 +0000865 };
Devang Patel1f48a952011-04-18 23:51:03 +0000866 return DIDescriptor(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000867}
868
Eric Christopher4fe34572012-02-08 00:22:26 +0000869/// createForwardDecl - Create a temporary forward-declared type that
870/// can be RAUW'd if the full type is seen.
David Blaikie692062f2013-08-16 20:42:14 +0000871DICompositeType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name,
Eric Christopher216432d2012-04-23 19:00:11 +0000872 DIDescriptor Scope, DIFile F,
Eli Friedmance3da6f2012-10-05 01:49:14 +0000873 unsigned Line, unsigned RuntimeLang,
874 uint64_t SizeInBits,
Manman Ren23f84cb2013-08-27 23:06:40 +0000875 uint64_t AlignInBits,
876 StringRef UniqueIdentifier) {
Eric Christopher4fe34572012-02-08 00:22:26 +0000877 // Create a temporary MDNode.
878 Value *Elts[] = {
879 GetTagConstant(VMContext, Tag),
David Blaikie4776bce2013-03-20 00:26:26 +0000880 F.getFileNode(),
Manman Ren5e5d4942013-10-09 18:10:55 +0000881 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Eric Christopher4fe34572012-02-08 00:22:26 +0000882 MDString::get(VMContext, Name),
Eric Christopher4fe34572012-02-08 00:22:26 +0000883 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
Eli Friedmance3da6f2012-10-05 01:49:14 +0000884 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
885 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher4fe34572012-02-08 00:22:26 +0000886 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
887 ConstantInt::get(Type::getInt32Ty(VMContext),
Eric Christopher9f90e872012-02-20 18:04:14 +0000888 DIDescriptor::FlagFwdDecl),
889 NULL,
890 DIArray(),
David Blaikie692062f2013-08-16 20:42:14 +0000891 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000892 NULL,
893 NULL, //TemplateParams
Manman Ren23f84cb2013-08-27 23:06:40 +0000894 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Eric Christopher4fe34572012-02-08 00:22:26 +0000895 };
896 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
David Blaikie692062f2013-08-16 20:42:14 +0000897 DICompositeType RetTy(Node);
898 assert(RetTy.isCompositeType() &&
Manman Ren89c83b72013-07-01 21:02:01 +0000899 "createForwardDecl result should be a DIType");
Manman Ren3a0e9b52013-08-29 23:17:54 +0000900 if (!UniqueIdentifier.empty())
901 retainType(RetTy);
Manman Ren88328d22013-07-02 18:37:35 +0000902 return RetTy;
Eric Christopher4fe34572012-02-08 00:22:26 +0000903}
904
Devang Patel50d280c2011-02-22 18:56:12 +0000905/// getOrCreateArray - Get a DIArray, create one if required.
Jay Foad68550182011-04-24 10:11:03 +0000906DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
907 if (Elements.empty()) {
Bill Wendlingf46b4972012-07-06 17:47:36 +0000908 Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext));
Jay Foadec9186b2011-04-21 19:59:31 +0000909 return DIArray(MDNode::get(VMContext, Null));
Devang Patelfe58f952010-12-07 23:25:47 +0000910 }
Jay Foad68550182011-04-24 10:11:03 +0000911 return DIArray(MDNode::get(VMContext, Elements));
Devang Patelfe58f952010-12-07 23:25:47 +0000912}
913
Devang Patel50d280c2011-02-22 18:56:12 +0000914/// getOrCreateSubrange - Create a descriptor for a value range. This
Devang Patel43c249c2010-12-08 01:50:15 +0000915/// implicitly uniques the values returned.
Bill Wendling9493dae2012-12-04 21:34:03 +0000916DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Devang Patel43c249c2010-12-08 01:50:15 +0000917 Value *Elts[] = {
918 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
919 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
Bill Wendlinga7645a32012-12-04 06:20:49 +0000920 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
Devang Patel43c249c2010-12-08 01:50:15 +0000921 };
922
Devang Patel1f48a952011-04-18 23:51:03 +0000923 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel43c249c2010-12-08 01:50:15 +0000924}
925
David Blaikie3fac43d2013-03-20 17:49:48 +0000926/// \brief Create a new descriptor for the specified global.
Devang Patelfe58f952010-12-07 23:25:47 +0000927DIGlobalVariable DIBuilder::
David Blaikie3fac43d2013-03-20 17:49:48 +0000928createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F,
929 unsigned LineNumber, DIType Ty, bool isLocalToUnit,
930 Value *Val) {
Devang Patelfe58f952010-12-07 23:25:47 +0000931 Value *Elts[] = {
932 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000933 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000934 NULL, // TheCU,
Devang Patelfe58f952010-12-07 23:25:47 +0000935 MDString::get(VMContext, Name),
936 MDString::get(VMContext, Name),
David Blaikie3fac43d2013-03-20 17:49:48 +0000937 MDString::get(VMContext, LinkageName),
Devang Patelfe58f952010-12-07 23:25:47 +0000938 F,
939 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
940 Ty,
941 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
942 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000943 Val,
944 DIDescriptor()
Devang Patelfe58f952010-12-07 23:25:47 +0000945 };
Devang Patel1f48a952011-04-18 23:51:03 +0000946 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000947 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000948 return DIGlobalVariable(Node);
949}
950
David Blaikie3fac43d2013-03-20 17:49:48 +0000951/// \brief Create a new descriptor for the specified global.
952DIGlobalVariable DIBuilder::
953createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber,
954 DIType Ty, bool isLocalToUnit, Value *Val) {
955 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
956 Val);
957}
958
Devang Patel50d280c2011-02-22 18:56:12 +0000959/// createStaticVariable - Create a new descriptor for the specified static
Devang Patelfe58f952010-12-07 23:25:47 +0000960/// variable.
961DIGlobalVariable DIBuilder::
Eric Christopher6c0046f2011-08-26 21:02:40 +0000962createStaticVariable(DIDescriptor Context, StringRef Name,
963 StringRef LinkageName, DIFile F, unsigned LineNumber,
Eric Christopher6b6061f2013-01-16 01:22:23 +0000964 DIType Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) {
Devang Patelfe58f952010-12-07 23:25:47 +0000965 Value *Elts[] = {
966 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendlingf46b4972012-07-06 17:47:36 +0000967 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000968 getNonCompileUnitScope(Context),
Devang Patelfe58f952010-12-07 23:25:47 +0000969 MDString::get(VMContext, Name),
970 MDString::get(VMContext, Name),
971 MDString::get(VMContext, LinkageName),
972 F,
973 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
974 Ty,
975 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
976 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher6b6061f2013-01-16 01:22:23 +0000977 Val,
978 DIDescriptor(Decl)
Devang Patelfe58f952010-12-07 23:25:47 +0000979 };
Devang Patel1f48a952011-04-18 23:51:03 +0000980 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel94c7ddb2011-08-16 22:09:43 +0000981 AllGVs.push_back(Node);
Devang Patelfe58f952010-12-07 23:25:47 +0000982 return DIGlobalVariable(Node);
983}
984
Devang Patel50d280c2011-02-22 18:56:12 +0000985/// createVariable - Create a new descriptor for the specified variable.
986DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel48f17ba2010-12-07 23:58:00 +0000987 StringRef Name, DIFile File,
Eric Christopher6c0046f2011-08-26 21:02:40 +0000988 unsigned LineNo, DIType Ty,
Devang Patele9e16c52011-03-01 22:58:13 +0000989 bool AlwaysPreserve, unsigned Flags,
990 unsigned ArgNo) {
David Blaikie66438682013-03-11 23:21:19 +0000991 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren89c83b72013-07-01 21:02:01 +0000992 assert((!Context || Context.isScope()) &&
David Blaikie66438682013-03-11 23:21:19 +0000993 "createLocalVariable should be called with a valid Context");
Manman Ren89c83b72013-07-01 21:02:01 +0000994 assert(Ty.isType() &&
David Blaikie66438682013-03-11 23:21:19 +0000995 "createLocalVariable should be called with a valid type");
Devang Patel48f17ba2010-12-07 23:58:00 +0000996 Value *Elts[] = {
997 GetTagConstant(VMContext, Tag),
Devang Patel94c7ddb2011-08-16 22:09:43 +0000998 getNonCompileUnitScope(Scope),
Devang Patel48f17ba2010-12-07 23:58:00 +0000999 MDString::get(VMContext, Name),
1000 File,
Devang Patele9e16c52011-03-01 22:58:13 +00001001 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
Devang Patel48f17ba2010-12-07 23:58:00 +00001002 Ty,
Devang Patel23336b42011-07-19 19:41:54 +00001003 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Bill Wendling9fdb7c02012-07-06 17:49:19 +00001004 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel48f17ba2010-12-07 23:58:00 +00001005 };
Devang Patel1f48a952011-04-18 23:51:03 +00001006 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel48f17ba2010-12-07 23:58:00 +00001007 if (AlwaysPreserve) {
1008 // The optimizer may remove local variable. If there is an interest
1009 // to preserve variable info in such situation then stash it in a
1010 // named mdnode.
1011 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel93d39be2011-08-19 23:28:12 +00001012 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel48f17ba2010-12-07 23:58:00 +00001013 FnLocals->addOperand(Node);
1014 }
Manman Ren88328d22013-07-02 18:37:35 +00001015 DIVariable RetVar(Node);
1016 assert(RetVar.isVariable() &&
Manman Ren89c83b72013-07-01 21:02:01 +00001017 "createLocalVariable should return a valid DIVariable");
Manman Ren88328d22013-07-02 18:37:35 +00001018 return RetVar;
Devang Patel48f17ba2010-12-07 23:58:00 +00001019}
1020
Devang Patel50d280c2011-02-22 18:56:12 +00001021/// createComplexVariable - Create a new descriptor for the specified variable
Devang Patelfe58f952010-12-07 23:25:47 +00001022/// which has a complex address expression for its address.
Devang Patel50d280c2011-02-22 18:56:12 +00001023DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
Devang Patelfe58f952010-12-07 23:25:47 +00001024 StringRef Name, DIFile F,
1025 unsigned LineNo,
Jay Foad68550182011-04-24 10:11:03 +00001026 DIType Ty, ArrayRef<Value *> Addr,
1027 unsigned ArgNo) {
Devang Patelfe58f952010-12-07 23:25:47 +00001028 SmallVector<Value *, 15> Elts;
1029 Elts.push_back(GetTagConstant(VMContext, Tag));
Devang Patel94c7ddb2011-08-16 22:09:43 +00001030 Elts.push_back(getNonCompileUnitScope(Scope)),
Devang Patelfe58f952010-12-07 23:25:47 +00001031 Elts.push_back(MDString::get(VMContext, Name));
1032 Elts.push_back(F);
Eric Christopher6c0046f2011-08-26 21:02:40 +00001033 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
Devang Patel9f997212012-02-08 00:17:07 +00001034 (LineNo | (ArgNo << 24))));
Devang Patelfe58f952010-12-07 23:25:47 +00001035 Elts.push_back(Ty);
Bill Wendlingf46b4972012-07-06 17:47:36 +00001036 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1037 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
Jay Foad68550182011-04-24 10:11:03 +00001038 Elts.append(Addr.begin(), Addr.end());
Devang Patelfe58f952010-12-07 23:25:47 +00001039
Devang Patel1f48a952011-04-18 23:51:03 +00001040 return DIVariable(MDNode::get(VMContext, Elts));
Devang Patelfe58f952010-12-07 23:25:47 +00001041}
1042
Devang Patel50d280c2011-02-22 18:56:12 +00001043/// createFunction - Create a new descriptor for the specified function.
Manman Renb8e48a62013-10-10 18:40:01 +00001044/// FIXME: this is added for dragonegg. Once we update dragonegg
1045/// to call resolve function, this will be removed.
1046DISubprogram DIBuilder::createFunction(DIScopeRef Context,
1047 StringRef Name,
1048 StringRef LinkageName,
1049 DIFile File, unsigned LineNo,
1050 DICompositeType Ty,
1051 bool isLocalToUnit, bool isDefinition,
1052 unsigned ScopeLine,
1053 unsigned Flags, bool isOptimized,
1054 Function *Fn,
1055 MDNode *TParams,
1056 MDNode *Decl) {
1057 // dragonegg does not generate identifier for types, so using an empty map
1058 // to resolve the context should be fine.
1059 DITypeIdentifierMap EmptyMap;
1060 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1061 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1062 Flags, isOptimized, Fn, TParams, Decl);
1063}
1064
1065/// createFunction - Create a new descriptor for the specified function.
Devang Patel50d280c2011-02-22 18:56:12 +00001066DISubprogram DIBuilder::createFunction(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001067 StringRef Name,
1068 StringRef LinkageName,
1069 DIFile File, unsigned LineNo,
David Blaikie3d331842013-05-22 23:22:18 +00001070 DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001071 bool isLocalToUnit, bool isDefinition,
Eric Christopher6126a1e2012-04-03 00:43:49 +00001072 unsigned ScopeLine,
Devang Patel44498a62010-12-08 20:42:44 +00001073 unsigned Flags, bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001074 Function *Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001075 MDNode *TParams,
1076 MDNode *Decl) {
David Blaikie3d331842013-05-22 23:22:18 +00001077 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1078 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001079 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001080 Value *Elts[] = {
1081 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001082 File.getFileNode(),
Manman Renb8e48a62013-10-10 18:40:01 +00001083 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel44498a62010-12-08 20:42:44 +00001084 MDString::get(VMContext, Name),
1085 MDString::get(VMContext, Name),
1086 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001087 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1088 Ty,
1089 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1090 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1091 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1092 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patel9642c572011-12-15 17:55:56 +00001093 NULL,
Devang Patel44498a62010-12-08 20:42:44 +00001094 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1095 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001096 Fn,
Devang Patel5e06bb82011-04-22 23:10:17 +00001097 TParams,
Devang Patel93d39be2011-08-19 23:28:12 +00001098 Decl,
David Blaikief839eed2013-02-04 05:56:36 +00001099 MDNode::getTemporary(VMContext, TElts),
Eric Christopher6126a1e2012-04-03 00:43:49 +00001100 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
Devang Patel44498a62010-12-08 20:42:44 +00001101 };
Devang Patel1f48a952011-04-18 23:51:03 +00001102 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel44498a62010-12-08 20:42:44 +00001103
1104 // Create a named metadata so that we do not lose this mdnode.
David Blaikie139f7e52013-02-18 07:10:22 +00001105 if (isDefinition)
1106 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001107 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001108 assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001109 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001110}
1111
Devang Patel50d280c2011-02-22 18:56:12 +00001112/// createMethod - Create a new descriptor for the specified C++ method.
1113DISubprogram DIBuilder::createMethod(DIDescriptor Context,
Devang Patel44498a62010-12-08 20:42:44 +00001114 StringRef Name,
1115 StringRef LinkageName,
1116 DIFile F,
David Blaikie3d331842013-05-22 23:22:18 +00001117 unsigned LineNo, DICompositeType Ty,
Devang Patel44498a62010-12-08 20:42:44 +00001118 bool isLocalToUnit,
1119 bool isDefinition,
1120 unsigned VK, unsigned VIndex,
Manman Ren8b56ca62013-09-06 23:54:23 +00001121 DIType VTableHolder,
Devang Patel44498a62010-12-08 20:42:44 +00001122 unsigned Flags,
1123 bool isOptimized,
Devang Patelda194752011-04-05 22:52:06 +00001124 Function *Fn,
1125 MDNode *TParam) {
David Blaikie3d331842013-05-22 23:22:18 +00001126 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1127 "function types should be subroutines");
Devang Patel93d39be2011-08-19 23:28:12 +00001128 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patel44498a62010-12-08 20:42:44 +00001129 Value *Elts[] = {
1130 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikiebb4e6192013-03-21 23:08:34 +00001131 F.getFileNode(),
Manman Renb8e48a62013-10-10 18:40:01 +00001132 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel44498a62010-12-08 20:42:44 +00001133 MDString::get(VMContext, Name),
1134 MDString::get(VMContext, Name),
1135 MDString::get(VMContext, LinkageName),
Devang Patel44498a62010-12-08 20:42:44 +00001136 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1137 Ty,
1138 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1139 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1140 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
1141 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
Manman Rene5388392013-09-30 19:42:10 +00001142 VTableHolder.getRef(),
Devang Patel44498a62010-12-08 20:42:44 +00001143 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1144 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patelda194752011-04-05 22:52:06 +00001145 Fn,
1146 TParam,
Bill Wendlingf46b4972012-07-06 17:47:36 +00001147 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikief839eed2013-02-04 05:56:36 +00001148 MDNode::getTemporary(VMContext, TElts),
Eric Christopher25016522012-05-18 00:16:22 +00001149 // FIXME: Do we want to use different scope/lines?
Eric Christopher6126a1e2012-04-03 00:43:49 +00001150 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
Devang Patel44498a62010-12-08 20:42:44 +00001151 };
Devang Patel1f48a952011-04-18 23:51:03 +00001152 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie139f7e52013-02-18 07:10:22 +00001153 if (isDefinition)
1154 AllSubprograms.push_back(Node);
David Blaikieebb51832013-03-21 20:28:52 +00001155 DISubprogram S(Node);
Manman Ren89c83b72013-07-01 21:02:01 +00001156 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikieebb51832013-03-21 20:28:52 +00001157 return S;
Devang Patel44498a62010-12-08 20:42:44 +00001158}
1159
Devang Patel50d280c2011-02-22 18:56:12 +00001160/// createNameSpace - This creates new descriptor for a namespace
Devang Patelfe58f952010-12-07 23:25:47 +00001161/// with the specified parent scope.
Devang Patel50d280c2011-02-22 18:56:12 +00001162DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patelfe58f952010-12-07 23:25:47 +00001163 DIFile File, unsigned LineNo) {
1164 Value *Elts[] = {
1165 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
David Blaikie6115ed02013-03-20 19:39:15 +00001166 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001167 getNonCompileUnitScope(Scope),
Devang Patelfe58f952010-12-07 23:25:47 +00001168 MDString::get(VMContext, Name),
Devang Patelfe58f952010-12-07 23:25:47 +00001169 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1170 };
David Blaikie66438682013-03-11 23:21:19 +00001171 DINameSpace R(MDNode::get(VMContext, Elts));
1172 assert(R.Verify() &&
1173 "createNameSpace should return a verifiable DINameSpace");
1174 return R;
Devang Patelfe58f952010-12-07 23:25:47 +00001175}
1176
Eric Christopher6618a242011-10-11 22:59:11 +00001177/// createLexicalBlockFile - This creates a new MDNode that encapsulates
1178/// an existing scope with a new filename.
1179DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
Devang Patel9f997212012-02-08 00:17:07 +00001180 DIFile File) {
Eric Christopher6618a242011-10-11 22:59:11 +00001181 Value *Elts[] = {
1182 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie8faed272013-03-22 20:18:46 +00001183 File.getFileNode(),
David Blaikie7b246862013-03-22 19:13:22 +00001184 Scope
Eric Christopher6618a242011-10-11 22:59:11 +00001185 };
David Blaikie66438682013-03-11 23:21:19 +00001186 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1187 assert(
1188 R.Verify() &&
1189 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1190 return R;
Eric Christopher6618a242011-10-11 22:59:11 +00001191}
1192
Devang Patel50d280c2011-02-22 18:56:12 +00001193DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
Devang Patel43c249c2010-12-08 01:50:15 +00001194 unsigned Line, unsigned Col) {
Adrian Prantle06db0c2013-06-24 21:19:43 +00001195 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel43c249c2010-12-08 01:50:15 +00001196 static unsigned int unique_id = 0;
1197 Value *Elts[] = {
1198 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie4b52a882013-03-22 17:33:20 +00001199 File.getFileNode(),
Devang Patel94c7ddb2011-08-16 22:09:43 +00001200 getNonCompileUnitScope(Scope),
Devang Patel43c249c2010-12-08 01:50:15 +00001201 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1202 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
Devang Patel43c249c2010-12-08 01:50:15 +00001203 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1204 };
David Blaikie66438682013-03-11 23:21:19 +00001205 DILexicalBlock R(MDNode::get(VMContext, Elts));
1206 assert(R.Verify() &&
1207 "createLexicalBlock should return a verifiable DILexicalBlock");
1208 return R;
Devang Patel43c249c2010-12-08 01:50:15 +00001209}
1210
Devang Patel50d280c2011-02-22 18:56:12 +00001211/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1212Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001213 Instruction *InsertBefore) {
1214 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001215 assert(VarInfo.isVariable() &&
1216 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001217 if (!DeclareFn)
1218 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1219
Jay Foadec9186b2011-04-21 19:59:31 +00001220 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001221 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001222}
1223
Devang Patel50d280c2011-02-22 18:56:12 +00001224/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1225Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patelfe58f952010-12-07 23:25:47 +00001226 BasicBlock *InsertAtEnd) {
1227 assert(Storage && "no storage passed to dbg.declare");
Manman Renda918172013-06-29 05:01:19 +00001228 assert(VarInfo.isVariable() &&
1229 "empty or invalid DIVariable passed to dbg.declare");
Devang Patelfe58f952010-12-07 23:25:47 +00001230 if (!DeclareFn)
1231 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1232
Jay Foadec9186b2011-04-21 19:59:31 +00001233 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Devang Patelfe58f952010-12-07 23:25:47 +00001234
1235 // If this block already has a terminator then insert this intrinsic
1236 // before the terminator.
1237 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foada3efbb12011-07-15 08:37:34 +00001238 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patelfe58f952010-12-07 23:25:47 +00001239 else
Jay Foada3efbb12011-07-15 08:37:34 +00001240 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001241}
1242
Devang Patel50d280c2011-02-22 18:56:12 +00001243/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1244Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001245 DIVariable VarInfo,
1246 Instruction *InsertBefore) {
1247 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001248 assert(VarInfo.isVariable() &&
1249 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001250 if (!ValueFn)
1251 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1252
Jay Foadec9186b2011-04-21 19:59:31 +00001253 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001254 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1255 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001256 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patelfe58f952010-12-07 23:25:47 +00001257}
1258
Devang Patel50d280c2011-02-22 18:56:12 +00001259/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1260Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patelfe58f952010-12-07 23:25:47 +00001261 DIVariable VarInfo,
1262 BasicBlock *InsertAtEnd) {
1263 assert(V && "no value passed to dbg.value");
Manman Renda918172013-06-29 05:01:19 +00001264 assert(VarInfo.isVariable() &&
1265 "empty or invalid DIVariable passed to dbg.value");
Devang Patelfe58f952010-12-07 23:25:47 +00001266 if (!ValueFn)
1267 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1268
Jay Foadec9186b2011-04-21 19:59:31 +00001269 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patelfe58f952010-12-07 23:25:47 +00001270 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1271 VarInfo };
Jay Foada3efbb12011-07-15 08:37:34 +00001272 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patelfe58f952010-12-07 23:25:47 +00001273}