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" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | using namespace llvm::dwarf; |
| 25 | |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 26 | namespace { |
| 27 | class HeaderBuilder { |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 28 | /// \brief Whether there are any fields yet. |
| 29 | /// |
| 30 | /// Note that this is not equivalent to \c Chars.empty(), since \a concat() |
| 31 | /// may have been called already with an empty string. |
| 32 | bool IsEmpty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 33 | SmallVector<char, 256> Chars; |
| 34 | |
| 35 | public: |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 36 | HeaderBuilder() : IsEmpty(true) {} |
| 37 | HeaderBuilder(const HeaderBuilder &X) : IsEmpty(X.IsEmpty), Chars(X.Chars) {} |
| 38 | HeaderBuilder(HeaderBuilder &&X) |
| 39 | : IsEmpty(X.IsEmpty), Chars(std::move(X.Chars)) {} |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 40 | |
| 41 | template <class Twineable> HeaderBuilder &concat(Twineable &&X) { |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 42 | if (IsEmpty) |
| 43 | IsEmpty = false; |
| 44 | else |
| 45 | Chars.push_back(0); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 46 | Twine(X).toVector(Chars); |
| 47 | return *this; |
| 48 | } |
| 49 | |
| 50 | MDString *get(LLVMContext &Context) const { |
| 51 | return MDString::get(Context, StringRef(Chars.begin(), Chars.size())); |
| 52 | } |
| 53 | |
| 54 | static HeaderBuilder get(unsigned Tag) { |
Duncan P. N. Exon Smith | aa687a3 | 2015-01-20 05:02:42 +0000 | [diff] [blame] | 55 | return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag)); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 56 | } |
| 57 | }; |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 58 | } |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 59 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 60 | DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 61 | : M(m), VMContext(M.getContext()), TempEnumTypes(nullptr), |
| 62 | TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(nullptr), |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 63 | DeclareFn(nullptr), ValueFn(nullptr), |
| 64 | AllowUnresolvedNodes(AllowUnresolvedNodes) {} |
| 65 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 66 | void DIBuilder::trackIfUnresolved(MDNode *N) { |
Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 67 | if (!N) |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 68 | return; |
Duncan P. N. Exon Smith | 9b1c6d3 | 2015-01-19 19:09:14 +0000 | [diff] [blame] | 69 | if (N->isResolved()) |
| 70 | return; |
| 71 | |
| 72 | assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes"); |
| 73 | UnresolvedNodes.emplace_back(N); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 74 | } |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 75 | |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 76 | void DIBuilder::finalize() { |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 77 | DIArray Enums = getOrCreateArray(AllEnumTypes); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 78 | TempEnumTypes->replaceAllUsesWith(Enums); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 79 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 80 | SmallVector<Metadata *, 16> RetainValues; |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 81 | // Declarations and definitions of the same type may be retained. Some |
| 82 | // clients RAUW these pairs, leaving duplicates in the retained types |
| 83 | // list. Use a set to remove the duplicates while we transform the |
| 84 | // TrackingVHs back into Values. |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 85 | SmallPtrSet<Metadata *, 16> RetainSet; |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 86 | for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 87 | if (RetainSet.insert(AllRetainTypes[I]).second) |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 88 | RetainValues.push_back(AllRetainTypes[I]); |
| 89 | DIArray RetainTypes = getOrCreateArray(RetainValues); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 90 | TempRetainTypes->replaceAllUsesWith(RetainTypes); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 91 | |
| 92 | DIArray SPs = getOrCreateArray(AllSubprograms); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 93 | TempSubprograms->replaceAllUsesWith(SPs); |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame^] | 94 | for (unsigned i = 0, e = SPs.size(); i != e; ++i) { |
| 95 | DISubprogram SP = cast<MDSubprogram>(SPs[i]); |
Eric Christopher | 27deb26 | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 96 | if (MDNode *Temp = SP.getVariablesNodes()) { |
Benjamin Kramer | 6cd780f | 2015-02-17 15:29:18 +0000 | [diff] [blame] | 97 | const auto &PV = PreservedVariables.lookup(SP); |
| 98 | SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end()); |
Eric Christopher | 27deb26 | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 99 | DIArray AV = getOrCreateArray(Variables); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 100 | Temp->replaceAllUsesWith(AV); |
Eric Christopher | 27deb26 | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 101 | } |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 102 | } |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 103 | |
| 104 | DIArray GVs = getOrCreateArray(AllGVs); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 105 | TempGVs->replaceAllUsesWith(GVs); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 106 | |
Benjamin Kramer | 6cd780f | 2015-02-17 15:29:18 +0000 | [diff] [blame] | 107 | SmallVector<Metadata *, 16> RetainValuesI(AllImportedModules.begin(), |
| 108 | AllImportedModules.end()); |
Eric Christopher | 2c3a6dc | 2014-02-28 21:27:57 +0000 | [diff] [blame] | 109 | DIArray IMs = getOrCreateArray(RetainValuesI); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 110 | TempImportedModules->replaceAllUsesWith(IMs); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 111 | |
| 112 | // Now that all temp nodes have been replaced or deleted, resolve remaining |
| 113 | // cycles. |
| 114 | for (const auto &N : UnresolvedNodes) |
Duncan P. N. Exon Smith | 2bc00f4 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 115 | if (N && !N->isResolved()) |
| 116 | N->resolveCycles(); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 117 | UnresolvedNodes.clear(); |
| 118 | |
| 119 | // Can't handle unresolved nodes anymore. |
| 120 | AllowUnresolvedNodes = false; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Duncan P. N. Exon Smith | 379e375 | 2014-10-01 21:32:15 +0000 | [diff] [blame] | 123 | /// If N is compile unit return NULL otherwise return N. |
Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 124 | static MDScope *getNonCompileUnitScope(MDNode *N) { |
| 125 | if (!N || isa<MDCompileUnit>(N)) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 126 | return nullptr; |
Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 127 | return cast<MDScope>(N); |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 130 | DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, |
| 131 | StringRef Directory, |
| 132 | StringRef Producer, bool isOptimized, |
| 133 | StringRef Flags, unsigned RunTimeVer, |
Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 134 | StringRef SplitName, |
Diego Novillo | 56653fd | 2014-06-24 17:02:03 +0000 | [diff] [blame] | 135 | DebugEmissionKind Kind, |
| 136 | bool EmitDebugInfo) { |
Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 137 | |
Bruce Mitchener | 7e575ed | 2015-02-07 06:35:30 +0000 | [diff] [blame] | 138 | assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || |
Chandler Carruth | 4c0ee74 | 2012-01-10 18:18:52 +0000 | [diff] [blame] | 139 | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
| 140 | "Invalid Language tag"); |
| 141 | assert(!Filename.empty() && |
| 142 | "Unable to create compile unit without filename"); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 143 | |
Duncan P. N. Exon Smith | b93569d | 2015-02-12 21:52:11 +0000 | [diff] [blame] | 144 | // TODO: Once we make MDCompileUnit distinct, stop using temporaries here |
| 145 | // (just start with operands assigned to nullptr). |
| 146 | TempEnumTypes = MDTuple::getTemporary(VMContext, None).release(); |
| 147 | TempRetainTypes = MDTuple::getTemporary(VMContext, None).release(); |
| 148 | TempSubprograms = MDTuple::getTemporary(VMContext, None).release(); |
| 149 | TempGVs = MDTuple::getTemporary(VMContext, None).release(); |
| 150 | TempImportedModules = MDTuple::getTemporary(VMContext, None).release(); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 151 | |
Duncan P. N. Exon Smith | b93569d | 2015-02-12 21:52:11 +0000 | [diff] [blame] | 152 | // TODO: Switch to getDistinct(). We never want to merge compile units based |
| 153 | // on contents. |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 154 | MDCompileUnit *CUNode = MDCompileUnit::get( |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 155 | VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer, |
| 156 | isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes, |
| 157 | TempRetainTypes, TempSubprograms, TempGVs, TempImportedModules); |
Devang Patel | 09fa69e | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 158 | |
| 159 | // Create a named metadata so that it is easier to find cu in a module. |
Diego Novillo | 56653fd | 2014-06-24 17:02:03 +0000 | [diff] [blame] | 160 | // Note that we only generate this when the caller wants to actually |
| 161 | // emit debug information. When we are only interested in tracking |
| 162 | // source line locations throughout the backend, we prevent codegen from |
| 163 | // emitting debug info in the final output by not generating llvm.dbg.cu. |
| 164 | if (EmitDebugInfo) { |
| 165 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
| 166 | NMD->addOperand(CUNode); |
| 167 | } |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 168 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 169 | trackIfUnresolved(CUNode); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 170 | return CUNode; |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 171 | } |
| 172 | |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 173 | static DIImportedEntity |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 174 | createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context, |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 175 | Metadata *NS, unsigned Line, StringRef Name, |
| 176 | SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { |
Duncan P. N. Exon Smith | d5e6a15 | 2015-04-07 04:07:31 +0000 | [diff] [blame] | 177 | DIImportedEntity M = |
| 178 | MDImportedEntity::get(C, Tag, Context, DebugNodeRef(NS), Line, Name); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 179 | AllImportedModules.emplace_back(M.get()); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 180 | return M; |
| 181 | } |
| 182 | |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 183 | DIImportedEntity DIBuilder::createImportedModule(DIScope Context, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 184 | DINameSpace NS, |
| 185 | unsigned Line) { |
| 186 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 187 | Context, NS, Line, StringRef(), AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | DIImportedEntity DIBuilder::createImportedModule(DIScope Context, |
| 191 | DIImportedEntity NS, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 192 | unsigned Line) { |
| 193 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 194 | Context, NS, Line, StringRef(), AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 195 | } |
| 196 | |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 197 | DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context, |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 198 | DIDescriptor Decl, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 199 | unsigned Line, |
| 200 | StringRef Name) { |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 201 | // Make sure to use the unique identifier based metadata reference for |
| 202 | // types that have one. |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 203 | return ::createImportedModule( |
| 204 | VMContext, dwarf::DW_TAG_imported_declaration, Context, |
| 205 | DebugNodeRef::get(cast_or_null<DebugNode>(Decl.get())), Line, Name, |
| 206 | AllImportedModules); |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context, |
| 210 | DIImportedEntity Imp, |
| 211 | unsigned Line, StringRef Name) { |
| 212 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
| 213 | Context, Imp, Line, Name, AllImportedModules); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 216 | DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 217 | return MDFile::get(VMContext, Filename, Directory); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 218 | } |
| 219 | |
David Blaikie | b761900 | 2013-06-24 17:34:33 +0000 | [diff] [blame] | 220 | DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 221 | assert(!Name.empty() && "Unable to create enumerator without name"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 222 | return MDEnumerator::get(VMContext, Val, Name); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 225 | DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) { |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 226 | assert(!Name.empty() && "Unable to create type without name"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 227 | return MDBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 230 | DIBasicType DIBuilder::createNullPtrType() { |
| 231 | return createUnspecifiedType("decltype(nullptr)"); |
| 232 | } |
| 233 | |
David Blaikie | 209d63a | 2013-02-12 00:40:41 +0000 | [diff] [blame] | 234 | DIBasicType |
| 235 | DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
| 236 | uint64_t AlignInBits, 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 | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 238 | return MDBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, |
| 239 | AlignInBits, Encoding); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 240 | } |
| 241 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 242 | DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 243 | return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 244 | MDTypeRef::get(FromTy), 0, 0, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 245 | } |
| 246 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 247 | DIDerivedType |
| 248 | DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits, |
| 249 | uint64_t AlignInBits, StringRef Name) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 250 | // FIXME: Why is there a name here? |
| 251 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 252 | nullptr, 0, nullptr, MDTypeRef::get(PointeeTy), |
| 253 | SizeInBits, AlignInBits, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Adrian Prantl | 48af2ef | 2014-12-23 19:11:47 +0000 | [diff] [blame] | 256 | DIDerivedType |
| 257 | DIBuilder::createMemberPointerType(DIType PointeeTy, DIType Base, |
| 258 | uint64_t SizeInBits, uint64_t AlignInBits) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 259 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 260 | nullptr, 0, nullptr, MDTypeRef::get(PointeeTy), |
| 261 | SizeInBits, AlignInBits, 0, 0, MDTypeRef::get(Base)); |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 262 | } |
| 263 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 264 | DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 265 | assert(RTy && "Unable to create reference type"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 266 | return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 267 | MDTypeRef::get(RTy), 0, 0, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 268 | } |
| 269 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 270 | DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File, |
| 271 | unsigned LineNo, DIDescriptor Context) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 272 | return MDDerivedType::get( |
| 273 | VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo, |
| 274 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), |
| 275 | MDTypeRef::get(Ty), 0, 0, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Manman Ren | 3c6acec | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 278 | DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) { |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 279 | // typedefs are encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 280 | assert(Ty && "Invalid type!"); |
| 281 | assert(FriendTy && "Invalid friend type!"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 282 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 283 | MDTypeRef::get(Ty), MDTypeRef::get(FriendTy), 0, 0, |
| 284 | 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 287 | DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy, |
| 288 | uint64_t BaseOffset, |
| 289 | unsigned Flags) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 290 | assert(Ty && "Unable to create inheritance"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 291 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 292 | 0, MDTypeRef::get(Ty), MDTypeRef::get(BaseTy), 0, 0, |
| 293 | BaseOffset, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 296 | DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name, |
| 297 | DIFile File, unsigned LineNumber, |
| 298 | uint64_t SizeInBits, |
| 299 | uint64_t AlignInBits, |
| 300 | uint64_t OffsetInBits, unsigned Flags, |
| 301 | DIType Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 302 | return MDDerivedType::get( |
| 303 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 304 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), |
| 305 | MDTypeRef::get(Ty), SizeInBits, AlignInBits, OffsetInBits, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 308 | static ConstantAsMetadata *getConstantOrNull(Constant *C) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 309 | if (C) |
| 310 | return ConstantAsMetadata::get(C); |
| 311 | return nullptr; |
| 312 | } |
| 313 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 314 | DIDerivedType DIBuilder::createStaticMemberType(DIDescriptor Scope, |
| 315 | StringRef Name, DIFile File, |
| 316 | unsigned LineNumber, DIType Ty, |
| 317 | unsigned Flags, |
| 318 | llvm::Constant *Val) { |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 319 | // TAG_member is encoded in DIDerivedType format. |
| 320 | Flags |= DIDescriptor::FlagStaticMember; |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 321 | return MDDerivedType::get( |
| 322 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 323 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), |
| 324 | MDTypeRef::get(Ty), 0, 0, 0, Flags, getConstantOrNull(Val)); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 327 | DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File, |
| 328 | unsigned LineNumber, |
| 329 | uint64_t SizeInBits, |
| 330 | uint64_t AlignInBits, |
| 331 | uint64_t OffsetInBits, unsigned Flags, |
| 332 | DIType Ty, MDNode *PropertyNode) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 333 | return MDDerivedType::get( |
| 334 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
| 335 | MDScopeRef::get(getNonCompileUnitScope(File)), MDTypeRef::get(Ty), |
| 336 | SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 339 | DIObjCProperty |
| 340 | DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber, |
| 341 | StringRef GetterName, StringRef SetterName, |
| 342 | unsigned PropertyAttributes, DIType Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 343 | return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, |
| 344 | SetterName, PropertyAttributes, Ty); |
Devang Patel | cc48159 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Eric Christopher | 3cc90fe | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 347 | DITemplateTypeParameter |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 348 | DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 349 | DIType Ty) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 350 | assert((!Context || isa<MDCompileUnit>(Context.get())) && |
Duncan P. N. Exon Smith | 89b075e | 2015-02-18 20:30:45 +0000 | [diff] [blame] | 351 | "Expected compile unit"); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 352 | return MDTemplateTypeParameter::get(VMContext, Name, MDTypeRef::get(Ty)); |
Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 355 | static DITemplateValueParameter |
| 356 | createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, |
| 357 | DIDescriptor Context, StringRef Name, |
| 358 | DIType Ty, Metadata *MD) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 359 | assert((!Context || isa<MDCompileUnit>(Context.get())) && |
Duncan P. N. Exon Smith | 89b075e | 2015-02-18 20:30:45 +0000 | [diff] [blame] | 360 | "Expected compile unit"); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 361 | return MDTemplateValueParameter::get(VMContext, Tag, Name, MDTypeRef::get(Ty), |
| 362 | MD); |
Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 363 | } |
| 364 | |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 365 | DITemplateValueParameter |
| 366 | DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 367 | DIType Ty, Constant *Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 368 | return createTemplateValueParameterHelper( |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 369 | 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] | 370 | getConstantOrNull(Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | DITemplateValueParameter |
| 374 | DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 375 | DIType Ty, StringRef Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 376 | return createTemplateValueParameterHelper( |
| 377 | 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] | 378 | MDString::get(VMContext, Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | DITemplateValueParameter |
| 382 | DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 383 | DIType Ty, DIArray Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 384 | return createTemplateValueParameterHelper( |
| 385 | VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 386 | Val); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 387 | } |
| 388 | |
David Blaikie | a7310a3 | 2013-03-26 23:46:39 +0000 | [diff] [blame] | 389 | DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, |
| 390 | DIFile File, unsigned LineNumber, |
| 391 | uint64_t SizeInBits, |
| 392 | uint64_t AlignInBits, |
| 393 | uint64_t OffsetInBits, |
| 394 | unsigned Flags, DIType DerivedFrom, |
| 395 | DIArray Elements, |
Manman Ren | 2755206 | 2013-09-06 23:54:23 +0000 | [diff] [blame] | 396 | DIType VTableHolder, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 397 | MDNode *TemplateParams, |
| 398 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 399 | assert((!Context || isa<MDScope>(Context)) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 400 | "createClassType should be called with a valid Context"); |
| 401 | // TAG_class_type is encoded in DICompositeType format. |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 402 | DICompositeType R = MDCompositeType::get( |
| 403 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 404 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), |
| 405 | MDTypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags, |
| 406 | Elements, 0, MDTypeRef::get(VTableHolder), |
| 407 | cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 408 | if (!UniqueIdentifier.empty()) |
| 409 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 410 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 411 | return R; |
Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 412 | } |
| 413 | |
David Blaikie | bbe0e1a | 2013-02-25 01:07:18 +0000 | [diff] [blame] | 414 | DICompositeType DIBuilder::createStructType(DIDescriptor Context, |
| 415 | StringRef Name, DIFile File, |
| 416 | unsigned LineNumber, |
| 417 | uint64_t SizeInBits, |
| 418 | uint64_t AlignInBits, |
| 419 | unsigned Flags, DIType DerivedFrom, |
| 420 | DIArray Elements, |
| 421 | unsigned RunTimeLang, |
Manman Ren | 2755206 | 2013-09-06 23:54:23 +0000 | [diff] [blame] | 422 | DIType VTableHolder, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 423 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 424 | DICompositeType R = MDCompositeType::get( |
| 425 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 426 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), |
| 427 | MDTypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements, |
| 428 | RunTimeLang, MDTypeRef::get(VTableHolder), nullptr, UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 429 | if (!UniqueIdentifier.empty()) |
| 430 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 431 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 432 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Eric Christopher | 17dd8f0 | 2013-04-02 22:55:52 +0000 | [diff] [blame] | 435 | DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name, |
| 436 | DIFile File, unsigned LineNumber, |
| 437 | uint64_t SizeInBits, |
| 438 | uint64_t AlignInBits, unsigned Flags, |
| 439 | DIArray Elements, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 440 | unsigned RunTimeLang, |
| 441 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 442 | DICompositeType R = MDCompositeType::get( |
| 443 | VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 444 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr, |
| 445 | SizeInBits, AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, |
| 446 | nullptr, UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 447 | if (!UniqueIdentifier.empty()) |
| 448 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 449 | trackIfUnresolved(R); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 450 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Manman Ren | f8a1967 | 2014-07-28 22:24:06 +0000 | [diff] [blame] | 453 | DISubroutineType DIBuilder::createSubroutineType(DIFile File, |
| 454 | DITypeArray ParameterTypes, |
| 455 | unsigned Flags) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 456 | return MDSubroutineType::get(VMContext, Flags, ParameterTypes); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 457 | } |
| 458 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 459 | DICompositeType DIBuilder::createEnumerationType( |
| 460 | DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, |
| 461 | uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 462 | DIType UnderlyingType, StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 463 | DICompositeType CTy = MDCompositeType::get( |
| 464 | VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 465 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), |
| 466 | MDTypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements, |
| 467 | 0, nullptr, nullptr, UniqueIdentifier); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 468 | AllEnumTypes.push_back(CTy); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 469 | if (!UniqueIdentifier.empty()) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 470 | retainType(CTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 471 | trackIfUnresolved(CTy); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 472 | return CTy; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 473 | } |
| 474 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 475 | DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, |
| 476 | DIType Ty, DIArray Subscripts) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 477 | auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 478 | nullptr, 0, nullptr, MDTypeRef::get(Ty), Size, |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 479 | AlignInBits, 0, 0, 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 | |
Manman Ren | 6071160 | 2013-06-07 03:13:46 +0000 | [diff] [blame] | 484 | DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits, |
| 485 | DIType Ty, DIArray Subscripts) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 486 | auto *R = |
| 487 | MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, |
| 488 | nullptr, MDTypeRef::get(Ty), Size, AlignInBits, 0, |
| 489 | DIType::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 | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 494 | static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty, |
| 495 | unsigned FlagsToSet) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 496 | TempMDType NewTy = cast<MDType>(static_cast<MDNode *>(Ty))->clone(); |
| 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 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +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. |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 503 | if (Ty.isArtificial()) |
| 504 | return Ty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 505 | return createTypeWithFlags(VMContext, Ty, DIType::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 | |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +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. |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 510 | if (Ty.isObjectPointer()) |
| 511 | return Ty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 512 | unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial; |
| 513 | return createTypeWithFlags(VMContext, Ty, Flags); |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Duncan P. N. Exon Smith | d9ccfb9 | 2015-03-27 23:00:49 +0000 | [diff] [blame] | 516 | void DIBuilder::retainType(DIType T) { |
| 517 | assert(T.get() && "Expected non-null type"); |
| 518 | AllRetainTypes.emplace_back(T); |
| 519 | } |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 520 | |
Manman Ren | f93ac4b | 2014-07-29 18:20:39 +0000 | [diff] [blame] | 521 | DIBasicType DIBuilder::createUnspecifiedParameter() { |
Manman Ren | 72b07e8 | 2014-07-29 22:58:13 +0000 | [diff] [blame] | 522 | return DIBasicType(); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 525 | DICompositeType |
| 526 | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope, |
| 527 | DIFile F, unsigned Line, unsigned RuntimeLang, |
| 528 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 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(). |
| 532 | DICompositeType RetTy = MDCompositeType::get( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 533 | VMContext, Tag, Name, F, Line, |
| 534 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr, |
| 535 | SizeInBits, AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr, |
| 536 | RuntimeLang, nullptr, nullptr, UniqueIdentifier); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 537 | if (!UniqueIdentifier.empty()) |
| 538 | retainType(RetTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 539 | trackIfUnresolved(RetTy); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 540 | return RetTy; |
| 541 | } |
| 542 | |
Adrian Prantl | 534a81a | 2015-02-11 17:45:05 +0000 | [diff] [blame] | 543 | DICompositeType DIBuilder::createReplaceableCompositeType( |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 544 | unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line, |
| 545 | unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, |
Adrian Prantl | 534a81a | 2015-02-11 17:45:05 +0000 | [diff] [blame] | 546 | unsigned Flags, StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 547 | DICompositeType RetTy = |
| 548 | MDCompositeType::getTemporary( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 549 | VMContext, Tag, Name, F, Line, |
| 550 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Scope))), nullptr, |
| 551 | SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, |
| 552 | nullptr, UniqueIdentifier) |
| 553 | .release(); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 554 | if (!UniqueIdentifier.empty()) |
| 555 | retainType(RetTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 556 | trackIfUnresolved(RetTy); |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 557 | return RetTy; |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 560 | DIArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { |
Jay Foad | dbf81d8 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 561 | return DIArray(MDNode::get(VMContext, Elements)); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 564 | DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { |
| 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 | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 568 | Elts.push_back(MDTypeRef::get(cast<MDType>(Elements[i]))); |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 569 | else |
| 570 | Elts.push_back(Elements[i]); |
| 571 | } |
| 572 | return DITypeArray(MDNode::get(VMContext, Elts)); |
| 573 | } |
| 574 | |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 575 | DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 576 | return MDSubrange::get(VMContext, Count, Lo); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 579 | static void checkGlobalVariableScope(DIDescriptor Context) { |
Duncan P. N. Exon Smith | 430220f | 2015-04-06 23:34:41 +0000 | [diff] [blame] | 580 | #ifndef NDEBUG |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 581 | if (DICompositeType CT = |
| 582 | dyn_cast_or_null<MDCompositeType>(getNonCompileUnitScope(Context))) |
| 583 | assert(!CT.getIdentifier() && |
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 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 588 | DIGlobalVariable DIBuilder::createGlobalVariable( |
| 589 | DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 590 | unsigned LineNumber, DIType Ty, bool isLocalToUnit, Constant *Val, |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 591 | MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 592 | checkGlobalVariableScope(Context); |
| 593 | |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 594 | auto *N = MDGlobalVariable::get( |
| 595 | VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, F, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 596 | LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true, |
| 597 | getConstantOrNull(Val), cast_or_null<MDDerivedType>(Decl)); |
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 | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 602 | DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl( |
| 603 | DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 604 | unsigned LineNumber, DIType Ty, bool isLocalToUnit, Constant *Val, |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 605 | MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 606 | checkGlobalVariableScope(Context); |
| 607 | |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 608 | return MDGlobalVariable::getTemporary( |
| 609 | VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 610 | F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, getConstantOrNull(Val), |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 611 | cast_or_null<MDDerivedType>(Decl)).release(); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 614 | DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 615 | StringRef Name, DIFile File, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 616 | unsigned LineNo, DIType Ty, |
Devang Patel | 40eee1e | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 617 | bool AlwaysPreserve, unsigned Flags, |
| 618 | unsigned ArgNo) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 619 | // FIXME: Why getNonCompileUnitScope()? |
| 620 | // FIXME: Why is "!Context" okay here? |
| 621 | // FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT |
| 622 | // the only valid scopes)? |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 623 | DIScope Context = getNonCompileUnitScope(Scope); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 624 | |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 625 | auto *Node = MDLocalVariable::get( |
| 626 | VMContext, Tag, cast_or_null<MDLocalScope>(Context.get()), Name, File, |
| 627 | LineNo, MDTypeRef::get(Ty), ArgNo, Flags); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 628 | if (AlwaysPreserve) { |
| 629 | // The optimizer may remove local variable. If there is an interest |
| 630 | // to preserve variable info in such situation then stash it in a |
| 631 | // named mdnode. |
| 632 | DISubprogram Fn(getDISubprogram(Scope)); |
Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 633 | assert(Fn && "Missing subprogram for local variable"); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 634 | PreservedVariables[Fn].emplace_back(Node); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 635 | } |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 636 | return Node; |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 639 | DIExpression DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 640 | return MDExpression::get(VMContext, Addr); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 643 | DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Signed) { |
| 644 | // TODO: Remove the callers of this signed version and delete. |
| 645 | SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); |
| 646 | return createExpression(Addr); |
| 647 | } |
| 648 | |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 649 | DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBytes, |
| 650 | unsigned SizeInBytes) { |
| 651 | uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes}; |
| 652 | return MDExpression::get(VMContext, Addr); |
Duncan P. N. Exon Smith | 9affbba | 2014-10-01 21:32:12 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 655 | DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name, |
| 656 | StringRef LinkageName, DIFile File, |
| 657 | unsigned LineNo, DICompositeType Ty, |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 658 | bool isLocalToUnit, bool isDefinition, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 659 | unsigned ScopeLine, unsigned Flags, |
| 660 | bool isOptimized, Function *Fn, |
| 661 | MDNode *TParams, MDNode *Decl) { |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 662 | // dragonegg does not generate identifier for types, so using an empty map |
| 663 | // to resolve the context should be fine. |
| 664 | DITypeIdentifierMap EmptyMap; |
| 665 | return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File, |
| 666 | LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, |
| 667 | Flags, isOptimized, Fn, TParams, Decl); |
| 668 | } |
| 669 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 670 | DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name, |
| 671 | StringRef LinkageName, DIFile File, |
| 672 | unsigned LineNo, DICompositeType Ty, |
| 673 | bool isLocalToUnit, bool isDefinition, |
| 674 | unsigned ScopeLine, unsigned Flags, |
| 675 | bool isOptimized, Function *Fn, |
| 676 | MDNode *TParams, MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 677 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 678 | "function types should be subroutines"); |
| 679 | auto *Node = MDSubprogram::get( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 680 | VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), |
| 681 | Name, LinkageName, File.get(), LineNo, |
| 682 | cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, isDefinition, |
| 683 | ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn), |
| 684 | cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl), |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 685 | MDTuple::getTemporary(VMContext, None).release()); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 686 | |
| 687 | if (isDefinition) |
| 688 | AllSubprograms.push_back(Node); |
| 689 | trackIfUnresolved(Node); |
| 690 | return Node; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 693 | DISubprogram |
| 694 | DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name, |
| 695 | StringRef LinkageName, DIFile File, |
| 696 | unsigned LineNo, DICompositeType Ty, |
| 697 | bool isLocalToUnit, bool isDefinition, |
| 698 | unsigned ScopeLine, unsigned Flags, |
| 699 | bool isOptimized, Function *Fn, |
| 700 | MDNode *TParams, MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 701 | return MDSubprogram::getTemporary( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 702 | VMContext, |
| 703 | MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name, |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 704 | LinkageName, File.get(), LineNo, |
| 705 | cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 706 | isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 707 | getConstantOrNull(Fn), cast_or_null<MDTuple>(TParams), |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 708 | cast_or_null<MDSubprogram>(Decl), nullptr) |
| 709 | .release(); |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 712 | DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, |
| 713 | StringRef LinkageName, DIFile F, |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 714 | unsigned LineNo, DICompositeType Ty, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 715 | bool isLocalToUnit, bool isDefinition, |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 716 | unsigned VK, unsigned VIndex, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 717 | DIType VTableHolder, unsigned Flags, |
| 718 | bool isOptimized, Function *Fn, |
Devang Patel | 9f73884 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 719 | MDNode *TParam) { |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 720 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 721 | "function types should be subroutines"); |
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? |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 726 | auto *SP = MDSubprogram::get( |
| 727 | VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName, |
| 728 | F.get(), LineNo, cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 729 | isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags, |
| 730 | isOptimized, getConstantOrNull(Fn), cast_or_null<MDTuple>(TParam), |
| 731 | nullptr, nullptr); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 732 | |
David Blaikie | 595eb44 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 733 | if (isDefinition) |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 734 | AllSubprograms.push_back(SP); |
| 735 | trackIfUnresolved(SP); |
| 736 | return SP; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 739 | DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 740 | DIFile File, unsigned LineNo) { |
Duncan P. N. Exon Smith | a5099dc | 2015-04-06 19:49:39 +0000 | [diff] [blame] | 741 | return MDNamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name, |
| 742 | LineNo); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 745 | DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, |
David Blaikie | 2f3f76f | 2014-08-21 22:45:21 +0000 | [diff] [blame] | 746 | DIFile File, |
| 747 | unsigned Discriminator) { |
Duncan P. N. Exon Smith | a5099dc | 2015-04-06 19:49:39 +0000 | [diff] [blame] | 748 | return MDLexicalBlockFile::get(VMContext, Scope, File.getFileNode(), |
| 749 | Discriminator); |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 752 | DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, |
David Blaikie | 2f3f76f | 2014-08-21 22:45:21 +0000 | [diff] [blame] | 753 | unsigned Line, unsigned Col) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 754 | // Make these distinct, to avoid merging two lexical blocks on the same |
| 755 | // file/line/column. |
Duncan P. N. Exon Smith | a5099dc | 2015-04-06 19:49:39 +0000 | [diff] [blame] | 756 | return MDLexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), |
| 757 | File.getFileNode(), Line, Col); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 760 | static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { |
| 761 | assert(V && "no value passed to dbg intrinsic"); |
| 762 | return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); |
| 763 | } |
| 764 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 765 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 766 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 767 | Instruction *InsertBefore) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 768 | assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 769 | if (!DeclareFn) |
| 770 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 771 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 772 | trackIfUnresolved(VarInfo); |
| 773 | trackIfUnresolved(Expr); |
| 774 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 775 | MetadataAsValue::get(VMContext, VarInfo), |
| 776 | MetadataAsValue::get(VMContext, Expr)}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 777 | return CallInst::Create(DeclareFn, Args, "", InsertBefore); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 780 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 781 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 782 | BasicBlock *InsertAtEnd) { |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 783 | assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 784 | if (!DeclareFn) |
| 785 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 786 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 787 | trackIfUnresolved(VarInfo); |
| 788 | trackIfUnresolved(Expr); |
| 789 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 790 | MetadataAsValue::get(VMContext, VarInfo), |
| 791 | MetadataAsValue::get(VMContext, Expr)}; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 792 | |
| 793 | // If this block already has a terminator then insert this intrinsic |
| 794 | // before the terminator. |
| 795 | if (TerminatorInst *T = InsertAtEnd->getTerminator()) |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 796 | return CallInst::Create(DeclareFn, Args, "", T); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 797 | else |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 798 | return CallInst::Create(DeclareFn, Args, "", InsertAtEnd); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 801 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 802 | DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 803 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 804 | Instruction *InsertBefore) { |
| 805 | assert(V && "no value passed to dbg.value"); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 806 | assert(VarInfo && "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 807 | if (!ValueFn) |
| 808 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 809 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 810 | trackIfUnresolved(VarInfo); |
| 811 | trackIfUnresolved(Expr); |
| 812 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| 813 | ConstantInt::get(Type::getInt64Ty(VMContext), Offset), |
| 814 | MetadataAsValue::get(VMContext, VarInfo), |
| 815 | MetadataAsValue::get(VMContext, Expr)}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 816 | return CallInst::Create(ValueFn, Args, "", InsertBefore); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 819 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 820 | DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 821 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 822 | BasicBlock *InsertAtEnd) { |
| 823 | assert(V && "no value passed to dbg.value"); |
Duncan P. N. Exon Smith | 9d1cf4c | 2015-04-06 23:18:49 +0000 | [diff] [blame] | 824 | assert(VarInfo && "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 825 | if (!ValueFn) |
| 826 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 827 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 828 | trackIfUnresolved(VarInfo); |
| 829 | trackIfUnresolved(Expr); |
| 830 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| 831 | ConstantInt::get(Type::getInt64Ty(VMContext), Offset), |
| 832 | MetadataAsValue::get(VMContext, VarInfo), |
| 833 | MetadataAsValue::get(VMContext, Expr)}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 834 | return CallInst::Create(ValueFn, Args, "", InsertAtEnd); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 835 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 836 | |
| 837 | void DIBuilder::replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder) { |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 838 | { |
| 839 | TypedTrackingMDRef<MDCompositeTypeBase> N(T); |
| 840 | N->replaceVTableHolder(MDTypeRef::get(VTableHolder)); |
| 841 | T = N.get(); |
| 842 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 843 | |
| 844 | // If this didn't create a self-reference, just return. |
| 845 | if (T != VTableHolder) |
| 846 | return; |
| 847 | |
Adrian Prantl | 18a25b0 | 2015-02-11 17:45:10 +0000 | [diff] [blame] | 848 | // Look for unresolved operands. T will drop RAUW support, orphaning any |
| 849 | // cycles underneath it. |
| 850 | if (T->isResolved()) |
| 851 | for (const MDOperand &O : T->operands()) |
| 852 | if (auto *N = dyn_cast_or_null<MDNode>(O)) |
| 853 | trackIfUnresolved(N); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | void DIBuilder::replaceArrays(DICompositeType &T, DIArray Elements, |
| 857 | DIArray TParams) { |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 858 | { |
| 859 | TypedTrackingMDRef<MDCompositeTypeBase> N(T); |
| 860 | if (Elements) |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame^] | 861 | N->replaceElements(Elements); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 862 | if (TParams) |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame^] | 863 | N->replaceTemplateParams(MDTemplateParameterArray(TParams)); |
Duncan P. N. Exon Smith | 8d33fdc | 2015-04-07 04:12:02 +0000 | [diff] [blame] | 864 | T = N.get(); |
| 865 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 866 | |
| 867 | // If T isn't resolved, there's no problem. |
| 868 | if (!T->isResolved()) |
| 869 | return; |
| 870 | |
| 871 | // If "T" is resolved, it may be due to a self-reference cycle. Track the |
| 872 | // arrays explicitly if they're unresolved, or else the cycles will be |
| 873 | // orphaned. |
| 874 | if (Elements) |
| 875 | trackIfUnresolved(Elements); |
| 876 | if (TParams) |
| 877 | trackIfUnresolved(TParams); |
| 878 | } |