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