blob: faf6bf753a9eff95cf21aa4346382aa080145de5 [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"
Amjad Aboud62f6f5c2016-03-13 11:11:39 +000022#include "LLVMContextImpl.h"
Devang Patel57c5a202010-11-04 15:01:38 +000023
24using namespace llvm;
25using namespace llvm::dwarf;
26
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000027namespace {
28class HeaderBuilder {
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000029 /// \brief Whether there are any fields yet.
30 ///
31 /// Note that this is not equivalent to \c Chars.empty(), since \a concat()
32 /// may have been called already with an empty string.
33 bool IsEmpty;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000034 SmallVector<char, 256> Chars;
35
36public:
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000037 HeaderBuilder() : IsEmpty(true) {}
38 HeaderBuilder(const HeaderBuilder &X) : IsEmpty(X.IsEmpty), Chars(X.Chars) {}
39 HeaderBuilder(HeaderBuilder &&X)
40 : IsEmpty(X.IsEmpty), Chars(std::move(X.Chars)) {}
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000041
42 template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000043 if (IsEmpty)
44 IsEmpty = false;
45 else
46 Chars.push_back(0);
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000047 Twine(X).toVector(Chars);
48 return *this;
49 }
50
51 MDString *get(LLVMContext &Context) const {
52 return MDString::get(Context, StringRef(Chars.begin(), Chars.size()));
53 }
54
55 static HeaderBuilder get(unsigned Tag) {
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000056 return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag));
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000057 }
58};
Alexander Kornienkof00654e2015-06-23 09:49:53 +000059}
Devang Patel63f83cd2010-12-07 23:58:00 +000060
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000061DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
Adrian Prantl18c073a2015-07-02 22:32:52 +000062 : M(m), VMContext(M.getContext()), CUNode(nullptr),
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000063 DeclareFn(nullptr), ValueFn(nullptr),
64 AllowUnresolvedNodes(AllowUnresolvedNodes) {}
65
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000066void DIBuilder::trackIfUnresolved(MDNode *N) {
Duncan P. N. Exon Smith9b1c6d32015-01-19 19:09:14 +000067 if (!N)
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000068 return;
Duncan P. N. Exon Smith9b1c6d32015-01-19 19:09:14 +000069 if (N->isResolved())
70 return;
71
72 assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
73 UnresolvedNodes.emplace_back(N);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000074}
Devang Patel57c5a202010-11-04 15:01:38 +000075
Devang Patel2b8acaf2011-08-15 23:00:00 +000076void DIBuilder::finalize() {
Adrian Prantl0e224a62015-07-06 16:22:12 +000077 if (!CUNode) {
78 assert(!AllowUnresolvedNodes &&
79 "creating type nodes without a CU is not supported");
80 return;
Devang Patel59e27c52011-08-19 23:28:12 +000081 }
Devang Pateleb1bb4e2011-08-16 22:09:43 +000082
Adrian Prantl0e224a62015-07-06 16:22:12 +000083 CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
84
85 SmallVector<Metadata *, 16> RetainValues;
86 // Declarations and definitions of the same type may be retained. Some
87 // clients RAUW these pairs, leaving duplicates in the retained types
88 // list. Use a set to remove the duplicates while we transform the
89 // TrackingVHs back into Values.
90 SmallPtrSet<Metadata *, 16> RetainSet;
91 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
92 if (RetainSet.insert(AllRetainTypes[I]).second)
93 RetainValues.push_back(AllRetainTypes[I]);
Adrian Prantl4276d4a2015-07-06 16:36:02 +000094
95 if (!RetainValues.empty())
96 CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
Adrian Prantl0e224a62015-07-06 16:22:12 +000097
98 DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
Adrian Prantl75819ae2016-04-15 15:57:41 +000099 auto resolveVariables = [&](DISubprogram *SP) {
Duncan P. N. Exon Smitha2495d92016-04-20 20:03:59 +0000100 MDTuple *Temp = SP->getVariables().get();
101 if (!Temp)
102 return;
103
104 SmallVector<Metadata *, 4> Variables;
105
106 auto PV = PreservedVariables.find(SP);
107 if (PV != PreservedVariables.end())
108 Variables.append(PV->second.begin(), PV->second.end());
109
110 DINodeArray AV = getOrCreateArray(Variables);
111 TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
Adrian Prantl75819ae2016-04-15 15:57:41 +0000112 };
113 for (auto *SP : SPs)
114 resolveVariables(SP);
115 for (auto *N : RetainValues)
116 if (auto *SP = dyn_cast<DISubprogram>(N))
117 resolveVariables(SP);
Adrian Prantl0e224a62015-07-06 16:22:12 +0000118
Adrian Prantl4276d4a2015-07-06 16:36:02 +0000119 if (!AllGVs.empty())
120 CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
Adrian Prantl0e224a62015-07-06 16:22:12 +0000121
Adrian Prantl4276d4a2015-07-06 16:36:02 +0000122 if (!AllImportedModules.empty())
123 CUNode->replaceImportedEntities(MDTuple::get(
124 VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
125 AllImportedModules.end())));
Adrian Prantl0e224a62015-07-06 16:22:12 +0000126
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000127 // Now that all temp nodes have been replaced or deleted, resolve remaining
128 // cycles.
129 for (const auto &N : UnresolvedNodes)
Duncan P. N. Exon Smith2bc00f42015-01-19 23:13:14 +0000130 if (N && !N->isResolved())
131 N->resolveCycles();
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000132 UnresolvedNodes.clear();
133
134 // Can't handle unresolved nodes anymore.
135 AllowUnresolvedNodes = false;
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000136}
137
Duncan P. N. Exon Smith379e3752014-10-01 21:32:15 +0000138/// If N is compile unit return NULL otherwise return N.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000139static DIScope *getNonCompileUnitScope(DIScope *N) {
140 if (!N || isa<DICompileUnit>(N))
Craig Topperc6207612014-04-09 06:08:46 +0000141 return nullptr;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000142 return cast<DIScope>(N);
Devang Patel2b8acaf2011-08-15 23:00:00 +0000143}
144
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000145DICompileUnit *DIBuilder::createCompileUnit(
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000146 unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer,
147 bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
Adrian Prantl5992a722016-04-08 22:43:03 +0000148 DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId) {
Eric Christopher75d49db2014-02-27 01:24:56 +0000149
Bruce Mitchener7e575ed2015-02-07 06:35:30 +0000150 assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
Chandler Carruth4c0ee742012-01-10 18:18:52 +0000151 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
152 "Invalid Language tag");
153 assert(!Filename.empty() &&
154 "Unable to create compile unit without filename");
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000155
Adrian Prantl18c073a2015-07-02 22:32:52 +0000156 assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
157 CUNode = DICompileUnit::getDistinct(
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000158 VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer,
Adrian Prantl75819ae2016-04-15 15:57:41 +0000159 isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, nullptr,
160 nullptr, nullptr, nullptr, DWOId);
Devang Patel09fa69e2011-05-03 16:18:28 +0000161
162 // Create a named metadata so that it is easier to find cu in a module.
Adrian Prantl5992a722016-04-08 22:43:03 +0000163 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
164 NMD->addOperand(CUNode);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000165 trackIfUnresolved(CUNode);
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000166 return CUNode;
Devang Patel57c5a202010-11-04 15:01:38 +0000167}
168
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000169static DIImportedEntity *
170createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000171 Metadata *NS, unsigned Line, StringRef Name,
172 SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
Amjad Aboud62f6f5c2016-03-13 11:11:39 +0000173 unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000174 auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name);
Amjad Aboud62f6f5c2016-03-13 11:11:39 +0000175 if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
176 // A new Imported Entity was just added to the context.
177 // Add it to the Imported Modules list.
178 AllImportedModules.emplace_back(M);
David Blaikie1fd43652013-05-07 21:35:53 +0000179 return M;
180}
181
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000182DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
183 DINamespace *NS,
184 unsigned Line) {
David Blaikie2a40c142014-04-06 06:29:01 +0000185 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
186 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000187}
188
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000189DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
190 DIImportedEntity *NS,
191 unsigned Line) {
David Blaikie2a40c142014-04-06 06:29:01 +0000192 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
193 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000194}
195
Adrian Prantlab1243f2015-06-29 23:03:47 +0000196DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M,
197 unsigned Line) {
198 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
199 Context, M, Line, StringRef(), AllImportedModules);
200}
201
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000202DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context,
203 DINode *Decl,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000204 unsigned Line,
205 StringRef Name) {
Frederic Riss4aa51ae2014-11-06 17:46:55 +0000206 // Make sure to use the unique identifier based metadata reference for
207 // types that have one.
David Blaikie2a40c142014-04-06 06:29:01 +0000208 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000209 Context, Decl, Line, Name, AllImportedModules);
David Blaikief55abea2013-04-22 06:12:31 +0000210}
211
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000212DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory) {
213 return DIFile::get(VMContext, Filename, Directory);
Devang Patel57c5a202010-11-04 15:01:38 +0000214}
215
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +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");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000218 return DIEnumerator::get(VMContext, Val, Name);
Devang Patel57c5a202010-11-04 15:01:38 +0000219}
220
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000221DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel04d6d472011-09-14 23:13:28 +0000222 assert(!Name.empty() && "Unable to create type without name");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000223 return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
Devang Patel04d6d472011-09-14 23:13:28 +0000224}
225
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000226DIBasicType *DIBuilder::createNullPtrType() {
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000227 return createUnspecifiedType("decltype(nullptr)");
228}
229
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000230DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000231 uint64_t AlignInBits,
232 unsigned Encoding) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000233 assert(!Name.empty() && "Unable to create type without name");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000234 return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000235 AlignInBits, Encoding);
Devang Patel57c5a202010-11-04 15:01:38 +0000236}
237
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000238DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000239 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
240 0, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000241}
242
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000243DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000244 uint64_t SizeInBits,
245 uint64_t AlignInBits,
246 StringRef Name) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000247 // FIXME: Why is there a name here?
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000248 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000249 nullptr, 0, nullptr, PointeeTy, SizeInBits,
250 AlignInBits, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000251}
252
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000253DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
254 DIType *Base,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000255 uint64_t SizeInBits,
Reid Kleckner604105b2016-06-17 21:31:33 +0000256 uint64_t AlignInBits,
257 unsigned Flags) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000258 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000259 nullptr, 0, nullptr, PointeeTy, SizeInBits,
Reid Kleckner604105b2016-06-17 21:31:33 +0000260 AlignInBits, 0, Flags, Base);
David Blaikie5d3249b2013-01-07 05:51:15 +0000261}
262
Keno Fischerb011c632015-11-16 07:57:32 +0000263DIDerivedType *DIBuilder::createReferenceType(unsigned Tag, DIType *RTy,
264 uint64_t SizeInBits,
265 uint64_t AlignInBits) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000266 assert(RTy && "Unable to create reference type");
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000267 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
268 SizeInBits, AlignInBits, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000269}
270
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000271DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
272 DIFile *File, unsigned LineNo,
273 DIScope *Context) {
274 return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000275 LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
276 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000277}
278
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000279DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000280 assert(Ty && "Invalid type!");
281 assert(FriendTy && "Invalid friend type!");
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000282 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
283 FriendTy, 0, 0, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000284}
285
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000286DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000287 uint64_t BaseOffset,
288 unsigned Flags) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000289 assert(Ty && "Unable to create inheritance");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000290 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000291 0, Ty, BaseTy, 0, 0, BaseOffset, Flags);
Devang Patel57c5a202010-11-04 15:01:38 +0000292}
293
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000294DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
295 DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000296 uint64_t SizeInBits,
297 uint64_t AlignInBits,
298 uint64_t OffsetInBits,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000299 unsigned Flags, DIType *Ty) {
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000300 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
301 LineNumber, getNonCompileUnitScope(Scope), Ty,
302 SizeInBits, AlignInBits, OffsetInBits, Flags);
Devang Patel57c5a202010-11-04 15:01:38 +0000303}
304
Duncan P. N. Exon Smith3cd2cab2015-03-27 00:34:10 +0000305static ConstantAsMetadata *getConstantOrNull(Constant *C) {
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000306 if (C)
307 return ConstantAsMetadata::get(C);
308 return nullptr;
309}
310
David Majnemer9319cbc2016-06-30 03:00:20 +0000311DIDerivedType *DIBuilder::createBitFieldMemberType(
312 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
313 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
314 uint64_t StorageOffsetInBits, unsigned Flags, DIType *Ty) {
315 Flags |= DINode::FlagBitField;
316 return DIDerivedType::get(
317 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
318 getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits,
319 Flags, ConstantAsMetadata::get(ConstantInt::get(
320 IntegerType::get(VMContext, 64), StorageOffsetInBits)));
321}
322
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000323DIDerivedType *DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name,
324 DIFile *File,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000325 unsigned LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000326 DIType *Ty, unsigned Flags,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000327 llvm::Constant *Val) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000328 Flags |= DINode::FlagStaticMember;
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000329 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
330 LineNumber, getNonCompileUnitScope(Scope), Ty, 0, 0,
331 0, Flags, getConstantOrNull(Val));
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000332}
333
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000335 unsigned LineNumber,
336 uint64_t SizeInBits,
337 uint64_t AlignInBits,
338 uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000339 DIType *Ty, MDNode *PropertyNode) {
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000340 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
341 LineNumber, getNonCompileUnitScope(File), Ty,
342 SizeInBits, AlignInBits, OffsetInBits, Flags,
343 PropertyNode);
Devang Patel44882172012-02-06 17:49:43 +0000344}
345
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000346DIObjCProperty *
347DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
Eric Christopher98f9c232013-10-15 23:31:31 +0000348 StringRef GetterName, StringRef SetterName,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000349 unsigned PropertyAttributes, DIType *Ty) {
350 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000351 SetterName, PropertyAttributes, Ty);
Devang Patelcc481592012-02-04 00:59:25 +0000352}
353
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000354DITemplateTypeParameter *
355DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name,
356 DIType *Ty) {
357 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000358 return DITemplateTypeParameter::get(VMContext, Name, Ty);
Devang Patel3a9e65e2011-02-02 21:38:25 +0000359}
360
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000361static DITemplateValueParameter *
Duncan P. N. Exon Smithb4aa16f2015-02-13 03:35:29 +0000362createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000363 DIScope *Context, StringRef Name, DIType *Ty,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000364 Metadata *MD) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000365 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000366 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
Devang Patelbe933b42011-02-02 22:35:53 +0000367}
368
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000369DITemplateValueParameter *
370DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name,
371 DIType *Ty, Constant *Val) {
Duncan P. N. Exon Smith774951f2014-11-15 00:05:04 +0000372 return createTemplateValueParameterHelper(
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000373 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
Duncan P. N. Exon Smithb4aa16f2015-02-13 03:35:29 +0000374 getConstantOrNull(Val));
David Blaikie2b380232013-06-22 18:59:11 +0000375}
376
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000377DITemplateValueParameter *
378DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
379 DIType *Ty, StringRef Val) {
Duncan P. N. Exon Smith774951f2014-11-15 00:05:04 +0000380 return createTemplateValueParameterHelper(
381 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
Duncan P. N. Exon Smithb4aa16f2015-02-13 03:35:29 +0000382 MDString::get(VMContext, Val));
David Blaikie2b380232013-06-22 18:59:11 +0000383}
384
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000385DITemplateValueParameter *
386DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name,
387 DIType *Ty, DINodeArray Val) {
Duncan P. N. Exon Smith774951f2014-11-15 00:05:04 +0000388 return createTemplateValueParameterHelper(
389 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +0000390 Val.get());
David Blaikie2b380232013-06-22 18:59:11 +0000391}
392
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000393DICompositeType *DIBuilder::createClassType(
394 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000395 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000396 unsigned Flags, DIType *DerivedFrom, DINodeArray Elements,
397 DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
398 assert((!Context || isa<DIScope>(Context)) &&
David Blaikie085abe32013-03-11 23:21:19 +0000399 "createClassType should be called with a valid Context");
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000400
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000401 auto *R = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000402 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000403 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
404 OffsetInBits, Flags, Elements, 0, VTableHolder,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000405 cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000406 trackIfUnresolved(R);
David Blaikie085abe32013-03-11 23:21:19 +0000407 return R;
Eric Christopher17426692012-07-06 02:35:57 +0000408}
409
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000410DICompositeType *DIBuilder::createStructType(
411 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000412 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000413 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
414 DIType *VTableHolder, StringRef UniqueIdentifier) {
415 auto *R = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000416 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000417 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
418 Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000419 trackIfUnresolved(R);
David Blaikie085abe32013-03-11 23:21:19 +0000420 return R;
Devang Patel746660f2010-12-07 23:25:47 +0000421}
422
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000423DICompositeType *DIBuilder::createUnionType(
424 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smithaa861aa2015-04-21 20:07:38 +0000425 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000426 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
427 auto *R = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000428 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000429 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
430 Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000431 trackIfUnresolved(R);
Manman Ren0b410402013-08-29 23:17:54 +0000432 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000433}
434
Eric Christopherbdafb3c2015-10-15 06:56:10 +0000435DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes,
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000436 unsigned Flags, unsigned CC) {
437 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
Devang Patel89ea4f22010-12-08 01:50:15 +0000438}
439
Adrian Prantlee5feaf2015-07-15 17:01:41 +0000440DICompositeType *DIBuilder::createExternalTypeRef(unsigned Tag, DIFile *File,
441 StringRef UniqueIdentifier) {
442 assert(!UniqueIdentifier.empty() && "external type ref without uid");
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000443 return DICompositeType::get(VMContext, Tag, "", nullptr, 0, nullptr, nullptr,
444 0, 0, 0, DINode::FlagExternalTypeRef, nullptr, 0,
445 nullptr, nullptr, UniqueIdentifier);
Adrian Prantlee5feaf2015-07-15 17:01:41 +0000446}
447
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000448DICompositeType *DIBuilder::createEnumerationType(
449 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
450 uint64_t SizeInBits, uint64_t AlignInBits, DINodeArray Elements,
451 DIType *UnderlyingType, StringRef UniqueIdentifier) {
452 auto *CTy = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000453 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000454 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
455 0, Elements, 0, nullptr, nullptr, UniqueIdentifier);
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000456 AllEnumTypes.push_back(CTy);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000457 trackIfUnresolved(CTy);
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000458 return CTy;
Devang Patel89ea4f22010-12-08 01:50:15 +0000459}
460
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000461DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
462 DIType *Ty,
463 DINodeArray Subscripts) {
464 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000465 nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
466 0, Subscripts, 0, nullptr);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000467 trackIfUnresolved(R);
468 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000469}
470
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000471DICompositeType *DIBuilder::createVectorType(uint64_t Size,
472 uint64_t AlignInBits, DIType *Ty,
473 DINodeArray Subscripts) {
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000474 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
475 nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
476 DINode::FlagVector, Subscripts, 0, nullptr);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000477 trackIfUnresolved(R);
478 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000479}
Devang Patel746660f2010-12-07 23:25:47 +0000480
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000481static DIType *createTypeWithFlags(LLVMContext &Context, DIType *Ty,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000482 unsigned FlagsToSet) {
483 auto NewTy = Ty->clone();
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000484 NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
485 return MDNode::replaceWithUniqued(std::move(NewTy));
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000486}
487
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000488DIType *DIBuilder::createArtificialType(DIType *Ty) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000489 // FIXME: Restrict this to the nodes where it's valid.
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000490 if (Ty->isArtificial())
Devang Patel57c5a202010-11-04 15:01:38 +0000491 return Ty;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000492 return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial);
Devang Patel57c5a202010-11-04 15:01:38 +0000493}
Devang Patel746660f2010-12-07 23:25:47 +0000494
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000495DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000496 // FIXME: Restrict this to the nodes where it's valid.
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000497 if (Ty->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000498 return Ty;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000499 unsigned Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000500 return createTypeWithFlags(VMContext, Ty, Flags);
Eric Christophere3417762012-09-12 23:36:19 +0000501}
502
Adrian Prantl75819ae2016-04-15 15:57:41 +0000503void DIBuilder::retainType(DIScope *T) {
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000504 assert(T && "Expected non-null type");
Adrian Prantl75819ae2016-04-15 15:57:41 +0000505 assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
506 cast<DISubprogram>(T)->isDefinition() == false)) &&
507 "Expected type or subprogram declaration");
Duncan P. N. Exon Smithd9ccfb92015-03-27 23:00:49 +0000508 AllRetainTypes.emplace_back(T);
509}
Devang Patel89ea4f22010-12-08 01:50:15 +0000510
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000511DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
Devang Patel89ea4f22010-12-08 01:50:15 +0000512
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000513DICompositeType *
514DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
515 DIFile *F, unsigned Line, unsigned RuntimeLang,
Eric Christopher98f9c232013-10-15 23:31:31 +0000516 uint64_t SizeInBits, uint64_t AlignInBits,
517 StringRef UniqueIdentifier) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000518 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
519 // replaceWithUniqued().
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000520 auto *RetTy = DICompositeType::get(
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000521 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
522 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
523 nullptr, nullptr, UniqueIdentifier);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000524 trackIfUnresolved(RetTy);
David Blaikied3f094a2014-05-06 03:41:57 +0000525 return RetTy;
526}
527
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000528DICompositeType *DIBuilder::createReplaceableCompositeType(
529 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
David Blaikied3f094a2014-05-06 03:41:57 +0000530 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
Adrian Prantl534a81a2015-02-11 17:45:05 +0000531 unsigned Flags, StringRef UniqueIdentifier) {
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000532 auto *RetTy =
533 DICompositeType::getTemporary(
534 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
535 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
536 nullptr, UniqueIdentifier)
537 .release();
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000538 trackIfUnresolved(RetTy);
Manman Rend0e67aa2013-07-02 18:37:35 +0000539 return RetTy;
Eric Christopherae56eec2012-02-08 00:22:26 +0000540}
541
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000542DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000543 return MDTuple::get(VMContext, Elements);
Devang Patel746660f2010-12-07 23:25:47 +0000544}
545
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000546DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000547 SmallVector<llvm::Metadata *, 16> Elts;
Manman Ren1a125c92014-07-28 19:33:20 +0000548 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
549 if (Elements[i] && isa<MDNode>(Elements[i]))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000550 Elts.push_back(cast<DIType>(Elements[i]));
Manman Ren1a125c92014-07-28 19:33:20 +0000551 else
552 Elts.push_back(Elements[i]);
553 }
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000554 return DITypeRefArray(MDNode::get(VMContext, Elts));
Manman Ren1a125c92014-07-28 19:33:20 +0000555}
556
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000557DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
558 return DISubrange::get(VMContext, Count, Lo);
Devang Patel89ea4f22010-12-08 01:50:15 +0000559}
560
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000561static void checkGlobalVariableScope(DIScope *Context) {
Duncan P. N. Exon Smith430220f2015-04-06 23:34:41 +0000562#ifndef NDEBUG
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000563 if (auto *CT =
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000564 dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000565 assert(CT->getIdentifier().empty() &&
Manman Renbfd2b8292014-11-21 19:47:48 +0000566 "Context of a global variable should not be a type with identifier");
Duncan P. N. Exon Smith430220f2015-04-06 23:34:41 +0000567#endif
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000568}
569
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000570DIGlobalVariable *DIBuilder::createGlobalVariable(
571 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
572 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, Constant *Val,
Duncan P. N. Exon Smithdbf64acd2014-11-15 00:23:49 +0000573 MDNode *Decl) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000574 checkGlobalVariableScope(Context);
575
Duncan P. N. Exon Smithc5225df2016-04-23 22:29:09 +0000576 auto *N = DIGlobalVariable::getDistinct(
577 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
578 LineNumber, Ty, isLocalToUnit, true, Val,
579 cast_or_null<DIDerivedType>(Decl));
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000580 AllGVs.push_back(N);
581 return N;
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000582}
583
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000584DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
585 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
586 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, Constant *Val,
Duncan P. N. Exon Smithdbf64acd2014-11-15 00:23:49 +0000587 MDNode *Decl) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000588 checkGlobalVariableScope(Context);
589
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000590 return DIGlobalVariable::getTemporary(
591 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000592 LineNumber, Ty, isLocalToUnit, false, Val,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000593 cast_or_null<DIDerivedType>(Decl))
Duncan P. N. Exon Smithb273d062015-04-16 01:37:00 +0000594 .release();
Devang Patel746660f2010-12-07 23:25:47 +0000595}
596
Duncan P. N. Exon Smith1e40dc42015-07-31 17:55:53 +0000597static DILocalVariable *createLocalVariable(
598 LLVMContext &VMContext,
Duncan P. N. Exon Smith3c406c22016-04-20 20:14:09 +0000599 DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
Duncan P. N. Exon Smith1e40dc42015-07-31 17:55:53 +0000600 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
601 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000602 // FIXME: Why getNonCompileUnitScope()?
603 // FIXME: Why is "!Context" okay here?
Adrian Prantl12d52842015-07-10 23:26:02 +0000604 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000605 // the only valid scopes)?
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000606 DIScope *Context = getNonCompileUnitScope(Scope);
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000607
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000608 auto *Node =
609 DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000610 File, LineNo, Ty, ArgNo, Flags);
Devang Patel63f83cd2010-12-07 23:58:00 +0000611 if (AlwaysPreserve) {
Adrian Prantl12d52842015-07-10 23:26:02 +0000612 // The optimizer may remove local variables. If there is an interest
Devang Patel63f83cd2010-12-07 23:58:00 +0000613 // to preserve variable info in such situation then stash it in a
614 // named mdnode.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000615 DISubprogram *Fn = getDISubprogram(Scope);
Duncan P. N. Exon Smith3bfffde2014-10-15 16:11:41 +0000616 assert(Fn && "Missing subprogram for local variable");
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000617 PreservedVariables[Fn].emplace_back(Node);
Devang Patel63f83cd2010-12-07 23:58:00 +0000618 }
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000619 return Node;
Devang Patel63f83cd2010-12-07 23:58:00 +0000620}
621
Duncan P. N. Exon Smith1e40dc42015-07-31 17:55:53 +0000622DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
623 DIFile *File, unsigned LineNo,
624 DIType *Ty, bool AlwaysPreserve,
625 unsigned Flags) {
626 return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
627 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
628 Flags);
629}
630
631DILocalVariable *DIBuilder::createParameterVariable(
632 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
633 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) {
634 assert(ArgNo && "Expected non-zero argument number for parameter");
635 return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
636 File, LineNo, Ty, AlwaysPreserve, Flags);
637}
638
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000639DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
640 return DIExpression::get(VMContext, Addr);
Devang Patel746660f2010-12-07 23:25:47 +0000641}
642
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000643DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
Duncan P. N. Exon Smithbd75ad42015-02-09 22:13:27 +0000644 // TODO: Remove the callers of this signed version and delete.
645 SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
646 return createExpression(Addr);
647}
648
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000649DIExpression *DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
650 unsigned SizeInBytes) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000651 uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000652 return DIExpression::get(VMContext, Addr);
Duncan P. N. Exon Smith9affbba2014-10-01 21:32:12 +0000653}
654
Duncan P. N. Exon Smithb2df6472015-08-26 22:50:16 +0000655template <class... Ts>
656static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
657 if (IsDistinct)
658 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
659 return DISubprogram::get(std::forward<Ts>(Args)...);
660}
661
Peter Collingbourned4bff302015-11-05 22:03:56 +0000662DISubprogram *DIBuilder::createFunction(
663 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
664 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
665 bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized,
666 DITemplateParameterArray TParams, DISubprogram *Decl) {
Adrian Prantl75819ae2016-04-15 15:57:41 +0000667 auto *Node = getSubprogram(
668 /* IsDistinct = */ isDefinition, VMContext,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000669 getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000670 isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags,
671 isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
Adrian Prantl75819ae2016-04-15 15:57:41 +0000672 MDTuple::getTemporary(VMContext, None).release());
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000673
674 if (isDefinition)
675 AllSubprograms.push_back(Node);
676 trackIfUnresolved(Node);
677 return Node;
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000678}
679
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000680DISubprogram *DIBuilder::createTempFunctionFwdDecl(
681 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
682 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
683 bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized,
Peter Collingbourned4bff302015-11-05 22:03:56 +0000684 DITemplateParameterArray TParams, DISubprogram *Decl) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000685 return DISubprogram::getTemporary(
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000686 VMContext, getNonCompileUnitScope(Context), Name, LinkageName,
687 File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000688 0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr,
689 TParams, Decl, nullptr)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000690 .release();
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000691}
692
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000693DISubprogram *
694DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName,
695 DIFile *F, unsigned LineNo, DISubroutineType *Ty,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000696 bool isLocalToUnit, bool isDefinition, unsigned VK,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000697 unsigned VIndex, int ThisAdjustment,
698 DIType *VTableHolder, unsigned Flags, bool isOptimized,
699 DITemplateParameterArray TParams) {
Eric Christopher5cb56322013-10-15 23:31:36 +0000700 assert(getNonCompileUnitScope(Context) &&
701 "Methods should have both a Context and a context that isn't "
702 "the compile unit.");
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000703 // FIXME: Do we want to use different scope/lines?
Peter Collingbourned4bff302015-11-05 22:03:56 +0000704 auto *SP = getSubprogram(
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000705 /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name,
706 LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000707 VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized,
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000708 isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr);
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000709
David Blaikie595eb442013-02-18 07:10:22 +0000710 if (isDefinition)
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000711 AllSubprograms.push_back(SP);
712 trackIfUnresolved(SP);
713 return SP;
Devang Patelb68c6232010-12-08 20:42:44 +0000714}
715
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000716DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
717 DIFile *File, unsigned LineNo) {
718 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name,
Duncan P. N. Exon Smitha5099dc2015-04-06 19:49:39 +0000719 LineNo);
Devang Patel746660f2010-12-07 23:25:47 +0000720}
721
Adrian Prantlab1243f2015-06-29 23:03:47 +0000722DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
723 StringRef ConfigurationMacros,
724 StringRef IncludePath,
725 StringRef ISysRoot) {
726 return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
727 ConfigurationMacros, IncludePath, ISysRoot);
728}
729
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000730DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,
731 DIFile *File,
732 unsigned Discriminator) {
733 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
Eric Christopher6647b832011-10-11 22:59:11 +0000734}
735
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000736DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
737 unsigned Line, unsigned Col) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000738 // Make these distinct, to avoid merging two lexical blocks on the same
739 // file/line/column.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000740 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
Duncan P. N. Exon Smith35ef22c2015-04-15 23:19:27 +0000741 File, Line, Col);
Devang Patel89ea4f22010-12-08 01:50:15 +0000742}
743
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000744static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
745 assert(V && "no value passed to dbg intrinsic");
746 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
747}
748
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000749static Instruction *withDebugLoc(Instruction *I, const DILocation *DL) {
750 I->setDebugLoc(const_cast<DILocation *>(DL));
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000751 return I;
752}
753
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000754Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
755 DIExpression *Expr, const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000756 Instruction *InsertBefore) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000757 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000758 assert(DL && "Expected debug loc");
759 assert(DL->getScope()->getSubprogram() ==
760 VarInfo->getScope()->getSubprogram() &&
761 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000762 if (!DeclareFn)
763 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
764
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000765 trackIfUnresolved(VarInfo);
766 trackIfUnresolved(Expr);
767 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
768 MetadataAsValue::get(VMContext, VarInfo),
769 MetadataAsValue::get(VMContext, Expr)};
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000770 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000771}
772
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000773Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
774 DIExpression *Expr, const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000775 BasicBlock *InsertAtEnd) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000776 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000777 assert(DL && "Expected debug loc");
778 assert(DL->getScope()->getSubprogram() ==
779 VarInfo->getScope()->getSubprogram() &&
780 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000781 if (!DeclareFn)
782 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
783
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000784 trackIfUnresolved(VarInfo);
785 trackIfUnresolved(Expr);
786 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
787 MetadataAsValue::get(VMContext, VarInfo),
788 MetadataAsValue::get(VMContext, Expr)};
Devang Patel746660f2010-12-07 23:25:47 +0000789
790 // If this block already has a terminator then insert this intrinsic
791 // before the terminator.
792 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000793 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL);
794 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000795}
796
Devang Patel9b412732011-02-22 18:56:12 +0000797Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000798 DILocalVariable *VarInfo,
799 DIExpression *Expr,
800 const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000801 Instruction *InsertBefore) {
802 assert(V && "no value passed to dbg.value");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000803 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000804 assert(DL && "Expected debug loc");
805 assert(DL->getScope()->getSubprogram() ==
806 VarInfo->getScope()->getSubprogram() &&
807 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000808 if (!ValueFn)
809 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
810
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000811 trackIfUnresolved(VarInfo);
812 trackIfUnresolved(Expr);
813 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
814 ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
815 MetadataAsValue::get(VMContext, VarInfo),
816 MetadataAsValue::get(VMContext, Expr)};
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000817 return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000818}
819
Devang Patel9b412732011-02-22 18:56:12 +0000820Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000821 DILocalVariable *VarInfo,
822 DIExpression *Expr,
823 const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000824 BasicBlock *InsertAtEnd) {
825 assert(V && "no value passed to dbg.value");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000826 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000827 assert(DL && "Expected debug loc");
828 assert(DL->getScope()->getSubprogram() ==
829 VarInfo->getScope()->getSubprogram() &&
830 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000831 if (!ValueFn)
832 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
833
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000834 trackIfUnresolved(VarInfo);
835 trackIfUnresolved(Expr);
836 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
837 ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
838 MetadataAsValue::get(VMContext, VarInfo),
839 MetadataAsValue::get(VMContext, Expr)};
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000840
841 return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000842}
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000843
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000844void DIBuilder::replaceVTableHolder(DICompositeType *&T,
845 DICompositeType *VTableHolder) {
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000846 {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000847 TypedTrackingMDRef<DICompositeType> N(T);
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000848 N->replaceVTableHolder(VTableHolder);
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000849 T = N.get();
850 }
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000851
852 // If this didn't create a self-reference, just return.
853 if (T != VTableHolder)
854 return;
855
Adrian Prantl18a25b02015-02-11 17:45:10 +0000856 // Look for unresolved operands. T will drop RAUW support, orphaning any
857 // cycles underneath it.
858 if (T->isResolved())
859 for (const MDOperand &O : T->operands())
860 if (auto *N = dyn_cast_or_null<MDNode>(O))
861 trackIfUnresolved(N);
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000862}
863
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000864void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
865 DINodeArray TParams) {
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000866 {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000867 TypedTrackingMDRef<DICompositeType> N(T);
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000868 if (Elements)
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000869 N->replaceElements(Elements);
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000870 if (TParams)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000871 N->replaceTemplateParams(DITemplateParameterArray(TParams));
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000872 T = N.get();
873 }
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000874
875 // If T isn't resolved, there's no problem.
876 if (!T->isResolved())
877 return;
878
Adrian Prantl12d52842015-07-10 23:26:02 +0000879 // If T is resolved, it may be due to a self-reference cycle. Track the
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000880 // arrays explicitly if they're unresolved, or else the cycles will be
881 // orphaned.
882 if (Elements)
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +0000883 trackIfUnresolved(Elements.get());
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000884 if (TParams)
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +0000885 trackIfUnresolved(TParams.get());
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000886}