Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 1 | //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===// |
| 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 helper classes used to build and interpret debug |
| 11 | // information in LLVM IR form. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Analysis/DebugInfo.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Intrinsics.h" |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 19 | #include "llvm/IntrinsicInst.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 20 | #include "llvm/Instructions.h" |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 21 | #include "llvm/LLVMContext.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 22 | #include "llvm/Module.h" |
| 23 | #include "llvm/Analysis/ValueTracking.h" |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Dwarf.h" |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 25 | #include "llvm/Support/DebugLoc.h" |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Streams.h" |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 27 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 28 | using namespace llvm; |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 29 | using namespace llvm::dwarf; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 30 | |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | // DIDescriptor |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 35 | /// ValidDebugInfo - Return true if V represents valid debug info value. |
| 36 | bool DIDescriptor::ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel) { |
| 37 | if (!V) |
| 38 | return false; |
| 39 | |
| 40 | GlobalVariable *GV = dyn_cast<GlobalVariable>(V->stripPointerCasts()); |
| 41 | if (!GV) |
| 42 | return false; |
| 43 | |
| 44 | if (!GV->hasInternalLinkage () && !GV->hasLinkOnceLinkage()) |
| 45 | return false; |
| 46 | |
| 47 | DIDescriptor DI(GV); |
| 48 | |
| 49 | // Check current version. Allow Version6 for now. |
| 50 | unsigned Version = DI.getVersion(); |
| 51 | if (Version != LLVMDebugVersion && Version != LLVMDebugVersion6) |
| 52 | return false; |
| 53 | |
| 54 | unsigned Tag = DI.getTag(); |
| 55 | switch (Tag) { |
| 56 | case DW_TAG_variable: |
| 57 | assert(DIVariable(GV).Verify() && "Invalid DebugInfo value"); |
| 58 | break; |
| 59 | case DW_TAG_compile_unit: |
| 60 | assert(DICompileUnit(GV).Verify() && "Invalid DebugInfo value"); |
| 61 | break; |
| 62 | case DW_TAG_subprogram: |
| 63 | assert(DISubprogram(GV).Verify() && "Invalid DebugInfo value"); |
| 64 | break; |
| 65 | case DW_TAG_lexical_block: |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 66 | // FIXME: This interfers with the quality of generated code during |
| 67 | // optimization. |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 68 | if (OptLevel != CodeGenOpt::None) |
| 69 | return false; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 70 | // FALLTHROUGH |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 71 | default: |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | return true; |
| 76 | } |
| 77 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 78 | DIDescriptor::DIDescriptor(GlobalVariable *GV, unsigned RequiredTag) { |
| 79 | DbgGV = GV; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 80 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 81 | // If this is non-null, check to see if the Tag matches. If not, set to null. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 82 | if (GV && getTag() != RequiredTag) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 83 | DbgGV = 0; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 86 | const std::string & |
| 87 | DIDescriptor::getStringField(unsigned Elt, std::string &Result) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 88 | if (DbgGV == 0) { |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 89 | Result.clear(); |
| 90 | return Result; |
| 91 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 92 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 93 | Constant *C = DbgGV->getInitializer(); |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 94 | if (C == 0 || Elt >= C->getNumOperands()) { |
| 95 | Result.clear(); |
| 96 | return Result; |
| 97 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 98 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 99 | // Fills in the string if it succeeds |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 100 | if (!GetConstantStringInfo(C->getOperand(Elt), Result)) |
| 101 | Result.clear(); |
| 102 | |
| 103 | return Result; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 107 | if (DbgGV == 0) return 0; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 108 | if (!DbgGV->hasInitializer()) return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 109 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 110 | Constant *C = DbgGV->getInitializer(); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 111 | if (C == 0 || Elt >= C->getNumOperands()) |
| 112 | return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 113 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 114 | if (ConstantInt *CI = dyn_cast<ConstantInt>(C->getOperand(Elt))) |
| 115 | return CI->getZExtValue(); |
| 116 | return 0; |
| 117 | } |
| 118 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 119 | DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 120 | if (DbgGV == 0) return DIDescriptor(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 121 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 122 | Constant *C = DbgGV->getInitializer(); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 123 | if (C == 0 || Elt >= C->getNumOperands()) |
| 124 | return DIDescriptor(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 125 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 126 | C = C->getOperand(Elt); |
| 127 | return DIDescriptor(dyn_cast<GlobalVariable>(C->stripPointerCasts())); |
| 128 | } |
| 129 | |
| 130 | GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 131 | if (DbgGV == 0) return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 132 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 133 | Constant *C = DbgGV->getInitializer(); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 134 | if (C == 0 || Elt >= C->getNumOperands()) |
| 135 | return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 136 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 137 | C = C->getOperand(Elt); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 138 | return dyn_cast<GlobalVariable>(C->stripPointerCasts()); |
| 139 | } |
| 140 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 141 | //===----------------------------------------------------------------------===// |
| 142 | // Simple Descriptor Constructors and other Methods |
| 143 | //===----------------------------------------------------------------------===// |
| 144 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 145 | // Needed by DIVariable::getType(). |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 146 | DIType::DIType(GlobalVariable *GV) : DIDescriptor(GV) { |
| 147 | if (!GV) return; |
Torok Edwin | b07fbd9 | 2008-12-13 08:25:29 +0000 | [diff] [blame] | 148 | unsigned tag = getTag(); |
| 149 | if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) && |
| 150 | !DICompositeType::isCompositeType(tag)) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 151 | DbgGV = 0; |
Torok Edwin | b07fbd9 | 2008-12-13 08:25:29 +0000 | [diff] [blame] | 152 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 153 | |
| 154 | /// isDerivedType - Return true if the specified tag is legal for |
| 155 | /// DIDerivedType. |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 156 | bool DIType::isDerivedType(unsigned Tag) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 157 | switch (Tag) { |
| 158 | case dwarf::DW_TAG_typedef: |
| 159 | case dwarf::DW_TAG_pointer_type: |
| 160 | case dwarf::DW_TAG_reference_type: |
| 161 | case dwarf::DW_TAG_const_type: |
| 162 | case dwarf::DW_TAG_volatile_type: |
| 163 | case dwarf::DW_TAG_restrict_type: |
| 164 | case dwarf::DW_TAG_member: |
| 165 | case dwarf::DW_TAG_inheritance: |
| 166 | return true; |
| 167 | default: |
| 168 | // FIXME: Even though it doesn't make sense, CompositeTypes are current |
| 169 | // modelled as DerivedTypes, this should return true for them as well. |
| 170 | return false; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 174 | /// isCompositeType - Return true if the specified tag is legal for |
| 175 | /// DICompositeType. |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 176 | bool DIType::isCompositeType(unsigned TAG) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 177 | switch (TAG) { |
| 178 | case dwarf::DW_TAG_array_type: |
| 179 | case dwarf::DW_TAG_structure_type: |
| 180 | case dwarf::DW_TAG_union_type: |
| 181 | case dwarf::DW_TAG_enumeration_type: |
| 182 | case dwarf::DW_TAG_vector_type: |
| 183 | case dwarf::DW_TAG_subroutine_type: |
Devang Patel | 25cb0d7 | 2009-03-25 03:52:06 +0000 | [diff] [blame] | 184 | case dwarf::DW_TAG_class_type: |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 185 | return true; |
| 186 | default: |
| 187 | return false; |
| 188 | } |
| 189 | } |
| 190 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 191 | /// isVariable - Return true if the specified tag is legal for DIVariable. |
| 192 | bool DIVariable::isVariable(unsigned Tag) { |
| 193 | switch (Tag) { |
| 194 | case dwarf::DW_TAG_auto_variable: |
| 195 | case dwarf::DW_TAG_arg_variable: |
| 196 | case dwarf::DW_TAG_return_variable: |
| 197 | return true; |
| 198 | default: |
| 199 | return false; |
| 200 | } |
| 201 | } |
| 202 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 203 | unsigned DIArray::getNumElements() const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 204 | assert (DbgGV && "Invalid DIArray"); |
| 205 | Constant *C = DbgGV->getInitializer(); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 206 | assert (C && "Invalid DIArray initializer"); |
| 207 | return C->getNumOperands(); |
| 208 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 209 | |
Devang Patel | c4999d7 | 2009-07-22 18:23:44 +0000 | [diff] [blame] | 210 | /// replaceAllUsesWith - Replace all uses of debug info referenced by |
| 211 | /// this descriptor. After this completes, the current debug info value |
| 212 | /// is erased. |
| 213 | void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) { |
| 214 | if (isNull()) |
| 215 | return; |
| 216 | |
Devang Patel | 6930f4f | 2009-07-22 18:56:16 +0000 | [diff] [blame] | 217 | assert (!D.isNull() && "Can not replace with null"); |
Devang Patel | c4999d7 | 2009-07-22 18:23:44 +0000 | [diff] [blame] | 218 | getGV()->replaceAllUsesWith(D.getGV()); |
| 219 | getGV()->eraseFromParent(); |
| 220 | } |
| 221 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 222 | /// Verify - Verify that a compile unit is well formed. |
| 223 | bool DICompileUnit::Verify() const { |
| 224 | if (isNull()) |
| 225 | return false; |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 226 | std::string Res; |
| 227 | if (getFilename(Res).empty()) |
| 228 | return false; |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 229 | // It is possible that directory and produce string is empty. |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 230 | return true; |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /// Verify - Verify that a type descriptor is well formed. |
| 234 | bool DIType::Verify() const { |
| 235 | if (isNull()) |
| 236 | return false; |
| 237 | if (getContext().isNull()) |
| 238 | return false; |
| 239 | |
| 240 | DICompileUnit CU = getCompileUnit(); |
| 241 | if (!CU.isNull() && !CU.Verify()) |
| 242 | return false; |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | /// Verify - Verify that a composite type descriptor is well formed. |
| 247 | bool DICompositeType::Verify() const { |
| 248 | if (isNull()) |
| 249 | return false; |
| 250 | if (getContext().isNull()) |
| 251 | return false; |
| 252 | |
| 253 | DICompileUnit CU = getCompileUnit(); |
| 254 | if (!CU.isNull() && !CU.Verify()) |
| 255 | return false; |
| 256 | return true; |
| 257 | } |
| 258 | |
| 259 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 260 | bool DISubprogram::Verify() const { |
| 261 | if (isNull()) |
| 262 | return false; |
| 263 | |
| 264 | if (getContext().isNull()) |
| 265 | return false; |
| 266 | |
| 267 | DICompileUnit CU = getCompileUnit(); |
| 268 | if (!CU.Verify()) |
| 269 | return false; |
| 270 | |
| 271 | DICompositeType Ty = getType(); |
| 272 | if (!Ty.isNull() && !Ty.Verify()) |
| 273 | return false; |
| 274 | return true; |
| 275 | } |
| 276 | |
| 277 | /// Verify - Verify that a global variable descriptor is well formed. |
| 278 | bool DIGlobalVariable::Verify() const { |
| 279 | if (isNull()) |
| 280 | return false; |
| 281 | |
| 282 | if (getContext().isNull()) |
| 283 | return false; |
| 284 | |
| 285 | DICompileUnit CU = getCompileUnit(); |
Chris Lattner | e3f6cea | 2009-05-05 04:55:56 +0000 | [diff] [blame] | 286 | if (!CU.isNull() && !CU.Verify()) |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 287 | return false; |
| 288 | |
| 289 | DIType Ty = getType(); |
| 290 | if (!Ty.Verify()) |
| 291 | return false; |
| 292 | |
| 293 | if (!getGlobal()) |
| 294 | return false; |
| 295 | |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | /// Verify - Verify that a variable descriptor is well formed. |
| 300 | bool DIVariable::Verify() const { |
| 301 | if (isNull()) |
| 302 | return false; |
| 303 | |
| 304 | if (getContext().isNull()) |
| 305 | return false; |
| 306 | |
| 307 | DIType Ty = getType(); |
| 308 | if (!Ty.Verify()) |
| 309 | return false; |
| 310 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 311 | return true; |
| 312 | } |
| 313 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 314 | /// getOriginalTypeSize - If this type is derived from a base type then |
| 315 | /// return base type size. |
| 316 | uint64_t DIDerivedType::getOriginalTypeSize() const { |
| 317 | if (getTag() != dwarf::DW_TAG_member) |
| 318 | return getSizeInBits(); |
| 319 | DIType BT = getTypeDerivedFrom(); |
| 320 | if (BT.getTag() != dwarf::DW_TAG_base_type) |
| 321 | return getSizeInBits(); |
| 322 | return BT.getSizeInBits(); |
| 323 | } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 324 | |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 325 | /// describes - Return true if this subprogram provides debugging |
| 326 | /// information for the function F. |
| 327 | bool DISubprogram::describes(const Function *F) { |
| 328 | assert (F && "Invalid function"); |
| 329 | std::string Name; |
| 330 | getLinkageName(Name); |
| 331 | if (Name.empty()) |
| 332 | getName(Name); |
Daniel Dunbar | 460f656 | 2009-07-26 09:48:23 +0000 | [diff] [blame] | 333 | if (F->getName() == Name) |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 334 | return true; |
| 335 | return false; |
| 336 | } |
| 337 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 338 | //===----------------------------------------------------------------------===// |
Devang Patel | 7136a65 | 2009-07-01 22:10:23 +0000 | [diff] [blame] | 339 | // DIDescriptor: dump routines for all descriptors. |
| 340 | //===----------------------------------------------------------------------===// |
| 341 | |
| 342 | |
| 343 | /// dump - Print descriptor. |
| 344 | void DIDescriptor::dump() const { |
| 345 | cerr << "[" << dwarf::TagString(getTag()) << "] "; |
| 346 | cerr << std::hex << "[GV:" << DbgGV << "]" << std::dec; |
| 347 | } |
| 348 | |
| 349 | /// dump - Print compile unit. |
| 350 | void DICompileUnit::dump() const { |
| 351 | if (getLanguage()) |
| 352 | cerr << " [" << dwarf::LanguageString(getLanguage()) << "] "; |
| 353 | |
| 354 | std::string Res1, Res2; |
| 355 | cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]"; |
| 356 | } |
| 357 | |
| 358 | /// dump - Print type. |
| 359 | void DIType::dump() const { |
| 360 | if (isNull()) return; |
| 361 | |
| 362 | std::string Res; |
| 363 | if (!getName(Res).empty()) |
| 364 | cerr << " [" << Res << "] "; |
| 365 | |
| 366 | unsigned Tag = getTag(); |
| 367 | cerr << " [" << dwarf::TagString(Tag) << "] "; |
| 368 | |
| 369 | // TODO : Print context |
| 370 | getCompileUnit().dump(); |
| 371 | cerr << " [" |
| 372 | << getLineNumber() << ", " |
| 373 | << getSizeInBits() << ", " |
| 374 | << getAlignInBits() << ", " |
| 375 | << getOffsetInBits() |
| 376 | << "] "; |
| 377 | |
| 378 | if (isPrivate()) |
| 379 | cerr << " [private] "; |
| 380 | else if (isProtected()) |
| 381 | cerr << " [protected] "; |
| 382 | |
| 383 | if (isForwardDecl()) |
| 384 | cerr << " [fwd] "; |
| 385 | |
| 386 | if (isBasicType(Tag)) |
| 387 | DIBasicType(DbgGV).dump(); |
| 388 | else if (isDerivedType(Tag)) |
| 389 | DIDerivedType(DbgGV).dump(); |
| 390 | else if (isCompositeType(Tag)) |
| 391 | DICompositeType(DbgGV).dump(); |
| 392 | else { |
| 393 | cerr << "Invalid DIType\n"; |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | cerr << "\n"; |
| 398 | } |
| 399 | |
| 400 | /// dump - Print basic type. |
| 401 | void DIBasicType::dump() const { |
| 402 | cerr << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] "; |
| 403 | } |
| 404 | |
| 405 | /// dump - Print derived type. |
| 406 | void DIDerivedType::dump() const { |
| 407 | cerr << "\n\t Derived From: "; getTypeDerivedFrom().dump(); |
| 408 | } |
| 409 | |
| 410 | /// dump - Print composite type. |
| 411 | void DICompositeType::dump() const { |
| 412 | DIArray A = getTypeArray(); |
| 413 | if (A.isNull()) |
| 414 | return; |
| 415 | cerr << " [" << A.getNumElements() << " elements]"; |
| 416 | } |
| 417 | |
| 418 | /// dump - Print global. |
| 419 | void DIGlobal::dump() const { |
| 420 | std::string Res; |
| 421 | if (!getName(Res).empty()) |
| 422 | cerr << " [" << Res << "] "; |
| 423 | |
| 424 | unsigned Tag = getTag(); |
| 425 | cerr << " [" << dwarf::TagString(Tag) << "] "; |
| 426 | |
| 427 | // TODO : Print context |
| 428 | getCompileUnit().dump(); |
| 429 | cerr << " [" << getLineNumber() << "] "; |
| 430 | |
| 431 | if (isLocalToUnit()) |
| 432 | cerr << " [local] "; |
| 433 | |
| 434 | if (isDefinition()) |
| 435 | cerr << " [def] "; |
| 436 | |
| 437 | if (isGlobalVariable(Tag)) |
| 438 | DIGlobalVariable(DbgGV).dump(); |
| 439 | |
| 440 | cerr << "\n"; |
| 441 | } |
| 442 | |
| 443 | /// dump - Print subprogram. |
| 444 | void DISubprogram::dump() const { |
| 445 | DIGlobal::dump(); |
| 446 | } |
| 447 | |
| 448 | /// dump - Print global variable. |
| 449 | void DIGlobalVariable::dump() const { |
| 450 | cerr << " ["; getGlobal()->dump(); cerr << "] "; |
| 451 | } |
| 452 | |
| 453 | /// dump - Print variable. |
| 454 | void DIVariable::dump() const { |
| 455 | std::string Res; |
| 456 | if (!getName(Res).empty()) |
| 457 | cerr << " [" << Res << "] "; |
| 458 | |
| 459 | getCompileUnit().dump(); |
| 460 | cerr << " [" << getLineNumber() << "] "; |
| 461 | getType().dump(); |
| 462 | cerr << "\n"; |
| 463 | } |
| 464 | |
| 465 | //===----------------------------------------------------------------------===// |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 466 | // DIFactory: Basic Helpers |
| 467 | //===----------------------------------------------------------------------===// |
| 468 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 469 | DIFactory::DIFactory(Module &m) |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 470 | : M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0), |
| 471 | RegionStartFn(0), RegionEndFn(0), |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 472 | DeclareFn(0) { |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 473 | EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext)); |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. |
| 477 | /// This is only valid when the descriptor is non-null. |
| 478 | Constant *DIFactory::getCastToEmpty(DIDescriptor D) { |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 479 | if (D.isNull()) return llvm::Constant::getNullValue(EmptyStructPtr); |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 480 | return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 483 | Constant *DIFactory::GetTagConstant(unsigned TAG) { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 484 | assert((TAG & LLVMDebugVersionMask) == 0 && |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 485 | "Tag too large for debug encoding!"); |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 486 | return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | Constant *DIFactory::GetStringConstant(const std::string &String) { |
| 490 | // Check string cache for previous edition. |
| 491 | Constant *&Slot = StringCache[String]; |
| 492 | |
| 493 | // Return Constant if previously defined. |
| 494 | if (Slot) return Slot; |
| 495 | |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 496 | const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 497 | |
Dan Gohman | a119de8 | 2009-06-14 23:30:43 +0000 | [diff] [blame] | 498 | // If empty string then use a i8* null instead. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 499 | if (String.empty()) |
Owen Anderson | 9e9a0d5 | 2009-07-30 23:03:37 +0000 | [diff] [blame] | 500 | return Slot = ConstantPointerNull::get(DestTy); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 501 | |
| 502 | // Construct string as an llvm constant. |
Owen Anderson | 1fd7096 | 2009-07-28 18:32:17 +0000 | [diff] [blame] | 503 | Constant *ConstStr = ConstantArray::get(String); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 504 | |
| 505 | // Otherwise create and return a new string global. |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 506 | GlobalVariable *StrGV = new GlobalVariable(M, ConstStr->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 507 | GlobalVariable::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 508 | ConstStr, ".str"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 509 | StrGV->setSection("llvm.metadata"); |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 510 | return Slot = ConstantExpr::getBitCast(StrGV, DestTy); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 513 | //===----------------------------------------------------------------------===// |
| 514 | // DIFactory: Primary Constructors |
| 515 | //===----------------------------------------------------------------------===// |
| 516 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 517 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
| 518 | /// This implicitly uniques the arrays created. |
| 519 | DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { |
| 520 | SmallVector<Constant*, 16> Elts; |
| 521 | |
| 522 | for (unsigned i = 0; i != NumTys; ++i) |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 523 | Elts.push_back(getCastToEmpty(Tys[i])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 524 | |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 525 | Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 526 | Elts.size()), |
Jay Foad | e3e51c0 | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 527 | Elts.data(), Elts.size()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 528 | // If we already have this array, just return the uniqued version. |
| 529 | DIDescriptor &Entry = SimpleConstantCache[Init]; |
| 530 | if (!Entry.isNull()) return DIArray(Entry.getGV()); |
Devang Patel | bceda93 | 2009-08-06 20:57:44 +0000 | [diff] [blame] | 531 | |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 532 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 533 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 534 | Init, "llvm.dbg.array"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 535 | GV->setSection("llvm.metadata"); |
| 536 | Entry = DIDescriptor(GV); |
| 537 | return DIArray(GV); |
| 538 | } |
| 539 | |
| 540 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 541 | /// implicitly uniques the values returned. |
| 542 | DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { |
| 543 | Constant *Elts[] = { |
| 544 | GetTagConstant(dwarf::DW_TAG_subrange_type), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 545 | ConstantInt::get(Type::Int64Ty, Lo), |
| 546 | ConstantInt::get(Type::Int64Ty, Hi) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 547 | }; |
| 548 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 549 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 550 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 551 | |
| 552 | // If we already have this range, just return the uniqued version. |
| 553 | DIDescriptor &Entry = SimpleConstantCache[Init]; |
| 554 | if (!Entry.isNull()) return DISubrange(Entry.getGV()); |
| 555 | |
| 556 | M.addTypeName("llvm.dbg.subrange.type", Init->getType()); |
| 557 | |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 558 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 559 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 560 | Init, "llvm.dbg.subrange"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 561 | GV->setSection("llvm.metadata"); |
| 562 | Entry = DIDescriptor(GV); |
| 563 | return DISubrange(GV); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | |
| 568 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 569 | /// unit. Note that this does not unique compile units within the module. |
| 570 | DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, |
| 571 | const std::string &Filename, |
| 572 | const std::string &Directory, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 573 | const std::string &Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 574 | bool isMain, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 575 | bool isOptimized, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 576 | const char *Flags, |
| 577 | unsigned RunTimeVer) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 578 | Constant *Elts[] = { |
| 579 | GetTagConstant(dwarf::DW_TAG_compile_unit), |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 580 | llvm::Constant::getNullValue(EmptyStructPtr), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 581 | ConstantInt::get(Type::Int32Ty, LangID), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 582 | GetStringConstant(Filename), |
| 583 | GetStringConstant(Directory), |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 584 | GetStringConstant(Producer), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 585 | ConstantInt::get(Type::Int1Ty, isMain), |
| 586 | ConstantInt::get(Type::Int1Ty, isOptimized), |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 587 | GetStringConstant(Flags), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 588 | ConstantInt::get(Type::Int32Ty, RunTimeVer) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 589 | }; |
| 590 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 591 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 592 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 593 | |
| 594 | M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 595 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 596 | GlobalValue::LinkOnceAnyLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 597 | Init, "llvm.dbg.compile_unit"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 598 | GV->setSection("llvm.metadata"); |
| 599 | return DICompileUnit(GV); |
| 600 | } |
| 601 | |
| 602 | /// CreateEnumerator - Create a single enumerator value. |
| 603 | DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){ |
| 604 | Constant *Elts[] = { |
| 605 | GetTagConstant(dwarf::DW_TAG_enumerator), |
| 606 | GetStringConstant(Name), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 607 | ConstantInt::get(Type::Int64Ty, Val) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 608 | }; |
| 609 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 610 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 611 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 612 | |
| 613 | M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 614 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 615 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 616 | Init, "llvm.dbg.enumerator"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 617 | GV->setSection("llvm.metadata"); |
| 618 | return DIEnumerator(GV); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | /// CreateBasicType - Create a basic type like int, float, etc. |
| 623 | DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 624 | const std::string &Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 625 | DICompileUnit CompileUnit, |
| 626 | unsigned LineNumber, |
| 627 | uint64_t SizeInBits, |
| 628 | uint64_t AlignInBits, |
| 629 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 630 | unsigned Encoding) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 631 | Constant *Elts[] = { |
| 632 | GetTagConstant(dwarf::DW_TAG_base_type), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 633 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 634 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 635 | getCastToEmpty(CompileUnit), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 636 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 637 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 638 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 639 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 640 | ConstantInt::get(Type::Int32Ty, Flags), |
| 641 | ConstantInt::get(Type::Int32Ty, Encoding) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 642 | }; |
| 643 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 644 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 645 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 646 | |
| 647 | M.addTypeName("llvm.dbg.basictype.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 648 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 649 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 650 | Init, "llvm.dbg.basictype"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 651 | GV->setSection("llvm.metadata"); |
| 652 | return DIBasicType(GV); |
| 653 | } |
| 654 | |
| 655 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 656 | /// pointer, typedef, etc. |
| 657 | DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, |
| 658 | DIDescriptor Context, |
| 659 | const std::string &Name, |
| 660 | DICompileUnit CompileUnit, |
| 661 | unsigned LineNumber, |
| 662 | uint64_t SizeInBits, |
| 663 | uint64_t AlignInBits, |
| 664 | uint64_t OffsetInBits, |
| 665 | unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 666 | DIType DerivedFrom) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 667 | Constant *Elts[] = { |
| 668 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 669 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 670 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 671 | getCastToEmpty(CompileUnit), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 672 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 673 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 674 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 675 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 676 | ConstantInt::get(Type::Int32Ty, Flags), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 677 | getCastToEmpty(DerivedFrom) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 678 | }; |
| 679 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 680 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 681 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 682 | |
| 683 | M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 684 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 685 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 686 | Init, "llvm.dbg.derivedtype"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 687 | GV->setSection("llvm.metadata"); |
| 688 | return DIDerivedType(GV); |
| 689 | } |
| 690 | |
| 691 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 692 | DICompositeType DIFactory::CreateCompositeType(unsigned Tag, |
| 693 | DIDescriptor Context, |
| 694 | const std::string &Name, |
| 695 | DICompileUnit CompileUnit, |
| 696 | unsigned LineNumber, |
| 697 | uint64_t SizeInBits, |
| 698 | uint64_t AlignInBits, |
| 699 | uint64_t OffsetInBits, |
| 700 | unsigned Flags, |
| 701 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 702 | DIArray Elements, |
| 703 | unsigned RuntimeLang) { |
Owen Anderson | e277fed | 2009-07-07 16:31:25 +0000 | [diff] [blame] | 704 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 705 | Constant *Elts[] = { |
| 706 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 707 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 708 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 709 | getCastToEmpty(CompileUnit), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 710 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 711 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 712 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 713 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 714 | ConstantInt::get(Type::Int32Ty, Flags), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 715 | getCastToEmpty(DerivedFrom), |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 716 | getCastToEmpty(Elements), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 717 | ConstantInt::get(Type::Int32Ty, RuntimeLang) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 718 | }; |
| 719 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 720 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 721 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 722 | |
| 723 | M.addTypeName("llvm.dbg.composite.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 724 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 725 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 726 | Init, "llvm.dbg.composite"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 727 | GV->setSection("llvm.metadata"); |
| 728 | return DICompositeType(GV); |
| 729 | } |
| 730 | |
| 731 | |
| 732 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 733 | /// See comments in DISubprogram for descriptions of these fields. This |
| 734 | /// method does not unique the generated descriptors. |
| 735 | DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, |
| 736 | const std::string &Name, |
| 737 | const std::string &DisplayName, |
| 738 | const std::string &LinkageName, |
| 739 | DICompileUnit CompileUnit, |
| 740 | unsigned LineNo, DIType Type, |
| 741 | bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 742 | bool isDefinition) { |
Devang Patel | 854967e | 2008-12-17 22:39:29 +0000 | [diff] [blame] | 743 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 744 | Constant *Elts[] = { |
| 745 | GetTagConstant(dwarf::DW_TAG_subprogram), |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 746 | llvm::Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 747 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 748 | GetStringConstant(Name), |
| 749 | GetStringConstant(DisplayName), |
| 750 | GetStringConstant(LinkageName), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 751 | getCastToEmpty(CompileUnit), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 752 | ConstantInt::get(Type::Int32Ty, LineNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 753 | getCastToEmpty(Type), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 754 | ConstantInt::get(Type::Int1Ty, isLocalToUnit), |
| 755 | ConstantInt::get(Type::Int1Ty, isDefinition) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 756 | }; |
| 757 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 758 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 759 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 760 | |
| 761 | M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 762 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 763 | GlobalValue::LinkOnceAnyLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 764 | Init, "llvm.dbg.subprogram"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 765 | GV->setSection("llvm.metadata"); |
| 766 | return DISubprogram(GV); |
| 767 | } |
| 768 | |
| 769 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 770 | DIGlobalVariable |
| 771 | DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, |
| 772 | const std::string &DisplayName, |
| 773 | const std::string &LinkageName, |
| 774 | DICompileUnit CompileUnit, |
| 775 | unsigned LineNo, DIType Type,bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 776 | bool isDefinition, llvm::GlobalVariable *Val) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 777 | Constant *Elts[] = { |
| 778 | GetTagConstant(dwarf::DW_TAG_variable), |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 779 | llvm::Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 780 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 781 | GetStringConstant(Name), |
| 782 | GetStringConstant(DisplayName), |
| 783 | GetStringConstant(LinkageName), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 784 | getCastToEmpty(CompileUnit), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 785 | ConstantInt::get(Type::Int32Ty, LineNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 786 | getCastToEmpty(Type), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 787 | ConstantInt::get(Type::Int1Ty, isLocalToUnit), |
| 788 | ConstantInt::get(Type::Int1Ty, isDefinition), |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 789 | ConstantExpr::getBitCast(Val, EmptyStructPtr) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 790 | }; |
| 791 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 792 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 793 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 794 | |
| 795 | M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 796 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 797 | GlobalValue::LinkOnceAnyLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 798 | Init, "llvm.dbg.global_variable"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 799 | GV->setSection("llvm.metadata"); |
| 800 | return DIGlobalVariable(GV); |
| 801 | } |
| 802 | |
| 803 | |
| 804 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 805 | DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context, |
| 806 | const std::string &Name, |
| 807 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 808 | DIType Type) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 809 | Constant *Elts[] = { |
| 810 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 811 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 812 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 813 | getCastToEmpty(CompileUnit), |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 814 | ConstantInt::get(Type::Int32Ty, LineNo), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 815 | getCastToEmpty(Type) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 816 | }; |
| 817 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 818 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 819 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 820 | |
| 821 | M.addTypeName("llvm.dbg.variable.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 822 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 823 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 824 | Init, "llvm.dbg.variable"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 825 | GV->setSection("llvm.metadata"); |
| 826 | return DIVariable(GV); |
| 827 | } |
| 828 | |
| 829 | |
| 830 | /// CreateBlock - This creates a descriptor for a lexical block with the |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 831 | /// specified parent VMContext. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 832 | DIBlock DIFactory::CreateBlock(DIDescriptor Context) { |
| 833 | Constant *Elts[] = { |
| 834 | GetTagConstant(dwarf::DW_TAG_lexical_block), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 835 | getCastToEmpty(Context) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 836 | }; |
| 837 | |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 838 | Constant *Init = ConstantStruct::get(VMContext, Elts, |
| 839 | sizeof(Elts)/sizeof(Elts[0])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 840 | |
| 841 | M.addTypeName("llvm.dbg.block.type", Init->getType()); |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 842 | GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 843 | GlobalValue::InternalLinkage, |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 844 | Init, "llvm.dbg.block"); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 845 | GV->setSection("llvm.metadata"); |
| 846 | return DIBlock(GV); |
| 847 | } |
| 848 | |
| 849 | |
| 850 | //===----------------------------------------------------------------------===// |
| 851 | // DIFactory: Routines for inserting code into a function |
| 852 | //===----------------------------------------------------------------------===// |
| 853 | |
| 854 | /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, |
| 855 | /// inserting it at the end of the specified basic block. |
| 856 | void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo, |
| 857 | unsigned ColNo, BasicBlock *BB) { |
| 858 | |
| 859 | // Lazily construct llvm.dbg.stoppoint function. |
| 860 | if (!StopPointFn) |
| 861 | StopPointFn = llvm::Intrinsic::getDeclaration(&M, |
| 862 | llvm::Intrinsic::dbg_stoppoint); |
| 863 | |
| 864 | // Invoke llvm.dbg.stoppoint |
| 865 | Value *Args[] = { |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 866 | ConstantInt::get(llvm::Type::Int32Ty, LineNo), |
| 867 | ConstantInt::get(llvm::Type::Int32Ty, ColNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 868 | getCastToEmpty(CU) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 869 | }; |
| 870 | CallInst::Create(StopPointFn, Args, Args+3, "", BB); |
| 871 | } |
| 872 | |
| 873 | /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to |
| 874 | /// mark the start of the specified subprogram. |
| 875 | void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) { |
| 876 | // Lazily construct llvm.dbg.func.start. |
| 877 | if (!FuncStartFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 878 | FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 879 | |
| 880 | // Call llvm.dbg.func.start which also implicitly sets a stoppoint. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 881 | CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to |
| 885 | /// mark the start of a region for the specified scoping descriptor. |
| 886 | void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) { |
| 887 | // Lazily construct llvm.dbg.region.start function. |
| 888 | if (!RegionStartFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 889 | RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start); |
| 890 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 891 | // Call llvm.dbg.func.start. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 892 | CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 895 | /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to |
| 896 | /// mark the end of a region for the specified scoping descriptor. |
| 897 | void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) { |
| 898 | // Lazily construct llvm.dbg.region.end function. |
| 899 | if (!RegionEndFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 900 | RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end); |
| 901 | |
| 902 | // Call llvm.dbg.region.end. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 903 | CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 907 | void DIFactory::InsertDeclare(Value *Storage, DIVariable D, BasicBlock *BB) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 908 | // Cast the storage to a {}* for the call to llvm.dbg.declare. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 909 | Storage = new BitCastInst(Storage, EmptyStructPtr, "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 910 | |
| 911 | if (!DeclareFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 912 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 913 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 914 | Value *Args[] = { Storage, getCastToEmpty(D) }; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 915 | CallInst::Create(DeclareFn, Args, Args+2, "", BB); |
| 916 | } |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 917 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 918 | //===----------------------------------------------------------------------===// |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 919 | // DebugInfoFinder implementations. |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 920 | //===----------------------------------------------------------------------===// |
| 921 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 922 | /// processModule - Process entire module and collect debug info. |
| 923 | void DebugInfoFinder::processModule(Module &M) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 924 | |
| 925 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
| 926 | for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI) |
| 927 | for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE; |
| 928 | ++BI) { |
| 929 | if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(BI)) |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 930 | processStopPoint(SPI); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 931 | else if (DbgFuncStartInst *FSI = dyn_cast<DbgFuncStartInst>(BI)) |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 932 | processFuncStart(FSI); |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 933 | else if (DbgRegionStartInst *DRS = dyn_cast<DbgRegionStartInst>(BI)) |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 934 | processRegionStart(DRS); |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 935 | else if (DbgRegionEndInst *DRE = dyn_cast<DbgRegionEndInst>(BI)) |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 936 | processRegionEnd(DRE); |
Devang Patel | b4d3130 | 2009-07-31 18:18:52 +0000 | [diff] [blame] | 937 | else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI)) |
| 938 | processDeclare(DDI); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | for (Module::global_iterator GVI = M.global_begin(), GVE = M.global_end(); |
| 942 | GVI != GVE; ++GVI) { |
| 943 | GlobalVariable *GV = GVI; |
| 944 | if (!GV->hasName() || !GV->isConstant() |
| 945 | || strcmp(GV->getName().data(), "llvm.dbg.global_variable") |
| 946 | || !GV->hasInitializer()) |
| 947 | continue; |
| 948 | DIGlobalVariable DIG(GV); |
| 949 | if (addGlobalVariable(DIG)) { |
| 950 | addCompileUnit(DIG.getCompileUnit()); |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 951 | processType(DIG.getType()); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | } |
| 955 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 956 | /// processType - Process DIType. |
| 957 | void DebugInfoFinder::processType(DIType DT) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 958 | if (DT.isNull()) |
| 959 | return; |
| 960 | if (!NodesSeen.insert(DT.getGV())) |
| 961 | return; |
| 962 | |
| 963 | addCompileUnit(DT.getCompileUnit()); |
| 964 | if (DT.isCompositeType(DT.getTag())) { |
| 965 | DICompositeType DCT(DT.getGV()); |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 966 | processType(DCT.getTypeDerivedFrom()); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 967 | DIArray DA = DCT.getTypeArray(); |
| 968 | if (!DA.isNull()) |
| 969 | for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) { |
| 970 | DIDescriptor D = DA.getElement(i); |
| 971 | DIType TypeE = DIType(D.getGV()); |
| 972 | if (!TypeE.isNull()) |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 973 | processType(TypeE); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 974 | else |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 975 | processSubprogram(DISubprogram(D.getGV())); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 976 | } |
| 977 | } else if (DT.isDerivedType(DT.getTag())) { |
| 978 | DIDerivedType DDT(DT.getGV()); |
| 979 | if (!DDT.isNull()) |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 980 | processType(DDT.getTypeDerivedFrom()); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 984 | /// processSubprogram - Process DISubprogram. |
| 985 | void DebugInfoFinder::processSubprogram(DISubprogram SP) { |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 986 | if (SP.isNull()) |
| 987 | return; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 988 | if (!addSubprogram(SP)) |
| 989 | return; |
| 990 | addCompileUnit(SP.getCompileUnit()); |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 991 | processType(SP.getType()); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 992 | } |
| 993 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 994 | /// processStopPoint - Process DbgStopPointInst. |
| 995 | void DebugInfoFinder::processStopPoint(DbgStopPointInst *SPI) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 996 | GlobalVariable *Context = dyn_cast<GlobalVariable>(SPI->getContext()); |
| 997 | addCompileUnit(DICompileUnit(Context)); |
| 998 | } |
| 999 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1000 | /// processFuncStart - Process DbgFuncStartInst. |
| 1001 | void DebugInfoFinder::processFuncStart(DbgFuncStartInst *FSI) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 1002 | GlobalVariable *SP = dyn_cast<GlobalVariable>(FSI->getSubprogram()); |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1003 | processSubprogram(DISubprogram(SP)); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1006 | /// processRegionStart - Process DbgRegionStart. |
| 1007 | void DebugInfoFinder::processRegionStart(DbgRegionStartInst *DRS) { |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 1008 | GlobalVariable *SP = dyn_cast<GlobalVariable>(DRS->getContext()); |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1009 | processSubprogram(DISubprogram(SP)); |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1012 | /// processRegionEnd - Process DbgRegionEnd. |
| 1013 | void DebugInfoFinder::processRegionEnd(DbgRegionEndInst *DRE) { |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 1014 | GlobalVariable *SP = dyn_cast<GlobalVariable>(DRE->getContext()); |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1015 | processSubprogram(DISubprogram(SP)); |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Devang Patel | b4d3130 | 2009-07-31 18:18:52 +0000 | [diff] [blame] | 1018 | /// processDeclare - Process DbgDeclareInst. |
| 1019 | void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) { |
| 1020 | DIVariable DV(cast<GlobalVariable>(DDI->getVariable())); |
| 1021 | if (DV.isNull()) |
| 1022 | return; |
| 1023 | |
| 1024 | if (!NodesSeen.insert(DV.getGV())) |
| 1025 | return; |
| 1026 | |
| 1027 | addCompileUnit(DV.getCompileUnit()); |
| 1028 | processType(DV.getType()); |
| 1029 | } |
| 1030 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 1031 | /// addCompileUnit - Add compile unit into CUs. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1032 | bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 1033 | if (CU.isNull()) |
| 1034 | return false; |
| 1035 | |
| 1036 | if (!NodesSeen.insert(CU.getGV())) |
| 1037 | return false; |
| 1038 | |
| 1039 | CUs.push_back(CU.getGV()); |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
| 1043 | /// addGlobalVariable - Add global variable into GVs. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1044 | bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 1045 | if (DIG.isNull()) |
| 1046 | return false; |
| 1047 | |
| 1048 | if (!NodesSeen.insert(DIG.getGV())) |
| 1049 | return false; |
| 1050 | |
| 1051 | GVs.push_back(DIG.getGV()); |
| 1052 | return true; |
| 1053 | } |
| 1054 | |
| 1055 | // addSubprogram - Add subprgoram into SPs. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 1056 | bool DebugInfoFinder::addSubprogram(DISubprogram SP) { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 1057 | if (SP.isNull()) |
| 1058 | return false; |
| 1059 | |
| 1060 | if (!NodesSeen.insert(SP.getGV())) |
| 1061 | return false; |
| 1062 | |
| 1063 | SPs.push_back(SP.getGV()); |
| 1064 | return true; |
| 1065 | } |
| 1066 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1067 | namespace llvm { |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1068 | /// findStopPoint - Find the stoppoint coressponding to this instruction, that |
| 1069 | /// is the stoppoint that dominates this instruction. |
| 1070 | const DbgStopPointInst *findStopPoint(const Instruction *Inst) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1071 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(Inst)) |
| 1072 | return DSI; |
| 1073 | |
| 1074 | const BasicBlock *BB = Inst->getParent(); |
| 1075 | BasicBlock::const_iterator I = Inst, B; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1076 | while (BB) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1077 | B = BB->begin(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1078 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1079 | // A BB consisting only of a terminator can't have a stoppoint. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1080 | while (I != B) { |
| 1081 | --I; |
| 1082 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I)) |
| 1083 | return DSI; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1084 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1085 | |
| 1086 | // This BB didn't have a stoppoint: if there is only one predecessor, look |
| 1087 | // for a stoppoint there. We could use getIDom(), but that would require |
| 1088 | // dominator info. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1089 | BB = I->getParent()->getUniquePredecessor(); |
| 1090 | if (BB) |
| 1091 | I = BB->getTerminator(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1094 | return 0; |
| 1095 | } |
| 1096 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1097 | /// findBBStopPoint - Find the stoppoint corresponding to first real |
| 1098 | /// (non-debug intrinsic) instruction in this Basic Block, and return the |
| 1099 | /// stoppoint for it. |
| 1100 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB) { |
| 1101 | for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1102 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I)) |
| 1103 | return DSI; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1104 | |
| 1105 | // Fallback to looking for stoppoint of unique predecessor. Useful if this |
| 1106 | // BB contains no stoppoints, but unique predecessor does. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1107 | BB = BB->getUniquePredecessor(); |
| 1108 | if (BB) |
| 1109 | return findStopPoint(BB->getTerminator()); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1110 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1111 | return 0; |
| 1112 | } |
| 1113 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1114 | Value *findDbgGlobalDeclare(GlobalVariable *V) { |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1115 | const Module *M = V->getParent(); |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 1116 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1117 | const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1118 | if (!Ty) return 0; |
| 1119 | |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 1120 | Ty = PointerType::get(Ty, 0); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1121 | |
| 1122 | Value *Val = V->stripPointerCasts(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1123 | for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1124 | I != E; ++I) { |
| 1125 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I)) { |
| 1126 | if (CE->getOpcode() == Instruction::BitCast) { |
| 1127 | Value *VV = CE; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1128 | |
| 1129 | while (VV->hasOneUse()) |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1130 | VV = *VV->use_begin(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1131 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1132 | if (VV->getType() == Ty) |
| 1133 | return VV; |
| 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | if (Val->getType() == Ty) |
| 1139 | return Val; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1140 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1141 | return 0; |
| 1142 | } |
| 1143 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1144 | /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1145 | /// It looks through pointer casts too. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1146 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1147 | if (stripCasts) { |
| 1148 | V = V->stripPointerCasts(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1149 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1150 | // Look for the bitcast. |
| 1151 | for (Value::use_const_iterator I = V->use_begin(), E =V->use_end(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1152 | I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1153 | if (isa<BitCastInst>(I)) |
| 1154 | return findDbgDeclare(*I, false); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1155 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1156 | return 0; |
| 1157 | } |
| 1158 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1159 | // Find llvm.dbg.declare among uses of the instruction. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1160 | for (Value::use_const_iterator I = V->use_begin(), E =V->use_end(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1161 | I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1162 | if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) |
| 1163 | return DDI; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1164 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1167 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1168 | bool getLocationInfo(const Value *V, std::string &DisplayName, |
| 1169 | std::string &Type, unsigned &LineNo, std::string &File, |
| 1170 | std::string &Dir) { |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1171 | DICompileUnit Unit; |
| 1172 | DIType TypeD; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1173 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1174 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) { |
| 1175 | Value *DIGV = findDbgGlobalDeclare(GV); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1176 | if (!DIGV) return false; |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1177 | DIGlobalVariable Var(cast<GlobalVariable>(DIGV)); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1178 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1179 | Var.getDisplayName(DisplayName); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1180 | LineNo = Var.getLineNumber(); |
| 1181 | Unit = Var.getCompileUnit(); |
| 1182 | TypeD = Var.getType(); |
| 1183 | } else { |
| 1184 | const DbgDeclareInst *DDI = findDbgDeclare(V); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1185 | if (!DDI) return false; |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1186 | DIVariable Var(cast<GlobalVariable>(DDI->getVariable())); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1187 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1188 | Var.getName(DisplayName); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1189 | LineNo = Var.getLineNumber(); |
| 1190 | Unit = Var.getCompileUnit(); |
| 1191 | TypeD = Var.getType(); |
| 1192 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1193 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1194 | TypeD.getName(Type); |
| 1195 | Unit.getFilename(File); |
| 1196 | Unit.getDirectory(Dir); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1197 | return true; |
| 1198 | } |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1199 | |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1200 | /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 1201 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1202 | bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI, |
| 1203 | CodeGenOpt::Level OptLev) { |
| 1204 | return DIDescriptor::ValidDebugInfo(SPI.getContext(), OptLev); |
| 1205 | } |
| 1206 | |
| 1207 | /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 1208 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1209 | bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI, |
| 1210 | CodeGenOpt::Level OptLev) { |
| 1211 | return DIDescriptor::ValidDebugInfo(FSI.getSubprogram(), OptLev); |
| 1212 | } |
| 1213 | |
| 1214 | /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 1215 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1216 | bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI, |
| 1217 | CodeGenOpt::Level OptLev) { |
| 1218 | return DIDescriptor::ValidDebugInfo(RSI.getContext(), OptLev); |
| 1219 | } |
| 1220 | |
| 1221 | /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 1222 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1223 | bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI, |
| 1224 | CodeGenOpt::Level OptLev) { |
| 1225 | return DIDescriptor::ValidDebugInfo(REI.getContext(), OptLev); |
| 1226 | } |
| 1227 | |
| 1228 | |
| 1229 | /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 1230 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1231 | bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI, |
| 1232 | CodeGenOpt::Level OptLev) { |
| 1233 | return DIDescriptor::ValidDebugInfo(DI.getVariable(), OptLev); |
| 1234 | } |
| 1235 | |
| 1236 | /// ExtractDebugLocation - Extract debug location information |
| 1237 | /// from llvm.dbg.stoppoint intrinsic. |
| 1238 | DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1239 | DebugLocTracker &DebugLocInfo) { |
| 1240 | DebugLoc DL; |
| 1241 | Value *Context = SPI.getContext(); |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1242 | |
| 1243 | // If this location is already tracked then use it. |
| 1244 | DebugLocTuple Tuple(cast<GlobalVariable>(Context), SPI.getLine(), |
| 1245 | SPI.getColumn()); |
| 1246 | DenseMap<DebugLocTuple, unsigned>::iterator II |
| 1247 | = DebugLocInfo.DebugIdMap.find(Tuple); |
| 1248 | if (II != DebugLocInfo.DebugIdMap.end()) |
| 1249 | return DebugLoc::get(II->second); |
| 1250 | |
| 1251 | // Add a new location entry. |
| 1252 | unsigned Id = DebugLocInfo.DebugLocations.size(); |
| 1253 | DebugLocInfo.DebugLocations.push_back(Tuple); |
| 1254 | DebugLocInfo.DebugIdMap[Tuple] = Id; |
| 1255 | |
| 1256 | return DebugLoc::get(Id); |
| 1257 | } |
| 1258 | |
| 1259 | /// ExtractDebugLocation - Extract debug location information |
| 1260 | /// from llvm.dbg.func_start intrinsic. |
| 1261 | DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1262 | DebugLocTracker &DebugLocInfo) { |
| 1263 | DebugLoc DL; |
| 1264 | Value *SP = FSI.getSubprogram(); |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 1265 | |
| 1266 | DISubprogram Subprogram(cast<GlobalVariable>(SP)); |
| 1267 | unsigned Line = Subprogram.getLineNumber(); |
| 1268 | DICompileUnit CU(Subprogram.getCompileUnit()); |
| 1269 | |
| 1270 | // If this location is already tracked then use it. |
| 1271 | DebugLocTuple Tuple(CU.getGV(), Line, /* Column */ 0); |
| 1272 | DenseMap<DebugLocTuple, unsigned>::iterator II |
| 1273 | = DebugLocInfo.DebugIdMap.find(Tuple); |
| 1274 | if (II != DebugLocInfo.DebugIdMap.end()) |
| 1275 | return DebugLoc::get(II->second); |
| 1276 | |
| 1277 | // Add a new location entry. |
| 1278 | unsigned Id = DebugLocInfo.DebugLocations.size(); |
| 1279 | DebugLocInfo.DebugLocations.push_back(Tuple); |
| 1280 | DebugLocInfo.DebugIdMap[Tuple] = Id; |
| 1281 | |
| 1282 | return DebugLoc::get(Id); |
| 1283 | } |
| 1284 | |
| 1285 | /// isInlinedFnStart - Return true if FSI is starting an inlined function. |
| 1286 | bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn) { |
| 1287 | DISubprogram Subprogram(cast<GlobalVariable>(FSI.getSubprogram())); |
| 1288 | if (Subprogram.describes(CurrentFn)) |
| 1289 | return false; |
| 1290 | |
| 1291 | return true; |
| 1292 | } |
| 1293 | |
| 1294 | /// isInlinedFnEnd - Return true if REI is ending an inlined function. |
| 1295 | bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn) { |
| 1296 | DISubprogram Subprogram(cast<GlobalVariable>(REI.getContext())); |
| 1297 | if (Subprogram.isNull() || Subprogram.describes(CurrentFn)) |
| 1298 | return false; |
| 1299 | |
| 1300 | return true; |
| 1301 | } |
| 1302 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1303 | } |