blob: a5c09b60c4f38437675003ae28947f113d1332e7 [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
Chandler Carruth12664a02014-03-06 00:22:06 +000014#include "llvm/IR/DIBuilder.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/STLExtras.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000016#include "llvm/IR/Constants.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000017#include "llvm/IR/DebugInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#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)
Craig Topperc6207612014-04-09 06:08:46 +000033 : M(m), VMContext(M.getContext()), TempEnumTypes(nullptr),
34 TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(nullptr),
35 DeclareFn(nullptr), ValueFn(nullptr) {}
Devang Patel57c5a202010-11-04 15:01:38 +000036
Devang Patel2b8acaf2011-08-15 23:00:00 +000037/// finalize - Construct any deferred debug info descriptors.
38void DIBuilder::finalize() {
Devang Pateleb1bb4e2011-08-16 22:09:43 +000039 DIArray Enums = getOrCreateArray(AllEnumTypes);
40 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
41
Manman Ren0b410402013-08-29 23:17:54 +000042 SmallVector<Value *, 16> RetainValues;
43 // Declarations and definitions of the same type may be retained. Some
44 // clients RAUW these pairs, leaving duplicates in the retained types
45 // list. Use a set to remove the duplicates while we transform the
46 // TrackingVHs back into Values.
47 SmallPtrSet<Value *, 16> RetainSet;
48 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
49 if (RetainSet.insert(AllRetainTypes[I]))
50 RetainValues.push_back(AllRetainTypes[I]);
51 DIArray RetainTypes = getOrCreateArray(RetainValues);
Devang Pateleb1bb4e2011-08-16 22:09:43 +000052 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
53
54 DIArray SPs = getOrCreateArray(AllSubprograms);
55 DIType(TempSubprograms).replaceAllUsesWith(SPs);
Devang Patel59e27c52011-08-19 23:28:12 +000056 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
57 DISubprogram SP(SPs.getElement(i));
Eric Christopher27deb262012-04-23 19:00:11 +000058 SmallVector<Value *, 4> Variables;
Devang Patel59e27c52011-08-19 23:28:12 +000059 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
Devang Patel59e27c52011-08-19 23:28:12 +000060 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
61 Variables.push_back(NMD->getOperand(ii));
Devang Patel59e27c52011-08-19 23:28:12 +000062 NMD->eraseFromParent();
63 }
Eric Christopher27deb262012-04-23 19:00:11 +000064 if (MDNode *Temp = SP.getVariablesNodes()) {
65 DIArray AV = getOrCreateArray(Variables);
66 DIType(Temp).replaceAllUsesWith(AV);
67 }
Devang Patel59e27c52011-08-19 23:28:12 +000068 }
Devang Pateleb1bb4e2011-08-16 22:09:43 +000069
70 DIArray GVs = getOrCreateArray(AllGVs);
71 DIType(TempGVs).replaceAllUsesWith(GVs);
David Blaikief55abea2013-04-22 06:12:31 +000072
Eric Christopher2c3a6dc2014-02-28 21:27:57 +000073 SmallVector<Value *, 16> RetainValuesI;
74 for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
75 RetainValuesI.push_back(AllImportedModules[I]);
76 DIArray IMs = getOrCreateArray(RetainValuesI);
David Blaikief55abea2013-04-22 06:12:31 +000077 DIType(TempImportedModules).replaceAllUsesWith(IMs);
Devang Pateleb1bb4e2011-08-16 22:09:43 +000078}
79
Eric Christopher3cc90fe2011-08-26 21:02:40 +000080/// getNonCompileUnitScope - If N is compile unit return NULL otherwise return
81/// N.
Devang Pateleb1bb4e2011-08-16 22:09:43 +000082static MDNode *getNonCompileUnitScope(MDNode *N) {
83 if (DIDescriptor(N).isCompileUnit())
Craig Topperc6207612014-04-09 06:08:46 +000084 return nullptr;
Devang Pateleb1bb4e2011-08-16 22:09:43 +000085 return N;
Devang Patel2b8acaf2011-08-15 23:00:00 +000086}
87
David Blaikieefb0d652013-03-20 23:58:12 +000088static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
89 StringRef Directory) {
90 assert(!Filename.empty() && "Unable to create file without name");
91 Value *Pair[] = {
92 MDString::get(VMContext, Filename),
Eric Christopher98f9c232013-10-15 23:31:31 +000093 MDString::get(VMContext, Directory)
David Blaikieefb0d652013-03-20 23:58:12 +000094 };
95 return MDNode::get(VMContext, Pair);
96}
97
Devang Patel9b412732011-02-22 18:56:12 +000098/// createCompileUnit - A CompileUnit provides an anchor for all debugging
Devang Patel57c5a202010-11-04 15:01:38 +000099/// information generated during this instance of compilation.
Eric Christopher03b3e112013-07-19 00:51:47 +0000100DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
101 StringRef Directory,
102 StringRef Producer, bool isOptimized,
103 StringRef Flags, unsigned RunTimeVer,
Eric Christopher75d49db2014-02-27 01:24:56 +0000104 StringRef SplitName,
Diego Novillo56653fd2014-06-24 17:02:03 +0000105 DebugEmissionKind Kind,
106 bool EmitDebugInfo) {
Eric Christopher75d49db2014-02-27 01:24:56 +0000107
Peter Collingbourneb2f70c72014-04-28 18:11:01 +0000108 assert(((Lang <= dwarf::DW_LANG_OCaml && Lang >= dwarf::DW_LANG_C89) ||
Chandler Carruth4c0ee742012-01-10 18:18:52 +0000109 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
110 "Invalid Language tag");
111 assert(!Filename.empty() &&
112 "Unable to create compile unit without filename");
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000113 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
114 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000115
116 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000117
118 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000119
120 TempGVs = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000121
David Blaikief55abea2013-04-22 06:12:31 +0000122 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
123
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000124 Value *Elts[] = {
125 GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
David Blaikieefb0d652013-03-20 23:58:12 +0000126 createFilePathPair(VMContext, Filename, Directory),
David Blaikie3b888522013-03-20 22:52:54 +0000127 ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000128 MDString::get(VMContext, Producer),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000129 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
130 MDString::get(VMContext, Flags),
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000131 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
David Blaikie33111df2013-02-02 05:56:24 +0000132 TempEnumTypes,
133 TempRetainTypes,
134 TempSubprograms,
Eric Christopher0dab3642013-02-22 23:50:04 +0000135 TempGVs,
David Blaikief55abea2013-04-22 06:12:31 +0000136 TempImportedModules,
Eric Christopher75d49db2014-02-27 01:24:56 +0000137 MDString::get(VMContext, SplitName),
138 ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000139 };
Eric Christopher03b3e112013-07-19 00:51:47 +0000140
141 MDNode *CUNode = MDNode::get(VMContext, Elts);
Devang Patel09fa69e2011-05-03 16:18:28 +0000142
143 // Create a named metadata so that it is easier to find cu in a module.
Diego Novillo56653fd2014-06-24 17:02:03 +0000144 // Note that we only generate this when the caller wants to actually
145 // emit debug information. When we are only interested in tracking
146 // source line locations throughout the backend, we prevent codegen from
147 // emitting debug info in the final output by not generating llvm.dbg.cu.
148 if (EmitDebugInfo) {
149 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
150 NMD->addOperand(CUNode);
151 }
Eric Christopher03b3e112013-07-19 00:51:47 +0000152
153 return DICompileUnit(CUNode);
Devang Patel57c5a202010-11-04 15:01:38 +0000154}
155
David Blaikiee63d5d12013-05-20 22:50:35 +0000156static DIImportedEntity
David Blaikie2a40c142014-04-06 06:29:01 +0000157createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
158 Value *NS, unsigned Line, StringRef Name,
159 SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
David Blaikiee63d5d12013-05-20 22:50:35 +0000160 const MDNode *R;
161 if (Name.empty()) {
162 Value *Elts[] = {
David Blaikie2a40c142014-04-06 06:29:01 +0000163 GetTagConstant(C, Tag),
David Blaikiee63d5d12013-05-20 22:50:35 +0000164 Context,
165 NS,
166 ConstantInt::get(Type::getInt32Ty(C), Line),
167 };
168 R = MDNode::get(C, Elts);
169 } else {
170 Value *Elts[] = {
David Blaikie2a40c142014-04-06 06:29:01 +0000171 GetTagConstant(C, Tag),
David Blaikiee63d5d12013-05-20 22:50:35 +0000172 Context,
173 NS,
174 ConstantInt::get(Type::getInt32Ty(C), Line),
175 MDString::get(C, Name)
176 };
177 R = MDNode::get(C, Elts);
178 }
179 DIImportedEntity M(R);
David Blaikie1fd43652013-05-07 21:35:53 +0000180 assert(M.Verify() && "Imported module should be valid");
Eric Christopher2c3a6dc2014-02-28 21:27:57 +0000181 AllImportedModules.push_back(TrackingVH<MDNode>(M));
David Blaikie1fd43652013-05-07 21:35:53 +0000182 return M;
183}
184
David Blaikiee63d5d12013-05-20 22:50:35 +0000185DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
David Blaikie2a40c142014-04-06 06:29:01 +0000186 DINameSpace NS,
187 unsigned Line) {
188 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
189 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000190}
191
192DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
193 DIImportedEntity NS,
David Blaikie2a40c142014-04-06 06:29:01 +0000194 unsigned Line) {
195 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
196 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000197}
198
David Blaikie1fd43652013-05-07 21:35:53 +0000199DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
Adrian Prantld09ba232014-04-01 03:41:04 +0000200 DIScope Decl,
David Blaikie2a40c142014-04-06 06:29:01 +0000201 unsigned Line, StringRef Name) {
202 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
203 Context, Decl.getRef(), Line, Name,
204 AllImportedModules);
205}
206
207DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
208 DIImportedEntity Imp,
209 unsigned Line, StringRef Name) {
210 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
211 Context, Imp, Line, Name, AllImportedModules);
David Blaikief55abea2013-04-22 06:12:31 +0000212}
213
Devang Patel9b412732011-02-22 18:56:12 +0000214/// createFile - Create a file descriptor to hold debugging information
Devang Patel57c5a202010-11-04 15:01:38 +0000215/// for a file.
Devang Patel9b412732011-02-22 18:56:12 +0000216DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
David Blaikie8fb82242013-03-17 21:13:55 +0000217 Value *Elts[] = {
218 GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
David Blaikie5692e722013-03-28 02:44:59 +0000219 createFilePathPair(VMContext, Filename, Directory)
David Blaikie8fb82242013-03-17 21:13:55 +0000220 };
David Blaikie5692e722013-03-28 02:44:59 +0000221 return DIFile(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000222}
223
Devang Patel9b412732011-02-22 18:56:12 +0000224/// createEnumerator - Create a single enumerator value.
David Blaikieb7619002013-06-24 17:34:33 +0000225DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000226 assert(!Name.empty() && "Unable to create enumerator without name");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000227 Value *Elts[] = {
228 GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
229 MDString::get(VMContext, Name),
230 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
231 };
David Blaikie5692e722013-03-28 02:44:59 +0000232 return DIEnumerator(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000233}
234
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000235/// \brief Create a DWARF unspecified type.
236DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel04d6d472011-09-14 23:13:28 +0000237 assert(!Name.empty() && "Unable to create type without name");
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000238 // Unspecified types are encoded in DIBasicType format. Line number, filename,
239 // size, alignment, offset and flags are always empty here.
Devang Patel04d6d472011-09-14 23:13:28 +0000240 Value *Elts[] = {
241 GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
Craig Topperc6207612014-04-09 06:08:46 +0000242 nullptr, // Filename
243 nullptr, // Unused
Devang Patel04d6d472011-09-14 23:13:28 +0000244 MDString::get(VMContext, Name),
Devang Patel04d6d472011-09-14 23:13:28 +0000245 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
246 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
247 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
248 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
249 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
Bill Wendling5ef31592012-07-06 17:49:19 +0000250 ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
Devang Patel04d6d472011-09-14 23:13:28 +0000251 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000252 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel04d6d472011-09-14 23:13:28 +0000253}
254
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000255/// \brief Create C++11 nullptr type.
256DIBasicType DIBuilder::createNullPtrType() {
257 return createUnspecifiedType("decltype(nullptr)");
258}
259
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000260/// createBasicType - Create debugging information entry for a basic
Devang Patel57c5a202010-11-04 15:01:38 +0000261/// type, e.g 'char'.
David Blaikie209d63a2013-02-12 00:40:41 +0000262DIBasicType
263DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
264 uint64_t AlignInBits, unsigned Encoding) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000265 assert(!Name.empty() && "Unable to create type without name");
Devang Patel57c5a202010-11-04 15:01:38 +0000266 // Basic types are encoded in DIBasicType format. Line number, filename,
267 // offset and flags are always empty here.
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000268 Value *Elts[] = {
269 GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
Craig Topperc6207612014-04-09 06:08:46 +0000270 nullptr, // File/directory name
271 nullptr, // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000272 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000273 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
274 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
275 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
276 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
277 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
278 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
279 };
David Blaikie5692e722013-03-28 02:44:59 +0000280 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000281}
282
Nick Lewycky47eebcf2011-11-09 22:45:04 +0000283/// createQualifiedType - Create debugging information entry for a qualified
Devang Patel57c5a202010-11-04 15:01:38 +0000284/// type, e.g. 'const int'.
David Blaikief11de2f2013-02-18 06:41:57 +0000285DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000286 // Qualified types are encoded in DIDerivedType format.
287 Value *Elts[] = {
288 GetTagConstant(VMContext, Tag),
Craig Topperc6207612014-04-09 06:08:46 +0000289 nullptr, // Filename
290 nullptr, // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000291 MDString::get(VMContext, StringRef()), // Empty name.
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000292 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
293 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
294 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
295 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
296 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000297 FromTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000298 };
David Blaikie5692e722013-03-28 02:44:59 +0000299 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000300}
301
Devang Patel9b412732011-02-22 18:56:12 +0000302/// createPointerType - Create debugging information entry for a pointer.
David Blaikief11de2f2013-02-18 06:41:57 +0000303DIDerivedType
304DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
305 uint64_t AlignInBits, StringRef Name) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000306 // Pointer types are encoded in DIDerivedType format.
307 Value *Elts[] = {
308 GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
Craig Topperc6207612014-04-09 06:08:46 +0000309 nullptr, // Filename
310 nullptr, // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000311 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000312 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
313 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
314 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
315 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
316 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renb3388602013-10-05 01:43:03 +0000317 PointeeTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000318 };
David Blaikie5692e722013-03-28 02:44:59 +0000319 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000320}
321
Eric Christopher89e594d2013-04-19 20:37:12 +0000322DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
323 DIType Base) {
David Blaikie5d3249b2013-01-07 05:51:15 +0000324 // Pointer types are encoded in DIDerivedType format.
325 Value *Elts[] = {
326 GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
Craig Topperc6207612014-04-09 06:08:46 +0000327 nullptr, // Filename
328 nullptr, // Unused
329 nullptr,
David Blaikie5d3249b2013-01-07 05:51:15 +0000330 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Eric Christopher98f9c232013-10-15 23:31:31 +0000331 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
332 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
David Blaikie5d3249b2013-01-07 05:51:15 +0000333 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
334 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000335 PointeeTy.getRef(),
Manman Renaad5c3b2013-09-30 19:42:10 +0000336 Base.getRef()
David Blaikie5d3249b2013-01-07 05:51:15 +0000337 };
David Blaikie5692e722013-03-28 02:44:59 +0000338 return DIDerivedType(MDNode::get(VMContext, Elts));
David Blaikie5d3249b2013-01-07 05:51:15 +0000339}
340
Eric Christopherb5cf66c2012-05-19 01:36:37 +0000341/// createReferenceType - Create debugging information entry for a reference
342/// type.
David Blaikief11de2f2013-02-18 06:41:57 +0000343DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
Manman Ren74c188f2013-07-01 21:02:01 +0000344 assert(RTy.isType() && "Unable to create reference type");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000345 // References are encoded in DIDerivedType format.
346 Value *Elts[] = {
Eric Christopherb5cf66c2012-05-19 01:36:37 +0000347 GetTagConstant(VMContext, Tag),
Craig Topperc6207612014-04-09 06:08:46 +0000348 nullptr, // Filename
349 nullptr, // TheCU,
350 nullptr, // Name
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000351 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
352 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
353 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
354 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
355 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000356 RTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000357 };
David Blaikie5692e722013-03-28 02:44:59 +0000358 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000359}
360
Devang Patel9b412732011-02-22 18:56:12 +0000361/// createTypedef - Create debugging information entry for a typedef.
David Blaikief11de2f2013-02-18 06:41:57 +0000362DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
363 unsigned LineNo, DIDescriptor Context) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000364 // typedefs are encoded in DIDerivedType format.
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000365 Value *Elts[] = {
366 GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
David Blaikie200b6ed2013-03-20 00:26:26 +0000367 File.getFileNode(),
Manman Ren5f99ec02013-10-08 23:49:38 +0000368 DIScope(getNonCompileUnitScope(Context)).getRef(),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000369 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000370 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
371 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
372 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
373 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
374 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000375 Ty.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000376 };
David Blaikie5692e722013-03-28 02:44:59 +0000377 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000378}
379
Devang Patel9b412732011-02-22 18:56:12 +0000380/// createFriend - Create debugging information entry for a 'friend'.
Manman Ren3c6acec2013-06-07 18:35:53 +0000381DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000382 // typedefs are encoded in DIDerivedType format.
Manman Ren74c188f2013-07-01 21:02:01 +0000383 assert(Ty.isType() && "Invalid type!");
384 assert(FriendTy.isType() && "Invalid friend type!");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000385 Value *Elts[] = {
386 GetTagConstant(VMContext, dwarf::DW_TAG_friend),
Craig Topperc6207612014-04-09 06:08:46 +0000387 nullptr,
Manman Renaad5c3b2013-09-30 19:42:10 +0000388 Ty.getRef(),
Craig Topperc6207612014-04-09 06:08:46 +0000389 nullptr, // Name
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000390 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
391 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
392 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
393 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
394 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renf69bd752013-10-08 22:56:31 +0000395 FriendTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000396 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000397 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000398}
399
Devang Patel9b412732011-02-22 18:56:12 +0000400/// createInheritance - Create debugging information entry to establish
Eric Christopher777c9282011-09-12 19:58:22 +0000401/// inheritance relationship between two types.
Eric Christopher98f9c232013-10-15 23:31:31 +0000402DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
403 uint64_t BaseOffset,
404 unsigned Flags) {
Manman Ren74c188f2013-07-01 21:02:01 +0000405 assert(Ty.isType() && "Unable to create inheritance");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000406 // TAG_inheritance is encoded in DIDerivedType format.
407 Value *Elts[] = {
408 GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
Craig Topperc6207612014-04-09 06:08:46 +0000409 nullptr,
Manman Renaad5c3b2013-09-30 19:42:10 +0000410 Ty.getRef(),
Craig Topperc6207612014-04-09 06:08:46 +0000411 nullptr, // Name
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000412 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
413 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
414 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
415 ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
416 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renf69bd752013-10-08 22:56:31 +0000417 BaseTy.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000418 };
David Blaikie5692e722013-03-28 02:44:59 +0000419 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000420}
421
Devang Patel9b412732011-02-22 18:56:12 +0000422/// createMemberType - Create debugging information entry for a member.
Eric Christopher98f9c232013-10-15 23:31:31 +0000423DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
424 DIFile File, unsigned LineNumber,
425 uint64_t SizeInBits,
426 uint64_t AlignInBits,
427 uint64_t OffsetInBits, unsigned Flags,
428 DIType Ty) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000429 // TAG_member is encoded in DIDerivedType format.
430 Value *Elts[] = {
431 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000432 File.getFileNode(),
Manman Renaad5c3b2013-09-30 19:42:10 +0000433 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000434 MDString::get(VMContext, Name),
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000435 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
436 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
437 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
438 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
439 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renf69bd752013-10-08 22:56:31 +0000440 Ty.getRef()
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000441 };
David Blaikie5692e722013-03-28 02:44:59 +0000442 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000443}
444
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000445/// createStaticMemberType - Create debugging information entry for a
446/// C++ static data member.
Manman Ren3c6acec2013-06-07 18:35:53 +0000447DIDerivedType
448DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
449 DIFile File, unsigned LineNumber,
450 DIType Ty, unsigned Flags,
451 llvm::Value *Val) {
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000452 // TAG_member is encoded in DIDerivedType format.
453 Flags |= DIDescriptor::FlagStaticMember;
454 Value *Elts[] = {
455 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000456 File.getFileNode(),
Manman Ren5f99ec02013-10-08 23:49:38 +0000457 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000458 MDString::get(VMContext, Name),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000459 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Eric Christopher98f9c232013-10-15 23:31:31 +0000460 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
461 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
462 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000463 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renf69bd752013-10-08 22:56:31 +0000464 Ty.getRef(),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000465 Val
466 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000467 return DIDerivedType(MDNode::get(VMContext, Elts));
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000468}
469
Devang Patel514b4002011-04-16 00:11:51 +0000470/// createObjCIVar - Create debugging information entry for Objective-C
471/// instance variable.
Eric Christopher98f9c232013-10-15 23:31:31 +0000472DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
473 unsigned LineNumber,
474 uint64_t SizeInBits,
475 uint64_t AlignInBits,
476 uint64_t OffsetInBits, unsigned Flags,
477 DIType Ty, MDNode *PropertyNode) {
Devang Patel44882172012-02-06 17:49:43 +0000478 // TAG_member is encoded in DIDerivedType format.
479 Value *Elts[] = {
480 GetTagConstant(VMContext, dwarf::DW_TAG_member),
David Blaikie200b6ed2013-03-20 00:26:26 +0000481 File.getFileNode(),
Devang Patel44882172012-02-06 17:49:43 +0000482 getNonCompileUnitScope(File),
483 MDString::get(VMContext, Name),
Devang Patel44882172012-02-06 17:49:43 +0000484 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
485 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
486 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
487 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
488 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
489 Ty,
490 PropertyNode
491 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000492 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel44882172012-02-06 17:49:43 +0000493}
494
Devang Patelcc481592012-02-04 00:59:25 +0000495/// createObjCProperty - Create debugging information entry for Objective-C
496/// property.
Eric Christopher98f9c232013-10-15 23:31:31 +0000497DIObjCProperty
498DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
499 StringRef GetterName, StringRef SetterName,
500 unsigned PropertyAttributes, DIType Ty) {
Devang Patelcc481592012-02-04 00:59:25 +0000501 Value *Elts[] = {
Eric Christopherc13fd6d2012-03-29 21:35:05 +0000502 GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
Devang Patelcc481592012-02-04 00:59:25 +0000503 MDString::get(VMContext, Name),
Eric Christopher70e1bd82012-03-29 08:42:56 +0000504 File,
505 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
Devang Patelcc481592012-02-04 00:59:25 +0000506 MDString::get(VMContext, GetterName),
507 MDString::get(VMContext, SetterName),
Eric Christopher70e1bd82012-03-29 08:42:56 +0000508 ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
509 Ty
Devang Patelcc481592012-02-04 00:59:25 +0000510 };
David Blaikie5692e722013-03-28 02:44:59 +0000511 return DIObjCProperty(MDNode::get(VMContext, Elts));
Devang Patelcc481592012-02-04 00:59:25 +0000512}
513
Devang Patel9b412732011-02-22 18:56:12 +0000514/// createTemplateTypeParameter - Create debugging information for template
Devang Patel3a9e65e2011-02-02 21:38:25 +0000515/// type parameter.
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000516DITemplateTypeParameter
Devang Patel9b412732011-02-22 18:56:12 +0000517DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
Devang Patel3a9e65e2011-02-02 21:38:25 +0000518 DIType Ty, MDNode *File, unsigned LineNo,
519 unsigned ColumnNo) {
520 Value *Elts[] = {
521 GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
Manman Ren88b0f942013-10-09 19:46:28 +0000522 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel3a9e65e2011-02-02 21:38:25 +0000523 MDString::get(VMContext, Name),
Manman Ren88b0f942013-10-09 19:46:28 +0000524 Ty.getRef(),
Devang Patel3a9e65e2011-02-02 21:38:25 +0000525 File,
526 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
527 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
528 };
David Blaikie5692e722013-03-28 02:44:59 +0000529 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
Devang Patel3a9e65e2011-02-02 21:38:25 +0000530}
531
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000532DITemplateValueParameter
David Blaikie2b380232013-06-22 18:59:11 +0000533DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
534 StringRef Name, DIType Ty,
535 Value *Val, MDNode *File,
536 unsigned LineNo,
Devang Patelbe933b42011-02-02 22:35:53 +0000537 unsigned ColumnNo) {
538 Value *Elts[] = {
David Blaikie2b380232013-06-22 18:59:11 +0000539 GetTagConstant(VMContext, Tag),
Manman Ren88b0f942013-10-09 19:46:28 +0000540 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patelbe933b42011-02-02 22:35:53 +0000541 MDString::get(VMContext, Name),
Manman Ren88b0f942013-10-09 19:46:28 +0000542 Ty.getRef(),
David Blaikiea1e813d2013-05-10 21:52:07 +0000543 Val,
Devang Patelbe933b42011-02-02 22:35:53 +0000544 File,
545 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
546 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
547 };
David Blaikie5692e722013-03-28 02:44:59 +0000548 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
Devang Patelbe933b42011-02-02 22:35:53 +0000549}
550
David Blaikie2b380232013-06-22 18:59:11 +0000551/// createTemplateValueParameter - Create debugging information for template
552/// value parameter.
553DITemplateValueParameter
554DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
555 DIType Ty, Value *Val,
556 MDNode *File, unsigned LineNo,
557 unsigned ColumnNo) {
558 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
559 Context, Name, Ty, Val, File, LineNo,
560 ColumnNo);
561}
562
563DITemplateValueParameter
564DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
565 DIType Ty, StringRef Val,
566 MDNode *File, unsigned LineNo,
567 unsigned ColumnNo) {
568 return createTemplateValueParameter(
569 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
570 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
571}
572
573DITemplateValueParameter
574DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
575 DIType Ty, DIArray Val,
576 MDNode *File, unsigned LineNo,
577 unsigned ColumnNo) {
578 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
579 Context, Name, Ty, Val, File, LineNo,
580 ColumnNo);
581}
582
Eric Christopher17426692012-07-06 02:35:57 +0000583/// createClassType - Create debugging information entry for a class.
David Blaikiea7310a32013-03-26 23:46:39 +0000584DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
585 DIFile File, unsigned LineNumber,
586 uint64_t SizeInBits,
587 uint64_t AlignInBits,
588 uint64_t OffsetInBits,
589 unsigned Flags, DIType DerivedFrom,
590 DIArray Elements,
Manman Ren27552062013-09-06 23:54:23 +0000591 DIType VTableHolder,
Manman Ren547467b2013-08-27 23:06:40 +0000592 MDNode *TemplateParams,
593 StringRef UniqueIdentifier) {
Manman Ren74c188f2013-07-01 21:02:01 +0000594 assert((!Context || Context.isScope() || Context.isType()) &&
David Blaikie085abe32013-03-11 23:21:19 +0000595 "createClassType should be called with a valid Context");
596 // TAG_class_type is encoded in DICompositeType format.
Eric Christopher17426692012-07-06 02:35:57 +0000597 Value *Elts[] = {
598 GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000599 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000600 DIScope(getNonCompileUnitScope(Context)).getRef(),
Eric Christopher17426692012-07-06 02:35:57 +0000601 MDString::get(VMContext, Name),
Eric Christopher17426692012-07-06 02:35:57 +0000602 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
603 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
604 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
605 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
606 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renbacd1ef2013-10-08 23:28:51 +0000607 DerivedFrom.getRef(),
Eric Christopher17426692012-07-06 02:35:57 +0000608 Elements,
609 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Manman Renaad5c3b2013-09-30 19:42:10 +0000610 VTableHolder.getRef(),
Manman Ren0ed70ae2013-08-26 22:39:55 +0000611 TemplateParams,
Craig Topperc6207612014-04-09 06:08:46 +0000612 UniqueIdentifier.empty() ? nullptr
613 : MDString::get(VMContext, UniqueIdentifier)
Eric Christopher17426692012-07-06 02:35:57 +0000614 };
David Blaikiea7310a32013-03-26 23:46:39 +0000615 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren74c188f2013-07-01 21:02:01 +0000616 assert(R.isCompositeType() &&
617 "createClassType should return a DICompositeType");
Manman Ren0b410402013-08-29 23:17:54 +0000618 if (!UniqueIdentifier.empty())
619 retainType(R);
David Blaikie085abe32013-03-11 23:21:19 +0000620 return R;
Eric Christopher17426692012-07-06 02:35:57 +0000621}
622
Devang Patel9b412732011-02-22 18:56:12 +0000623/// createStructType - Create debugging information entry for a struct.
David Blaikiebbe0e1a2013-02-25 01:07:18 +0000624DICompositeType DIBuilder::createStructType(DIDescriptor Context,
625 StringRef Name, DIFile File,
626 unsigned LineNumber,
627 uint64_t SizeInBits,
628 uint64_t AlignInBits,
629 unsigned Flags, DIType DerivedFrom,
630 DIArray Elements,
631 unsigned RunTimeLang,
Manman Ren27552062013-09-06 23:54:23 +0000632 DIType VTableHolder,
Manman Ren547467b2013-08-27 23:06:40 +0000633 StringRef UniqueIdentifier) {
Devang Patel746660f2010-12-07 23:25:47 +0000634 // TAG_structure_type is encoded in DICompositeType format.
635 Value *Elts[] = {
636 GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000637 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000638 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patel746660f2010-12-07 23:25:47 +0000639 MDString::get(VMContext, Name),
Devang Patel746660f2010-12-07 23:25:47 +0000640 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
641 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
642 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Devang Patel89ea4f22010-12-08 01:50:15 +0000643 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Devang Patel746660f2010-12-07 23:25:47 +0000644 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Manman Renbacd1ef2013-10-08 23:28:51 +0000645 DerivedFrom.getRef(),
Devang Patel746660f2010-12-07 23:25:47 +0000646 Elements,
647 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Manman Renaad5c3b2013-09-30 19:42:10 +0000648 VTableHolder.getRef(),
Craig Topperc6207612014-04-09 06:08:46 +0000649 nullptr,
650 UniqueIdentifier.empty() ? nullptr
651 : MDString::get(VMContext, UniqueIdentifier)
Devang Patel746660f2010-12-07 23:25:47 +0000652 };
David Blaikie085abe32013-03-11 23:21:19 +0000653 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren74c188f2013-07-01 21:02:01 +0000654 assert(R.isCompositeType() &&
655 "createStructType should return a DICompositeType");
Manman Ren0b410402013-08-29 23:17:54 +0000656 if (!UniqueIdentifier.empty())
657 retainType(R);
David Blaikie085abe32013-03-11 23:21:19 +0000658 return R;
Devang Patel746660f2010-12-07 23:25:47 +0000659}
660
Devang Patel9b412732011-02-22 18:56:12 +0000661/// createUnionType - Create debugging information entry for an union.
Eric Christopher17dd8f02013-04-02 22:55:52 +0000662DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
663 DIFile File, unsigned LineNumber,
664 uint64_t SizeInBits,
665 uint64_t AlignInBits, unsigned Flags,
666 DIArray Elements,
Manman Ren547467b2013-08-27 23:06:40 +0000667 unsigned RunTimeLang,
668 StringRef UniqueIdentifier) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000669 // TAG_union_type is encoded in DICompositeType format.
670 Value *Elts[] = {
671 GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000672 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000673 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000674 MDString::get(VMContext, Name),
Devang Patel89ea4f22010-12-08 01:50:15 +0000675 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
676 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
677 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000678 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Devang Patel89ea4f22010-12-08 01:50:15 +0000679 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Craig Topperc6207612014-04-09 06:08:46 +0000680 nullptr,
Devang Patel89ea4f22010-12-08 01:50:15 +0000681 Elements,
682 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
Craig Topperc6207612014-04-09 06:08:46 +0000683 nullptr,
684 nullptr,
685 UniqueIdentifier.empty() ? nullptr
686 : MDString::get(VMContext, UniqueIdentifier)
Devang Patel89ea4f22010-12-08 01:50:15 +0000687 };
Manman Ren0b410402013-08-29 23:17:54 +0000688 DICompositeType R(MDNode::get(VMContext, Elts));
689 if (!UniqueIdentifier.empty())
690 retainType(R);
691 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000692}
693
Devang Patel9b412732011-02-22 18:56:12 +0000694/// createSubroutineType - Create subroutine type.
Manman Renf8a19672014-07-28 22:24:06 +0000695DISubroutineType DIBuilder::createSubroutineType(DIFile File,
696 DITypeArray ParameterTypes,
697 unsigned Flags) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000698 // TAG_subroutine_type is encoded in DICompositeType format.
699 Value *Elts[] = {
700 GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
Bill Wendling7154c432012-07-06 17:47:36 +0000701 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Craig Topperc6207612014-04-09 06:08:46 +0000702 nullptr,
David Blaikieabec74b2013-03-19 23:25:22 +0000703 MDString::get(VMContext, ""),
Eric Christopher98f9c232013-10-15 23:31:31 +0000704 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
705 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
706 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
707 ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
Adrian Prantl99c7af22013-12-18 21:48:19 +0000708 ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
Craig Topperc6207612014-04-09 06:08:46 +0000709 nullptr,
Devang Patel89ea4f22010-12-08 01:50:15 +0000710 ParameterTypes,
711 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Craig Topperc6207612014-04-09 06:08:46 +0000712 nullptr,
713 nullptr,
714 nullptr // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000715 };
Manman Renf8a19672014-07-28 22:24:06 +0000716 return DISubroutineType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000717}
718
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000719/// createEnumerationType - Create debugging information entry for an
Devang Patel89ea4f22010-12-08 01:50:15 +0000720/// enumeration.
David Blaikief11de2f2013-02-18 06:41:57 +0000721DICompositeType DIBuilder::createEnumerationType(
722 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
723 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Manman Ren547467b2013-08-27 23:06:40 +0000724 DIType UnderlyingType, StringRef UniqueIdentifier) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000725 // TAG_enumeration_type is encoded in DICompositeType format.
726 Value *Elts[] = {
727 GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
David Blaikie200b6ed2013-03-20 00:26:26 +0000728 File.getFileNode(),
Manman Renea57f672013-10-09 00:17:04 +0000729 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000730 MDString::get(VMContext, Name),
Devang Patel89ea4f22010-12-08 01:50:15 +0000731 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
732 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
733 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000734 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
735 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renbacd1ef2013-10-08 23:28:51 +0000736 UnderlyingType.getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000737 Elements,
738 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Craig Topperc6207612014-04-09 06:08:46 +0000739 nullptr,
740 nullptr,
741 UniqueIdentifier.empty() ? nullptr
742 : MDString::get(VMContext, UniqueIdentifier)
Devang Patel89ea4f22010-12-08 01:50:15 +0000743 };
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000744 DICompositeType CTy(MDNode::get(VMContext, Elts));
745 AllEnumTypes.push_back(CTy);
Manman Ren0b410402013-08-29 23:17:54 +0000746 if (!UniqueIdentifier.empty())
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000747 retainType(CTy);
748 return CTy;
Devang Patel89ea4f22010-12-08 01:50:15 +0000749}
750
Devang Patel9b412732011-02-22 18:56:12 +0000751/// createArrayType - Create debugging information entry for an array.
David Blaikief11de2f2013-02-18 06:41:57 +0000752DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
753 DIType Ty, DIArray Subscripts) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000754 // TAG_array_type is encoded in DICompositeType format.
755 Value *Elts[] = {
756 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
Craig Topperc6207612014-04-09 06:08:46 +0000757 nullptr, // Filename/Directory,
758 nullptr, // Unused
Devang Patel89ea4f22010-12-08 01:50:15 +0000759 MDString::get(VMContext, ""),
Eric Christopher98f9c232013-10-15 23:31:31 +0000760 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Devang Patel89ea4f22010-12-08 01:50:15 +0000761 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
762 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000763 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
764 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
Manman Renbacd1ef2013-10-08 23:28:51 +0000765 Ty.getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000766 Subscripts,
767 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Craig Topperc6207612014-04-09 06:08:46 +0000768 nullptr,
769 nullptr,
770 nullptr // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000771 };
David Blaikie5692e722013-03-28 02:44:59 +0000772 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000773}
774
Devang Patel9b412732011-02-22 18:56:12 +0000775/// createVectorType - Create debugging information entry for a vector.
Manman Ren60711602013-06-07 03:13:46 +0000776DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
777 DIType Ty, DIArray Subscripts) {
Eric Christopher72a52952013-01-08 01:53:52 +0000778 // A vector is an array type with the FlagVector flag applied.
Devang Patel89ea4f22010-12-08 01:50:15 +0000779 Value *Elts[] = {
Eric Christopher72a52952013-01-08 01:53:52 +0000780 GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
Craig Topperc6207612014-04-09 06:08:46 +0000781 nullptr, // Filename/Directory,
782 nullptr, // Unused
Devang Patel89ea4f22010-12-08 01:50:15 +0000783 MDString::get(VMContext, ""),
Eric Christopher98f9c232013-10-15 23:31:31 +0000784 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
Devang Patel89ea4f22010-12-08 01:50:15 +0000785 ConstantInt::get(Type::getInt64Ty(VMContext), Size),
786 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000787 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
Eric Christopher72a52952013-01-08 01:53:52 +0000788 ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
Manman Renbacd1ef2013-10-08 23:28:51 +0000789 Ty.getRef(),
Devang Patel89ea4f22010-12-08 01:50:15 +0000790 Subscripts,
791 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Craig Topperc6207612014-04-09 06:08:46 +0000792 nullptr,
793 nullptr,
794 nullptr // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000795 };
Manman Ren60711602013-06-07 03:13:46 +0000796 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000797}
Devang Patel746660f2010-12-07 23:25:47 +0000798
Devang Patel9b412732011-02-22 18:56:12 +0000799/// createArtificialType - Create a new DIType with "artificial" flag set.
800DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel57c5a202010-11-04 15:01:38 +0000801 if (Ty.isArtificial())
802 return Ty;
803
804 SmallVector<Value *, 9> Elts;
805 MDNode *N = Ty;
806 assert (N && "Unexpected input DIType!");
Manman Ren8ddddad2013-09-08 06:00:42 +0000807 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
808 Elts.push_back(N->getOperand(i));
Devang Patel57c5a202010-11-04 15:01:38 +0000809
810 unsigned CurFlags = Ty.getFlags();
811 CurFlags = CurFlags | DIType::FlagArtificial;
812
813 // Flags are stored at this slot.
Eric Christopher98f9c232013-10-15 23:31:31 +0000814 // FIXME: Add an enum for this magic value.
David Blaikie5692e722013-03-28 02:44:59 +0000815 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Devang Patel57c5a202010-11-04 15:01:38 +0000816
David Blaikie5692e722013-03-28 02:44:59 +0000817 return DIType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000818}
Devang Patel746660f2010-12-07 23:25:47 +0000819
Eric Christopher9bd36092013-01-08 01:53:42 +0000820/// createObjectPointerType - Create a new type with both the object pointer
821/// and artificial flags set.
Eric Christophere3417762012-09-12 23:36:19 +0000822DIType DIBuilder::createObjectPointerType(DIType Ty) {
823 if (Ty.isObjectPointer())
824 return Ty;
825
826 SmallVector<Value *, 9> Elts;
827 MDNode *N = Ty;
828 assert (N && "Unexpected input DIType!");
Manman Ren8ddddad2013-09-08 06:00:42 +0000829 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
830 Elts.push_back(N->getOperand(i));
Eric Christophere3417762012-09-12 23:36:19 +0000831
832 unsigned CurFlags = Ty.getFlags();
833 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
834
835 // Flags are stored at this slot.
Eric Christopher98f9c232013-10-15 23:31:31 +0000836 // FIXME: Add an enum for this magic value.
David Blaikie5692e722013-03-28 02:44:59 +0000837 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
Eric Christophere3417762012-09-12 23:36:19 +0000838
David Blaikie5692e722013-03-28 02:44:59 +0000839 return DIType(MDNode::get(VMContext, Elts));
Eric Christophere3417762012-09-12 23:36:19 +0000840}
841
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000842/// retainType - Retain DIType in a module even if it is not referenced
Devang Patel89ea4f22010-12-08 01:50:15 +0000843/// through debug info anchors.
Devang Patel9b412732011-02-22 18:56:12 +0000844void DIBuilder::retainType(DIType T) {
Manman Ren0b410402013-08-29 23:17:54 +0000845 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
Devang Patel89ea4f22010-12-08 01:50:15 +0000846}
847
Devang Patel9b412732011-02-22 18:56:12 +0000848/// createUnspecifiedParameter - Create unspeicified type descriptor
Devang Patel89ea4f22010-12-08 01:50:15 +0000849/// for the subroutine type.
Manman Renf93ac4b2014-07-29 18:20:39 +0000850DIBasicType DIBuilder::createUnspecifiedParameter() {
Manman Ren72b07e82014-07-29 22:58:13 +0000851 return DIBasicType();
Devang Patel89ea4f22010-12-08 01:50:15 +0000852}
853
Frederic Rissa8734142014-09-10 16:03:14 +0000854/// createForwardDecl - Create a permanent forward-declared type.
Eric Christopher98f9c232013-10-15 23:31:31 +0000855DICompositeType
856DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
857 DIFile F, unsigned Line, unsigned RuntimeLang,
858 uint64_t SizeInBits, uint64_t AlignInBits,
859 StringRef UniqueIdentifier) {
Eric Christopherae56eec2012-02-08 00:22:26 +0000860 // Create a temporary MDNode.
861 Value *Elts[] = {
862 GetTagConstant(VMContext, Tag),
David Blaikie200b6ed2013-03-20 00:26:26 +0000863 F.getFileNode(),
Manman Renb3dc3af2013-10-09 18:10:55 +0000864 DIScope(getNonCompileUnitScope(Scope)).getRef(),
Eric Christopherae56eec2012-02-08 00:22:26 +0000865 MDString::get(VMContext, Name),
Eric Christopherae56eec2012-02-08 00:22:26 +0000866 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
Eli Friedmanc6c86c42012-10-05 01:49:14 +0000867 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
868 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
Eric Christopher98f9c232013-10-15 23:31:31 +0000869 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
870 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
Craig Topperc6207612014-04-09 06:08:46 +0000871 nullptr,
Eric Christopher89797122012-02-20 18:04:14 +0000872 DIArray(),
David Blaikied4e106e2013-08-16 20:42:14 +0000873 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
Craig Topperc6207612014-04-09 06:08:46 +0000874 nullptr,
875 nullptr, //TemplateParams
876 UniqueIdentifier.empty() ? nullptr
877 : MDString::get(VMContext, UniqueIdentifier)
Eric Christopherae56eec2012-02-08 00:22:26 +0000878 };
David Blaikied3f094a2014-05-06 03:41:57 +0000879 MDNode *Node = MDNode::get(VMContext, Elts);
880 DICompositeType RetTy(Node);
881 assert(RetTy.isCompositeType() &&
882 "createForwardDecl result should be a DIType");
883 if (!UniqueIdentifier.empty())
884 retainType(RetTy);
885 return RetTy;
886}
887
Frederic Rissa8734142014-09-10 16:03:14 +0000888/// createReplaceableForwardDecl - Create a temporary forward-declared type that
David Blaikied3f094a2014-05-06 03:41:57 +0000889/// can be RAUW'd if the full type is seen.
890DICompositeType DIBuilder::createReplaceableForwardDecl(
891 unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line,
892 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
893 StringRef UniqueIdentifier) {
894 // Create a temporary MDNode.
895 Value *Elts[] = {
896 GetTagConstant(VMContext, Tag),
897 F.getFileNode(),
898 DIScope(getNonCompileUnitScope(Scope)).getRef(),
899 MDString::get(VMContext, Name),
900 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
901 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
902 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
903 ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
904 ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
905 nullptr,
906 DIArray(),
907 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
908 nullptr,
909 nullptr, //TemplateParams
910 UniqueIdentifier.empty() ? nullptr
911 : MDString::get(VMContext, UniqueIdentifier)
912 };
Eric Christopherae56eec2012-02-08 00:22:26 +0000913 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
David Blaikied4e106e2013-08-16 20:42:14 +0000914 DICompositeType RetTy(Node);
915 assert(RetTy.isCompositeType() &&
Frederic Rissa8734142014-09-10 16:03:14 +0000916 "createReplaceableForwardDecl result should be a DIType");
Manman Ren0b410402013-08-29 23:17:54 +0000917 if (!UniqueIdentifier.empty())
918 retainType(RetTy);
Manman Rend0e67aa2013-07-02 18:37:35 +0000919 return RetTy;
Eric Christopherae56eec2012-02-08 00:22:26 +0000920}
921
Devang Patel9b412732011-02-22 18:56:12 +0000922/// getOrCreateArray - Get a DIArray, create one if required.
Jay Foaddbf81d82011-04-24 10:11:03 +0000923DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
Jay Foaddbf81d82011-04-24 10:11:03 +0000924 return DIArray(MDNode::get(VMContext, Elements));
Devang Patel746660f2010-12-07 23:25:47 +0000925}
926
Manman Ren1a125c92014-07-28 19:33:20 +0000927/// getOrCreateTypeArray - Get a DITypeArray, create one if required.
928DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Value *> Elements) {
929 SmallVector<llvm::Value *, 16> Elts;
930 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
931 if (Elements[i] && isa<MDNode>(Elements[i]))
932 Elts.push_back(DIType(cast<MDNode>(Elements[i])).getRef());
933 else
934 Elts.push_back(Elements[i]);
935 }
936 return DITypeArray(MDNode::get(VMContext, Elts));
937}
938
Devang Patel9b412732011-02-22 18:56:12 +0000939/// getOrCreateSubrange - Create a descriptor for a value range. This
Devang Patel89ea4f22010-12-08 01:50:15 +0000940/// implicitly uniques the values returned.
Bill Wendlingd7767122012-12-04 21:34:03 +0000941DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000942 Value *Elts[] = {
943 GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
944 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
Bill Wendlingbfc0e572012-12-04 06:20:49 +0000945 ConstantInt::get(Type::getInt64Ty(VMContext), Count)
Devang Patel89ea4f22010-12-08 01:50:15 +0000946 };
947
Devang Patel0c773242011-04-18 23:51:03 +0000948 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000949}
950
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000951static DIGlobalVariable
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000952createGlobalVariableHelper(LLVMContext &VMContext, DIDescriptor Context,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000953 StringRef Name, StringRef LinkageName, DIFile F,
954 unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit,
955 Value *Val, MDNode *Decl, bool isDefinition,
956 std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
Devang Patel746660f2010-12-07 23:25:47 +0000957 Value *Elts[] = {
958 GetTagConstant(VMContext, dwarf::DW_TAG_variable),
Bill Wendling7154c432012-07-06 17:47:36 +0000959 Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000960 getNonCompileUnitScope(Context),
Devang Patel746660f2010-12-07 23:25:47 +0000961 MDString::get(VMContext, Name),
962 MDString::get(VMContext, Name),
963 MDString::get(VMContext, LinkageName),
964 F,
965 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
966 Ty,
967 ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000968 ConstantInt::get(Type::getInt32Ty(VMContext), isDefinition),
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000969 Val,
970 DIDescriptor(Decl)
Devang Patel746660f2010-12-07 23:25:47 +0000971 };
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000972
973 return DIGlobalVariable(CreateFunc(Elts));
974}
975
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000976/// createGlobalVariable - Create a new descriptor for the specified
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000977/// variable.
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000978DIGlobalVariable DIBuilder::createGlobalVariable(DIDescriptor Context,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000979 StringRef Name,
980 StringRef LinkageName,
981 DIFile F, unsigned LineNumber,
982 DITypeRef Ty,
983 bool isLocalToUnit,
984 Value *Val, MDNode *Decl) {
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000985 return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000986 LineNumber, Ty, isLocalToUnit, Val, Decl, true,
987 [&] (ArrayRef<Value *> Elts) -> MDNode * {
988 MDNode *Node = MDNode::get(VMContext, Elts);
989 AllGVs.push_back(Node);
990 return Node;
991 });
992}
993
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000994/// createTempGlobalVariableFwdDecl - Create a new temporary descriptor for the
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000995/// specified variable declarartion.
996DIGlobalVariable
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000997DIBuilder::createTempGlobalVariableFwdDecl(DIDescriptor Context,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000998 StringRef Name,
999 StringRef LinkageName,
1000 DIFile F, unsigned LineNumber,
1001 DITypeRef Ty,
1002 bool isLocalToUnit,
1003 Value *Val, MDNode *Decl) {
Jyoti Allurb76b57f2014-09-29 06:32:54 +00001004 return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +00001005 LineNumber, Ty, isLocalToUnit, Val, Decl, false,
1006 [&] (ArrayRef<Value *> Elts) {
1007 return MDNode::getTemporary(VMContext, Elts);
1008 });
Devang Patel746660f2010-12-07 23:25:47 +00001009}
1010
Devang Patel9b412732011-02-22 18:56:12 +00001011/// createVariable - Create a new descriptor for the specified variable.
1012DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel63f83cd2010-12-07 23:58:00 +00001013 StringRef Name, DIFile File,
Adrian Prantl1a1647c2014-03-18 02:34:58 +00001014 unsigned LineNo, DITypeRef Ty,
Devang Patel40eee1e2011-03-01 22:58:13 +00001015 bool AlwaysPreserve, unsigned Flags,
1016 unsigned ArgNo) {
David Blaikie085abe32013-03-11 23:21:19 +00001017 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren74c188f2013-07-01 21:02:01 +00001018 assert((!Context || Context.isScope()) &&
David Blaikie085abe32013-03-11 23:21:19 +00001019 "createLocalVariable should be called with a valid Context");
Devang Patel63f83cd2010-12-07 23:58:00 +00001020 Value *Elts[] = {
1021 GetTagConstant(VMContext, Tag),
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001022 getNonCompileUnitScope(Scope),
Devang Patel63f83cd2010-12-07 23:58:00 +00001023 MDString::get(VMContext, Name),
1024 File,
Devang Patel40eee1e2011-03-01 22:58:13 +00001025 ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
Devang Patel63f83cd2010-12-07 23:58:00 +00001026 Ty,
Devang Patelcfa82a32011-07-19 19:41:54 +00001027 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Bill Wendling5ef31592012-07-06 17:49:19 +00001028 Constant::getNullValue(Type::getInt32Ty(VMContext))
Devang Patel63f83cd2010-12-07 23:58:00 +00001029 };
Devang Patel0c773242011-04-18 23:51:03 +00001030 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel63f83cd2010-12-07 23:58:00 +00001031 if (AlwaysPreserve) {
1032 // The optimizer may remove local variable. If there is an interest
1033 // to preserve variable info in such situation then stash it in a
1034 // named mdnode.
1035 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel59e27c52011-08-19 23:28:12 +00001036 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel63f83cd2010-12-07 23:58:00 +00001037 FnLocals->addOperand(Node);
1038 }
Manman Rend0e67aa2013-07-02 18:37:35 +00001039 DIVariable RetVar(Node);
1040 assert(RetVar.isVariable() &&
Manman Ren74c188f2013-07-01 21:02:01 +00001041 "createLocalVariable should return a valid DIVariable");
Manman Rend0e67aa2013-07-02 18:37:35 +00001042 return RetVar;
Devang Patel63f83cd2010-12-07 23:58:00 +00001043}
1044
Devang Patel9b412732011-02-22 18:56:12 +00001045/// createComplexVariable - Create a new descriptor for the specified variable
Devang Patel746660f2010-12-07 23:25:47 +00001046/// which has a complex address expression for its address.
Devang Patel9b412732011-02-22 18:56:12 +00001047DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel746660f2010-12-07 23:25:47 +00001048 StringRef Name, DIFile F,
1049 unsigned LineNo,
Adrian Prantl1a1647c2014-03-18 02:34:58 +00001050 DITypeRef Ty,
1051 ArrayRef<Value *> Addr,
Jay Foaddbf81d82011-04-24 10:11:03 +00001052 unsigned ArgNo) {
Adrian Prantlda7d92e2014-06-30 17:17:35 +00001053 assert(Addr.size() > 0 && "complex address is empty");
1054 Value *Elts[] = {
1055 GetTagConstant(VMContext, Tag),
1056 getNonCompileUnitScope(Scope),
1057 MDString::get(VMContext, Name),
1058 F,
1059 ConstantInt::get(Type::getInt32Ty(VMContext),
1060 (LineNo | (ArgNo << 24))),
1061 Ty,
1062 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1063 Constant::getNullValue(Type::getInt32Ty(VMContext)),
1064 MDNode::get(VMContext, Addr)
1065 };
Devang Patel0c773242011-04-18 23:51:03 +00001066 return DIVariable(MDNode::get(VMContext, Elts));
Devang Patel746660f2010-12-07 23:25:47 +00001067}
1068
Adrian Prantlb1416832014-08-01 22:11:58 +00001069/// createVariablePiece - Create a descriptor to describe one part
1070/// of aggregate variable that is fragmented across multiple Values.
1071DIVariable DIBuilder::createVariablePiece(DIVariable Variable,
1072 unsigned OffsetInBytes,
1073 unsigned SizeInBytes) {
1074 assert(SizeInBytes > 0 && "zero-size piece");
1075 Value *Addr[] = {
1076 ConstantInt::get(Type::getInt32Ty(VMContext), OpPiece),
1077 ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBytes),
1078 ConstantInt::get(Type::getInt32Ty(VMContext), SizeInBytes)
1079 };
1080
1081 assert((Variable->getNumOperands() == 8 || Variable.isVariablePiece()) &&
1082 "variable already has a complex address");
1083 SmallVector<Value *, 9> Elts;
1084 for (unsigned i = 0; i < 8; ++i)
1085 Elts.push_back(Variable->getOperand(i));
1086
1087 Elts.push_back(MDNode::get(VMContext, Addr));
1088 return DIVariable(MDNode::get(VMContext, Elts));
1089}
1090
Devang Patel9b412732011-02-22 18:56:12 +00001091/// createFunction - Create a new descriptor for the specified function.
Manman Renc50fa112013-10-10 18:40:01 +00001092/// FIXME: this is added for dragonegg. Once we update dragonegg
1093/// to call resolve function, this will be removed.
Eric Christopher98f9c232013-10-15 23:31:31 +00001094DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1095 StringRef LinkageName, DIFile File,
1096 unsigned LineNo, DICompositeType Ty,
Manman Renc50fa112013-10-10 18:40:01 +00001097 bool isLocalToUnit, bool isDefinition,
Eric Christopher98f9c232013-10-15 23:31:31 +00001098 unsigned ScopeLine, unsigned Flags,
1099 bool isOptimized, Function *Fn,
1100 MDNode *TParams, MDNode *Decl) {
Manman Renc50fa112013-10-10 18:40:01 +00001101 // dragonegg does not generate identifier for types, so using an empty map
1102 // to resolve the context should be fine.
1103 DITypeIdentifierMap EmptyMap;
1104 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
1105 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1106 Flags, isOptimized, Fn, TParams, Decl);
1107}
1108
Frederic Riss5e6bc9e2014-09-17 09:28:34 +00001109static DISubprogram
1110createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
1111 StringRef LinkageName, DIFile File, unsigned LineNo,
1112 DICompositeType Ty, bool isLocalToUnit, bool isDefinition,
1113 unsigned ScopeLine, unsigned Flags, bool isOptimized,
1114 Function *Fn, MDNode *TParams, MDNode *Decl,
1115 std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
David Blaikie5174c842013-05-22 23:22:18 +00001116 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1117 "function types should be subroutines");
Devang Patel59e27c52011-08-19 23:28:12 +00001118 Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Devang Patelb68c6232010-12-08 20:42:44 +00001119 Value *Elts[] = {
1120 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikie5ef3fcb2013-03-21 23:08:34 +00001121 File.getFileNode(),
Manman Renc50fa112013-10-10 18:40:01 +00001122 DIScope(getNonCompileUnitScope(Context)).getRef(),
Devang Patelb68c6232010-12-08 20:42:44 +00001123 MDString::get(VMContext, Name),
1124 MDString::get(VMContext, Name),
1125 MDString::get(VMContext, LinkageName),
Devang Patelb68c6232010-12-08 20:42:44 +00001126 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1127 Ty,
1128 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1129 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
1130 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
1131 ConstantInt::get(Type::getInt32Ty(VMContext), 0),
Craig Topperc6207612014-04-09 06:08:46 +00001132 nullptr,
Devang Patelb68c6232010-12-08 20:42:44 +00001133 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1134 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patel9f738842011-04-05 22:52:06 +00001135 Fn,
Devang Patel1d6bbd42011-04-22 23:10:17 +00001136 TParams,
Devang Patel59e27c52011-08-19 23:28:12 +00001137 Decl,
David Blaikie2811f8a2013-02-04 05:56:36 +00001138 MDNode::getTemporary(VMContext, TElts),
Eric Christopher34164192012-04-03 00:43:49 +00001139 ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
Devang Patelb68c6232010-12-08 20:42:44 +00001140 };
Devang Patelb68c6232010-12-08 20:42:44 +00001141
Frederic Riss5e6bc9e2014-09-17 09:28:34 +00001142 DISubprogram S(CreateFunc(Elts));
Eric Christopher961959f2014-02-28 21:27:59 +00001143 assert(S.isSubprogram() &&
1144 "createFunction should return a valid DISubprogram");
David Blaikiecc8d0902013-03-21 20:28:52 +00001145 return S;
Devang Patelb68c6232010-12-08 20:42:44 +00001146}
1147
Frederic Riss5e6bc9e2014-09-17 09:28:34 +00001148
1149/// createFunction - Create a new descriptor for the specified function.
1150DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1151 StringRef LinkageName, DIFile File,
1152 unsigned LineNo, DICompositeType Ty,
1153 bool isLocalToUnit, bool isDefinition,
1154 unsigned ScopeLine, unsigned Flags,
1155 bool isOptimized, Function *Fn,
1156 MDNode *TParams, MDNode *Decl) {
1157 return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1158 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1159 Flags, isOptimized, Fn, TParams, Decl,
1160 [&] (ArrayRef<Value *> Elts) -> MDNode *{
1161 MDNode *Node = MDNode::get(VMContext, Elts);
1162 // Create a named metadata so that we
1163 // do not lose this mdnode.
1164 if (isDefinition)
1165 AllSubprograms.push_back(Node);
1166 return Node;
1167 });
1168}
1169
1170/// createTempFunctionFwdDecl - Create a new temporary descriptor for
1171/// the specified function declaration.
1172DISubprogram
1173DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
1174 StringRef LinkageName, DIFile File,
1175 unsigned LineNo, DICompositeType Ty,
1176 bool isLocalToUnit, bool isDefinition,
1177 unsigned ScopeLine, unsigned Flags,
1178 bool isOptimized, Function *Fn,
1179 MDNode *TParams, MDNode *Decl) {
1180 return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1181 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1182 Flags, isOptimized, Fn, TParams, Decl,
1183 [&] (ArrayRef<Value *> Elts) {
1184 return MDNode::getTemporary(VMContext, Elts);
1185 });
1186}
1187
Devang Patel9b412732011-02-22 18:56:12 +00001188/// createMethod - Create a new descriptor for the specified C++ method.
Eric Christopher98f9c232013-10-15 23:31:31 +00001189DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1190 StringRef LinkageName, DIFile F,
David Blaikie5174c842013-05-22 23:22:18 +00001191 unsigned LineNo, DICompositeType Ty,
Eric Christopher98f9c232013-10-15 23:31:31 +00001192 bool isLocalToUnit, bool isDefinition,
Devang Patelb68c6232010-12-08 20:42:44 +00001193 unsigned VK, unsigned VIndex,
Eric Christopher98f9c232013-10-15 23:31:31 +00001194 DIType VTableHolder, unsigned Flags,
1195 bool isOptimized, Function *Fn,
Devang Patel9f738842011-04-05 22:52:06 +00001196 MDNode *TParam) {
David Blaikie5174c842013-05-22 23:22:18 +00001197 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1198 "function types should be subroutines");
Eric Christopher5cb56322013-10-15 23:31:36 +00001199 assert(getNonCompileUnitScope(Context) &&
1200 "Methods should have both a Context and a context that isn't "
1201 "the compile unit.");
Devang Patelb68c6232010-12-08 20:42:44 +00001202 Value *Elts[] = {
1203 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
David Blaikie5ef3fcb2013-03-21 23:08:34 +00001204 F.getFileNode(),
Eric Christopher5cb56322013-10-15 23:31:36 +00001205 DIScope(Context).getRef(),
Devang Patelb68c6232010-12-08 20:42:44 +00001206 MDString::get(VMContext, Name),
1207 MDString::get(VMContext, Name),
1208 MDString::get(VMContext, LinkageName),
Devang Patelb68c6232010-12-08 20:42:44 +00001209 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1210 Ty,
1211 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1212 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
Eric Christopher98f9c232013-10-15 23:31:31 +00001213 ConstantInt::get(Type::getInt32Ty(VMContext), VK),
Devang Patelb68c6232010-12-08 20:42:44 +00001214 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
Manman Renaad5c3b2013-09-30 19:42:10 +00001215 VTableHolder.getRef(),
Devang Patelb68c6232010-12-08 20:42:44 +00001216 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
1217 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patel9f738842011-04-05 22:52:06 +00001218 Fn,
1219 TParam,
Bill Wendling7154c432012-07-06 17:47:36 +00001220 Constant::getNullValue(Type::getInt32Ty(VMContext)),
David Blaikief248c162014-05-07 06:08:28 +00001221 nullptr,
Eric Christopher5d5338f2012-05-18 00:16:22 +00001222 // FIXME: Do we want to use different scope/lines?
Eric Christopher34164192012-04-03 00:43:49 +00001223 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
Devang Patelb68c6232010-12-08 20:42:44 +00001224 };
Devang Patel0c773242011-04-18 23:51:03 +00001225 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie595eb442013-02-18 07:10:22 +00001226 if (isDefinition)
1227 AllSubprograms.push_back(Node);
David Blaikiecc8d0902013-03-21 20:28:52 +00001228 DISubprogram S(Node);
Manman Ren74c188f2013-07-01 21:02:01 +00001229 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikiecc8d0902013-03-21 20:28:52 +00001230 return S;
Devang Patelb68c6232010-12-08 20:42:44 +00001231}
1232
Devang Patel9b412732011-02-22 18:56:12 +00001233/// createNameSpace - This creates new descriptor for a namespace
Devang Patel746660f2010-12-07 23:25:47 +00001234/// with the specified parent scope.
Devang Patel9b412732011-02-22 18:56:12 +00001235DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patel746660f2010-12-07 23:25:47 +00001236 DIFile File, unsigned LineNo) {
1237 Value *Elts[] = {
1238 GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
David Blaikie2881da72013-03-20 19:39:15 +00001239 File.getFileNode(),
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001240 getNonCompileUnitScope(Scope),
Devang Patel746660f2010-12-07 23:25:47 +00001241 MDString::get(VMContext, Name),
Devang Patel746660f2010-12-07 23:25:47 +00001242 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1243 };
David Blaikie085abe32013-03-11 23:21:19 +00001244 DINameSpace R(MDNode::get(VMContext, Elts));
1245 assert(R.Verify() &&
1246 "createNameSpace should return a verifiable DINameSpace");
1247 return R;
Devang Patel746660f2010-12-07 23:25:47 +00001248}
1249
Eric Christopher6647b832011-10-11 22:59:11 +00001250/// createLexicalBlockFile - This creates a new MDNode that encapsulates
1251/// an existing scope with a new filename.
1252DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
David Blaikie2f3f76f2014-08-21 22:45:21 +00001253 DIFile File,
1254 unsigned Discriminator) {
Eric Christopher6647b832011-10-11 22:59:11 +00001255 Value *Elts[] = {
1256 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie61ef2be2013-03-22 20:18:46 +00001257 File.getFileNode(),
David Blaikie2f3f76f2014-08-21 22:45:21 +00001258 Scope,
1259 ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
Eric Christopher6647b832011-10-11 22:59:11 +00001260 };
David Blaikie085abe32013-03-11 23:21:19 +00001261 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1262 assert(
1263 R.Verify() &&
1264 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1265 return R;
Eric Christopher6647b832011-10-11 22:59:11 +00001266}
1267
Devang Patel9b412732011-02-22 18:56:12 +00001268DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
David Blaikie2f3f76f2014-08-21 22:45:21 +00001269 unsigned Line, unsigned Col) {
David Blaikie6c217162014-05-15 20:09:55 +00001270 // FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing.
1271 // I believe the right way is to have a self-referential element in the node.
1272 // Also: why do we bother with line/column - they're not used and the
1273 // documentation (SourceLevelDebugging.rst) claims the line/col are necessary
1274 // for uniquing, yet then we have this other solution (because line/col were
1275 // inadequate) anyway. Remove all 3 and replace them with a self-reference.
1276
Adrian Prantl21e8d4a2013-06-24 21:19:43 +00001277 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel89ea4f22010-12-08 01:50:15 +00001278 static unsigned int unique_id = 0;
1279 Value *Elts[] = {
1280 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
David Blaikie30ce0782013-03-22 17:33:20 +00001281 File.getFileNode(),
Devang Pateleb1bb4e2011-08-16 22:09:43 +00001282 getNonCompileUnitScope(Scope),
Devang Patel89ea4f22010-12-08 01:50:15 +00001283 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
1284 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
Devang Patel89ea4f22010-12-08 01:50:15 +00001285 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
1286 };
David Blaikie085abe32013-03-11 23:21:19 +00001287 DILexicalBlock R(MDNode::get(VMContext, Elts));
1288 assert(R.Verify() &&
1289 "createLexicalBlock should return a verifiable DILexicalBlock");
1290 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +00001291}
1292
Devang Patel9b412732011-02-22 18:56:12 +00001293/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1294Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patel746660f2010-12-07 23:25:47 +00001295 Instruction *InsertBefore) {
1296 assert(Storage && "no storage passed to dbg.declare");
Manman Ren9822a112013-06-29 05:01:19 +00001297 assert(VarInfo.isVariable() &&
1298 "empty or invalid DIVariable passed to dbg.declare");
Devang Patel746660f2010-12-07 23:25:47 +00001299 if (!DeclareFn)
1300 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1301
Jay Foad5514afe2011-04-21 19:59:31 +00001302 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Jay Foad5bd375a2011-07-15 08:37:34 +00001303 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patel746660f2010-12-07 23:25:47 +00001304}
1305
Devang Patel9b412732011-02-22 18:56:12 +00001306/// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
1307Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Devang Patel746660f2010-12-07 23:25:47 +00001308 BasicBlock *InsertAtEnd) {
1309 assert(Storage && "no storage passed to dbg.declare");
Manman Ren9822a112013-06-29 05:01:19 +00001310 assert(VarInfo.isVariable() &&
1311 "empty or invalid DIVariable passed to dbg.declare");
Devang Patel746660f2010-12-07 23:25:47 +00001312 if (!DeclareFn)
1313 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1314
Jay Foad5514afe2011-04-21 19:59:31 +00001315 Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo };
Devang Patel746660f2010-12-07 23:25:47 +00001316
1317 // If this block already has a terminator then insert this intrinsic
1318 // before the terminator.
1319 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foad5bd375a2011-07-15 08:37:34 +00001320 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patel746660f2010-12-07 23:25:47 +00001321 else
Jay Foad5bd375a2011-07-15 08:37:34 +00001322 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patel746660f2010-12-07 23:25:47 +00001323}
1324
Devang Patel9b412732011-02-22 18:56:12 +00001325/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1326Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patel746660f2010-12-07 23:25:47 +00001327 DIVariable VarInfo,
1328 Instruction *InsertBefore) {
1329 assert(V && "no value passed to dbg.value");
Manman Ren9822a112013-06-29 05:01:19 +00001330 assert(VarInfo.isVariable() &&
1331 "empty or invalid DIVariable passed to dbg.value");
Devang Patel746660f2010-12-07 23:25:47 +00001332 if (!ValueFn)
1333 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1334
Jay Foad5514afe2011-04-21 19:59:31 +00001335 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patel746660f2010-12-07 23:25:47 +00001336 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1337 VarInfo };
Jay Foad5bd375a2011-07-15 08:37:34 +00001338 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patel746660f2010-12-07 23:25:47 +00001339}
1340
Devang Patel9b412732011-02-22 18:56:12 +00001341/// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
1342Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patel746660f2010-12-07 23:25:47 +00001343 DIVariable VarInfo,
1344 BasicBlock *InsertAtEnd) {
1345 assert(V && "no value passed to dbg.value");
Manman Ren9822a112013-06-29 05:01:19 +00001346 assert(VarInfo.isVariable() &&
1347 "empty or invalid DIVariable passed to dbg.value");
Devang Patel746660f2010-12-07 23:25:47 +00001348 if (!ValueFn)
1349 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1350
Jay Foad5514afe2011-04-21 19:59:31 +00001351 Value *Args[] = { MDNode::get(V->getContext(), V),
Devang Patel746660f2010-12-07 23:25:47 +00001352 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1353 VarInfo };
Jay Foad5bd375a2011-07-15 08:37:34 +00001354 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patel746660f2010-12-07 23:25:47 +00001355}