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