blob: 773a8cf0f52d918aa638ad6fba8f78618a226d31 [file] [log] [blame]
Devang Patel57c5a202010-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 Wendlingf799efd2012-06-29 08:32:07 +000014#include "llvm/DIBuilder.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/STLExtras.h"
Bill Wendlinge38859d2012-06-28 00:05:13 +000016#include "llvm/DebugInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000017#include "llvm/IR/Constants.h"
18#include "llvm/IR/IntrinsicInst.h"
19#include "llvm/IR/Module.h"
Eric Christopher34164192012-04-03 00:43:49 +000020#include "llvm/Support/Debug.h"
Devang Patel57c5a202010-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 Patel63f83cd2010-12-07 23:58:00 +000031
Devang Patel57c5a202010-11-04 15:01:38 +000032DIBuilder::DIBuilder(Module &m)
Eric Christopher98f9c232013-10-15 23:31:31 +000033 : M(m), VMContext(M.getContext()), TempEnumTypes(0), TempRetainTypes(0),
34 TempSubprograms(0), TempGVs(0), DeclareFn(0), ValueFn(0) {}
Devang Patel57c5a202010-11-04 15:01:38 +000035
Devang Patel2b8acaf2011-08-15 23:00:00 +000036/// finalize - Construct any deferred debug info descriptors.
37void DIBuilder::finalize() {
Devang Pateleb1bb4e2011-08-16 22:09:43 +000038 DIArray Enums = getOrCreateArray(AllEnumTypes);
39 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
40
Manman Ren0b410402013-08-29 23:17:54 +000041 SmallVector<Value *, 16> RetainValues;
42 // Declarations and definitions of the same type may be retained. Some
43 // clients RAUW these pairs, leaving duplicates in the retained types
44 // list. Use a set to remove the duplicates while we transform the
45 // TrackingVHs back into Values.
46 SmallPtrSet<Value *, 16> RetainSet;
47 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
48 if (RetainSet.insert(AllRetainTypes[I]))
49 RetainValues.push_back(AllRetainTypes[I]);
50 DIArray RetainTypes = getOrCreateArray(RetainValues);
Devang Pateleb1bb4e2011-08-16 22:09:43 +000051 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
52
53 DIArray SPs = getOrCreateArray(AllSubprograms);
54 DIType(TempSubprograms).replaceAllUsesWith(SPs);
Devang Patel59e27c52011-08-19 23:28:12 +000055 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
56 DISubprogram SP(SPs.getElement(i));
Eric Christopher27deb262012-04-23 19:00:11 +000057 SmallVector<Value *, 4> Variables;
Devang Patel59e27c52011-08-19 23:28:12 +000058 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
Devang Patel59e27c52011-08-19 23:28:12 +000059 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
60 Variables.push_back(NMD->getOperand(ii));
Devang Patel59e27c52011-08-19 23:28:12 +000061 NMD->eraseFromParent();
62 }
Eric Christopher27deb262012-04-23 19:00:11 +000063 if (MDNode *Temp = SP.getVariablesNodes()) {
64 DIArray AV = getOrCreateArray(Variables);
65 DIType(Temp).replaceAllUsesWith(AV);
66 }
Devang Patel59e27c52011-08-19 23:28:12 +000067 }
Devang Pateleb1bb4e2011-08-16 22:09:43 +000068
69 DIArray GVs = getOrCreateArray(AllGVs);
70 DIType(TempGVs).replaceAllUsesWith(GVs);
David Blaikief55abea2013-04-22 06:12:31 +000071
Eric Christopher2c3a6dc2014-02-28 21:27:57 +000072 SmallVector<Value *, 16> RetainValuesI;
73 for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
74 RetainValuesI.push_back(AllImportedModules[I]);
75 DIArray IMs = getOrCreateArray(RetainValuesI);
David Blaikief55abea2013-04-22 06:12:31 +000076 DIType(TempImportedModules).replaceAllUsesWith(IMs);
Devang Pateleb1bb4e2011-08-16 22:09:43 +000077}
78
Eric Christopher3cc90fe2011-08-26 21:02:40 +000079/// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
80/// N.
Devang Pateleb1bb4e2011-08-16 22:09:43 +000081static MDNode *getNonCompileUnitScope(MDNode *N) {
82 if (DIDescriptor(N).isCompileUnit())
83 return NULL;
84 return N;
Devang Patel2b8acaf2011-08-15 23:00:00 +000085}
86
David Blaikieefb0d652013-03-20 23:58:12 +000087static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
88 StringRef Directory) {
89 assert(!Filename.empty() && "Unable to create file without name");
90 Value *Pair[] = {
91 MDString::get(VMContext, Filename),
Eric Christopher98f9c232013-10-15 23:31:31 +000092 MDString::get(VMContext, Directory)
David Blaikieefb0d652013-03-20 23:58:12 +000093 };
94 return MDNode::get(VMContext, Pair);
95}
96
Devang Patel9b412732011-02-22 18:56:12 +000097/// createCompileUnit - A CompileUnit provides an anchor for all debugging
Devang Patel57c5a202010-11-04 15:01:38 +000098/// information generated during this instance of compilation.
Eric Christopher03b3e112013-07-19 00:51:47 +000099DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
100 StringRef Directory,
101 StringRef Producer, bool isOptimized,
102 StringRef Flags, unsigned RunTimeVer,
Eric Christopher75d49db2014-02-27 01:24:56 +0000103 StringRef SplitName,
104 DebugEmissionKind Kind) {
105
Chandler Carruth4c0ee742012-01-10 18:18:52 +0000106 assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) ||
107 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
108 "Invalid Language tag");
109 assert(!Filename.empty() &&
110 "Unable to create compile unit without filename");
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000111 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
112 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000113
114 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000115
116 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000117
118 TempGVs = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000119
David Blaikief55abea2013-04-22 06:12:31 +0000120 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
121
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000122 Value *Elts[] = {
123 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
David Blaikieefb0d652013-03-20 23:58:12 +0000124 createFilePathPair(VMContext, Filename, Directory),
David Blaikie3b888522013-03-20 22:52:54 +0000125 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000126 MDString::get(VMContext, Producer),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000127 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
128 MDString::get(VMContext, Flags),
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000129 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
David Blaikie33111df2013-02-02 05:56:24 +0000130 TempEnumTypes,
131 TempRetainTypes,
132 TempSubprograms,
Eric Christopher0dab3642013-02-22 23:50:04 +0000133 TempGVs,
David Blaikief55abea2013-04-22 06:12:31 +0000134 TempImportedModules,
Eric Christopher75d49db2014-02-27 01:24:56 +0000135 MDString::get(VMContext, SplitName),
136 ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000137 };
Eric Christopher03b3e112013-07-19 00:51:47 +0000138
139 MDNode *CUNode = MDNode::get(VMContext, Elts);
Devang Patel09fa69e2011-05-03 16:18:28 +0000140
141 // Create a named metadata so that it is easier to find cu in a module.
142 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
Eric Christopher03b3e112013-07-19 00:51:47 +0000143 NMD->addOperand(CUNode);
144
145 return DICompileUnit(CUNode);
Devang Patel57c5a202010-11-04 15:01:38 +0000146}
147
David Blaikiee63d5d12013-05-20 22:50:35 +0000148static DIImportedEntity
149createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
150 unsigned Line, StringRef Name,
Eric Christophere587c082014-02-28 21:37:28 +0000151 SmallVectorImpl<TrackingVH<MDNode> > &AllImportedModules) {
David Blaikiee63d5d12013-05-20 22:50:35 +0000152 const MDNode *R;
153 if (Name.empty()) {
154 Value *Elts[] = {
155 GetTagConstant(C, dwarf::DW_TAG_imported_module),
156 Context,
157 NS,
158 ConstantInt::get(Type::getInt32Ty(C), Line),
159 };
160 R = MDNode::get(C, Elts);
161 } else {
162 Value *Elts[] = {
163 GetTagConstant(C, dwarf::DW_TAG_imported_module),
164 Context,
165 NS,
166 ConstantInt::get(Type::getInt32Ty(C), Line),
167 MDString::get(C, Name)
168 };
169 R = MDNode::get(C, Elts);
170 }
171 DIImportedEntity M(R);
David Blaikie1fd43652013-05-07 21:35:53 +0000172 assert(M.Verify() && "Imported module should be valid");
Eric Christopher2c3a6dc2014-02-28 21:27:57 +0000173 AllImportedModules.push_back(TrackingVH<MDNode>(M));
David Blaikie1fd43652013-05-07 21:35:53 +0000174 return M;
175}
176
David Blaikiee63d5d12013-05-20 22:50:35 +0000177DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
178 DINameSpace NS, unsigned Line,
179 StringRef Name) {
180 return ::createImportedModule(VMContext, Context, NS, Line, Name,
181 AllImportedModules);
182}
183
184DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
185 DIImportedEntity NS,
186 unsigned Line,
187 StringRef Name) {
188 return ::createImportedModule(VMContext, Context, NS, Line, Name,
189 AllImportedModules);
190}
191
David Blaikie1fd43652013-05-07 21:35:53 +0000192DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
193 DIDescriptor Decl,
194 unsigned Line) {
195 Value *Elts[] = {
196 GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration),
197 Context,
198 Decl,
199 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
200 };
201 DIImportedEntity M(MDNode::get(VMContext, Elts));
David Blaikief55abea2013-04-22 06:12:31 +0000202 assert(M.Verify() && "Imported module should be valid");
Eric Christopher2c3a6dc2014-02-28 21:27:57 +0000203 AllImportedModules.push_back(TrackingVH<MDNode>(M));
David Blaikief55abea2013-04-22 06:12:31 +0000204 return M;
205}
206
Devang Patel9b412732011-02-22 18:56:12 +0000207/// createFile - Create a file descriptor to hold debugging information
Devang Patel57c5a202010-11-04 15:01:38 +0000208/// for a file.
Devang Patel9b412732011-02-22 18:56:12 +0000209DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
David Blaikie8fb82242013-03-17 21:13:55 +0000210 Value *Elts[] = {
211 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
David Blaikie5692e722013-03-28 02:44:59 +0000212 createFilePathPair(VMContext, Filename, Directory)
David Blaikie8fb82242013-03-17 21:13:55 +0000213 };
David Blaikie5692e722013-03-28 02:44:59 +0000214 return DIFile(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000215}
216
Devang Patel9b412732011-02-22 18:56:12 +0000217/// createEnumerator - Create a single enumerator value.
David Blaikieb7619002013-06-24 17:34:33 +0000218DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000219 assert(!Name.empty() && "Unable to create enumerator without name");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000220 Value *Elts[] = {
221 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
222 MDString::get(VMContext, Name),
223 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
224 };
David Blaikie5692e722013-03-28 02:44:59 +0000225 return DIEnumerator(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000226}
227
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000228/// \brief Create a DWARF unspecified type.
229DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel04d6d472011-09-14 23:13:28 +0000230 assert(!Name.empty() && "Unable to create type without name");
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000231 // Unspecified types are encoded in DIBasicType format. Line number, filename,
232 // size, alignment, offset and flags are always empty here.
Devang Patel04d6d472011-09-14 23:13:28 +0000233 Value *Elts[] = {
234 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
David Blaikieabec74b2013-03-19 23:25:22 +0000235 NULL, // Filename
Eric Christopher03b3e112013-07-19 00:51:47 +0000236 NULL, // Unused
Devang Patel04d6d472011-09-14 23:13:28 +0000237 MDString::get(VMContext, Name),
Devang Patel04d6d472011-09-14 23:13:28 +0000238 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
239 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
240 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
241 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
242 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
Bill Wendling5ef31592012-07-06 17:49:19 +0000243 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
Devang Patel04d6d472011-09-14 23:13:28 +0000244 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000245 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel04d6d472011-09-14 23:13:28 +0000246}
247
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000248/// \brief Create C++11 nullptr type.
249DIBasicType DIBuilder::createNullPtrType() {
250 return createUnspecifiedType("decltype(nullptr)");
251}
252
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000253/// createBasicType - Create debugging information entry for a basic
Devang Patel57c5a202010-11-04 15:01:38 +0000254/// type, e.g 'char'.
David Blaikie209d63a2013-02-12 00:40:41 +0000255DIBasicType
256DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
257 uint64_t AlignInBits, unsigned Encoding) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000258 assert(!Name.empty() && "Unable to create type without name");
Devang Patel57c5a202010-11-04 15:01:38 +0000259 // Basic types are encoded in DIBasicType format. Line number, filename,
260 // offset and flags are always empty here.
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000261 Value *Elts[] = {
262 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
David Blaikieabec74b2013-03-19 23:25:22 +0000263 NULL, // File/directory name
Eric Christopher03b3e112013-07-19 00:51:47 +0000264 NULL, // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000265 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000266 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
267 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
268 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
269 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
270 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
271 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
272 };
David Blaikie5692e722013-03-28 02:44:59 +0000273 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000274}
275
Nick Lewycky47eebcf2011-11-09 22:45:04 +0000276/// createQualifiedType - Create debugging information entry for a qualified
Devang Patel57c5a202010-11-04 15:01:38 +0000277/// type, e.g. 'const int'.
David Blaikief11de2f2013-02-18 06:41:57 +0000278DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000279 // Qualified types are encoded in DIDerivedType format.
280 Value *Elts[] = {
281 GetTagConstant(VMContext, Tag),
David Blaikieabec74b2013-03-19 23:25:22 +0000282 NULL, // Filename
Eric Christopher03b3e112013-07-19 00:51:47 +0000283 NULL, // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000284 MDString::get(VMContext, StringRef()), // Empty name.
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000285 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
286 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
287 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
288 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
289 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000290 FromTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000291 };
David Blaikie5692e722013-03-28 02:44:59 +0000292 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000293}
294
Devang Patel9b412732011-02-22 18:56:12 +0000295/// createPointerType - Create debugging information entry for a pointer.
David Blaikief11de2f2013-02-18 06:41:57 +0000296DIDerivedType
297DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
298 uint64_t AlignInBits, StringRef Name) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000299 // Pointer types are encoded in DIDerivedType format.
300 Value *Elts[] = {
301 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
David Blaikieabec74b2013-03-19 23:25:22 +0000302 NULL, // Filename
Eric Christopher03b3e112013-07-19 00:51:47 +0000303 NULL, // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000304 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000305 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
306 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
307 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
308 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
309 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renb3388602013-10-05 01:43:03 +0000310 PointeeTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000311 };
David Blaikie5692e722013-03-28 02:44:59 +0000312 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000313}
314
Eric Christopher89e594d2013-04-19 20:37:12 +0000315DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
316 DIType Base) {
David Blaikie5d3249b2013-01-07 05:51:15 +0000317 // Pointer types are encoded in DIDerivedType format.
318 Value *Elts[] = {
319 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
David Blaikieabec74b2013-03-19 23:25:22 +0000320 NULL, // Filename
Eric Christopher03b3e112013-07-19 00:51:47 +0000321 NULL, // Unused
David Blaikie5d3249b2013-01-07 05:51:15 +0000322 NULL,
David Blaikie5d3249b2013-01-07 05:51:15 +0000323 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Eric Christopher98f9c232013-10-15 23:31:31 +0000324 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
325 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
David Blaikie5d3249b2013-01-07 05:51:15 +0000326 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
327 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000328 PointeeTy.getRef(),
Manman Renaad5c3b2013-09-30 19:42:10 +0000329 Base.getRef()
David Blaikie5d3249b2013-01-07 05:51:15 +0000330 };
David Blaikie5692e722013-03-28 02:44:59 +0000331 return DIDerivedType(MDNode::get(VMContext, Elts));
David Blaikie5d3249b2013-01-07 05:51:15 +0000332}
333
Eric Christopherb5cf66c2012-05-19 01:36:37 +0000334/// createReferenceType - Create debugging information entry for a reference
335/// type.
David Blaikief11de2f2013-02-18 06:41:57 +0000336DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
Manman Ren74c188f2013-07-01 21:02:01 +0000337 assert(RTy.isType() && "Unable to create reference type");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000338 // References are encoded in DIDerivedType format.
339 Value *Elts[] = {
Eric Christopherb5cf66c2012-05-19 01:36:37 +0000340 GetTagConstant(VMContext, Tag),
David Blaikieabec74b2013-03-19 23:25:22 +0000341 NULL, // Filename
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000342 NULL, // TheCU,
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000343 NULL, // Name
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000344 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
345 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
346 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
347 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
348 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000349 RTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000350 };
David Blaikie5692e722013-03-28 02:44:59 +0000351 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000352}
353
Devang Patel9b412732011-02-22 18:56:12 +0000354/// createTypedef - Create debugging information entry for a typedef.
David Blaikief11de2f2013-02-18 06:41:57 +0000355DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
356 unsigned LineNo, DIDescriptor Context) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000357 // typedefs are encoded in DIDerivedType format.
Manman Ren74c188f2013-07-01 21:02:01 +0000358 assert(Ty.isType() && "Invalid typedef type!");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000359 Value *Elts[] = {
360 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
David Blaikie200b6ed2013-03-20 00:26:26 +0000361 File.getFileNode(),
Manman Ren5f99ec02013-10-08 23:49:38 +0000362 DIScope(getNonCompileUnitScope(Context)).getRef(),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000363 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000364 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
365 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
366 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
367 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
368 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000369 Ty.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000370 };
David Blaikie5692e722013-03-28 02:44:59 +0000371 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000372}
373
Devang Patel9b412732011-02-22 18:56:12 +0000374/// createFriend - Create debugging information entry for a 'friend'.
Manman Ren3c6acec2013-06-07 18:35:53 +0000375DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000376 // typedefs are encoded in DIDerivedType format.
Manman Ren74c188f2013-07-01 21:02:01 +0000377 assert(Ty.isType() && "Invalid type!");
378 assert(FriendTy.isType() && "Invalid friend type!");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000379 Value *Elts[] = {
380 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
David Blaikieabec74b2013-03-19 23:25:22 +0000381 NULL,
Manman Renaad5c3b2013-09-30 19:42:10 +0000382 Ty.getRef(),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000383 NULL, // Name
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000384 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
385 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
386 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
387 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
388 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000389 FriendTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000390 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000391 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000392}
393
Devang Patel9b412732011-02-22 18:56:12 +0000394/// createInheritance - Create debugging information entry to establish
Eric Christopher777c9282011-09-12 19:58:22 +0000395/// inheritance relationship between two types.
Eric Christopher98f9c232013-10-15 23:31:31 +0000396DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
397 uint64_t BaseOffset,
398 unsigned Flags) {
Manman Ren74c188f2013-07-01 21:02:01 +0000399 assert(Ty.isType() && "Unable to create inheritance");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000400 // TAG_inheritance is encoded in DIDerivedType format.
401 Value *Elts[] = {
402 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
David Blaikieabec74b2013-03-19 23:25:22 +0000403 NULL,
Manman Renaad5c3b2013-09-30 19:42:10 +0000404 Ty.getRef(),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000405 NULL, // Name
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000406 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
407 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
408 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
409 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
410 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renf69bd752013-10-08 22:56:31 +0000411 BaseTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000412 };
David Blaikie5692e722013-03-28 02:44:59 +0000413 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000414}
415
Devang Patel9b412732011-02-22 18:56:12 +0000416/// createMemberType - Create debugging information entry for a member.
Eric Christopher98f9c232013-10-15 23:31:31 +0000417DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
418 DIFile File, unsigned LineNumber,
419 uint64_t SizeInBits,
420 uint64_t AlignInBits,
421 uint64_t OffsetInBits, unsigned Flags,
422 DIType Ty) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000423 // TAG_member is encoded in DIDerivedType format.
424 Value *Elts[] = {
425 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000426 File.getFileNode(),
Manman Renaad5c3b2013-09-30 19:42:10 +0000427 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000428 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000429 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
430 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
431 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
432 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
433 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renf69bd752013-10-08 22:56:31 +0000434 Ty.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000435 };
David Blaikie5692e722013-03-28 02:44:59 +0000436 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000437}
438
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000439/// createStaticMemberType - Create debugging information entry for a
440/// C++ static data member.
Manman Ren3c6acec2013-06-07 18:35:53 +0000441DIDerivedType
442DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
443 DIFile File, unsigned LineNumber,
444 DIType Ty, unsigned Flags,
445 llvm::Value *Val) {
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000446 // TAG_member is encoded in DIDerivedType format.
447 Flags |= DIDescriptor::FlagStaticMember;
448 Value *Elts[] = {
449 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000450 File.getFileNode(),
Manman Ren5f99ec02013-10-08 23:49:38 +0000451 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000452 MDString::get(VMContext, Name),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000453 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Eric Christopher98f9c232013-10-15 23:31:31 +0000454 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
455 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
456 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000457 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renf69bd752013-10-08 22:56:31 +0000458 Ty.getRef(),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000459 Val
460 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000461 return DIDerivedType(MDNode::get(VMContext, Elts));
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000462}
463
Devang Patel514b4002011-04-16 00:11:51 +0000464/// createObjCIVar - Create debugging information entry for Objective-C
465/// instance variable.
Manman Ren3c6acec2013-06-07 18:35:53 +0000466DIDerivedType
Eric Christopher98f9c232013-10-15 23:31:31 +0000467DIBuilder::createObjCIVar(StringRef Name, DIFile File, unsigned LineNumber,
Manman Ren3c6acec2013-06-07 18:35:53 +0000468 uint64_t SizeInBits, uint64_t AlignInBits,
Eric Christopher98f9c232013-10-15 23:31:31 +0000469 uint64_t OffsetInBits, unsigned Flags, DIType Ty,
470 StringRef PropertyName, StringRef GetterName,
471 StringRef SetterName, unsigned PropertyAttributes) {
Devang Patel514b4002011-04-16 00:11:51 +0000472 // TAG_member is encoded in DIDerivedType format.
473 Value *Elts[] = {
474 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000475 File.getFileNode(),
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000476 getNonCompileUnitScope(File),
Devang Patel514b4002011-04-16 00:11:51 +0000477 MDString::get(VMContext, Name),
Devang Patel514b4002011-04-16 00:11:51 +0000478 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
479 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
480 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
481 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
482 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
483 Ty,
484 MDString::get(VMContext, PropertyName),
485 MDString::get(VMContext, GetterName),
486 MDString::get(VMContext, SetterName),
487 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes)
488 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000489 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel514b4002011-04-16 00:11:51 +0000490}
491
Devang Patel44882172012-02-06 17:49:43 +0000492/// createObjCIVar - Create debugging information entry for Objective-C
493/// instance variable.
Eric Christopher98f9c232013-10-15 23:31:31 +0000494DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
495 unsigned LineNumber,
496 uint64_t SizeInBits,
497 uint64_t AlignInBits,
498 uint64_t OffsetInBits, unsigned Flags,
499 DIType Ty, MDNode *PropertyNode) {
Devang Patel44882172012-02-06 17:49:43 +0000500 // TAG_member is encoded in DIDerivedType format.
501 Value *Elts[] = {
502 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000503 File.getFileNode(),
Devang Patel44882172012-02-06 17:49:43 +0000504 getNonCompileUnitScope(File),
505 MDString::get(VMContext, Name),
Devang Patel44882172012-02-06 17:49:43 +0000506 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
507 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
508 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
509 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
510 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
511 Ty,
512 PropertyNode
513 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000514 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel44882172012-02-06 17:49:43 +0000515}
516
Devang Patelcc481592012-02-04 00:59:25 +0000517/// createObjCProperty - Create debugging information entry for Objective-C
518/// property.
Eric Christopher98f9c232013-10-15 23:31:31 +0000519DIObjCProperty
520DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
521 StringRef GetterName, StringRef SetterName,
522 unsigned PropertyAttributes, DIType Ty) {
Devang Patelcc481592012-02-04 00:59:25 +0000523 Value *Elts[] = {
Eric Christopherc13fd6d2012-03-29 21:35:05 +0000524 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
Devang Patelcc481592012-02-04 00:59:25 +0000525 MDString::get(VMContext, Name),
Eric Christopher70e1bd82012-03-29 08:42:56 +0000526 File,
527 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Devang Patelcc481592012-02-04 00:59:25 +0000528 MDString::get(VMContext, GetterName),
529 MDString::get(VMContext, SetterName),
Eric Christopher70e1bd82012-03-29 08:42:56 +0000530 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
531 Ty
Devang Patelcc481592012-02-04 00:59:25 +0000532 };
David Blaikie5692e722013-03-28 02:44:59 +0000533 return DIObjCProperty(MDNode::get(VMContext, Elts));
Devang Patelcc481592012-02-04 00:59:25 +0000534}
535
Devang Patel9b412732011-02-22 18:56:12 +0000536/// createTemplateTypeParameter - Create debugging information for template
Devang Patel3a9e65e2011-02-02 21:38:25 +0000537/// type parameter.
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000538DITemplateTypeParameter
Devang Patel9b412732011-02-22 18:56:12 +0000539DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
Devang Patel3a9e65e2011-02-02 21:38:25 +0000540 DIType Ty, MDNode *File, unsigned LineNo,
541 unsigned ColumnNo) {
542 Value *Elts[] = {
543 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
Manman Ren88b0f942013-10-09 19:46:28 +0000544 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel3a9e65e2011-02-02 21:38:25 +0000545 MDString::get(VMContext, Name),
Manman Ren88b0f942013-10-09 19:46:28 +0000546 Ty.getRef(),
Devang Patel3a9e65e2011-02-02 21:38:25 +0000547 File,
548 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
549 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
550 };
David Blaikie5692e722013-03-28 02:44:59 +0000551 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
Devang Patel3a9e65e2011-02-02 21:38:25 +0000552}
553
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000554DITemplateValueParameter
David Blaikie2b380232013-06-22 18:59:11 +0000555DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
556 StringRef Name, DIType Ty,
557 Value *Val, MDNode *File,
558 unsigned LineNo,
Devang Patelbe933b42011-02-02 22:35:53 +0000559 unsigned ColumnNo) {
560 Value *Elts[] = {
David Blaikie2b380232013-06-22 18:59:11 +0000561 GetTagConstant(VMContext, Tag),
Manman Ren88b0f942013-10-09 19:46:28 +0000562 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patelbe933b42011-02-02 22:35:53 +0000563 MDString::get(VMContext, Name),
Manman Ren88b0f942013-10-09 19:46:28 +0000564 Ty.getRef(),
David Blaikiea1e813d2013-05-10 21:52:07 +0000565 Val,
Devang Patelbe933b42011-02-02 22:35:53 +0000566 File,
567 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
568 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
569 };
David Blaikie5692e722013-03-28 02:44:59 +0000570 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
Devang Patelbe933b42011-02-02 22:35:53 +0000571}
572
David Blaikie2b380232013-06-22 18:59:11 +0000573/// createTemplateValueParameter - Create debugging information for template
574/// value parameter.
575DITemplateValueParameter
576DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
577 DIType Ty, Value *Val,
578 MDNode *File, unsigned LineNo,
579 unsigned ColumnNo) {
580 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
581 Context, Name, Ty, Val, File, LineNo,
582 ColumnNo);
583}
584
585DITemplateValueParameter
586DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
587 DIType Ty, StringRef Val,
588 MDNode *File, unsigned LineNo,
589 unsigned ColumnNo) {
590 return createTemplateValueParameter(
591 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
592 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
593}
594
595DITemplateValueParameter
596DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
597 DIType Ty, DIArray Val,
598 MDNode *File, unsigned LineNo,
599 unsigned ColumnNo) {
600 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
601 Context, Name, Ty, Val, File, LineNo,
602 ColumnNo);
603}
604
Eric Christopher17426692012-07-06 02:35:57 +0000605/// createClassType - Create debugging information entry for a class.
David Blaikiea7310a32013-03-26 23:46:39 +0000606DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
607 DIFile File, unsigned LineNumber,
608 uint64_t SizeInBits,
609 uint64_t AlignInBits,
610 uint64_t OffsetInBits,
611 unsigned Flags, DIType DerivedFrom,
612 DIArray Elements,
Manman Ren27552062013-09-06 23:54:23 +0000613 DIType VTableHolder,
Manman Ren547467b2013-08-27 23:06:40 +0000614 MDNode *TemplateParams,
615 StringRef UniqueIdentifier) {
Manman Ren74c188f2013-07-01 21:02:01 +0000616 assert((!Context || Context.isScope() || Context.isType()) &&
David Blaikie085abe32013-03-11 23:21:19 +0000617 "createClassType should be called with a valid Context");
618 // TAG_class_type is encoded in DICompositeType format.
Eric Christopher17426692012-07-06 02:35:57 +0000619 Value *Elts[] = {
620 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000621 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000622 DIScope(getNonCompileUnitScope(Context)).getRef(),
Eric Christopher17426692012-07-06 02:35:57 +0000623 MDString::get(VMContext, Name),
Eric Christopher17426692012-07-06 02:35:57 +0000624 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
625 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
626 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
627 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
628 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renbacd1ef2013-10-08 23:28:51 +0000629 DerivedFrom.getRef(),
Eric Christopher17426692012-07-06 02:35:57 +0000630 Elements,
631 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Renaad5c3b2013-09-30 19:42:10 +0000632 VTableHolder.getRef(),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000633 TemplateParams,
Manman Ren547467b2013-08-27 23:06:40 +0000634 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Eric Christopher17426692012-07-06 02:35:57 +0000635 };
David Blaikiea7310a32013-03-26 23:46:39 +0000636 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren74c188f2013-07-01 21:02:01 +0000637 assert(R.isCompositeType() &&
638 "createClassType should return a DICompositeType");
Manman Ren0b410402013-08-29 23:17:54 +0000639 if (!UniqueIdentifier.empty())
640 retainType(R);
David Blaikie085abe32013-03-11 23:21:19 +0000641 return R;
Eric Christopher17426692012-07-06 02:35:57 +0000642}
643
Devang Patel9b412732011-02-22 18:56:12 +0000644/// createStructType - Create debugging information entry for a struct.
David Blaikiebbe0e1a2013-02-25 01:07:18 +0000645DICompositeType DIBuilder::createStructType(DIDescriptor Context,
646 StringRef Name, DIFile File,
647 unsigned LineNumber,
648 uint64_t SizeInBits,
649 uint64_t AlignInBits,
650 unsigned Flags, DIType DerivedFrom,
651 DIArray Elements,
652 unsigned RunTimeLang,
Manman Ren27552062013-09-06 23:54:23 +0000653 DIType VTableHolder,
Manman Ren547467b2013-08-27 23:06:40 +0000654 StringRef UniqueIdentifier) {
Devang Patel746660f2010-12-07 23:25:47 +0000655 // TAG_structure_type is encoded in DICompositeType format.
656 Value *Elts[] = {
657 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000658 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000659 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel746660f2010-12-07 23:25:47 +0000660 MDString::get(VMContext, Name),
Devang Patel746660f2010-12-07 23:25:47 +0000661 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
662 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
663 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Devang Patel89ea4f22010-12-08 01:50:15 +0000664 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patel746660f2010-12-07 23:25:47 +0000665 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renbacd1ef2013-10-08 23:28:51 +0000666 DerivedFrom.getRef(),
Devang Patel746660f2010-12-07 23:25:47 +0000667 Elements,
668 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Renaad5c3b2013-09-30 19:42:10 +0000669 VTableHolder.getRef(),
David Blaikie12bbf712013-02-18 07:27:30 +0000670 NULL,
Manman Ren547467b2013-08-27 23:06:40 +0000671 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel746660f2010-12-07 23:25:47 +0000672 };
David Blaikie085abe32013-03-11 23:21:19 +0000673 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren74c188f2013-07-01 21:02:01 +0000674 assert(R.isCompositeType() &&
675 "createStructType should return a DICompositeType");
Manman Ren0b410402013-08-29 23:17:54 +0000676 if (!UniqueIdentifier.empty())
677 retainType(R);
David Blaikie085abe32013-03-11 23:21:19 +0000678 return R;
Devang Patel746660f2010-12-07 23:25:47 +0000679}
680
Devang Patel9b412732011-02-22 18:56:12 +0000681/// createUnionType - Create debugging information entry for an union.
Eric Christopher17dd8f02013-04-02 22:55:52 +0000682DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
683 DIFile File, unsigned LineNumber,
684 uint64_t SizeInBits,
685 uint64_t AlignInBits, unsigned Flags,
686 DIArray Elements,
Manman Ren547467b2013-08-27 23:06:40 +0000687 unsigned RunTimeLang,
688 StringRef UniqueIdentifier) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000689 // TAG_union_type is encoded in DICompositeType format.
690 Value *Elts[] = {
691 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000692 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000693 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000694 MDString::get(VMContext, Name),
Devang Patel89ea4f22010-12-08 01:50:15 +0000695 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
696 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
697 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000698 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Devang Patel89ea4f22010-12-08 01:50:15 +0000699 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patel78847f02011-12-16 17:51:31 +0000700 NULL,
Devang Patel89ea4f22010-12-08 01:50:15 +0000701 Elements,
702 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000703 NULL,
704 NULL,
Manman Ren547467b2013-08-27 23:06:40 +0000705 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel89ea4f22010-12-08 01:50:15 +0000706 };
Manman Ren0b410402013-08-29 23:17:54 +0000707 DICompositeType R(MDNode::get(VMContext, Elts));
708 if (!UniqueIdentifier.empty())
709 retainType(R);
710 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000711}
712
Devang Patel9b412732011-02-22 18:56:12 +0000713/// createSubroutineType - Create subroutine type.
Eric Christopher98f9c232013-10-15 23:31:31 +0000714DICompositeType DIBuilder::createSubroutineType(DIFile File,
Adrian Prantl99c7af22013-12-18 21:48:19 +0000715 DIArray ParameterTypes,
716 unsigned Flags) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000717 // TAG_subroutine_type is encoded in DICompositeType format.
718 Value *Elts[] = {
719 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
Bill Wendling7154c432012-07-06 17:47:36 +0000720 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Manman Ren8ddddad2013-09-08 06:00:42 +0000721 NULL,
David Blaikieabec74b2013-03-19 23:25:22 +0000722 MDString::get(VMContext, ""),
Eric Christopher98f9c232013-10-15 23:31:31 +0000723 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
724 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
725 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
726 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Adrian Prantl99c7af22013-12-18 21:48:19 +0000727 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
Devang Patel78847f02011-12-16 17:51:31 +0000728 NULL,
Devang Patel89ea4f22010-12-08 01:50:15 +0000729 ParameterTypes,
730 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000731 NULL,
732 NULL,
733 NULL // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000734 };
David Blaikie5692e722013-03-28 02:44:59 +0000735 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000736}
737
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000738/// createEnumerationType - Create debugging information entry for an
Devang Patel89ea4f22010-12-08 01:50:15 +0000739/// enumeration.
David Blaikief11de2f2013-02-18 06:41:57 +0000740DICompositeType DIBuilder::createEnumerationType(
741 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
742 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Manman Ren547467b2013-08-27 23:06:40 +0000743 DIType UnderlyingType, StringRef UniqueIdentifier) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000744 // TAG_enumeration_type is encoded in DICompositeType format.
745 Value *Elts[] = {
746 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000747 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000748 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000749 MDString::get(VMContext, Name),
Devang Patel89ea4f22010-12-08 01:50:15 +0000750 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
751 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
752 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000753 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
754 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renbacd1ef2013-10-08 23:28:51 +0000755 UnderlyingType.getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000756 Elements,
757 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000758 NULL,
759 NULL,
Manman Ren547467b2013-08-27 23:06:40 +0000760 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Devang Patel89ea4f22010-12-08 01:50:15 +0000761 };
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000762 DICompositeType CTy(MDNode::get(VMContext, Elts));
763 AllEnumTypes.push_back(CTy);
Manman Ren0b410402013-08-29 23:17:54 +0000764 if (!UniqueIdentifier.empty())
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000765 retainType(CTy);
766 return CTy;
Devang Patel89ea4f22010-12-08 01:50:15 +0000767}
768
Devang Patel9b412732011-02-22 18:56:12 +0000769/// createArrayType - Create debugging information entry for an array.
David Blaikief11de2f2013-02-18 06:41:57 +0000770DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
771 DIType Ty, DIArray Subscripts) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000772 // TAG_array_type is encoded in DICompositeType format.
773 Value *Elts[] = {
774 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikieabec74b2013-03-19 23:25:22 +0000775 NULL, // Filename/Directory,
Eric Christopher03b3e112013-07-19 00:51:47 +0000776 NULL, // Unused
Devang Patel89ea4f22010-12-08 01:50:15 +0000777 MDString::get(VMContext, ""),
Eric Christopher98f9c232013-10-15 23:31:31 +0000778 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Devang Patel89ea4f22010-12-08 01:50:15 +0000779 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
780 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000781 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
782 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renbacd1ef2013-10-08 23:28:51 +0000783 Ty.getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000784 Subscripts,
785 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000786 NULL,
787 NULL,
788 NULL // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000789 };
David Blaikie5692e722013-03-28 02:44:59 +0000790 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000791}
792
Devang Patel9b412732011-02-22 18:56:12 +0000793/// createVectorType - Create debugging information entry for a vector.
Manman Ren60711602013-06-07 03:13:46 +0000794DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
795 DIType Ty, DIArray Subscripts) {
Eric Christopher72a52952013-01-08 01:53:52 +0000796 // A vector is an array type with the FlagVector flag applied.
Devang Patel89ea4f22010-12-08 01:50:15 +0000797 Value *Elts[] = {
Eric Christopher72a52952013-01-08 01:53:52 +0000798 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
David Blaikieabec74b2013-03-19 23:25:22 +0000799 NULL, // Filename/Directory,
Eric Christopher03b3e112013-07-19 00:51:47 +0000800 NULL, // Unused
Devang Patel89ea4f22010-12-08 01:50:15 +0000801 MDString::get(VMContext, ""),
Eric Christopher98f9c232013-10-15 23:31:31 +0000802 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Devang Patel89ea4f22010-12-08 01:50:15 +0000803 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
804 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000805 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
Eric Christopher72a52952013-01-08 01:53:52 +0000806 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
Manman Renbacd1ef2013-10-08 23:28:51 +0000807 Ty.getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000808 Subscripts,
809 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000810 NULL,
811 NULL,
812 NULL // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000813 };
Manman Ren60711602013-06-07 03:13:46 +0000814 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000815}
Devang Patel746660f2010-12-07 23:25:47 +0000816
Devang Patel9b412732011-02-22 18:56:12 +0000817/// createArtificialType - Create a new DIType with "artificial" flag set.
818DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel57c5a202010-11-04 15:01:38 +0000819 if (Ty.isArtificial())
820 return Ty;
821
822 SmallVector<Value *, 9> Elts;
823 MDNode *N = Ty;
824 assert (N && "Unexpected input DIType!");
Manman Ren8ddddad2013-09-08 06:00:42 +0000825 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
826 Elts.push_back(N->getOperand(i));
Devang Patel57c5a202010-11-04 15:01:38 +0000827
828 unsigned CurFlags = Ty.getFlags();
829 CurFlags = CurFlags | DIType::FlagArtificial;
830
831 // Flags are stored at this slot.
Eric Christopher98f9c232013-10-15 23:31:31 +0000832 // FIXME: Add an enum for this magic value.
David Blaikie5692e722013-03-28 02:44:59 +0000833 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Devang Patel57c5a202010-11-04 15:01:38 +0000834
David Blaikie5692e722013-03-28 02:44:59 +0000835 return DIType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000836}
Devang Patel746660f2010-12-07 23:25:47 +0000837
Eric Christopher9bd36092013-01-08 01:53:42 +0000838/// createObjectPointerType - Create a new type with both the object pointer
839/// and artificial flags set.
Eric Christophere3417762012-09-12 23:36:19 +0000840DIType DIBuilder::createObjectPointerType(DIType Ty) {
841 if (Ty.isObjectPointer())
842 return Ty;
843
844 SmallVector<Value *, 9> Elts;
845 MDNode *N = Ty;
846 assert (N && "Unexpected input DIType!");
Manman Ren8ddddad2013-09-08 06:00:42 +0000847 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
848 Elts.push_back(N->getOperand(i));
Eric Christophere3417762012-09-12 23:36:19 +0000849
850 unsigned CurFlags = Ty.getFlags();
851 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
852
853 // Flags are stored at this slot.
Eric Christopher98f9c232013-10-15 23:31:31 +0000854 // FIXME: Add an enum for this magic value.
David Blaikie5692e722013-03-28 02:44:59 +0000855 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Eric Christophere3417762012-09-12 23:36:19 +0000856
David Blaikie5692e722013-03-28 02:44:59 +0000857 return DIType(MDNode::get(VMContext, Elts));
Eric Christophere3417762012-09-12 23:36:19 +0000858}
859
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000860/// retainType - Retain DIType in a module even if it is not referenced
Devang Patel89ea4f22010-12-08 01:50:15 +0000861/// through debug info anchors.
Devang Patel9b412732011-02-22 18:56:12 +0000862void DIBuilder::retainType(DIType T) {
Manman Ren0b410402013-08-29 23:17:54 +0000863 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
Devang Patel89ea4f22010-12-08 01:50:15 +0000864}
865
Devang Patel9b412732011-02-22 18:56:12 +0000866/// createUnspecifiedParameter - Create unspeicified type descriptor
Devang Patel89ea4f22010-12-08 01:50:15 +0000867/// for the subroutine type.
Devang Patel9b412732011-02-22 18:56:12 +0000868DIDescriptor DIBuilder::createUnspecifiedParameter() {
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000869 Value *Elts[] = {
870 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
Devang Patel89ea4f22010-12-08 01:50:15 +0000871 };
Devang Patel0c773242011-04-18 23:51:03 +0000872 return DIDescriptor(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000873}
874
Eric Christopherae56eec2012-02-08 00:22:26 +0000875/// createForwardDecl - Create a temporary forward-declared type that
876/// can be RAUW'd if the full type is seen.
Eric Christopher98f9c232013-10-15 23:31:31 +0000877DICompositeType
878DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
879 DIFile F, unsigned Line, unsigned RuntimeLang,
880 uint64_t SizeInBits, uint64_t AlignInBits,
881 StringRef UniqueIdentifier) {
Eric Christopherae56eec2012-02-08 00:22:26 +0000882 // Create a temporary MDNode.
883 Value *Elts[] = {
884 GetTagConstant(VMContext, Tag),
David Blaikie200b6ed2013-03-20 00:26:26 +0000885 F.getFileNode(),
Manman Renb3dc3af2013-10-09 18:10:55 +0000886 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Eric Christopherae56eec2012-02-08 00:22:26 +0000887 MDString::get(VMContext, Name),
Eric Christopherae56eec2012-02-08 00:22:26 +0000888 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
Eli Friedmanc6c86c42012-10-05 01:49:14 +0000889 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
890 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000891 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
892 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
Eric Christopher89797122012-02-20 18:04:14 +0000893 NULL,
894 DIArray(),
David Blaikied4e106e2013-08-16 20:42:14 +0000895 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000896 NULL,
897 NULL, //TemplateParams
Manman Ren547467b2013-08-27 23:06:40 +0000898 UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
Eric Christopherae56eec2012-02-08 00:22:26 +0000899 };
900 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
David Blaikied4e106e2013-08-16 20:42:14 +0000901 DICompositeType RetTy(Node);
902 assert(RetTy.isCompositeType() &&
Manman Ren74c188f2013-07-01 21:02:01 +0000903 "createForwardDecl result should be a DIType");
Manman Ren0b410402013-08-29 23:17:54 +0000904 if (!UniqueIdentifier.empty())
905 retainType(RetTy);
Manman Rend0e67aa2013-07-02 18:37:35 +0000906 return RetTy;
Eric Christopherae56eec2012-02-08 00:22:26 +0000907}
908
Devang Patel9b412732011-02-22 18:56:12 +0000909/// getOrCreateArray - Get a DIArray, create one if required.
Jay Foaddbf81d82011-04-24 10:11:03 +0000910DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
Jay Foaddbf81d82011-04-24 10:11:03 +0000911 return DIArray(MDNode::get(VMContext, Elements));
Devang Patel746660f2010-12-07 23:25:47 +0000912}
913
Devang Patel9b412732011-02-22 18:56:12 +0000914/// getOrCreateSubrange - Create a descriptor for a value range. This
Devang Patel89ea4f22010-12-08 01:50:15 +0000915/// implicitly uniques the values returned.
Bill Wendlingd7767122012-12-04 21:34:03 +0000916DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000917 Value *Elts[] = {
918 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
919 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
Bill Wendlingbfc0e572012-12-04 06:20:49 +0000920 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
Devang Patel89ea4f22010-12-08 01:50:15 +0000921 };
922
Devang Patel0c773242011-04-18 23:51:03 +0000923 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000924}
925
David Blaikie62f1fea2013-03-20 17:49:48 +0000926/// \brief Create a new descriptor for the specified global.
Eric Christopher98f9c232013-10-15 23:31:31 +0000927DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
928 StringRef LinkageName,
929 DIFile F, unsigned LineNumber,
930 DIType Ty, bool isLocalToUnit,
931 Value *Val) {
Devang Patel746660f2010-12-07 23:25:47 +0000932 Value *Elts[] = {
933 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendling7154c432012-07-06 17:47:36 +0000934 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000935 NULL, // TheCU,
Devang Patel746660f2010-12-07 23:25:47 +0000936 MDString::get(VMContext, Name),
937 MDString::get(VMContext, Name),
David Blaikie62f1fea2013-03-20 17:49:48 +0000938 MDString::get(VMContext, LinkageName),
Devang Patel746660f2010-12-07 23:25:47 +0000939 F,
940 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
941 Ty,
942 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
943 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000944 Val,
945 DIDescriptor()
Devang Patel746660f2010-12-07 23:25:47 +0000946 };
Devang Patel0c773242011-04-18 23:51:03 +0000947 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000948 AllGVs.push_back(Node);
Devang Patel746660f2010-12-07 23:25:47 +0000949 return DIGlobalVariable(Node);
950}
951
David Blaikie62f1fea2013-03-20 17:49:48 +0000952/// \brief Create a new descriptor for the specified global.
Eric Christopher98f9c232013-10-15 23:31:31 +0000953DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
954 unsigned LineNumber, DIType Ty,
955 bool isLocalToUnit,
956 Value *Val) {
David Blaikie62f1fea2013-03-20 17:49:48 +0000957 return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
958 Val);
959}
960
Devang Patel9b412732011-02-22 18:56:12 +0000961/// createStaticVariable - Create a new descriptor for the specified static
Devang Patel746660f2010-12-07 23:25:47 +0000962/// variable.
Eric Christopher98f9c232013-10-15 23:31:31 +0000963DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
964 StringRef Name,
965 StringRef LinkageName,
966 DIFile F, unsigned LineNumber,
967 DIType Ty, bool isLocalToUnit,
968 Value *Val, MDNode *Decl) {
Devang Patel746660f2010-12-07 23:25:47 +0000969 Value *Elts[] = {
970 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendling7154c432012-07-06 17:47:36 +0000971 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000972 getNonCompileUnitScope(Context),
Devang Patel746660f2010-12-07 23:25:47 +0000973 MDString::get(VMContext, Name),
974 MDString::get(VMContext, Name),
975 MDString::get(VMContext, LinkageName),
976 F,
977 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
978 Ty,
979 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
980 ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000981 Val,
982 DIDescriptor(Decl)
Devang Patel746660f2010-12-07 23:25:47 +0000983 };
Devang Patel0c773242011-04-18 23:51:03 +0000984 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000985 AllGVs.push_back(Node);
Devang Patel746660f2010-12-07 23:25:47 +0000986 return DIGlobalVariable(Node);
987}
988
Devang Patel9b412732011-02-22 18:56:12 +0000989/// createVariable - Create a new descriptor for the specified variable.
990DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel63f83cd2010-12-07 23:58:00 +0000991 StringRef Name, DIFile File,
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000992 unsigned LineNo, DIType Ty,
Devang Patel40eee1e2011-03-01 22:58:13 +0000993 bool AlwaysPreserve, unsigned Flags,
994 unsigned ArgNo) {
David Blaikie085abe32013-03-11 23:21:19 +0000995 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren74c188f2013-07-01 21:02:01 +0000996 assert((!Context || Context.isScope()) &&
David Blaikie085abe32013-03-11 23:21:19 +0000997 "createLocalVariable should be called with a valid Context");
Manman Ren74c188f2013-07-01 21:02:01 +0000998 assert(Ty.isType() &&
David Blaikie085abe32013-03-11 23:21:19 +0000999 "createLocalVariable should be called with a valid type");
Devang Patel63f83cd2010-12-07 23:58:00 +00001000 Value *Elts[] = {
1001 GetTagConstant(VMContext, Tag),
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001002 getNonCompileUnitScope(Scope),
Devang Patel63f83cd2010-12-07 23:58:00 +00001003 MDString::get(VMContext, Name),
1004 File,
Devang Patel40eee1e2011-03-01 22:58:13 +00001005 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
Devang Patel63f83cd2010-12-07 23:58:00 +00001006 Ty,
Devang Patelcfa82a32011-07-19 19:41:54 +00001007 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Bill Wendling5ef31592012-07-06 17:49:19 +00001008 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel63f83cd2010-12-07 23:58:00 +00001009 };
Devang Patel0c773242011-04-18 23:51:03 +00001010 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel63f83cd2010-12-07 23:58:00 +00001011 if (AlwaysPreserve) {
1012 // The optimizer may remove local variable. If there is an interest
1013 // to preserve variable info in such situation then stash it in a
1014 // named mdnode.
1015 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel59e27c52011-08-19 23:28:12 +00001016 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel63f83cd2010-12-07 23:58:00 +00001017 FnLocals->addOperand(Node);
1018 }
Manman Rend0e67aa2013-07-02 18:37:35 +00001019 DIVariable RetVar(Node);
1020 assert(RetVar.isVariable() &&
Manman Ren74c188f2013-07-01 21:02:01 +00001021 "createLocalVariable should return a valid DIVariable");
Manman Rend0e67aa2013-07-02 18:37:35 +00001022 return RetVar;
Devang Patel63f83cd2010-12-07 23:58:00 +00001023}
1024
Devang Patel9b412732011-02-22 18:56:12 +00001025/// createComplexVariable - Create a new descriptor for the specified variable
Devang Patel746660f2010-12-07 23:25:47 +00001026/// which has a complex address expression for its address.
Devang Patel9b412732011-02-22 18:56:12 +00001027DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel746660f2010-12-07 23:25:47 +00001028 StringRef Name, DIFile F,
1029 unsigned LineNo,
Jay Foaddbf81d82011-04-24 10:11:03 +00001030 DIType Ty, ArrayRef<Value *> Addr,
1031 unsigned ArgNo) {
Devang Patel746660f2010-12-07 23:25:47 +00001032 SmallVector<Value *, 15> Elts;
1033 Elts.push_back(GetTagConstant(VMContext, Tag));
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001034 Elts.push_back(getNonCompileUnitScope(Scope)),
Devang Patel746660f2010-12-07 23:25:47 +00001035 Elts.push_back(MDString::get(VMContext, Name));
1036 Elts.push_back(F);
Eric Christopher3cc90fe2011-08-26 21:02:40 +00001037 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext),
Devang Patela93cc252012-02-08 00:17:07 +00001038 (LineNo | (ArgNo << 24))));
Devang Patel746660f2010-12-07 23:25:47 +00001039 Elts.push_back(Ty);
Bill Wendling7154c432012-07-06 17:47:36 +00001040 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
1041 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
Jay Foaddbf81d82011-04-24 10:11:03 +00001042 Elts.append(Addr.begin(), Addr.end());
Devang Patel746660f2010-12-07 23:25:47 +00001043
Devang Patel0c773242011-04-18 23:51:03 +00001044 return DIVariable(MDNode::get(VMContext, Elts));
Devang Patel746660f2010-12-07 23:25:47 +00001045}
1046
Devang Patel9b412732011-02-22 18:56:12 +00001047/// createFunction - Create a new descriptor for the specified function.
Manman Renc50fa112013-10-10 18:40:01 +00001048/// FIXME: this is added for dragonegg. Once we update dragonegg
1049/// to call resolve function, this will be removed.
Eric Christopher98f9c232013-10-15 23:31:31 +00001050DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1051 StringRef LinkageName, DIFile File,
1052 unsigned LineNo, DICompositeType Ty,
Manman Renc50fa112013-10-10 18:40:01 +00001053 bool isLocalToUnit, bool isDefinition,
Eric Christopher98f9c232013-10-15 23:31:31 +00001054 unsigned ScopeLine, unsigned Flags,
1055 bool isOptimized, Function *Fn,
1056 MDNode *TParams, MDNode *Decl) {
Manman Renc50fa112013-10-10 18:40:01 +00001057 // 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.
Eric Christopher98f9c232013-10-15 23:31:31 +00001066DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1067 StringRef LinkageName, DIFile File,
1068 unsigned LineNo, DICompositeType Ty,
Devang Patelb68c6232010-12-08 20:42:44 +00001069 bool isLocalToUnit, bool isDefinition,
Eric Christopher98f9c232013-10-15 23:31:31 +00001070 unsigned ScopeLine, unsigned Flags,
1071 bool isOptimized, Function *Fn,
1072 MDNode *TParams, MDNode *Decl) {
David Blaikie5174c842013-05-22 23:22:18 +00001073 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1074 "function types should be subroutines");
Devang Patel59e27c52011-08-19 23:28:12 +00001075 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patelb68c6232010-12-08 20:42:44 +00001076 Value *Elts[] = {
1077 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikie5ef3fcb2013-03-21 23:08:34 +00001078 File.getFileNode(),
Manman Renc50fa112013-10-10 18:40:01 +00001079 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patelb68c6232010-12-08 20:42:44 +00001080 MDString::get(VMContext, Name),
1081 MDString::get(VMContext, Name),
1082 MDString::get(VMContext, LinkageName),
Devang Patelb68c6232010-12-08 20:42:44 +00001083 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1084 Ty,
1085 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1086 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1087 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1088 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patelcdd833e2011-12-15 17:55:56 +00001089 NULL,
Devang Patelb68c6232010-12-08 20:42:44 +00001090 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1091 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patel9f738842011-04-05 22:52:06 +00001092 Fn,
Devang Patel1d6bbd42011-04-22 23:10:17 +00001093 TParams,
Devang Patel59e27c52011-08-19 23:28:12 +00001094 Decl,
David Blaikie2811f8a2013-02-04 05:56:36 +00001095 MDNode::getTemporary(VMContext, TElts),
Eric Christopher34164192012-04-03 00:43:49 +00001096 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
Devang Patelb68c6232010-12-08 20:42:44 +00001097 };
Devang Patel0c773242011-04-18 23:51:03 +00001098 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patelb68c6232010-12-08 20:42:44 +00001099
1100 // Create a named metadata so that we do not lose this mdnode.
David Blaikie595eb442013-02-18 07:10:22 +00001101 if (isDefinition)
1102 AllSubprograms.push_back(Node);
David Blaikiecc8d0902013-03-21 20:28:52 +00001103 DISubprogram S(Node);
Eric Christopher961959f2014-02-28 21:27:59 +00001104 assert(S.isSubprogram() &&
1105 "createFunction should return a valid DISubprogram");
David Blaikiecc8d0902013-03-21 20:28:52 +00001106 return S;
Devang Patelb68c6232010-12-08 20:42:44 +00001107}
1108
Devang Patel9b412732011-02-22 18:56:12 +00001109/// createMethod - Create a new descriptor for the specified C++ method.
Eric Christopher98f9c232013-10-15 23:31:31 +00001110DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1111 StringRef LinkageName, DIFile F,
David Blaikie5174c842013-05-22 23:22:18 +00001112 unsigned LineNo, DICompositeType Ty,
Eric Christopher98f9c232013-10-15 23:31:31 +00001113 bool isLocalToUnit, bool isDefinition,
Devang Patelb68c6232010-12-08 20:42:44 +00001114 unsigned VK, unsigned VIndex,
Eric Christopher98f9c232013-10-15 23:31:31 +00001115 DIType VTableHolder, unsigned Flags,
1116 bool isOptimized, Function *Fn,
Devang Patel9f738842011-04-05 22:52:06 +00001117 MDNode *TParam) {
David Blaikie5174c842013-05-22 23:22:18 +00001118 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1119 "function types should be subroutines");
Eric Christopher5cb56322013-10-15 23:31:36 +00001120 assert(getNonCompileUnitScope(Context) &&
1121 "Methods should have both a Context and a context that isn't "
1122 "the compile unit.");
Devang Patel59e27c52011-08-19 23:28:12 +00001123 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patelb68c6232010-12-08 20:42:44 +00001124 Value *Elts[] = {
1125 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikie5ef3fcb2013-03-21 23:08:34 +00001126 F.getFileNode(),
Eric Christopher5cb56322013-10-15 23:31:36 +00001127 DIScope(Context).getRef(),
Devang Patelb68c6232010-12-08 20:42:44 +00001128 MDString::get(VMContext, Name),
1129 MDString::get(VMContext, Name),
1130 MDString::get(VMContext, LinkageName),
Devang Patelb68c6232010-12-08 20:42:44 +00001131 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1132 Ty,
1133 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1134 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
Eric Christopher98f9c232013-10-15 23:31:31 +00001135 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
Devang Patelb68c6232010-12-08 20:42:44 +00001136 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
Manman Renaad5c3b2013-09-30 19:42:10 +00001137 VTableHolder.getRef(),
Devang Patelb68c6232010-12-08 20:42:44 +00001138 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1139 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patel9f738842011-04-05 22:52:06 +00001140 Fn,
1141 TParam,
Bill Wendling7154c432012-07-06 17:47:36 +00001142 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikie2811f8a2013-02-04 05:56:36 +00001143 MDNode::getTemporary(VMContext, TElts),
Eric Christopher5d5338f2012-05-18 00:16:22 +00001144 // FIXME: Do we want to use different scope/lines?
Eric Christopher34164192012-04-03 00:43:49 +00001145 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
Devang Patelb68c6232010-12-08 20:42:44 +00001146 };
Devang Patel0c773242011-04-18 23:51:03 +00001147 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie595eb442013-02-18 07:10:22 +00001148 if (isDefinition)
1149 AllSubprograms.push_back(Node);
David Blaikiecc8d0902013-03-21 20:28:52 +00001150 DISubprogram S(Node);
Manman Ren74c188f2013-07-01 21:02:01 +00001151 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikiecc8d0902013-03-21 20:28:52 +00001152 return S;
Devang Patelb68c6232010-12-08 20:42:44 +00001153}
1154
Devang Patel9b412732011-02-22 18:56:12 +00001155/// createNameSpace - This creates new descriptor for a namespace
Devang Patel746660f2010-12-07 23:25:47 +00001156/// with the specified parent scope.
Devang Patel9b412732011-02-22 18:56:12 +00001157DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patel746660f2010-12-07 23:25:47 +00001158 DIFile File, unsigned LineNo) {
1159 Value *Elts[] = {
1160 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
David Blaikie2881da72013-03-20 19:39:15 +00001161 File.getFileNode(),
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001162 getNonCompileUnitScope(Scope),
Devang Patel746660f2010-12-07 23:25:47 +00001163 MDString::get(VMContext, Name),
Devang Patel746660f2010-12-07 23:25:47 +00001164 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1165 };
David Blaikie085abe32013-03-11 23:21:19 +00001166 DINameSpace R(MDNode::get(VMContext, Elts));
1167 assert(R.Verify() &&
1168 "createNameSpace should return a verifiable DINameSpace");
1169 return R;
Devang Patel746660f2010-12-07 23:25:47 +00001170}
1171
Eric Christopher6647b832011-10-11 22:59:11 +00001172/// createLexicalBlockFile - This creates a new MDNode that encapsulates
1173/// an existing scope with a new filename.
1174DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
Devang Patela93cc252012-02-08 00:17:07 +00001175 DIFile File) {
Eric Christopher6647b832011-10-11 22:59:11 +00001176 Value *Elts[] = {
1177 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie61ef2be2013-03-22 20:18:46 +00001178 File.getFileNode(),
David Blaikie7c8dbc12013-03-22 19:13:22 +00001179 Scope
Eric Christopher6647b832011-10-11 22:59:11 +00001180 };
David Blaikie085abe32013-03-11 23:21:19 +00001181 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1182 assert(
1183 R.Verify() &&
1184 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1185 return R;
Eric Christopher6647b832011-10-11 22:59:11 +00001186}
1187
Devang Patel9b412732011-02-22 18:56:12 +00001188DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
Diego Novillo282450d2014-03-03 18:53:17 +00001189 unsigned Line, unsigned Col,
1190 unsigned Discriminator) {
Adrian Prantl21e8d4a2013-06-24 21:19:43 +00001191 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel89ea4f22010-12-08 01:50:15 +00001192 static unsigned int unique_id = 0;
1193 Value *Elts[] = {
1194 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie30ce0782013-03-22 17:33:20 +00001195 File.getFileNode(),
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001196 getNonCompileUnitScope(Scope),
Devang Patel89ea4f22010-12-08 01:50:15 +00001197 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1198 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
Diego Novillo282450d2014-03-03 18:53:17 +00001199 ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
Devang Patel89ea4f22010-12-08 01:50:15 +00001200 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1201 };
David Blaikie085abe32013-03-11 23:21:19 +00001202 DILexicalBlock R(MDNode::get(VMContext, Elts));
1203 assert(R.Verify() &&
1204 "createLexicalBlock should return a verifiable DILexicalBlock");
1205 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +00001206}
1207
Devang Patel9b412732011-02-22 18:56:12 +00001208/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1209Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patel746660f2010-12-07 23:25:47 +00001210 Instruction *InsertBefore) {
1211 assert(Storage && "no storage passed to dbg.declare");
Manman Ren9822a112013-06-29 05:01:19 +00001212 assert(VarInfo.isVariable() &&
1213 "empty or invalid DIVariable passed to dbg.declare");
Devang Patel746660f2010-12-07 23:25:47 +00001214 if (!DeclareFn)
1215 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1216
Jay Foad5514afe2011-04-21 19:59:31 +00001217 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Jay Foad5bd375a2011-07-15 08:37:34 +00001218 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patel746660f2010-12-07 23:25:47 +00001219}
1220
Devang Patel9b412732011-02-22 18:56:12 +00001221/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1222Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patel746660f2010-12-07 23:25:47 +00001223 BasicBlock *InsertAtEnd) {
1224 assert(Storage && "no storage passed to dbg.declare");
Manman Ren9822a112013-06-29 05:01:19 +00001225 assert(VarInfo.isVariable() &&
1226 "empty or invalid DIVariable passed to dbg.declare");
Devang Patel746660f2010-12-07 23:25:47 +00001227 if (!DeclareFn)
1228 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1229
Jay Foad5514afe2011-04-21 19:59:31 +00001230 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Devang Patel746660f2010-12-07 23:25:47 +00001231
1232 // If this block already has a terminator then insert this intrinsic
1233 // before the terminator.
1234 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foad5bd375a2011-07-15 08:37:34 +00001235 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patel746660f2010-12-07 23:25:47 +00001236 else
Jay Foad5bd375a2011-07-15 08:37:34 +00001237 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patel746660f2010-12-07 23:25:47 +00001238}
1239
Devang Patel9b412732011-02-22 18:56:12 +00001240/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1241Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patel746660f2010-12-07 23:25:47 +00001242 DIVariable VarInfo,
1243 Instruction *InsertBefore) {
1244 assert(V && "no value passed to dbg.value");
Manman Ren9822a112013-06-29 05:01:19 +00001245 assert(VarInfo.isVariable() &&
1246 "empty or invalid DIVariable passed to dbg.value");
Devang Patel746660f2010-12-07 23:25:47 +00001247 if (!ValueFn)
1248 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1249
Jay Foad5514afe2011-04-21 19:59:31 +00001250 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patel746660f2010-12-07 23:25:47 +00001251 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1252 VarInfo };
Jay Foad5bd375a2011-07-15 08:37:34 +00001253 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patel746660f2010-12-07 23:25:47 +00001254}
1255
Devang Patel9b412732011-02-22 18:56:12 +00001256/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1257Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patel746660f2010-12-07 23:25:47 +00001258 DIVariable VarInfo,
1259 BasicBlock *InsertAtEnd) {
1260 assert(V && "no value passed to dbg.value");
Manman Ren9822a112013-06-29 05:01:19 +00001261 assert(VarInfo.isVariable() &&
1262 "empty or invalid DIVariable passed to dbg.value");
Devang Patel746660f2010-12-07 23:25:47 +00001263 if (!ValueFn)
1264 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1265
Jay Foad5514afe2011-04-21 19:59:31 +00001266 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patel746660f2010-12-07 23:25:47 +00001267 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1268 VarInfo };
Jay Foad5bd375a2011-07-15 08:37:34 +00001269 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patel746660f2010-12-07 23:25:47 +00001270}