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