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