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