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); |
| 78 | DIType(TempEnumTypes).replaceAllUsesWith(Enums); |
| 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); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 90 | DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes); |
| 91 | |
| 92 | DIArray SPs = getOrCreateArray(AllSubprograms); |
| 93 | DIType(TempSubprograms).replaceAllUsesWith(SPs); |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 94 | for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) { |
| 95 | DISubprogram SP(SPs.getElement(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); |
| 100 | DIType(Temp).replaceAllUsesWith(AV); |
| 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); |
| 105 | DIType(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); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 110 | DIType(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 | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 154 | MDNode *CUNode = MDCompileUnit::get( |
| 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); |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 170 | return DICompileUnit(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 | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 177 | DIImportedEntity M = MDImportedEntity::get(C, Tag, Context, NS, Line, Name); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 178 | assert(M.Verify() && "Imported module should be valid"); |
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, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 199 | unsigned Line, StringRef Name) { |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 200 | // Make sure to use the unique identifier based metadata reference for |
| 201 | // types that have one. |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 202 | Metadata *V = |
| 203 | Decl.isType() ? static_cast<Metadata *>(DIType(Decl).getRef()) : Decl; |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 204 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 205 | Context, V, Line, Name, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 206 | AllImportedModules); |
| 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, |
| 244 | FromTy.getRef(), 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, |
| 252 | nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits, |
| 253 | 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, "", |
| 260 | nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits, |
| 261 | AlignInBits, 0, 0, Base.getRef()); |
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) { |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 265 | assert(RTy.isType() && "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, |
| 267 | RTy.getRef(), 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 | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 272 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, |
| 273 | File.getFileNode(), LineNo, |
| 274 | DIScope(getNonCompileUnitScope(Context)).getRef(), |
| 275 | Ty.getRef(), 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. |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 280 | assert(Ty.isType() && "Invalid type!"); |
| 281 | assert(FriendTy.isType() && "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, |
| 283 | Ty.getRef(), FriendTy.getRef(), 0, 0, 0, 0); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 286 | DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy, |
| 287 | uint64_t BaseOffset, |
| 288 | unsigned Flags) { |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 289 | assert(Ty.isType() && "Unable to create inheritance"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 290 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, |
| 291 | 0, Ty.getRef(), BaseTy.getRef(), 0, 0, BaseOffset, |
| 292 | Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 295 | DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name, |
| 296 | DIFile File, unsigned LineNumber, |
| 297 | uint64_t SizeInBits, |
| 298 | uint64_t AlignInBits, |
| 299 | uint64_t OffsetInBits, unsigned Flags, |
| 300 | DIType Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 301 | return MDDerivedType::get( |
| 302 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
| 303 | DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), SizeInBits, |
| 304 | AlignInBits, OffsetInBits, Flags); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Duncan P. N. Exon Smith | 3cd2cab | 2015-03-27 00:34:10 +0000 | [diff] [blame] | 307 | static ConstantAsMetadata *getConstantOrNull(Constant *C) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 308 | if (C) |
| 309 | return ConstantAsMetadata::get(C); |
| 310 | return nullptr; |
| 311 | } |
| 312 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 313 | DIDerivedType DIBuilder::createStaticMemberType(DIDescriptor Scope, |
| 314 | StringRef Name, DIFile File, |
| 315 | unsigned LineNumber, DIType Ty, |
| 316 | unsigned Flags, |
| 317 | llvm::Constant *Val) { |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 318 | // TAG_member is encoded in DIDerivedType format. |
| 319 | Flags |= DIDescriptor::FlagStaticMember; |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 320 | return MDDerivedType::get( |
| 321 | VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, |
| 322 | DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), 0, 0, 0, |
| 323 | Flags, getConstantOrNull(Val)); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 326 | DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File, |
| 327 | unsigned LineNumber, |
| 328 | uint64_t SizeInBits, |
| 329 | uint64_t AlignInBits, |
| 330 | uint64_t OffsetInBits, unsigned Flags, |
| 331 | DIType Ty, MDNode *PropertyNode) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 332 | return MDDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, |
| 333 | LineNumber, getNonCompileUnitScope(File), |
| 334 | Ty.getRef(), SizeInBits, AlignInBits, OffsetInBits, |
| 335 | Flags, PropertyNode); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 338 | DIObjCProperty |
| 339 | DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber, |
| 340 | StringRef GetterName, StringRef SetterName, |
| 341 | unsigned PropertyAttributes, DIType Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 342 | return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, |
| 343 | SetterName, PropertyAttributes, Ty); |
Devang Patel | cc48159 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Eric Christopher | 3cc90fe | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 346 | DITemplateTypeParameter |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 347 | DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 348 | DIType Ty) { |
Duncan P. N. Exon Smith | 89b075e | 2015-02-18 20:30:45 +0000 | [diff] [blame] | 349 | assert(!DIScope(getNonCompileUnitScope(Context)).getRef() && |
| 350 | "Expected compile unit"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 351 | return MDTemplateTypeParameter::get(VMContext, Name, Ty.getRef()); |
Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 354 | static DITemplateValueParameter |
| 355 | createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, |
| 356 | DIDescriptor Context, StringRef Name, |
| 357 | DIType Ty, Metadata *MD) { |
Duncan P. N. Exon Smith | 89b075e | 2015-02-18 20:30:45 +0000 | [diff] [blame] | 358 | assert(!DIScope(getNonCompileUnitScope(Context)).getRef() && |
| 359 | "Expected compile unit"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 360 | return MDTemplateValueParameter::get(VMContext, Tag, Name, Ty.getRef(), MD); |
Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 361 | } |
| 362 | |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 363 | DITemplateValueParameter |
| 364 | DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 365 | DIType Ty, Constant *Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 366 | return createTemplateValueParameterHelper( |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 367 | 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] | 368 | getConstantOrNull(Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | DITemplateValueParameter |
| 372 | DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 373 | DIType Ty, StringRef Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 374 | return createTemplateValueParameterHelper( |
| 375 | 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] | 376 | MDString::get(VMContext, Val)); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | DITemplateValueParameter |
| 380 | DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | b4aa16f | 2015-02-13 03:35:29 +0000 | [diff] [blame] | 381 | DIType Ty, DIArray Val) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 382 | return createTemplateValueParameterHelper( |
| 383 | 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] | 384 | Val); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 385 | } |
| 386 | |
David Blaikie | a7310a3 | 2013-03-26 23:46:39 +0000 | [diff] [blame] | 387 | DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, |
| 388 | DIFile File, unsigned LineNumber, |
| 389 | uint64_t SizeInBits, |
| 390 | uint64_t AlignInBits, |
| 391 | uint64_t OffsetInBits, |
| 392 | unsigned Flags, DIType DerivedFrom, |
| 393 | DIArray Elements, |
Manman Ren | 2755206 | 2013-09-06 23:54:23 +0000 | [diff] [blame] | 394 | DIType VTableHolder, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 395 | MDNode *TemplateParams, |
| 396 | StringRef UniqueIdentifier) { |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 397 | assert((!Context || Context.isScope() || Context.isType()) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 398 | "createClassType should be called with a valid Context"); |
| 399 | // TAG_class_type is encoded in DICompositeType format. |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 400 | DICompositeType R = MDCompositeType::get( |
| 401 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
| 402 | DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(), |
| 403 | SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, 0, |
| 404 | VTableHolder.getRef(), TemplateParams, UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 405 | if (!UniqueIdentifier.empty()) |
| 406 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 407 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 408 | return R; |
Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 409 | } |
| 410 | |
David Blaikie | bbe0e1a | 2013-02-25 01:07:18 +0000 | [diff] [blame] | 411 | DICompositeType DIBuilder::createStructType(DIDescriptor Context, |
| 412 | StringRef Name, DIFile File, |
| 413 | unsigned LineNumber, |
| 414 | uint64_t SizeInBits, |
| 415 | uint64_t AlignInBits, |
| 416 | unsigned Flags, DIType DerivedFrom, |
| 417 | DIArray Elements, |
| 418 | unsigned RunTimeLang, |
Manman Ren | 2755206 | 2013-09-06 23:54:23 +0000 | [diff] [blame] | 419 | DIType VTableHolder, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 420 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 421 | DICompositeType R = MDCompositeType::get( |
| 422 | VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, |
| 423 | DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(), |
| 424 | SizeInBits, AlignInBits, 0, Flags, Elements, RunTimeLang, |
| 425 | VTableHolder.getRef(), nullptr, UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 426 | if (!UniqueIdentifier.empty()) |
| 427 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 428 | trackIfUnresolved(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 429 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Eric Christopher | 17dd8f0 | 2013-04-02 22:55:52 +0000 | [diff] [blame] | 432 | DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name, |
| 433 | DIFile File, unsigned LineNumber, |
| 434 | uint64_t SizeInBits, |
| 435 | uint64_t AlignInBits, unsigned Flags, |
| 436 | DIArray Elements, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 437 | unsigned RunTimeLang, |
| 438 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 439 | DICompositeType R = MDCompositeType::get( |
| 440 | VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, |
| 441 | DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits, |
| 442 | AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr, |
| 443 | UniqueIdentifier); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 444 | if (!UniqueIdentifier.empty()) |
| 445 | retainType(R); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 446 | trackIfUnresolved(R); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 447 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Manman Ren | f8a1967 | 2014-07-28 22:24:06 +0000 | [diff] [blame] | 450 | DISubroutineType DIBuilder::createSubroutineType(DIFile File, |
| 451 | DITypeArray ParameterTypes, |
| 452 | unsigned Flags) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 453 | return MDSubroutineType::get(VMContext, Flags, ParameterTypes); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 454 | } |
| 455 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 456 | DICompositeType DIBuilder::createEnumerationType( |
| 457 | DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, |
| 458 | uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 459 | DIType UnderlyingType, StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 460 | DICompositeType CTy = MDCompositeType::get( |
| 461 | VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, |
| 462 | DIScope(getNonCompileUnitScope(Scope)).getRef(), UnderlyingType.getRef(), |
| 463 | SizeInBits, AlignInBits, 0, 0, Elements, 0, nullptr, nullptr, |
| 464 | UniqueIdentifier); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 465 | AllEnumTypes.push_back(CTy); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 466 | if (!UniqueIdentifier.empty()) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 467 | retainType(CTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 468 | trackIfUnresolved(CTy); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 469 | return CTy; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 470 | } |
| 471 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 472 | DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, |
| 473 | DIType Ty, DIArray Subscripts) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 474 | auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", |
| 475 | nullptr, 0, nullptr, Ty.getRef(), Size, |
| 476 | AlignInBits, 0, 0, Subscripts, 0, nullptr); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 477 | trackIfUnresolved(R); |
| 478 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Manman Ren | 6071160 | 2013-06-07 03:13:46 +0000 | [diff] [blame] | 481 | DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits, |
| 482 | DIType Ty, DIArray Subscripts) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 483 | auto *R = MDCompositeType::get( |
| 484 | VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty.getRef(), |
| 485 | Size, AlignInBits, 0, DIType::FlagVector, Subscripts, 0, nullptr); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 486 | trackIfUnresolved(R); |
| 487 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 488 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 489 | |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 490 | static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty, |
| 491 | unsigned FlagsToSet) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 492 | TempMDType NewTy = cast<MDType>(static_cast<MDNode *>(Ty))->clone(); |
| 493 | NewTy->setFlags(NewTy->getFlags() | FlagsToSet); |
| 494 | return MDNode::replaceWithUniqued(std::move(NewTy)); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 497 | DIType DIBuilder::createArtificialType(DIType Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 498 | // FIXME: Restrict this to the nodes where it's valid. |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 499 | if (Ty.isArtificial()) |
| 500 | return Ty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 501 | return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 502 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 503 | |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 504 | DIType DIBuilder::createObjectPointerType(DIType Ty) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 505 | // FIXME: Restrict this to the nodes where it's valid. |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 506 | if (Ty.isObjectPointer()) |
| 507 | return Ty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 508 | unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial; |
| 509 | return createTypeWithFlags(VMContext, Ty, Flags); |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 512 | void DIBuilder::retainType(DIType T) { AllRetainTypes.emplace_back(T); } |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 513 | |
Manman Ren | f93ac4b | 2014-07-29 18:20:39 +0000 | [diff] [blame] | 514 | DIBasicType DIBuilder::createUnspecifiedParameter() { |
Manman Ren | 72b07e8 | 2014-07-29 22:58:13 +0000 | [diff] [blame] | 515 | return DIBasicType(); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 518 | DICompositeType |
| 519 | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope, |
| 520 | DIFile F, unsigned Line, unsigned RuntimeLang, |
| 521 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 522 | StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 523 | // FIXME: Define in terms of createReplaceableForwardDecl() by calling |
| 524 | // replaceWithUniqued(). |
| 525 | DICompositeType RetTy = MDCompositeType::get( |
| 526 | VMContext, Tag, Name, F.getFileNode(), Line, |
| 527 | DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits, |
| 528 | AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr, RuntimeLang, nullptr, |
| 529 | nullptr, UniqueIdentifier); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 530 | if (!UniqueIdentifier.empty()) |
| 531 | retainType(RetTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 532 | trackIfUnresolved(RetTy); |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 533 | return RetTy; |
| 534 | } |
| 535 | |
Adrian Prantl | 534a81a | 2015-02-11 17:45:05 +0000 | [diff] [blame] | 536 | DICompositeType DIBuilder::createReplaceableCompositeType( |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 537 | unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line, |
| 538 | unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, |
Adrian Prantl | 534a81a | 2015-02-11 17:45:05 +0000 | [diff] [blame] | 539 | unsigned Flags, StringRef UniqueIdentifier) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 540 | DICompositeType RetTy = |
| 541 | MDCompositeType::getTemporary( |
| 542 | VMContext, Tag, Name, F.getFileNode(), Line, |
| 543 | DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits, |
| 544 | AlignInBits, 0, Flags, nullptr, RuntimeLang, |
| 545 | nullptr, nullptr, UniqueIdentifier).release(); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 546 | if (!UniqueIdentifier.empty()) |
| 547 | retainType(RetTy); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 548 | trackIfUnresolved(RetTy); |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 549 | return RetTy; |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 552 | DIArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { |
Jay Foad | dbf81d8 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 553 | return DIArray(MDNode::get(VMContext, Elements)); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 556 | DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { |
| 557 | SmallVector<llvm::Metadata *, 16> Elts; |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 558 | for (unsigned i = 0, e = Elements.size(); i != e; ++i) { |
| 559 | if (Elements[i] && isa<MDNode>(Elements[i])) |
| 560 | Elts.push_back(DIType(cast<MDNode>(Elements[i])).getRef()); |
| 561 | else |
| 562 | Elts.push_back(Elements[i]); |
| 563 | } |
| 564 | return DITypeArray(MDNode::get(VMContext, Elts)); |
| 565 | } |
| 566 | |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 567 | DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 568 | return MDSubrange::get(VMContext, Count, Lo); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 571 | static void checkGlobalVariableScope(DIDescriptor Context) { |
Manman Ren | bfd2b829 | 2014-11-21 19:47:48 +0000 | [diff] [blame] | 572 | MDNode *TheCtx = getNonCompileUnitScope(Context); |
| 573 | if (DIScope(TheCtx).isCompositeType()) { |
| 574 | assert(!DICompositeType(TheCtx).getIdentifier() && |
| 575 | "Context of a global variable should not be a type with identifier"); |
| 576 | } |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 579 | DIGlobalVariable DIBuilder::createGlobalVariable( |
| 580 | DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |
| 581 | unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val, |
| 582 | MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 583 | checkGlobalVariableScope(Context); |
| 584 | |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 585 | auto *N = MDGlobalVariable::get( |
| 586 | VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, F, |
| 587 | LineNumber, Ty, isLocalToUnit, true, getConstantOrNull(Val), |
| 588 | cast_or_null<MDDerivedType>(Decl)); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 589 | AllGVs.push_back(N); |
| 590 | return N; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 593 | DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl( |
| 594 | DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |
| 595 | unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val, |
| 596 | MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 597 | checkGlobalVariableScope(Context); |
| 598 | |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 599 | return MDGlobalVariable::getTemporary( |
| 600 | VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, |
| 601 | F, LineNumber, Ty, isLocalToUnit, false, getConstantOrNull(Val), |
| 602 | cast_or_null<MDDerivedType>(Decl)).release(); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 605 | DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 606 | StringRef Name, DIFile File, |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 607 | unsigned LineNo, DITypeRef Ty, |
Devang Patel | 40eee1e | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 608 | bool AlwaysPreserve, unsigned Flags, |
| 609 | unsigned ArgNo) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 610 | // FIXME: Why getNonCompileUnitScope()? |
| 611 | // FIXME: Why is "!Context" okay here? |
| 612 | // FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT |
| 613 | // the only valid scopes)? |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 614 | DIDescriptor Context(getNonCompileUnitScope(Scope)); |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 615 | assert((!Context || Context.isScope()) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 616 | "createLocalVariable should be called with a valid Context"); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 617 | |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 618 | auto *Node = MDLocalVariable::get(VMContext, Tag, |
| 619 | cast_or_null<MDLocalScope>(Context.get()), |
| 620 | Name, File, LineNo, Ty, ArgNo, Flags); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 621 | if (AlwaysPreserve) { |
| 622 | // The optimizer may remove local variable. If there is an interest |
| 623 | // to preserve variable info in such situation then stash it in a |
| 624 | // named mdnode. |
| 625 | DISubprogram Fn(getDISubprogram(Scope)); |
Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 626 | assert(Fn && "Missing subprogram for local variable"); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 627 | PreservedVariables[Fn].emplace_back(Node); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 628 | } |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 629 | return Node; |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 632 | DIExpression DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 633 | return MDExpression::get(VMContext, Addr); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Duncan P. N. Exon Smith | bd75ad4 | 2015-02-09 22:13:27 +0000 | [diff] [blame] | 636 | DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Signed) { |
| 637 | // TODO: Remove the callers of this signed version and delete. |
| 638 | SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); |
| 639 | return createExpression(Addr); |
| 640 | } |
| 641 | |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 642 | DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBytes, |
| 643 | unsigned SizeInBytes) { |
| 644 | uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes}; |
| 645 | return MDExpression::get(VMContext, Addr); |
Duncan P. N. Exon Smith | 9affbba | 2014-10-01 21:32:12 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 648 | DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name, |
| 649 | StringRef LinkageName, DIFile File, |
| 650 | unsigned LineNo, DICompositeType Ty, |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 651 | bool isLocalToUnit, bool isDefinition, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 652 | unsigned ScopeLine, unsigned Flags, |
| 653 | bool isOptimized, Function *Fn, |
| 654 | MDNode *TParams, MDNode *Decl) { |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 655 | // dragonegg does not generate identifier for types, so using an empty map |
| 656 | // to resolve the context should be fine. |
| 657 | DITypeIdentifierMap EmptyMap; |
| 658 | return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File, |
| 659 | LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, |
| 660 | Flags, isOptimized, Fn, TParams, Decl); |
| 661 | } |
| 662 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 663 | DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name, |
| 664 | StringRef LinkageName, DIFile File, |
| 665 | unsigned LineNo, DICompositeType Ty, |
| 666 | bool isLocalToUnit, bool isDefinition, |
| 667 | unsigned ScopeLine, unsigned Flags, |
| 668 | bool isOptimized, Function *Fn, |
| 669 | MDNode *TParams, MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 670 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 671 | "function types should be subroutines"); |
| 672 | auto *Node = MDSubprogram::get( |
| 673 | VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name, |
| 674 | LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit, isDefinition, |
| 675 | ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn), |
| 676 | TParams, Decl, MDNode::getTemporary(VMContext, None).release()); |
| 677 | |
| 678 | if (isDefinition) |
| 679 | AllSubprograms.push_back(Node); |
| 680 | trackIfUnresolved(Node); |
| 681 | return Node; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 684 | DISubprogram |
| 685 | DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name, |
| 686 | StringRef LinkageName, DIFile File, |
| 687 | unsigned LineNo, DICompositeType Ty, |
| 688 | bool isLocalToUnit, bool isDefinition, |
| 689 | unsigned ScopeLine, unsigned Flags, |
| 690 | bool isOptimized, Function *Fn, |
| 691 | MDNode *TParams, MDNode *Decl) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 692 | return MDSubprogram::getTemporary( |
| 693 | VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name, |
| 694 | LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit, |
| 695 | isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, |
| 696 | getConstantOrNull(Fn), TParams, Decl, nullptr).release(); |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 699 | DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, |
| 700 | StringRef LinkageName, DIFile F, |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 701 | unsigned LineNo, DICompositeType Ty, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 702 | bool isLocalToUnit, bool isDefinition, |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 703 | unsigned VK, unsigned VIndex, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 704 | DIType VTableHolder, unsigned Flags, |
| 705 | bool isOptimized, Function *Fn, |
Devang Patel | 9f73884 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 706 | MDNode *TParam) { |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 707 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 708 | "function types should be subroutines"); |
Eric Christopher | 5cb5632 | 2013-10-15 23:31:36 +0000 | [diff] [blame] | 709 | assert(getNonCompileUnitScope(Context) && |
| 710 | "Methods should have both a Context and a context that isn't " |
| 711 | "the compile unit."); |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 712 | // FIXME: Do we want to use different scope/lines? |
| 713 | auto *Node = MDSubprogram::get( |
| 714 | VMContext, DIScope(Context).getRef(), Name, LinkageName, F.getFileNode(), |
| 715 | LineNo, Ty, isLocalToUnit, isDefinition, LineNo, VTableHolder.getRef(), |
| 716 | VK, VIndex, Flags, isOptimized, getConstantOrNull(Fn), TParam, nullptr, |
| 717 | nullptr); |
| 718 | |
David Blaikie | 595eb44 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 719 | if (isDefinition) |
| 720 | AllSubprograms.push_back(Node); |
David Blaikie | cc8d090 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 721 | DISubprogram S(Node); |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 722 | assert(S.isSubprogram() && "createMethod should return a valid DISubprogram"); |
Adrian Prantl | ea7f1c2 | 2015-02-17 19:17:39 +0000 | [diff] [blame] | 723 | trackIfUnresolved(S); |
David Blaikie | cc8d090 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 724 | return S; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 727 | DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 728 | DIFile File, unsigned LineNo) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 729 | DINameSpace R = MDNamespace::get(VMContext, getNonCompileUnitScope(Scope), |
| 730 | File.getFileNode(), Name, LineNo); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 731 | assert(R.Verify() && |
| 732 | "createNameSpace should return a verifiable DINameSpace"); |
| 733 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 736 | DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, |
David Blaikie | 2f3f76f | 2014-08-21 22:45:21 +0000 | [diff] [blame] | 737 | DIFile File, |
| 738 | unsigned Discriminator) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 739 | DILexicalBlockFile R = MDLexicalBlockFile::get( |
| 740 | VMContext, Scope, File.getFileNode(), Discriminator); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 741 | assert( |
| 742 | R.Verify() && |
| 743 | "createLexicalBlockFile should return a verifiable DILexicalBlockFile"); |
| 744 | return R; |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 747 | DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, |
David Blaikie | 2f3f76f | 2014-08-21 22:45:21 +0000 | [diff] [blame] | 748 | unsigned Line, unsigned Col) { |
Duncan P. N. Exon Smith | e274180 | 2015-03-03 17:24:31 +0000 | [diff] [blame] | 749 | // Make these distinct, to avoid merging two lexical blocks on the same |
| 750 | // file/line/column. |
| 751 | DILexicalBlock R = MDLexicalBlock::getDistinct( |
| 752 | VMContext, getNonCompileUnitScope(Scope), File.getFileNode(), Line, Col); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 753 | assert(R.Verify() && |
| 754 | "createLexicalBlock should return a verifiable DILexicalBlock"); |
| 755 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 758 | static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { |
| 759 | assert(V && "no value passed to dbg intrinsic"); |
| 760 | return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); |
| 761 | } |
| 762 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 763 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 764 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 765 | Instruction *InsertBefore) { |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 766 | assert(VarInfo.isVariable() && |
| 767 | "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 768 | if (!DeclareFn) |
| 769 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 770 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 771 | trackIfUnresolved(VarInfo); |
| 772 | trackIfUnresolved(Expr); |
| 773 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), |
| 774 | MetadataAsValue::get(VMContext, VarInfo), |
| 775 | MetadataAsValue::get(VMContext, Expr)}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 776 | return CallInst::Create(DeclareFn, Args, "", InsertBefore); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 779 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 780 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 781 | BasicBlock *InsertAtEnd) { |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 782 | assert(VarInfo.isVariable() && |
| 783 | "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"); |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 806 | assert(VarInfo.isVariable() && |
| 807 | "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 808 | if (!ValueFn) |
| 809 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 810 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 811 | trackIfUnresolved(VarInfo); |
| 812 | trackIfUnresolved(Expr); |
| 813 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| 814 | ConstantInt::get(Type::getInt64Ty(VMContext), Offset), |
| 815 | MetadataAsValue::get(VMContext, VarInfo), |
| 816 | MetadataAsValue::get(VMContext, Expr)}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 817 | return CallInst::Create(ValueFn, Args, "", InsertBefore); |
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, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 821 | DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 822 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 823 | BasicBlock *InsertAtEnd) { |
| 824 | assert(V && "no value passed to dbg.value"); |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 825 | assert(VarInfo.isVariable() && |
| 826 | "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 827 | if (!ValueFn) |
| 828 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 829 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 830 | trackIfUnresolved(VarInfo); |
| 831 | trackIfUnresolved(Expr); |
| 832 | Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), |
| 833 | ConstantInt::get(Type::getInt64Ty(VMContext), Offset), |
| 834 | MetadataAsValue::get(VMContext, VarInfo), |
| 835 | MetadataAsValue::get(VMContext, Expr)}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 836 | return CallInst::Create(ValueFn, Args, "", InsertAtEnd); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 837 | } |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 838 | |
| 839 | void DIBuilder::replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder) { |
| 840 | T.setContainingType(VTableHolder); |
| 841 | |
| 842 | // If this didn't create a self-reference, just return. |
| 843 | if (T != VTableHolder) |
| 844 | return; |
| 845 | |
Adrian Prantl | 18a25b0 | 2015-02-11 17:45:10 +0000 | [diff] [blame] | 846 | // Look for unresolved operands. T will drop RAUW support, orphaning any |
| 847 | // cycles underneath it. |
| 848 | if (T->isResolved()) |
| 849 | for (const MDOperand &O : T->operands()) |
| 850 | if (auto *N = dyn_cast_or_null<MDNode>(O)) |
| 851 | trackIfUnresolved(N); |
Duncan P. N. Exon Smith | 97f07c2 | 2014-12-18 00:46:16 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | void DIBuilder::replaceArrays(DICompositeType &T, DIArray Elements, |
| 855 | DIArray TParams) { |
| 856 | T.setArrays(Elements, TParams); |
| 857 | |
| 858 | // If T isn't resolved, there's no problem. |
| 859 | if (!T->isResolved()) |
| 860 | return; |
| 861 | |
| 862 | // If "T" is resolved, it may be due to a self-reference cycle. Track the |
| 863 | // arrays explicitly if they're unresolved, or else the cycles will be |
| 864 | // orphaned. |
| 865 | if (Elements) |
| 866 | trackIfUnresolved(Elements); |
| 867 | if (TParams) |
| 868 | trackIfUnresolved(TParams); |
| 869 | } |