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