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