Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 1 | //===--- 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 Carruth | 12664a0 | 2014-03-06 00:22:06 +0000 | [diff] [blame] | 14 | #include "llvm/IR/DIBuilder.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Constants.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 17 | #include "llvm/IR/DebugInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/IntrinsicInst.h" |
| 19 | #include "llvm/IR/Module.h" |
Eric Christopher | 3416419 | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Dwarf.h" |
Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame^] | 22 | #include "LLVMContextImpl.h" |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
| 25 | using namespace llvm::dwarf; |
| 26 | |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 27 | namespace { |
| 28 | class HeaderBuilder { |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 29 | /// \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 Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 34 | SmallVector<char, 256> Chars; |
| 35 | |
| 36 | public: |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 37 | 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 Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 41 | |
| 42 | template <class Twineable> HeaderBuilder &concat(Twineable &&X) { |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 43 | if (IsEmpty) |
| 44 | IsEmpty = false; |
| 45 | else |
| 46 | Chars.push_back(0); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 47 | 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 Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 56 | return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag)); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 57 | } |
| 58 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 59 | } |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 60 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 61 | DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes) |
Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 62 | : M(m), VMContext(M.getContext()), CUNode(nullptr), |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 63 | DeclareFn(nullptr), ValueFn(nullptr), |
| 64 | AllowUnresolvedNodes(AllowUnresolvedNodes) {} |
| 65 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 66 | void DIBuilder::trackIfUnresolved(MDNode *N) { |
Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 67 | if (!N) |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 68 | return; |
Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 69 | if (N->isResolved()) |
| 70 | return; |
| 71 | |
| 72 | assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes"); |
| 73 | UnresolvedNodes.emplace_back(N); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 74 | } |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 75 | |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 76 | void DIBuilder::finalize() { |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 77 | if (!CUNode) { |
| 78 | assert(!AllowUnresolvedNodes && |
| 79 | "creating type nodes without a CU is not supported"); |
| 80 | return; |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 81 | } |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 82 | |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 83 | 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 Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 94 | |
| 95 | if (!RetainValues.empty()) |
| 96 | CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 97 | |
| 98 | DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); |
Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 99 | if (!AllSubprograms.empty()) |
| 100 | CUNode->replaceSubprograms(SPs.get()); |
| 101 | |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 102 | for (auto *SP : SPs) { |
| 103 | if (MDTuple *Temp = SP->getVariables().get()) { |
| 104 | const auto &PV = PreservedVariables.lookup(SP); |
| 105 | SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end()); |
| 106 | DINodeArray AV = getOrCreateArray(Variables); |
| 107 | TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); |
| 108 | } |
| 109 | } |
| 110 | |
Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 111 | if (!AllGVs.empty()) |
| 112 | CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 113 | |
Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 114 | if (!AllImportedModules.empty()) |
| 115 | CUNode->replaceImportedEntities(MDTuple::get( |
| 116 | VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), |
| 117 | AllImportedModules.end()))); |
Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 118 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 119 | // Now that all temp nodes have been replaced or deleted, resolve remaining |
| 120 | // cycles. |
| 121 | for (const auto &N : UnresolvedNodes) |
Duncan P. N. Exon Smith | 2bc00f4 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 122 | if (N && !N->isResolved()) |
| 123 | N->resolveCycles(); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 124 | UnresolvedNodes.clear(); |
| 125 | |
| 126 | // Can't handle unresolved nodes anymore. |
| 127 | AllowUnresolvedNodes = false; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Duncan P. N. Exon Smith | 379e375 | 2014-10-01 21:32:15 +0000 | [diff] [blame] | 130 | /// If N is compile unit return NULL otherwise return N. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 131 | static DIScope *getNonCompileUnitScope(DIScope *N) { |
| 132 | if (!N || isa<DICompileUnit>(N)) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 133 | return nullptr; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 134 | return cast<DIScope>(N); |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 137 | DICompileUnit *DIBuilder::createCompileUnit( |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 138 | unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer, |
| 139 | bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName, |
Adrian Prantl | 1f599f9 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 140 | DebugEmissionKind Kind, uint64_t DWOId, bool EmitDebugInfo) { |
Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 141 | |
Bruce Mitchener | 7e575ed | 2015-02-07 06:35:30 +0000 | [diff] [blame] | 142 | assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || |
Chandler Carruth | 4c0ee74 | 2012-01-10 18:18:52 +0000 | [diff] [blame] | 143 | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
| 144 | "Invalid Language tag"); |
| 145 | assert(!Filename.empty() && |
| 146 | "Unable to create compile unit without filename"); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 147 | |
Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 148 | assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); |
| 149 | CUNode = DICompileUnit::getDistinct( |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 150 | VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer, |
Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 151 | isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 152 | nullptr, nullptr, nullptr, nullptr, nullptr, DWOId); |
Devang Patel | 09fa69e | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 153 | |
| 154 | // Create a named metadata so that it is easier to find cu in a module. |
Diego Novillo | 56653fd | 2014-06-24 17:02:03 +0000 | [diff] [blame] | 155 | // Note that we only generate this when the caller wants to actually |
| 156 | // emit debug information. When we are only interested in tracking |
| 157 | // source line locations throughout the backend, we prevent codegen from |
| 158 | // emitting debug info in the final output by not generating llvm.dbg.cu. |
| 159 | if (EmitDebugInfo) { |
| 160 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
| 161 | NMD->addOperand(CUNode); |
| 162 | } |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 163 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 164 | trackIfUnresolved(CUNode); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 165 | return CUNode; |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 168 | static DIImportedEntity * |
| 169 | createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 170 | Metadata *NS, unsigned Line, StringRef Name, |
| 171 | SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { |
Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame^] | 172 | unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 173 | auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name); |
Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame^] | 174 | if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) |
| 175 | // A new Imported Entity was just added to the context. |
| 176 | // Add it to the Imported Modules list. |
| 177 | AllImportedModules.emplace_back(M); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 178 | return M; |
| 179 | } |
| 180 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 181 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
| 182 | DINamespace *NS, |
| 183 | unsigned Line) { |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 184 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 185 | Context, NS, Line, StringRef(), AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 188 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
| 189 | DIImportedEntity *NS, |
| 190 | unsigned Line) { |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 191 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 192 | Context, NS, Line, StringRef(), AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 195 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M, |
| 196 | unsigned Line) { |
| 197 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 198 | Context, M, Line, StringRef(), AllImportedModules); |
| 199 | } |
| 200 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 201 | DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, |
| 202 | DINode *Decl, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 203 | unsigned Line, |
| 204 | StringRef Name) { |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 205 | // Make sure to use the unique identifier based metadata reference for |
| 206 | // types that have one. |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 207 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 208 | Context, DINodeRef::get(Decl), Line, Name, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 209 | AllImportedModules); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 212 | DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory) { |
| 213 | return DIFile::get(VMContext, Filename, Directory); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 216 | DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 217 | assert(!Name.empty() && "Unable to create enumerator without name"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 218 | return DIEnumerator::get(VMContext, Val, Name); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 221 | DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) { |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 222 | assert(!Name.empty() && "Unable to create type without name"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 223 | return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 226 | DIBasicType *DIBuilder::createNullPtrType() { |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 227 | return createUnspecifiedType("decltype(nullptr)"); |
| 228 | } |
| 229 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 230 | DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 231 | uint64_t AlignInBits, |
| 232 | unsigned Encoding) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 233 | assert(!Name.empty() && "Unable to create type without name"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 234 | return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 235 | AlignInBits, Encoding); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 238 | DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { |
| 239 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, |
| 240 | DITypeRef::get(FromTy), 0, 0, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 243 | DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 244 | uint64_t SizeInBits, |
| 245 | uint64_t AlignInBits, |
| 246 | StringRef Name) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 247 | // FIXME: Why is there a name here? |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 248 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, |
| 249 | nullptr, 0, nullptr, DITypeRef::get(PointeeTy), |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 250 | SizeInBits, AlignInBits, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 253 | DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, |
| 254 | DIType *Base, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 255 | uint64_t SizeInBits, |
| 256 | uint64_t AlignInBits) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 257 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", |
| 258 | nullptr, 0, nullptr, DITypeRef::get(PointeeTy), |
| 259 | SizeInBits, AlignInBits, 0, 0, |
| 260 | DITypeRef::get(Base)); |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Keno Fischer | b011c63 | 2015-11-16 07:57:32 +0000 | [diff] [blame] | 263 | DIDerivedType *DIBuilder::createReferenceType(unsigned Tag, DIType *RTy, |
| 264 | uint64_t SizeInBits, |
| 265 | uint64_t AlignInBits) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 266 | assert(RTy && "Unable to create reference type"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 267 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, |
Keno Fischer | b011c63 | 2015-11-16 07:57:32 +0000 | [diff] [blame] | 268 | DITypeRef::get(RTy), SizeInBits, AlignInBits, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 271 | DIDerivedType *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 Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 275 | LineNo, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 276 | DIScopeRef::get(getNonCompileUnitScope(Context)), |
| 277 | DITypeRef::get(Ty), 0, 0, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 280 | DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 281 | assert(Ty && "Invalid type!"); |
| 282 | assert(FriendTy && "Invalid friend type!"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 283 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, |
| 284 | DITypeRef::get(Ty), DITypeRef::get(FriendTy), 0, 0, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 285 | 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 288 | DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 289 | uint64_t BaseOffset, |
| 290 | unsigned Flags) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 291 | assert(Ty && "Unable to create inheritance"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 292 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, |
| 293 | 0, DITypeRef::get(Ty), DITypeRef::get(BaseTy), 0, 0, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 294 | BaseOffset, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 297 | DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, |
| 298 | DIFile *File, unsigned LineNumber, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 299 | uint64_t SizeInBits, |
| 300 | uint64_t AlignInBits, |
| 301 | uint64_t OffsetInBits, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 302 | unsigned Flags, DIType *Ty) { |
| 303 | return DIDerivedType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 304 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 305 | DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty), |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 306 | SizeInBits, AlignInBits, OffsetInBits, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 309 | static ConstantAsMetadata *getConstantOrNull(Constant *C) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 310 | if (C) |
| 311 | return ConstantAsMetadata::get(C); |
| 312 | return nullptr; |
| 313 | } |
| 314 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 315 | DIDerivedType *DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, |
| 316 | DIFile *File, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 317 | unsigned LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 318 | DIType *Ty, unsigned Flags, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 319 | llvm::Constant *Val) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 320 | Flags |= DINode::FlagStaticMember; |
| 321 | return DIDerivedType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 322 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 323 | DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty), 0, 0, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 324 | 0, Flags, getConstantOrNull(Val)); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 327 | DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 328 | unsigned LineNumber, |
| 329 | uint64_t SizeInBits, |
| 330 | uint64_t AlignInBits, |
| 331 | uint64_t OffsetInBits, unsigned Flags, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 332 | DIType *Ty, MDNode *PropertyNode) { |
| 333 | return DIDerivedType::get( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 334 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 335 | DIScopeRef::get(getNonCompileUnitScope(File)), DITypeRef::get(Ty), |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 336 | SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 339 | DIObjCProperty * |
| 340 | DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 341 | StringRef GetterName, StringRef SetterName, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 342 | unsigned PropertyAttributes, DIType *Ty) { |
| 343 | return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, |
Adrian Prantl | 8ff53b3 | 2015-06-15 23:18:03 +0000 | [diff] [blame] | 344 | SetterName, PropertyAttributes, |
| 345 | DITypeRef::get(Ty)); |
Devang Patel | cc48159 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 348 | DITemplateTypeParameter * |
| 349 | DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name, |
| 350 | DIType *Ty) { |
| 351 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
| 352 | return DITemplateTypeParameter::get(VMContext, Name, DITypeRef::get(Ty)); |
Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 355 | static DITemplateValueParameter * |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 356 | createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 357 | DIScope *Context, StringRef Name, DIType *Ty, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 358 | Metadata *MD) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 359 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
| 360 | return DITemplateValueParameter::get(VMContext, Tag, Name, DITypeRef::get(Ty), |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 361 | MD); |
Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 364 | DITemplateValueParameter * |
| 365 | DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name, |
| 366 | DIType *Ty, Constant *Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 367 | return createTemplateValueParameterHelper( |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 368 | VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 369 | getConstantOrNull(Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 372 | DITemplateValueParameter * |
| 373 | DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name, |
| 374 | DIType *Ty, StringRef Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 375 | return createTemplateValueParameterHelper( |
| 376 | VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 377 | MDString::get(VMContext, Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 380 | DITemplateValueParameter * |
| 381 | DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name, |
| 382 | DIType *Ty, DINodeArray Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 383 | return createTemplateValueParameterHelper( |
| 384 | VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty, |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 385 | Val.get()); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 388 | DICompositeType *DIBuilder::createClassType( |
| 389 | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 390 | uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 391 | unsigned Flags, DIType *DerivedFrom, DINodeArray Elements, |
| 392 | DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) { |
| 393 | assert((!Context || isa<DIScope>(Context)) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 394 | "createClassType should be called with a valid Context"); |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 395 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 396 | auto *R = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 397 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 398 | DIScopeRef::get(getNonCompileUnitScope(Context)), |
| 399 | DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags, |
| 400 | Elements, 0, DITypeRef::get(VTableHolder), |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 401 | cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 402 | if (!UniqueIdentifier.empty()) |
| 403 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 404 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 405 | return R; |
Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 408 | DICompositeType *DIBuilder::createStructType( |
| 409 | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 410 | uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 411 | DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang, |
| 412 | DIType *VTableHolder, StringRef UniqueIdentifier) { |
| 413 | auto *R = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 414 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 415 | DIScopeRef::get(getNonCompileUnitScope(Context)), |
| 416 | DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements, |
| 417 | RunTimeLang, DITypeRef::get(VTableHolder), nullptr, UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 418 | if (!UniqueIdentifier.empty()) |
| 419 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 420 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 421 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 424 | DICompositeType *DIBuilder::createUnionType( |
| 425 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
Duncan P. N. Exon Smith | aa861aa | 2015-04-21 20:07:38 +0000 | [diff] [blame] | 426 | uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 427 | DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) { |
| 428 | auto *R = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 429 | VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 430 | DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 431 | AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr, |
| 432 | UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 433 | if (!UniqueIdentifier.empty()) |
| 434 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 435 | trackIfUnresolved(R); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 436 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Eric Christopher | bdafb3c | 2015-10-15 06:56:10 +0000 | [diff] [blame] | 439 | DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 440 | unsigned Flags) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 441 | return DISubroutineType::get(VMContext, Flags, ParameterTypes); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Adrian Prantl | ee5feaf | 2015-07-15 17:01:41 +0000 | [diff] [blame] | 444 | DICompositeType *DIBuilder::createExternalTypeRef(unsigned Tag, DIFile *File, |
| 445 | StringRef UniqueIdentifier) { |
| 446 | assert(!UniqueIdentifier.empty() && "external type ref without uid"); |
| 447 | auto *CTy = |
| 448 | DICompositeType::get(VMContext, Tag, "", nullptr, 0, nullptr, nullptr, 0, |
| 449 | 0, 0, DINode::FlagExternalTypeRef, nullptr, 0, |
| 450 | nullptr, nullptr, UniqueIdentifier); |
| 451 | // Types with unique IDs need to be in the type map. |
| 452 | retainType(CTy); |
| 453 | return CTy; |
| 454 | } |
| 455 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 456 | DICompositeType *DIBuilder::createEnumerationType( |
| 457 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| 458 | uint64_t SizeInBits, uint64_t AlignInBits, DINodeArray Elements, |
| 459 | DIType *UnderlyingType, StringRef UniqueIdentifier) { |
| 460 | auto *CTy = DICompositeType::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 461 | VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 462 | DIScopeRef::get(getNonCompileUnitScope(Scope)), |
| 463 | DITypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 464 | 0, nullptr, nullptr, UniqueIdentifier); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 465 | AllEnumTypes.push_back(CTy); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 466 | if (!UniqueIdentifier.empty()) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 467 | retainType(CTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 468 | trackIfUnresolved(CTy); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 469 | return CTy; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 472 | DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, |
| 473 | DIType *Ty, |
| 474 | DINodeArray Subscripts) { |
| 475 | auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
| 476 | nullptr, 0, nullptr, DITypeRef::get(Ty), Size, |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 477 | AlignInBits, 0, 0, Subscripts, 0, nullptr); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 478 | trackIfUnresolved(R); |
| 479 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 482 | DICompositeType *DIBuilder::createVectorType(uint64_t Size, |
| 483 | uint64_t AlignInBits, DIType *Ty, |
| 484 | DINodeArray Subscripts) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 485 | auto *R = |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 486 | DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, |
| 487 | nullptr, DITypeRef::get(Ty), Size, AlignInBits, 0, |
| 488 | DINode::FlagVector, Subscripts, 0, nullptr); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 489 | trackIfUnresolved(R); |
| 490 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 491 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 492 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 493 | static DIType *createTypeWithFlags(LLVMContext &Context, DIType *Ty, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 494 | unsigned FlagsToSet) { |
| 495 | auto NewTy = Ty->clone(); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 496 | NewTy->setFlags(NewTy->getFlags() | FlagsToSet); |
| 497 | return MDNode::replaceWithUniqued(std::move(NewTy)); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 500 | DIType *DIBuilder::createArtificialType(DIType *Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 501 | // FIXME: Restrict this to the nodes where it's valid. |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 502 | if (Ty->isArtificial()) |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 503 | return Ty; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 504 | return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 505 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 506 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 507 | DIType *DIBuilder::createObjectPointerType(DIType *Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 508 | // FIXME: Restrict this to the nodes where it's valid. |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 509 | if (Ty->isObjectPointer()) |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 510 | return Ty; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 511 | unsigned Flags = DINode::FlagObjectPointer | DINode::FlagArtificial; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 512 | return createTypeWithFlags(VMContext, Ty, Flags); |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 515 | void DIBuilder::retainType(DIType *T) { |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 516 | assert(T && "Expected non-null type"); |
Duncan P. N. Exon Smith | d9ccfb9 | 2015-03-27 23:00:49 +0000 | [diff] [blame] | 517 | AllRetainTypes.emplace_back(T); |
| 518 | } |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 519 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 520 | DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; } |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 521 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 522 | DICompositeType * |
| 523 | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, |
| 524 | DIFile *F, unsigned Line, unsigned RuntimeLang, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 525 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 526 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 527 | // FIXME: Define in terms of createReplaceableForwardDecl() by calling |
| 528 | // replaceWithUniqued(). |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 529 | auto *RetTy = DICompositeType::get( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 530 | VMContext, Tag, Name, F, Line, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 531 | DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits, |
| 532 | AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, nullptr, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 533 | nullptr, UniqueIdentifier); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 534 | if (!UniqueIdentifier.empty()) |
| 535 | retainType(RetTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 536 | trackIfUnresolved(RetTy); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 537 | return RetTy; |
| 538 | } |
| 539 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 540 | DICompositeType *DIBuilder::createReplaceableCompositeType( |
| 541 | unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 542 | unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, |
Adrian Prantl | 534a81a | 2015-02-11 17:45:05 +0000 | [diff] [blame] | 543 | unsigned Flags, StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 544 | auto *RetTy = DICompositeType::getTemporary( |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 545 | VMContext, Tag, Name, F, Line, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 546 | DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 547 | SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 548 | nullptr, nullptr, UniqueIdentifier) |
| 549 | .release(); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 550 | if (!UniqueIdentifier.empty()) |
| 551 | retainType(RetTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 552 | trackIfUnresolved(RetTy); |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 553 | return RetTy; |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 556 | DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 557 | return MDTuple::get(VMContext, Elements); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 560 | DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 561 | SmallVector<llvm::Metadata *, 16> Elts; |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 562 | for (unsigned i = 0, e = Elements.size(); i != e; ++i) { |
| 563 | if (Elements[i] && isa<MDNode>(Elements[i])) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 564 | Elts.push_back(DITypeRef::get(cast<DIType>(Elements[i]))); |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 565 | else |
| 566 | Elts.push_back(Elements[i]); |
| 567 | } |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 568 | return DITypeRefArray(MDNode::get(VMContext, Elts)); |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 571 | DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
| 572 | return DISubrange::get(VMContext, Count, Lo); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 575 | static void checkGlobalVariableScope(DIScope *Context) { |
Duncan P. N. Exon Smith | 430220f | 2015-04-06 23:34:41 +0000 | [diff] [blame] | 576 | #ifndef NDEBUG |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 577 | if (auto *CT = |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 578 | dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context))) |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 579 | assert(CT->getIdentifier().empty() && |
Manman Ren | bfd2b829 | 2014-11-21 19:47:48 +0000 | [diff] [blame] | 580 | "Context of a global variable should not be a type with identifier"); |
Duncan P. N. Exon Smith | 430220f | 2015-04-06 23:34:41 +0000 | [diff] [blame] | 581 | #endif |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 584 | DIGlobalVariable *DIBuilder::createGlobalVariable( |
| 585 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
| 586 | unsigned LineNumber, DIType *Ty, bool isLocalToUnit, Constant *Val, |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 587 | MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 588 | checkGlobalVariableScope(Context); |
| 589 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 590 | auto *N = DIGlobalVariable::get(VMContext, cast_or_null<DIScope>(Context), |
Duncan P. N. Exon Smith | b273d06 | 2015-04-16 01:37:00 +0000 | [diff] [blame] | 591 | Name, LinkageName, F, LineNumber, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 592 | DITypeRef::get(Ty), isLocalToUnit, true, Val, |
| 593 | cast_or_null<DIDerivedType>(Decl)); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 594 | AllGVs.push_back(N); |
| 595 | return N; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 598 | DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( |
| 599 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
| 600 | unsigned LineNumber, DIType *Ty, bool isLocalToUnit, Constant *Val, |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 601 | MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 602 | checkGlobalVariableScope(Context); |
| 603 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 604 | return DIGlobalVariable::getTemporary( |
| 605 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
| 606 | LineNumber, DITypeRef::get(Ty), isLocalToUnit, false, Val, |
| 607 | cast_or_null<DIDerivedType>(Decl)) |
Duncan P. N. Exon Smith | b273d06 | 2015-04-16 01:37:00 +0000 | [diff] [blame] | 608 | .release(); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 611 | static DILocalVariable *createLocalVariable( |
| 612 | LLVMContext &VMContext, |
| 613 | DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> &PreservedVariables, |
| 614 | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
| 615 | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 616 | // FIXME: Why getNonCompileUnitScope()? |
| 617 | // FIXME: Why is "!Context" okay here? |
Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 618 | // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 619 | // the only valid scopes)? |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 620 | DIScope *Context = getNonCompileUnitScope(Scope); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 621 | |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 622 | auto *Node = |
| 623 | DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, |
| 624 | File, LineNo, DITypeRef::get(Ty), ArgNo, Flags); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 625 | if (AlwaysPreserve) { |
Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 626 | // The optimizer may remove local variables. If there is an interest |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 627 | // to preserve variable info in such situation then stash it in a |
| 628 | // named mdnode. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 629 | DISubprogram *Fn = getDISubprogram(Scope); |
Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 630 | assert(Fn && "Missing subprogram for local variable"); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 631 | PreservedVariables[Fn].emplace_back(Node); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 632 | } |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 633 | return Node; |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 636 | DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, |
| 637 | DIFile *File, unsigned LineNo, |
| 638 | DIType *Ty, bool AlwaysPreserve, |
| 639 | unsigned Flags) { |
| 640 | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, |
| 641 | /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, |
| 642 | Flags); |
| 643 | } |
| 644 | |
| 645 | DILocalVariable *DIBuilder::createParameterVariable( |
| 646 | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
| 647 | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) { |
| 648 | assert(ArgNo && "Expected non-zero argument number for parameter"); |
| 649 | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, |
| 650 | File, LineNo, Ty, AlwaysPreserve, Flags); |
| 651 | } |
| 652 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 653 | DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { |
| 654 | return DIExpression::get(VMContext, Addr); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 657 | DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) { |
Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 658 | // TODO: Remove the callers of this signed version and delete. |
| 659 | SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); |
| 660 | return createExpression(Addr); |
| 661 | } |
| 662 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 663 | DIExpression *DIBuilder::createBitPieceExpression(unsigned OffsetInBytes, |
| 664 | unsigned SizeInBytes) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 665 | uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 666 | return DIExpression::get(VMContext, Addr); |
Duncan P. N. Exon Smith | 9affbba | 2014-10-01 21:32:12 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 669 | DISubprogram *DIBuilder::createFunction( |
| 670 | DIScopeRef Context, StringRef Name, StringRef LinkageName, DIFile *File, |
| 671 | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
| 672 | bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized, |
| 673 | DITemplateParameterArray TParams, DISubprogram *Decl) { |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 674 | // dragonegg does not generate identifier for types, so using an empty map |
| 675 | // to resolve the context should be fine. |
| 676 | DITypeIdentifierMap EmptyMap; |
| 677 | return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File, |
| 678 | LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 679 | Flags, isOptimized, TParams, Decl); |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Duncan P. N. Exon Smith | b2df647 | 2015-08-26 22:50:16 +0000 | [diff] [blame] | 682 | template <class... Ts> |
| 683 | static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { |
| 684 | if (IsDistinct) |
| 685 | return DISubprogram::getDistinct(std::forward<Ts>(Args)...); |
| 686 | return DISubprogram::get(std::forward<Ts>(Args)...); |
| 687 | } |
| 688 | |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 689 | DISubprogram *DIBuilder::createFunction( |
| 690 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
| 691 | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
| 692 | bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized, |
| 693 | DITemplateParameterArray TParams, DISubprogram *Decl) { |
| 694 | auto *Node = |
| 695 | getSubprogram(/* IsDistinct = */ isDefinition, VMContext, |
| 696 | DIScopeRef::get(getNonCompileUnitScope(Context)), Name, |
| 697 | LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition, |
| 698 | ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl, |
| 699 | MDTuple::getTemporary(VMContext, None).release()); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 700 | |
| 701 | if (isDefinition) |
| 702 | AllSubprograms.push_back(Node); |
| 703 | trackIfUnresolved(Node); |
| 704 | return Node; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 707 | DISubprogram *DIBuilder::createTempFunctionFwdDecl( |
| 708 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
| 709 | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
| 710 | bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized, |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 711 | DITemplateParameterArray TParams, DISubprogram *Decl) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 712 | return DISubprogram::getTemporary( |
| 713 | VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name, |
| 714 | LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition, |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 715 | ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 716 | nullptr) |
| 717 | .release(); |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 720 | DISubprogram * |
| 721 | DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName, |
| 722 | DIFile *F, unsigned LineNo, DISubroutineType *Ty, |
Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 723 | bool isLocalToUnit, bool isDefinition, unsigned VK, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 724 | unsigned VIndex, DIType *VTableHolder, unsigned Flags, |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 725 | bool isOptimized, DITemplateParameterArray TParams) { |
Eric Christopher | 5cb5632 | 2013-10-15 23:31:36 +0000 | [diff] [blame] | 726 | assert(getNonCompileUnitScope(Context) && |
| 727 | "Methods should have both a Context and a context that isn't " |
| 728 | "the compile unit."); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 729 | // FIXME: Do we want to use different scope/lines? |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 730 | auto *SP = getSubprogram( |
| 731 | /* IsDistinct = */ isDefinition, VMContext, |
| 732 | DIScopeRef::get(cast<DIScope>(Context)), Name, LinkageName, F, LineNo, Ty, |
| 733 | isLocalToUnit, isDefinition, LineNo, DITypeRef::get(VTableHolder), VK, |
| 734 | VIndex, Flags, isOptimized, TParams, nullptr, nullptr); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 735 | |
David Blaikie | 595eb44 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 736 | if (isDefinition) |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 737 | AllSubprograms.push_back(SP); |
| 738 | trackIfUnresolved(SP); |
| 739 | return SP; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 742 | DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, |
| 743 | DIFile *File, unsigned LineNo) { |
| 744 | return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name, |
Duncan P. N. Exon Smith | a5099dc | 2015-04-06 19:49:39 +0000 | [diff] [blame] | 745 | LineNo); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 748 | DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, |
| 749 | StringRef ConfigurationMacros, |
| 750 | StringRef IncludePath, |
| 751 | StringRef ISysRoot) { |
| 752 | return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name, |
| 753 | ConfigurationMacros, IncludePath, ISysRoot); |
| 754 | } |
| 755 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 756 | DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope, |
| 757 | DIFile *File, |
| 758 | unsigned Discriminator) { |
| 759 | return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator); |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 762 | DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File, |
| 763 | unsigned Line, unsigned Col) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 764 | // Make these distinct, to avoid merging two lexical blocks on the same |
| 765 | // file/line/column. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 766 | return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), |
Duncan P. N. Exon Smith | 35ef22c | 2015-04-15 23:19:27 +0000 | [diff] [blame] | 767 | File, Line, Col); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 770 | static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { |
| 771 | assert(V && "no value passed to dbg intrinsic"); |
| 772 | return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); |
| 773 | } |
| 774 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 775 | static Instruction *withDebugLoc(Instruction *I, const DILocation *DL) { |
| 776 | I->setDebugLoc(const_cast<DILocation *>(DL)); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 777 | return I; |
| 778 | } |
| 779 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 780 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 781 | DIExpression *Expr, const DILocation *DL, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 782 | Instruction *InsertBefore) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 783 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 784 | assert(DL && "Expected debug loc"); |
| 785 | assert(DL->getScope()->getSubprogram() == |
| 786 | VarInfo->getScope()->getSubprogram() && |
| 787 | "Expected matching subprograms"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 788 | if (!DeclareFn) |
| 789 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 790 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 791 | trackIfUnresolved(VarInfo); |
| 792 | trackIfUnresolved(Expr); |
| 793 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 794 | MetadataAsValue::get(VMContext, VarInfo), |
| 795 | MetadataAsValue::get(VMContext, Expr)}; |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 796 | return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 799 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 800 | DIExpression *Expr, const DILocation *DL, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 801 | BasicBlock *InsertAtEnd) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 802 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 803 | assert(DL && "Expected debug loc"); |
| 804 | assert(DL->getScope()->getSubprogram() == |
| 805 | VarInfo->getScope()->getSubprogram() && |
| 806 | "Expected matching subprograms"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 807 | if (!DeclareFn) |
| 808 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 809 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 810 | trackIfUnresolved(VarInfo); |
| 811 | trackIfUnresolved(Expr); |
| 812 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 813 | MetadataAsValue::get(VMContext, VarInfo), |
| 814 | MetadataAsValue::get(VMContext, Expr)}; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 815 | |
| 816 | // If this block already has a terminator then insert this intrinsic |
| 817 | // before the terminator. |
| 818 | if (TerminatorInst *T = InsertAtEnd->getTerminator()) |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 819 | return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL); |
| 820 | return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 823 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 824 | DILocalVariable *VarInfo, |
| 825 | DIExpression *Expr, |
| 826 | const DILocation *DL, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 827 | Instruction *InsertBefore) { |
| 828 | assert(V && "no value passed to dbg.value"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 829 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 830 | assert(DL && "Expected debug loc"); |
| 831 | assert(DL->getScope()->getSubprogram() == |
| 832 | VarInfo->getScope()->getSubprogram() && |
| 833 | "Expected matching subprograms"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 834 | if (!ValueFn) |
| 835 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 836 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 837 | trackIfUnresolved(VarInfo); |
| 838 | trackIfUnresolved(Expr); |
| 839 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| 840 | ConstantInt::get(Type::getInt64Ty(VMContext), Offset), |
| 841 | MetadataAsValue::get(VMContext, VarInfo), |
| 842 | MetadataAsValue::get(VMContext, Expr)}; |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 843 | return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 846 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 847 | DILocalVariable *VarInfo, |
| 848 | DIExpression *Expr, |
| 849 | const DILocation *DL, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 850 | BasicBlock *InsertAtEnd) { |
| 851 | assert(V && "no value passed to dbg.value"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 852 | assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 853 | assert(DL && "Expected debug loc"); |
| 854 | assert(DL->getScope()->getSubprogram() == |
| 855 | VarInfo->getScope()->getSubprogram() && |
| 856 | "Expected matching subprograms"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 857 | if (!ValueFn) |
| 858 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 859 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 860 | trackIfUnresolved(VarInfo); |
| 861 | trackIfUnresolved(Expr); |
| 862 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| 863 | ConstantInt::get(Type::getInt64Ty(VMContext), Offset), |
| 864 | MetadataAsValue::get(VMContext, VarInfo), |
| 865 | MetadataAsValue::get(VMContext, Expr)}; |
Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 866 | |
| 867 | return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 868 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 869 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 870 | void DIBuilder::replaceVTableHolder(DICompositeType *&T, |
| 871 | DICompositeType *VTableHolder) { |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 872 | { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 873 | TypedTrackingMDRef<DICompositeType> N(T); |
| 874 | N->replaceVTableHolder(DITypeRef::get(VTableHolder)); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 875 | T = N.get(); |
| 876 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 877 | |
| 878 | // If this didn't create a self-reference, just return. |
| 879 | if (T != VTableHolder) |
| 880 | return; |
| 881 | |
Adrian Prantl | 18a25b0 | 2015-02-11 17:45:10 +0000 | [diff] [blame] | 882 | // Look for unresolved operands. T will drop RAUW support, orphaning any |
| 883 | // cycles underneath it. |
| 884 | if (T->isResolved()) |
| 885 | for (const MDOperand &O : T->operands()) |
| 886 | if (auto *N = dyn_cast_or_null<MDNode>(O)) |
| 887 | trackIfUnresolved(N); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 890 | void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements, |
| 891 | DINodeArray TParams) { |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 892 | { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 893 | TypedTrackingMDRef<DICompositeType> N(T); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 894 | if (Elements) |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 895 | N->replaceElements(Elements); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 896 | if (TParams) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 897 | N->replaceTemplateParams(DITemplateParameterArray(TParams)); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 898 | T = N.get(); |
| 899 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 900 | |
| 901 | // If T isn't resolved, there's no problem. |
| 902 | if (!T->isResolved()) |
| 903 | return; |
| 904 | |
Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 905 | // If T is resolved, it may be due to a self-reference cycle. Track the |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 906 | // arrays explicitly if they're unresolved, or else the cycles will be |
| 907 | // orphaned. |
| 908 | if (Elements) |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 909 | trackIfUnresolved(Elements.get()); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 910 | if (TParams) |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 911 | trackIfUnresolved(TParams.get()); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 912 | } |