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