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