Devang Patel | 35fcd65 | 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 | |
Bill Wendling | 16eeb6f | 2012-06-29 08:32:07 +0000 | [diff] [blame] | 14 | #include "llvm/DIBuilder.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/STLExtras.h" |
Bill Wendling | 0bcbd1d | 2012-06-28 00:05:13 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Constants.h" |
| 18 | #include "llvm/IR/IntrinsicInst.h" |
| 19 | #include "llvm/IR/Module.h" |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Devang Patel | 35fcd65 | 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 | |
| 26 | static Constant *GetTagConstant(LLVMContext &VMContext, unsigned Tag) { |
| 27 | assert((Tag & LLVMDebugVersionMask) == 0 && |
| 28 | "Tag too large for debug encoding!"); |
| 29 | return ConstantInt::get(Type::getInt32Ty(VMContext), Tag | LLVMDebugVersion); |
| 30 | } |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 31 | |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 32 | DIBuilder::DIBuilder(Module &m) |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 33 | : M(m), VMContext(M.getContext()), TempEnumTypes(0), |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 34 | TempRetainTypes(0), TempSubprograms(0), TempGVs(0), DeclareFn(0), |
| 35 | ValueFn(0) |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 36 | {} |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 37 | |
Devang Patel | 6326a42 | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 38 | /// finalize - Construct any deferred debug info descriptors. |
| 39 | void DIBuilder::finalize() { |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 40 | DIArray Enums = getOrCreateArray(AllEnumTypes); |
| 41 | DIType(TempEnumTypes).replaceAllUsesWith(Enums); |
| 42 | |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 43 | SmallVector<Value *, 16> RetainValues; |
| 44 | // Declarations and definitions of the same type may be retained. Some |
| 45 | // clients RAUW these pairs, leaving duplicates in the retained types |
| 46 | // list. Use a set to remove the duplicates while we transform the |
| 47 | // TrackingVHs back into Values. |
| 48 | SmallPtrSet<Value *, 16> RetainSet; |
| 49 | for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) |
| 50 | if (RetainSet.insert(AllRetainTypes[I])) |
| 51 | RetainValues.push_back(AllRetainTypes[I]); |
| 52 | DIArray RetainTypes = getOrCreateArray(RetainValues); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 53 | DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes); |
| 54 | |
| 55 | DIArray SPs = getOrCreateArray(AllSubprograms); |
| 56 | DIType(TempSubprograms).replaceAllUsesWith(SPs); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 57 | for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) { |
| 58 | DISubprogram SP(SPs.getElement(i)); |
Eric Christopher | 216432d | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 59 | SmallVector<Value *, 4> Variables; |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 60 | if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) { |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 61 | for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii) |
| 62 | Variables.push_back(NMD->getOperand(ii)); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 63 | NMD->eraseFromParent(); |
| 64 | } |
Eric Christopher | 216432d | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 65 | if (MDNode *Temp = SP.getVariablesNodes()) { |
| 66 | DIArray AV = getOrCreateArray(Variables); |
| 67 | DIType(Temp).replaceAllUsesWith(AV); |
| 68 | } |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 69 | } |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 70 | |
| 71 | DIArray GVs = getOrCreateArray(AllGVs); |
| 72 | DIType(TempGVs).replaceAllUsesWith(GVs); |
David Blaikie | c462db6 | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 73 | |
| 74 | DIArray IMs = getOrCreateArray(AllImportedModules); |
| 75 | DIType(TempImportedModules).replaceAllUsesWith(IMs); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 78 | /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return |
| 79 | /// N. |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 80 | static MDNode *getNonCompileUnitScope(MDNode *N) { |
| 81 | if (DIDescriptor(N).isCompileUnit()) |
| 82 | return NULL; |
| 83 | return N; |
Devang Patel | 6326a42 | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 84 | } |
| 85 | |
David Blaikie | 00c5c5d | 2013-03-20 23:58:12 +0000 | [diff] [blame] | 86 | static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename, |
| 87 | StringRef Directory) { |
| 88 | assert(!Filename.empty() && "Unable to create file without name"); |
| 89 | Value *Pair[] = { |
| 90 | MDString::get(VMContext, Filename), |
| 91 | MDString::get(VMContext, Directory), |
| 92 | }; |
| 93 | return MDNode::get(VMContext, Pair); |
| 94 | } |
| 95 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 96 | /// createCompileUnit - A CompileUnit provides an anchor for all debugging |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 97 | /// information generated during this instance of compilation. |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 98 | DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, |
| 99 | StringRef Directory, |
| 100 | StringRef Producer, bool isOptimized, |
| 101 | StringRef Flags, unsigned RunTimeVer, |
| 102 | StringRef SplitName) { |
Chandler Carruth | b0dc4d9 | 2012-01-10 18:18:52 +0000 | [diff] [blame] | 103 | assert(((Lang <= dwarf::DW_LANG_Python && Lang >= dwarf::DW_LANG_C89) || |
| 104 | (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && |
| 105 | "Invalid Language tag"); |
| 106 | assert(!Filename.empty() && |
| 107 | "Unable to create compile unit without filename"); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 108 | Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
| 109 | TempEnumTypes = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 110 | |
| 111 | TempRetainTypes = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 112 | |
| 113 | TempSubprograms = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 114 | |
| 115 | TempGVs = MDNode::getTemporary(VMContext, TElts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 116 | |
David Blaikie | c462db6 | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 117 | TempImportedModules = MDNode::getTemporary(VMContext, TElts); |
| 118 | |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 119 | Value *Elts[] = { |
| 120 | GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit), |
David Blaikie | 00c5c5d | 2013-03-20 23:58:12 +0000 | [diff] [blame] | 121 | createFilePathPair(VMContext, Filename, Directory), |
David Blaikie | 162c800 | 2013-03-20 22:52:54 +0000 | [diff] [blame] | 122 | ConstantInt::get(Type::getInt32Ty(VMContext), Lang), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 123 | MDString::get(VMContext, Producer), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 124 | ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), |
| 125 | MDString::get(VMContext, Flags), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 126 | ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer), |
David Blaikie | a8eefc7 | 2013-02-02 05:56:24 +0000 | [diff] [blame] | 127 | TempEnumTypes, |
| 128 | TempRetainTypes, |
| 129 | TempSubprograms, |
Eric Christopher | e4b6790 | 2013-02-22 23:50:04 +0000 | [diff] [blame] | 130 | TempGVs, |
David Blaikie | c462db6 | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 131 | TempImportedModules, |
Eric Christopher | e4b6790 | 2013-02-22 23:50:04 +0000 | [diff] [blame] | 132 | MDString::get(VMContext, SplitName) |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 133 | }; |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 134 | |
| 135 | MDNode *CUNode = MDNode::get(VMContext, Elts); |
Devang Patel | 464f4ef | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 136 | |
| 137 | // Create a named metadata so that it is easier to find cu in a module. |
| 138 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 139 | NMD->addOperand(CUNode); |
| 140 | |
| 141 | return DICompileUnit(CUNode); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 142 | } |
| 143 | |
David Blaikie | 7b72cc7 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 144 | static DIImportedEntity |
| 145 | createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS, |
| 146 | unsigned Line, StringRef Name, |
| 147 | SmallVectorImpl<Value *> &AllImportedModules) { |
| 148 | const MDNode *R; |
| 149 | if (Name.empty()) { |
| 150 | Value *Elts[] = { |
| 151 | GetTagConstant(C, dwarf::DW_TAG_imported_module), |
| 152 | Context, |
| 153 | NS, |
| 154 | ConstantInt::get(Type::getInt32Ty(C), Line), |
| 155 | }; |
| 156 | R = MDNode::get(C, Elts); |
| 157 | } else { |
| 158 | Value *Elts[] = { |
| 159 | GetTagConstant(C, dwarf::DW_TAG_imported_module), |
| 160 | Context, |
| 161 | NS, |
| 162 | ConstantInt::get(Type::getInt32Ty(C), Line), |
| 163 | MDString::get(C, Name) |
| 164 | }; |
| 165 | R = MDNode::get(C, Elts); |
| 166 | } |
| 167 | DIImportedEntity M(R); |
David Blaikie | 20d9e41 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 168 | assert(M.Verify() && "Imported module should be valid"); |
| 169 | AllImportedModules.push_back(M); |
| 170 | return M; |
| 171 | } |
| 172 | |
David Blaikie | 7b72cc7 | 2013-05-20 22:50:35 +0000 | [diff] [blame] | 173 | DIImportedEntity DIBuilder::createImportedModule(DIScope Context, |
| 174 | DINameSpace NS, unsigned Line, |
| 175 | StringRef Name) { |
| 176 | return ::createImportedModule(VMContext, Context, NS, Line, Name, |
| 177 | AllImportedModules); |
| 178 | } |
| 179 | |
| 180 | DIImportedEntity DIBuilder::createImportedModule(DIScope Context, |
| 181 | DIImportedEntity NS, |
| 182 | unsigned Line, |
| 183 | StringRef Name) { |
| 184 | return ::createImportedModule(VMContext, Context, NS, Line, Name, |
| 185 | AllImportedModules); |
| 186 | } |
| 187 | |
David Blaikie | 20d9e41 | 2013-05-07 21:35:53 +0000 | [diff] [blame] | 188 | DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context, |
| 189 | DIDescriptor Decl, |
| 190 | unsigned Line) { |
| 191 | Value *Elts[] = { |
| 192 | GetTagConstant(VMContext, dwarf::DW_TAG_imported_declaration), |
| 193 | Context, |
| 194 | Decl, |
| 195 | ConstantInt::get(Type::getInt32Ty(VMContext), Line), |
| 196 | }; |
| 197 | DIImportedEntity M(MDNode::get(VMContext, Elts)); |
David Blaikie | c462db6 | 2013-04-22 06:12:31 +0000 | [diff] [blame] | 198 | assert(M.Verify() && "Imported module should be valid"); |
| 199 | AllImportedModules.push_back(M); |
| 200 | return M; |
| 201 | } |
| 202 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 203 | /// createFile - Create a file descriptor to hold debugging information |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 204 | /// for a file. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 205 | DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) { |
David Blaikie | b4cf0ab | 2013-03-17 21:13:55 +0000 | [diff] [blame] | 206 | Value *Elts[] = { |
| 207 | GetTagConstant(VMContext, dwarf::DW_TAG_file_type), |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 208 | createFilePathPair(VMContext, Filename, Directory) |
David Blaikie | b4cf0ab | 2013-03-17 21:13:55 +0000 | [diff] [blame] | 209 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 210 | return DIFile(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 213 | /// createEnumerator - Create a single enumerator value. |
David Blaikie | 8de0a46 | 2013-06-24 17:34:33 +0000 | [diff] [blame] | 214 | DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) { |
Devang Patel | 811ae5b | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 215 | assert(!Name.empty() && "Unable to create enumerator without name"); |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 216 | Value *Elts[] = { |
| 217 | GetTagConstant(VMContext, dwarf::DW_TAG_enumerator), |
| 218 | MDString::get(VMContext, Name), |
| 219 | ConstantInt::get(Type::getInt64Ty(VMContext), Val) |
| 220 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 221 | return DIEnumerator(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Peter Collingbourne | 03ccdb5 | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 224 | /// \brief Create a DWARF unspecified type. |
| 225 | DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) { |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 226 | assert(!Name.empty() && "Unable to create type without name"); |
Peter Collingbourne | 03ccdb5 | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 227 | // Unspecified types are encoded in DIBasicType format. Line number, filename, |
| 228 | // size, alignment, offset and flags are always empty here. |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 229 | Value *Elts[] = { |
| 230 | GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 231 | NULL, // Filename |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 232 | NULL, // Unused |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 233 | MDString::get(VMContext, Name), |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 234 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 235 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 236 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 237 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 238 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags; |
Bill Wendling | 9fdb7c0 | 2012-07-06 17:49:19 +0000 | [diff] [blame] | 239 | ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 240 | }; |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 241 | return DIBasicType(MDNode::get(VMContext, Elts)); |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Peter Collingbourne | 03ccdb5 | 2013-06-27 22:50:59 +0000 | [diff] [blame] | 244 | /// \brief Create C++11 nullptr type. |
| 245 | DIBasicType DIBuilder::createNullPtrType() { |
| 246 | return createUnspecifiedType("decltype(nullptr)"); |
| 247 | } |
| 248 | |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 249 | /// createBasicType - Create debugging information entry for a basic |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 250 | /// type, e.g 'char'. |
David Blaikie | 2ce067a | 2013-02-12 00:40:41 +0000 | [diff] [blame] | 251 | DIBasicType |
| 252 | DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
| 253 | uint64_t AlignInBits, unsigned Encoding) { |
Devang Patel | 811ae5b | 2011-09-12 18:26:08 +0000 | [diff] [blame] | 254 | assert(!Name.empty() && "Unable to create type without name"); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 255 | // Basic types are encoded in DIBasicType format. Line number, filename, |
| 256 | // offset and flags are always empty here. |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 257 | Value *Elts[] = { |
| 258 | GetTagConstant(VMContext, dwarf::DW_TAG_base_type), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 259 | NULL, // File/directory name |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 260 | NULL, // Unused |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 261 | MDString::get(VMContext, Name), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 262 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 263 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 264 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 265 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 266 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags; |
| 267 | ConstantInt::get(Type::getInt32Ty(VMContext), Encoding) |
| 268 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 269 | return DIBasicType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Nick Lewycky | ffab7d0 | 2011-11-09 22:45:04 +0000 | [diff] [blame] | 272 | /// createQualifiedType - Create debugging information entry for a qualified |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 273 | /// type, e.g. 'const int'. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 274 | DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 275 | // Qualified types are encoded in DIDerivedType format. |
| 276 | Value *Elts[] = { |
| 277 | GetTagConstant(VMContext, Tag), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 278 | NULL, // Filename |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 279 | NULL, // Unused |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 280 | MDString::get(VMContext, StringRef()), // Empty name. |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 281 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 282 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 283 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 284 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 285 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 286 | FromTy |
| 287 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 288 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 291 | /// createPointerType - Create debugging information entry for a pointer. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 292 | DIDerivedType |
| 293 | DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits, |
| 294 | uint64_t AlignInBits, StringRef Name) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 295 | // Pointer types are encoded in DIDerivedType format. |
| 296 | Value *Elts[] = { |
| 297 | GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 298 | NULL, // Filename |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 299 | NULL, // Unused |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 300 | MDString::get(VMContext, Name), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 301 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 302 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 303 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 304 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 305 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 306 | PointeeTy |
| 307 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 308 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Eric Christopher | 09b7981 | 2013-04-19 20:37:12 +0000 | [diff] [blame] | 311 | DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy, |
| 312 | DIType Base) { |
David Blaikie | 62fdfb5 | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 313 | // Pointer types are encoded in DIDerivedType format. |
| 314 | Value *Elts[] = { |
| 315 | GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 316 | NULL, // Filename |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 317 | NULL, // Unused |
David Blaikie | 62fdfb5 | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 318 | NULL, |
David Blaikie | 62fdfb5 | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 319 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 320 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 321 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 322 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 323 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 324 | PointeeTy, |
Manman Ren | 5930eab | 2013-09-06 18:27:00 +0000 | [diff] [blame^] | 325 | Base.generateRef() |
David Blaikie | 62fdfb5 | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 326 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 327 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
David Blaikie | 62fdfb5 | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Eric Christopher | 791e629 | 2012-05-19 01:36:37 +0000 | [diff] [blame] | 330 | /// createReferenceType - Create debugging information entry for a reference |
| 331 | /// type. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 332 | DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) { |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 333 | assert(RTy.isType() && "Unable to create reference type"); |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 334 | // References are encoded in DIDerivedType format. |
| 335 | Value *Elts[] = { |
Eric Christopher | 791e629 | 2012-05-19 01:36:37 +0000 | [diff] [blame] | 336 | GetTagConstant(VMContext, Tag), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 337 | NULL, // Filename |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 338 | NULL, // TheCU, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 339 | NULL, // Name |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 340 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 341 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 342 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 343 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 344 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 345 | RTy |
| 346 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 347 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 350 | /// createTypedef - Create debugging information entry for a typedef. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 351 | DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File, |
| 352 | unsigned LineNo, DIDescriptor Context) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 353 | // typedefs are encoded in DIDerivedType format. |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 354 | assert(Ty.isType() && "Invalid typedef type!"); |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 355 | Value *Elts[] = { |
| 356 | GetTagConstant(VMContext, dwarf::DW_TAG_typedef), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 357 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 358 | getNonCompileUnitScope(Context), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 359 | MDString::get(VMContext, Name), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 360 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 361 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 362 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 363 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 364 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 365 | Ty |
| 366 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 367 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 370 | /// createFriend - Create debugging information entry for a 'friend'. |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 371 | DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 372 | // typedefs are encoded in DIDerivedType format. |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 373 | assert(Ty.isType() && "Invalid type!"); |
| 374 | assert(FriendTy.isType() && "Invalid friend type!"); |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 375 | Value *Elts[] = { |
| 376 | GetTagConstant(VMContext, dwarf::DW_TAG_friend), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 377 | NULL, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 378 | Ty, |
| 379 | NULL, // Name |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 380 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 381 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 382 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 383 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 384 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 385 | FriendTy |
| 386 | }; |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 387 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 390 | /// createInheritance - Create debugging information entry to establish |
Eric Christopher | c27c734 | 2011-09-12 19:58:22 +0000 | [diff] [blame] | 391 | /// inheritance relationship between two types. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 392 | DIDerivedType DIBuilder::createInheritance( |
| 393 | DIType Ty, DIType BaseTy, uint64_t BaseOffset, unsigned Flags) { |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 394 | assert(Ty.isType() && "Unable to create inheritance"); |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 395 | // TAG_inheritance is encoded in DIDerivedType format. |
| 396 | Value *Elts[] = { |
| 397 | GetTagConstant(VMContext, dwarf::DW_TAG_inheritance), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 398 | NULL, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 399 | Ty, |
| 400 | NULL, // Name |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 401 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 402 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 403 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 404 | ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset), |
| 405 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 406 | BaseTy |
| 407 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 408 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 411 | /// createMemberType - Create debugging information entry for a member. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 412 | DIDerivedType DIBuilder::createMemberType( |
| 413 | DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, |
| 414 | uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, |
| 415 | unsigned Flags, DIType Ty) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 416 | // TAG_member is encoded in DIDerivedType format. |
| 417 | Value *Elts[] = { |
| 418 | GetTagConstant(VMContext, dwarf::DW_TAG_member), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 419 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 420 | getNonCompileUnitScope(Scope), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 421 | MDString::get(VMContext, Name), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 422 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 423 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 424 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 425 | ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), |
| 426 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 427 | Ty |
| 428 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 429 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 432 | /// createStaticMemberType - Create debugging information entry for a |
| 433 | /// C++ static data member. |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 434 | DIDerivedType |
| 435 | DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name, |
| 436 | DIFile File, unsigned LineNumber, |
| 437 | DIType Ty, unsigned Flags, |
| 438 | llvm::Value *Val) { |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 439 | // TAG_member is encoded in DIDerivedType format. |
| 440 | Flags |= DIDescriptor::FlagStaticMember; |
| 441 | Value *Elts[] = { |
| 442 | GetTagConstant(VMContext, dwarf::DW_TAG_member), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 443 | File.getFileNode(), |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 444 | getNonCompileUnitScope(Scope), |
| 445 | MDString::get(VMContext, Name), |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 446 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 447 | ConstantInt::get(Type::getInt64Ty(VMContext), 0/*SizeInBits*/), |
| 448 | ConstantInt::get(Type::getInt64Ty(VMContext), 0/*AlignInBits*/), |
| 449 | ConstantInt::get(Type::getInt64Ty(VMContext), 0/*OffsetInBits*/), |
| 450 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 451 | Ty, |
| 452 | Val |
| 453 | }; |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 454 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 457 | /// createObjCIVar - Create debugging information entry for Objective-C |
| 458 | /// instance variable. |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 459 | DIDerivedType |
| 460 | DIBuilder::createObjCIVar(StringRef Name, |
| 461 | DIFile File, unsigned LineNumber, |
| 462 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 463 | uint64_t OffsetInBits, unsigned Flags, |
| 464 | DIType Ty, StringRef PropertyName, |
| 465 | StringRef GetterName, StringRef SetterName, |
| 466 | unsigned PropertyAttributes) { |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 467 | // TAG_member is encoded in DIDerivedType format. |
| 468 | Value *Elts[] = { |
| 469 | GetTagConstant(VMContext, dwarf::DW_TAG_member), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 470 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 471 | getNonCompileUnitScope(File), |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 472 | MDString::get(VMContext, Name), |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 473 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 474 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 475 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 476 | ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), |
| 477 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 478 | Ty, |
| 479 | MDString::get(VMContext, PropertyName), |
| 480 | MDString::get(VMContext, GetterName), |
| 481 | MDString::get(VMContext, SetterName), |
| 482 | ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes) |
| 483 | }; |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 484 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 487 | /// createObjCIVar - Create debugging information entry for Objective-C |
| 488 | /// instance variable. |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 489 | DIDerivedType |
| 490 | DIBuilder::createObjCIVar(StringRef Name, |
| 491 | DIFile File, unsigned LineNumber, |
| 492 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 493 | uint64_t OffsetInBits, unsigned Flags, |
| 494 | DIType Ty, MDNode *PropertyNode) { |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 495 | // TAG_member is encoded in DIDerivedType format. |
| 496 | Value *Elts[] = { |
| 497 | GetTagConstant(VMContext, dwarf::DW_TAG_member), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 498 | File.getFileNode(), |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 499 | getNonCompileUnitScope(File), |
| 500 | MDString::get(VMContext, Name), |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 501 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 502 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 503 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 504 | ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), |
| 505 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 506 | Ty, |
| 507 | PropertyNode |
| 508 | }; |
Manman Ren | 576d49a | 2013-06-07 18:35:53 +0000 | [diff] [blame] | 509 | return DIDerivedType(MDNode::get(VMContext, Elts)); |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 512 | /// createObjCProperty - Create debugging information entry for Objective-C |
| 513 | /// property. |
Eric Christopher | b8ca988 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 514 | DIObjCProperty DIBuilder::createObjCProperty(StringRef Name, |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 515 | DIFile File, unsigned LineNumber, |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 516 | StringRef GetterName, |
Adrian Prantl | 2f445be | 2013-04-19 19:56:02 +0000 | [diff] [blame] | 517 | StringRef SetterName, |
Eric Christopher | b8ca988 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 518 | unsigned PropertyAttributes, |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 519 | DIType Ty) { |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 520 | Value *Elts[] = { |
Eric Christopher | 6c31ee2 | 2012-03-29 21:35:05 +0000 | [diff] [blame] | 521 | GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property), |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 522 | MDString::get(VMContext, Name), |
Eric Christopher | b8ca988 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 523 | File, |
| 524 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 525 | MDString::get(VMContext, GetterName), |
| 526 | MDString::get(VMContext, SetterName), |
Eric Christopher | b8ca988 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 527 | ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes), |
| 528 | Ty |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 529 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 530 | return DIObjCProperty(MDNode::get(VMContext, Elts)); |
Devang Patel | 1ea02d4 | 2012-02-04 00:59:25 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 533 | /// createTemplateTypeParameter - Create debugging information for template |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 534 | /// type parameter. |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 535 | DITemplateTypeParameter |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 536 | DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name, |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 537 | DIType Ty, MDNode *File, unsigned LineNo, |
| 538 | unsigned ColumnNo) { |
| 539 | Value *Elts[] = { |
| 540 | GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 541 | getNonCompileUnitScope(Context), |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 542 | MDString::get(VMContext, Name), |
| 543 | Ty, |
| 544 | File, |
| 545 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 546 | ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo) |
| 547 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 548 | return DITemplateTypeParameter(MDNode::get(VMContext, Elts)); |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 551 | DITemplateValueParameter |
David Blaikie | e88939c | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 552 | DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context, |
| 553 | StringRef Name, DIType Ty, |
| 554 | Value *Val, MDNode *File, |
| 555 | unsigned LineNo, |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 556 | unsigned ColumnNo) { |
| 557 | Value *Elts[] = { |
David Blaikie | e88939c | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 558 | GetTagConstant(VMContext, Tag), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 559 | getNonCompileUnitScope(Context), |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 560 | MDString::get(VMContext, Name), |
| 561 | Ty, |
David Blaikie | 4de9d72 | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 562 | Val, |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 563 | File, |
| 564 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 565 | ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo) |
| 566 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 567 | return DITemplateValueParameter(MDNode::get(VMContext, Elts)); |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 568 | } |
| 569 | |
David Blaikie | e88939c | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 570 | /// createTemplateValueParameter - Create debugging information for template |
| 571 | /// value parameter. |
| 572 | DITemplateValueParameter |
| 573 | DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name, |
| 574 | DIType Ty, Value *Val, |
| 575 | MDNode *File, unsigned LineNo, |
| 576 | unsigned ColumnNo) { |
| 577 | return createTemplateValueParameter(dwarf::DW_TAG_template_value_parameter, |
| 578 | Context, Name, Ty, Val, File, LineNo, |
| 579 | ColumnNo); |
| 580 | } |
| 581 | |
| 582 | DITemplateValueParameter |
| 583 | DIBuilder::createTemplateTemplateParameter(DIDescriptor Context, StringRef Name, |
| 584 | DIType Ty, StringRef Val, |
| 585 | MDNode *File, unsigned LineNo, |
| 586 | unsigned ColumnNo) { |
| 587 | return createTemplateValueParameter( |
| 588 | dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, |
| 589 | MDString::get(VMContext, Val), File, LineNo, ColumnNo); |
| 590 | } |
| 591 | |
| 592 | DITemplateValueParameter |
| 593 | DIBuilder::createTemplateParameterPack(DIDescriptor Context, StringRef Name, |
| 594 | DIType Ty, DIArray Val, |
| 595 | MDNode *File, unsigned LineNo, |
| 596 | unsigned ColumnNo) { |
| 597 | return createTemplateValueParameter(dwarf::DW_TAG_GNU_template_parameter_pack, |
| 598 | Context, Name, Ty, Val, File, LineNo, |
| 599 | ColumnNo); |
| 600 | } |
| 601 | |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 602 | /// createClassType - Create debugging information entry for a class. |
David Blaikie | ca442a4 | 2013-03-26 23:46:39 +0000 | [diff] [blame] | 603 | DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, |
| 604 | DIFile File, unsigned LineNumber, |
| 605 | uint64_t SizeInBits, |
| 606 | uint64_t AlignInBits, |
| 607 | uint64_t OffsetInBits, |
| 608 | unsigned Flags, DIType DerivedFrom, |
| 609 | DIArray Elements, |
| 610 | MDNode *VTableHolder, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 611 | MDNode *TemplateParams, |
| 612 | StringRef UniqueIdentifier) { |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 613 | assert((!Context || Context.isScope() || Context.isType()) && |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 614 | "createClassType should be called with a valid Context"); |
| 615 | // TAG_class_type is encoded in DICompositeType format. |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 616 | Value *Elts[] = { |
| 617 | GetTagConstant(VMContext, dwarf::DW_TAG_class_type), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 618 | File.getFileNode(), |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 619 | getNonCompileUnitScope(Context), |
| 620 | MDString::get(VMContext, Name), |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 621 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 622 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 623 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 624 | ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits), |
| 625 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 626 | DerivedFrom, |
| 627 | Elements, |
| 628 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 629 | VTableHolder, |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 630 | TemplateParams, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 631 | UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier) |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 632 | }; |
David Blaikie | ca442a4 | 2013-03-26 23:46:39 +0000 | [diff] [blame] | 633 | DICompositeType R(MDNode::get(VMContext, Elts)); |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 634 | assert(R.isCompositeType() && |
| 635 | "createClassType should return a DICompositeType"); |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 636 | if (!UniqueIdentifier.empty()) |
| 637 | retainType(R); |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 638 | return R; |
Eric Christopher | 87c06a8 | 2012-07-06 02:35:57 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 641 | /// createStructType - Create debugging information entry for a struct. |
David Blaikie | 6172f02 | 2013-02-25 01:07:18 +0000 | [diff] [blame] | 642 | DICompositeType DIBuilder::createStructType(DIDescriptor Context, |
| 643 | StringRef Name, DIFile File, |
| 644 | unsigned LineNumber, |
| 645 | uint64_t SizeInBits, |
| 646 | uint64_t AlignInBits, |
| 647 | unsigned Flags, DIType DerivedFrom, |
| 648 | DIArray Elements, |
| 649 | unsigned RunTimeLang, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 650 | MDNode *VTableHolder, |
| 651 | StringRef UniqueIdentifier) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 652 | // TAG_structure_type is encoded in DICompositeType format. |
| 653 | Value *Elts[] = { |
| 654 | GetTagConstant(VMContext, dwarf::DW_TAG_structure_type), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 655 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 656 | getNonCompileUnitScope(Context), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 657 | MDString::get(VMContext, Name), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 658 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 659 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 660 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 661 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 662 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
David Blaikie | 6172f02 | 2013-02-25 01:07:18 +0000 | [diff] [blame] | 663 | DerivedFrom, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 664 | Elements, |
| 665 | ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang), |
David Blaikie | 6172f02 | 2013-02-25 01:07:18 +0000 | [diff] [blame] | 666 | VTableHolder, |
David Blaikie | d4f92fd | 2013-02-18 07:27:30 +0000 | [diff] [blame] | 667 | NULL, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 668 | UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier) |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 669 | }; |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 670 | DICompositeType R(MDNode::get(VMContext, Elts)); |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 671 | assert(R.isCompositeType() && |
| 672 | "createStructType should return a DICompositeType"); |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 673 | if (!UniqueIdentifier.empty()) |
| 674 | retainType(R); |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 675 | return R; |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 678 | /// createUnionType - Create debugging information entry for an union. |
Eric Christopher | cf0623b | 2013-04-02 22:55:52 +0000 | [diff] [blame] | 679 | DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name, |
| 680 | DIFile File, unsigned LineNumber, |
| 681 | uint64_t SizeInBits, |
| 682 | uint64_t AlignInBits, unsigned Flags, |
| 683 | DIArray Elements, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 684 | unsigned RunTimeLang, |
| 685 | StringRef UniqueIdentifier) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 686 | // TAG_union_type is encoded in DICompositeType format. |
| 687 | Value *Elts[] = { |
| 688 | GetTagConstant(VMContext, dwarf::DW_TAG_union_type), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 689 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 690 | getNonCompileUnitScope(Scope), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 691 | MDString::get(VMContext, Name), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 692 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 693 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 694 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 695 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 696 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
Devang Patel | c104cf2 | 2011-12-16 17:51:31 +0000 | [diff] [blame] | 697 | NULL, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 698 | Elements, |
| 699 | ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang), |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 700 | NULL, |
| 701 | NULL, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 702 | UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier) |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 703 | }; |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 704 | DICompositeType R(MDNode::get(VMContext, Elts)); |
| 705 | if (!UniqueIdentifier.empty()) |
| 706 | retainType(R); |
| 707 | return R; |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 710 | /// createSubroutineType - Create subroutine type. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 711 | DICompositeType |
| 712 | DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 713 | // TAG_subroutine_type is encoded in DICompositeType format. |
| 714 | Value *Elts[] = { |
| 715 | GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type), |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 716 | Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 717 | Constant::getNullValue(Type::getInt32Ty(VMContext)), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 718 | MDString::get(VMContext, ""), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 719 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 720 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 721 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
Devang Patel | c104cf2 | 2011-12-16 17:51:31 +0000 | [diff] [blame] | 722 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 723 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Devang Patel | c104cf2 | 2011-12-16 17:51:31 +0000 | [diff] [blame] | 724 | NULL, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 725 | ParameterTypes, |
| 726 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 727 | NULL, |
| 728 | NULL, |
| 729 | NULL // Type Identifer |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 730 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 731 | return DICompositeType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 734 | /// createEnumerationType - Create debugging information entry for an |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 735 | /// enumeration. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 736 | DICompositeType DIBuilder::createEnumerationType( |
| 737 | DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber, |
| 738 | uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 739 | DIType UnderlyingType, StringRef UniqueIdentifier) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 740 | // TAG_enumeration_type is encoded in DICompositeType format. |
| 741 | Value *Elts[] = { |
| 742 | GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 743 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 744 | getNonCompileUnitScope(Scope), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 745 | MDString::get(VMContext, Name), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 746 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 747 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 748 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 749 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Eli Friedman | ce3da6f | 2012-10-05 01:49:14 +0000 | [diff] [blame] | 750 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Adrian Prantl | 2f445be | 2013-04-19 19:56:02 +0000 | [diff] [blame] | 751 | UnderlyingType, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 752 | Elements, |
| 753 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 754 | NULL, |
| 755 | NULL, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 756 | UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier) |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 757 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 758 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 759 | AllEnumTypes.push_back(Node); |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 760 | if (!UniqueIdentifier.empty()) |
| 761 | retainType(Node); |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 762 | return DICompositeType(Node); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 765 | /// createArrayType - Create debugging information entry for an array. |
David Blaikie | d67c5ca | 2013-02-18 06:41:57 +0000 | [diff] [blame] | 766 | DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, |
| 767 | DIType Ty, DIArray Subscripts) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 768 | // TAG_array_type is encoded in DICompositeType format. |
| 769 | Value *Elts[] = { |
| 770 | GetTagConstant(VMContext, dwarf::DW_TAG_array_type), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 771 | NULL, // Filename/Directory, |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 772 | NULL, // Unused |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 773 | MDString::get(VMContext, ""), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 774 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 775 | ConstantInt::get(Type::getInt64Ty(VMContext), Size), |
| 776 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 777 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 778 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 779 | Ty, |
| 780 | Subscripts, |
| 781 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 782 | NULL, |
| 783 | NULL, |
| 784 | NULL // Type Identifer |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 785 | }; |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 786 | return DICompositeType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 789 | /// createVectorType - Create debugging information entry for a vector. |
Manman Ren | 37bfb18 | 2013-06-07 03:13:46 +0000 | [diff] [blame] | 790 | DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits, |
| 791 | DIType Ty, DIArray Subscripts) { |
Eric Christopher | 9a1e0e2 | 2013-01-08 01:53:52 +0000 | [diff] [blame] | 792 | // A vector is an array type with the FlagVector flag applied. |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 793 | Value *Elts[] = { |
Eric Christopher | 9a1e0e2 | 2013-01-08 01:53:52 +0000 | [diff] [blame] | 794 | GetTagConstant(VMContext, dwarf::DW_TAG_array_type), |
David Blaikie | a13f3cd | 2013-03-19 23:25:22 +0000 | [diff] [blame] | 795 | NULL, // Filename/Directory, |
Eric Christopher | 1fe3f9a | 2013-07-19 00:51:47 +0000 | [diff] [blame] | 796 | NULL, // Unused |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 797 | MDString::get(VMContext, ""), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 798 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 799 | ConstantInt::get(Type::getInt64Ty(VMContext), Size), |
| 800 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 801 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Eric Christopher | 9a1e0e2 | 2013-01-08 01:53:52 +0000 | [diff] [blame] | 802 | ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 803 | Ty, |
| 804 | Subscripts, |
| 805 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 806 | NULL, |
| 807 | NULL, |
| 808 | NULL // Type Identifer |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 809 | }; |
Manman Ren | 37bfb18 | 2013-06-07 03:13:46 +0000 | [diff] [blame] | 810 | return DICompositeType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 811 | } |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 812 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 813 | /// createArtificialType - Create a new DIType with "artificial" flag set. |
| 814 | DIType DIBuilder::createArtificialType(DIType Ty) { |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 815 | if (Ty.isArtificial()) |
| 816 | return Ty; |
| 817 | |
| 818 | SmallVector<Value *, 9> Elts; |
| 819 | MDNode *N = Ty; |
| 820 | assert (N && "Unexpected input DIType!"); |
| 821 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 822 | if (Value *V = N->getOperand(i)) |
| 823 | Elts.push_back(V); |
| 824 | else |
| 825 | Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); |
| 826 | } |
| 827 | |
| 828 | unsigned CurFlags = Ty.getFlags(); |
| 829 | CurFlags = CurFlags | DIType::FlagArtificial; |
| 830 | |
| 831 | // Flags are stored at this slot. |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 832 | Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 833 | |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 834 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 835 | } |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 836 | |
Eric Christopher | 1f55eb4 | 2013-01-08 01:53:42 +0000 | [diff] [blame] | 837 | /// createObjectPointerType - Create a new type with both the object pointer |
| 838 | /// and artificial flags set. |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 839 | DIType DIBuilder::createObjectPointerType(DIType Ty) { |
| 840 | if (Ty.isObjectPointer()) |
| 841 | return Ty; |
| 842 | |
| 843 | SmallVector<Value *, 9> Elts; |
| 844 | MDNode *N = Ty; |
| 845 | assert (N && "Unexpected input DIType!"); |
| 846 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 847 | if (Value *V = N->getOperand(i)) |
| 848 | Elts.push_back(V); |
| 849 | else |
| 850 | Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); |
| 851 | } |
| 852 | |
| 853 | unsigned CurFlags = Ty.getFlags(); |
| 854 | CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial); |
| 855 | |
| 856 | // Flags are stored at this slot. |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 857 | Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags); |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 858 | |
David Blaikie | 72dfb05 | 2013-03-28 02:44:59 +0000 | [diff] [blame] | 859 | return DIType(MDNode::get(VMContext, Elts)); |
Eric Christopher | e521278 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 862 | /// retainType - Retain DIType in a module even if it is not referenced |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 863 | /// through debug info anchors. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 864 | void DIBuilder::retainType(DIType T) { |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 865 | AllRetainTypes.push_back(TrackingVH<MDNode>(T)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 868 | /// createUnspecifiedParameter - Create unspeicified type descriptor |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 869 | /// for the subroutine type. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 870 | DIDescriptor DIBuilder::createUnspecifiedParameter() { |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 871 | Value *Elts[] = { |
| 872 | GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters) |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 873 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 874 | return DIDescriptor(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 877 | /// createForwardDecl - Create a temporary forward-declared type that |
| 878 | /// can be RAUW'd if the full type is seen. |
David Blaikie | 692062f | 2013-08-16 20:42:14 +0000 | [diff] [blame] | 879 | DICompositeType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, |
Eric Christopher | 216432d | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 880 | DIDescriptor Scope, DIFile F, |
Eli Friedman | ce3da6f | 2012-10-05 01:49:14 +0000 | [diff] [blame] | 881 | unsigned Line, unsigned RuntimeLang, |
| 882 | uint64_t SizeInBits, |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 883 | uint64_t AlignInBits, |
| 884 | StringRef UniqueIdentifier) { |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 885 | // Create a temporary MDNode. |
| 886 | Value *Elts[] = { |
| 887 | GetTagConstant(VMContext, Tag), |
David Blaikie | 4776bce | 2013-03-20 00:26:26 +0000 | [diff] [blame] | 888 | F.getFileNode(), |
Eric Christopher | 216432d | 2012-04-23 19:00:11 +0000 | [diff] [blame] | 889 | getNonCompileUnitScope(Scope), |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 890 | MDString::get(VMContext, Name), |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 891 | ConstantInt::get(Type::getInt32Ty(VMContext), Line), |
Eli Friedman | ce3da6f | 2012-10-05 01:49:14 +0000 | [diff] [blame] | 892 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 893 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 894 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 895 | ConstantInt::get(Type::getInt32Ty(VMContext), |
Eric Christopher | 9f90e87 | 2012-02-20 18:04:14 +0000 | [diff] [blame] | 896 | DIDescriptor::FlagFwdDecl), |
| 897 | NULL, |
| 898 | DIArray(), |
David Blaikie | 692062f | 2013-08-16 20:42:14 +0000 | [diff] [blame] | 899 | ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang), |
Manman Ren | 6e3cd0e | 2013-08-26 22:39:55 +0000 | [diff] [blame] | 900 | NULL, |
| 901 | NULL, //TemplateParams |
Manman Ren | 23f84cb | 2013-08-27 23:06:40 +0000 | [diff] [blame] | 902 | UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier) |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 903 | }; |
| 904 | MDNode *Node = MDNode::getTemporary(VMContext, Elts); |
David Blaikie | 692062f | 2013-08-16 20:42:14 +0000 | [diff] [blame] | 905 | DICompositeType RetTy(Node); |
| 906 | assert(RetTy.isCompositeType() && |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 907 | "createForwardDecl result should be a DIType"); |
Manman Ren | 3a0e9b5 | 2013-08-29 23:17:54 +0000 | [diff] [blame] | 908 | if (!UniqueIdentifier.empty()) |
| 909 | retainType(RetTy); |
Manman Ren | 88328d2 | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 910 | return RetTy; |
Eric Christopher | 4fe3457 | 2012-02-08 00:22:26 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 913 | /// getOrCreateArray - Get a DIArray, create one if required. |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 914 | DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) { |
| 915 | if (Elements.empty()) { |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 916 | Value *Null = Constant::getNullValue(Type::getInt32Ty(VMContext)); |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 917 | return DIArray(MDNode::get(VMContext, Null)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 918 | } |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 919 | return DIArray(MDNode::get(VMContext, Elements)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 922 | /// getOrCreateSubrange - Create a descriptor for a value range. This |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 923 | /// implicitly uniques the values returned. |
Bill Wendling | 9493dae | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 924 | DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 925 | Value *Elts[] = { |
| 926 | GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type), |
| 927 | ConstantInt::get(Type::getInt64Ty(VMContext), Lo), |
Bill Wendling | a7645a3 | 2012-12-04 06:20:49 +0000 | [diff] [blame] | 928 | ConstantInt::get(Type::getInt64Ty(VMContext), Count) |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 931 | return DISubrange(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 932 | } |
| 933 | |
David Blaikie | 3fac43d | 2013-03-20 17:49:48 +0000 | [diff] [blame] | 934 | /// \brief Create a new descriptor for the specified global. |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 935 | DIGlobalVariable DIBuilder:: |
David Blaikie | 3fac43d | 2013-03-20 17:49:48 +0000 | [diff] [blame] | 936 | createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile F, |
| 937 | unsigned LineNumber, DIType Ty, bool isLocalToUnit, |
| 938 | Value *Val) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 939 | Value *Elts[] = { |
| 940 | GetTagConstant(VMContext, dwarf::DW_TAG_variable), |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 941 | Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 942 | NULL, // TheCU, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 943 | MDString::get(VMContext, Name), |
| 944 | MDString::get(VMContext, Name), |
David Blaikie | 3fac43d | 2013-03-20 17:49:48 +0000 | [diff] [blame] | 945 | MDString::get(VMContext, LinkageName), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 946 | F, |
| 947 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 948 | Ty, |
| 949 | ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit), |
| 950 | ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/ |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 951 | Val, |
| 952 | DIDescriptor() |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 953 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 954 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 955 | AllGVs.push_back(Node); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 956 | return DIGlobalVariable(Node); |
| 957 | } |
| 958 | |
David Blaikie | 3fac43d | 2013-03-20 17:49:48 +0000 | [diff] [blame] | 959 | /// \brief Create a new descriptor for the specified global. |
| 960 | DIGlobalVariable DIBuilder:: |
| 961 | createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber, |
| 962 | DIType Ty, bool isLocalToUnit, Value *Val) { |
| 963 | return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit, |
| 964 | Val); |
| 965 | } |
| 966 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 967 | /// createStaticVariable - Create a new descriptor for the specified static |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 968 | /// variable. |
| 969 | DIGlobalVariable DIBuilder:: |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 970 | createStaticVariable(DIDescriptor Context, StringRef Name, |
| 971 | StringRef LinkageName, DIFile F, unsigned LineNumber, |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 972 | DIType Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 973 | Value *Elts[] = { |
| 974 | GetTagConstant(VMContext, dwarf::DW_TAG_variable), |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 975 | Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 976 | getNonCompileUnitScope(Context), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 977 | MDString::get(VMContext, Name), |
| 978 | MDString::get(VMContext, Name), |
| 979 | MDString::get(VMContext, LinkageName), |
| 980 | F, |
| 981 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 982 | Ty, |
| 983 | ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit), |
| 984 | ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/ |
Eric Christopher | 6b6061f | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 985 | Val, |
| 986 | DIDescriptor(Decl) |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 987 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 988 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 989 | AllGVs.push_back(Node); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 990 | return DIGlobalVariable(Node); |
| 991 | } |
| 992 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 993 | /// createVariable - Create a new descriptor for the specified variable. |
| 994 | DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 995 | StringRef Name, DIFile File, |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 996 | unsigned LineNo, DIType Ty, |
Devang Patel | e9e16c5 | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 997 | bool AlwaysPreserve, unsigned Flags, |
| 998 | unsigned ArgNo) { |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 999 | DIDescriptor Context(getNonCompileUnitScope(Scope)); |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 1000 | assert((!Context || Context.isScope()) && |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1001 | "createLocalVariable should be called with a valid Context"); |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 1002 | assert(Ty.isType() && |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1003 | "createLocalVariable should be called with a valid type"); |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1004 | Value *Elts[] = { |
| 1005 | GetTagConstant(VMContext, Tag), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1006 | getNonCompileUnitScope(Scope), |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1007 | MDString::get(VMContext, Name), |
| 1008 | File, |
Devang Patel | e9e16c5 | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 1009 | ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))), |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1010 | Ty, |
Devang Patel | 23336b4 | 2011-07-19 19:41:54 +0000 | [diff] [blame] | 1011 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
Bill Wendling | 9fdb7c0 | 2012-07-06 17:49:19 +0000 | [diff] [blame] | 1012 | Constant::getNullValue(Type::getInt32Ty(VMContext)) |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1013 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 1014 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1015 | if (AlwaysPreserve) { |
| 1016 | // The optimizer may remove local variable. If there is an interest |
| 1017 | // to preserve variable info in such situation then stash it in a |
| 1018 | // named mdnode. |
| 1019 | DISubprogram Fn(getDISubprogram(Scope)); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1020 | NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn); |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1021 | FnLocals->addOperand(Node); |
| 1022 | } |
Manman Ren | 88328d2 | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 1023 | DIVariable RetVar(Node); |
| 1024 | assert(RetVar.isVariable() && |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 1025 | "createLocalVariable should return a valid DIVariable"); |
Manman Ren | 88328d2 | 2013-07-02 18:37:35 +0000 | [diff] [blame] | 1026 | return RetVar; |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1029 | /// createComplexVariable - Create a new descriptor for the specified variable |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1030 | /// which has a complex address expression for its address. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1031 | DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1032 | StringRef Name, DIFile F, |
| 1033 | unsigned LineNo, |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 1034 | DIType Ty, ArrayRef<Value *> Addr, |
| 1035 | unsigned ArgNo) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1036 | SmallVector<Value *, 15> Elts; |
| 1037 | Elts.push_back(GetTagConstant(VMContext, Tag)); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1038 | Elts.push_back(getNonCompileUnitScope(Scope)), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1039 | Elts.push_back(MDString::get(VMContext, Name)); |
| 1040 | Elts.push_back(F); |
Eric Christopher | 6c0046f | 2011-08-26 21:02:40 +0000 | [diff] [blame] | 1041 | Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), |
Devang Patel | 9f99721 | 2012-02-08 00:17:07 +0000 | [diff] [blame] | 1042 | (LineNo | (ArgNo << 24)))); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1043 | Elts.push_back(Ty); |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 1044 | Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); |
| 1045 | Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 1046 | Elts.append(Addr.begin(), Addr.end()); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1047 | |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 1048 | return DIVariable(MDNode::get(VMContext, Elts)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1051 | /// createFunction - Create a new descriptor for the specified function. |
| 1052 | DISubprogram DIBuilder::createFunction(DIDescriptor Context, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1053 | StringRef Name, |
| 1054 | StringRef LinkageName, |
| 1055 | DIFile File, unsigned LineNo, |
David Blaikie | 3d33184 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1056 | DICompositeType Ty, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1057 | bool isLocalToUnit, bool isDefinition, |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1058 | unsigned ScopeLine, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1059 | unsigned Flags, bool isOptimized, |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1060 | Function *Fn, |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 1061 | MDNode *TParams, |
| 1062 | MDNode *Decl) { |
David Blaikie | 3d33184 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1063 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 1064 | "function types should be subroutines"); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1065 | Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1066 | Value *Elts[] = { |
| 1067 | GetTagConstant(VMContext, dwarf::DW_TAG_subprogram), |
David Blaikie | bb4e619 | 2013-03-21 23:08:34 +0000 | [diff] [blame] | 1068 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1069 | getNonCompileUnitScope(Context), |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1070 | MDString::get(VMContext, Name), |
| 1071 | MDString::get(VMContext, Name), |
| 1072 | MDString::get(VMContext, LinkageName), |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1073 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 1074 | Ty, |
| 1075 | ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit), |
| 1076 | ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition), |
| 1077 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 1078 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Devang Patel | 9642c57 | 2011-12-15 17:55:56 +0000 | [diff] [blame] | 1079 | NULL, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1080 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 1081 | ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1082 | Fn, |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 1083 | TParams, |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1084 | Decl, |
David Blaikie | f839eed | 2013-02-04 05:56:36 +0000 | [diff] [blame] | 1085 | MDNode::getTemporary(VMContext, TElts), |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1086 | ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine) |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1087 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 1088 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1089 | |
| 1090 | // Create a named metadata so that we do not lose this mdnode. |
David Blaikie | 139f7e5 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 1091 | if (isDefinition) |
| 1092 | AllSubprograms.push_back(Node); |
David Blaikie | ebb5183 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 1093 | DISubprogram S(Node); |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 1094 | assert(S.isSubprogram() && "createFunction should return a valid DISubprogram"); |
David Blaikie | ebb5183 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 1095 | return S; |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1098 | /// createMethod - Create a new descriptor for the specified C++ method. |
| 1099 | DISubprogram DIBuilder::createMethod(DIDescriptor Context, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1100 | StringRef Name, |
| 1101 | StringRef LinkageName, |
| 1102 | DIFile F, |
David Blaikie | 3d33184 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1103 | unsigned LineNo, DICompositeType Ty, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1104 | bool isLocalToUnit, |
| 1105 | bool isDefinition, |
| 1106 | unsigned VK, unsigned VIndex, |
| 1107 | MDNode *VTableHolder, |
| 1108 | unsigned Flags, |
| 1109 | bool isOptimized, |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1110 | Function *Fn, |
| 1111 | MDNode *TParam) { |
David Blaikie | 3d33184 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1112 | assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && |
| 1113 | "function types should be subroutines"); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 1114 | Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1115 | Value *Elts[] = { |
| 1116 | GetTagConstant(VMContext, dwarf::DW_TAG_subprogram), |
David Blaikie | bb4e619 | 2013-03-21 23:08:34 +0000 | [diff] [blame] | 1117 | F.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1118 | getNonCompileUnitScope(Context), |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1119 | MDString::get(VMContext, Name), |
| 1120 | MDString::get(VMContext, Name), |
| 1121 | MDString::get(VMContext, LinkageName), |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1122 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 1123 | Ty, |
| 1124 | ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit), |
| 1125 | ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition), |
| 1126 | ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK), |
| 1127 | ConstantInt::get(Type::getInt32Ty(VMContext), VIndex), |
| 1128 | VTableHolder, |
| 1129 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 1130 | ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1131 | Fn, |
| 1132 | TParam, |
Bill Wendling | f46b497 | 2012-07-06 17:47:36 +0000 | [diff] [blame] | 1133 | Constant::getNullValue(Type::getInt32Ty(VMContext)), |
David Blaikie | f839eed | 2013-02-04 05:56:36 +0000 | [diff] [blame] | 1134 | MDNode::getTemporary(VMContext, TElts), |
Eric Christopher | 2501652 | 2012-05-18 00:16:22 +0000 | [diff] [blame] | 1135 | // FIXME: Do we want to use different scope/lines? |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 1136 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo) |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1137 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 1138 | MDNode *Node = MDNode::get(VMContext, Elts); |
David Blaikie | 139f7e5 | 2013-02-18 07:10:22 +0000 | [diff] [blame] | 1139 | if (isDefinition) |
| 1140 | AllSubprograms.push_back(Node); |
David Blaikie | ebb5183 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 1141 | DISubprogram S(Node); |
Manman Ren | 89c83b7 | 2013-07-01 21:02:01 +0000 | [diff] [blame] | 1142 | assert(S.isSubprogram() && "createMethod should return a valid DISubprogram"); |
David Blaikie | ebb5183 | 2013-03-21 20:28:52 +0000 | [diff] [blame] | 1143 | return S; |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1146 | /// createNameSpace - This creates new descriptor for a namespace |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1147 | /// with the specified parent scope. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1148 | DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1149 | DIFile File, unsigned LineNo) { |
| 1150 | Value *Elts[] = { |
| 1151 | GetTagConstant(VMContext, dwarf::DW_TAG_namespace), |
David Blaikie | 6115ed0 | 2013-03-20 19:39:15 +0000 | [diff] [blame] | 1152 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1153 | getNonCompileUnitScope(Scope), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1154 | MDString::get(VMContext, Name), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1155 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo) |
| 1156 | }; |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1157 | DINameSpace R(MDNode::get(VMContext, Elts)); |
| 1158 | assert(R.Verify() && |
| 1159 | "createNameSpace should return a verifiable DINameSpace"); |
| 1160 | return R; |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1163 | /// createLexicalBlockFile - This creates a new MDNode that encapsulates |
| 1164 | /// an existing scope with a new filename. |
| 1165 | DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, |
Devang Patel | 9f99721 | 2012-02-08 00:17:07 +0000 | [diff] [blame] | 1166 | DIFile File) { |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1167 | Value *Elts[] = { |
| 1168 | GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block), |
David Blaikie | 8faed27 | 2013-03-22 20:18:46 +0000 | [diff] [blame] | 1169 | File.getFileNode(), |
David Blaikie | 7b24686 | 2013-03-22 19:13:22 +0000 | [diff] [blame] | 1170 | Scope |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1171 | }; |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1172 | DILexicalBlockFile R(MDNode::get(VMContext, Elts)); |
| 1173 | assert( |
| 1174 | R.Verify() && |
| 1175 | "createLexicalBlockFile should return a verifiable DILexicalBlockFile"); |
| 1176 | return R; |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1179 | DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1180 | unsigned Line, unsigned Col) { |
Adrian Prantl | e06db0c | 2013-06-24 21:19:43 +0000 | [diff] [blame] | 1181 | // Defeat MDNode uniquing for lexical blocks by using unique id. |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1182 | static unsigned int unique_id = 0; |
| 1183 | Value *Elts[] = { |
| 1184 | GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block), |
David Blaikie | 4b52a88 | 2013-03-22 17:33:20 +0000 | [diff] [blame] | 1185 | File.getFileNode(), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 1186 | getNonCompileUnitScope(Scope), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1187 | ConstantInt::get(Type::getInt32Ty(VMContext), Line), |
| 1188 | ConstantInt::get(Type::getInt32Ty(VMContext), Col), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1189 | ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++) |
| 1190 | }; |
David Blaikie | 6643868 | 2013-03-11 23:21:19 +0000 | [diff] [blame] | 1191 | DILexicalBlock R(MDNode::get(VMContext, Elts)); |
| 1192 | assert(R.Verify() && |
| 1193 | "createLexicalBlock should return a verifiable DILexicalBlock"); |
| 1194 | return R; |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1197 | /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 1198 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1199 | Instruction *InsertBefore) { |
| 1200 | assert(Storage && "no storage passed to dbg.declare"); |
Manman Ren | da91817 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1201 | assert(VarInfo.isVariable() && |
| 1202 | "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1203 | if (!DeclareFn) |
| 1204 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 1205 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 1206 | Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo }; |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1207 | return CallInst::Create(DeclareFn, Args, "", InsertBefore); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1210 | /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 1211 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1212 | BasicBlock *InsertAtEnd) { |
| 1213 | assert(Storage && "no storage passed to dbg.declare"); |
Manman Ren | da91817 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1214 | assert(VarInfo.isVariable() && |
| 1215 | "empty or invalid DIVariable passed to dbg.declare"); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1216 | if (!DeclareFn) |
| 1217 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 1218 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 1219 | Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo }; |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1220 | |
| 1221 | // If this block already has a terminator then insert this intrinsic |
| 1222 | // before the terminator. |
| 1223 | if (TerminatorInst *T = InsertAtEnd->getTerminator()) |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1224 | return CallInst::Create(DeclareFn, Args, "", T); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1225 | else |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1226 | return CallInst::Create(DeclareFn, Args, "", InsertAtEnd); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1229 | /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. |
| 1230 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1231 | DIVariable VarInfo, |
| 1232 | Instruction *InsertBefore) { |
| 1233 | assert(V && "no value passed to dbg.value"); |
Manman Ren | da91817 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1234 | assert(VarInfo.isVariable() && |
| 1235 | "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1236 | if (!ValueFn) |
| 1237 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 1238 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 1239 | Value *Args[] = { MDNode::get(V->getContext(), V), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1240 | ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset), |
| 1241 | VarInfo }; |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1242 | return CallInst::Create(ValueFn, Args, "", InsertBefore); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 1245 | /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. |
| 1246 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1247 | DIVariable VarInfo, |
| 1248 | BasicBlock *InsertAtEnd) { |
| 1249 | assert(V && "no value passed to dbg.value"); |
Manman Ren | da91817 | 2013-06-29 05:01:19 +0000 | [diff] [blame] | 1250 | assert(VarInfo.isVariable() && |
| 1251 | "empty or invalid DIVariable passed to dbg.value"); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1252 | if (!ValueFn) |
| 1253 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 1254 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 1255 | Value *Args[] = { MDNode::get(V->getContext(), V), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1256 | ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset), |
| 1257 | VarInfo }; |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1258 | return CallInst::Create(ValueFn, Args, "", InsertAtEnd); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 1259 | } |