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