blob: f23f280c978ac9b1d5c1c44c228c11650678f647 [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 {
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000028 /// \brief Whether there are any fields yet.
29 ///
30 /// Note that this is not equivalent to \c Chars.empty(), since \a concat()
31 /// may have been called already with an empty string.
32 bool IsEmpty;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000033 SmallVector<char, 256> Chars;
34
35public:
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000036 HeaderBuilder() : IsEmpty(true) {}
37 HeaderBuilder(const HeaderBuilder &X) : IsEmpty(X.IsEmpty), Chars(X.Chars) {}
38 HeaderBuilder(HeaderBuilder &&X)
39 : IsEmpty(X.IsEmpty), Chars(std::move(X.Chars)) {}
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000040
41 template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000042 if (IsEmpty)
43 IsEmpty = false;
44 else
45 Chars.push_back(0);
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000046 Twine(X).toVector(Chars);
47 return *this;
48 }
49
50 MDString *get(LLVMContext &Context) const {
51 return MDString::get(Context, StringRef(Chars.begin(), Chars.size()));
52 }
53
54 static HeaderBuilder get(unsigned Tag) {
Duncan P. N. Exon Smithaa687a32015-01-20 05:02:42 +000055 return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag));
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +000056 }
57};
Alexander Kornienkof00654e2015-06-23 09:49:53 +000058}
Devang Patel63f83cd2010-12-07 23:58:00 +000059
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000060DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
Craig Topperc6207612014-04-09 06:08:46 +000061 : M(m), VMContext(M.getContext()), TempEnumTypes(nullptr),
62 TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(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() {
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +000077 TempEnumTypes->replaceAllUsesWith(MDTuple::get(VMContext, AllEnumTypes));
Devang Pateleb1bb4e2011-08-16 22:09:43 +000078
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000079 SmallVector<Metadata *, 16> RetainValues;
Manman Ren0b410402013-08-29 23:17:54 +000080 // Declarations and definitions of the same type may be retained. Some
81 // clients RAUW these pairs, leaving duplicates in the retained types
82 // list. Use a set to remove the duplicates while we transform the
83 // TrackingVHs back into Values.
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000084 SmallPtrSet<Metadata *, 16> RetainSet;
Manman Ren0b410402013-08-29 23:17:54 +000085 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
David Blaikie70573dc2014-11-19 07:49:26 +000086 if (RetainSet.insert(AllRetainTypes[I]).second)
Manman Ren0b410402013-08-29 23:17:54 +000087 RetainValues.push_back(AllRetainTypes[I]);
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +000088 TempRetainTypes->replaceAllUsesWith(MDTuple::get(VMContext, RetainValues));
Devang Pateleb1bb4e2011-08-16 22:09:43 +000089
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000090 DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +000091 TempSubprograms->replaceAllUsesWith(SPs.get());
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +000092 for (auto *SP : SPs) {
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +000093 if (MDTuple *Temp = SP->getVariables().get()) {
Benjamin Kramer6cd780f2015-02-17 15:29:18 +000094 const auto &PV = PreservedVariables.lookup(SP);
95 SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000096 DINodeArray AV = getOrCreateArray(Variables);
Duncan P. N. Exon Smith457bfc72015-04-10 18:01:58 +000097 TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
Eric Christopher27deb262012-04-23 19:00:11 +000098 }
Devang Patel59e27c52011-08-19 23:28:12 +000099 }
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000100
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000101 TempGVs->replaceAllUsesWith(MDTuple::get(VMContext, AllGVs));
David Blaikief55abea2013-04-22 06:12:31 +0000102
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000103 TempImportedModules->replaceAllUsesWith(MDTuple::get(
104 VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
105 AllImportedModules.end())));
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000106
107 // Now that all temp nodes have been replaced or deleted, resolve remaining
108 // cycles.
109 for (const auto &N : UnresolvedNodes)
Duncan P. N. Exon Smith2bc00f42015-01-19 23:13:14 +0000110 if (N && !N->isResolved())
111 N->resolveCycles();
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000112 UnresolvedNodes.clear();
113
114 // Can't handle unresolved nodes anymore.
115 AllowUnresolvedNodes = false;
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000116}
117
Duncan P. N. Exon Smith379e3752014-10-01 21:32:15 +0000118/// If N is compile unit return NULL otherwise return N.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000119static DIScope *getNonCompileUnitScope(DIScope *N) {
120 if (!N || isa<DICompileUnit>(N))
Craig Topperc6207612014-04-09 06:08:46 +0000121 return nullptr;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000122 return cast<DIScope>(N);
Devang Patel2b8acaf2011-08-15 23:00:00 +0000123}
124
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000125DICompileUnit *DIBuilder::createCompileUnit(
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000126 unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer,
127 bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
Adrian Prantl1f599f92015-05-21 20:37:30 +0000128 DebugEmissionKind Kind, uint64_t DWOId, bool EmitDebugInfo) {
Eric Christopher75d49db2014-02-27 01:24:56 +0000129
Bruce Mitchener7e575ed2015-02-07 06:35:30 +0000130 assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
Chandler Carruth4c0ee742012-01-10 18:18:52 +0000131 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
132 "Invalid Language tag");
133 assert(!Filename.empty() &&
134 "Unable to create compile unit without filename");
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000135
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000136 // TODO: Once we make DICompileUnit distinct, stop using temporaries here
Duncan P. N. Exon Smithb93569d2015-02-12 21:52:11 +0000137 // (just start with operands assigned to nullptr).
Duncan P. N. Exon Smith457bfc72015-04-10 18:01:58 +0000138 TempEnumTypes = MDTuple::getTemporary(VMContext, None);
139 TempRetainTypes = MDTuple::getTemporary(VMContext, None);
140 TempSubprograms = MDTuple::getTemporary(VMContext, None);
141 TempGVs = MDTuple::getTemporary(VMContext, None);
142 TempImportedModules = MDTuple::getTemporary(VMContext, None);
David Blaikief55abea2013-04-22 06:12:31 +0000143
Duncan P. N. Exon Smithb93569d2015-02-12 21:52:11 +0000144 // TODO: Switch to getDistinct(). We never want to merge compile units based
145 // on contents.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000146 DICompileUnit *CUNode = DICompileUnit::get(
147 VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer,
Duncan P. N. Exon Smith457bfc72015-04-10 18:01:58 +0000148 isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes.get(),
149 TempRetainTypes.get(), TempSubprograms.get(), TempGVs.get(),
Adrian Prantl1f599f92015-05-21 20:37:30 +0000150 TempImportedModules.get(), DWOId);
Devang Patel09fa69e2011-05-03 16:18:28 +0000151
152 // Create a named metadata so that it is easier to find cu in a module.
Diego Novillo56653fd2014-06-24 17:02:03 +0000153 // Note that we only generate this when the caller wants to actually
154 // emit debug information. When we are only interested in tracking
155 // source line locations throughout the backend, we prevent codegen from
156 // emitting debug info in the final output by not generating llvm.dbg.cu.
157 if (EmitDebugInfo) {
158 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
159 NMD->addOperand(CUNode);
160 }
Eric Christopher03b3e112013-07-19 00:51:47 +0000161
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000162 trackIfUnresolved(CUNode);
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000163 return CUNode;
Devang Patel57c5a202010-11-04 15:01:38 +0000164}
165
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000166static DIImportedEntity *
167createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000168 Metadata *NS, unsigned Line, StringRef Name,
169 SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000170 auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name);
Duncan P. N. Exon Smithde8e4272015-04-14 01:46:44 +0000171 AllImportedModules.emplace_back(M);
David Blaikie1fd43652013-05-07 21:35:53 +0000172 return M;
173}
174
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000175DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
176 DINamespace *NS,
177 unsigned Line) {
David Blaikie2a40c142014-04-06 06:29:01 +0000178 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
179 Context, NS, Line, StringRef(), AllImportedModules);
David Blaikiee63d5d12013-05-20 22:50:35 +0000180}
181
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000182DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
183 DIImportedEntity *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::createImportedDeclaration(DIScope *Context,
190 DINode *Decl,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000191 unsigned Line,
192 StringRef Name) {
Frederic Riss4aa51ae2014-11-06 17:46:55 +0000193 // Make sure to use the unique identifier based metadata reference for
194 // types that have one.
David Blaikie2a40c142014-04-06 06:29:01 +0000195 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000196 Context, DINodeRef::get(Decl), Line, Name,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000197 AllImportedModules);
David Blaikief55abea2013-04-22 06:12:31 +0000198}
199
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000200DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory) {
201 return DIFile::get(VMContext, Filename, Directory);
Devang Patel57c5a202010-11-04 15:01:38 +0000202}
203
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000204DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000205 assert(!Name.empty() && "Unable to create enumerator without name");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000206 return DIEnumerator::get(VMContext, Val, Name);
Devang Patel57c5a202010-11-04 15:01:38 +0000207}
208
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000209DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
Devang Patel04d6d472011-09-14 23:13:28 +0000210 assert(!Name.empty() && "Unable to create type without name");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000211 return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
Devang Patel04d6d472011-09-14 23:13:28 +0000212}
213
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000214DIBasicType *DIBuilder::createNullPtrType() {
Peter Collingbournea4a47cb2013-06-27 22:50:59 +0000215 return createUnspecifiedType("decltype(nullptr)");
216}
217
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000218DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000219 uint64_t AlignInBits,
220 unsigned Encoding) {
Devang Patel1ad1abe2011-09-12 18:26:08 +0000221 assert(!Name.empty() && "Unable to create type without name");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000222 return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000223 AlignInBits, Encoding);
Devang Patel57c5a202010-11-04 15:01:38 +0000224}
225
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000226DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
227 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
228 DITypeRef::get(FromTy), 0, 0, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000229}
230
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000231DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000232 uint64_t SizeInBits,
233 uint64_t AlignInBits,
234 StringRef Name) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000235 // FIXME: Why is there a name here?
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000236 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
237 nullptr, 0, nullptr, DITypeRef::get(PointeeTy),
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000238 SizeInBits, AlignInBits, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000239}
240
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000241DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
242 DIType *Base,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000243 uint64_t SizeInBits,
244 uint64_t AlignInBits) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000245 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
246 nullptr, 0, nullptr, DITypeRef::get(PointeeTy),
247 SizeInBits, AlignInBits, 0, 0,
248 DITypeRef::get(Base));
David Blaikie5d3249b2013-01-07 05:51:15 +0000249}
250
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000251DIDerivedType *DIBuilder::createReferenceType(unsigned Tag, DIType *RTy) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000252 assert(RTy && "Unable to create reference type");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000253 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
254 DITypeRef::get(RTy), 0, 0, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000255}
256
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000257DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
258 DIFile *File, unsigned LineNo,
259 DIScope *Context) {
260 return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000261 LineNo,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000262 DIScopeRef::get(getNonCompileUnitScope(Context)),
263 DITypeRef::get(Ty), 0, 0, 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000264}
265
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000266DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000267 assert(Ty && "Invalid type!");
268 assert(FriendTy && "Invalid friend type!");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000269 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
270 DITypeRef::get(Ty), DITypeRef::get(FriendTy), 0, 0,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000271 0, 0);
Devang Patel57c5a202010-11-04 15:01:38 +0000272}
273
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000274DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000275 uint64_t BaseOffset,
276 unsigned Flags) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000277 assert(Ty && "Unable to create inheritance");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000278 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
279 0, DITypeRef::get(Ty), DITypeRef::get(BaseTy), 0, 0,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000280 BaseOffset, Flags);
Devang Patel57c5a202010-11-04 15:01:38 +0000281}
282
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000283DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
284 DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000285 uint64_t SizeInBits,
286 uint64_t AlignInBits,
287 uint64_t OffsetInBits,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000288 unsigned Flags, DIType *Ty) {
289 return DIDerivedType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000290 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000291 DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty),
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000292 SizeInBits, AlignInBits, OffsetInBits, Flags);
Devang Patel57c5a202010-11-04 15:01:38 +0000293}
294
Duncan P. N. Exon Smith3cd2cab2015-03-27 00:34:10 +0000295static ConstantAsMetadata *getConstantOrNull(Constant *C) {
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000296 if (C)
297 return ConstantAsMetadata::get(C);
298 return nullptr;
299}
300
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000301DIDerivedType *DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name,
302 DIFile *File,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000303 unsigned LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000304 DIType *Ty, unsigned Flags,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000305 llvm::Constant *Val) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000306 Flags |= DINode::FlagStaticMember;
307 return DIDerivedType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000308 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000309 DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty), 0, 0,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000310 0, Flags, getConstantOrNull(Val));
Eric Christopher4d23a4a2013-01-16 01:22:23 +0000311}
312
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000313DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000314 unsigned LineNumber,
315 uint64_t SizeInBits,
316 uint64_t AlignInBits,
317 uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000318 DIType *Ty, MDNode *PropertyNode) {
319 return DIDerivedType::get(
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000320 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000321 DIScopeRef::get(getNonCompileUnitScope(File)), DITypeRef::get(Ty),
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000322 SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode);
Devang Patel44882172012-02-06 17:49:43 +0000323}
324
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000325DIObjCProperty *
326DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
Eric Christopher98f9c232013-10-15 23:31:31 +0000327 StringRef GetterName, StringRef SetterName,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000328 unsigned PropertyAttributes, DIType *Ty) {
329 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
Adrian Prantl8ff53b32015-06-15 23:18:03 +0000330 SetterName, PropertyAttributes,
331 DITypeRef::get(Ty));
Devang Patelcc481592012-02-04 00:59:25 +0000332}
333
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334DITemplateTypeParameter *
335DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name,
336 DIType *Ty) {
337 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
338 return DITemplateTypeParameter::get(VMContext, Name, DITypeRef::get(Ty));
Devang Patel3a9e65e2011-02-02 21:38:25 +0000339}
340
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000341static DITemplateValueParameter *
Duncan P. N. Exon Smithb4aa16f2015-02-13 03:35:29 +0000342createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000343 DIScope *Context, StringRef Name, DIType *Ty,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000344 Metadata *MD) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000345 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
346 return DITemplateValueParameter::get(VMContext, Tag, Name, DITypeRef::get(Ty),
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000347 MD);
Devang Patelbe933b42011-02-02 22:35:53 +0000348}
349
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000350DITemplateValueParameter *
351DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name,
352 DIType *Ty, Constant *Val) {
Duncan P. N. Exon Smith774951f2014-11-15 00:05:04 +0000353 return createTemplateValueParameterHelper(
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000354 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
Duncan P. N. Exon Smithb4aa16f2015-02-13 03:35:29 +0000355 getConstantOrNull(Val));
David Blaikie2b380232013-06-22 18:59:11 +0000356}
357
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000358DITemplateValueParameter *
359DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
360 DIType *Ty, StringRef Val) {
Duncan P. N. Exon Smith774951f2014-11-15 00:05:04 +0000361 return createTemplateValueParameterHelper(
362 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
Duncan P. N. Exon Smithb4aa16f2015-02-13 03:35:29 +0000363 MDString::get(VMContext, Val));
David Blaikie2b380232013-06-22 18:59:11 +0000364}
365
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000366DITemplateValueParameter *
367DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name,
368 DIType *Ty, DINodeArray Val) {
Duncan P. N. Exon Smith774951f2014-11-15 00:05:04 +0000369 return createTemplateValueParameterHelper(
370 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +0000371 Val.get());
David Blaikie2b380232013-06-22 18:59:11 +0000372}
373
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000374DICompositeType *DIBuilder::createClassType(
375 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000376 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000377 unsigned Flags, DIType *DerivedFrom, DINodeArray Elements,
378 DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
379 assert((!Context || isa<DIScope>(Context)) &&
David Blaikie085abe32013-03-11 23:21:19 +0000380 "createClassType should be called with a valid Context");
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000381
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000382 auto *R = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000383 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000384 DIScopeRef::get(getNonCompileUnitScope(Context)),
385 DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags,
386 Elements, 0, DITypeRef::get(VTableHolder),
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000387 cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
Manman Ren0b410402013-08-29 23:17:54 +0000388 if (!UniqueIdentifier.empty())
389 retainType(R);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000390 trackIfUnresolved(R);
David Blaikie085abe32013-03-11 23:21:19 +0000391 return R;
Eric Christopher17426692012-07-06 02:35:57 +0000392}
393
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000394DICompositeType *DIBuilder::createStructType(
395 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000396 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000397 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
398 DIType *VTableHolder, StringRef UniqueIdentifier) {
399 auto *R = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000400 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000401 DIScopeRef::get(getNonCompileUnitScope(Context)),
402 DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements,
403 RunTimeLang, DITypeRef::get(VTableHolder), nullptr, UniqueIdentifier);
Manman Ren0b410402013-08-29 23:17:54 +0000404 if (!UniqueIdentifier.empty())
405 retainType(R);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000406 trackIfUnresolved(R);
David Blaikie085abe32013-03-11 23:21:19 +0000407 return R;
Devang Patel746660f2010-12-07 23:25:47 +0000408}
409
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000410DICompositeType *DIBuilder::createUnionType(
411 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
Duncan P. N. Exon Smithaa861aa2015-04-21 20:07:38 +0000412 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000413 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
414 auto *R = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000415 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000416 DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000417 AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
418 UniqueIdentifier);
Manman Ren0b410402013-08-29 23:17:54 +0000419 if (!UniqueIdentifier.empty())
420 retainType(R);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000421 trackIfUnresolved(R);
Manman Ren0b410402013-08-29 23:17:54 +0000422 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000423}
424
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000425DISubroutineType *DIBuilder::createSubroutineType(DIFile *File,
426 DITypeRefArray ParameterTypes,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000427 unsigned Flags) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000428 return DISubroutineType::get(VMContext, Flags, ParameterTypes);
Devang Patel89ea4f22010-12-08 01:50:15 +0000429}
430
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000431DICompositeType *DIBuilder::createEnumerationType(
432 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
433 uint64_t SizeInBits, uint64_t AlignInBits, DINodeArray Elements,
434 DIType *UnderlyingType, StringRef UniqueIdentifier) {
435 auto *CTy = DICompositeType::get(
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000436 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000437 DIScopeRef::get(getNonCompileUnitScope(Scope)),
438 DITypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000439 0, nullptr, nullptr, UniqueIdentifier);
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000440 AllEnumTypes.push_back(CTy);
Manman Ren0b410402013-08-29 23:17:54 +0000441 if (!UniqueIdentifier.empty())
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000442 retainType(CTy);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000443 trackIfUnresolved(CTy);
David Blaikie4f6bf27a2013-11-18 23:33:32 +0000444 return CTy;
Devang Patel89ea4f22010-12-08 01:50:15 +0000445}
446
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000447DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
448 DIType *Ty,
449 DINodeArray Subscripts) {
450 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
451 nullptr, 0, nullptr, DITypeRef::get(Ty), Size,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000452 AlignInBits, 0, 0, Subscripts, 0, nullptr);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000453 trackIfUnresolved(R);
454 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000455}
456
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000457DICompositeType *DIBuilder::createVectorType(uint64_t Size,
458 uint64_t AlignInBits, DIType *Ty,
459 DINodeArray Subscripts) {
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000460 auto *R =
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000461 DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
462 nullptr, DITypeRef::get(Ty), Size, AlignInBits, 0,
463 DINode::FlagVector, Subscripts, 0, nullptr);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000464 trackIfUnresolved(R);
465 return R;
Devang Patel89ea4f22010-12-08 01:50:15 +0000466}
Devang Patel746660f2010-12-07 23:25:47 +0000467
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000468static DIType *createTypeWithFlags(LLVMContext &Context, DIType *Ty,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000469 unsigned FlagsToSet) {
470 auto NewTy = Ty->clone();
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000471 NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
472 return MDNode::replaceWithUniqued(std::move(NewTy));
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000473}
474
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000475DIType *DIBuilder::createArtificialType(DIType *Ty) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000476 // FIXME: Restrict this to the nodes where it's valid.
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000477 if (Ty->isArtificial())
Devang Patel57c5a202010-11-04 15:01:38 +0000478 return Ty;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000479 return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial);
Devang Patel57c5a202010-11-04 15:01:38 +0000480}
Devang Patel746660f2010-12-07 23:25:47 +0000481
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000482DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000483 // FIXME: Restrict this to the nodes where it's valid.
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000484 if (Ty->isObjectPointer())
Eric Christophere3417762012-09-12 23:36:19 +0000485 return Ty;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000486 unsigned Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
Duncan P. N. Exon Smith176b6912014-10-03 20:01:09 +0000487 return createTypeWithFlags(VMContext, Ty, Flags);
Eric Christophere3417762012-09-12 23:36:19 +0000488}
489
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000490void DIBuilder::retainType(DIType *T) {
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000491 assert(T && "Expected non-null type");
Duncan P. N. Exon Smithd9ccfb92015-03-27 23:00:49 +0000492 AllRetainTypes.emplace_back(T);
493}
Devang Patel89ea4f22010-12-08 01:50:15 +0000494
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000495DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
Devang Patel89ea4f22010-12-08 01:50:15 +0000496
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000497DICompositeType *
498DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
499 DIFile *F, unsigned Line, unsigned RuntimeLang,
Eric Christopher98f9c232013-10-15 23:31:31 +0000500 uint64_t SizeInBits, uint64_t AlignInBits,
501 StringRef UniqueIdentifier) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000502 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
503 // replaceWithUniqued().
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000504 auto *RetTy = DICompositeType::get(
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000505 VMContext, Tag, Name, F, Line,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000506 DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
507 AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000508 nullptr, UniqueIdentifier);
David Blaikied3f094a2014-05-06 03:41:57 +0000509 if (!UniqueIdentifier.empty())
510 retainType(RetTy);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000511 trackIfUnresolved(RetTy);
David Blaikied3f094a2014-05-06 03:41:57 +0000512 return RetTy;
513}
514
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000515DICompositeType *DIBuilder::createReplaceableCompositeType(
516 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
David Blaikied3f094a2014-05-06 03:41:57 +0000517 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
Adrian Prantl534a81a2015-02-11 17:45:05 +0000518 unsigned Flags, StringRef UniqueIdentifier) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000519 auto *RetTy = DICompositeType::getTemporary(
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000520 VMContext, Tag, Name, F, Line,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000521 DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000522 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000523 nullptr, nullptr, UniqueIdentifier)
524 .release();
Manman Ren0b410402013-08-29 23:17:54 +0000525 if (!UniqueIdentifier.empty())
526 retainType(RetTy);
Adrian Prantlea7f1c22015-02-17 19:17:39 +0000527 trackIfUnresolved(RetTy);
Manman Rend0e67aa2013-07-02 18:37:35 +0000528 return RetTy;
Eric Christopherae56eec2012-02-08 00:22:26 +0000529}
530
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000531DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000532 return MDTuple::get(VMContext, Elements);
Devang Patel746660f2010-12-07 23:25:47 +0000533}
534
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000535DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000536 SmallVector<llvm::Metadata *, 16> Elts;
Manman Ren1a125c92014-07-28 19:33:20 +0000537 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
538 if (Elements[i] && isa<MDNode>(Elements[i]))
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000539 Elts.push_back(DITypeRef::get(cast<DIType>(Elements[i])));
Manman Ren1a125c92014-07-28 19:33:20 +0000540 else
541 Elts.push_back(Elements[i]);
542 }
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000543 return DITypeRefArray(MDNode::get(VMContext, Elts));
Manman Ren1a125c92014-07-28 19:33:20 +0000544}
545
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000546DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
547 return DISubrange::get(VMContext, Count, Lo);
Devang Patel89ea4f22010-12-08 01:50:15 +0000548}
549
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000550static void checkGlobalVariableScope(DIScope *Context) {
Duncan P. N. Exon Smith430220f2015-04-06 23:34:41 +0000551#ifndef NDEBUG
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000552 if (auto *CT =
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000553 dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000554 assert(CT->getIdentifier().empty() &&
Manman Renbfd2b8292014-11-21 19:47:48 +0000555 "Context of a global variable should not be a type with identifier");
Duncan P. N. Exon Smith430220f2015-04-06 23:34:41 +0000556#endif
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000557}
558
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000559DIGlobalVariable *DIBuilder::createGlobalVariable(
560 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
561 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, Constant *Val,
Duncan P. N. Exon Smithdbf64acd2014-11-15 00:23:49 +0000562 MDNode *Decl) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000563 checkGlobalVariableScope(Context);
564
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000565 auto *N = DIGlobalVariable::get(VMContext, cast_or_null<DIScope>(Context),
Duncan P. N. Exon Smithb273d062015-04-16 01:37:00 +0000566 Name, LinkageName, F, LineNumber,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000567 DITypeRef::get(Ty), isLocalToUnit, true, Val,
568 cast_or_null<DIDerivedType>(Decl));
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000569 AllGVs.push_back(N);
570 return N;
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000571}
572
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000573DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
574 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
575 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, Constant *Val,
Duncan P. N. Exon Smithdbf64acd2014-11-15 00:23:49 +0000576 MDNode *Decl) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000577 checkGlobalVariableScope(Context);
578
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000579 return DIGlobalVariable::getTemporary(
580 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
581 LineNumber, DITypeRef::get(Ty), isLocalToUnit, false, Val,
582 cast_or_null<DIDerivedType>(Decl))
Duncan P. N. Exon Smithb273d062015-04-16 01:37:00 +0000583 .release();
Devang Patel746660f2010-12-07 23:25:47 +0000584}
585
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000586DILocalVariable *DIBuilder::createLocalVariable(
587 unsigned Tag, DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
588 DIType *Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000589 // FIXME: Why getNonCompileUnitScope()?
590 // FIXME: Why is "!Context" okay here?
591 // FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT
592 // the only valid scopes)?
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000593 DIScope *Context = getNonCompileUnitScope(Scope);
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000594
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000595 auto *Node = DILocalVariable::get(
596 VMContext, Tag, cast_or_null<DILocalScope>(Context), Name, File, LineNo,
597 DITypeRef::get(Ty), ArgNo, Flags);
Devang Patel63f83cd2010-12-07 23:58:00 +0000598 if (AlwaysPreserve) {
599 // The optimizer may remove local variable. If there is an interest
600 // to preserve variable info in such situation then stash it in a
601 // named mdnode.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000602 DISubprogram *Fn = getDISubprogram(Scope);
Duncan P. N. Exon Smith3bfffde2014-10-15 16:11:41 +0000603 assert(Fn && "Missing subprogram for local variable");
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000604 PreservedVariables[Fn].emplace_back(Node);
Devang Patel63f83cd2010-12-07 23:58:00 +0000605 }
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000606 return Node;
Devang Patel63f83cd2010-12-07 23:58:00 +0000607}
608
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000609DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
610 return DIExpression::get(VMContext, Addr);
Devang Patel746660f2010-12-07 23:25:47 +0000611}
612
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000613DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
Duncan P. N. Exon Smithbd75ad42015-02-09 22:13:27 +0000614 // TODO: Remove the callers of this signed version and delete.
615 SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
616 return createExpression(Addr);
617}
618
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000619DIExpression *DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
620 unsigned SizeInBytes) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000621 uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000622 return DIExpression::get(VMContext, Addr);
Duncan P. N. Exon Smith9affbba2014-10-01 21:32:12 +0000623}
624
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000625DISubprogram *DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
626 StringRef LinkageName, DIFile *File,
627 unsigned LineNo, DISubroutineType *Ty,
Duncan P. N. Exon Smith848af382015-04-20 18:20:03 +0000628 bool isLocalToUnit, bool isDefinition,
629 unsigned ScopeLine, unsigned Flags,
630 bool isOptimized, Function *Fn,
631 MDNode *TParams, MDNode *Decl) {
Manman Renc50fa112013-10-10 18:40:01 +0000632 // dragonegg does not generate identifier for types, so using an empty map
633 // to resolve the context should be fine.
634 DITypeIdentifierMap EmptyMap;
635 return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File,
636 LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
637 Flags, isOptimized, Fn, TParams, Decl);
638}
639
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000640DISubprogram *DIBuilder::createFunction(DIScope *Context, StringRef Name,
641 StringRef LinkageName, DIFile *File,
642 unsigned LineNo, DISubroutineType *Ty,
643 bool isLocalToUnit, bool isDefinition,
644 unsigned ScopeLine, unsigned Flags,
645 bool isOptimized, Function *Fn,
646 MDNode *TParams, MDNode *Decl) {
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000647 assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000648 "function types should be subroutines");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000649 auto *Node = DISubprogram::get(
650 VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name,
651 LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
652 nullptr, 0, 0, Flags, isOptimized, Fn, cast_or_null<MDTuple>(TParams),
653 cast_or_null<DISubprogram>(Decl),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000654 MDTuple::getTemporary(VMContext, None).release());
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000655
656 if (isDefinition)
657 AllSubprograms.push_back(Node);
658 trackIfUnresolved(Node);
659 return Node;
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000660}
661
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000662DISubprogram *DIBuilder::createTempFunctionFwdDecl(
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 Function *Fn, MDNode *TParams, MDNode *Decl) {
667 return DISubprogram::getTemporary(
668 VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name,
669 LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition,
670 ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
671 cast_or_null<MDTuple>(TParams), cast_or_null<DISubprogram>(Decl),
672 nullptr)
673 .release();
Frederic Riss5e6bc9e2014-09-17 09:28:34 +0000674}
675
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000676DISubprogram *
677DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName,
678 DIFile *F, unsigned LineNo, DISubroutineType *Ty,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000679 bool isLocalToUnit, bool isDefinition, unsigned VK,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000680 unsigned VIndex, DIType *VTableHolder, unsigned Flags,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000681 bool isOptimized, Function *Fn, MDNode *TParam) {
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000682 assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
David Blaikie5174c842013-05-22 23:22:18 +0000683 "function types should be subroutines");
Eric Christopher5cb56322013-10-15 23:31:36 +0000684 assert(getNonCompileUnitScope(Context) &&
685 "Methods should have both a Context and a context that isn't "
686 "the compile unit.");
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000687 // FIXME: Do we want to use different scope/lines?
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000688 auto *SP = DISubprogram::get(
689 VMContext, DIScopeRef::get(cast<DIScope>(Context)), Name, LinkageName, F,
Duncan P. N. Exon Smith02083532015-04-16 16:36:23 +0000690 LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000691 DITypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn,
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000692 cast_or_null<MDTuple>(TParam), nullptr, nullptr);
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000693
David Blaikie595eb442013-02-18 07:10:22 +0000694 if (isDefinition)
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000695 AllSubprograms.push_back(SP);
696 trackIfUnresolved(SP);
697 return SP;
Devang Patelb68c6232010-12-08 20:42:44 +0000698}
699
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000700DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
701 DIFile *File, unsigned LineNo) {
702 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name,
Duncan P. N. Exon Smitha5099dc2015-04-06 19:49:39 +0000703 LineNo);
Devang Patel746660f2010-12-07 23:25:47 +0000704}
705
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000706DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,
707 DIFile *File,
708 unsigned Discriminator) {
709 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
Eric Christopher6647b832011-10-11 22:59:11 +0000710}
711
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000712DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
713 unsigned Line, unsigned Col) {
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000714 // Make these distinct, to avoid merging two lexical blocks on the same
715 // file/line/column.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000716 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
Duncan P. N. Exon Smith35ef22c2015-04-15 23:19:27 +0000717 File, Line, Col);
Devang Patel89ea4f22010-12-08 01:50:15 +0000718}
719
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000720static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
721 assert(V && "no value passed to dbg intrinsic");
722 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
723}
724
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000725static Instruction *withDebugLoc(Instruction *I, const DILocation *DL) {
726 I->setDebugLoc(const_cast<DILocation *>(DL));
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000727 return I;
728}
729
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000730Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
731 DIExpression *Expr, const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000732 Instruction *InsertBefore) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000733 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000734 assert(DL && "Expected debug loc");
735 assert(DL->getScope()->getSubprogram() ==
736 VarInfo->getScope()->getSubprogram() &&
737 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000738 if (!DeclareFn)
739 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
740
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000741 trackIfUnresolved(VarInfo);
742 trackIfUnresolved(Expr);
743 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
744 MetadataAsValue::get(VMContext, VarInfo),
745 MetadataAsValue::get(VMContext, Expr)};
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000746 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000747}
748
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000749Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
750 DIExpression *Expr, const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000751 BasicBlock *InsertAtEnd) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000752 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000753 assert(DL && "Expected debug loc");
754 assert(DL->getScope()->getSubprogram() ==
755 VarInfo->getScope()->getSubprogram() &&
756 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000757 if (!DeclareFn)
758 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
759
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000760 trackIfUnresolved(VarInfo);
761 trackIfUnresolved(Expr);
762 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
763 MetadataAsValue::get(VMContext, VarInfo),
764 MetadataAsValue::get(VMContext, Expr)};
Devang Patel746660f2010-12-07 23:25:47 +0000765
766 // If this block already has a terminator then insert this intrinsic
767 // before the terminator.
768 if (TerminatorInst *T = InsertAtEnd->getTerminator())
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000769 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL);
770 return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000771}
772
Devang Patel9b412732011-02-22 18:56:12 +0000773Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000774 DILocalVariable *VarInfo,
775 DIExpression *Expr,
776 const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000777 Instruction *InsertBefore) {
778 assert(V && "no value passed to dbg.value");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000779 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000780 assert(DL && "Expected debug loc");
781 assert(DL->getScope()->getSubprogram() ==
782 VarInfo->getScope()->getSubprogram() &&
783 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000784 if (!ValueFn)
785 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
786
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000787 trackIfUnresolved(VarInfo);
788 trackIfUnresolved(Expr);
789 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
790 ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
791 MetadataAsValue::get(VMContext, VarInfo),
792 MetadataAsValue::get(VMContext, Expr)};
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000793 return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000794}
795
Devang Patel9b412732011-02-22 18:56:12 +0000796Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000797 DILocalVariable *VarInfo,
798 DIExpression *Expr,
799 const DILocation *DL,
Devang Patel746660f2010-12-07 23:25:47 +0000800 BasicBlock *InsertAtEnd) {
801 assert(V && "no value passed to dbg.value");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000802 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000803 assert(DL && "Expected debug loc");
804 assert(DL->getScope()->getSubprogram() ==
805 VarInfo->getScope()->getSubprogram() &&
806 "Expected matching subprograms");
Devang Patel746660f2010-12-07 23:25:47 +0000807 if (!ValueFn)
808 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
809
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000810 trackIfUnresolved(VarInfo);
811 trackIfUnresolved(Expr);
812 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
813 ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
814 MetadataAsValue::get(VMContext, VarInfo),
815 MetadataAsValue::get(VMContext, Expr)};
Duncan P. N. Exon Smithcd1aecf2015-04-15 21:18:07 +0000816
817 return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
Devang Patel746660f2010-12-07 23:25:47 +0000818}
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000819
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000820void DIBuilder::replaceVTableHolder(DICompositeType *&T,
821 DICompositeType *VTableHolder) {
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000822 {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000823 TypedTrackingMDRef<DICompositeType> N(T);
824 N->replaceVTableHolder(DITypeRef::get(VTableHolder));
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000825 T = N.get();
826 }
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000827
828 // If this didn't create a self-reference, just return.
829 if (T != VTableHolder)
830 return;
831
Adrian Prantl18a25b02015-02-11 17:45:10 +0000832 // Look for unresolved operands. T will drop RAUW support, orphaning any
833 // cycles underneath it.
834 if (T->isResolved())
835 for (const MDOperand &O : T->operands())
836 if (auto *N = dyn_cast_or_null<MDNode>(O))
837 trackIfUnresolved(N);
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000838}
839
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000840void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
841 DINodeArray TParams) {
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000842 {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000843 TypedTrackingMDRef<DICompositeType> N(T);
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000844 if (Elements)
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000845 N->replaceElements(Elements);
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000846 if (TParams)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000847 N->replaceTemplateParams(DITemplateParameterArray(TParams));
Duncan P. N. Exon Smith8d33fdc2015-04-07 04:12:02 +0000848 T = N.get();
849 }
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000850
851 // If T isn't resolved, there's no problem.
852 if (!T->isResolved())
853 return;
854
855 // If "T" is resolved, it may be due to a self-reference cycle. Track the
856 // arrays explicitly if they're unresolved, or else the cycles will be
857 // orphaned.
858 if (Elements)
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +0000859 trackIfUnresolved(Elements.get());
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000860 if (TParams)
Duncan P. N. Exon Smith11344732015-04-07 16:50:39 +0000861 trackIfUnresolved(TParams.get());
Duncan P. N. Exon Smith97f07c22014-12-18 00:46:16 +0000862}