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 { |
| 28 | SmallVector<char, 256> Chars; |
| 29 | |
| 30 | public: |
| 31 | explicit HeaderBuilder(Twine T) { T.toVector(Chars); } |
| 32 | HeaderBuilder(const HeaderBuilder &X) : Chars(X.Chars) {} |
| 33 | HeaderBuilder(HeaderBuilder &&X) : Chars(std::move(X.Chars)) {} |
| 34 | |
| 35 | template <class Twineable> HeaderBuilder &concat(Twineable &&X) { |
| 36 | Chars.push_back(0); |
| 37 | Twine(X).toVector(Chars); |
| 38 | return *this; |
| 39 | } |
| 40 | |
| 41 | MDString *get(LLVMContext &Context) const { |
| 42 | return MDString::get(Context, StringRef(Chars.begin(), Chars.size())); |
| 43 | } |
| 44 | |
| 45 | static HeaderBuilder get(unsigned Tag) { |
| 46 | return HeaderBuilder("0x" + Twine::utohexstr(Tag)); |
| 47 | } |
| 48 | }; |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 49 | } |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 50 | |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 51 | DIBuilder::DIBuilder(Module &m) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 52 | : M(m), VMContext(M.getContext()), TempEnumTypes(nullptr), |
| 53 | TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(nullptr), |
| 54 | DeclareFn(nullptr), ValueFn(nullptr) {} |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 55 | |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 56 | void DIBuilder::finalize() { |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 57 | DIArray Enums = getOrCreateArray(AllEnumTypes); |
| 58 | DIType(TempEnumTypes).replaceAllUsesWith(Enums); |
| 59 | |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 60 | SmallVector<Value *, 16> RetainValues; |
| 61 | // Declarations and definitions of the same type may be retained. Some |
| 62 | // clients RAUW these pairs, leaving duplicates in the retained types |
| 63 | // list. Use a set to remove the duplicates while we transform the |
| 64 | // TrackingVHs back into Values. |
| 65 | SmallPtrSet<Value *, 16> RetainSet; |
| 66 | for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame^] | 67 | if (RetainSet.insert(AllRetainTypes[I]).second) |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 68 | RetainValues.push_back(AllRetainTypes[I]); |
| 69 | DIArray RetainTypes = getOrCreateArray(RetainValues); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 70 | DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes); |
| 71 | |
| 72 | DIArray SPs = getOrCreateArray(AllSubprograms); |
| 73 | DIType(TempSubprograms).replaceAllUsesWith(SPs); |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 74 | for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) { |
| 75 | DISubprogram SP(SPs.getElement(i)); |
Eric Christopher | 27deb26 | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 76 | if (MDNode *Temp = SP.getVariablesNodes()) { |
Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 77 | SmallVector<Value *, 4> Variables; |
| 78 | for (Value *V : PreservedVariables.lookup(SP)) |
| 79 | Variables.push_back(V); |
Eric Christopher | 27deb26 | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 80 | DIArray AV = getOrCreateArray(Variables); |
| 81 | DIType(Temp).replaceAllUsesWith(AV); |
| 82 | } |
Devang Patel | 59e27c5 | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 83 | } |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 84 | |
| 85 | DIArray GVs = getOrCreateArray(AllGVs); |
| 86 | DIType(TempGVs).replaceAllUsesWith(GVs); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 87 | |
Eric Christopher | 2c3a6dc | 2014-02-28 21:27:57 +0000 | [diff] [blame] | 88 | SmallVector<Value *, 16> RetainValuesI; |
| 89 | for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++) |
| 90 | RetainValuesI.push_back(AllImportedModules[I]); |
| 91 | DIArray IMs = getOrCreateArray(RetainValuesI); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 92 | DIType(TempImportedModules).replaceAllUsesWith(IMs); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Duncan P. N. Exon Smith | 379e375 | 2014-10-01 21:32:15 +0000 | [diff] [blame] | 95 | /// If N is compile unit return NULL otherwise return N. |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 96 | static MDNode *getNonCompileUnitScope(MDNode *N) { |
| 97 | if (DIDescriptor(N).isCompileUnit()) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 98 | return nullptr; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 99 | return N; |
Devang Patel | 2b8acaf | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 100 | } |
| 101 | |
David Blaikie | efb0d65 | 2013-03-20 23:58:12 +0000 | [diff] [blame] | 102 | static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename, |
| 103 | StringRef Directory) { |
| 104 | assert(!Filename.empty() && "Unable to create file without name"); |
| 105 | Value *Pair[] = { |
| 106 | MDString::get(VMContext, Filename), |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 107 | MDString::get(VMContext, Directory) |
David Blaikie | efb0d65 | 2013-03-20 23:58:12 +0000 | [diff] [blame] | 108 | }; |
| 109 | return MDNode::get(VMContext, Pair); |
| 110 | } |
| 111 | |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 112 | DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, |
| 113 | StringRef Directory, |
| 114 | StringRef Producer, bool isOptimized, |
| 115 | StringRef Flags, unsigned RunTimeVer, |
Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 116 | StringRef SplitName, |
Diego Novillo | 56653fd | 2014-06-24 17:02:03 +0000 | [diff] [blame] | 117 | DebugEmissionKind Kind, |
| 118 | bool EmitDebugInfo) { |
Eric Christopher | 75d49db | 2014-02-27 01:24:56 +0000 | [diff] [blame] | 119 | |
Peter Collingbourne | b2f70c7 | 2014-04-28 18:11:01 +0000 | [diff] [blame] | 120 | assert(((Lang <= dwarf::DW_LANG_OCaml && Lang >= dwarf::DW_LANG_C89) || |
Chandler Carruth | 4c0ee74 | 2012-01-10 18:18:52 +0000 | [diff] [blame] | 121 | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
| 122 | "Invalid Language tag"); |
| 123 | assert(!Filename.empty() && |
| 124 | "Unable to create compile unit without filename"); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 125 | Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)}; |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 126 | TempEnumTypes = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 127 | |
| 128 | TempRetainTypes = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 129 | |
| 130 | TempSubprograms = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 131 | |
| 132 | TempGVs = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 133 | |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 134 | TempImportedModules = MDNode::getTemporary(VMContext, TElts); |
| 135 | |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 136 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_compile_unit) |
| 137 | .concat(Lang) |
| 138 | .concat(Producer) |
| 139 | .concat(isOptimized) |
| 140 | .concat(Flags) |
| 141 | .concat(RunTimeVer) |
| 142 | .concat(SplitName) |
| 143 | .concat(Kind) |
| 144 | .get(VMContext), |
| 145 | createFilePathPair(VMContext, Filename, Directory), |
| 146 | TempEnumTypes, TempRetainTypes, TempSubprograms, TempGVs, |
| 147 | TempImportedModules}; |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 148 | |
| 149 | MDNode *CUNode = MDNode::get(VMContext, Elts); |
Devang Patel | 09fa69e | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 150 | |
| 151 | // 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] | 152 | // Note that we only generate this when the caller wants to actually |
| 153 | // emit debug information. When we are only interested in tracking |
| 154 | // source line locations throughout the backend, we prevent codegen from |
| 155 | // emitting debug info in the final output by not generating llvm.dbg.cu. |
| 156 | if (EmitDebugInfo) { |
| 157 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
| 158 | NMD->addOperand(CUNode); |
| 159 | } |
Eric Christopher | 03b3e11 | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 160 | |
| 161 | return DICompileUnit(CUNode); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 162 | } |
| 163 | |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 164 | static DIImportedEntity |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 165 | createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context, |
| 166 | Value *NS, unsigned Line, StringRef Name, |
| 167 | SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) { |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 168 | const MDNode *R; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 169 | Value *Elts[] = {HeaderBuilder::get(Tag).concat(Line).concat(Name).get(C), |
| 170 | Context, NS}; |
| 171 | R = MDNode::get(C, Elts); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 172 | DIImportedEntity M(R); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 173 | assert(M.Verify() && "Imported module should be valid"); |
Eric Christopher | 2c3a6dc | 2014-02-28 21:27:57 +0000 | [diff] [blame] | 174 | AllImportedModules.push_back(TrackingVH<MDNode>(M)); |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 175 | return M; |
| 176 | } |
| 177 | |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 178 | DIImportedEntity DIBuilder::createImportedModule(DIScope Context, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 179 | DINameSpace NS, |
| 180 | unsigned Line) { |
| 181 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 182 | Context, NS, Line, StringRef(), AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | DIImportedEntity DIBuilder::createImportedModule(DIScope Context, |
| 186 | DIImportedEntity NS, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 187 | unsigned Line) { |
| 188 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, |
| 189 | Context, NS, Line, StringRef(), AllImportedModules); |
David Blaikie | e63d5d1 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 190 | } |
| 191 | |
David Blaikie | 1fd4365 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 192 | DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context, |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 193 | DIDescriptor Decl, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 194 | unsigned Line, StringRef Name) { |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 195 | // Make sure to use the unique identifier based metadata reference for |
| 196 | // types that have one. |
Frederic Riss | 051cd75 | 2014-11-06 19:00:47 +0000 | [diff] [blame] | 197 | Value *V = Decl.isType() ? static_cast<Value*>(DIType(Decl).getRef()) : Decl; |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 198 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
Frederic Riss | 4aa51ae | 2014-11-06 17:46:55 +0000 | [diff] [blame] | 199 | Context, V, Line, Name, |
David Blaikie | 2a40c14 | 2014-04-06 06:29:01 +0000 | [diff] [blame] | 200 | AllImportedModules); |
| 201 | } |
| 202 | |
| 203 | DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context, |
| 204 | DIImportedEntity Imp, |
| 205 | unsigned Line, StringRef Name) { |
| 206 | return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, |
| 207 | Context, Imp, Line, Name, AllImportedModules); |
David Blaikie | f55abea | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 210 | DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 211 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_file_type).get(VMContext), |
| 212 | createFilePathPair(VMContext, Filename, Directory)}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 213 | return DIFile(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 214 | } |
| 215 | |
David Blaikie | b761900 | 2013-06-24 17:34:33 +0000 | [diff] [blame] | 216 | DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 217 | assert(!Name.empty() && "Unable to create enumerator without name"); |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 218 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 219 | HeaderBuilder::get(dwarf::DW_TAG_enumerator).concat(Name).concat(Val).get( |
| 220 | VMContext)}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 221 | return DIEnumerator(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 224 | DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) { |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 225 | assert(!Name.empty() && "Unable to create type without name"); |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 226 | // Unspecified types are encoded in DIBasicType format. Line number, filename, |
| 227 | // size, alignment, offset and flags are always empty here. |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 228 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 229 | HeaderBuilder::get(dwarf::DW_TAG_unspecified_type) |
| 230 | .concat(Name) |
| 231 | .concat(0) |
| 232 | .concat(0) |
| 233 | .concat(0) |
| 234 | .concat(0) |
| 235 | .concat(0) |
| 236 | .concat(0) |
| 237 | .get(VMContext), |
| 238 | nullptr, // Filename |
| 239 | nullptr // Unused |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 240 | }; |
Manman Ren | 3c6acec | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 241 | return DIBasicType(MDNode::get(VMContext, Elts)); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Peter Collingbourne | a4a47cb | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 244 | DIBasicType DIBuilder::createNullPtrType() { |
| 245 | return createUnspecifiedType("decltype(nullptr)"); |
| 246 | } |
| 247 | |
David Blaikie | 209d63a | 2013-02-12 00:40:41 +0000 | [diff] [blame] | 248 | DIBasicType |
| 249 | DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
| 250 | uint64_t AlignInBits, unsigned Encoding) { |
Devang Patel | 1ad1abe | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 251 | assert(!Name.empty() && "Unable to create type without name"); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 252 | // Basic types are encoded in DIBasicType format. Line number, filename, |
| 253 | // offset and flags are always empty here. |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 254 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 255 | HeaderBuilder::get(dwarf::DW_TAG_base_type) |
| 256 | .concat(Name) |
| 257 | .concat(0) // Line |
| 258 | .concat(SizeInBits) |
| 259 | .concat(AlignInBits) |
| 260 | .concat(0) // Offset |
| 261 | .concat(0) // Flags |
| 262 | .concat(Encoding) |
| 263 | .get(VMContext), |
| 264 | nullptr, // Filename |
| 265 | nullptr // Unused |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 266 | }; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 267 | return DIBasicType(MDNode::get(VMContext, Elts)); |
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::createQualifiedType(unsigned Tag, DIType FromTy) { |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 271 | // Qualified types are encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 272 | Value *Elts[] = {HeaderBuilder::get(Tag) |
| 273 | .concat(StringRef()) // Name |
| 274 | .concat(0) // Line |
| 275 | .concat(0) // Size |
| 276 | .concat(0) // Align |
| 277 | .concat(0) // Offset |
| 278 | .concat(0) // Flags |
| 279 | .get(VMContext), |
| 280 | nullptr, // Filename |
| 281 | nullptr, // Unused |
| 282 | FromTy.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 283 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 284 | } |
| 285 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 286 | DIDerivedType |
| 287 | DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits, |
| 288 | uint64_t AlignInBits, StringRef Name) { |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 289 | // Pointer types are encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 290 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_pointer_type) |
| 291 | .concat(Name) |
| 292 | .concat(0) // Line |
| 293 | .concat(SizeInBits) |
| 294 | .concat(AlignInBits) |
| 295 | .concat(0) // Offset |
| 296 | .concat(0) // Flags |
| 297 | .get(VMContext), |
| 298 | nullptr, // Filename |
| 299 | nullptr, // Unused |
| 300 | PointeeTy.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 301 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Eric Christopher | 89e594d | 2013-04-19 20:37:12 +0000 | [diff] [blame] | 304 | DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy, |
| 305 | DIType Base) { |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 306 | // Pointer types are encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 307 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_ptr_to_member_type) |
| 308 | .concat(StringRef()) |
| 309 | .concat(0) // Line |
| 310 | .concat(0) // Size |
| 311 | .concat(0) // Align |
| 312 | .concat(0) // Offset |
| 313 | .concat(0) // Flags |
| 314 | .get(VMContext), |
| 315 | nullptr, // Filename |
| 316 | nullptr, // Unused |
| 317 | PointeeTy.getRef(), Base.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 318 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 319 | } |
| 320 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 321 | DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) { |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 322 | assert(RTy.isType() && "Unable to create reference type"); |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 323 | // References are encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 324 | Value *Elts[] = {HeaderBuilder::get(Tag) |
| 325 | .concat(StringRef()) // Name |
| 326 | .concat(0) // Line |
| 327 | .concat(0) // Size |
| 328 | .concat(0) // Align |
| 329 | .concat(0) // Offset |
| 330 | .concat(0) // Flags |
| 331 | .get(VMContext), |
| 332 | nullptr, // Filename |
| 333 | nullptr, // TheCU, |
| 334 | RTy.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 335 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 336 | } |
| 337 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 338 | DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File, |
| 339 | unsigned LineNo, DIDescriptor Context) { |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 340 | // typedefs are encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 341 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_typedef) |
| 342 | .concat(Name) |
| 343 | .concat(LineNo) |
| 344 | .concat(0) // Size |
| 345 | .concat(0) // Align |
| 346 | .concat(0) // Offset |
| 347 | .concat(0) // Flags |
| 348 | .get(VMContext), |
| 349 | File.getFileNode(), |
| 350 | DIScope(getNonCompileUnitScope(Context)).getRef(), |
| 351 | Ty.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 352 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Manman Ren | 3c6acec | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 355 | DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) { |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 356 | // typedefs are encoded in DIDerivedType format. |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 357 | assert(Ty.isType() && "Invalid type!"); |
| 358 | assert(FriendTy.isType() && "Invalid friend type!"); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 359 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_friend) |
| 360 | .concat(StringRef()) // Name |
| 361 | .concat(0) // Line |
| 362 | .concat(0) // Size |
| 363 | .concat(0) // Align |
| 364 | .concat(0) // Offset |
| 365 | .concat(0) // Flags |
| 366 | .get(VMContext), |
| 367 | nullptr, Ty.getRef(), FriendTy.getRef()}; |
Manman Ren | 3c6acec | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 368 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 371 | DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy, |
| 372 | uint64_t BaseOffset, |
| 373 | unsigned Flags) { |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 374 | assert(Ty.isType() && "Unable to create inheritance"); |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 375 | // TAG_inheritance is encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 376 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_inheritance) |
| 377 | .concat(StringRef()) // Name |
| 378 | .concat(0) // Line |
| 379 | .concat(0) // Size |
| 380 | .concat(0) // Align |
| 381 | .concat(BaseOffset) |
| 382 | .concat(Flags) |
| 383 | .get(VMContext), |
| 384 | nullptr, Ty.getRef(), BaseTy.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 385 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 388 | DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name, |
| 389 | DIFile File, unsigned LineNumber, |
| 390 | uint64_t SizeInBits, |
| 391 | uint64_t AlignInBits, |
| 392 | uint64_t OffsetInBits, unsigned Flags, |
| 393 | DIType Ty) { |
Benjamin Kramer | ed8b7bf | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 394 | // TAG_member is encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 395 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member) |
| 396 | .concat(Name) |
| 397 | .concat(LineNumber) |
| 398 | .concat(SizeInBits) |
| 399 | .concat(AlignInBits) |
| 400 | .concat(OffsetInBits) |
| 401 | .concat(Flags) |
| 402 | .get(VMContext), |
| 403 | File.getFileNode(), |
| 404 | DIScope(getNonCompileUnitScope(Scope)).getRef(), |
| 405 | Ty.getRef()}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 406 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 409 | DIDerivedType DIBuilder::createStaticMemberType(DIDescriptor Scope, |
| 410 | StringRef Name, DIFile File, |
| 411 | unsigned LineNumber, DIType Ty, |
| 412 | unsigned Flags, |
| 413 | llvm::Constant *Val) { |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 414 | // TAG_member is encoded in DIDerivedType format. |
| 415 | Flags |= DIDescriptor::FlagStaticMember; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 416 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member) |
| 417 | .concat(Name) |
| 418 | .concat(LineNumber) |
| 419 | .concat(0) // Size |
| 420 | .concat(0) // Align |
| 421 | .concat(0) // Offset |
| 422 | .concat(Flags) |
| 423 | .get(VMContext), |
| 424 | File.getFileNode(), |
| 425 | DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), |
| 426 | Val}; |
Manman Ren | 3c6acec | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 427 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 430 | DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File, |
| 431 | unsigned LineNumber, |
| 432 | uint64_t SizeInBits, |
| 433 | uint64_t AlignInBits, |
| 434 | uint64_t OffsetInBits, unsigned Flags, |
| 435 | DIType Ty, MDNode *PropertyNode) { |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 436 | // TAG_member is encoded in DIDerivedType format. |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 437 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member) |
| 438 | .concat(Name) |
| 439 | .concat(LineNumber) |
| 440 | .concat(SizeInBits) |
| 441 | .concat(AlignInBits) |
| 442 | .concat(OffsetInBits) |
| 443 | .concat(Flags) |
| 444 | .get(VMContext), |
| 445 | File.getFileNode(), getNonCompileUnitScope(File), Ty, |
| 446 | PropertyNode}; |
Manman Ren | 3c6acec | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 447 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 450 | DIObjCProperty |
| 451 | DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber, |
| 452 | StringRef GetterName, StringRef SetterName, |
| 453 | unsigned PropertyAttributes, DIType Ty) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 454 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_APPLE_property) |
| 455 | .concat(Name) |
| 456 | .concat(LineNumber) |
| 457 | .concat(GetterName) |
| 458 | .concat(SetterName) |
| 459 | .concat(PropertyAttributes) |
| 460 | .get(VMContext), |
| 461 | File, Ty}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 462 | return DIObjCProperty(MDNode::get(VMContext, Elts)); |
Devang Patel | cc48159 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Eric Christopher | 3cc90fe | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 465 | DITemplateTypeParameter |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 466 | DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name, |
Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 467 | DIType Ty, MDNode *File, unsigned LineNo, |
| 468 | unsigned ColumnNo) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 469 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_template_type_parameter) |
| 470 | .concat(Name) |
| 471 | .concat(LineNo) |
| 472 | .concat(ColumnNo) |
| 473 | .get(VMContext), |
| 474 | DIScope(getNonCompileUnitScope(Context)).getRef(), |
| 475 | Ty.getRef(), File}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 476 | return DITemplateTypeParameter(MDNode::get(VMContext, Elts)); |
Devang Patel | 3a9e65e | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 479 | static DITemplateValueParameter createTemplateValueParameterHelper( |
| 480 | LLVMContext &VMContext, unsigned Tag, DIDescriptor Context, StringRef Name, |
| 481 | DIType Ty, Value *Val, MDNode *File, unsigned LineNo, unsigned ColumnNo) { |
Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 482 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 483 | HeaderBuilder::get(Tag).concat(Name).concat(LineNo).concat(ColumnNo).get( |
| 484 | VMContext), |
| 485 | DIScope(getNonCompileUnitScope(Context)).getRef(), Ty.getRef(), Val, |
| 486 | File}; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 487 | return DITemplateValueParameter(MDNode::get(VMContext, Elts)); |
Devang Patel | be933b4 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 488 | } |
| 489 | |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 490 | DITemplateValueParameter |
| 491 | DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name, |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 492 | DIType Ty, Constant *Val, MDNode *File, |
| 493 | unsigned LineNo, unsigned ColumnNo) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 494 | return createTemplateValueParameterHelper( |
| 495 | VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty, Val, |
| 496 | File, LineNo, ColumnNo); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | DITemplateValueParameter |
| 500 | DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name, |
| 501 | DIType Ty, StringRef Val, |
| 502 | MDNode *File, unsigned LineNo, |
| 503 | unsigned ColumnNo) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 504 | return createTemplateValueParameterHelper( |
| 505 | VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 506 | MDString::get(VMContext, Val), File, LineNo, ColumnNo); |
| 507 | } |
| 508 | |
| 509 | DITemplateValueParameter |
| 510 | DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name, |
| 511 | DIType Ty, DIArray Val, |
| 512 | MDNode *File, unsigned LineNo, |
| 513 | unsigned ColumnNo) { |
Duncan P. N. Exon Smith | 774951f | 2014-11-15 00:05:04 +0000 | [diff] [blame] | 514 | return createTemplateValueParameterHelper( |
| 515 | VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty, |
| 516 | Val, File, LineNo, ColumnNo); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 517 | } |
| 518 | |
David Blaikie | a7310a3 | 2013-03-26 23:46:39 +0000 | [diff] [blame] | 519 | DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, |
| 520 | DIFile File, unsigned LineNumber, |
| 521 | uint64_t SizeInBits, |
| 522 | uint64_t AlignInBits, |
| 523 | uint64_t OffsetInBits, |
| 524 | unsigned Flags, DIType DerivedFrom, |
| 525 | DIArray Elements, |
Manman Ren | 2755206 | 2013-09-06 23:54:23 +0000 | [diff] [blame] | 526 | DIType VTableHolder, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 527 | MDNode *TemplateParams, |
| 528 | StringRef UniqueIdentifier) { |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 529 | assert((!Context || Context.isScope() || Context.isType()) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 530 | "createClassType should be called with a valid Context"); |
| 531 | // TAG_class_type is encoded in DICompositeType format. |
Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 532 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 533 | HeaderBuilder::get(dwarf::DW_TAG_class_type) |
| 534 | .concat(Name) |
| 535 | .concat(LineNumber) |
| 536 | .concat(SizeInBits) |
| 537 | .concat(AlignInBits) |
| 538 | .concat(OffsetInBits) |
| 539 | .concat(Flags) |
| 540 | .concat(0) |
| 541 | .get(VMContext), |
| 542 | File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(), |
| 543 | DerivedFrom.getRef(), Elements, VTableHolder.getRef(), TemplateParams, |
| 544 | UniqueIdentifier.empty() ? nullptr |
| 545 | : MDString::get(VMContext, UniqueIdentifier)}; |
David Blaikie | a7310a3 | 2013-03-26 23:46:39 +0000 | [diff] [blame] | 546 | DICompositeType R(MDNode::get(VMContext, Elts)); |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 547 | assert(R.isCompositeType() && |
| 548 | "createClassType should return a DICompositeType"); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 549 | if (!UniqueIdentifier.empty()) |
| 550 | retainType(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 551 | return R; |
Eric Christopher | 1742669 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 552 | } |
| 553 | |
David Blaikie | bbe0e1a | 2013-02-25 01:07:18 +0000 | [diff] [blame] | 554 | DICompositeType DIBuilder::createStructType(DIDescriptor Context, |
| 555 | StringRef Name, DIFile File, |
| 556 | unsigned LineNumber, |
| 557 | uint64_t SizeInBits, |
| 558 | uint64_t AlignInBits, |
| 559 | unsigned Flags, DIType DerivedFrom, |
| 560 | DIArray Elements, |
| 561 | unsigned RunTimeLang, |
Manman Ren | 2755206 | 2013-09-06 23:54:23 +0000 | [diff] [blame] | 562 | DIType VTableHolder, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 563 | StringRef UniqueIdentifier) { |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 564 | // TAG_structure_type is encoded in DICompositeType format. |
| 565 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 566 | HeaderBuilder::get(dwarf::DW_TAG_structure_type) |
| 567 | .concat(Name) |
| 568 | .concat(LineNumber) |
| 569 | .concat(SizeInBits) |
| 570 | .concat(AlignInBits) |
| 571 | .concat(0) |
| 572 | .concat(Flags) |
| 573 | .concat(RunTimeLang) |
| 574 | .get(VMContext), |
| 575 | File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(), |
| 576 | DerivedFrom.getRef(), Elements, VTableHolder.getRef(), nullptr, |
| 577 | UniqueIdentifier.empty() ? nullptr |
| 578 | : MDString::get(VMContext, UniqueIdentifier)}; |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 579 | DICompositeType R(MDNode::get(VMContext, Elts)); |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 580 | assert(R.isCompositeType() && |
| 581 | "createStructType should return a DICompositeType"); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 582 | if (!UniqueIdentifier.empty()) |
| 583 | retainType(R); |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 584 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Eric Christopher | 17dd8f0 | 2013-04-02 22:55:52 +0000 | [diff] [blame] | 587 | DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name, |
| 588 | DIFile File, unsigned LineNumber, |
| 589 | uint64_t SizeInBits, |
| 590 | uint64_t AlignInBits, unsigned Flags, |
| 591 | DIArray Elements, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 592 | unsigned RunTimeLang, |
| 593 | StringRef UniqueIdentifier) { |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 594 | // TAG_union_type is encoded in DICompositeType format. |
| 595 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 596 | HeaderBuilder::get(dwarf::DW_TAG_union_type) |
| 597 | .concat(Name) |
| 598 | .concat(LineNumber) |
| 599 | .concat(SizeInBits) |
| 600 | .concat(AlignInBits) |
| 601 | .concat(0) // Offset |
| 602 | .concat(Flags) |
| 603 | .concat(RunTimeLang) |
| 604 | .get(VMContext), |
| 605 | File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), |
| 606 | nullptr, Elements, nullptr, nullptr, |
| 607 | UniqueIdentifier.empty() ? nullptr |
| 608 | : MDString::get(VMContext, UniqueIdentifier)}; |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 609 | DICompositeType R(MDNode::get(VMContext, Elts)); |
| 610 | if (!UniqueIdentifier.empty()) |
| 611 | retainType(R); |
| 612 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Manman Ren | f8a1967 | 2014-07-28 22:24:06 +0000 | [diff] [blame] | 615 | DISubroutineType DIBuilder::createSubroutineType(DIFile File, |
| 616 | DITypeArray ParameterTypes, |
| 617 | unsigned Flags) { |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 618 | // TAG_subroutine_type is encoded in DICompositeType format. |
| 619 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 620 | HeaderBuilder::get(dwarf::DW_TAG_subroutine_type) |
| 621 | .concat(StringRef()) |
| 622 | .concat(0) // Line |
| 623 | .concat(0) // Size |
| 624 | .concat(0) // Align |
| 625 | .concat(0) // Offset |
| 626 | .concat(Flags) // Flags |
| 627 | .concat(0) |
| 628 | .get(VMContext), |
| 629 | nullptr, nullptr, nullptr, ParameterTypes, nullptr, nullptr, |
| 630 | nullptr // Type Identifer |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 631 | }; |
Manman Ren | f8a1967 | 2014-07-28 22:24:06 +0000 | [diff] [blame] | 632 | return DISubroutineType(MDNode::get(VMContext, Elts)); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 633 | } |
| 634 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 635 | DICompositeType DIBuilder::createEnumerationType( |
| 636 | DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, |
| 637 | uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements, |
Manman Ren | 547467b | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 638 | DIType UnderlyingType, StringRef UniqueIdentifier) { |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 639 | // TAG_enumeration_type is encoded in DICompositeType format. |
| 640 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 641 | HeaderBuilder::get(dwarf::DW_TAG_enumeration_type) |
| 642 | .concat(Name) |
| 643 | .concat(LineNumber) |
| 644 | .concat(SizeInBits) |
| 645 | .concat(AlignInBits) |
| 646 | .concat(0) // Offset |
| 647 | .concat(0) // Flags |
| 648 | .concat(0) |
| 649 | .get(VMContext), |
| 650 | File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), |
| 651 | UnderlyingType.getRef(), Elements, nullptr, nullptr, |
| 652 | UniqueIdentifier.empty() ? nullptr |
| 653 | : MDString::get(VMContext, UniqueIdentifier)}; |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 654 | DICompositeType CTy(MDNode::get(VMContext, Elts)); |
| 655 | AllEnumTypes.push_back(CTy); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 656 | if (!UniqueIdentifier.empty()) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 657 | retainType(CTy); |
| 658 | return CTy; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 659 | } |
| 660 | |
David Blaikie | f11de2f | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 661 | DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, |
| 662 | DIType Ty, DIArray Subscripts) { |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 663 | // TAG_array_type is encoded in DICompositeType format. |
| 664 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 665 | HeaderBuilder::get(dwarf::DW_TAG_array_type) |
| 666 | .concat(StringRef()) |
| 667 | .concat(0) // Line |
| 668 | .concat(Size) |
| 669 | .concat(AlignInBits) |
| 670 | .concat(0) // Offset |
| 671 | .concat(0) // Flags |
| 672 | .concat(0) |
| 673 | .get(VMContext), |
| 674 | nullptr, // Filename/Directory, |
| 675 | nullptr, // Unused |
| 676 | Ty.getRef(), Subscripts, nullptr, nullptr, |
| 677 | nullptr // Type Identifer |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 678 | }; |
David Blaikie | 5692e72 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 679 | return DICompositeType(MDNode::get(VMContext, Elts)); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Manman Ren | 6071160 | 2013-06-07 03:13:46 +0000 | [diff] [blame] | 682 | DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits, |
| 683 | DIType Ty, DIArray Subscripts) { |
Eric Christopher | 72a5295 | 2013-01-08 01:53:52 +0000 | [diff] [blame] | 684 | // A vector is an array type with the FlagVector flag applied. |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 685 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 686 | HeaderBuilder::get(dwarf::DW_TAG_array_type) |
| 687 | .concat("") |
| 688 | .concat(0) // Line |
| 689 | .concat(Size) |
| 690 | .concat(AlignInBits) |
| 691 | .concat(0) // Offset |
| 692 | .concat(DIType::FlagVector) |
| 693 | .concat(0) |
| 694 | .get(VMContext), |
| 695 | nullptr, // Filename/Directory, |
| 696 | nullptr, // Unused |
| 697 | Ty.getRef(), Subscripts, nullptr, nullptr, |
| 698 | nullptr // Type Identifer |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 699 | }; |
Manman Ren | 6071160 | 2013-06-07 03:13:46 +0000 | [diff] [blame] | 700 | return DICompositeType(MDNode::get(VMContext, Elts)); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 701 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 702 | |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 703 | static HeaderBuilder setTypeFlagsInHeader(StringRef Header, |
| 704 | unsigned FlagsToSet) { |
| 705 | DIHeaderFieldIterator I(Header); |
| 706 | std::advance(I, 6); |
| 707 | |
| 708 | unsigned Flags; |
| 709 | if (I->getAsInteger(0, Flags)) |
| 710 | Flags = 0; |
| 711 | Flags |= FlagsToSet; |
| 712 | |
| 713 | return HeaderBuilder(Twine(I.getPrefix())).concat(Flags).concat( |
| 714 | I.getSuffix()); |
| 715 | } |
| 716 | |
| 717 | static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty, |
| 718 | unsigned FlagsToSet) { |
| 719 | SmallVector<Value *, 9> Elts; |
| 720 | MDNode *N = Ty; |
| 721 | assert(N && "Unexpected input DIType!"); |
| 722 | // Update header field. |
| 723 | Elts.push_back(setTypeFlagsInHeader(Ty.getHeader(), FlagsToSet).get(Context)); |
| 724 | for (unsigned I = 1, E = N->getNumOperands(); I != E; ++I) |
| 725 | Elts.push_back(N->getOperand(I)); |
| 726 | |
| 727 | return DIType(MDNode::get(Context, Elts)); |
| 728 | } |
| 729 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 730 | DIType DIBuilder::createArtificialType(DIType Ty) { |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 731 | if (Ty.isArtificial()) |
| 732 | return Ty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 733 | return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial); |
Devang Patel | 57c5a20 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 734 | } |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 735 | |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 736 | DIType DIBuilder::createObjectPointerType(DIType Ty) { |
| 737 | if (Ty.isObjectPointer()) |
| 738 | return Ty; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 739 | unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial; |
| 740 | return createTypeWithFlags(VMContext, Ty, Flags); |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 743 | void DIBuilder::retainType(DIType T) { |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 744 | AllRetainTypes.push_back(TrackingVH<MDNode>(T)); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Manman Ren | f93ac4b | 2014-07-29 18:20:39 +0000 | [diff] [blame] | 747 | DIBasicType DIBuilder::createUnspecifiedParameter() { |
Manman Ren | 72b07e8 | 2014-07-29 22:58:13 +0000 | [diff] [blame] | 748 | return DIBasicType(); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 751 | DICompositeType |
| 752 | DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope, |
| 753 | DIFile F, unsigned Line, unsigned RuntimeLang, |
| 754 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 755 | StringRef UniqueIdentifier) { |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 756 | // Create a temporary MDNode. |
| 757 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 758 | HeaderBuilder::get(Tag) |
| 759 | .concat(Name) |
| 760 | .concat(Line) |
| 761 | .concat(SizeInBits) |
| 762 | .concat(AlignInBits) |
| 763 | .concat(0) // Offset |
| 764 | .concat(DIDescriptor::FlagFwdDecl) |
| 765 | .concat(RuntimeLang) |
| 766 | .get(VMContext), |
| 767 | F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, |
| 768 | DIArray(), nullptr, |
| 769 | nullptr, // TemplateParams |
| 770 | UniqueIdentifier.empty() ? nullptr |
| 771 | : MDString::get(VMContext, UniqueIdentifier)}; |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 772 | MDNode *Node = MDNode::get(VMContext, Elts); |
| 773 | DICompositeType RetTy(Node); |
| 774 | assert(RetTy.isCompositeType() && |
| 775 | "createForwardDecl result should be a DIType"); |
| 776 | if (!UniqueIdentifier.empty()) |
| 777 | retainType(RetTy); |
| 778 | return RetTy; |
| 779 | } |
| 780 | |
David Blaikie | d3f094a | 2014-05-06 03:41:57 +0000 | [diff] [blame] | 781 | DICompositeType DIBuilder::createReplaceableForwardDecl( |
| 782 | unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line, |
| 783 | unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, |
| 784 | StringRef UniqueIdentifier) { |
| 785 | // Create a temporary MDNode. |
| 786 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 787 | HeaderBuilder::get(Tag) |
| 788 | .concat(Name) |
| 789 | .concat(Line) |
| 790 | .concat(SizeInBits) |
| 791 | .concat(AlignInBits) |
| 792 | .concat(0) // Offset |
| 793 | .concat(DIDescriptor::FlagFwdDecl) |
| 794 | .concat(RuntimeLang) |
| 795 | .get(VMContext), |
| 796 | F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, |
| 797 | DIArray(), nullptr, |
| 798 | nullptr, // TemplateParams |
| 799 | UniqueIdentifier.empty() ? nullptr |
| 800 | : MDString::get(VMContext, UniqueIdentifier)}; |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 801 | MDNode *Node = MDNode::getTemporary(VMContext, Elts); |
David Blaikie | d4e106e | 2013-08-16 20:42:14 +0000 | [diff] [blame] | 802 | DICompositeType RetTy(Node); |
| 803 | assert(RetTy.isCompositeType() && |
Frederic Riss | a873414 | 2014-09-10 16:03:14 +0000 | [diff] [blame] | 804 | "createReplaceableForwardDecl result should be a DIType"); |
Manman Ren | 0b41040 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 805 | if (!UniqueIdentifier.empty()) |
| 806 | retainType(RetTy); |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 807 | return RetTy; |
Eric Christopher | ae56eec | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Jay Foad | dbf81d8 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 810 | DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) { |
Jay Foad | dbf81d8 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 811 | return DIArray(MDNode::get(VMContext, Elements)); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Manman Ren | 1a125c9 | 2014-07-28 19:33:20 +0000 | [diff] [blame] | 814 | DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Value *> Elements) { |
| 815 | SmallVector<llvm::Value *, 16> Elts; |
| 816 | for (unsigned i = 0, e = Elements.size(); i != e; ++i) { |
| 817 | if (Elements[i] && isa<MDNode>(Elements[i])) |
| 818 | Elts.push_back(DIType(cast<MDNode>(Elements[i])).getRef()); |
| 819 | else |
| 820 | Elts.push_back(Elements[i]); |
| 821 | } |
| 822 | return DITypeArray(MDNode::get(VMContext, Elts)); |
| 823 | } |
| 824 | |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 825 | DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 826 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subrange_type) |
| 827 | .concat(Lo) |
| 828 | .concat(Count) |
| 829 | .get(VMContext)}; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 830 | |
Devang Patel | 0c77324 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 831 | return DISubrange(MDNode::get(VMContext, Elts)); |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 834 | static DIGlobalVariable createGlobalVariableHelper( |
| 835 | LLVMContext &VMContext, DIDescriptor Context, StringRef Name, |
| 836 | StringRef LinkageName, DIFile F, unsigned LineNumber, DITypeRef Ty, |
| 837 | bool isLocalToUnit, Constant *Val, MDNode *Decl, bool isDefinition, |
| 838 | std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 839 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_variable) |
| 840 | .concat(Name) |
| 841 | .concat(Name) |
| 842 | .concat(LinkageName) |
| 843 | .concat(LineNumber) |
| 844 | .concat(isLocalToUnit) |
| 845 | .concat(isDefinition) |
| 846 | .get(VMContext), |
Manman Ren | 554865d | 2014-11-18 00:29:08 +0000 | [diff] [blame] | 847 | DIScope(getNonCompileUnitScope(Context)).getRef(), F, Ty, Val, |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 848 | DIDescriptor(Decl)}; |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 849 | |
| 850 | return DIGlobalVariable(CreateFunc(Elts)); |
| 851 | } |
| 852 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 853 | DIGlobalVariable DIBuilder::createGlobalVariable( |
| 854 | DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |
| 855 | unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val, |
| 856 | MDNode *Decl) { |
Jyoti Allur | b76b57f | 2014-09-29 06:32:54 +0000 | [diff] [blame] | 857 | return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F, |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 858 | LineNumber, Ty, isLocalToUnit, Val, Decl, true, |
| 859 | [&] (ArrayRef<Value *> Elts) -> MDNode * { |
| 860 | MDNode *Node = MDNode::get(VMContext, Elts); |
| 861 | AllGVs.push_back(Node); |
| 862 | return Node; |
| 863 | }); |
| 864 | } |
| 865 | |
Duncan P. N. Exon Smith | dbf64acd | 2014-11-15 00:23:49 +0000 | [diff] [blame] | 866 | DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl( |
| 867 | DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |
| 868 | unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val, |
| 869 | MDNode *Decl) { |
Jyoti Allur | b76b57f | 2014-09-29 06:32:54 +0000 | [diff] [blame] | 870 | return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F, |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 871 | LineNumber, Ty, isLocalToUnit, Val, Decl, false, |
| 872 | [&] (ArrayRef<Value *> Elts) { |
| 873 | return MDNode::getTemporary(VMContext, Elts); |
| 874 | }); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 877 | DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 878 | StringRef Name, DIFile File, |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 879 | unsigned LineNo, DITypeRef Ty, |
Devang Patel | 40eee1e | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 880 | bool AlwaysPreserve, unsigned Flags, |
| 881 | unsigned ArgNo) { |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 882 | DIDescriptor Context(getNonCompileUnitScope(Scope)); |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 883 | assert((!Context || Context.isScope()) && |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 884 | "createLocalVariable should be called with a valid Context"); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 885 | Value *Elts[] = {HeaderBuilder::get(Tag) |
| 886 | .concat(Name) |
| 887 | .concat(LineNo | (ArgNo << 24)) |
| 888 | .concat(Flags) |
| 889 | .get(VMContext), |
| 890 | getNonCompileUnitScope(Scope), File, Ty}; |
Devang Patel | 0c77324 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 891 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 892 | if (AlwaysPreserve) { |
| 893 | // The optimizer may remove local variable. If there is an interest |
| 894 | // to preserve variable info in such situation then stash it in a |
| 895 | // named mdnode. |
| 896 | DISubprogram Fn(getDISubprogram(Scope)); |
Duncan P. N. Exon Smith | 3bfffde | 2014-10-15 16:11:41 +0000 | [diff] [blame] | 897 | assert(Fn && "Missing subprogram for local variable"); |
| 898 | PreservedVariables[Fn].push_back(Node); |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 899 | } |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 900 | DIVariable RetVar(Node); |
| 901 | assert(RetVar.isVariable() && |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 902 | "createLocalVariable should return a valid DIVariable"); |
Manman Ren | d0e67aa | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 903 | return RetVar; |
Devang Patel | 63f83cd | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Duncan P. N. Exon Smith | 611afb2 | 2014-10-01 20:26:08 +0000 | [diff] [blame] | 906 | DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Addr) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 907 | auto Header = HeaderBuilder::get(DW_TAG_expression); |
Duncan P. N. Exon Smith | 611afb2 | 2014-10-01 20:26:08 +0000 | [diff] [blame] | 908 | for (int64_t I : Addr) |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 909 | Header.concat(I); |
| 910 | Value *Elts[] = {Header.get(VMContext)}; |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 911 | return DIExpression(MDNode::get(VMContext, Elts)); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Duncan P. N. Exon Smith | 9affbba | 2014-10-01 21:32:12 +0000 | [diff] [blame] | 914 | DIExpression DIBuilder::createPieceExpression(unsigned OffsetInBytes, |
| 915 | unsigned SizeInBytes) { |
| 916 | int64_t Addr[] = {dwarf::DW_OP_piece, OffsetInBytes, SizeInBytes}; |
| 917 | return createExpression(Addr); |
| 918 | } |
| 919 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 920 | DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name, |
| 921 | StringRef LinkageName, DIFile File, |
| 922 | unsigned LineNo, DICompositeType Ty, |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 923 | bool isLocalToUnit, bool isDefinition, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 924 | unsigned ScopeLine, unsigned Flags, |
| 925 | bool isOptimized, Function *Fn, |
| 926 | MDNode *TParams, MDNode *Decl) { |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 927 | // dragonegg does not generate identifier for types, so using an empty map |
| 928 | // to resolve the context should be fine. |
| 929 | DITypeIdentifierMap EmptyMap; |
| 930 | return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File, |
| 931 | LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, |
| 932 | Flags, isOptimized, Fn, TParams, Decl); |
| 933 | } |
| 934 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 935 | static DISubprogram |
| 936 | createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Name, |
| 937 | StringRef LinkageName, DIFile File, unsigned LineNo, |
| 938 | DICompositeType Ty, bool isLocalToUnit, bool isDefinition, |
| 939 | unsigned ScopeLine, unsigned Flags, bool isOptimized, |
| 940 | Function *Fn, MDNode *TParams, MDNode *Decl, |
| 941 | std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) { |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 942 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 943 | "function types should be subroutines"); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 944 | Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)}; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 945 | Value *Elts[] = { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 946 | HeaderBuilder::get(dwarf::DW_TAG_subprogram) |
| 947 | .concat(Name) |
| 948 | .concat(Name) |
| 949 | .concat(LinkageName) |
| 950 | .concat(LineNo) |
| 951 | .concat(isLocalToUnit) |
| 952 | .concat(isDefinition) |
| 953 | .concat(0) |
| 954 | .concat(0) |
| 955 | .concat(Flags) |
| 956 | .concat(isOptimized) |
| 957 | .concat(ScopeLine) |
| 958 | .get(VMContext), |
| 959 | File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(), Ty, |
| 960 | nullptr, Fn, TParams, Decl, MDNode::getTemporary(VMContext, TElts)}; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 961 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 962 | DISubprogram S(CreateFunc(Elts)); |
Eric Christopher | 961959f | 2014-02-28 21:27:59 +0000 | [diff] [blame] | 963 | assert(S.isSubprogram() && |
| 964 | "createFunction should return a valid DISubprogram"); |
David Blaikie | cc8d090 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 965 | return S; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 968 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 969 | DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name, |
| 970 | StringRef LinkageName, DIFile File, |
| 971 | unsigned LineNo, DICompositeType Ty, |
| 972 | bool isLocalToUnit, bool isDefinition, |
| 973 | unsigned ScopeLine, unsigned Flags, |
| 974 | bool isOptimized, Function *Fn, |
| 975 | MDNode *TParams, MDNode *Decl) { |
| 976 | return createFunctionHelper(VMContext, Context, Name, LinkageName, File, |
| 977 | LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, |
| 978 | Flags, isOptimized, Fn, TParams, Decl, |
| 979 | [&] (ArrayRef<Value *> Elts) -> MDNode *{ |
| 980 | MDNode *Node = MDNode::get(VMContext, Elts); |
| 981 | // Create a named metadata so that we |
| 982 | // do not lose this mdnode. |
| 983 | if (isDefinition) |
| 984 | AllSubprograms.push_back(Node); |
| 985 | return Node; |
| 986 | }); |
| 987 | } |
| 988 | |
Frederic Riss | 5e6bc9e | 2014-09-17 09:28:34 +0000 | [diff] [blame] | 989 | DISubprogram |
| 990 | DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name, |
| 991 | StringRef LinkageName, DIFile File, |
| 992 | unsigned LineNo, DICompositeType Ty, |
| 993 | bool isLocalToUnit, bool isDefinition, |
| 994 | unsigned ScopeLine, unsigned Flags, |
| 995 | bool isOptimized, Function *Fn, |
| 996 | MDNode *TParams, MDNode *Decl) { |
| 997 | return createFunctionHelper(VMContext, Context, Name, LinkageName, File, |
| 998 | LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, |
| 999 | Flags, isOptimized, Fn, TParams, Decl, |
| 1000 | [&] (ArrayRef<Value *> Elts) { |
| 1001 | return MDNode::getTemporary(VMContext, Elts); |
| 1002 | }); |
| 1003 | } |
| 1004 | |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 1005 | DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, |
| 1006 | StringRef LinkageName, DIFile F, |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1007 | unsigned LineNo, DICompositeType Ty, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 1008 | bool isLocalToUnit, bool isDefinition, |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1009 | unsigned VK, unsigned VIndex, |
Eric Christopher | 98f9c23 | 2013-10-15 23:31:31 +0000 | [diff] [blame] | 1010 | DIType VTableHolder, unsigned Flags, |
| 1011 | bool isOptimized, Function *Fn, |
Devang Patel | 9f73884 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1012 | MDNode *TParam) { |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1013 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 1014 | "function types should be subroutines"); |
Eric Christopher | 5cb5632 | 2013-10-15 23:31:36 +0000 | [diff] [blame] | 1015 | assert(getNonCompileUnitScope(Context) && |
| 1016 | "Methods should have both a Context and a context that isn't " |
| 1017 | "the compile unit."); |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 1018 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram) |
| 1019 | .concat(Name) |
| 1020 | .concat(Name) |
| 1021 | .concat(LinkageName) |
| 1022 | .concat(LineNo) |
| 1023 | .concat(isLocalToUnit) |
| 1024 | .concat(isDefinition) |
| 1025 | .concat(VK) |
| 1026 | .concat(VIndex) |
| 1027 | .concat(Flags) |
| 1028 | .concat(isOptimized) |
| 1029 | .concat(LineNo) |
| 1030 | // FIXME: Do we want to use different scope/lines? |
| 1031 | .get(VMContext), |
| 1032 | F.getFileNode(), DIScope(Context).getRef(), Ty, |
| 1033 | VTableHolder.getRef(), Fn, TParam, nullptr, nullptr}; |
Devang Patel | 0c77324 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 1034 | MDNode *Node = MDNode::get(VMContext, Elts); |
David Blaikie | 595eb44 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 1035 | if (isDefinition) |
| 1036 | AllSubprograms.push_back(Node); |
David Blaikie | cc8d090 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 1037 | DISubprogram S(Node); |
Manman Ren | 74c188f | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 1038 | assert(S.isSubprogram() && "createMethod should return a valid DISubprogram"); |
David Blaikie | cc8d090 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 1039 | return S; |
Devang Patel | b68c623 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1042 | DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1043 | DIFile File, unsigned LineNo) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 1044 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_namespace) |
| 1045 | .concat(Name) |
| 1046 | .concat(LineNo) |
| 1047 | .get(VMContext), |
| 1048 | File.getFileNode(), getNonCompileUnitScope(Scope)}; |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1049 | DINameSpace R(MDNode::get(VMContext, Elts)); |
| 1050 | assert(R.Verify() && |
| 1051 | "createNameSpace should return a verifiable DINameSpace"); |
| 1052 | return R; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1055 | DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, |
David Blaikie | 2f3f76f | 2014-08-21 22:45:21 +0000 | [diff] [blame] | 1056 | DIFile File, |
| 1057 | unsigned Discriminator) { |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 1058 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block) |
| 1059 | .concat(Discriminator) |
| 1060 | .get(VMContext), |
| 1061 | File.getFileNode(), Scope}; |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1062 | DILexicalBlockFile R(MDNode::get(VMContext, Elts)); |
| 1063 | assert( |
| 1064 | R.Verify() && |
| 1065 | "createLexicalBlockFile should return a verifiable DILexicalBlockFile"); |
| 1066 | return R; |
Eric Christopher | 6647b83 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1069 | DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, |
David Blaikie | 2f3f76f | 2014-08-21 22:45:21 +0000 | [diff] [blame] | 1070 | unsigned Line, unsigned Col) { |
David Blaikie | 6c21716 | 2014-05-15 20:09:55 +0000 | [diff] [blame] | 1071 | // FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing. |
| 1072 | // I believe the right way is to have a self-referential element in the node. |
| 1073 | // Also: why do we bother with line/column - they're not used and the |
| 1074 | // documentation (SourceLevelDebugging.rst) claims the line/col are necessary |
| 1075 | // for uniquing, yet then we have this other solution (because line/col were |
| 1076 | // inadequate) anyway. Remove all 3 and replace them with a self-reference. |
| 1077 | |
Adrian Prantl | 21e8d4a | 2013-06-24 21:19:43 +0000 | [diff] [blame] | 1078 | // Defeat MDNode uniquing for lexical blocks by using unique id. |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1079 | static unsigned int unique_id = 0; |
Duncan P. N. Exon Smith | 176b691 | 2014-10-03 20:01:09 +0000 | [diff] [blame] | 1080 | Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block) |
| 1081 | .concat(Line) |
| 1082 | .concat(Col) |
| 1083 | .concat(unique_id++) |
| 1084 | .get(VMContext), |
| 1085 | File.getFileNode(), getNonCompileUnitScope(Scope)}; |
David Blaikie | 085abe3 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1086 | DILexicalBlock R(MDNode::get(VMContext, Elts)); |
| 1087 | assert(R.Verify() && |
| 1088 | "createLexicalBlock should return a verifiable DILexicalBlock"); |
| 1089 | return R; |
Devang Patel | 89ea4f2 | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1092 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1093 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1094 | Instruction *InsertBefore) { |
| 1095 | assert(Storage && "no storage passed to dbg.declare"); |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1096 | assert(VarInfo.isVariable() && |
| 1097 | "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1098 | if (!DeclareFn) |
| 1099 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 1100 | |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1101 | Value *Args[] = {MDNode::get(Storage->getContext(), Storage), VarInfo, Expr}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1102 | return CallInst::Create(DeclareFn, Args, "", InsertBefore); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1105 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1106 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1107 | BasicBlock *InsertAtEnd) { |
| 1108 | assert(Storage && "no storage passed to dbg.declare"); |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1109 | assert(VarInfo.isVariable() && |
| 1110 | "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1111 | if (!DeclareFn) |
| 1112 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 1113 | |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1114 | Value *Args[] = {MDNode::get(Storage->getContext(), Storage), VarInfo, Expr}; |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1115 | |
| 1116 | // If this block already has a terminator then insert this intrinsic |
| 1117 | // before the terminator. |
| 1118 | if (TerminatorInst *T = InsertAtEnd->getTerminator()) |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1119 | return CallInst::Create(DeclareFn, Args, "", T); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1120 | else |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1121 | return CallInst::Create(DeclareFn, Args, "", InsertAtEnd); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1124 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1125 | DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1126 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1127 | Instruction *InsertBefore) { |
| 1128 | assert(V && "no value passed to dbg.value"); |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1129 | assert(VarInfo.isVariable() && |
| 1130 | "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1131 | if (!ValueFn) |
| 1132 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 1133 | |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1134 | Value *Args[] = {MDNode::get(V->getContext(), V), |
| 1135 | ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset), |
| 1136 | VarInfo, Expr}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1137 | return CallInst::Create(ValueFn, Args, "", InsertBefore); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Devang Patel | 9b41273 | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1140 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1141 | DIVariable VarInfo, |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1142 | DIExpression Expr, |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1143 | BasicBlock *InsertAtEnd) { |
| 1144 | assert(V && "no value passed to dbg.value"); |
Manman Ren | 9822a11 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1145 | assert(VarInfo.isVariable() && |
| 1146 | "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1147 | if (!ValueFn) |
| 1148 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 1149 | |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 1150 | Value *Args[] = {MDNode::get(V->getContext(), V), |
| 1151 | ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset), |
| 1152 | VarInfo, Expr}; |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1153 | return CallInst::Create(ValueFn, Args, "", InsertAtEnd); |
Devang Patel | 746660f | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1154 | } |