Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===// |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 9 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 11 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 12 | #include "llvm/Constants.h" |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 13 | #include "llvm/Analysis/ValueTracking.h" |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 15 | #include "llvm/CodeGen/MachineFunction.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineLocation.h" |
Evan Cheng | 8b56a90 | 2008-09-22 22:21:38 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/Passes.h" |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetInstrInfo.h" |
| 19 | #include "llvm/Target/TargetMachine.h" |
Jim Laskey | c1c47c3 | 2007-01-29 23:40:33 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetOptions.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 21 | #include "llvm/DerivedTypes.h" |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 22 | #include "llvm/GlobalVariable.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 23 | #include "llvm/Intrinsics.h" |
| 24 | #include "llvm/Instructions.h" |
| 25 | #include "llvm/Module.h" |
| 26 | #include "llvm/Support/Dwarf.h" |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Streams.h" |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 28 | using namespace llvm; |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 29 | using namespace llvm::dwarf; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 30 | |
| 31 | // Handle the Pass registration stuff necessary to use TargetData's. |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 32 | static RegisterPass<MachineModuleInfo> |
| 33 | X("machinemoduleinfo", "Module Information"); |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 34 | char MachineModuleInfo::ID = 0; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 35 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 38 | /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 39 | /// specified value in their initializer somewhere. |
| 40 | static void |
Bill Wendling | 0ac1b6d | 2008-06-27 01:32:08 +0000 | [diff] [blame] | 41 | getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) { |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 42 | // Scan though value users. |
| 43 | for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) { |
| 44 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 45 | // If the user is a GlobalVariable then add to result. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 46 | Result.push_back(GV); |
| 47 | } else if (Constant *C = dyn_cast<Constant>(*I)) { |
| 48 | // If the user is a constant variable then scan its users |
| 49 | getGlobalVariablesUsing(C, Result); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 54 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 55 | /// named GlobalVariable. |
Bill Wendling | c04f465 | 2008-07-03 23:13:02 +0000 | [diff] [blame] | 56 | static void |
| 57 | getGlobalVariablesUsing(Module &M, const std::string &RootName, |
| 58 | std::vector<GlobalVariable*> &Result) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 59 | std::vector<const Type*> FieldTypes; |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 60 | FieldTypes.push_back(Type::Int32Ty); |
| 61 | FieldTypes.push_back(Type::Int32Ty); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 62 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 63 | // Get the GlobalVariable root. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 64 | GlobalVariable *UseRoot = M.getGlobalVariable(RootName, |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 65 | StructType::get(FieldTypes)); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 66 | |
| 67 | // If present and linkonce then scan for users. |
Bill Wendling | c04f465 | 2008-07-03 23:13:02 +0000 | [diff] [blame] | 68 | if (UseRoot && UseRoot->hasLinkOnceLinkage()) |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 69 | getGlobalVariablesUsing(UseRoot, Result); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 72 | /// isStringValue - Return true if the given value can be coerced to a string. |
| 73 | /// |
| 74 | static bool isStringValue(Value *V) { |
| 75 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 76 | if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) { |
| 77 | ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); |
| 78 | return Init->isString(); |
| 79 | } |
| 80 | } else if (Constant *C = dyn_cast<Constant>(V)) { |
| 81 | if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 82 | return isStringValue(GV); |
| 83 | else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { |
| 84 | if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 85 | if (CE->getNumOperands() == 3 && |
| 86 | cast<Constant>(CE->getOperand(1))->isNullValue() && |
| 87 | isa<ConstantInt>(CE->getOperand(2))) { |
| 88 | return isStringValue(CE->getOperand(0)); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | return false; |
| 94 | } |
| 95 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 96 | /// getGlobalVariable - Return either a direct or cast Global value. |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 97 | /// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 98 | static GlobalVariable *getGlobalVariable(Value *V) { |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 99 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 100 | return GV; |
| 101 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 102 | if (CE->getOpcode() == Instruction::BitCast) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 103 | return dyn_cast<GlobalVariable>(CE->getOperand(0)); |
Dale Johannesen | 7757fff | 2008-01-30 19:00:21 +0000 | [diff] [blame] | 104 | } else if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 105 | for (unsigned int i=1; i<CE->getNumOperands(); i++) { |
Dale Johannesen | 43b8f3b | 2008-01-30 19:44:39 +0000 | [diff] [blame] | 106 | if (!CE->getOperand(i)->isNullValue()) |
Dale Johannesen | 7757fff | 2008-01-30 19:00:21 +0000 | [diff] [blame] | 107 | return NULL; |
| 108 | } |
| 109 | return dyn_cast<GlobalVariable>(CE->getOperand(0)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 110 | } |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 111 | } |
| 112 | return NULL; |
| 113 | } |
| 114 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 115 | /// isGlobalVariable - Return true if the given value can be coerced to a |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 116 | /// GlobalVariable. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 117 | static bool isGlobalVariable(Value *V) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 118 | if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) { |
| 119 | return true; |
| 120 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 121 | if (CE->getOpcode() == Instruction::BitCast) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 122 | return isa<GlobalVariable>(CE->getOperand(0)); |
Dale Johannesen | 7757fff | 2008-01-30 19:00:21 +0000 | [diff] [blame] | 123 | } else if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 124 | for (unsigned int i=1; i<CE->getNumOperands(); i++) { |
Dale Johannesen | 43b8f3b | 2008-01-30 19:44:39 +0000 | [diff] [blame] | 125 | if (!CE->getOperand(i)->isNullValue()) |
Dale Johannesen | 7757fff | 2008-01-30 19:00:21 +0000 | [diff] [blame] | 126 | return false; |
| 127 | } |
| 128 | return isa<GlobalVariable>(CE->getOperand(0)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 134 | /// getUIntOperand - Return ith operand if it is an unsigned integer. |
| 135 | /// |
| 136 | static ConstantInt *getUIntOperand(GlobalVariable *GV, unsigned i) { |
| 137 | // Make sure the GlobalVariable has an initializer. |
| 138 | if (!GV->hasInitializer()) return NULL; |
| 139 | |
| 140 | // Get the initializer constant. |
| 141 | ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer()); |
| 142 | if (!CI) return NULL; |
| 143 | |
| 144 | // Check if there is at least i + 1 operands. |
| 145 | unsigned N = CI->getNumOperands(); |
| 146 | if (i >= N) return NULL; |
| 147 | |
| 148 | // Check constant. |
| 149 | return dyn_cast<ConstantInt>(CI->getOperand(i)); |
| 150 | } |
| 151 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 152 | //===----------------------------------------------------------------------===// |
| 153 | |
Bill Wendling | 3e30cbb | 2008-07-09 06:02:33 +0000 | [diff] [blame] | 154 | static unsigned CountFields(DebugInfoDesc *DD) { |
| 155 | unsigned Count = 0; |
| 156 | |
| 157 | switch (DD->getTag()) { |
| 158 | case DW_TAG_anchor: // AnchorDesc |
| 159 | // Tag |
| 160 | // AnchorTag |
| 161 | Count = 2; |
| 162 | break; |
| 163 | case DW_TAG_compile_unit: // CompileUnitDesc |
| 164 | // [DW_TAG_anchor] |
| 165 | // if (Version == 0) DebugVersion |
| 166 | // Language |
| 167 | // FileName |
| 168 | // Directory |
| 169 | // Producer |
| 170 | Count = 6; |
| 171 | |
| 172 | // Handle cases out of sync with compiler. |
| 173 | if (DD->getVersion() == 0) |
| 174 | ++Count; |
| 175 | |
| 176 | break; |
| 177 | case DW_TAG_variable: // GlobalVariableDesc |
| 178 | // [DW_TAG_anchor] |
| 179 | // Context |
| 180 | // Name |
| 181 | // FullName |
| 182 | // LinkageName |
| 183 | // File |
| 184 | // Line |
| 185 | // TyDesc |
| 186 | // IsStatic |
| 187 | // IsDefinition |
| 188 | // Global |
| 189 | Count = 12; |
| 190 | break; |
| 191 | case DW_TAG_subprogram: // SubprogramDesc |
| 192 | // [DW_TAG_anchor] |
| 193 | // Context |
| 194 | // Name |
| 195 | // FullName |
| 196 | // LinkageName |
| 197 | // File |
| 198 | // Line |
| 199 | // TyDesc |
| 200 | // IsStatic |
| 201 | // IsDefinition |
| 202 | Count = 11; |
| 203 | break; |
| 204 | case DW_TAG_lexical_block: // BlockDesc |
| 205 | // Tag |
| 206 | // Context |
| 207 | Count = 2; |
| 208 | break; |
| 209 | case DW_TAG_base_type: // BasicTypeDesc |
| 210 | // Tag |
| 211 | // Context |
| 212 | // Name |
| 213 | // File |
| 214 | // Line |
| 215 | // Size |
| 216 | // Align |
| 217 | // Offset |
| 218 | // if (Version > LLVMDebugVersion4) Flags |
| 219 | // Encoding |
| 220 | Count = 9; |
| 221 | |
| 222 | if (DD->getVersion() > LLVMDebugVersion4) |
| 223 | ++Count; |
| 224 | |
| 225 | break; |
| 226 | case DW_TAG_typedef: |
| 227 | case DW_TAG_pointer_type: |
| 228 | case DW_TAG_reference_type: |
| 229 | case DW_TAG_const_type: |
| 230 | case DW_TAG_volatile_type: |
| 231 | case DW_TAG_restrict_type: |
| 232 | case DW_TAG_member: |
| 233 | case DW_TAG_inheritance: // DerivedTypeDesc |
| 234 | // Tag |
| 235 | // Context |
| 236 | // Name |
| 237 | // File |
| 238 | // Line |
| 239 | // Size |
| 240 | // Align |
| 241 | // Offset |
| 242 | // if (Version > LLVMDebugVersion4) Flags |
| 243 | // FromType |
| 244 | Count = 9; |
| 245 | |
| 246 | if (DD->getVersion() > LLVMDebugVersion4) |
| 247 | ++Count; |
| 248 | |
| 249 | break; |
| 250 | case DW_TAG_array_type: |
| 251 | case DW_TAG_structure_type: |
| 252 | case DW_TAG_union_type: |
| 253 | case DW_TAG_enumeration_type: |
| 254 | case DW_TAG_vector_type: |
| 255 | case DW_TAG_subroutine_type: // CompositeTypeDesc |
| 256 | // Tag |
| 257 | // Context |
| 258 | // Name |
| 259 | // File |
| 260 | // Line |
| 261 | // Size |
| 262 | // Align |
| 263 | // Offset |
| 264 | // if (Version > LLVMDebugVersion4) Flags |
| 265 | // FromType |
| 266 | // Elements |
| 267 | Count = 10; |
| 268 | |
| 269 | if (DD->getVersion() > LLVMDebugVersion4) |
| 270 | ++Count; |
| 271 | |
| 272 | break; |
| 273 | case DW_TAG_subrange_type: // SubrangeDesc |
| 274 | // Tag |
| 275 | // Lo |
| 276 | // Hi |
| 277 | Count = 3; |
| 278 | break; |
| 279 | case DW_TAG_enumerator: // EnumeratorDesc |
| 280 | // Tag |
| 281 | // Name |
| 282 | // Value |
| 283 | Count = 3; |
| 284 | break; |
| 285 | case DW_TAG_return_variable: |
| 286 | case DW_TAG_arg_variable: |
| 287 | case DW_TAG_auto_variable: // VariableDesc |
| 288 | // Tag |
| 289 | // Context |
| 290 | // Name |
| 291 | // File |
| 292 | // Line |
| 293 | // TyDesc |
| 294 | Count = 6; |
| 295 | break; |
| 296 | default: |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | return Count; |
| 301 | } |
| 302 | |
| 303 | //===----------------------------------------------------------------------===// |
| 304 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 305 | /// ApplyToFields - Target the visitor to each field of the debug information |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 306 | /// descriptor. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 307 | void DIVisitor::ApplyToFields(DebugInfoDesc *DD) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 308 | DD->ApplyToFields(this); |
| 309 | } |
| 310 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 311 | namespace { |
| 312 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 313 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 314 | /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the |
| 315 | /// supplied DebugInfoDesc. |
| 316 | class DIDeserializeVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 317 | private: |
| 318 | DIDeserializer &DR; // Active deserializer. |
| 319 | unsigned I; // Current operand index. |
| 320 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 321 | |
| 322 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 323 | DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV) |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 324 | : DIVisitor(), DR(D), I(0), CI(cast<ConstantStruct>(GV->getInitializer())) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 325 | {} |
| 326 | |
| 327 | /// Apply - Set the value of each of the fields. |
| 328 | /// |
| 329 | virtual void Apply(int &Field) { |
| 330 | Constant *C = CI->getOperand(I++); |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 331 | Field = cast<ConstantInt>(C)->getSExtValue(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 332 | } |
| 333 | virtual void Apply(unsigned &Field) { |
| 334 | Constant *C = CI->getOperand(I++); |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 335 | Field = cast<ConstantInt>(C)->getZExtValue(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 336 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 337 | virtual void Apply(int64_t &Field) { |
| 338 | Constant *C = CI->getOperand(I++); |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 339 | Field = cast<ConstantInt>(C)->getSExtValue(); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 340 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 341 | virtual void Apply(uint64_t &Field) { |
| 342 | Constant *C = CI->getOperand(I++); |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 343 | Field = cast<ConstantInt>(C)->getZExtValue(); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 344 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 345 | virtual void Apply(bool &Field) { |
| 346 | Constant *C = CI->getOperand(I++); |
Reid Spencer | 579dca1 | 2007-01-12 04:24:46 +0000 | [diff] [blame] | 347 | Field = cast<ConstantInt>(C)->getZExtValue(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 348 | } |
| 349 | virtual void Apply(std::string &Field) { |
| 350 | Constant *C = CI->getOperand(I++); |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 351 | // Fills in the string if it succeeds |
| 352 | if (!GetConstantStringInfo(C, Field)) |
| 353 | Field.clear(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 354 | } |
| 355 | virtual void Apply(DebugInfoDesc *&Field) { |
| 356 | Constant *C = CI->getOperand(I++); |
| 357 | Field = DR.Deserialize(C); |
| 358 | } |
| 359 | virtual void Apply(GlobalVariable *&Field) { |
| 360 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 361 | Field = getGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 362 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 363 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 364 | Field.resize(0); |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 365 | Constant *C = CI->getOperand(I++); |
| 366 | GlobalVariable *GV = getGlobalVariable(C); |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 367 | if (GV->hasInitializer()) { |
| 368 | if (ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer())) { |
| 369 | for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) { |
| 370 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 371 | DebugInfoDesc *DE = DR.Deserialize(GVE); |
| 372 | Field.push_back(DE); |
| 373 | } |
| 374 | } else if (GV->getInitializer()->isNullValue()) { |
| 375 | if (const ArrayType *T = |
| 376 | dyn_cast<ArrayType>(GV->getType()->getElementType())) { |
| 377 | Field.resize(T->getNumElements()); |
| 378 | } |
Jim Laskey | 2b0e309 | 2006-03-08 02:07:02 +0000 | [diff] [blame] | 379 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 385 | /// DISerializeVisitor - This DIVisitor serializes all the fields in |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 386 | /// the supplied DebugInfoDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 387 | class DISerializeVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 388 | private: |
| 389 | DISerializer &SR; // Active serializer. |
| 390 | std::vector<Constant*> &Elements; // Element accumulator. |
| 391 | |
| 392 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 393 | DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E) |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 394 | : DIVisitor() |
| 395 | , SR(S) |
| 396 | , Elements(E) |
| 397 | {} |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 398 | |
| 399 | /// Apply - Set the value of each of the fields. |
| 400 | /// |
| 401 | virtual void Apply(int &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 402 | Elements.push_back(ConstantInt::get(Type::Int32Ty, int32_t(Field))); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 403 | } |
| 404 | virtual void Apply(unsigned &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 405 | Elements.push_back(ConstantInt::get(Type::Int32Ty, uint32_t(Field))); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 406 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 407 | virtual void Apply(int64_t &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 408 | Elements.push_back(ConstantInt::get(Type::Int64Ty, int64_t(Field))); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 409 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 410 | virtual void Apply(uint64_t &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 411 | Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field))); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 412 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 413 | virtual void Apply(bool &Field) { |
Reid Spencer | 579dca1 | 2007-01-12 04:24:46 +0000 | [diff] [blame] | 414 | Elements.push_back(ConstantInt::get(Type::Int1Ty, Field)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 415 | } |
| 416 | virtual void Apply(std::string &Field) { |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 417 | Elements.push_back(SR.getString(Field)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 418 | } |
| 419 | virtual void Apply(DebugInfoDesc *&Field) { |
| 420 | GlobalVariable *GV = NULL; |
| 421 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 422 | // If non-NULL then convert to global. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 423 | if (Field) GV = SR.Serialize(Field); |
| 424 | |
| 425 | // FIXME - At some point should use specific type. |
| 426 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 427 | |
| 428 | if (GV) { |
| 429 | // Set to pointer to global. |
Reid Spencer | 15f46d6 | 2006-12-12 01:17:41 +0000 | [diff] [blame] | 430 | Elements.push_back(ConstantExpr::getBitCast(GV, EmptyTy)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 431 | } else { |
| 432 | // Use NULL. |
| 433 | Elements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 434 | } |
| 435 | } |
| 436 | virtual void Apply(GlobalVariable *&Field) { |
| 437 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 438 | if (Field) { |
Reid Spencer | 15f46d6 | 2006-12-12 01:17:41 +0000 | [diff] [blame] | 439 | Elements.push_back(ConstantExpr::getBitCast(Field, EmptyTy)); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 440 | } else { |
| 441 | Elements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 442 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 443 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 444 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 445 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 446 | unsigned N = Field.size(); |
| 447 | ArrayType *AT = ArrayType::get(EmptyTy, N); |
| 448 | std::vector<Constant *> ArrayElements; |
| 449 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 450 | for (unsigned i = 0, N = Field.size(); i < N; ++i) { |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 451 | if (DebugInfoDesc *Element = Field[i]) { |
| 452 | GlobalVariable *GVE = SR.Serialize(Element); |
Reid Spencer | 15f46d6 | 2006-12-12 01:17:41 +0000 | [diff] [blame] | 453 | Constant *CE = ConstantExpr::getBitCast(GVE, EmptyTy); |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 454 | ArrayElements.push_back(cast<Constant>(CE)); |
| 455 | } else { |
| 456 | ArrayElements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 457 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | Constant *CA = ConstantArray::get(AT, ArrayElements); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 461 | GlobalVariable *CAGV = new GlobalVariable(AT, true, |
| 462 | GlobalValue::InternalLinkage, |
| 463 | CA, "llvm.dbg.array", |
| 464 | SR.getModule()); |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 465 | CAGV->setSection("llvm.metadata"); |
Reid Spencer | 15f46d6 | 2006-12-12 01:17:41 +0000 | [diff] [blame] | 466 | Constant *CAE = ConstantExpr::getBitCast(CAGV, EmptyTy); |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 467 | Elements.push_back(CAE); |
| 468 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 469 | }; |
| 470 | |
| 471 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 472 | /// DIGetTypesVisitor - This DIVisitor gathers all the field types in |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 473 | /// the supplied DebugInfoDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 474 | class DIGetTypesVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 475 | private: |
| 476 | DISerializer &SR; // Active serializer. |
| 477 | std::vector<const Type*> &Fields; // Type accumulator. |
| 478 | |
| 479 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 480 | DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F) |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 481 | : DIVisitor() |
| 482 | , SR(S) |
| 483 | , Fields(F) |
| 484 | {} |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 485 | |
| 486 | /// Apply - Set the value of each of the fields. |
| 487 | /// |
| 488 | virtual void Apply(int &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 489 | Fields.push_back(Type::Int32Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 490 | } |
| 491 | virtual void Apply(unsigned &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 492 | Fields.push_back(Type::Int32Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 493 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 494 | virtual void Apply(int64_t &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 495 | Fields.push_back(Type::Int64Ty); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 496 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 497 | virtual void Apply(uint64_t &Field) { |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 498 | Fields.push_back(Type::Int64Ty); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 499 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 500 | virtual void Apply(bool &Field) { |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 501 | Fields.push_back(Type::Int1Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 502 | } |
| 503 | virtual void Apply(std::string &Field) { |
| 504 | Fields.push_back(SR.getStrPtrType()); |
| 505 | } |
| 506 | virtual void Apply(DebugInfoDesc *&Field) { |
| 507 | // FIXME - At some point should use specific type. |
| 508 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 509 | Fields.push_back(EmptyTy); |
| 510 | } |
| 511 | virtual void Apply(GlobalVariable *&Field) { |
| 512 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 513 | Fields.push_back(EmptyTy); |
| 514 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 515 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 516 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 517 | Fields.push_back(EmptyTy); |
| 518 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 519 | }; |
| 520 | |
| 521 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 522 | /// DIVerifyVisitor - This DIVisitor verifies all the field types against |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 523 | /// a constant initializer. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 524 | class DIVerifyVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 525 | private: |
| 526 | DIVerifier &VR; // Active verifier. |
| 527 | bool IsValid; // Validity status. |
| 528 | unsigned I; // Current operand index. |
| 529 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 530 | |
| 531 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 532 | DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV) |
| 533 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 534 | , VR(V) |
| 535 | , IsValid(true) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 536 | , I(0) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 537 | , CI(cast<ConstantStruct>(GV->getInitializer())) |
| 538 | { |
| 539 | } |
| 540 | |
| 541 | // Accessors. |
| 542 | bool isValid() const { return IsValid; } |
| 543 | |
| 544 | /// Apply - Set the value of each of the fields. |
| 545 | /// |
| 546 | virtual void Apply(int &Field) { |
| 547 | Constant *C = CI->getOperand(I++); |
| 548 | IsValid = IsValid && isa<ConstantInt>(C); |
| 549 | } |
| 550 | virtual void Apply(unsigned &Field) { |
| 551 | Constant *C = CI->getOperand(I++); |
| 552 | IsValid = IsValid && isa<ConstantInt>(C); |
| 553 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 554 | virtual void Apply(int64_t &Field) { |
| 555 | Constant *C = CI->getOperand(I++); |
| 556 | IsValid = IsValid && isa<ConstantInt>(C); |
| 557 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 558 | virtual void Apply(uint64_t &Field) { |
| 559 | Constant *C = CI->getOperand(I++); |
| 560 | IsValid = IsValid && isa<ConstantInt>(C); |
| 561 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 562 | virtual void Apply(bool &Field) { |
| 563 | Constant *C = CI->getOperand(I++); |
Reid Spencer | 4fe16d6 | 2007-01-11 18:21:29 +0000 | [diff] [blame] | 564 | IsValid = IsValid && isa<ConstantInt>(C) && C->getType() == Type::Int1Ty; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 565 | } |
| 566 | virtual void Apply(std::string &Field) { |
| 567 | Constant *C = CI->getOperand(I++); |
Jim Laskey | 26a3687 | 2007-01-03 13:46:20 +0000 | [diff] [blame] | 568 | IsValid = IsValid && |
| 569 | (!C || isStringValue(C) || C->isNullValue()); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 570 | } |
| 571 | virtual void Apply(DebugInfoDesc *&Field) { |
| 572 | // FIXME - Prepare the correct descriptor. |
| 573 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 574 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 575 | } |
| 576 | virtual void Apply(GlobalVariable *&Field) { |
| 577 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 578 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 579 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 580 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 581 | Constant *C = CI->getOperand(I++); |
| 582 | IsValid = IsValid && isGlobalVariable(C); |
| 583 | if (!IsValid) return; |
| 584 | |
| 585 | GlobalVariable *GV = getGlobalVariable(C); |
| 586 | IsValid = IsValid && GV && GV->hasInitializer(); |
| 587 | if (!IsValid) return; |
| 588 | |
| 589 | ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 590 | IsValid = IsValid && CA; |
| 591 | if (!IsValid) return; |
| 592 | |
| 593 | for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) { |
| 594 | IsValid = IsValid && isGlobalVariable(CA->getOperand(i)); |
| 595 | if (!IsValid) return; |
| 596 | |
| 597 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 598 | VR.Verify(GVE); |
| 599 | } |
| 600 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 601 | }; |
| 602 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 603 | } |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 604 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 605 | //===----------------------------------------------------------------------===// |
| 606 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 607 | /// TagFromGlobal - Returns the tag number from a debug info descriptor |
| 608 | /// GlobalVariable. Return DIIValid if operand is not an unsigned int. |
| 609 | unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) { |
| 610 | ConstantInt *C = getUIntOperand(GV, 0); |
| 611 | return C ? ((unsigned)C->getZExtValue() & ~LLVMDebugVersionMask) : |
| 612 | (unsigned)DW_TAG_invalid; |
| 613 | } |
| 614 | |
| 615 | /// VersionFromGlobal - Returns the version number from a debug info |
| 616 | /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned |
| 617 | /// int. |
| 618 | unsigned DebugInfoDesc::VersionFromGlobal(GlobalVariable *GV) { |
| 619 | ConstantInt *C = getUIntOperand(GV, 0); |
| 620 | return C ? ((unsigned)C->getZExtValue() & LLVMDebugVersionMask) : |
| 621 | (unsigned)DW_TAG_invalid; |
| 622 | } |
| 623 | |
| 624 | /// DescFactory - Create an instance of debug info descriptor based on Tag. |
| 625 | /// Return NULL if not a recognized Tag. |
| 626 | DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) { |
| 627 | switch (Tag) { |
| 628 | case DW_TAG_anchor: return new AnchorDesc(); |
| 629 | case DW_TAG_compile_unit: return new CompileUnitDesc(); |
| 630 | case DW_TAG_variable: return new GlobalVariableDesc(); |
| 631 | case DW_TAG_subprogram: return new SubprogramDesc(); |
| 632 | case DW_TAG_lexical_block: return new BlockDesc(); |
| 633 | case DW_TAG_base_type: return new BasicTypeDesc(); |
| 634 | case DW_TAG_typedef: |
| 635 | case DW_TAG_pointer_type: |
| 636 | case DW_TAG_reference_type: |
| 637 | case DW_TAG_const_type: |
| 638 | case DW_TAG_volatile_type: |
| 639 | case DW_TAG_restrict_type: |
| 640 | case DW_TAG_member: |
| 641 | case DW_TAG_inheritance: return new DerivedTypeDesc(Tag); |
| 642 | case DW_TAG_array_type: |
| 643 | case DW_TAG_structure_type: |
| 644 | case DW_TAG_union_type: |
| 645 | case DW_TAG_enumeration_type: |
| 646 | case DW_TAG_vector_type: |
| 647 | case DW_TAG_subroutine_type: return new CompositeTypeDesc(Tag); |
| 648 | case DW_TAG_subrange_type: return new SubrangeDesc(); |
| 649 | case DW_TAG_enumerator: return new EnumeratorDesc(); |
| 650 | case DW_TAG_return_variable: |
| 651 | case DW_TAG_arg_variable: |
| 652 | case DW_TAG_auto_variable: return new VariableDesc(Tag); |
| 653 | default: break; |
| 654 | } |
| 655 | return NULL; |
| 656 | } |
| 657 | |
| 658 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 659 | /// |
| 660 | GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const { |
| 661 | return GlobalValue::InternalLinkage; |
| 662 | } |
| 663 | |
| 664 | /// ApplyToFields - Target the vistor to the fields of the descriptor. |
| 665 | /// |
| 666 | void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) { |
| 667 | Visitor->Apply(Tag); |
| 668 | } |
| 669 | |
| 670 | //===----------------------------------------------------------------------===// |
| 671 | |
| 672 | AnchorDesc::AnchorDesc() |
| 673 | : DebugInfoDesc(DW_TAG_anchor) |
| 674 | , AnchorTag(0) |
| 675 | {} |
| 676 | AnchorDesc::AnchorDesc(AnchoredDesc *D) |
| 677 | : DebugInfoDesc(DW_TAG_anchor) |
| 678 | , AnchorTag(D->getTag()) |
| 679 | {} |
| 680 | |
| 681 | // Implement isa/cast/dyncast. |
| 682 | bool AnchorDesc::classof(const DebugInfoDesc *D) { |
| 683 | return D->getTag() == DW_TAG_anchor; |
| 684 | } |
| 685 | |
| 686 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 687 | /// |
| 688 | GlobalValue::LinkageTypes AnchorDesc::getLinkage() const { |
| 689 | return GlobalValue::LinkOnceLinkage; |
| 690 | } |
| 691 | |
| 692 | /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc. |
| 693 | /// |
| 694 | void AnchorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 695 | DebugInfoDesc::ApplyToFields(Visitor); |
| 696 | |
| 697 | Visitor->Apply(AnchorTag); |
| 698 | } |
| 699 | |
| 700 | /// getDescString - Return a string used to compose global names and labels. A |
| 701 | /// A global variable name needs to be defined for each debug descriptor that is |
| 702 | /// anchored. NOTE: that each global variable named here also needs to be added |
| 703 | /// to the list of names left external in the internalizer. |
| 704 | /// ExternalNames.insert("llvm.dbg.compile_units"); |
| 705 | /// ExternalNames.insert("llvm.dbg.global_variables"); |
| 706 | /// ExternalNames.insert("llvm.dbg.subprograms"); |
| 707 | const char *AnchorDesc::getDescString() const { |
| 708 | switch (AnchorTag) { |
| 709 | case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString; |
| 710 | case DW_TAG_variable: return GlobalVariableDesc::AnchorString; |
| 711 | case DW_TAG_subprogram: return SubprogramDesc::AnchorString; |
| 712 | default: break; |
| 713 | } |
| 714 | |
| 715 | assert(0 && "Tag does not have a case for anchor string"); |
| 716 | return ""; |
| 717 | } |
| 718 | |
| 719 | /// getTypeString - Return a string used to label this descriptors type. |
| 720 | /// |
| 721 | const char *AnchorDesc::getTypeString() const { |
| 722 | return "llvm.dbg.anchor.type"; |
| 723 | } |
| 724 | |
| 725 | #ifndef NDEBUG |
| 726 | void AnchorDesc::dump() { |
| 727 | cerr << getDescString() << " " |
| 728 | << "Version(" << getVersion() << "), " |
| 729 | << "Tag(" << getTag() << "), " |
| 730 | << "AnchorTag(" << AnchorTag << ")\n"; |
| 731 | } |
| 732 | #endif |
| 733 | |
| 734 | //===----------------------------------------------------------------------===// |
| 735 | |
| 736 | AnchoredDesc::AnchoredDesc(unsigned T) |
| 737 | : DebugInfoDesc(T) |
| 738 | , Anchor(NULL) |
| 739 | {} |
| 740 | |
| 741 | /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc. |
| 742 | /// |
| 743 | void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) { |
| 744 | DebugInfoDesc::ApplyToFields(Visitor); |
| 745 | |
| 746 | Visitor->Apply(Anchor); |
| 747 | } |
| 748 | |
| 749 | //===----------------------------------------------------------------------===// |
| 750 | |
| 751 | CompileUnitDesc::CompileUnitDesc() |
| 752 | : AnchoredDesc(DW_TAG_compile_unit) |
| 753 | , Language(0) |
| 754 | , FileName("") |
| 755 | , Directory("") |
| 756 | , Producer("") |
| 757 | {} |
| 758 | |
| 759 | // Implement isa/cast/dyncast. |
| 760 | bool CompileUnitDesc::classof(const DebugInfoDesc *D) { |
| 761 | return D->getTag() == DW_TAG_compile_unit; |
| 762 | } |
| 763 | |
| 764 | /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc. |
| 765 | /// |
| 766 | void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) { |
| 767 | AnchoredDesc::ApplyToFields(Visitor); |
| 768 | |
| 769 | // Handle cases out of sync with compiler. |
| 770 | if (getVersion() == 0) { |
| 771 | unsigned DebugVersion; |
| 772 | Visitor->Apply(DebugVersion); |
| 773 | } |
| 774 | |
| 775 | Visitor->Apply(Language); |
| 776 | Visitor->Apply(FileName); |
| 777 | Visitor->Apply(Directory); |
| 778 | Visitor->Apply(Producer); |
| 779 | } |
| 780 | |
| 781 | /// getDescString - Return a string used to compose global names and labels. |
| 782 | /// |
| 783 | const char *CompileUnitDesc::getDescString() const { |
| 784 | return "llvm.dbg.compile_unit"; |
| 785 | } |
| 786 | |
| 787 | /// getTypeString - Return a string used to label this descriptors type. |
| 788 | /// |
| 789 | const char *CompileUnitDesc::getTypeString() const { |
| 790 | return "llvm.dbg.compile_unit.type"; |
| 791 | } |
| 792 | |
| 793 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 794 | /// |
| 795 | const char *const CompileUnitDesc::AnchorString = "llvm.dbg.compile_units"; |
| 796 | const char *CompileUnitDesc::getAnchorString() const { |
| 797 | return AnchorString; |
| 798 | } |
| 799 | |
| 800 | #ifndef NDEBUG |
| 801 | void CompileUnitDesc::dump() { |
| 802 | cerr << getDescString() << " " |
| 803 | << "Version(" << getVersion() << "), " |
| 804 | << "Tag(" << getTag() << "), " |
| 805 | << "Anchor(" << getAnchor() << "), " |
| 806 | << "Language(" << Language << "), " |
| 807 | << "FileName(\"" << FileName << "\"), " |
| 808 | << "Directory(\"" << Directory << "\"), " |
| 809 | << "Producer(\"" << Producer << "\")\n"; |
| 810 | } |
| 811 | #endif |
| 812 | |
| 813 | //===----------------------------------------------------------------------===// |
| 814 | |
| 815 | TypeDesc::TypeDesc(unsigned T) |
| 816 | : DebugInfoDesc(T) |
| 817 | , Context(NULL) |
| 818 | , Name("") |
| 819 | , File(NULL) |
| 820 | , Line(0) |
| 821 | , Size(0) |
| 822 | , Align(0) |
| 823 | , Offset(0) |
| 824 | , Flags(0) |
| 825 | {} |
| 826 | |
| 827 | /// ApplyToFields - Target the visitor to the fields of the TypeDesc. |
| 828 | /// |
| 829 | void TypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 830 | DebugInfoDesc::ApplyToFields(Visitor); |
| 831 | |
| 832 | Visitor->Apply(Context); |
| 833 | Visitor->Apply(Name); |
| 834 | Visitor->Apply(File); |
| 835 | Visitor->Apply(Line); |
| 836 | Visitor->Apply(Size); |
| 837 | Visitor->Apply(Align); |
| 838 | Visitor->Apply(Offset); |
| 839 | if (getVersion() > LLVMDebugVersion4) Visitor->Apply(Flags); |
| 840 | } |
| 841 | |
| 842 | /// getDescString - Return a string used to compose global names and labels. |
| 843 | /// |
| 844 | const char *TypeDesc::getDescString() const { |
| 845 | return "llvm.dbg.type"; |
| 846 | } |
| 847 | |
| 848 | /// getTypeString - Return a string used to label this descriptor's type. |
| 849 | /// |
| 850 | const char *TypeDesc::getTypeString() const { |
| 851 | return "llvm.dbg.type.type"; |
| 852 | } |
| 853 | |
| 854 | #ifndef NDEBUG |
| 855 | void TypeDesc::dump() { |
| 856 | cerr << getDescString() << " " |
| 857 | << "Version(" << getVersion() << "), " |
| 858 | << "Tag(" << getTag() << "), " |
| 859 | << "Context(" << Context << "), " |
| 860 | << "Name(\"" << Name << "\"), " |
| 861 | << "File(" << File << "), " |
| 862 | << "Line(" << Line << "), " |
| 863 | << "Size(" << Size << "), " |
| 864 | << "Align(" << Align << "), " |
| 865 | << "Offset(" << Offset << "), " |
| 866 | << "Flags(" << Flags << ")\n"; |
| 867 | } |
| 868 | #endif |
| 869 | |
| 870 | //===----------------------------------------------------------------------===// |
| 871 | |
| 872 | BasicTypeDesc::BasicTypeDesc() |
| 873 | : TypeDesc(DW_TAG_base_type) |
| 874 | , Encoding(0) |
| 875 | {} |
| 876 | |
| 877 | // Implement isa/cast/dyncast. |
| 878 | bool BasicTypeDesc::classof(const DebugInfoDesc *D) { |
| 879 | return D->getTag() == DW_TAG_base_type; |
| 880 | } |
| 881 | |
| 882 | /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc. |
| 883 | /// |
| 884 | void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 885 | TypeDesc::ApplyToFields(Visitor); |
| 886 | |
| 887 | Visitor->Apply(Encoding); |
| 888 | } |
| 889 | |
| 890 | /// getDescString - Return a string used to compose global names and labels. |
| 891 | /// |
| 892 | const char *BasicTypeDesc::getDescString() const { |
| 893 | return "llvm.dbg.basictype"; |
| 894 | } |
| 895 | |
| 896 | /// getTypeString - Return a string used to label this descriptor's type. |
| 897 | /// |
| 898 | const char *BasicTypeDesc::getTypeString() const { |
| 899 | return "llvm.dbg.basictype.type"; |
| 900 | } |
| 901 | |
| 902 | #ifndef NDEBUG |
| 903 | void BasicTypeDesc::dump() { |
| 904 | cerr << getDescString() << " " |
| 905 | << "Version(" << getVersion() << "), " |
| 906 | << "Tag(" << getTag() << "), " |
| 907 | << "Context(" << getContext() << "), " |
| 908 | << "Name(\"" << getName() << "\"), " |
| 909 | << "Size(" << getSize() << "), " |
| 910 | << "Encoding(" << Encoding << ")\n"; |
| 911 | } |
| 912 | #endif |
| 913 | |
| 914 | //===----------------------------------------------------------------------===// |
| 915 | |
| 916 | DerivedTypeDesc::DerivedTypeDesc(unsigned T) |
| 917 | : TypeDesc(T) |
| 918 | , FromType(NULL) |
| 919 | {} |
| 920 | |
| 921 | // Implement isa/cast/dyncast. |
| 922 | bool DerivedTypeDesc::classof(const DebugInfoDesc *D) { |
| 923 | unsigned T = D->getTag(); |
| 924 | switch (T) { |
| 925 | case DW_TAG_typedef: |
| 926 | case DW_TAG_pointer_type: |
| 927 | case DW_TAG_reference_type: |
| 928 | case DW_TAG_const_type: |
| 929 | case DW_TAG_volatile_type: |
| 930 | case DW_TAG_restrict_type: |
| 931 | case DW_TAG_member: |
| 932 | case DW_TAG_inheritance: |
| 933 | return true; |
| 934 | default: break; |
| 935 | } |
| 936 | return false; |
| 937 | } |
| 938 | |
| 939 | /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. |
| 940 | /// |
| 941 | void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 942 | TypeDesc::ApplyToFields(Visitor); |
| 943 | |
| 944 | Visitor->Apply(FromType); |
| 945 | } |
| 946 | |
| 947 | /// getDescString - Return a string used to compose global names and labels. |
| 948 | /// |
| 949 | const char *DerivedTypeDesc::getDescString() const { |
| 950 | return "llvm.dbg.derivedtype"; |
| 951 | } |
| 952 | |
| 953 | /// getTypeString - Return a string used to label this descriptor's type. |
| 954 | /// |
| 955 | const char *DerivedTypeDesc::getTypeString() const { |
| 956 | return "llvm.dbg.derivedtype.type"; |
| 957 | } |
| 958 | |
| 959 | #ifndef NDEBUG |
| 960 | void DerivedTypeDesc::dump() { |
| 961 | cerr << getDescString() << " " |
| 962 | << "Version(" << getVersion() << "), " |
| 963 | << "Tag(" << getTag() << "), " |
| 964 | << "Context(" << getContext() << "), " |
| 965 | << "Name(\"" << getName() << "\"), " |
| 966 | << "Size(" << getSize() << "), " |
| 967 | << "File(" << getFile() << "), " |
| 968 | << "Line(" << getLine() << "), " |
| 969 | << "FromType(" << FromType << ")\n"; |
| 970 | } |
| 971 | #endif |
| 972 | |
| 973 | //===----------------------------------------------------------------------===// |
| 974 | |
| 975 | CompositeTypeDesc::CompositeTypeDesc(unsigned T) |
| 976 | : DerivedTypeDesc(T) |
| 977 | , Elements() |
| 978 | {} |
| 979 | |
| 980 | // Implement isa/cast/dyncast. |
| 981 | bool CompositeTypeDesc::classof(const DebugInfoDesc *D) { |
| 982 | unsigned T = D->getTag(); |
| 983 | switch (T) { |
| 984 | case DW_TAG_array_type: |
| 985 | case DW_TAG_structure_type: |
| 986 | case DW_TAG_union_type: |
| 987 | case DW_TAG_enumeration_type: |
| 988 | case DW_TAG_vector_type: |
| 989 | case DW_TAG_subroutine_type: |
| 990 | return true; |
| 991 | default: break; |
| 992 | } |
| 993 | return false; |
| 994 | } |
| 995 | |
| 996 | /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc. |
| 997 | /// |
| 998 | void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 999 | DerivedTypeDesc::ApplyToFields(Visitor); |
| 1000 | |
| 1001 | Visitor->Apply(Elements); |
| 1002 | } |
| 1003 | |
| 1004 | /// getDescString - Return a string used to compose global names and labels. |
| 1005 | /// |
| 1006 | const char *CompositeTypeDesc::getDescString() const { |
| 1007 | return "llvm.dbg.compositetype"; |
| 1008 | } |
| 1009 | |
| 1010 | /// getTypeString - Return a string used to label this descriptor's type. |
| 1011 | /// |
| 1012 | const char *CompositeTypeDesc::getTypeString() const { |
| 1013 | return "llvm.dbg.compositetype.type"; |
| 1014 | } |
| 1015 | |
| 1016 | #ifndef NDEBUG |
| 1017 | void CompositeTypeDesc::dump() { |
| 1018 | cerr << getDescString() << " " |
| 1019 | << "Version(" << getVersion() << "), " |
| 1020 | << "Tag(" << getTag() << "), " |
| 1021 | << "Context(" << getContext() << "), " |
| 1022 | << "Name(\"" << getName() << "\"), " |
| 1023 | << "Size(" << getSize() << "), " |
| 1024 | << "File(" << getFile() << "), " |
| 1025 | << "Line(" << getLine() << "), " |
| 1026 | << "FromType(" << getFromType() << "), " |
| 1027 | << "Elements.size(" << Elements.size() << ")\n"; |
| 1028 | } |
| 1029 | #endif |
| 1030 | |
| 1031 | //===----------------------------------------------------------------------===// |
| 1032 | |
| 1033 | SubrangeDesc::SubrangeDesc() |
| 1034 | : DebugInfoDesc(DW_TAG_subrange_type) |
| 1035 | , Lo(0) |
| 1036 | , Hi(0) |
| 1037 | {} |
| 1038 | |
| 1039 | // Implement isa/cast/dyncast. |
| 1040 | bool SubrangeDesc::classof(const DebugInfoDesc *D) { |
| 1041 | return D->getTag() == DW_TAG_subrange_type; |
| 1042 | } |
| 1043 | |
| 1044 | /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc. |
| 1045 | /// |
| 1046 | void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1047 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1048 | |
| 1049 | Visitor->Apply(Lo); |
| 1050 | Visitor->Apply(Hi); |
| 1051 | } |
| 1052 | |
| 1053 | /// getDescString - Return a string used to compose global names and labels. |
| 1054 | /// |
| 1055 | const char *SubrangeDesc::getDescString() const { |
| 1056 | return "llvm.dbg.subrange"; |
| 1057 | } |
| 1058 | |
| 1059 | /// getTypeString - Return a string used to label this descriptor's type. |
| 1060 | /// |
| 1061 | const char *SubrangeDesc::getTypeString() const { |
| 1062 | return "llvm.dbg.subrange.type"; |
| 1063 | } |
| 1064 | |
| 1065 | #ifndef NDEBUG |
| 1066 | void SubrangeDesc::dump() { |
| 1067 | cerr << getDescString() << " " |
| 1068 | << "Version(" << getVersion() << "), " |
| 1069 | << "Tag(" << getTag() << "), " |
| 1070 | << "Lo(" << Lo << "), " |
| 1071 | << "Hi(" << Hi << ")\n"; |
| 1072 | } |
| 1073 | #endif |
| 1074 | |
| 1075 | //===----------------------------------------------------------------------===// |
| 1076 | |
| 1077 | EnumeratorDesc::EnumeratorDesc() |
| 1078 | : DebugInfoDesc(DW_TAG_enumerator) |
| 1079 | , Name("") |
| 1080 | , Value(0) |
| 1081 | {} |
| 1082 | |
| 1083 | // Implement isa/cast/dyncast. |
| 1084 | bool EnumeratorDesc::classof(const DebugInfoDesc *D) { |
| 1085 | return D->getTag() == DW_TAG_enumerator; |
| 1086 | } |
| 1087 | |
| 1088 | /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc. |
| 1089 | /// |
| 1090 | void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1091 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1092 | |
| 1093 | Visitor->Apply(Name); |
| 1094 | Visitor->Apply(Value); |
| 1095 | } |
| 1096 | |
| 1097 | /// getDescString - Return a string used to compose global names and labels. |
| 1098 | /// |
| 1099 | const char *EnumeratorDesc::getDescString() const { |
| 1100 | return "llvm.dbg.enumerator"; |
| 1101 | } |
| 1102 | |
| 1103 | /// getTypeString - Return a string used to label this descriptor's type. |
| 1104 | /// |
| 1105 | const char *EnumeratorDesc::getTypeString() const { |
| 1106 | return "llvm.dbg.enumerator.type"; |
| 1107 | } |
| 1108 | |
| 1109 | #ifndef NDEBUG |
| 1110 | void EnumeratorDesc::dump() { |
| 1111 | cerr << getDescString() << " " |
| 1112 | << "Version(" << getVersion() << "), " |
| 1113 | << "Tag(" << getTag() << "), " |
| 1114 | << "Name(" << Name << "), " |
| 1115 | << "Value(" << Value << ")\n"; |
| 1116 | } |
| 1117 | #endif |
| 1118 | |
| 1119 | //===----------------------------------------------------------------------===// |
| 1120 | |
| 1121 | VariableDesc::VariableDesc(unsigned T) |
| 1122 | : DebugInfoDesc(T) |
| 1123 | , Context(NULL) |
| 1124 | , Name("") |
| 1125 | , File(NULL) |
| 1126 | , Line(0) |
| 1127 | , TyDesc(0) |
| 1128 | {} |
| 1129 | |
| 1130 | // Implement isa/cast/dyncast. |
| 1131 | bool VariableDesc::classof(const DebugInfoDesc *D) { |
| 1132 | unsigned T = D->getTag(); |
| 1133 | switch (T) { |
| 1134 | case DW_TAG_auto_variable: |
| 1135 | case DW_TAG_arg_variable: |
| 1136 | case DW_TAG_return_variable: |
| 1137 | return true; |
| 1138 | default: break; |
| 1139 | } |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | /// ApplyToFields - Target the visitor to the fields of the VariableDesc. |
| 1144 | /// |
| 1145 | void VariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1146 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1147 | |
| 1148 | Visitor->Apply(Context); |
| 1149 | Visitor->Apply(Name); |
| 1150 | Visitor->Apply(File); |
| 1151 | Visitor->Apply(Line); |
| 1152 | Visitor->Apply(TyDesc); |
| 1153 | } |
| 1154 | |
| 1155 | /// getDescString - Return a string used to compose global names and labels. |
| 1156 | /// |
| 1157 | const char *VariableDesc::getDescString() const { |
| 1158 | return "llvm.dbg.variable"; |
| 1159 | } |
| 1160 | |
| 1161 | /// getTypeString - Return a string used to label this descriptor's type. |
| 1162 | /// |
| 1163 | const char *VariableDesc::getTypeString() const { |
| 1164 | return "llvm.dbg.variable.type"; |
| 1165 | } |
| 1166 | |
| 1167 | #ifndef NDEBUG |
| 1168 | void VariableDesc::dump() { |
| 1169 | cerr << getDescString() << " " |
| 1170 | << "Version(" << getVersion() << "), " |
| 1171 | << "Tag(" << getTag() << "), " |
| 1172 | << "Context(" << Context << "), " |
| 1173 | << "Name(\"" << Name << "\"), " |
| 1174 | << "File(" << File << "), " |
| 1175 | << "Line(" << Line << "), " |
| 1176 | << "TyDesc(" << TyDesc << ")\n"; |
| 1177 | } |
| 1178 | #endif |
| 1179 | |
| 1180 | //===----------------------------------------------------------------------===// |
| 1181 | |
| 1182 | GlobalDesc::GlobalDesc(unsigned T) |
| 1183 | : AnchoredDesc(T) |
| 1184 | , Context(0) |
| 1185 | , Name("") |
| 1186 | , FullName("") |
| 1187 | , LinkageName("") |
| 1188 | , File(NULL) |
| 1189 | , Line(0) |
| 1190 | , TyDesc(NULL) |
| 1191 | , IsStatic(false) |
| 1192 | , IsDefinition(false) |
| 1193 | {} |
| 1194 | |
| 1195 | /// ApplyToFields - Target the visitor to the fields of the global. |
| 1196 | /// |
| 1197 | void GlobalDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1198 | AnchoredDesc::ApplyToFields(Visitor); |
| 1199 | |
| 1200 | Visitor->Apply(Context); |
| 1201 | Visitor->Apply(Name); |
| 1202 | Visitor->Apply(FullName); |
| 1203 | Visitor->Apply(LinkageName); |
| 1204 | Visitor->Apply(File); |
| 1205 | Visitor->Apply(Line); |
| 1206 | Visitor->Apply(TyDesc); |
| 1207 | Visitor->Apply(IsStatic); |
| 1208 | Visitor->Apply(IsDefinition); |
| 1209 | } |
| 1210 | |
| 1211 | //===----------------------------------------------------------------------===// |
| 1212 | |
| 1213 | GlobalVariableDesc::GlobalVariableDesc() |
| 1214 | : GlobalDesc(DW_TAG_variable) |
| 1215 | , Global(NULL) |
| 1216 | {} |
| 1217 | |
| 1218 | // Implement isa/cast/dyncast. |
| 1219 | bool GlobalVariableDesc::classof(const DebugInfoDesc *D) { |
| 1220 | return D->getTag() == DW_TAG_variable; |
| 1221 | } |
| 1222 | |
| 1223 | /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc. |
| 1224 | /// |
| 1225 | void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1226 | GlobalDesc::ApplyToFields(Visitor); |
| 1227 | |
| 1228 | Visitor->Apply(Global); |
| 1229 | } |
| 1230 | |
| 1231 | /// getDescString - Return a string used to compose global names and labels. |
| 1232 | /// |
| 1233 | const char *GlobalVariableDesc::getDescString() const { |
| 1234 | return "llvm.dbg.global_variable"; |
| 1235 | } |
| 1236 | |
| 1237 | /// getTypeString - Return a string used to label this descriptors type. |
| 1238 | /// |
| 1239 | const char *GlobalVariableDesc::getTypeString() const { |
| 1240 | return "llvm.dbg.global_variable.type"; |
| 1241 | } |
| 1242 | |
| 1243 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1244 | /// |
| 1245 | const char *const GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables"; |
| 1246 | const char *GlobalVariableDesc::getAnchorString() const { |
| 1247 | return AnchorString; |
| 1248 | } |
| 1249 | |
| 1250 | #ifndef NDEBUG |
| 1251 | void GlobalVariableDesc::dump() { |
| 1252 | cerr << getDescString() << " " |
| 1253 | << "Version(" << getVersion() << "), " |
| 1254 | << "Tag(" << getTag() << "), " |
| 1255 | << "Anchor(" << getAnchor() << "), " |
| 1256 | << "Name(\"" << getName() << "\"), " |
| 1257 | << "FullName(\"" << getFullName() << "\"), " |
| 1258 | << "LinkageName(\"" << getLinkageName() << "\"), " |
| 1259 | << "File(" << getFile() << ")," |
| 1260 | << "Line(" << getLine() << ")," |
| 1261 | << "Type(" << getType() << "), " |
| 1262 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1263 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " |
| 1264 | << "Global(" << Global << ")\n"; |
| 1265 | } |
| 1266 | #endif |
| 1267 | |
| 1268 | //===----------------------------------------------------------------------===// |
| 1269 | |
| 1270 | SubprogramDesc::SubprogramDesc() |
| 1271 | : GlobalDesc(DW_TAG_subprogram) |
| 1272 | {} |
| 1273 | |
| 1274 | // Implement isa/cast/dyncast. |
| 1275 | bool SubprogramDesc::classof(const DebugInfoDesc *D) { |
| 1276 | return D->getTag() == DW_TAG_subprogram; |
| 1277 | } |
| 1278 | |
| 1279 | /// ApplyToFields - Target the visitor to the fields of the |
| 1280 | /// SubprogramDesc. |
| 1281 | void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1282 | GlobalDesc::ApplyToFields(Visitor); |
| 1283 | } |
| 1284 | |
| 1285 | /// getDescString - Return a string used to compose global names and labels. |
| 1286 | /// |
| 1287 | const char *SubprogramDesc::getDescString() const { |
| 1288 | return "llvm.dbg.subprogram"; |
| 1289 | } |
| 1290 | |
| 1291 | /// getTypeString - Return a string used to label this descriptors type. |
| 1292 | /// |
| 1293 | const char *SubprogramDesc::getTypeString() const { |
| 1294 | return "llvm.dbg.subprogram.type"; |
| 1295 | } |
| 1296 | |
| 1297 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1298 | /// |
| 1299 | const char *const SubprogramDesc::AnchorString = "llvm.dbg.subprograms"; |
| 1300 | const char *SubprogramDesc::getAnchorString() const { |
| 1301 | return AnchorString; |
| 1302 | } |
| 1303 | |
| 1304 | #ifndef NDEBUG |
| 1305 | void SubprogramDesc::dump() { |
| 1306 | cerr << getDescString() << " " |
| 1307 | << "Version(" << getVersion() << "), " |
| 1308 | << "Tag(" << getTag() << "), " |
| 1309 | << "Anchor(" << getAnchor() << "), " |
| 1310 | << "Name(\"" << getName() << "\"), " |
| 1311 | << "FullName(\"" << getFullName() << "\"), " |
| 1312 | << "LinkageName(\"" << getLinkageName() << "\"), " |
| 1313 | << "File(" << getFile() << ")," |
| 1314 | << "Line(" << getLine() << ")," |
| 1315 | << "Type(" << getType() << "), " |
| 1316 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1317 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n"; |
| 1318 | } |
| 1319 | #endif |
| 1320 | |
| 1321 | //===----------------------------------------------------------------------===// |
| 1322 | |
| 1323 | BlockDesc::BlockDesc() |
| 1324 | : DebugInfoDesc(DW_TAG_lexical_block) |
| 1325 | , Context(NULL) |
| 1326 | {} |
| 1327 | |
| 1328 | // Implement isa/cast/dyncast. |
| 1329 | bool BlockDesc::classof(const DebugInfoDesc *D) { |
| 1330 | return D->getTag() == DW_TAG_lexical_block; |
| 1331 | } |
| 1332 | |
| 1333 | /// ApplyToFields - Target the visitor to the fields of the BlockDesc. |
| 1334 | /// |
| 1335 | void BlockDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1336 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1337 | |
| 1338 | Visitor->Apply(Context); |
| 1339 | } |
| 1340 | |
| 1341 | /// getDescString - Return a string used to compose global names and labels. |
| 1342 | /// |
| 1343 | const char *BlockDesc::getDescString() const { |
| 1344 | return "llvm.dbg.block"; |
| 1345 | } |
| 1346 | |
| 1347 | /// getTypeString - Return a string used to label this descriptors type. |
| 1348 | /// |
| 1349 | const char *BlockDesc::getTypeString() const { |
| 1350 | return "llvm.dbg.block.type"; |
| 1351 | } |
| 1352 | |
| 1353 | #ifndef NDEBUG |
| 1354 | void BlockDesc::dump() { |
| 1355 | cerr << getDescString() << " " |
| 1356 | << "Version(" << getVersion() << "), " |
| 1357 | << "Tag(" << getTag() << ")," |
| 1358 | << "Context(" << Context << ")\n"; |
| 1359 | } |
| 1360 | #endif |
| 1361 | |
| 1362 | //===----------------------------------------------------------------------===// |
| 1363 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1364 | DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1365 | return Deserialize(getGlobalVariable(V)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1366 | } |
| 1367 | DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1368 | // Handle NULL. |
| 1369 | if (!GV) return NULL; |
| 1370 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1371 | // Check to see if it has been already deserialized. |
| 1372 | DebugInfoDesc *&Slot = GlobalDescs[GV]; |
| 1373 | if (Slot) return Slot; |
| 1374 | |
| 1375 | // Get the Tag from the global. |
| 1376 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
| 1377 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1378 | // Create an empty instance of the correct sort. |
| 1379 | Slot = DebugInfoDesc::DescFactory(Tag); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1380 | |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1381 | // If not a user defined descriptor. |
| 1382 | if (Slot) { |
| 1383 | // Deserialize the fields. |
| 1384 | DIDeserializeVisitor DRAM(*this, GV); |
| 1385 | DRAM.ApplyToFields(Slot); |
| 1386 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1387 | |
| 1388 | return Slot; |
| 1389 | } |
| 1390 | |
| 1391 | //===----------------------------------------------------------------------===// |
| 1392 | |
| 1393 | /// getStrPtrType - Return a "sbyte *" type. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1394 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1395 | const PointerType *DISerializer::getStrPtrType() { |
| 1396 | // If not already defined. |
| 1397 | if (!StrPtrTy) { |
| 1398 | // Construct the pointer to signed bytes. |
Christopher Lamb | 43ad6b3 | 2007-12-17 01:12:55 +0000 | [diff] [blame] | 1399 | StrPtrTy = PointerType::getUnqual(Type::Int8Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | return StrPtrTy; |
| 1403 | } |
| 1404 | |
| 1405 | /// getEmptyStructPtrType - Return a "{ }*" type. |
| 1406 | /// |
| 1407 | const PointerType *DISerializer::getEmptyStructPtrType() { |
| 1408 | // If not already defined. |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1409 | if (EmptyStructPtrTy) return EmptyStructPtrTy; |
Bill Wendling | e6b6bae | 2008-06-27 00:56:36 +0000 | [diff] [blame] | 1410 | |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1411 | // Construct the pointer to empty structure type. |
Bill Wendling | 4925567 | 2008-07-07 21:41:57 +0000 | [diff] [blame] | 1412 | const StructType *EmptyStructTy = StructType::get(NULL, NULL); |
Bill Wendling | 0ac1b6d | 2008-06-27 01:32:08 +0000 | [diff] [blame] | 1413 | |
| 1414 | // Construct the pointer to empty structure type. |
| 1415 | EmptyStructPtrTy = PointerType::getUnqual(EmptyStructTy); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1416 | return EmptyStructPtrTy; |
| 1417 | } |
| 1418 | |
| 1419 | /// getTagType - Return the type describing the specified descriptor (via tag.) |
| 1420 | /// |
| 1421 | const StructType *DISerializer::getTagType(DebugInfoDesc *DD) { |
| 1422 | // Attempt to get the previously defined type. |
| 1423 | StructType *&Ty = TagTypes[DD->getTag()]; |
| 1424 | |
| 1425 | // If not already defined. |
| 1426 | if (!Ty) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1427 | // Set up fields vector. |
| 1428 | std::vector<const Type*> Fields; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1429 | // Get types of fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1430 | DIGetTypesVisitor GTAM(*this, Fields); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1431 | GTAM.ApplyToFields(DD); |
| 1432 | |
| 1433 | // Construct structured type. |
| 1434 | Ty = StructType::get(Fields); |
| 1435 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1436 | // Register type name with module. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1437 | M->addTypeName(DD->getTypeString(), Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | return Ty; |
| 1441 | } |
| 1442 | |
| 1443 | /// getString - Construct the string as constant string global. |
| 1444 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1445 | Constant *DISerializer::getString(const std::string &String) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1446 | // Check string cache for previous edition. |
Bill Wendling | 667a68b | 2008-07-07 20:59:31 +0000 | [diff] [blame] | 1447 | Constant *&Slot = StringCache[String]; |
Bill Wendling | e6b6bae | 2008-06-27 00:56:36 +0000 | [diff] [blame] | 1448 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1449 | // Return Constant if previously defined. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1450 | if (Slot) return Slot; |
Bill Wendling | e6b6bae | 2008-06-27 00:56:36 +0000 | [diff] [blame] | 1451 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1452 | // If empty string then use a sbyte* null instead. |
| 1453 | if (String.empty()) { |
| 1454 | Slot = ConstantPointerNull::get(getStrPtrType()); |
| 1455 | } else { |
| 1456 | // Construct string as an llvm constant. |
| 1457 | Constant *ConstStr = ConstantArray::get(String); |
Bill Wendling | e6b6bae | 2008-06-27 00:56:36 +0000 | [diff] [blame] | 1458 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1459 | // Otherwise create and return a new string global. |
| 1460 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 1461 | GlobalVariable::InternalLinkage, |
Devang Patel | 1e4c23a | 2007-05-11 23:14:43 +0000 | [diff] [blame] | 1462 | ConstStr, ".str", M); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1463 | StrGV->setSection("llvm.metadata"); |
Bill Wendling | e6b6bae | 2008-06-27 00:56:36 +0000 | [diff] [blame] | 1464 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1465 | // Convert to generic string pointer. |
Reid Spencer | 15f46d6 | 2006-12-12 01:17:41 +0000 | [diff] [blame] | 1466 | Slot = ConstantExpr::getBitCast(StrGV, getStrPtrType()); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1467 | } |
Bill Wendling | e6b6bae | 2008-06-27 00:56:36 +0000 | [diff] [blame] | 1468 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1469 | return Slot; |
| 1470 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | /// Serialize - Recursively cast the specified descriptor into a GlobalVariable |
| 1474 | /// so that it can be serialized to a .bc or .ll file. |
| 1475 | GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) { |
| 1476 | // Check if the DebugInfoDesc is already in the map. |
| 1477 | GlobalVariable *&Slot = DescGlobals[DD]; |
| 1478 | |
| 1479 | // See if DebugInfoDesc exists, if so return prior GlobalVariable. |
| 1480 | if (Slot) return Slot; |
| 1481 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1482 | // Get the type associated with the Tag. |
| 1483 | const StructType *Ty = getTagType(DD); |
| 1484 | |
| 1485 | // Create the GlobalVariable early to prevent infinite recursion. |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1486 | GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(), |
| 1487 | NULL, DD->getDescString(), M); |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 1488 | GV->setSection("llvm.metadata"); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1489 | |
| 1490 | // Insert new GlobalVariable in DescGlobals map. |
| 1491 | Slot = GV; |
| 1492 | |
| 1493 | // Set up elements vector |
| 1494 | std::vector<Constant*> Elements; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1495 | // Add fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1496 | DISerializeVisitor SRAM(*this, Elements); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1497 | SRAM.ApplyToFields(DD); |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1498 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1499 | // Set the globals initializer. |
| 1500 | GV->setInitializer(ConstantStruct::get(Ty, Elements)); |
| 1501 | |
| 1502 | return GV; |
| 1503 | } |
| 1504 | |
Devang Patel | 962e075 | 2007-11-30 00:51:33 +0000 | [diff] [blame] | 1505 | /// addDescriptor - Directly connect DD with existing GV. |
| 1506 | void DISerializer::addDescriptor(DebugInfoDesc *DD, |
| 1507 | GlobalVariable *GV) { |
| 1508 | DescGlobals[DD] = GV; |
| 1509 | } |
| 1510 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1511 | //===----------------------------------------------------------------------===// |
| 1512 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1513 | /// Verify - Return true if the GlobalVariable appears to be a valid |
| 1514 | /// serialization of a DebugInfoDesc. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1515 | bool DIVerifier::Verify(Value *V) { |
Jim Laskey | aaa80eb | 2006-03-28 01:30:18 +0000 | [diff] [blame] | 1516 | return !V || Verify(getGlobalVariable(V)); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1517 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1518 | bool DIVerifier::Verify(GlobalVariable *GV) { |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1519 | // NULLs are valid. |
| 1520 | if (!GV) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1521 | |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1522 | // Check prior validity. |
| 1523 | unsigned &ValiditySlot = Validity[GV]; |
| 1524 | |
| 1525 | // If visited before then use old state. |
| 1526 | if (ValiditySlot) return ValiditySlot == Valid; |
| 1527 | |
| 1528 | // Assume validity for the time being (recursion.) |
| 1529 | ValiditySlot = Valid; |
Jim Laskey | a8299de | 2006-03-27 01:51:47 +0000 | [diff] [blame] | 1530 | |
| 1531 | // Make sure the global is internal or link once (anchor.) |
| 1532 | if (GV->getLinkage() != GlobalValue::InternalLinkage && |
| 1533 | GV->getLinkage() != GlobalValue::LinkOnceLinkage) { |
| 1534 | ValiditySlot = Invalid; |
| 1535 | return false; |
| 1536 | } |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1537 | |
Jim Laskey | 2bbff6d | 2006-11-30 18:29:23 +0000 | [diff] [blame] | 1538 | // Get the Tag. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1539 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1540 | |
| 1541 | // Check for user defined descriptors. |
Jim Laskey | 2bbff6d | 2006-11-30 18:29:23 +0000 | [diff] [blame] | 1542 | if (Tag == DW_TAG_invalid) { |
| 1543 | ValiditySlot = Valid; |
| 1544 | return true; |
| 1545 | } |
| 1546 | |
| 1547 | // Get the Version. |
| 1548 | unsigned Version = DebugInfoDesc::VersionFromGlobal(GV); |
| 1549 | |
| 1550 | // Check for version mismatch. |
| 1551 | if (Version != LLVMDebugVersion) { |
| 1552 | ValiditySlot = Invalid; |
| 1553 | return false; |
| 1554 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1555 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1556 | // Construct an empty DebugInfoDesc. |
| 1557 | DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag); |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1558 | |
| 1559 | // Allow for user defined descriptors. |
| 1560 | if (!DD) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1561 | |
| 1562 | // Get the initializer constant. |
| 1563 | ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer()); |
| 1564 | |
| 1565 | // Get the operand count. |
| 1566 | unsigned N = CI->getNumOperands(); |
| 1567 | |
| 1568 | // Get the field count. |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1569 | unsigned &CountSlot = Counts[Tag]; |
Bill Wendling | 3e30cbb | 2008-07-09 06:02:33 +0000 | [diff] [blame] | 1570 | |
| 1571 | if (!CountSlot) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1572 | // Check the operand count to the field count |
Bill Wendling | 3e30cbb | 2008-07-09 06:02:33 +0000 | [diff] [blame] | 1573 | CountSlot = CountFields(DD); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1574 | |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1575 | // Field count must be at most equal operand count. |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1576 | if (CountSlot > N) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1577 | delete DD; |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1578 | ValiditySlot = Invalid; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1579 | return false; |
| 1580 | } |
| 1581 | |
| 1582 | // Check each field for valid type. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1583 | DIVerifyVisitor VRAM(*this, GV); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1584 | VRAM.ApplyToFields(DD); |
| 1585 | |
| 1586 | // Release empty DebugInfoDesc. |
| 1587 | delete DD; |
| 1588 | |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1589 | // If fields are not valid. |
| 1590 | if (!VRAM.isValid()) { |
| 1591 | ValiditySlot = Invalid; |
| 1592 | return false; |
| 1593 | } |
| 1594 | |
| 1595 | return true; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1598 | /// isVerified - Return true if the specified GV has already been |
| 1599 | /// verified as a debug information descriptor. |
| 1600 | bool DIVerifier::isVerified(GlobalVariable *GV) { |
| 1601 | unsigned &ValiditySlot = Validity[GV]; |
| 1602 | if (ValiditySlot) return ValiditySlot == Valid; |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1606 | //===----------------------------------------------------------------------===// |
| 1607 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1608 | DebugScope::~DebugScope() { |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1609 | for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i]; |
| 1610 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j]; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | //===----------------------------------------------------------------------===// |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1614 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1615 | MachineModuleInfo::MachineModuleInfo() |
Dan Gohman | ae73dc1 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 1616 | : ImmutablePass(&ID) |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 1617 | , DR() |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1618 | , VR() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1619 | , CompileUnits() |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1620 | , Directories() |
| 1621 | , SourceFiles() |
| 1622 | , Lines() |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 1623 | , LabelIDList() |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1624 | , ScopeMap() |
| 1625 | , RootScope(NULL) |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1626 | , FrameMoves() |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1627 | , LandingPads() |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1628 | , Personalities() |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1629 | , CallsEHReturn(0) |
| 1630 | , CallsUnwindInit(0) |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1631 | { |
| 1632 | // Always emit "no personality" info |
| 1633 | Personalities.push_back(NULL); |
| 1634 | } |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1635 | MachineModuleInfo::~MachineModuleInfo() { |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1636 | |
| 1637 | } |
| 1638 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1639 | /// doInitialization - Initialize the state for a new module. |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1640 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1641 | bool MachineModuleInfo::doInitialization() { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1642 | return false; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1645 | /// doFinalization - Tear down the state after completion of a module. |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1646 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1647 | bool MachineModuleInfo::doFinalization() { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1648 | return false; |
| 1649 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1650 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1651 | /// BeginFunction - Begin gathering function meta information. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1652 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1653 | void MachineModuleInfo::BeginFunction(MachineFunction *MF) { |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1654 | // Coming soon. |
| 1655 | } |
| 1656 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1657 | /// EndFunction - Discard function meta information. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1658 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1659 | void MachineModuleInfo::EndFunction() { |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1660 | // Clean up scope information. |
| 1661 | if (RootScope) { |
| 1662 | delete RootScope; |
| 1663 | ScopeMap.clear(); |
| 1664 | RootScope = NULL; |
| 1665 | } |
| 1666 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1667 | // Clean up line info. |
| 1668 | Lines.clear(); |
| 1669 | |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1670 | // Clean up frame info. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1671 | FrameMoves.clear(); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1672 | |
| 1673 | // Clean up exception info. |
| 1674 | LandingPads.clear(); |
| 1675 | TypeInfos.clear(); |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1676 | FilterIds.clear(); |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 1677 | FilterEnds.clear(); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 1678 | CallsEHReturn = 0; |
| 1679 | CallsUnwindInit = 0; |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1682 | /// getDescFor - Convert a Value to a debug information descriptor. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1683 | /// |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1684 | // FIXME - use new Value type when available. |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1685 | DebugInfoDesc *MachineModuleInfo::getDescFor(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1686 | return DR.Deserialize(V); |
| 1687 | } |
| 1688 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1689 | /// AnalyzeModule - Scan the module for global debug information. |
| 1690 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1691 | void MachineModuleInfo::AnalyzeModule(Module &M) { |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1692 | SetupCompileUnits(M); |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 1693 | |
| 1694 | // Insert functions in the llvm.used array into UsedFunctions. |
| 1695 | GlobalVariable *GV = M.getGlobalVariable("llvm.used"); |
| 1696 | if (!GV || !GV->hasInitializer()) return; |
| 1697 | |
| 1698 | // Should be an array of 'i8*'. |
| 1699 | ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 1700 | if (InitList == 0) return; |
| 1701 | |
| 1702 | for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) { |
| 1703 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(InitList->getOperand(i))) |
| 1704 | if (CE->getOpcode() == Instruction::BitCast) |
| 1705 | if (Function *F = dyn_cast<Function>(CE->getOperand(0))) |
| 1706 | UsedFunctions.insert(F); |
| 1707 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /// SetupCompileUnits - Set up the unique vector of compile units. |
| 1711 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1712 | void MachineModuleInfo::SetupCompileUnits(Module &M) { |
Bill Wendling | c04f465 | 2008-07-03 23:13:02 +0000 | [diff] [blame] | 1713 | std::vector<CompileUnitDesc *> CU; |
| 1714 | getAnchoredDescriptors<CompileUnitDesc>(M, CU); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1715 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1716 | for (unsigned i = 0, N = CU.size(); i < N; i++) { |
| 1717 | CompileUnits.insert(CU[i]); |
| 1718 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1721 | /// getCompileUnits - Return a vector of debug compile units. |
| 1722 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1723 | const UniqueVector<CompileUnitDesc *> MachineModuleInfo::getCompileUnits()const{ |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1724 | return CompileUnits; |
| 1725 | } |
| 1726 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1727 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 1728 | /// named GlobalVariable. |
Bill Wendling | c04f465 | 2008-07-03 23:13:02 +0000 | [diff] [blame] | 1729 | void |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1730 | MachineModuleInfo::getGlobalVariablesUsing(Module &M, |
Bill Wendling | c04f465 | 2008-07-03 23:13:02 +0000 | [diff] [blame] | 1731 | const std::string &RootName, |
| 1732 | std::vector<GlobalVariable*>&Result){ |
| 1733 | return ::getGlobalVariablesUsing(M, RootName, Result); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1734 | } |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1735 | |
Evan Cheng | a647c92 | 2008-02-01 02:05:57 +0000 | [diff] [blame] | 1736 | /// RecordSourceLine - Records location information and associates it with a |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1737 | /// debug label. Returns a unique label ID used to generate a label and |
| 1738 | /// provide correspondence to the source line list. |
Evan Cheng | a647c92 | 2008-02-01 02:05:57 +0000 | [diff] [blame] | 1739 | unsigned MachineModuleInfo::RecordSourceLine(unsigned Line, unsigned Column, |
| 1740 | unsigned Source) { |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1741 | unsigned ID = NextLabelID(); |
Chris Lattner | 8466b21 | 2006-10-17 22:06:46 +0000 | [diff] [blame] | 1742 | Lines.push_back(SourceLineInfo(Line, Column, Source, ID)); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1743 | return ID; |
| 1744 | } |
| 1745 | |
| 1746 | /// RecordSource - Register a source file with debug info. Returns an source |
| 1747 | /// ID. |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1748 | unsigned MachineModuleInfo::RecordSource(const std::string &Directory, |
| 1749 | const std::string &Source) { |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1750 | unsigned DirectoryID = Directories.insert(Directory); |
| 1751 | return SourceFiles.insert(SourceFileInfo(DirectoryID, Source)); |
| 1752 | } |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1753 | unsigned MachineModuleInfo::RecordSource(const CompileUnitDesc *CompileUnit) { |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1754 | return RecordSource(CompileUnit->getDirectory(), |
| 1755 | CompileUnit->getFileName()); |
| 1756 | } |
| 1757 | |
| 1758 | /// RecordRegionStart - Indicate the start of a region. |
| 1759 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1760 | unsigned MachineModuleInfo::RecordRegionStart(Value *V) { |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1761 | // FIXME - need to be able to handle split scopes because of bb cloning. |
| 1762 | DebugInfoDesc *ScopeDesc = DR.Deserialize(V); |
| 1763 | DebugScope *Scope = getOrCreateScope(ScopeDesc); |
| 1764 | unsigned ID = NextLabelID(); |
| 1765 | if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID); |
| 1766 | return ID; |
| 1767 | } |
| 1768 | |
| 1769 | /// RecordRegionEnd - Indicate the end of a region. |
| 1770 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1771 | unsigned MachineModuleInfo::RecordRegionEnd(Value *V) { |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1772 | // FIXME - need to be able to handle split scopes because of bb cloning. |
| 1773 | DebugInfoDesc *ScopeDesc = DR.Deserialize(V); |
| 1774 | DebugScope *Scope = getOrCreateScope(ScopeDesc); |
| 1775 | unsigned ID = NextLabelID(); |
| 1776 | Scope->setEndLabelID(ID); |
| 1777 | return ID; |
| 1778 | } |
| 1779 | |
| 1780 | /// RecordVariable - Indicate the declaration of a local variable. |
| 1781 | /// |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 1782 | void MachineModuleInfo::RecordVariable(GlobalValue *GV, unsigned FrameIndex) { |
| 1783 | VariableDesc *VD = cast<VariableDesc>(DR.Deserialize(GV)); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1784 | DebugScope *Scope = getOrCreateScope(VD->getContext()); |
| 1785 | DebugVariable *DV = new DebugVariable(VD, FrameIndex); |
| 1786 | Scope->AddVariable(DV); |
| 1787 | } |
| 1788 | |
| 1789 | /// getOrCreateScope - Returns the scope associated with the given descriptor. |
| 1790 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1791 | DebugScope *MachineModuleInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) { |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1792 | DebugScope *&Slot = ScopeMap[ScopeDesc]; |
| 1793 | if (!Slot) { |
| 1794 | // FIXME - breaks down when the context is an inlined function. |
| 1795 | DebugInfoDesc *ParentDesc = NULL; |
| 1796 | if (BlockDesc *Block = dyn_cast<BlockDesc>(ScopeDesc)) { |
| 1797 | ParentDesc = Block->getContext(); |
| 1798 | } |
| 1799 | DebugScope *Parent = ParentDesc ? getOrCreateScope(ParentDesc) : NULL; |
| 1800 | Slot = new DebugScope(Parent, ScopeDesc); |
| 1801 | if (Parent) { |
| 1802 | Parent->AddScope(Slot); |
| 1803 | } else if (RootScope) { |
| 1804 | // FIXME - Add inlined function scopes to the root so we can delete |
| 1805 | // them later. Long term, handle inlined functions properly. |
| 1806 | RootScope->AddScope(Slot); |
| 1807 | } else { |
| 1808 | // First function is top level function. |
| 1809 | RootScope = Slot; |
| 1810 | } |
| 1811 | } |
| 1812 | return Slot; |
| 1813 | } |
| 1814 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1815 | //===-EH-------------------------------------------------------------------===// |
| 1816 | |
| 1817 | /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the |
| 1818 | /// specified MachineBasicBlock. |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1819 | LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo |
| 1820 | (MachineBasicBlock *LandingPad) { |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1821 | unsigned N = LandingPads.size(); |
| 1822 | for (unsigned i = 0; i < N; ++i) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1823 | LandingPadInfo &LP = LandingPads[i]; |
| 1824 | if (LP.LandingPadBlock == LandingPad) |
| 1825 | return LP; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | LandingPads.push_back(LandingPadInfo(LandingPad)); |
| 1829 | return LandingPads[N]; |
| 1830 | } |
| 1831 | |
| 1832 | /// addInvoke - Provide the begin and end labels of an invoke style call and |
| 1833 | /// associate it with a try landing pad block. |
| 1834 | void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad, |
| 1835 | unsigned BeginLabel, unsigned EndLabel) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1836 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 1837 | LP.BeginLabels.push_back(BeginLabel); |
| 1838 | LP.EndLabels.push_back(EndLabel); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /// addLandingPad - Provide the label of a try LandingPad block. |
| 1842 | /// |
| 1843 | unsigned MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) { |
| 1844 | unsigned LandingPadLabel = NextLabelID(); |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1845 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 1846 | LP.LandingPadLabel = LandingPadLabel; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1847 | return LandingPadLabel; |
| 1848 | } |
| 1849 | |
| 1850 | /// addPersonality - Provide the personality function for the exception |
| 1851 | /// information. |
| 1852 | void MachineModuleInfo::addPersonality(MachineBasicBlock *LandingPad, |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1853 | Function *Personality) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1854 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1855 | LP.Personality = Personality; |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 1856 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1857 | for (unsigned i = 0; i < Personalities.size(); ++i) |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1858 | if (Personalities[i] == Personality) |
| 1859 | return; |
| 1860 | |
| 1861 | Personalities.push_back(Personality); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. |
| 1865 | /// |
| 1866 | void MachineModuleInfo::addCatchTypeInfo(MachineBasicBlock *LandingPad, |
| 1867 | std::vector<GlobalVariable *> &TyInfo) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1868 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1869 | for (unsigned N = TyInfo.size(); N; --N) |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1870 | LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1])); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1871 | } |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1872 | |
| 1873 | /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad. |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1874 | /// |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1875 | void MachineModuleInfo::addFilterTypeInfo(MachineBasicBlock *LandingPad, |
| 1876 | std::vector<GlobalVariable *> &TyInfo) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1877 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Bill Wendling | 4925567 | 2008-07-07 21:41:57 +0000 | [diff] [blame] | 1878 | std::vector<unsigned> IdsInFilter(TyInfo.size()); |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1879 | for (unsigned I = 0, E = TyInfo.size(); I != E; ++I) |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1880 | IdsInFilter[I] = getTypeIDFor(TyInfo[I]); |
| 1881 | LP.TypeIds.push_back(getFilterIDFor(IdsInFilter)); |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
Duncan Sands | 6590b04 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 1884 | /// addCleanup - Add a cleanup action for a landing pad. |
| 1885 | /// |
| 1886 | void MachineModuleInfo::addCleanup(MachineBasicBlock *LandingPad) { |
| 1887 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 1888 | LP.TypeIds.push_back(0); |
| 1889 | } |
| 1890 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1891 | /// TidyLandingPads - Remap landing pad labels and remove any deleted landing |
| 1892 | /// pads. |
| 1893 | void MachineModuleInfo::TidyLandingPads() { |
| 1894 | for (unsigned i = 0; i != LandingPads.size(); ) { |
| 1895 | LandingPadInfo &LandingPad = LandingPads[i]; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1896 | LandingPad.LandingPadLabel = MappedLabel(LandingPad.LandingPadLabel); |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 1897 | |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 1898 | // Special case: we *should* emit LPs with null LP MBB. This indicates |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 1899 | // "nounwind" case. |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 1900 | if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) { |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1901 | LandingPads.erase(LandingPads.begin() + i); |
| 1902 | continue; |
| 1903 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 1904 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1905 | for (unsigned j=0; j != LandingPads[i].BeginLabels.size(); ) { |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 1906 | unsigned BeginLabel = MappedLabel(LandingPad.BeginLabels[j]); |
| 1907 | unsigned EndLabel = MappedLabel(LandingPad.EndLabels[j]); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 1908 | |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 1909 | if (!BeginLabel || !EndLabel) { |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 1910 | LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j); |
| 1911 | LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j); |
| 1912 | continue; |
| 1913 | } |
| 1914 | |
| 1915 | LandingPad.BeginLabels[j] = BeginLabel; |
| 1916 | LandingPad.EndLabels[j] = EndLabel; |
| 1917 | ++j; |
| 1918 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 1919 | |
| 1920 | // Remove landing pads with no try-ranges. |
Dan Gohman | 3035959 | 2008-01-29 13:02:09 +0000 | [diff] [blame] | 1921 | if (LandingPads[i].BeginLabels.empty()) { |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 1922 | LandingPads.erase(LandingPads.begin() + i); |
| 1923 | continue; |
| 1924 | } |
| 1925 | |
| 1926 | // If there is no landing pad, ensure that the list of typeids is empty. |
| 1927 | // If the only typeid is a cleanup, this is the same as having no typeids. |
| 1928 | if (!LandingPad.LandingPadBlock || |
| 1929 | (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0])) |
| 1930 | LandingPad.TypeIds.clear(); |
| 1931 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1932 | ++i; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | /// getTypeIDFor - Return the type id for the specified typeinfo. This is |
| 1937 | /// function wide. |
| 1938 | unsigned MachineModuleInfo::getTypeIDFor(GlobalVariable *TI) { |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1939 | for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i) |
| 1940 | if (TypeInfos[i] == TI) return i + 1; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1941 | |
| 1942 | TypeInfos.push_back(TI); |
| 1943 | return TypeInfos.size(); |
| 1944 | } |
| 1945 | |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1946 | /// getFilterIDFor - Return the filter id for the specified typeinfos. This is |
| 1947 | /// function wide. |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1948 | int MachineModuleInfo::getFilterIDFor(std::vector<unsigned> &TyIds) { |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 1949 | // If the new filter coincides with the tail of an existing filter, then |
| 1950 | // re-use the existing filter. Folding filters more than this requires |
| 1951 | // re-ordering filters and/or their elements - probably not worth it. |
| 1952 | for (std::vector<unsigned>::iterator I = FilterEnds.begin(), |
| 1953 | E = FilterEnds.end(); I != E; ++I) { |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1954 | unsigned i = *I, j = TyIds.size(); |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 1955 | |
| 1956 | while (i && j) |
| 1957 | if (FilterIds[--i] != TyIds[--j]) |
| 1958 | goto try_next; |
| 1959 | |
| 1960 | if (!j) |
| 1961 | // The new filter coincides with range [i, end) of the existing filter. |
| 1962 | return -(1 + i); |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1963 | |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 1964 | try_next:; |
| 1965 | } |
| 1966 | |
| 1967 | // Add the new filter. |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1968 | int FilterID = -(1 + FilterIds.size()); |
| 1969 | FilterIds.reserve(FilterIds.size() + TyIds.size() + 1); |
| 1970 | for (unsigned I = 0, N = TyIds.size(); I != N; ++I) |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1971 | FilterIds.push_back(TyIds[I]); |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 1972 | FilterEnds.push_back(FilterIds.size()); |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 1973 | FilterIds.push_back(0); // terminator |
| 1974 | return FilterID; |
| 1975 | } |
| 1976 | |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1977 | /// getPersonality - Return the personality function for the current function. |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1978 | Function *MachineModuleInfo::getPersonality() const { |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 1979 | // FIXME: Until PR1414 will be fixed, we're using 1 personality function per |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1980 | // function |
| 1981 | return !LandingPads.empty() ? LandingPads[0].Personality : NULL; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1984 | /// getPersonalityIndex - Return unique index for current personality |
| 1985 | /// function. NULL personality function should always get zero index. |
| 1986 | unsigned MachineModuleInfo::getPersonalityIndex() const { |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 1987 | const Function* Personality = NULL; |
| 1988 | |
| 1989 | // Scan landing pads. If there is at least one non-NULL personality - use it. |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1990 | for (unsigned i = 0; i != LandingPads.size(); ++i) |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 1991 | if (LandingPads[i].Personality) { |
| 1992 | Personality = LandingPads[i].Personality; |
| 1993 | break; |
| 1994 | } |
| 1995 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1996 | for (unsigned i = 0; i < Personalities.size(); ++i) { |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 1997 | if (Personalities[i] == Personality) |
| 1998 | return i; |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 1999 | } |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 2000 | |
| 2001 | // This should never happen |
| 2002 | assert(0 && "Personality function should be set!"); |
| 2003 | return 0; |
| 2004 | } |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 2005 | |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2006 | //===----------------------------------------------------------------------===// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 2007 | /// DebugLabelFolding pass - This pass prunes out redundant labels. This allows |
| 2008 | /// a info consumer to determine if the range of two labels is empty, by seeing |
| 2009 | /// if the labels map to the same reduced label. |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2010 | |
| 2011 | namespace llvm { |
| 2012 | |
| 2013 | struct DebugLabelFolder : public MachineFunctionPass { |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 2014 | static char ID; |
Dan Gohman | ae73dc1 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 2015 | DebugLabelFolder() : MachineFunctionPass(&ID) {} |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 2016 | |
Evan Cheng | bbeeb2a | 2008-09-22 20:58:04 +0000 | [diff] [blame] | 2017 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Evan Cheng | 8b56a90 | 2008-09-22 22:21:38 +0000 | [diff] [blame] | 2018 | AU.addPreservedID(MachineLoopInfoID); |
| 2019 | AU.addPreservedID(MachineDominatorsID); |
Evan Cheng | bbeeb2a | 2008-09-22 20:58:04 +0000 | [diff] [blame] | 2020 | MachineFunctionPass::getAnalysisUsage(AU); |
| 2021 | } |
| 2022 | |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2023 | virtual bool runOnMachineFunction(MachineFunction &MF); |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 2024 | virtual const char *getPassName() const { return "Label Folder"; } |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2025 | }; |
| 2026 | |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 2027 | char DebugLabelFolder::ID = 0; |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 2028 | |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2029 | bool DebugLabelFolder::runOnMachineFunction(MachineFunction &MF) { |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 2030 | // Get machine module info. |
| 2031 | MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>(); |
| 2032 | if (!MMI) return false; |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2033 | |
| 2034 | // Track if change is made. |
| 2035 | bool MadeChange = false; |
| 2036 | // No prior label to begin. |
| 2037 | unsigned PriorLabel = 0; |
| 2038 | |
| 2039 | // Iterate through basic blocks. |
| 2040 | for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); |
| 2041 | BB != E; ++BB) { |
| 2042 | // Iterate through instructions. |
| 2043 | for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 2044 | // Is it a label. |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 2045 | if (I->isDebugLabel()) { |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2046 | // The label ID # is always operand #0, an immediate. |
| 2047 | unsigned NextLabel = I->getOperand(0).getImm(); |
| 2048 | |
| 2049 | // If there was an immediate prior label. |
| 2050 | if (PriorLabel) { |
| 2051 | // Remap the current label to prior label. |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 2052 | MMI->RemapLabel(NextLabel, PriorLabel); |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2053 | // Delete the current label. |
| 2054 | I = BB->erase(I); |
| 2055 | // Indicate a change has been made. |
| 2056 | MadeChange = true; |
| 2057 | continue; |
| 2058 | } else { |
| 2059 | // Start a new round. |
| 2060 | PriorLabel = NextLabel; |
| 2061 | } |
| 2062 | } else { |
| 2063 | // No consecutive labels. |
| 2064 | PriorLabel = 0; |
| 2065 | } |
| 2066 | |
| 2067 | ++I; |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | return MadeChange; |
| 2072 | } |
| 2073 | |
| 2074 | FunctionPass *createDebugLabelFoldingPass() { return new DebugLabelFolder(); } |
| 2075 | |
| 2076 | } |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 2077 | |