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