| 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" |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 15 | #include "llvm/IR/IRBuilder.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "LLVMContextImpl.h" |
| Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Optional.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
| Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 19 | #include "llvm/BinaryFormat/Dwarf.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Constants.h" |
| Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DebugInfo.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 22 | #include "llvm/IR/IntrinsicInst.h" |
| 23 | #include "llvm/IR/Module.h" |
| Eric Christopher | 3416419 | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Debug.h" |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace llvm; |
| 27 | using namespace llvm::dwarf; |
| 28 | |
| Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 29 | cl::opt<bool> |
| 30 | UseDbgAddr("use-dbg-addr", |
| Zachary Turner | 8065f0b | 2017-12-01 00:53:10 +0000 | [diff] [blame] | 31 | llvm::cl::desc("Use llvm.dbg.addr for all local variables"), |
| 32 | cl::init(false), cl::Hidden); |
| Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 33 | |
| Jessica Paquette | a499c3c | 2018-01-19 21:21:49 +0000 | [diff] [blame] | 34 | DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) |
| 35 | : M(m), VMContext(M.getContext()), CUNode(CU), |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 36 | DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr), |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 37 | AllowUnresolvedNodes(AllowUnresolvedNodes) {} |
| 38 | |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 39 | void DIBuilder::trackIfUnresolved(MDNode *N) { |
| Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 40 | if (!N) |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 41 | return; |
| Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 42 | if (N->isResolved()) |
| 43 | return; |
| 44 | |
| 45 | assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes"); |
| 46 | UnresolvedNodes.emplace_back(N); |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 47 | } |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 48 | |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 49 | void DIBuilder::finalizeSubprogram(DISubprogram *SP) { |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 50 | MDTuple *Temp = SP->getRetainedNodes().get(); |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 51 | if (!Temp || !Temp->isTemporary()) |
| 52 | return; |
| 53 | |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 54 | SmallVector<Metadata *, 16> RetainedNodes; |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 55 | |
| 56 | auto PV = PreservedVariables.find(SP); |
| 57 | if (PV != PreservedVariables.end()) |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 58 | RetainedNodes.append(PV->second.begin(), PV->second.end()); |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 59 | |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 60 | auto PL = PreservedLabels.find(SP); |
| 61 | if (PL != PreservedLabels.end()) |
| 62 | RetainedNodes.append(PL->second.begin(), PL->second.end()); |
| 63 | |
| 64 | DINodeArray Node = getOrCreateArray(RetainedNodes); |
| 65 | |
| 66 | TempMDTuple(Temp)->replaceAllUsesWith(Node.get()); |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 69 | void DIBuilder::finalize() { |
| Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 70 | if (!CUNode) { |
| 71 | assert(!AllowUnresolvedNodes && |
| 72 | "creating type nodes without a CU is not supported"); |
| 73 | return; |
| Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 74 | } |
| Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 75 | |
| Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 76 | CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); |
| 77 | |
| 78 | SmallVector<Metadata *, 16> RetainValues; |
| 79 | // Declarations and definitions of the same type may be retained. Some |
| 80 | // clients RAUW these pairs, leaving duplicates in the retained types |
| 81 | // list. Use a set to remove the duplicates while we transform the |
| 82 | // TrackingVHs back into Values. |
| 83 | SmallPtrSet<Metadata *, 16> RetainSet; |
| 84 | for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) |
| 85 | if (RetainSet.insert(AllRetainTypes[I]).second) |
| 86 | RetainValues.push_back(AllRetainTypes[I]); |
| Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 87 | |
| 88 | if (!RetainValues.empty()) |
| 89 | CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); |
| Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 90 | |
| 91 | DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 92 | for (auto *SP : SPs) |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 93 | finalizeSubprogram(SP); |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 94 | for (auto *N : RetainValues) |
| 95 | if (auto *SP = dyn_cast<DISubprogram>(N)) |
| Keno Fischer | 3cdd493 | 2017-06-01 20:42:44 +0000 | [diff] [blame] | 96 | finalizeSubprogram(SP); |
| Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 97 | |
| Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 98 | if (!AllGVs.empty()) |
| 99 | CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); |
| Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 100 | |
| Adrian Prantl | 4276d4a | 2015-07-06 16:36:02 +0000 | [diff] [blame] | 101 | if (!AllImportedModules.empty()) |
| 102 | CUNode->replaceImportedEntities(MDTuple::get( |
| 103 | VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), |
| 104 | AllImportedModules.end()))); |
| Adrian Prantl | 0e224a6 | 2015-07-06 16:22:12 +0000 | [diff] [blame] | 105 | |
| Amjad Aboud | 9607571 | 2017-01-12 15:49:46 +0000 | [diff] [blame] | 106 | for (const auto &I : AllMacrosPerParent) { |
| 107 | // DIMacroNode's with nullptr parent are DICompileUnit direct children. |
| 108 | if (!I.first) { |
| 109 | CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef())); |
| 110 | continue; |
| 111 | } |
| 112 | // Otherwise, it must be a temporary DIMacroFile that need to be resolved. |
| 113 | auto *TMF = cast<DIMacroFile>(I.first); |
| 114 | auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file, |
| 115 | TMF->getLine(), TMF->getFile(), |
| 116 | getOrCreateMacroArray(I.second.getArrayRef())); |
| 117 | replaceTemporary(llvm::TempDIMacroNode(TMF), MF); |
| 118 | } |
| 119 | |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 120 | // Now that all temp nodes have been replaced or deleted, resolve remaining |
| 121 | // cycles. |
| 122 | for (const auto &N : UnresolvedNodes) |
| Duncan P. N. Exon Smith | 2bc00f4 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 123 | if (N && !N->isResolved()) |
| 124 | N->resolveCycles(); |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 125 | UnresolvedNodes.clear(); |
| 126 | |
| 127 | // Can't handle unresolved nodes anymore. |
| 128 | AllowUnresolvedNodes = false; |
| Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| Duncan P. N. Exon Smith | 379e375 | 2014-10-01 21:32:15 +0000 | [diff] [blame] | 131 | /// 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] | 132 | static DIScope *getNonCompileUnitScope(DIScope *N) { |
| 133 | if (!N || isa<DICompileUnit>(N)) |
| Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 134 | return nullptr; |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 135 | return cast<DIScope>(N); |
| Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 138 | DICompileUnit *DIBuilder::createCompileUnit( |
| Amjad Aboud | 43c8b6b | 2016-12-14 20:24:54 +0000 | [diff] [blame] | 139 | unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized, |
| 140 | StringRef Flags, unsigned RunTimeVer, StringRef SplitName, |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 141 | DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, |
| Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 142 | bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) { |
| Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 143 | |
| Bruce Mitchener | 7e575ed | 2015-02-07 06:35:30 +0000 | [diff] [blame] | 144 | assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || |
| Chandler Carruth | 4c0ee74 | 2012-01-10 18:18:52 +0000 | [diff] [blame] | 145 | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
| 146 | "Invalid Language tag"); |
| Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 147 | |
| Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 148 | assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); |
| 149 | CUNode = DICompileUnit::getDistinct( |
| Amjad Aboud | 43c8b6b | 2016-12-14 20:24:54 +0000 | [diff] [blame] | 150 | VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer, |
| 151 | SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId, |
| Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 152 | SplitDebugInlining, DebugInfoForProfiling, GnuPubnames); |
| Devang Patel | 09fa69e | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 153 | |
| 154 | // Create a named metadata so that it is easier to find cu in a module. |
| Adrian Prantl | 5992a72 | 2016-04-08 22:43:03 +0000 | [diff] [blame] | 155 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
| 156 | NMD->addOperand(CUNode); |
| 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, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 163 | Metadata *NS, DIFile *File, unsigned Line, StringRef Name, |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 164 | SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 165 | if (Line) |
| 166 | assert(File && "Source location has line number but no file"); |
| Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame] | 167 | unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 168 | auto *M = |
| 169 | DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name); |
| Amjad Aboud | 62f6f5c | 2016-03-13 11:11:39 +0000 | [diff] [blame] | 170 | if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) |
| 171 | // A new Imported Entity was just added to the context. |
| 172 | // Add it to the Imported Modules list. |
| 173 | AllImportedModules.emplace_back(M); |
| David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 174 | return M; |
| 175 | } |
| 176 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 177 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 178 | DINamespace *NS, DIFile *File, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 179 | unsigned Line) { |
| David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 180 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 181 | Context, NS, File, Line, StringRef(), |
| 182 | AllImportedModules); |
| David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 185 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, |
| 186 | DIImportedEntity *NS, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 187 | DIFile *File, unsigned Line) { |
| David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 188 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 189 | Context, NS, File, Line, StringRef(), |
| 190 | AllImportedModules); |
| David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 193 | DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 194 | DIFile *File, unsigned Line) { |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 195 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 196 | Context, M, File, Line, StringRef(), |
| 197 | AllImportedModules); |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 200 | DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, |
| 201 | DINode *Decl, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 202 | DIFile *File, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 203 | unsigned Line, |
| 204 | StringRef Name) { |
| Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 205 | // Make sure to use the unique identifier based metadata reference for |
| 206 | // types that have one. |
| David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 207 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
| Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 208 | Context, Decl, File, Line, Name, |
| 209 | AllImportedModules); |
| David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 212 | DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory, |
| Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 213 | Optional<DIFile::ChecksumInfo<StringRef>> CS, |
| 214 | Optional<StringRef> Source) { |
| 215 | return DIFile::get(VMContext, Filename, Directory, CS, Source); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| Amjad Aboud | 9607571 | 2017-01-12 15:49:46 +0000 | [diff] [blame] | 218 | DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber, |
| 219 | unsigned MacroType, StringRef Name, |
| 220 | StringRef Value) { |
| 221 | assert(!Name.empty() && "Unable to create macro without name"); |
| 222 | assert((MacroType == dwarf::DW_MACINFO_undef || |
| 223 | MacroType == dwarf::DW_MACINFO_define) && |
| 224 | "Unexpected macro type"); |
| 225 | auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value); |
| 226 | AllMacrosPerParent[Parent].insert(M); |
| 227 | return M; |
| 228 | } |
| 229 | |
| 230 | DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent, |
| 231 | unsigned LineNumber, DIFile *File) { |
| 232 | auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file, |
| 233 | LineNumber, File, DIMacroNodeArray()) |
| 234 | .release(); |
| 235 | AllMacrosPerParent[Parent].insert(MF); |
| 236 | // Add the new temporary DIMacroFile to the macro per parent map as a parent. |
| 237 | // This is needed to assure DIMacroFile with no children to have an entry in |
| 238 | // the map. Otherwise, it will not be resolved in DIBuilder::finalize(). |
| 239 | AllMacrosPerParent.insert({MF, {}}); |
| 240 | return MF; |
| 241 | } |
| 242 | |
| Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 243 | DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val, |
| 244 | bool IsUnsigned) { |
| Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 245 | assert(!Name.empty() && "Unable to create enumerator without name"); |
| Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 246 | return DIEnumerator::get(VMContext, Val, IsUnsigned, Name); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 249 | DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) { |
| Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 250 | assert(!Name.empty() && "Unable to create type without name"); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 251 | return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name); |
| Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 254 | DIBasicType *DIBuilder::createNullPtrType() { |
| Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 255 | return createUnspecifiedType("decltype(nullptr)"); |
| 256 | } |
| 257 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 258 | DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 259 | unsigned Encoding) { |
| Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 260 | assert(!Name.empty() && "Unable to create type without name"); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 261 | return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 262 | 0, Encoding); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 265 | DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 266 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 267 | 0, 0, None, DINode::FlagZero); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 270 | DIDerivedType *DIBuilder::createPointerType( |
| 271 | DIType *PointeeTy, |
| 272 | uint64_t SizeInBits, |
| 273 | uint32_t AlignInBits, |
| 274 | Optional<unsigned> DWARFAddressSpace, |
| 275 | StringRef Name) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 276 | // FIXME: Why is there a name here? |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 277 | 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] | 278 | nullptr, 0, nullptr, PointeeTy, SizeInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 279 | AlignInBits, 0, DWARFAddressSpace, |
| 280 | DINode::FlagZero); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 283 | DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, |
| 284 | DIType *Base, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 285 | uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 286 | uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 287 | DINode::DIFlags Flags) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 288 | 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] | 289 | nullptr, 0, nullptr, PointeeTy, SizeInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 290 | AlignInBits, 0, None, Flags, Base); |
| David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 293 | DIDerivedType *DIBuilder::createReferenceType( |
| 294 | unsigned Tag, DIType *RTy, |
| 295 | uint64_t SizeInBits, |
| 296 | uint32_t AlignInBits, |
| 297 | Optional<unsigned> DWARFAddressSpace) { |
| Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 298 | assert(RTy && "Unable to create reference type"); |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 299 | return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 300 | SizeInBits, AlignInBits, 0, DWARFAddressSpace, |
| 301 | DINode::FlagZero); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 304 | DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, |
| 305 | DIFile *File, unsigned LineNo, |
| 306 | DIScope *Context) { |
| 307 | 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] | 308 | LineNo, getNonCompileUnitScope(Context), Ty, 0, 0, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 309 | 0, None, DINode::FlagZero); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 312 | DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { |
| Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 313 | assert(Ty && "Invalid type!"); |
| 314 | assert(FriendTy && "Invalid friend type!"); |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 315 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 316 | FriendTy, 0, 0, 0, None, DINode::FlagZero); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 319 | DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 320 | uint64_t BaseOffset, |
| Brock Wyma | 3db2b10 | 2018-05-14 21:21:22 +0000 | [diff] [blame] | 321 | uint32_t VBPtrOffset, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 322 | DINode::DIFlags Flags) { |
| Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 323 | assert(Ty && "Unable to create inheritance"); |
| Brock Wyma | 3db2b10 | 2018-05-14 21:21:22 +0000 | [diff] [blame] | 324 | Metadata *ExtraData = ConstantAsMetadata::get( |
| 325 | ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset)); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 326 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, |
| Brock Wyma | 3db2b10 | 2018-05-14 21:21:22 +0000 | [diff] [blame] | 327 | 0, Ty, BaseTy, 0, 0, BaseOffset, None, |
| 328 | Flags, ExtraData); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 331 | DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, |
| 332 | DIFile *File, unsigned LineNumber, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 333 | uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 334 | uint32_t AlignInBits, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 335 | uint64_t OffsetInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 336 | DINode::DIFlags Flags, DIType *Ty) { |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 337 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 338 | LineNumber, getNonCompileUnitScope(Scope), Ty, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 339 | SizeInBits, AlignInBits, OffsetInBits, None, Flags); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 342 | static ConstantAsMetadata *getConstantOrNull(Constant *C) { |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 343 | if (C) |
| 344 | return ConstantAsMetadata::get(C); |
| 345 | return nullptr; |
| 346 | } |
| 347 | |
| Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 348 | DIDerivedType *DIBuilder::createVariantMemberType(DIScope *Scope, StringRef Name, |
| 349 | DIFile *File, unsigned LineNumber, |
| 350 | uint64_t SizeInBits, |
| 351 | uint32_t AlignInBits, |
| 352 | uint64_t OffsetInBits, |
| 353 | Constant *Discriminant, |
| 354 | DINode::DIFlags Flags, DIType *Ty) { |
| 355 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 356 | LineNumber, getNonCompileUnitScope(Scope), Ty, |
| 357 | SizeInBits, AlignInBits, OffsetInBits, None, Flags, |
| 358 | getConstantOrNull(Discriminant)); |
| 359 | } |
| 360 | |
| David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 361 | DIDerivedType *DIBuilder::createBitFieldMemberType( |
| 362 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 363 | uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, |
| 364 | DINode::DIFlags Flags, DIType *Ty) { |
| David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 365 | Flags |= DINode::FlagBitField; |
| 366 | return DIDerivedType::get( |
| 367 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 368 | getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 369 | OffsetInBits, None, Flags, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 370 | ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64), |
| 371 | StorageOffsetInBits))); |
| David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 374 | DIDerivedType * |
| 375 | DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, |
| 376 | unsigned LineNumber, DIType *Ty, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 377 | DINode::DIFlags Flags, llvm::Constant *Val, |
| 378 | uint32_t AlignInBits) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 379 | Flags |= DINode::FlagStaticMember; |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 380 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 381 | LineNumber, getNonCompileUnitScope(Scope), Ty, 0, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 382 | AlignInBits, 0, None, Flags, |
| 383 | getConstantOrNull(Val)); |
| Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 386 | DIDerivedType * |
| 387 | DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 388 | uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 389 | uint64_t OffsetInBits, DINode::DIFlags Flags, |
| 390 | DIType *Ty, MDNode *PropertyNode) { |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 391 | return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 392 | LineNumber, getNonCompileUnitScope(File), Ty, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 393 | SizeInBits, AlignInBits, OffsetInBits, None, Flags, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 394 | PropertyNode); |
| Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 397 | DIObjCProperty * |
| 398 | DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, |
| Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 399 | StringRef GetterName, StringRef SetterName, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 400 | unsigned PropertyAttributes, DIType *Ty) { |
| 401 | return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 402 | SetterName, PropertyAttributes, Ty); |
| Devang Patel | cc48159 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 405 | DITemplateTypeParameter * |
| 406 | DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name, |
| 407 | DIType *Ty) { |
| 408 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 409 | return DITemplateTypeParameter::get(VMContext, Name, Ty); |
| Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 412 | static DITemplateValueParameter * |
| Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 413 | createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 414 | DIScope *Context, StringRef Name, DIType *Ty, |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 415 | Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 416 | assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 417 | return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD); |
| Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 420 | DITemplateValueParameter * |
| 421 | DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name, |
| 422 | DIType *Ty, Constant *Val) { |
| Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 423 | return createTemplateValueParameterHelper( |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 424 | 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] | 425 | getConstantOrNull(Val)); |
| David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 428 | DITemplateValueParameter * |
| 429 | DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name, |
| 430 | DIType *Ty, StringRef Val) { |
| Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 431 | return createTemplateValueParameterHelper( |
| 432 | 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] | 433 | MDString::get(VMContext, Val)); |
| David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 436 | DITemplateValueParameter * |
| 437 | DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name, |
| 438 | DIType *Ty, DINodeArray Val) { |
| Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 439 | return createTemplateValueParameterHelper( |
| 440 | 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] | 441 | Val.get()); |
| David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 444 | DICompositeType *DIBuilder::createClassType( |
| 445 | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 446 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 447 | DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 448 | DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) { |
| 449 | assert((!Context || isa<DIScope>(Context)) && |
| David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 450 | "createClassType should be called with a valid Context"); |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 451 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 452 | auto *R = DICompositeType::get( |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 453 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 454 | getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, |
| 455 | OffsetInBits, Flags, Elements, 0, VTableHolder, |
| Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 456 | cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 457 | trackIfUnresolved(R); |
| David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 458 | return R; |
| Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 461 | DICompositeType *DIBuilder::createStructType( |
| 462 | DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 463 | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 464 | DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang, |
| 465 | DIType *VTableHolder, StringRef UniqueIdentifier) { |
| 466 | auto *R = DICompositeType::get( |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 467 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 468 | getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0, |
| 469 | Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 470 | trackIfUnresolved(R); |
| David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 471 | return R; |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 474 | DICompositeType *DIBuilder::createUnionType( |
| 475 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 476 | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 477 | DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) { |
| 478 | auto *R = DICompositeType::get( |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 479 | VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 480 | getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, |
| 481 | Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 482 | trackIfUnresolved(R); |
| Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 483 | return R; |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 486 | DICompositeType *DIBuilder::createVariantPart( |
| 487 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| 488 | uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, |
| 489 | DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) { |
| 490 | auto *R = DICompositeType::get( |
| 491 | VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber, |
| 492 | getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, |
| 493 | Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator); |
| 494 | trackIfUnresolved(R); |
| 495 | return R; |
| 496 | } |
| 497 | |
| Eric Christopher | bdafb3c | 2015-10-15 06:56:10 +0000 | [diff] [blame] | 498 | DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 499 | DINode::DIFlags Flags, |
| 500 | unsigned CC) { |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 501 | return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes); |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 504 | DICompositeType *DIBuilder::createEnumerationType( |
| 505 | DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 506 | uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, |
| Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 507 | DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsFixed) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 508 | auto *CTy = DICompositeType::get( |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 509 | VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 510 | getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0, |
| Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 511 | IsFixed ? DINode::FlagFixedEnum : DINode::FlagZero, Elements, 0, nullptr, |
| 512 | nullptr, UniqueIdentifier); |
| David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 513 | AllEnumTypes.push_back(CTy); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 514 | trackIfUnresolved(CTy); |
| David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 515 | return CTy; |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 518 | DICompositeType *DIBuilder::createArrayType(uint64_t Size, |
| 519 | uint32_t AlignInBits, DIType *Ty, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 520 | DINodeArray Subscripts) { |
| 521 | 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] | 522 | nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 523 | DINode::FlagZero, Subscripts, 0, nullptr); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 524 | trackIfUnresolved(R); |
| 525 | return R; |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 528 | DICompositeType *DIBuilder::createVectorType(uint64_t Size, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 529 | uint32_t AlignInBits, DIType *Ty, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 530 | DINodeArray Subscripts) { |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 531 | auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
| 532 | nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, |
| 533 | DINode::FlagVector, Subscripts, 0, nullptr); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 534 | trackIfUnresolved(R); |
| 535 | return R; |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 536 | } |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 537 | |
| Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 538 | DISubprogram *DIBuilder::createArtificialSubprogram(DISubprogram *SP) { |
| 539 | auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial); |
| 540 | return MDNode::replaceWithDistinct(std::move(NewSP)); |
| 541 | } |
| 542 | |
| 543 | static DIType *createTypeWithFlags(const DIType *Ty, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 544 | DINode::DIFlags FlagsToSet) { |
| Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 545 | auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet); |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 546 | return MDNode::replaceWithUniqued(std::move(NewTy)); |
| Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 549 | DIType *DIBuilder::createArtificialType(DIType *Ty) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 550 | // 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] | 551 | if (Ty->isArtificial()) |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 552 | return Ty; |
| Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 553 | return createTypeWithFlags(Ty, DINode::FlagArtificial); |
| Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 554 | } |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 555 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 556 | DIType *DIBuilder::createObjectPointerType(DIType *Ty) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 557 | // 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] | 558 | if (Ty->isObjectPointer()) |
| Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 559 | return Ty; |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 560 | DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial; |
| Roman Tereshin | cf88ffa | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 561 | return createTypeWithFlags(Ty, Flags); |
| Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 564 | void DIBuilder::retainType(DIScope *T) { |
| Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 565 | assert(T && "Expected non-null type"); |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 566 | assert((isa<DIType>(T) || (isa<DISubprogram>(T) && |
| 567 | cast<DISubprogram>(T)->isDefinition() == false)) && |
| 568 | "Expected type or subprogram declaration"); |
| Duncan P. N. Exon Smith | d9ccfb9 | 2015-03-27 23:00:49 +0000 | [diff] [blame] | 569 | AllRetainTypes.emplace_back(T); |
| 570 | } |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 571 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 572 | DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; } |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 573 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 574 | DICompositeType * |
| 575 | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, |
| 576 | DIFile *F, unsigned Line, unsigned RuntimeLang, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 577 | uint64_t SizeInBits, uint32_t AlignInBits, |
| Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 578 | StringRef UniqueIdentifier) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 579 | // FIXME: Define in terms of createReplaceableForwardDecl() by calling |
| 580 | // replaceWithUniqued(). |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 581 | auto *RetTy = DICompositeType::get( |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 582 | VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, |
| 583 | SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, |
| 584 | nullptr, nullptr, UniqueIdentifier); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 585 | trackIfUnresolved(RetTy); |
| David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 586 | return RetTy; |
| 587 | } |
| 588 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 589 | DICompositeType *DIBuilder::createReplaceableCompositeType( |
| 590 | unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 591 | unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 592 | DINode::DIFlags Flags, StringRef UniqueIdentifier) { |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 593 | auto *RetTy = |
| 594 | DICompositeType::getTemporary( |
| 595 | VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, |
| 596 | SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, |
| 597 | nullptr, UniqueIdentifier) |
| 598 | .release(); |
| Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 599 | trackIfUnresolved(RetTy); |
| Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 600 | return RetTy; |
| Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 603 | DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { |
| Duncan P. N. Exon Smith | 0208353 | 2015-04-16 16:36:23 +0000 | [diff] [blame] | 604 | return MDTuple::get(VMContext, Elements); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| Amjad Aboud | 9607571 | 2017-01-12 15:49:46 +0000 | [diff] [blame] | 607 | DIMacroNodeArray |
| 608 | DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) { |
| 609 | return MDTuple::get(VMContext, Elements); |
| 610 | } |
| 611 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 612 | DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 613 | SmallVector<llvm::Metadata *, 16> Elts; |
| Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 614 | for (unsigned i = 0, e = Elements.size(); i != e; ++i) { |
| 615 | if (Elements[i] && isa<MDNode>(Elements[i])) |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 616 | Elts.push_back(cast<DIType>(Elements[i])); |
| Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 617 | else |
| 618 | Elts.push_back(Elements[i]); |
| 619 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 620 | return DITypeRefArray(MDNode::get(VMContext, Elts)); |
| Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 623 | DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
| 624 | return DISubrange::get(VMContext, Count, Lo); |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 627 | DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, Metadata *CountNode) { |
| 628 | return DISubrange::get(VMContext, CountNode, Lo); |
| 629 | } |
| 630 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 631 | static void checkGlobalVariableScope(DIScope *Context) { |
| Duncan P. N. Exon Smith | 430220f | 2015-04-06 23:34:41 +0000 | [diff] [blame] | 632 | #ifndef NDEBUG |
| Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 633 | if (auto *CT = |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 634 | dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context))) |
| Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 635 | assert(CT->getIdentifier().empty() && |
| Manman Ren | bfd2b829 | 2014-11-21 19:47:48 +0000 | [diff] [blame] | 636 | "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] | 637 | #endif |
| Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 640 | DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression( |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 641 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 642 | unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, |
| 643 | MDNode *Decl, uint32_t AlignInBits) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 644 | checkGlobalVariableScope(Context); |
| 645 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 646 | auto *GV = DIGlobalVariable::getDistinct( |
| Duncan P. N. Exon Smith | c5225df | 2016-04-23 22:29:09 +0000 | [diff] [blame] | 647 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 648 | LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl), |
| 649 | AlignInBits); |
| Adrian Prantl | 0578221 | 2017-08-30 18:06:51 +0000 | [diff] [blame] | 650 | if (!Expr) |
| 651 | Expr = createExpression(); |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 652 | auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 653 | AllGVs.push_back(N); |
| 654 | return N; |
| Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 657 | DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( |
| 658 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 659 | unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl, |
| 660 | uint32_t AlignInBits) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 661 | checkGlobalVariableScope(Context); |
| 662 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 663 | return DIGlobalVariable::getTemporary( |
| 664 | VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 665 | LineNumber, Ty, isLocalToUnit, false, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 666 | cast_or_null<DIDerivedType>(Decl), AlignInBits) |
| Duncan P. N. Exon Smith | b273d06 | 2015-04-16 01:37:00 +0000 | [diff] [blame] | 667 | .release(); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 670 | static DILocalVariable *createLocalVariable( |
| 671 | LLVMContext &VMContext, |
| Duncan P. N. Exon Smith | 3c406c2 | 2016-04-20 20:14:09 +0000 | [diff] [blame] | 672 | DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 673 | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 674 | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, |
| 675 | uint32_t AlignInBits) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 676 | // FIXME: Why getNonCompileUnitScope()? |
| 677 | // FIXME: Why is "!Context" okay here? |
| Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 678 | // 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] | 679 | // the only valid scopes)? |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 680 | DIScope *Context = getNonCompileUnitScope(Scope); |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 681 | |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 682 | auto *Node = |
| 683 | DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 684 | File, LineNo, Ty, ArgNo, Flags, AlignInBits); |
| Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 685 | if (AlwaysPreserve) { |
| Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 686 | // The optimizer may remove local variables. If there is an interest |
| Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 687 | // to preserve variable info in such situation then stash it in a |
| 688 | // named mdnode. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 689 | DISubprogram *Fn = getDISubprogram(Scope); |
| Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 690 | assert(Fn && "Missing subprogram for local variable"); |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 691 | PreservedVariables[Fn].emplace_back(Node); |
| Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 692 | } |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 693 | return Node; |
| Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 696 | DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, |
| 697 | DIFile *File, unsigned LineNo, |
| 698 | DIType *Ty, bool AlwaysPreserve, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 699 | DINode::DIFlags Flags, |
| 700 | uint32_t AlignInBits) { |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 701 | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, |
| 702 | /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 703 | Flags, AlignInBits); |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | DILocalVariable *DIBuilder::createParameterVariable( |
| 707 | DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 708 | unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 709 | assert(ArgNo && "Expected non-zero argument number for parameter"); |
| 710 | return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 711 | File, LineNo, Ty, AlwaysPreserve, Flags, |
| 712 | /* AlignInBits */0); |
| Duncan P. N. Exon Smith | 1e40dc4 | 2015-07-31 17:55:53 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 715 | DILabel *DIBuilder::createLabel( |
| 716 | DIScope *Scope, StringRef Name, DIFile *File, |
| 717 | unsigned LineNo, bool AlwaysPreserve) { |
| 718 | DIScope *Context = getNonCompileUnitScope(Scope); |
| 719 | |
| 720 | auto *Node = |
| 721 | DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name, |
| 722 | File, LineNo); |
| 723 | |
| 724 | if (AlwaysPreserve) { |
| 725 | /// The optimizer may remove labels. If there is an interest |
| 726 | /// to preserve label info in such situation then append it to |
| 727 | /// the list of retained nodes of the DISubprogram. |
| 728 | DISubprogram *Fn = getDISubprogram(Scope); |
| 729 | assert(Fn && "Missing subprogram for label"); |
| 730 | PreservedLabels[Fn].emplace_back(Node); |
| 731 | } |
| 732 | return Node; |
| 733 | } |
| 734 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 735 | DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { |
| 736 | return DIExpression::get(VMContext, Addr); |
| 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 | DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) { |
| Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 740 | // TODO: Remove the callers of this signed version and delete. |
| 741 | SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); |
| 742 | return createExpression(Addr); |
| 743 | } |
| 744 | |
| Duncan P. N. Exon Smith | b2df647 | 2015-08-26 22:50:16 +0000 | [diff] [blame] | 745 | template <class... Ts> |
| 746 | static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { |
| 747 | if (IsDistinct) |
| 748 | return DISubprogram::getDistinct(std::forward<Ts>(Args)...); |
| 749 | return DISubprogram::get(std::forward<Ts>(Args)...); |
| 750 | } |
| 751 | |
| Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 752 | DISubprogram *DIBuilder::createFunction( |
| 753 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
| 754 | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 755 | bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 756 | bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl, |
| 757 | DITypeArray ThrownTypes) { |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 758 | auto *Node = getSubprogram( |
| 759 | /* IsDistinct = */ isDefinition, VMContext, |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 760 | getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 761 | isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags, |
| 762 | isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 763 | MDTuple::getTemporary(VMContext, None).release(), ThrownTypes); |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 764 | |
| 765 | if (isDefinition) |
| 766 | AllSubprograms.push_back(Node); |
| 767 | trackIfUnresolved(Node); |
| 768 | return Node; |
| Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 771 | DISubprogram *DIBuilder::createTempFunctionFwdDecl( |
| 772 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, |
| 773 | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 774 | bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 775 | bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl, |
| 776 | DITypeArray ThrownTypes) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 777 | return DISubprogram::getTemporary( |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 778 | VMContext, getNonCompileUnitScope(Context), Name, LinkageName, |
| 779 | File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 780 | 0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 781 | TParams, Decl, nullptr, ThrownTypes) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 782 | .release(); |
| Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 785 | DISubprogram *DIBuilder::createMethod( |
| 786 | DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, |
| 787 | unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, |
| 788 | bool isDefinition, unsigned VK, unsigned VIndex, int ThisAdjustment, |
| 789 | DIType *VTableHolder, DINode::DIFlags Flags, bool isOptimized, |
| 790 | DITemplateParameterArray TParams, DITypeArray ThrownTypes) { |
| Eric Christopher | 5cb5632 | 2013-10-15 23:31:36 +0000 | [diff] [blame] | 791 | assert(getNonCompileUnitScope(Context) && |
| 792 | "Methods should have both a Context and a context that isn't " |
| 793 | "the compile unit."); |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 794 | // FIXME: Do we want to use different scope/lines? |
| Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 795 | auto *SP = getSubprogram( |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 796 | /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name, |
| 797 | LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 798 | VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 799 | isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr, ThrownTypes); |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 800 | |
| David Blaikie | 595eb44 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 801 | if (isDefinition) |
| Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 802 | AllSubprograms.push_back(SP); |
| 803 | trackIfUnresolved(SP); |
| 804 | return SP; |
| Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 807 | DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, |
| Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 808 | bool ExportSymbols) { |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 809 | |
| 810 | // It is okay to *not* make anonymous top-level namespaces distinct, because |
| 811 | // all nodes that have an anonymous namespace as their parent scope are |
| 812 | // guaranteed to be unique and/or are linked to their containing |
| 813 | // DICompileUnit. This decision is an explicit tradeoff of link time versus |
| 814 | // memory usage versus code simplicity and may get revisited in the future. |
| 815 | return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name, |
| 816 | ExportSymbols); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 819 | DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, |
| 820 | StringRef ConfigurationMacros, |
| 821 | StringRef IncludePath, |
| 822 | StringRef ISysRoot) { |
| 823 | return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name, |
| 824 | ConfigurationMacros, IncludePath, ISysRoot); |
| 825 | } |
| 826 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 827 | DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope, |
| 828 | DIFile *File, |
| 829 | unsigned Discriminator) { |
| 830 | return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator); |
| Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 833 | DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File, |
| 834 | unsigned Line, unsigned Col) { |
| Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 835 | // Make these distinct, to avoid merging two lexical blocks on the same |
| 836 | // file/line/column. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 837 | return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), |
| Duncan P. N. Exon Smith | 35ef22c | 2015-04-15 23:19:27 +0000 | [diff] [blame] | 838 | File, Line, Col); |
| Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 841 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 842 | DIExpression *Expr, const DILocation *DL, |
| 843 | Instruction *InsertBefore) { |
| 844 | return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(), |
| 845 | InsertBefore); |
| 846 | } |
| 847 | |
| 848 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 849 | DIExpression *Expr, const DILocation *DL, |
| 850 | BasicBlock *InsertAtEnd) { |
| 851 | // If this block already has a terminator then insert this intrinsic before |
| 852 | // the terminator. Otherwise, put it at the end of the block. |
| 853 | Instruction *InsertBefore = InsertAtEnd->getTerminator(); |
| 854 | return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore); |
| 855 | } |
| 856 | |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 857 | Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, |
| 858 | Instruction *InsertBefore) { |
| 859 | return insertLabel( |
| 860 | LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr, |
| 861 | InsertBefore); |
| 862 | } |
| 863 | |
| 864 | Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, |
| 865 | BasicBlock *InsertAtEnd) { |
| 866 | return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr); |
| 867 | } |
| 868 | |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 869 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, |
| 870 | DILocalVariable *VarInfo, |
| 871 | DIExpression *Expr, |
| 872 | const DILocation *DL, |
| 873 | Instruction *InsertBefore) { |
| 874 | return insertDbgValueIntrinsic( |
| 875 | V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr, |
| 876 | InsertBefore); |
| 877 | } |
| 878 | |
| 879 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, |
| 880 | DILocalVariable *VarInfo, |
| 881 | DIExpression *Expr, |
| 882 | const DILocation *DL, |
| 883 | BasicBlock *InsertAtEnd) { |
| 884 | return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr); |
| 885 | } |
| 886 | |
| 887 | /// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This |
| 888 | /// abstracts over the various ways to specify an insert position. |
| 889 | static IRBuilder<> getIRBForDbgInsertion(const DILocation *DL, |
| 890 | BasicBlock *InsertBB, |
| 891 | Instruction *InsertBefore) { |
| 892 | IRBuilder<> B(DL->getContext()); |
| 893 | if (InsertBefore) |
| 894 | B.SetInsertPoint(InsertBefore); |
| 895 | else if (InsertBB) |
| 896 | B.SetInsertPoint(InsertBB); |
| 897 | B.SetCurrentDebugLocation(DL); |
| 898 | return B; |
| 899 | } |
| 900 | |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 901 | static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { |
| 902 | assert(V && "no value passed to dbg intrinsic"); |
| 903 | return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); |
| 904 | } |
| 905 | |
| Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 906 | static Function *getDeclareIntrin(Module &M) { |
| 907 | return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr |
| 908 | : Intrinsic::dbg_declare); |
| 909 | } |
| 910 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 911 | Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, |
| 912 | DIExpression *Expr, const DILocation *DL, |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 913 | BasicBlock *InsertBB, Instruction *InsertBefore) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 914 | 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] | 915 | assert(DL && "Expected debug loc"); |
| 916 | assert(DL->getScope()->getSubprogram() == |
| 917 | VarInfo->getScope()->getSubprogram() && |
| 918 | "Expected matching subprograms"); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 919 | if (!DeclareFn) |
| Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 920 | DeclareFn = getDeclareIntrin(M); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 921 | |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 922 | trackIfUnresolved(VarInfo); |
| 923 | trackIfUnresolved(Expr); |
| 924 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 925 | MetadataAsValue::get(VMContext, VarInfo), |
| 926 | MetadataAsValue::get(VMContext, Expr)}; |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 927 | |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 928 | IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore); |
| 929 | return B.CreateCall(DeclareFn, Args); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 932 | Instruction *DIBuilder::insertDbgValueIntrinsic( |
| 933 | Value *V, DILocalVariable *VarInfo, DIExpression *Expr, |
| 934 | const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) { |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 935 | assert(V && "no value passed to dbg.value"); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 936 | 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] | 937 | assert(DL && "Expected debug loc"); |
| 938 | assert(DL->getScope()->getSubprogram() == |
| 939 | VarInfo->getScope()->getSubprogram() && |
| 940 | "Expected matching subprograms"); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 941 | if (!ValueFn) |
| 942 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 943 | |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 944 | trackIfUnresolved(VarInfo); |
| 945 | trackIfUnresolved(Expr); |
| 946 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 947 | MetadataAsValue::get(VMContext, VarInfo), |
| 948 | MetadataAsValue::get(VMContext, Expr)}; |
| Duncan P. N. Exon Smith | cd1aecf | 2015-04-15 21:18:07 +0000 | [diff] [blame] | 949 | |
| Reid Kleckner | bc66947 | 2017-10-03 20:36:40 +0000 | [diff] [blame] | 950 | IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore); |
| 951 | return B.CreateCall(ValueFn, Args); |
| Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 952 | } |
| Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 953 | |
| Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 954 | Instruction *DIBuilder::insertLabel( |
| 955 | DILabel *LabelInfo, const DILocation *DL, |
| 956 | BasicBlock *InsertBB, Instruction *InsertBefore) { |
| 957 | assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label"); |
| 958 | assert(DL && "Expected debug loc"); |
| 959 | assert(DL->getScope()->getSubprogram() == |
| 960 | LabelInfo->getScope()->getSubprogram() && |
| 961 | "Expected matching subprograms"); |
| 962 | if (!LabelFn) |
| 963 | LabelFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_label); |
| 964 | |
| 965 | trackIfUnresolved(LabelInfo); |
| 966 | Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)}; |
| 967 | |
| 968 | IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore); |
| 969 | return B.CreateCall(LabelFn, Args); |
| 970 | } |
| 971 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 972 | void DIBuilder::replaceVTableHolder(DICompositeType *&T, |
| Adrian Prantl | a8e5645 | 2017-11-08 22:04:43 +0000 | [diff] [blame] | 973 | DIType *VTableHolder) { |
| Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 974 | { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 975 | TypedTrackingMDRef<DICompositeType> N(T); |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 976 | N->replaceVTableHolder(VTableHolder); |
| Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 977 | T = N.get(); |
| 978 | } |
| Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 979 | |
| 980 | // If this didn't create a self-reference, just return. |
| 981 | if (T != VTableHolder) |
| 982 | return; |
| 983 | |
| Adrian Prantl | 18a25b0 | 2015-02-11 17:45:10 +0000 | [diff] [blame] | 984 | // Look for unresolved operands. T will drop RAUW support, orphaning any |
| 985 | // cycles underneath it. |
| 986 | if (T->isResolved()) |
| 987 | for (const MDOperand &O : T->operands()) |
| 988 | if (auto *N = dyn_cast_or_null<MDNode>(O)) |
| 989 | trackIfUnresolved(N); |
| Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 992 | void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements, |
| 993 | DINodeArray TParams) { |
| Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 994 | { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 995 | TypedTrackingMDRef<DICompositeType> N(T); |
| Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 996 | if (Elements) |
| Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 997 | N->replaceElements(Elements); |
| Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 998 | if (TParams) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 999 | N->replaceTemplateParams(DITemplateParameterArray(TParams)); |
| Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 1000 | T = N.get(); |
| 1001 | } |
| Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1002 | |
| 1003 | // If T isn't resolved, there's no problem. |
| 1004 | if (!T->isResolved()) |
| 1005 | return; |
| 1006 | |
| Adrian Prantl | 12d5284 | 2015-07-10 23:26:02 +0000 | [diff] [blame] | 1007 | // 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] | 1008 | // arrays explicitly if they're unresolved, or else the cycles will be |
| 1009 | // orphaned. |
| 1010 | if (Elements) |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1011 | trackIfUnresolved(Elements.get()); |
| Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1012 | if (TParams) |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1013 | trackIfUnresolved(TParams.get()); |
| Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 1014 | } |