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 | |
| 14 | #include "llvm/Analysis/DIBuilder.h" |
| 15 | #include "llvm/Analysis/DebugInfo.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/IntrinsicInst.h" |
| 18 | #include "llvm/Module.h" |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Dwarf.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | using namespace llvm::dwarf; |
| 24 | |
| 25 | static Constant *GetTagConstant(LLVMContext &VMContext, unsigned Tag) { |
| 26 | assert((Tag & LLVMDebugVersionMask) == 0 && |
| 27 | "Tag too large for debug encoding!"); |
| 28 | return ConstantInt::get(Type::getInt32Ty(VMContext), Tag | LLVMDebugVersion); |
| 29 | } |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 30 | |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 31 | DIBuilder::DIBuilder(Module &m) |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 32 | : M(m), VMContext(M.getContext()), TheCU(0), TempEnumTypes(0), |
| 33 | TempRetainTypes(0), TempSubprograms(0), TempGVs(0), DeclareFn(0), ValueFn(0) |
| 34 | {} |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 35 | |
Devang Patel | 6326a42 | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 36 | /// finalize - Construct any deferred debug info descriptors. |
| 37 | void DIBuilder::finalize() { |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 38 | DIArray Enums = getOrCreateArray(AllEnumTypes); |
| 39 | DIType(TempEnumTypes).replaceAllUsesWith(Enums); |
| 40 | |
| 41 | DIArray RetainTypes = getOrCreateArray(AllRetainTypes); |
| 42 | DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes); |
| 43 | |
| 44 | DIArray SPs = getOrCreateArray(AllSubprograms); |
| 45 | DIType(TempSubprograms).replaceAllUsesWith(SPs); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 46 | for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) { |
| 47 | DISubprogram SP(SPs.getElement(i)); |
| 48 | if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) { |
| 49 | SmallVector<Value *, 4> Variables; |
| 50 | for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii) |
| 51 | Variables.push_back(NMD->getOperand(ii)); |
| 52 | if (MDNode *Temp = SP.getVariablesNodes()) { |
| 53 | DIArray AV = getOrCreateArray(Variables); |
| 54 | DIType(Temp).replaceAllUsesWith(AV); |
| 55 | } |
| 56 | NMD->eraseFromParent(); |
| 57 | } |
| 58 | } |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 59 | |
| 60 | DIArray GVs = getOrCreateArray(AllGVs); |
| 61 | DIType(TempGVs).replaceAllUsesWith(GVs); |
| 62 | } |
| 63 | |
| 64 | /// getNonCompileUnitScope - If N is compile unit return NULL otherwise return N. |
| 65 | static MDNode *getNonCompileUnitScope(MDNode *N) { |
| 66 | if (DIDescriptor(N).isCompileUnit()) |
| 67 | return NULL; |
| 68 | return N; |
Devang Patel | 6326a42 | 2011-08-15 23:00:00 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 71 | /// createCompileUnit - A CompileUnit provides an anchor for all debugging |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 72 | /// information generated during this instance of compilation. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 73 | void DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 74 | StringRef Directory, StringRef Producer, |
| 75 | bool isOptimized, StringRef Flags, |
| 76 | unsigned RunTimeVer) { |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 77 | Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
| 78 | TempEnumTypes = MDNode::getTemporary(VMContext, TElts); |
| 79 | Value *THElts[] = { TempEnumTypes }; |
| 80 | MDNode *EnumHolder = MDNode::get(VMContext, THElts); |
| 81 | |
| 82 | TempRetainTypes = MDNode::getTemporary(VMContext, TElts); |
| 83 | Value *TRElts[] = { TempRetainTypes }; |
| 84 | MDNode *RetainHolder = MDNode::get(VMContext, TRElts); |
| 85 | |
| 86 | TempSubprograms = MDNode::getTemporary(VMContext, TElts); |
| 87 | Value *TSElts[] = { TempSubprograms }; |
| 88 | MDNode *SPHolder = MDNode::get(VMContext, TSElts); |
| 89 | |
| 90 | TempGVs = MDNode::getTemporary(VMContext, TElts); |
| 91 | Value *TVElts[] = { TempGVs }; |
| 92 | MDNode *GVHolder = MDNode::get(VMContext, TVElts); |
| 93 | |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 94 | Value *Elts[] = { |
| 95 | GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit), |
| 96 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 97 | ConstantInt::get(Type::getInt32Ty(VMContext), Lang), |
| 98 | MDString::get(VMContext, Filename), |
| 99 | MDString::get(VMContext, Directory), |
| 100 | MDString::get(VMContext, Producer), |
| 101 | // Deprecate isMain field. |
| 102 | ConstantInt::get(Type::getInt1Ty(VMContext), true), // isMain |
| 103 | ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), |
| 104 | MDString::get(VMContext, Flags), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 105 | ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer), |
| 106 | EnumHolder, |
| 107 | RetainHolder, |
| 108 | SPHolder, |
| 109 | GVHolder |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 110 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 111 | TheCU = DICompileUnit(MDNode::get(VMContext, Elts)); |
Devang Patel | 464f4ef | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 112 | |
| 113 | // Create a named metadata so that it is easier to find cu in a module. |
| 114 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); |
| 115 | NMD->addOperand(TheCU); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 118 | /// createFile - Create a file descriptor to hold debugging information |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 119 | /// for a file. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 120 | DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 121 | assert(TheCU && "Unable to create DW_TAG_file_type without CompileUnit"); |
| 122 | Value *Elts[] = { |
| 123 | GetTagConstant(VMContext, dwarf::DW_TAG_file_type), |
| 124 | MDString::get(VMContext, Filename), |
| 125 | MDString::get(VMContext, Directory), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 126 | NULL // TheCU |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 127 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 128 | return DIFile(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 131 | /// createEnumerator - Create a single enumerator value. |
| 132 | DIEnumerator DIBuilder::createEnumerator(StringRef Name, uint64_t Val) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 133 | Value *Elts[] = { |
| 134 | GetTagConstant(VMContext, dwarf::DW_TAG_enumerator), |
| 135 | MDString::get(VMContext, Name), |
| 136 | ConstantInt::get(Type::getInt64Ty(VMContext), Val) |
| 137 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 138 | return DIEnumerator(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 141 | /// createBasicType - Create debugging information entry for a basic |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 142 | /// type, e.g 'char'. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 143 | DIType DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 144 | uint64_t AlignInBits, |
| 145 | unsigned Encoding) { |
| 146 | // Basic types are encoded in DIBasicType format. Line number, filename, |
| 147 | // offset and flags are always empty here. |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 148 | Value *Elts[] = { |
| 149 | GetTagConstant(VMContext, dwarf::DW_TAG_base_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 150 | NULL, //TheCU, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 151 | MDString::get(VMContext, Name), |
| 152 | NULL, // Filename |
| 153 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 154 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 155 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 156 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 157 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags; |
| 158 | ConstantInt::get(Type::getInt32Ty(VMContext), Encoding) |
| 159 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 160 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 163 | /// createQaulifiedType - Create debugging information entry for a qualified |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 164 | /// type, e.g. 'const int'. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 165 | DIType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 166 | // Qualified types are encoded in DIDerivedType format. |
| 167 | Value *Elts[] = { |
| 168 | GetTagConstant(VMContext, Tag), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 169 | NULL, //TheCU, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 170 | MDString::get(VMContext, StringRef()), // Empty name. |
| 171 | NULL, // Filename |
| 172 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 173 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 174 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 175 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 176 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 177 | FromTy |
| 178 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 179 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 182 | /// createPointerType - Create debugging information entry for a pointer. |
| 183 | DIType DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits, |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 184 | uint64_t AlignInBits, StringRef Name) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 185 | // Pointer types are encoded in DIDerivedType format. |
| 186 | Value *Elts[] = { |
| 187 | GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 188 | NULL, //TheCU, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 189 | MDString::get(VMContext, Name), |
| 190 | NULL, // Filename |
| 191 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 192 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 193 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 194 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 195 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 196 | PointeeTy |
| 197 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 198 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 201 | /// createReferenceType - Create debugging information entry for a reference. |
| 202 | DIType DIBuilder::createReferenceType(DIType RTy) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 203 | // References are encoded in DIDerivedType format. |
| 204 | Value *Elts[] = { |
| 205 | GetTagConstant(VMContext, dwarf::DW_TAG_reference_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 206 | NULL, //TheCU, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 207 | NULL, // Name |
| 208 | NULL, // Filename |
| 209 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 210 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 211 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 212 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 213 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 214 | RTy |
| 215 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 216 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 219 | /// createTypedef - Create debugging information entry for a typedef. |
| 220 | DIType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File, |
Devang Patel | da174c1 | 2011-06-03 17:04:51 +0000 | [diff] [blame] | 221 | unsigned LineNo, DIDescriptor Context) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 222 | // typedefs are encoded in DIDerivedType format. |
| 223 | assert(Ty.Verify() && "Invalid typedef type!"); |
| 224 | Value *Elts[] = { |
| 225 | GetTagConstant(VMContext, dwarf::DW_TAG_typedef), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 226 | getNonCompileUnitScope(Context), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 227 | MDString::get(VMContext, Name), |
| 228 | File, |
| 229 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 230 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 231 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 232 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 233 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 234 | Ty |
| 235 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 236 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 239 | /// createFriend - Create debugging information entry for a 'friend'. |
| 240 | DIType DIBuilder::createFriend(DIType Ty, DIType FriendTy) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 241 | // typedefs are encoded in DIDerivedType format. |
| 242 | assert(Ty.Verify() && "Invalid type!"); |
| 243 | assert(FriendTy.Verify() && "Invalid friend type!"); |
| 244 | Value *Elts[] = { |
| 245 | GetTagConstant(VMContext, dwarf::DW_TAG_friend), |
| 246 | Ty, |
| 247 | NULL, // Name |
| 248 | Ty.getFile(), |
| 249 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 250 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 251 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 252 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset |
| 253 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags |
| 254 | FriendTy |
| 255 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 256 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 259 | /// createInheritance - Create debugging information entry to establish |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 260 | /// inheritnace relationship between two types. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 261 | DIType DIBuilder::createInheritance(DIType Ty, DIType BaseTy, |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 262 | uint64_t BaseOffset, unsigned Flags) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 263 | // TAG_inheritance is encoded in DIDerivedType format. |
| 264 | Value *Elts[] = { |
| 265 | GetTagConstant(VMContext, dwarf::DW_TAG_inheritance), |
| 266 | Ty, |
| 267 | NULL, // Name |
Devang Patel | b351ebf | 2010-12-08 21:46:37 +0000 | [diff] [blame] | 268 | Ty.getFile(), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 269 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line |
| 270 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size |
| 271 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align |
| 272 | ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset), |
| 273 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 274 | BaseTy |
| 275 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 276 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 279 | /// createMemberType - Create debugging information entry for a member. |
Devang Patel | fa3f9c0 | 2011-06-24 22:00:39 +0000 | [diff] [blame] | 280 | DIType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 281 | DIFile File, unsigned LineNumber, |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 282 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 283 | uint64_t OffsetInBits, unsigned Flags, |
| 284 | DIType Ty) { |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 285 | // TAG_member is encoded in DIDerivedType format. |
| 286 | Value *Elts[] = { |
| 287 | GetTagConstant(VMContext, dwarf::DW_TAG_member), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 288 | getNonCompileUnitScope(Scope), |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 289 | MDString::get(VMContext, Name), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 290 | File, |
Benjamin Kramer | 42c9b25 | 2010-11-04 18:45:27 +0000 | [diff] [blame] | 291 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 292 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 293 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 294 | ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), |
| 295 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 296 | Ty |
| 297 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 298 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 301 | /// createObjCIVar - Create debugging information entry for Objective-C |
| 302 | /// instance variable. |
| 303 | DIType DIBuilder::createObjCIVar(StringRef Name, |
| 304 | DIFile File, unsigned LineNumber, |
| 305 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 306 | uint64_t OffsetInBits, unsigned Flags, |
| 307 | DIType Ty, StringRef PropertyName, |
| 308 | StringRef GetterName, StringRef SetterName, |
| 309 | unsigned PropertyAttributes) { |
| 310 | // TAG_member is encoded in DIDerivedType format. |
| 311 | Value *Elts[] = { |
| 312 | GetTagConstant(VMContext, dwarf::DW_TAG_member), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 313 | getNonCompileUnitScope(File), |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 314 | MDString::get(VMContext, Name), |
| 315 | File, |
| 316 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 317 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 318 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 319 | ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), |
| 320 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 321 | Ty, |
| 322 | MDString::get(VMContext, PropertyName), |
| 323 | MDString::get(VMContext, GetterName), |
| 324 | MDString::get(VMContext, SetterName), |
| 325 | ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes) |
| 326 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 327 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 330 | /// createClassType - Create debugging information entry for a class. |
| 331 | DIType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, |
Devang Patel | 0a2551d | 2010-12-08 20:18:20 +0000 | [diff] [blame] | 332 | DIFile File, unsigned LineNumber, |
| 333 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 334 | uint64_t OffsetInBits, unsigned Flags, |
| 335 | DIType DerivedFrom, DIArray Elements, |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 336 | MDNode *VTableHoder, MDNode *TemplateParams) { |
Devang Patel | 0a2551d | 2010-12-08 20:18:20 +0000 | [diff] [blame] | 337 | // TAG_class_type is encoded in DICompositeType format. |
| 338 | Value *Elts[] = { |
| 339 | GetTagConstant(VMContext, dwarf::DW_TAG_class_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 340 | getNonCompileUnitScope(Context), |
Devang Patel | 0a2551d | 2010-12-08 20:18:20 +0000 | [diff] [blame] | 341 | MDString::get(VMContext, Name), |
| 342 | File, |
| 343 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 344 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 345 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 346 | ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits), |
| 347 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 348 | DerivedFrom, |
| 349 | Elements, |
| 350 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 351 | VTableHoder, |
| 352 | TemplateParams |
Devang Patel | 0a2551d | 2010-12-08 20:18:20 +0000 | [diff] [blame] | 353 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 354 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 0a2551d | 2010-12-08 20:18:20 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 357 | /// createTemplateTypeParameter - Create debugging information for template |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 358 | /// type parameter. |
| 359 | DITemplateTypeParameter |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 360 | DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name, |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 361 | DIType Ty, MDNode *File, unsigned LineNo, |
| 362 | unsigned ColumnNo) { |
| 363 | Value *Elts[] = { |
| 364 | GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 365 | getNonCompileUnitScope(Context), |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 366 | MDString::get(VMContext, Name), |
| 367 | Ty, |
| 368 | File, |
| 369 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 370 | ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo) |
| 371 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 372 | return DITemplateTypeParameter(MDNode::get(VMContext, Elts)); |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 375 | /// createTemplateValueParameter - Create debugging information for template |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 376 | /// value parameter. |
| 377 | DITemplateValueParameter |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 378 | DIBuilder::createTemplateValueParameter(DIDescriptor Context, StringRef Name, |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 379 | DIType Ty, uint64_t Val, |
| 380 | MDNode *File, unsigned LineNo, |
| 381 | unsigned ColumnNo) { |
| 382 | Value *Elts[] = { |
| 383 | GetTagConstant(VMContext, dwarf::DW_TAG_template_value_parameter), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 384 | getNonCompileUnitScope(Context), |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 385 | MDString::get(VMContext, Name), |
| 386 | Ty, |
| 387 | ConstantInt::get(Type::getInt64Ty(VMContext), Val), |
| 388 | File, |
| 389 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 390 | ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo) |
| 391 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 392 | return DITemplateValueParameter(MDNode::get(VMContext, Elts)); |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 395 | /// createStructType - Create debugging information entry for a struct. |
| 396 | DIType DIBuilder::createStructType(DIDescriptor Context, StringRef Name, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 397 | DIFile File, unsigned LineNumber, |
| 398 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 399 | unsigned Flags, DIArray Elements, |
| 400 | unsigned RunTimeLang) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 401 | // TAG_structure_type is encoded in DICompositeType format. |
| 402 | Value *Elts[] = { |
| 403 | GetTagConstant(VMContext, dwarf::DW_TAG_structure_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 404 | getNonCompileUnitScope(Context), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 405 | MDString::get(VMContext, Name), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 406 | File, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 407 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 408 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 409 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 410 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 411 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 412 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 413 | Elements, |
| 414 | ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang), |
| 415 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 416 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 417 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 420 | /// createUnionType - Create debugging information entry for an union. |
| 421 | DIType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 422 | DIFile File, |
| 423 | unsigned LineNumber, uint64_t SizeInBits, |
| 424 | uint64_t AlignInBits, unsigned Flags, |
| 425 | DIArray Elements, unsigned RunTimeLang) { |
| 426 | // TAG_union_type is encoded in DICompositeType format. |
| 427 | Value *Elts[] = { |
| 428 | GetTagConstant(VMContext, dwarf::DW_TAG_union_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 429 | getNonCompileUnitScope(Scope), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 430 | MDString::get(VMContext, Name), |
| 431 | File, |
| 432 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 433 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 434 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 435 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 436 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 437 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 438 | Elements, |
| 439 | ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang), |
| 440 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 441 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 442 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 445 | /// createSubroutineType - Create subroutine type. |
| 446 | DIType DIBuilder::createSubroutineType(DIFile File, DIArray ParameterTypes) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 447 | // TAG_subroutine_type is encoded in DICompositeType format. |
| 448 | Value *Elts[] = { |
| 449 | GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type), |
Devang Patel | 2bd6269 | 2011-08-18 23:50:57 +0000 | [diff] [blame] | 450 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 451 | MDString::get(VMContext, ""), |
Devang Patel | 2bd6269 | 2011-08-18 23:50:57 +0000 | [diff] [blame] | 452 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 453 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 454 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 455 | ConstantInt::get(Type::getInt64Ty(VMContext), 0), |
| 456 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 457 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 458 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 459 | ParameterTypes, |
| 460 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 461 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 462 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 463 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 466 | /// createEnumerationType - Create debugging information entry for an |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 467 | /// enumeration. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 468 | DIType DIBuilder::createEnumerationType(DIDescriptor Scope, StringRef Name, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 469 | DIFile File, unsigned LineNumber, |
| 470 | uint64_t SizeInBits, |
| 471 | uint64_t AlignInBits, DIArray Elements) { |
| 472 | // TAG_enumeration_type is encoded in DICompositeType format. |
| 473 | Value *Elts[] = { |
| 474 | GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 475 | getNonCompileUnitScope(Scope), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 476 | MDString::get(VMContext, Name), |
| 477 | File, |
| 478 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 479 | ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), |
| 480 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 481 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 482 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 483 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 484 | Elements, |
| 485 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 486 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 487 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 488 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 489 | AllEnumTypes.push_back(Node); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 490 | return DIType(Node); |
| 491 | } |
| 492 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 493 | /// createArrayType - Create debugging information entry for an array. |
| 494 | DIType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 495 | DIType Ty, DIArray Subscripts) { |
| 496 | // TAG_array_type is encoded in DICompositeType format. |
| 497 | Value *Elts[] = { |
| 498 | GetTagConstant(VMContext, dwarf::DW_TAG_array_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 499 | NULL, //TheCU, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 500 | MDString::get(VMContext, ""), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 501 | NULL, //TheCU, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 502 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 503 | ConstantInt::get(Type::getInt64Ty(VMContext), Size), |
| 504 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 505 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 506 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 507 | Ty, |
| 508 | Subscripts, |
| 509 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 510 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 511 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 512 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 515 | /// createVectorType - Create debugging information entry for a vector. |
| 516 | DIType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 517 | DIType Ty, DIArray Subscripts) { |
| 518 | // TAG_vector_type is encoded in DICompositeType format. |
| 519 | Value *Elts[] = { |
| 520 | GetTagConstant(VMContext, dwarf::DW_TAG_vector_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 521 | NULL, //TheCU, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 522 | MDString::get(VMContext, ""), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 523 | NULL, //TheCU, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 524 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 525 | ConstantInt::get(Type::getInt64Ty(VMContext), Size), |
| 526 | ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), |
| 527 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 528 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 529 | Ty, |
| 530 | Subscripts, |
| 531 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 532 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 533 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 534 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 535 | } |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 536 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 537 | /// createArtificialType - Create a new DIType with "artificial" flag set. |
| 538 | DIType DIBuilder::createArtificialType(DIType Ty) { |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 539 | if (Ty.isArtificial()) |
| 540 | return Ty; |
| 541 | |
| 542 | SmallVector<Value *, 9> Elts; |
| 543 | MDNode *N = Ty; |
| 544 | assert (N && "Unexpected input DIType!"); |
| 545 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 546 | if (Value *V = N->getOperand(i)) |
| 547 | Elts.push_back(V); |
| 548 | else |
| 549 | Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); |
| 550 | } |
| 551 | |
| 552 | unsigned CurFlags = Ty.getFlags(); |
| 553 | CurFlags = CurFlags | DIType::FlagArtificial; |
| 554 | |
| 555 | // Flags are stored at this slot. |
| 556 | Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags); |
| 557 | |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 558 | return DIType(MDNode::get(VMContext, Elts)); |
Devang Patel | 35fcd65 | 2010-11-04 15:01:38 +0000 | [diff] [blame] | 559 | } |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 560 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 561 | /// retainType - Retain DIType in a module even if it is not referenced |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 562 | /// through debug info anchors. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 563 | void DIBuilder::retainType(DIType T) { |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 564 | AllRetainTypes.push_back(T); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 567 | /// createUnspecifiedParameter - Create unspeicified type descriptor |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 568 | /// for the subroutine type. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 569 | DIDescriptor DIBuilder::createUnspecifiedParameter() { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 570 | Value *Elts[] = { |
| 571 | GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters) |
| 572 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 573 | return DIDescriptor(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 576 | /// createTemporaryType - Create a temporary forward-declared type. |
| 577 | DIType DIBuilder::createTemporaryType() { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 578 | // Give the temporary MDNode a tag. It doesn't matter what tag we |
| 579 | // use here as long as DIType accepts it. |
| 580 | Value *Elts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 581 | MDNode *Node = MDNode::getTemporary(VMContext, Elts); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 582 | return DIType(Node); |
| 583 | } |
| 584 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 585 | /// createTemporaryType - Create a temporary forward-declared type. |
| 586 | DIType DIBuilder::createTemporaryType(DIFile F) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 587 | // Give the temporary MDNode a tag. It doesn't matter what tag we |
| 588 | // use here as long as DIType accepts it. |
| 589 | Value *Elts[] = { |
| 590 | GetTagConstant(VMContext, DW_TAG_base_type), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 591 | TheCU, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 592 | NULL, |
| 593 | F |
| 594 | }; |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 595 | MDNode *Node = MDNode::getTemporary(VMContext, Elts); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 596 | return DIType(Node); |
| 597 | } |
| 598 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 599 | /// getOrCreateArray - Get a DIArray, create one if required. |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 600 | DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) { |
| 601 | if (Elements.empty()) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 602 | Value *Null = llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)); |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 603 | return DIArray(MDNode::get(VMContext, Null)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 604 | } |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 605 | return DIArray(MDNode::get(VMContext, Elements)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 608 | /// getOrCreateSubrange - Create a descriptor for a value range. This |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 609 | /// implicitly uniques the values returned. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 610 | DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Hi) { |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 611 | Value *Elts[] = { |
| 612 | GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type), |
| 613 | ConstantInt::get(Type::getInt64Ty(VMContext), Lo), |
| 614 | ConstantInt::get(Type::getInt64Ty(VMContext), Hi) |
| 615 | }; |
| 616 | |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 617 | return DISubrange(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 620 | /// createGlobalVariable - Create a new descriptor for the specified global. |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 621 | DIGlobalVariable DIBuilder:: |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 622 | createGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 623 | DIType Ty, bool isLocalToUnit, llvm::Value *Val) { |
| 624 | Value *Elts[] = { |
| 625 | GetTagConstant(VMContext, dwarf::DW_TAG_variable), |
| 626 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 627 | NULL, // TheCU, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 628 | MDString::get(VMContext, Name), |
| 629 | MDString::get(VMContext, Name), |
Devang Patel | 94541ef | 2010-12-08 00:06:22 +0000 | [diff] [blame] | 630 | MDString::get(VMContext, Name), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 631 | F, |
| 632 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 633 | Ty, |
| 634 | ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit), |
| 635 | ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/ |
| 636 | Val |
| 637 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 638 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 639 | AllGVs.push_back(Node); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 640 | return DIGlobalVariable(Node); |
| 641 | } |
| 642 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 643 | /// createStaticVariable - Create a new descriptor for the specified static |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 644 | /// variable. |
| 645 | DIGlobalVariable DIBuilder:: |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 646 | createStaticVariable(DIDescriptor Context, StringRef Name, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 647 | StringRef LinkageName, DIFile F, unsigned LineNumber, |
| 648 | DIType Ty, bool isLocalToUnit, llvm::Value *Val) { |
| 649 | Value *Elts[] = { |
| 650 | GetTagConstant(VMContext, dwarf::DW_TAG_variable), |
| 651 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 652 | getNonCompileUnitScope(Context), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 653 | MDString::get(VMContext, Name), |
| 654 | MDString::get(VMContext, Name), |
| 655 | MDString::get(VMContext, LinkageName), |
| 656 | F, |
| 657 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), |
| 658 | Ty, |
| 659 | ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit), |
| 660 | ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/ |
| 661 | Val |
| 662 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 663 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 664 | AllGVs.push_back(Node); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 665 | return DIGlobalVariable(Node); |
| 666 | } |
| 667 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 668 | /// createVariable - Create a new descriptor for the specified variable. |
| 669 | DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 670 | StringRef Name, DIFile File, |
| 671 | unsigned LineNo, DIType Ty, |
Devang Patel | e9e16c5 | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 672 | bool AlwaysPreserve, unsigned Flags, |
| 673 | unsigned ArgNo) { |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 674 | Value *Elts[] = { |
| 675 | GetTagConstant(VMContext, Tag), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 676 | getNonCompileUnitScope(Scope), |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 677 | MDString::get(VMContext, Name), |
| 678 | File, |
Devang Patel | e9e16c5 | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 679 | ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))), |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 680 | Ty, |
Devang Patel | 23336b4 | 2011-07-19 19:41:54 +0000 | [diff] [blame] | 681 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 682 | Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 683 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 684 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 685 | if (AlwaysPreserve) { |
| 686 | // The optimizer may remove local variable. If there is an interest |
| 687 | // to preserve variable info in such situation then stash it in a |
| 688 | // named mdnode. |
| 689 | DISubprogram Fn(getDISubprogram(Scope)); |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 690 | NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn); |
Devang Patel | 48f17ba | 2010-12-07 23:58:00 +0000 | [diff] [blame] | 691 | FnLocals->addOperand(Node); |
| 692 | } |
| 693 | return DIVariable(Node); |
| 694 | } |
| 695 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 696 | /// createComplexVariable - Create a new descriptor for the specified variable |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 697 | /// which has a complex address expression for its address. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 698 | DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 699 | StringRef Name, DIFile F, |
| 700 | unsigned LineNo, |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 701 | DIType Ty, ArrayRef<Value *> Addr, |
| 702 | unsigned ArgNo) { |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 703 | SmallVector<Value *, 15> Elts; |
| 704 | Elts.push_back(GetTagConstant(VMContext, Tag)); |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 705 | Elts.push_back(getNonCompileUnitScope(Scope)), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 706 | Elts.push_back(MDString::get(VMContext, Name)); |
| 707 | Elts.push_back(F); |
Devang Patel | e9e16c5 | 2011-03-01 22:58:13 +0000 | [diff] [blame] | 708 | Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24)))); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 709 | Elts.push_back(Ty); |
Devang Patel | 7b5bd37 | 2011-04-26 18:24:39 +0000 | [diff] [blame] | 710 | Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext))); |
Devang Patel | 23336b4 | 2011-07-19 19:41:54 +0000 | [diff] [blame] | 711 | Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext))); |
Jay Foad | 6855018 | 2011-04-24 10:11:03 +0000 | [diff] [blame] | 712 | Elts.append(Addr.begin(), Addr.end()); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 713 | |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 714 | return DIVariable(MDNode::get(VMContext, Elts)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 717 | /// createFunction - Create a new descriptor for the specified function. |
| 718 | DISubprogram DIBuilder::createFunction(DIDescriptor Context, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 719 | StringRef Name, |
| 720 | StringRef LinkageName, |
| 721 | DIFile File, unsigned LineNo, |
| 722 | DIType Ty, |
| 723 | bool isLocalToUnit, bool isDefinition, |
| 724 | unsigned Flags, bool isOptimized, |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 725 | Function *Fn, |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 726 | MDNode *TParams, |
| 727 | MDNode *Decl) { |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 728 | Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
| 729 | MDNode *Temp = MDNode::getTemporary(VMContext, TElts); |
| 730 | Value *TVElts[] = { Temp }; |
| 731 | MDNode *THolder = MDNode::get(VMContext, TVElts); |
| 732 | |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 733 | Value *Elts[] = { |
| 734 | GetTagConstant(VMContext, dwarf::DW_TAG_subprogram), |
| 735 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 736 | getNonCompileUnitScope(Context), |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 737 | MDString::get(VMContext, Name), |
| 738 | MDString::get(VMContext, Name), |
| 739 | MDString::get(VMContext, LinkageName), |
| 740 | File, |
| 741 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 742 | Ty, |
| 743 | ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit), |
| 744 | ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition), |
| 745 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 746 | ConstantInt::get(Type::getInt32Ty(VMContext), 0), |
| 747 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 748 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 749 | ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 750 | Fn, |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 751 | TParams, |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 752 | Decl, |
| 753 | THolder |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 754 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 755 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 756 | |
| 757 | // Create a named metadata so that we do not lose this mdnode. |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 758 | AllSubprograms.push_back(Node); |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 759 | return DISubprogram(Node); |
| 760 | } |
| 761 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 762 | /// createMethod - Create a new descriptor for the specified C++ method. |
| 763 | DISubprogram DIBuilder::createMethod(DIDescriptor Context, |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 764 | StringRef Name, |
| 765 | StringRef LinkageName, |
| 766 | DIFile F, |
| 767 | unsigned LineNo, DIType Ty, |
| 768 | bool isLocalToUnit, |
| 769 | bool isDefinition, |
| 770 | unsigned VK, unsigned VIndex, |
| 771 | MDNode *VTableHolder, |
| 772 | unsigned Flags, |
| 773 | bool isOptimized, |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 774 | Function *Fn, |
| 775 | MDNode *TParam) { |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 776 | Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; |
| 777 | MDNode *Temp = MDNode::getTemporary(VMContext, TElts); |
| 778 | Value *TVElts[] = { Temp }; |
| 779 | MDNode *THolder = MDNode::get(VMContext, TVElts); |
| 780 | |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 781 | Value *Elts[] = { |
| 782 | GetTagConstant(VMContext, dwarf::DW_TAG_subprogram), |
| 783 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 784 | getNonCompileUnitScope(Context), |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 785 | MDString::get(VMContext, Name), |
| 786 | MDString::get(VMContext, Name), |
| 787 | MDString::get(VMContext, LinkageName), |
| 788 | F, |
| 789 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), |
| 790 | Ty, |
| 791 | ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit), |
| 792 | ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition), |
| 793 | ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK), |
| 794 | ConstantInt::get(Type::getInt32Ty(VMContext), VIndex), |
| 795 | VTableHolder, |
| 796 | ConstantInt::get(Type::getInt32Ty(VMContext), Flags), |
| 797 | ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 798 | Fn, |
| 799 | TParam, |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 800 | llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)), |
| 801 | THolder |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 802 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 803 | MDNode *Node = MDNode::get(VMContext, Elts); |
Devang Patel | 44498a6 | 2010-12-08 20:42:44 +0000 | [diff] [blame] | 804 | return DISubprogram(Node); |
| 805 | } |
| 806 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 807 | /// createNameSpace - This creates new descriptor for a namespace |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 808 | /// with the specified parent scope. |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 809 | DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 810 | DIFile File, unsigned LineNo) { |
| 811 | Value *Elts[] = { |
| 812 | GetTagConstant(VMContext, dwarf::DW_TAG_namespace), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 813 | getNonCompileUnitScope(Scope), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 814 | MDString::get(VMContext, Name), |
| 815 | File, |
| 816 | ConstantInt::get(Type::getInt32Ty(VMContext), LineNo) |
| 817 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 818 | return DINameSpace(MDNode::get(VMContext, Elts)); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 821 | DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 822 | unsigned Line, unsigned Col) { |
| 823 | // Defeat MDNode uniqing for lexical blocks by using unique id. |
| 824 | static unsigned int unique_id = 0; |
| 825 | Value *Elts[] = { |
| 826 | GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block), |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 827 | getNonCompileUnitScope(Scope), |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 828 | ConstantInt::get(Type::getInt32Ty(VMContext), Line), |
| 829 | ConstantInt::get(Type::getInt32Ty(VMContext), Col), |
| 830 | File, |
| 831 | ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++) |
| 832 | }; |
Devang Patel | 1f48a95 | 2011-04-18 23:51:03 +0000 | [diff] [blame] | 833 | return DILexicalBlock(MDNode::get(VMContext, Elts)); |
Devang Patel | 43c249c | 2010-12-08 01:50:15 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 836 | /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 837 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 838 | Instruction *InsertBefore) { |
| 839 | assert(Storage && "no storage passed to dbg.declare"); |
| 840 | assert(VarInfo.Verify() && "empty DIVariable passed to dbg.declare"); |
| 841 | if (!DeclareFn) |
| 842 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 843 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 844 | Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo }; |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 845 | return CallInst::Create(DeclareFn, Args, "", InsertBefore); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 848 | /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 849 | Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 850 | BasicBlock *InsertAtEnd) { |
| 851 | assert(Storage && "no storage passed to dbg.declare"); |
| 852 | assert(VarInfo.Verify() && "invalid DIVariable passed to dbg.declare"); |
| 853 | if (!DeclareFn) |
| 854 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 855 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 856 | Value *Args[] = { MDNode::get(Storage->getContext(), Storage), VarInfo }; |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 857 | |
| 858 | // If this block already has a terminator then insert this intrinsic |
| 859 | // before the terminator. |
| 860 | if (TerminatorInst *T = InsertAtEnd->getTerminator()) |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 861 | return CallInst::Create(DeclareFn, Args, "", T); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 862 | else |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 863 | return CallInst::Create(DeclareFn, Args, "", InsertAtEnd); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 866 | /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. |
| 867 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 868 | DIVariable VarInfo, |
| 869 | Instruction *InsertBefore) { |
| 870 | assert(V && "no value passed to dbg.value"); |
| 871 | assert(VarInfo.Verify() && "invalid DIVariable passed to dbg.value"); |
| 872 | if (!ValueFn) |
| 873 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 874 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 875 | Value *Args[] = { MDNode::get(V->getContext(), V), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 876 | ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset), |
| 877 | VarInfo }; |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 878 | return CallInst::Create(ValueFn, Args, "", InsertBefore); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Devang Patel | 50d280c | 2011-02-22 18:56:12 +0000 | [diff] [blame] | 881 | /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. |
| 882 | Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset, |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 883 | DIVariable VarInfo, |
| 884 | BasicBlock *InsertAtEnd) { |
| 885 | assert(V && "no value passed to dbg.value"); |
| 886 | assert(VarInfo.Verify() && "invalid DIVariable passed to dbg.value"); |
| 887 | if (!ValueFn) |
| 888 | ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); |
| 889 | |
Jay Foad | ec9186b | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 890 | Value *Args[] = { MDNode::get(V->getContext(), V), |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 891 | ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset), |
| 892 | VarInfo }; |
Jay Foad | a3efbb1 | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 893 | return CallInst::Create(ValueFn, Args, "", InsertAtEnd); |
Devang Patel | fe58f95 | 2010-12-07 23:25:47 +0000 | [diff] [blame] | 894 | } |
| 895 | |