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