blob: c131b544b5f960fcc2c99d65eb4953ce4bc1b7c2 [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
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000026namespace {
27class HeaderBuilder {
28 SmallVector<char, 256> Chars;
29
30public:
31 explicit HeaderBuilder(Twine T) { T.toVector(Chars); }
32 HeaderBuilder(const HeaderBuilder &X) : Chars(X.Chars) {}
33 HeaderBuilder(HeaderBuilder &&X) : Chars(std::move(X.Chars)) {}
34
35 template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
36 Chars.push_back(0);
37 Twine(X).toVector(Chars);
38 return *this;
39 }
40
41 MDString *get(LLVMContext &Context) const {
42 return MDString::get(Context, StringRef(Chars.begin(), Chars.size()));
43 }
44
45 static HeaderBuilder get(unsigned Tag) {
46 return HeaderBuilder("0x" + Twine::utohexstr(Tag));
47 }
48};
Devang Patel57c5a202010-11-04 15:01:38 +000049}
Devang Patel63f83cd2010-12-07 23:58:00 +000050
Devang Patel57c5a202010-11-04 15:01:38 +000051DIBuilder::DIBuilder(Module &m)
Craig Topperc6207612014-04-09 06:08:46 +000052 : M(m), VMContext(M.getContext()), TempEnumTypes(nullptr),
53 TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(nullptr),
54 DeclareFn(nullptr), ValueFn(nullptr) {}
Devang Patel57c5a202010-11-04 15:01:38 +000055
Devang Patel2b8acaf2011-08-15 23:00:00 +000056void DIBuilder::finalize() {
Devang Pateleb1bb4e2011-08-16 22:09:43 +000057 DIArray Enums = getOrCreateArray(AllEnumTypes);
58 DIType(TempEnumTypes).replaceAllUsesWith(Enums);
59
Manman Ren0b410402013-08-29 23:17:54 +000060 SmallVector<Value *, 16> RetainValues;
61 // Declarations and definitions of the same type may be retained. Some
62 // clients RAUW these pairs, leaving duplicates in the retained types
63 // list. Use a set to remove the duplicates while we transform the
64 // TrackingVHs back into Values.
65 SmallPtrSet<Value *, 16> RetainSet;
66 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
67 if (RetainSet.insert(AllRetainTypes[I]))
68 RetainValues.push_back(AllRetainTypes[I]);
69 DIArray RetainTypes = getOrCreateArray(RetainValues);
Devang Pateleb1bb4e2011-08-16 22:09:43 +000070 DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
71
72 DIArray SPs = getOrCreateArray(AllSubprograms);
73 DIType(TempSubprograms).replaceAllUsesWith(SPs);
Devang Patel59e27c52011-08-19 23:28:12 +000074 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
75 DISubprogram SP(SPs.getElement(i));
Eric Christopher27deb262012-04-23 19:00:11 +000076 SmallVector<Value *, 4> Variables;
Devang Patel59e27c52011-08-19 23:28:12 +000077 if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) {
Devang Patel59e27c52011-08-19 23:28:12 +000078 for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii)
79 Variables.push_back(NMD->getOperand(ii));
Devang Patel59e27c52011-08-19 23:28:12 +000080 NMD->eraseFromParent();
81 }
Eric Christopher27deb262012-04-23 19:00:11 +000082 if (MDNode *Temp = SP.getVariablesNodes()) {
83 DIArray AV = getOrCreateArray(Variables);
84 DIType(Temp).replaceAllUsesWith(AV);
85 }
Devang Patel59e27c52011-08-19 23:28:12 +000086 }
Devang Pateleb1bb4e2011-08-16 22:09:43 +000087
88 DIArray GVs = getOrCreateArray(AllGVs);
89 DIType(TempGVs).replaceAllUsesWith(GVs);
David Blaikief55abea2013-04-22 06:12:31 +000090
Eric Christopher2c3a6dc2014-02-28 21:27:57 +000091 SmallVector<Value *, 16> RetainValuesI;
92 for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
93 RetainValuesI.push_back(AllImportedModules[I]);
94 DIArray IMs = getOrCreateArray(RetainValuesI);
David Blaikief55abea2013-04-22 06:12:31 +000095 DIType(TempImportedModules).replaceAllUsesWith(IMs);
Devang Pateleb1bb4e2011-08-16 22:09:43 +000096}
97
Duncan P. N. Exon Smith379e3752014-10-01 21:32:15 +000098/// If N is compile unit return NULL otherwise return N.
Devang Pateleb1bb4e2011-08-16 22:09:43 +000099static MDNode *getNonCompileUnitScope(MDNode *N) {
100 if (DIDescriptor(N).isCompileUnit())
Craig Topperc6207612014-04-09 06:08:46 +0000101 return nullptr;
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000102 return N;
Devang Patel2b8acaf2011-08-15 23:00:00 +0000103}
104
David Blaikieefb0d652013-03-20 23:58:12 +0000105static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
106 StringRef Directory) {
107 assert(!Filename.empty() && "Unable to create file without name");
108 Value *Pair[] = {
109 MDString::get(VMContext, Filename),
Eric Christopher98f9c232013-10-15 23:31:31 +0000110 MDString::get(VMContext, Directory)
David Blaikieefb0d652013-03-20 23:58:12 +0000111 };
112 return MDNode::get(VMContext, Pair);
113}
114
Eric Christopher03b3e112013-07-19 00:51:47 +0000115DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
116 StringRef Directory,
117 StringRef Producer, bool isOptimized,
118 StringRef Flags, unsigned RunTimeVer,
Eric Christopher75d49db2014-02-27 01:24:56 +0000119 StringRef SplitName,
Diego Novillo56653fd2014-06-24 17:02:03 +0000120 DebugEmissionKind Kind,
121 bool EmitDebugInfo) {
Eric Christopher75d49db2014-02-27 01:24:56 +0000122
Peter Collingbourneb2f70c72014-04-28 18:11:01 +0000123 assert(((Lang <= dwarf::DW_LANG_OCaml && Lang >= dwarf::DW_LANG_C89) ||
Chandler Carruth4c0ee742012-01-10 18:18:52 +0000124 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
125 "Invalid Language tag");
126 assert(!Filename.empty() &&
127 "Unable to create compile unit without filename");
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000128 Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)};
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000129 TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000130
131 TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000132
133 TempSubprograms = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000134
135 TempGVs = MDNode::getTemporary(VMContext, TElts);
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000136
David Blaikief55abea2013-04-22 06:12:31 +0000137 TempImportedModules = MDNode::getTemporary(VMContext, TElts);
138
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000139 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_compile_unit)
140 .concat(Lang)
141 .concat(Producer)
142 .concat(isOptimized)
143 .concat(Flags)
144 .concat(RunTimeVer)
145 .concat(SplitName)
146 .concat(Kind)
147 .get(VMContext),
148 createFilePathPair(VMContext, Filename, Directory),
149 TempEnumTypes, TempRetainTypes, TempSubprograms, TempGVs,
150 TempImportedModules};
Eric Christopher03b3e112013-07-19 00:51:47 +0000151
152 MDNode *CUNode = MDNode::get(VMContext, Elts);
Devang Patel09fa69e2011-05-03 16:18:28 +0000153
154 // Create a named metadata so that it is easier to find cu in a module.
Diego Novillo56653fd2014-06-24 17:02:03 +0000155 // Note that we only generate this when the caller wants to actually
156 // emit debug information. When we are only interested in tracking
157 // source line locations throughout the backend, we prevent codegen from
158 // emitting debug info in the final output by not generating llvm.dbg.cu.
159 if (EmitDebugInfo) {
160 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
161 NMD->addOperand(CUNode);
162 }
Eric Christopher03b3e112013-07-19 00:51:47 +0000163
164 return DICompileUnit(CUNode);
Devang Patel57c5a202010-11-04 15:01:38 +0000165}
166
David Blaikiee63d5d12013-05-20 22:50:35 +0000167static DIImportedEntity
David Blaikie2a40c142014-04-06 06:29:01 +0000168createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
169 Value *NS, unsigned Line, StringRef Name,
170 SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
David Blaikiee63d5d12013-05-20 22:50:35 +0000171 const MDNode *R;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000172 Value *Elts[] = {HeaderBuilder::get(Tag).concat(Line).concat(Name).get(C),
173 Context, NS};
174 R = MDNode::get(C, Elts);
David Blaikiee63d5d12013-05-20 22:50:35 +0000175 DIImportedEntity M(R);
David Blaikie1fd43652013-05-07 21:35:53 +0000176 assert(M.Verify() && "Imported module should be valid");
Eric Christopher2c3a6dc2014-02-28 21:27:57 +0000177 AllImportedModules.push_back(TrackingVH<MDNode>(M));
David Blaikie1fd43652013-05-07 21:35:53 +0000178 return M;
179}
180
David Blaikiee63d5d12013-05-20 22:50:35 +0000181DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
David Blaikie2a40c142014-04-06 06:29:01 +0000182 DINameSpace NS,
183 unsigned Line) {
184 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
185 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000186}
187
188DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
189 DIImportedEntity NS,
David Blaikie2a40c142014-04-06 06:29:01 +0000190 unsigned Line) {
191 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
192 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000193}
194
David Blaikie1fd43652013-05-07 21:35:53 +0000195DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
Adrian Prantld09ba232014-04-01 03:41:04 +0000196 DIScope Decl,
David Blaikie2a40c142014-04-06 06:29:01 +0000197 unsigned Line, StringRef Name) {
198 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
199 Context, Decl.getRef(), Line, Name,
200 AllImportedModules);
201}
202
203DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
204 DIImportedEntity Imp,
205 unsigned Line, StringRef Name) {
206 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
207 Context, Imp, Line, Name, AllImportedModules);
David Blaikief55abea2013-04-22 06:12:31 +0000208}
209
Devang Patel9b412732011-02-22 18:56:12 +0000210DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000211 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_file_type).get(VMContext),
212 createFilePathPair(VMContext, Filename, Directory)};
David Blaikie5692e722013-03-28 02:44:59 +0000213 return DIFile(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000214}
215
David Blaikieb7619002013-06-24 17:34:33 +0000216DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000217 assert(!Name.empty() && "Unable to create enumerator without name");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000218 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000219 HeaderBuilder::get(dwarf::DW_TAG_enumerator).concat(Name).concat(Val).get(
220 VMContext)};
David Blaikie5692e722013-03-28 02:44:59 +0000221 return DIEnumerator(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000222}
223
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000224DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel04d6d472011-09-14 23:13:28 +0000225 assert(!Name.empty() && "Unable to create type without name");
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000226 // Unspecified types are encoded in DIBasicType format. Line number, filename,
227 // size, alignment, offset and flags are always empty here.
Devang Patel04d6d472011-09-14 23:13:28 +0000228 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000229 HeaderBuilder::get(dwarf::DW_TAG_unspecified_type)
230 .concat(Name)
231 .concat(0)
232 .concat(0)
233 .concat(0)
234 .concat(0)
235 .concat(0)
236 .concat(0)
237 .get(VMContext),
238 nullptr, // Filename
239 nullptr // Unused
Devang Patel04d6d472011-09-14 23:13:28 +0000240 };
Manman Ren3c6acec2013-06-07 18:35:53 +0000241 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel04d6d472011-09-14 23:13:28 +0000242}
243
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000244DIBasicType DIBuilder::createNullPtrType() {
245 return createUnspecifiedType("decltype(nullptr)");
246}
247
David Blaikie209d63a2013-02-12 00:40:41 +0000248DIBasicType
249DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
250 uint64_t AlignInBits, unsigned Encoding) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000251 assert(!Name.empty() && "Unable to create type without name");
Devang Patel57c5a202010-11-04 15:01:38 +0000252 // Basic types are encoded in DIBasicType format. Line number, filename,
253 // offset and flags are always empty here.
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000254 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000255 HeaderBuilder::get(dwarf::DW_TAG_base_type)
256 .concat(Name)
257 .concat(0) // Line
258 .concat(SizeInBits)
259 .concat(AlignInBits)
260 .concat(0) // Offset
261 .concat(0) // Flags
262 .concat(Encoding)
263 .get(VMContext),
264 nullptr, // Filename
265 nullptr // Unused
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000266 };
David Blaikie5692e722013-03-28 02:44:59 +0000267 return DIBasicType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000268}
269
David Blaikief11de2f2013-02-18 06:41:57 +0000270DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000271 // Qualified types are encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000272 Value *Elts[] = {HeaderBuilder::get(Tag)
273 .concat(StringRef()) // Name
274 .concat(0) // Line
275 .concat(0) // Size
276 .concat(0) // Align
277 .concat(0) // Offset
278 .concat(0) // Flags
279 .get(VMContext),
280 nullptr, // Filename
281 nullptr, // Unused
282 FromTy.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000283 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000284}
285
David Blaikief11de2f2013-02-18 06:41:57 +0000286DIDerivedType
287DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
288 uint64_t AlignInBits, StringRef Name) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000289 // Pointer types are encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000290 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_pointer_type)
291 .concat(Name)
292 .concat(0) // Line
293 .concat(SizeInBits)
294 .concat(AlignInBits)
295 .concat(0) // Offset
296 .concat(0) // Flags
297 .get(VMContext),
298 nullptr, // Filename
299 nullptr, // Unused
300 PointeeTy.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000301 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000302}
303
Eric Christopher89e594d2013-04-19 20:37:12 +0000304DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
305 DIType Base) {
David Blaikie5d3249b2013-01-07 05:51:15 +0000306 // Pointer types are encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000307 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_ptr_to_member_type)
308 .concat(StringRef())
309 .concat(0) // Line
310 .concat(0) // Size
311 .concat(0) // Align
312 .concat(0) // Offset
313 .concat(0) // Flags
314 .get(VMContext),
315 nullptr, // Filename
316 nullptr, // Unused
317 PointeeTy.getRef(), Base.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000318 return DIDerivedType(MDNode::get(VMContext, Elts));
David Blaikie5d3249b2013-01-07 05:51:15 +0000319}
320
David Blaikief11de2f2013-02-18 06:41:57 +0000321DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
Manman Ren74c188f2013-07-01 21:02:01 +0000322 assert(RTy.isType() && "Unable to create reference type");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000323 // References are encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000324 Value *Elts[] = {HeaderBuilder::get(Tag)
325 .concat(StringRef()) // Name
326 .concat(0) // Line
327 .concat(0) // Size
328 .concat(0) // Align
329 .concat(0) // Offset
330 .concat(0) // Flags
331 .get(VMContext),
332 nullptr, // Filename
333 nullptr, // TheCU,
334 RTy.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000335 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000336}
337
David Blaikief11de2f2013-02-18 06:41:57 +0000338DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
339 unsigned LineNo, DIDescriptor Context) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000340 // typedefs are encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000341 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_typedef)
342 .concat(Name)
343 .concat(LineNo)
344 .concat(0) // Size
345 .concat(0) // Align
346 .concat(0) // Offset
347 .concat(0) // Flags
348 .get(VMContext),
349 File.getFileNode(),
350 DIScope(getNonCompileUnitScope(Context)).getRef(),
351 Ty.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000352 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000353}
354
Manman Ren3c6acec2013-06-07 18:35:53 +0000355DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000356 // typedefs are encoded in DIDerivedType format.
Manman Ren74c188f2013-07-01 21:02:01 +0000357 assert(Ty.isType() && "Invalid type!");
358 assert(FriendTy.isType() && "Invalid friend type!");
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000359 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_friend)
360 .concat(StringRef()) // Name
361 .concat(0) // Line
362 .concat(0) // Size
363 .concat(0) // Align
364 .concat(0) // Offset
365 .concat(0) // Flags
366 .get(VMContext),
367 nullptr, Ty.getRef(), FriendTy.getRef()};
Manman Ren3c6acec2013-06-07 18:35:53 +0000368 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000369}
370
Eric Christopher98f9c232013-10-15 23:31:31 +0000371DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
372 uint64_t BaseOffset,
373 unsigned Flags) {
Manman Ren74c188f2013-07-01 21:02:01 +0000374 assert(Ty.isType() && "Unable to create inheritance");
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000375 // TAG_inheritance is encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000376 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_inheritance)
377 .concat(StringRef()) // Name
378 .concat(0) // Line
379 .concat(0) // Size
380 .concat(0) // Align
381 .concat(BaseOffset)
382 .concat(Flags)
383 .get(VMContext),
384 nullptr, Ty.getRef(), BaseTy.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000385 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000386}
387
Eric Christopher98f9c232013-10-15 23:31:31 +0000388DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
389 DIFile File, unsigned LineNumber,
390 uint64_t SizeInBits,
391 uint64_t AlignInBits,
392 uint64_t OffsetInBits, unsigned Flags,
393 DIType Ty) {
Benjamin Kramered8b7bf2010-11-04 18:45:27 +0000394 // TAG_member is encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000395 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
396 .concat(Name)
397 .concat(LineNumber)
398 .concat(SizeInBits)
399 .concat(AlignInBits)
400 .concat(OffsetInBits)
401 .concat(Flags)
402 .get(VMContext),
403 File.getFileNode(),
404 DIScope(getNonCompileUnitScope(Scope)).getRef(),
405 Ty.getRef()};
David Blaikie5692e722013-03-28 02:44:59 +0000406 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel57c5a202010-11-04 15:01:38 +0000407}
408
Manman Ren3c6acec2013-06-07 18:35:53 +0000409DIDerivedType
410DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
411 DIFile File, unsigned LineNumber,
412 DIType Ty, unsigned Flags,
413 llvm::Value *Val) {
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000414 // TAG_member is encoded in DIDerivedType format.
415 Flags |= DIDescriptor::FlagStaticMember;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000416 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
417 .concat(Name)
418 .concat(LineNumber)
419 .concat(0) // Size
420 .concat(0) // Align
421 .concat(0) // Offset
422 .concat(Flags)
423 .get(VMContext),
424 File.getFileNode(),
425 DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(),
426 Val};
Manman Ren3c6acec2013-06-07 18:35:53 +0000427 return DIDerivedType(MDNode::get(VMContext, Elts));
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000428}
429
Eric Christopher98f9c232013-10-15 23:31:31 +0000430DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
431 unsigned LineNumber,
432 uint64_t SizeInBits,
433 uint64_t AlignInBits,
434 uint64_t OffsetInBits, unsigned Flags,
435 DIType Ty, MDNode *PropertyNode) {
Devang Patel44882172012-02-06 17:49:43 +0000436 // TAG_member is encoded in DIDerivedType format.
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000437 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
438 .concat(Name)
439 .concat(LineNumber)
440 .concat(SizeInBits)
441 .concat(AlignInBits)
442 .concat(OffsetInBits)
443 .concat(Flags)
444 .get(VMContext),
445 File.getFileNode(), getNonCompileUnitScope(File), Ty,
446 PropertyNode};
Manman Ren3c6acec2013-06-07 18:35:53 +0000447 return DIDerivedType(MDNode::get(VMContext, Elts));
Devang Patel44882172012-02-06 17:49:43 +0000448}
449
Eric Christopher98f9c232013-10-15 23:31:31 +0000450DIObjCProperty
451DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
452 StringRef GetterName, StringRef SetterName,
453 unsigned PropertyAttributes, DIType Ty) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000454 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_APPLE_property)
455 .concat(Name)
456 .concat(LineNumber)
457 .concat(GetterName)
458 .concat(SetterName)
459 .concat(PropertyAttributes)
460 .get(VMContext),
461 File, Ty};
David Blaikie5692e722013-03-28 02:44:59 +0000462 return DIObjCProperty(MDNode::get(VMContext, Elts));
Devang Patelcc481592012-02-04 00:59:25 +0000463}
464
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000465DITemplateTypeParameter
Devang Patel9b412732011-02-22 18:56:12 +0000466DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
Devang Patel3a9e65e2011-02-02 21:38:25 +0000467 DIType Ty, MDNode *File, unsigned LineNo,
468 unsigned ColumnNo) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000469 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_template_type_parameter)
470 .concat(Name)
471 .concat(LineNo)
472 .concat(ColumnNo)
473 .get(VMContext),
474 DIScope(getNonCompileUnitScope(Context)).getRef(),
475 Ty.getRef(), File};
David Blaikie5692e722013-03-28 02:44:59 +0000476 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
Devang Patel3a9e65e2011-02-02 21:38:25 +0000477}
478
Eric Christopher3cc90fe2011-08-26 21:02:40 +0000479DITemplateValueParameter
David Blaikie2b380232013-06-22 18:59:11 +0000480DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
481 StringRef Name, DIType Ty,
482 Value *Val, MDNode *File,
483 unsigned LineNo,
Devang Patelbe933b42011-02-02 22:35:53 +0000484 unsigned ColumnNo) {
485 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000486 HeaderBuilder::get(Tag).concat(Name).concat(LineNo).concat(ColumnNo).get(
487 VMContext),
488 DIScope(getNonCompileUnitScope(Context)).getRef(), Ty.getRef(), Val,
489 File};
David Blaikie5692e722013-03-28 02:44:59 +0000490 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
Devang Patelbe933b42011-02-02 22:35:53 +0000491}
492
David Blaikie2b380232013-06-22 18:59:11 +0000493DITemplateValueParameter
494DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name,
495 DIType Ty, Value *Val,
496 MDNode *File, unsigned LineNo,
497 unsigned ColumnNo) {
498 return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter,
499 Context, Name, Ty, Val, File, LineNo,
500 ColumnNo);
501}
502
503DITemplateValueParameter
504DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name,
505 DIType Ty, StringRef Val,
506 MDNode *File, unsigned LineNo,
507 unsigned ColumnNo) {
508 return createTemplateValueParameter(
509 dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
510 MDString::get(VMContext, Val), File, LineNo, ColumnNo);
511}
512
513DITemplateValueParameter
514DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name,
515 DIType Ty, DIArray Val,
516 MDNode *File, unsigned LineNo,
517 unsigned ColumnNo) {
518 return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack,
519 Context, Name, Ty, Val, File, LineNo,
520 ColumnNo);
521}
522
David Blaikiea7310a32013-03-26 23:46:39 +0000523DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
524 DIFile File, unsigned LineNumber,
525 uint64_t SizeInBits,
526 uint64_t AlignInBits,
527 uint64_t OffsetInBits,
528 unsigned Flags, DIType DerivedFrom,
529 DIArray Elements,
Manman Ren27552062013-09-06 23:54:23 +0000530 DIType VTableHolder,
Manman Ren547467b2013-08-27 23:06:40 +0000531 MDNode *TemplateParams,
532 StringRef UniqueIdentifier) {
Manman Ren74c188f2013-07-01 21:02:01 +0000533 assert((!Context || Context.isScope() || Context.isType()) &&
David Blaikie085abe32013-03-11 23:21:19 +0000534 "createClassType should be called with a valid Context");
535 // TAG_class_type is encoded in DICompositeType format.
Eric Christopher17426692012-07-06 02:35:57 +0000536 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000537 HeaderBuilder::get(dwarf::DW_TAG_class_type)
538 .concat(Name)
539 .concat(LineNumber)
540 .concat(SizeInBits)
541 .concat(AlignInBits)
542 .concat(OffsetInBits)
543 .concat(Flags)
544 .concat(0)
545 .get(VMContext),
546 File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(),
547 DerivedFrom.getRef(), Elements, VTableHolder.getRef(), TemplateParams,
548 UniqueIdentifier.empty() ? nullptr
549 : MDString::get(VMContext, UniqueIdentifier)};
David Blaikiea7310a32013-03-26 23:46:39 +0000550 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren74c188f2013-07-01 21:02:01 +0000551 assert(R.isCompositeType() &&
552 "createClassType should return a DICompositeType");
Manman Ren0b410402013-08-29 23:17:54 +0000553 if (!UniqueIdentifier.empty())
554 retainType(R);
David Blaikie085abe32013-03-11 23:21:19 +0000555 return R;
Eric Christopher17426692012-07-06 02:35:57 +0000556}
557
David Blaikiebbe0e1a2013-02-25 01:07:18 +0000558DICompositeType DIBuilder::createStructType(DIDescriptor Context,
559 StringRef Name, DIFile File,
560 unsigned LineNumber,
561 uint64_t SizeInBits,
562 uint64_t AlignInBits,
563 unsigned Flags, DIType DerivedFrom,
564 DIArray Elements,
565 unsigned RunTimeLang,
Manman Ren27552062013-09-06 23:54:23 +0000566 DIType VTableHolder,
Manman Ren547467b2013-08-27 23:06:40 +0000567 StringRef UniqueIdentifier) {
Devang Patel746660f2010-12-07 23:25:47 +0000568 // TAG_structure_type is encoded in DICompositeType format.
569 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000570 HeaderBuilder::get(dwarf::DW_TAG_structure_type)
571 .concat(Name)
572 .concat(LineNumber)
573 .concat(SizeInBits)
574 .concat(AlignInBits)
575 .concat(0)
576 .concat(Flags)
577 .concat(RunTimeLang)
578 .get(VMContext),
579 File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(),
580 DerivedFrom.getRef(), Elements, VTableHolder.getRef(), nullptr,
581 UniqueIdentifier.empty() ? nullptr
582 : MDString::get(VMContext, UniqueIdentifier)};
David Blaikie085abe32013-03-11 23:21:19 +0000583 DICompositeType R(MDNode::get(VMContext, Elts));
Manman Ren74c188f2013-07-01 21:02:01 +0000584 assert(R.isCompositeType() &&
585 "createStructType should return a DICompositeType");
Manman Ren0b410402013-08-29 23:17:54 +0000586 if (!UniqueIdentifier.empty())
587 retainType(R);
David Blaikie085abe32013-03-11 23:21:19 +0000588 return R;
Devang Patel746660f2010-12-07 23:25:47 +0000589}
590
Eric Christopher17dd8f02013-04-02 22:55:52 +0000591DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
592 DIFile File, unsigned LineNumber,
593 uint64_t SizeInBits,
594 uint64_t AlignInBits, unsigned Flags,
595 DIArray Elements,
Manman Ren547467b2013-08-27 23:06:40 +0000596 unsigned RunTimeLang,
597 StringRef UniqueIdentifier) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000598 // TAG_union_type is encoded in DICompositeType format.
599 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000600 HeaderBuilder::get(dwarf::DW_TAG_union_type)
601 .concat(Name)
602 .concat(LineNumber)
603 .concat(SizeInBits)
604 .concat(AlignInBits)
605 .concat(0) // Offset
606 .concat(Flags)
607 .concat(RunTimeLang)
608 .get(VMContext),
609 File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(),
610 nullptr, Elements, nullptr, nullptr,
611 UniqueIdentifier.empty() ? nullptr
612 : MDString::get(VMContext, UniqueIdentifier)};
Manman Ren0b410402013-08-29 23:17:54 +0000613 DICompositeType R(MDNode::get(VMContext, Elts));
614 if (!UniqueIdentifier.empty())
615 retainType(R);
616 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000617}
618
Manman Renf8a19672014-07-28 22:24:06 +0000619DISubroutineType DIBuilder::createSubroutineType(DIFile File,
620 DITypeArray ParameterTypes,
621 unsigned Flags) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000622 // TAG_subroutine_type is encoded in DICompositeType format.
623 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000624 HeaderBuilder::get(dwarf::DW_TAG_subroutine_type)
625 .concat(StringRef())
626 .concat(0) // Line
627 .concat(0) // Size
628 .concat(0) // Align
629 .concat(0) // Offset
630 .concat(Flags) // Flags
631 .concat(0)
632 .get(VMContext),
633 nullptr, nullptr, nullptr, ParameterTypes, nullptr, nullptr,
634 nullptr // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000635 };
Manman Renf8a19672014-07-28 22:24:06 +0000636 return DISubroutineType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000637}
638
David Blaikief11de2f2013-02-18 06:41:57 +0000639DICompositeType DIBuilder::createEnumerationType(
640 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
641 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
Manman Ren547467b2013-08-27 23:06:40 +0000642 DIType UnderlyingType, StringRef UniqueIdentifier) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000643 // TAG_enumeration_type is encoded in DICompositeType format.
644 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000645 HeaderBuilder::get(dwarf::DW_TAG_enumeration_type)
646 .concat(Name)
647 .concat(LineNumber)
648 .concat(SizeInBits)
649 .concat(AlignInBits)
650 .concat(0) // Offset
651 .concat(0) // Flags
652 .concat(0)
653 .get(VMContext),
654 File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(),
655 UnderlyingType.getRef(), Elements, nullptr, nullptr,
656 UniqueIdentifier.empty() ? nullptr
657 : MDString::get(VMContext, UniqueIdentifier)};
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000658 DICompositeType CTy(MDNode::get(VMContext, Elts));
659 AllEnumTypes.push_back(CTy);
Manman Ren0b410402013-08-29 23:17:54 +0000660 if (!UniqueIdentifier.empty())
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000661 retainType(CTy);
662 return CTy;
Devang Patel89ea4f22010-12-08 01:50:15 +0000663}
664
David Blaikief11de2f2013-02-18 06:41:57 +0000665DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
666 DIType Ty, DIArray Subscripts) {
Devang Patel89ea4f22010-12-08 01:50:15 +0000667 // TAG_array_type is encoded in DICompositeType format.
668 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000669 HeaderBuilder::get(dwarf::DW_TAG_array_type)
670 .concat(StringRef())
671 .concat(0) // Line
672 .concat(Size)
673 .concat(AlignInBits)
674 .concat(0) // Offset
675 .concat(0) // Flags
676 .concat(0)
677 .get(VMContext),
678 nullptr, // Filename/Directory,
679 nullptr, // Unused
680 Ty.getRef(), Subscripts, nullptr, nullptr,
681 nullptr // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000682 };
David Blaikie5692e722013-03-28 02:44:59 +0000683 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000684}
685
Manman Ren60711602013-06-07 03:13:46 +0000686DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
687 DIType Ty, DIArray Subscripts) {
Eric Christopher72a52952013-01-08 01:53:52 +0000688 // A vector is an array type with the FlagVector flag applied.
Devang Patel89ea4f22010-12-08 01:50:15 +0000689 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000690 HeaderBuilder::get(dwarf::DW_TAG_array_type)
691 .concat("")
692 .concat(0) // Line
693 .concat(Size)
694 .concat(AlignInBits)
695 .concat(0) // Offset
696 .concat(DIType::FlagVector)
697 .concat(0)
698 .get(VMContext),
699 nullptr, // Filename/Directory,
700 nullptr, // Unused
701 Ty.getRef(), Subscripts, nullptr, nullptr,
702 nullptr // Type Identifer
Devang Patel89ea4f22010-12-08 01:50:15 +0000703 };
Manman Ren60711602013-06-07 03:13:46 +0000704 return DICompositeType(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000705}
Devang Patel746660f2010-12-07 23:25:47 +0000706
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000707static HeaderBuilder setTypeFlagsInHeader(StringRef Header,
708 unsigned FlagsToSet) {
709 DIHeaderFieldIterator I(Header);
710 std::advance(I, 6);
711
712 unsigned Flags;
713 if (I->getAsInteger(0, Flags))
714 Flags = 0;
715 Flags |= FlagsToSet;
716
717 return HeaderBuilder(Twine(I.getPrefix())).concat(Flags).concat(
718 I.getSuffix());
719}
720
721static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
722 unsigned FlagsToSet) {
723 SmallVector<Value *, 9> Elts;
724 MDNode *N = Ty;
725 assert(N && "Unexpected input DIType!");
726 // Update header field.
727 Elts.push_back(setTypeFlagsInHeader(Ty.getHeader(), FlagsToSet).get(Context));
728 for (unsigned I = 1, E = N->getNumOperands(); I != E; ++I)
729 Elts.push_back(N->getOperand(I));
730
731 return DIType(MDNode::get(Context, Elts));
732}
733
Devang Patel9b412732011-02-22 18:56:12 +0000734DIType DIBuilder::createArtificialType(DIType Ty) {
Devang Patel57c5a202010-11-04 15:01:38 +0000735 if (Ty.isArtificial())
736 return Ty;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000737 return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial);
Devang Patel57c5a202010-11-04 15:01:38 +0000738}
Devang Patel746660f2010-12-07 23:25:47 +0000739
Eric Christophere3417762012-09-12 23:36:19 +0000740DIType DIBuilder::createObjectPointerType(DIType Ty) {
741 if (Ty.isObjectPointer())
742 return Ty;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000743 unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
744 return createTypeWithFlags(VMContext, Ty, Flags);
Eric Christophere3417762012-09-12 23:36:19 +0000745}
746
Devang Patel9b412732011-02-22 18:56:12 +0000747void DIBuilder::retainType(DIType T) {
Manman Ren0b410402013-08-29 23:17:54 +0000748 AllRetainTypes.push_back(TrackingVH<MDNode>(T));
Devang Patel89ea4f22010-12-08 01:50:15 +0000749}
750
Manman Renf93ac4b2014-07-29 18:20:39 +0000751DIBasicType DIBuilder::createUnspecifiedParameter() {
Manman Ren72b07e82014-07-29 22:58:13 +0000752 return DIBasicType();
Devang Patel89ea4f22010-12-08 01:50:15 +0000753}
754
Eric Christopher98f9c232013-10-15 23:31:31 +0000755DICompositeType
756DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
757 DIFile F, unsigned Line, unsigned RuntimeLang,
758 uint64_t SizeInBits, uint64_t AlignInBits,
759 StringRef UniqueIdentifier) {
Eric Christopherae56eec2012-02-08 00:22:26 +0000760 // Create a temporary MDNode.
761 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000762 HeaderBuilder::get(Tag)
763 .concat(Name)
764 .concat(Line)
765 .concat(SizeInBits)
766 .concat(AlignInBits)
767 .concat(0) // Offset
768 .concat(DIDescriptor::FlagFwdDecl)
769 .concat(RuntimeLang)
770 .get(VMContext),
771 F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr,
772 DIArray(), nullptr,
773 nullptr, // TemplateParams
774 UniqueIdentifier.empty() ? nullptr
775 : MDString::get(VMContext, UniqueIdentifier)};
David Blaikied3f094a2014-05-06 03:41:57 +0000776 MDNode *Node = MDNode::get(VMContext, Elts);
777 DICompositeType RetTy(Node);
778 assert(RetTy.isCompositeType() &&
779 "createForwardDecl result should be a DIType");
780 if (!UniqueIdentifier.empty())
781 retainType(RetTy);
782 return RetTy;
783}
784
David Blaikied3f094a2014-05-06 03:41:57 +0000785DICompositeType DIBuilder::createReplaceableForwardDecl(
786 unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line,
787 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
788 StringRef UniqueIdentifier) {
789 // Create a temporary MDNode.
790 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000791 HeaderBuilder::get(Tag)
792 .concat(Name)
793 .concat(Line)
794 .concat(SizeInBits)
795 .concat(AlignInBits)
796 .concat(0) // Offset
797 .concat(DIDescriptor::FlagFwdDecl)
798 .concat(RuntimeLang)
799 .get(VMContext),
800 F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr,
801 DIArray(), nullptr,
802 nullptr, // TemplateParams
803 UniqueIdentifier.empty() ? nullptr
804 : MDString::get(VMContext, UniqueIdentifier)};
Eric Christopherae56eec2012-02-08 00:22:26 +0000805 MDNode *Node = MDNode::getTemporary(VMContext, Elts);
David Blaikied4e106e2013-08-16 20:42:14 +0000806 DICompositeType RetTy(Node);
807 assert(RetTy.isCompositeType() &&
Frederic Rissa8734142014-09-10 16:03:14 +0000808 "createReplaceableForwardDecl result should be a DIType");
Manman Ren0b410402013-08-29 23:17:54 +0000809 if (!UniqueIdentifier.empty())
810 retainType(RetTy);
Manman Rend0e67aa2013-07-02 18:37:35 +0000811 return RetTy;
Eric Christopherae56eec2012-02-08 00:22:26 +0000812}
813
Jay Foaddbf81d82011-04-24 10:11:03 +0000814DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) {
Jay Foaddbf81d82011-04-24 10:11:03 +0000815 return DIArray(MDNode::get(VMContext, Elements));
Devang Patel746660f2010-12-07 23:25:47 +0000816}
817
Manman Ren1a125c92014-07-28 19:33:20 +0000818DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Value *> Elements) {
819 SmallVector<llvm::Value *, 16> Elts;
820 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
821 if (Elements[i] && isa<MDNode>(Elements[i]))
822 Elts.push_back(DIType(cast<MDNode>(Elements[i])).getRef());
823 else
824 Elts.push_back(Elements[i]);
825 }
826 return DITypeArray(MDNode::get(VMContext, Elts));
827}
828
Bill Wendlingd7767122012-12-04 21:34:03 +0000829DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000830 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subrange_type)
831 .concat(Lo)
832 .concat(Count)
833 .get(VMContext)};
Devang Patel89ea4f22010-12-08 01:50:15 +0000834
Devang Patel0c773242011-04-18 23:51:03 +0000835 return DISubrange(MDNode::get(VMContext, Elts));
Devang Patel89ea4f22010-12-08 01:50:15 +0000836}
837
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000838static DIGlobalVariable
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000839createGlobalVariableHelper(LLVMContext &VMContext, DIDescriptor Context,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000840 StringRef Name, StringRef LinkageName, DIFile F,
841 unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit,
842 Value *Val, MDNode *Decl, bool isDefinition,
843 std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000844 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_variable)
845 .concat(Name)
846 .concat(Name)
847 .concat(LinkageName)
848 .concat(LineNumber)
849 .concat(isLocalToUnit)
850 .concat(isDefinition)
851 .get(VMContext),
852 getNonCompileUnitScope(Context), F, Ty, Val,
853 DIDescriptor(Decl)};
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000854
855 return DIGlobalVariable(CreateFunc(Elts));
856}
857
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000858DIGlobalVariable DIBuilder::createGlobalVariable(DIDescriptor Context,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000859 StringRef Name,
860 StringRef LinkageName,
861 DIFile F, unsigned LineNumber,
862 DITypeRef Ty,
863 bool isLocalToUnit,
864 Value *Val, MDNode *Decl) {
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000865 return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000866 LineNumber, Ty, isLocalToUnit, Val, Decl, true,
867 [&] (ArrayRef<Value *> Elts) -> MDNode * {
868 MDNode *Node = MDNode::get(VMContext, Elts);
869 AllGVs.push_back(Node);
870 return Node;
871 });
872}
873
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000874DIGlobalVariable
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000875DIBuilder::createTempGlobalVariableFwdDecl(DIDescriptor Context,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000876 StringRef Name,
877 StringRef LinkageName,
878 DIFile F, unsigned LineNumber,
879 DITypeRef Ty,
880 bool isLocalToUnit,
881 Value *Val, MDNode *Decl) {
Jyoti Allurb76b57f2014-09-29 06:32:54 +0000882 return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F,
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000883 LineNumber, Ty, isLocalToUnit, Val, Decl, false,
884 [&] (ArrayRef<Value *> Elts) {
885 return MDNode::getTemporary(VMContext, Elts);
886 });
Devang Patel746660f2010-12-07 23:25:47 +0000887}
888
Devang Patel9b412732011-02-22 18:56:12 +0000889DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
Devang Patel63f83cd2010-12-07 23:58:00 +0000890 StringRef Name, DIFile File,
Adrian Prantl1a1647c2014-03-18 02:34:58 +0000891 unsigned LineNo, DITypeRef Ty,
Devang Patel40eee1e2011-03-01 22:58:13 +0000892 bool AlwaysPreserve, unsigned Flags,
893 unsigned ArgNo) {
David Blaikie085abe32013-03-11 23:21:19 +0000894 DIDescriptor Context(getNonCompileUnitScope(Scope));
Manman Ren74c188f2013-07-01 21:02:01 +0000895 assert((!Context || Context.isScope()) &&
David Blaikie085abe32013-03-11 23:21:19 +0000896 "createLocalVariable should be called with a valid Context");
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000897 Value *Elts[] = {HeaderBuilder::get(Tag)
898 .concat(Name)
899 .concat(LineNo | (ArgNo << 24))
900 .concat(Flags)
901 .get(VMContext),
902 getNonCompileUnitScope(Scope), File, Ty};
Devang Patel0c773242011-04-18 23:51:03 +0000903 MDNode *Node = MDNode::get(VMContext, Elts);
Devang Patel63f83cd2010-12-07 23:58:00 +0000904 if (AlwaysPreserve) {
905 // The optimizer may remove local variable. If there is an interest
906 // to preserve variable info in such situation then stash it in a
907 // named mdnode.
908 DISubprogram Fn(getDISubprogram(Scope));
Devang Patel59e27c52011-08-19 23:28:12 +0000909 NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn);
Devang Patel63f83cd2010-12-07 23:58:00 +0000910 FnLocals->addOperand(Node);
911 }
Manman Rend0e67aa2013-07-02 18:37:35 +0000912 DIVariable RetVar(Node);
913 assert(RetVar.isVariable() &&
Manman Ren74c188f2013-07-01 21:02:01 +0000914 "createLocalVariable should return a valid DIVariable");
Manman Rend0e67aa2013-07-02 18:37:35 +0000915 return RetVar;
Devang Patel63f83cd2010-12-07 23:58:00 +0000916}
917
Duncan P. N. Exon Smith611afb22014-10-01 20:26:08 +0000918DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Addr) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000919 auto Header = HeaderBuilder::get(DW_TAG_expression);
Duncan P. N. Exon Smith611afb22014-10-01 20:26:08 +0000920 for (int64_t I : Addr)
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000921 Header.concat(I);
922 Value *Elts[] = {Header.get(VMContext)};
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000923 return DIExpression(MDNode::get(VMContext, Elts));
Devang Patel746660f2010-12-07 23:25:47 +0000924}
925
Duncan P. N. Exon Smith9affbba2014-10-01 21:32:12 +0000926DIExpression DIBuilder::createPieceExpression(unsigned OffsetInBytes,
927 unsigned SizeInBytes) {
928 int64_t Addr[] = {dwarf::DW_OP_piece, OffsetInBytes, SizeInBytes};
929 return createExpression(Addr);
930}
931
Eric Christopher98f9c232013-10-15 23:31:31 +0000932DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
933 StringRef LinkageName, DIFile File,
934 unsigned LineNo, DICompositeType Ty,
Manman Renc50fa112013-10-10 18:40:01 +0000935 bool isLocalToUnit, bool isDefinition,
Eric Christopher98f9c232013-10-15 23:31:31 +0000936 unsigned ScopeLine, unsigned Flags,
937 bool isOptimized, Function *Fn,
938 MDNode *TParams, MDNode *Decl) {
Manman Renc50fa112013-10-10 18:40:01 +0000939 // dragonegg does not generate identifier for types, so using an empty map
940 // to resolve the context should be fine.
941 DITypeIdentifierMap EmptyMap;
942 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
943 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
944 Flags, isOptimized, Fn, TParams, Decl);
945}
946
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000947static DISubprogram
948createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
949 StringRef LinkageName, DIFile File, unsigned LineNo,
950 DICompositeType Ty, bool isLocalToUnit, bool isDefinition,
951 unsigned ScopeLine, unsigned Flags, bool isOptimized,
952 Function *Fn, MDNode *TParams, MDNode *Decl,
953 std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
David Blaikie5174c842013-05-22 23:22:18 +0000954 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
955 "function types should be subroutines");
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000956 Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)};
Devang Patelb68c6232010-12-08 20:42:44 +0000957 Value *Elts[] = {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000958 HeaderBuilder::get(dwarf::DW_TAG_subprogram)
959 .concat(Name)
960 .concat(Name)
961 .concat(LinkageName)
962 .concat(LineNo)
963 .concat(isLocalToUnit)
964 .concat(isDefinition)
965 .concat(0)
966 .concat(0)
967 .concat(Flags)
968 .concat(isOptimized)
969 .concat(ScopeLine)
970 .get(VMContext),
971 File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(), Ty,
972 nullptr, Fn, TParams, Decl, MDNode::getTemporary(VMContext, TElts)};
Devang Patelb68c6232010-12-08 20:42:44 +0000973
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000974 DISubprogram S(CreateFunc(Elts));
Eric Christopher961959f2014-02-28 21:27:59 +0000975 assert(S.isSubprogram() &&
976 "createFunction should return a valid DISubprogram");
David Blaikiecc8d0902013-03-21 20:28:52 +0000977 return S;
Devang Patelb68c6232010-12-08 20:42:44 +0000978}
979
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000980
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000981DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
982 StringRef LinkageName, DIFile File,
983 unsigned LineNo, DICompositeType Ty,
984 bool isLocalToUnit, bool isDefinition,
985 unsigned ScopeLine, unsigned Flags,
986 bool isOptimized, Function *Fn,
987 MDNode *TParams, MDNode *Decl) {
988 return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
989 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
990 Flags, isOptimized, Fn, TParams, Decl,
991 [&] (ArrayRef<Value *> Elts) -> MDNode *{
992 MDNode *Node = MDNode::get(VMContext, Elts);
993 // Create a named metadata so that we
994 // do not lose this mdnode.
995 if (isDefinition)
996 AllSubprograms.push_back(Node);
997 return Node;
998 });
999}
1000
Frederic Riss5e6bc9e2014-09-17 09:28:34 +00001001DISubprogram
1002DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
1003 StringRef LinkageName, DIFile File,
1004 unsigned LineNo, DICompositeType Ty,
1005 bool isLocalToUnit, bool isDefinition,
1006 unsigned ScopeLine, unsigned Flags,
1007 bool isOptimized, Function *Fn,
1008 MDNode *TParams, MDNode *Decl) {
1009 return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1010 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1011 Flags, isOptimized, Fn, TParams, Decl,
1012 [&] (ArrayRef<Value *> Elts) {
1013 return MDNode::getTemporary(VMContext, Elts);
1014 });
1015}
1016
Eric Christopher98f9c232013-10-15 23:31:31 +00001017DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1018 StringRef LinkageName, DIFile F,
David Blaikie5174c842013-05-22 23:22:18 +00001019 unsigned LineNo, DICompositeType Ty,
Eric Christopher98f9c232013-10-15 23:31:31 +00001020 bool isLocalToUnit, bool isDefinition,
Devang Patelb68c6232010-12-08 20:42:44 +00001021 unsigned VK, unsigned VIndex,
Eric Christopher98f9c232013-10-15 23:31:31 +00001022 DIType VTableHolder, unsigned Flags,
1023 bool isOptimized, Function *Fn,
Devang Patel9f738842011-04-05 22:52:06 +00001024 MDNode *TParam) {
David Blaikie5174c842013-05-22 23:22:18 +00001025 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
1026 "function types should be subroutines");
Eric Christopher5cb56322013-10-15 23:31:36 +00001027 assert(getNonCompileUnitScope(Context) &&
1028 "Methods should have both a Context and a context that isn't "
1029 "the compile unit.");
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +00001030 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram)
1031 .concat(Name)
1032 .concat(Name)
1033 .concat(LinkageName)
1034 .concat(LineNo)
1035 .concat(isLocalToUnit)
1036 .concat(isDefinition)
1037 .concat(VK)
1038 .concat(VIndex)
1039 .concat(Flags)
1040 .concat(isOptimized)
1041 .concat(LineNo)
1042 // FIXME: Do we want to use different scope/lines?
1043 .get(VMContext),
1044 F.getFileNode(), DIScope(Context).getRef(), Ty,
1045 VTableHolder.getRef(), Fn, TParam, nullptr, nullptr};
Devang Patel0c773242011-04-18 23:51:03 +00001046 MDNode *Node = MDNode::get(VMContext, Elts);
David Blaikie595eb442013-02-18 07:10:22 +00001047 if (isDefinition)
1048 AllSubprograms.push_back(Node);
David Blaikiecc8d0902013-03-21 20:28:52 +00001049 DISubprogram S(Node);
Manman Ren74c188f2013-07-01 21:02:01 +00001050 assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
David Blaikiecc8d0902013-03-21 20:28:52 +00001051 return S;
Devang Patelb68c6232010-12-08 20:42:44 +00001052}
1053
Devang Patel9b412732011-02-22 18:56:12 +00001054DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Devang Patel746660f2010-12-07 23:25:47 +00001055 DIFile File, unsigned LineNo) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +00001056 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_namespace)
1057 .concat(Name)
1058 .concat(LineNo)
1059 .get(VMContext),
1060 File.getFileNode(), getNonCompileUnitScope(Scope)};
David Blaikie085abe32013-03-11 23:21:19 +00001061 DINameSpace R(MDNode::get(VMContext, Elts));
1062 assert(R.Verify() &&
1063 "createNameSpace should return a verifiable DINameSpace");
1064 return R;
Devang Patel746660f2010-12-07 23:25:47 +00001065}
1066
Eric Christopher6647b832011-10-11 22:59:11 +00001067DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
David Blaikie2f3f76f2014-08-21 22:45:21 +00001068 DIFile File,
1069 unsigned Discriminator) {
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +00001070 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
1071 .concat(Discriminator)
1072 .get(VMContext),
1073 File.getFileNode(), Scope};
David Blaikie085abe32013-03-11 23:21:19 +00001074 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
1075 assert(
1076 R.Verify() &&
1077 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1078 return R;
Eric Christopher6647b832011-10-11 22:59:11 +00001079}
1080
Devang Patel9b412732011-02-22 18:56:12 +00001081DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
David Blaikie2f3f76f2014-08-21 22:45:21 +00001082 unsigned Line, unsigned Col) {
David Blaikie6c217162014-05-15 20:09:55 +00001083 // FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing.
1084 // I believe the right way is to have a self-referential element in the node.
1085 // Also: why do we bother with line/column - they're not used and the
1086 // documentation (SourceLevelDebugging.rst) claims the line/col are necessary
1087 // for uniquing, yet then we have this other solution (because line/col were
1088 // inadequate) anyway. Remove all 3 and replace them with a self-reference.
1089
Adrian Prantl21e8d4a2013-06-24 21:19:43 +00001090 // Defeat MDNode uniquing for lexical blocks by using unique id.
Devang Patel89ea4f22010-12-08 01:50:15 +00001091 static unsigned int unique_id = 0;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +00001092 Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
1093 .concat(Line)
1094 .concat(Col)
1095 .concat(unique_id++)
1096 .get(VMContext),
1097 File.getFileNode(), getNonCompileUnitScope(Scope)};
David Blaikie085abe32013-03-11 23:21:19 +00001098 DILexicalBlock R(MDNode::get(VMContext, Elts));
1099 assert(R.Verify() &&
1100 "createLexicalBlock should return a verifiable DILexicalBlock");
1101 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +00001102}
1103
Devang Patel9b412732011-02-22 18:56:12 +00001104Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001105 DIExpression Expr,
Devang Patel746660f2010-12-07 23:25:47 +00001106 Instruction *InsertBefore) {
1107 assert(Storage && "no storage passed to dbg.declare");
Manman Ren9822a112013-06-29 05:01:19 +00001108 assert(VarInfo.isVariable() &&
1109 "empty or invalid DIVariable passed to dbg.declare");
Devang Patel746660f2010-12-07 23:25:47 +00001110 if (!DeclareFn)
1111 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1112
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001113 Value *Args[] = {MDNode::get(Storage->getContext(), Storage), VarInfo, Expr};
Jay Foad5bd375a2011-07-15 08:37:34 +00001114 return CallInst::Create(DeclareFn, Args, "", InsertBefore);
Devang Patel746660f2010-12-07 23:25:47 +00001115}
1116
Devang Patel9b412732011-02-22 18:56:12 +00001117Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001118 DIExpression Expr,
Devang Patel746660f2010-12-07 23:25:47 +00001119 BasicBlock *InsertAtEnd) {
1120 assert(Storage && "no storage passed to dbg.declare");
Manman Ren9822a112013-06-29 05:01:19 +00001121 assert(VarInfo.isVariable() &&
1122 "empty or invalid DIVariable passed to dbg.declare");
Devang Patel746660f2010-12-07 23:25:47 +00001123 if (!DeclareFn)
1124 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1125
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001126 Value *Args[] = {MDNode::get(Storage->getContext(), Storage), VarInfo, Expr};
Devang Patel746660f2010-12-07 23:25:47 +00001127
1128 // If this block already has a terminator then insert this intrinsic
1129 // before the terminator.
1130 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Jay Foad5bd375a2011-07-15 08:37:34 +00001131 return CallInst::Create(DeclareFn, Args, "", T);
Devang Patel746660f2010-12-07 23:25:47 +00001132 else
Jay Foad5bd375a2011-07-15 08:37:34 +00001133 return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
Devang Patel746660f2010-12-07 23:25:47 +00001134}
1135
Devang Patel9b412732011-02-22 18:56:12 +00001136Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patel746660f2010-12-07 23:25:47 +00001137 DIVariable VarInfo,
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001138 DIExpression Expr,
Devang Patel746660f2010-12-07 23:25:47 +00001139 Instruction *InsertBefore) {
1140 assert(V && "no value passed to dbg.value");
Manman Ren9822a112013-06-29 05:01:19 +00001141 assert(VarInfo.isVariable() &&
1142 "empty or invalid DIVariable passed to dbg.value");
Devang Patel746660f2010-12-07 23:25:47 +00001143 if (!ValueFn)
1144 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1145
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001146 Value *Args[] = {MDNode::get(V->getContext(), V),
1147 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1148 VarInfo, Expr};
Jay Foad5bd375a2011-07-15 08:37:34 +00001149 return CallInst::Create(ValueFn, Args, "", InsertBefore);
Devang Patel746660f2010-12-07 23:25:47 +00001150}
1151
Devang Patel9b412732011-02-22 18:56:12 +00001152Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Devang Patel746660f2010-12-07 23:25:47 +00001153 DIVariable VarInfo,
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001154 DIExpression Expr,
Devang Patel746660f2010-12-07 23:25:47 +00001155 BasicBlock *InsertAtEnd) {
1156 assert(V && "no value passed to dbg.value");
Manman Ren9822a112013-06-29 05:01:19 +00001157 assert(VarInfo.isVariable() &&
1158 "empty or invalid DIVariable passed to dbg.value");
Devang Patel746660f2010-12-07 23:25:47 +00001159 if (!ValueFn)
1160 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1161
Adrian Prantl87b7eb92014-10-01 18:55:02 +00001162 Value *Args[] = {MDNode::get(V->getContext(), V),
1163 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
1164 VarInfo, Expr};
Jay Foad5bd375a2011-07-15 08:37:34 +00001165 return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
Devang Patel746660f2010-12-07 23:25:47 +00001166}