Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 1 | //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a bunch of datatypes that are useful for creating and |
| 11 | // walking debug info in LLVM IR form. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Evan Cheng | 891415b | 2009-01-26 07:31:20 +0000 | [diff] [blame] | 15 | #ifndef LLVM_ANALYSIS_DEBUGINFO_H |
| 16 | #define LLVM_ANALYSIS_DEBUGINFO_H |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 17 | |
| 18 | #include "llvm/ADT/StringMap.h" |
| 19 | #include "llvm/ADT/DenseMap.h" |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | class BasicBlock; |
| 24 | class Constant; |
| 25 | class Function; |
| 26 | class GlobalVariable; |
| 27 | class Module; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 28 | class Type; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 29 | class Value; |
Cedric Venet | aff9c27 | 2009-02-14 16:06:42 +0000 | [diff] [blame^] | 30 | struct DbgStopPointInst; |
| 31 | struct DbgDeclareInst; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 32 | class Instruction; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 33 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 34 | class DIDescriptor { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 35 | protected: |
| 36 | GlobalVariable *GV; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 37 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 38 | /// DIDescriptor constructor. If the specified GV is non-null, this checks |
| 39 | /// to make sure that the tag in the descriptor matches 'RequiredTag'. If |
| 40 | /// not, the debug info is corrupt and we ignore it. |
| 41 | DIDescriptor(GlobalVariable *GV, unsigned RequiredTag); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 42 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 43 | std::string getStringField(unsigned Elt) const; |
| 44 | unsigned getUnsignedField(unsigned Elt) const { |
| 45 | return (unsigned)getUInt64Field(Elt); |
| 46 | } |
| 47 | uint64_t getUInt64Field(unsigned Elt) const; |
| 48 | DIDescriptor getDescriptorField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 49 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 50 | template <typename DescTy> |
| 51 | DescTy getFieldAs(unsigned Elt) const { |
Torok Edwin | b07fbd9 | 2008-12-13 08:25:29 +0000 | [diff] [blame] | 52 | return DescTy(getDescriptorField(Elt).getGV()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 53 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 54 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 55 | GlobalVariable *getGlobalVariableField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 56 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 57 | public: |
| 58 | explicit DIDescriptor() : GV(0) {} |
| 59 | explicit DIDescriptor(GlobalVariable *gv) : GV(gv) {} |
| 60 | |
| 61 | bool isNull() const { return GV == 0; } |
| 62 | |
| 63 | GlobalVariable *getGV() const { return GV; } |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 64 | |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 65 | unsigned getVersion() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 66 | return getUnsignedField(0) & LLVMDebugVersionMask; |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 67 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 68 | |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 69 | unsigned getTag() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 70 | return getUnsignedField(0) & ~LLVMDebugVersionMask; |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 71 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 72 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 73 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 74 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 75 | /// DIAnchor - A wrapper for various anchor descriptors. |
| 76 | class DIAnchor : public DIDescriptor { |
| 77 | public: |
| 78 | explicit DIAnchor(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 79 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 80 | unsigned getAnchorTag() const { return getUnsignedField(1); } |
| 81 | }; |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 82 | |
| 83 | /// DISubrange - This is used to represent ranges, for array bounds. |
| 84 | class DISubrange : public DIDescriptor { |
| 85 | public: |
| 86 | explicit DISubrange(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 87 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 88 | int64_t getLo() const { return (int64_t)getUInt64Field(1); } |
| 89 | int64_t getHi() const { return (int64_t)getUInt64Field(2); } |
| 90 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 91 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 92 | /// DIArray - This descriptor holds an array of descriptors. |
| 93 | class DIArray : public DIDescriptor { |
| 94 | public: |
| 95 | explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 96 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 97 | unsigned getNumElements() const; |
Devang Patel | a22d57d | 2009-01-05 19:55:07 +0000 | [diff] [blame] | 98 | DIDescriptor getElement(unsigned Idx) const { |
| 99 | return getDescriptorField(Idx); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 100 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 101 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 102 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 103 | /// DICompileUnit - A wrapper for a compile unit. |
| 104 | class DICompileUnit : public DIDescriptor { |
| 105 | public: |
| 106 | explicit DICompileUnit(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 107 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 108 | unsigned getLanguage() const { return getUnsignedField(2); } |
| 109 | std::string getFilename() const { return getStringField(3); } |
| 110 | std::string getDirectory() const { return getStringField(4); } |
| 111 | std::string getProducer() const { return getStringField(5); } |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 112 | |
| 113 | /// isMain - Each input file is encoded as a separate compile unit in LLVM |
| 114 | /// debugging information output. However, many target specific tool chains |
| 115 | /// prefer to encode only one compile unit in an object file. In this |
| 116 | /// situation, the LLVM code generator will include debugging information |
| 117 | /// entities in the compile unit that is marked as main compile unit. The |
| 118 | /// code generator accepts maximum one main compile unit per module. If a |
| 119 | /// module does not contain any main compile unit then the code generator |
| 120 | /// will emit multiple compile units in the output object file. |
| 121 | bool isMain() const { return getUnsignedField(6); } |
| 122 | bool isOptimized() const { return getUnsignedField(7); } |
| 123 | std::string getFlags() const { return getStringField(8); } |
Devang Patel | ce31b02 | 2009-01-20 18:13:03 +0000 | [diff] [blame] | 124 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 125 | /// Verify - Verify that a compile unit is well formed. |
| 126 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 127 | |
| 128 | /// dump - print compile unit. |
| 129 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). |
| 133 | /// FIXME: it seems strange that this doesn't have either a reference to the |
| 134 | /// type/precision or a file/line pair for location info. |
| 135 | class DIEnumerator : public DIDescriptor { |
| 136 | public: |
| 137 | explicit DIEnumerator(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 138 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 139 | std::string getName() const { return getStringField(1); } |
Devang Patel | c69bf2c | 2009-01-05 18:38:38 +0000 | [diff] [blame] | 140 | uint64_t getEnumValue() const { return getUInt64Field(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 141 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 142 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 143 | /// DIType - This is a wrapper for a type. |
| 144 | /// FIXME: Types should be factored much better so that CV qualifiers and |
| 145 | /// others do not require a huge and empty descriptor full of zeros. |
| 146 | class DIType : public DIDescriptor { |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 147 | public: |
| 148 | enum { |
| 149 | FlagPrivate = 1 << 0, |
| 150 | FlagProtected = 1 << 1, |
Devang Patel | 4766159 | 2009-01-21 00:08:04 +0000 | [diff] [blame] | 151 | FlagFwdDecl = 1 << 2 |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 154 | protected: |
| 155 | DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {} |
| 156 | // This ctor is used when the Tag has already been validated by a derived |
| 157 | // ctor. |
| 158 | DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 159 | |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 160 | public: |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 161 | /// isDerivedType - Return true if the specified tag is legal for |
| 162 | /// DIDerivedType. |
| 163 | static bool isDerivedType(unsigned TAG); |
| 164 | |
| 165 | /// isCompositeType - Return true if the specified tag is legal for |
| 166 | /// DICompositeType. |
| 167 | static bool isCompositeType(unsigned TAG); |
| 168 | |
| 169 | /// isBasicType - Return true if the specified tag is legal for |
| 170 | /// DIBasicType. |
| 171 | static bool isBasicType(unsigned TAG) { |
| 172 | return TAG == dwarf::DW_TAG_base_type; |
| 173 | } |
| 174 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 175 | /// Verify - Verify that a type descriptor is well formed. |
| 176 | bool Verify() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 177 | public: |
| 178 | explicit DIType(GlobalVariable *GV); |
| 179 | explicit DIType() {} |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 180 | virtual ~DIType() {} |
| 181 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 182 | DIDescriptor getContext() const { return getDescriptorField(1); } |
| 183 | std::string getName() const { return getStringField(2); } |
| 184 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 185 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 186 | uint64_t getSizeInBits() const { return getUInt64Field(5); } |
| 187 | uint64_t getAlignInBits() const { return getUInt64Field(6); } |
| 188 | // FIXME: Offset is only used for DW_TAG_member nodes. Making every type |
| 189 | // carry this is just plain insane. |
| 190 | uint64_t getOffsetInBits() const { return getUInt64Field(7); } |
| 191 | unsigned getFlags() const { return getUnsignedField(8); } |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 192 | bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; } |
| 193 | bool isProtected() const { return (getFlags() & FlagProtected) != 0; } |
| 194 | bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 195 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 196 | /// dump - print type. |
| 197 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 198 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 199 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 200 | /// DIBasicType - A basic type, like 'int' or 'float'. |
| 201 | class DIBasicType : public DIType { |
| 202 | public: |
| 203 | explicit DIBasicType(GlobalVariable *GV); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 204 | unsigned getEncoding() const { return getUnsignedField(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 205 | |
| 206 | /// dump - print basic type. |
| 207 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 208 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 209 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 210 | /// DIDerivedType - A simple derived type, like a const qualified type, |
| 211 | /// a typedef, a pointer or reference, etc. |
| 212 | class DIDerivedType : public DIType { |
| 213 | protected: |
| 214 | explicit DIDerivedType(GlobalVariable *GV, bool, bool) |
| 215 | : DIType(GV, true, true) {} |
| 216 | public: |
| 217 | explicit DIDerivedType(GlobalVariable *GV); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 218 | DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 219 | |
| 220 | /// dump - print derived type. |
| 221 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 224 | /// DICompositeType - This descriptor holds a type that can refer to multiple |
| 225 | /// other types, like a function or struct. |
| 226 | /// FIXME: Why is this a DIDerivedType?? |
| 227 | class DICompositeType : public DIDerivedType { |
| 228 | public: |
| 229 | explicit DICompositeType(GlobalVariable *GV); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 230 | DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 231 | |
| 232 | /// Verify - Verify that a composite type descriptor is well formed. |
| 233 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 234 | |
| 235 | /// dump - print composite type. |
| 236 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 237 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 238 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 239 | /// DIGlobal - This is a common class for global variables and subprograms. |
| 240 | class DIGlobal : public DIDescriptor { |
| 241 | protected: |
Chris Lattner | 3b78185 | 2008-11-10 03:11:39 +0000 | [diff] [blame] | 242 | explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 243 | : DIDescriptor(GV, RequiredTag) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 244 | |
| 245 | /// isSubprogram - Return true if the specified tag is legal for |
| 246 | /// DISubprogram. |
| 247 | static bool isSubprogram(unsigned TAG) { |
| 248 | return TAG == dwarf::DW_TAG_subprogram; |
| 249 | } |
| 250 | |
| 251 | /// isGlobalVariable - Return true if the specified tag is legal for |
| 252 | /// DIGlobalVariable. |
| 253 | static bool isGlobalVariable(unsigned TAG) { |
| 254 | return TAG == dwarf::DW_TAG_variable; |
| 255 | } |
| 256 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 257 | public: |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 258 | virtual ~DIGlobal() {} |
| 259 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 260 | DIDescriptor getContext() const { return getDescriptorField(2); } |
| 261 | std::string getName() const { return getStringField(3); } |
| 262 | std::string getDisplayName() const { return getStringField(4); } |
| 263 | std::string getLinkageName() const { return getStringField(5); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 264 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); } |
| 265 | unsigned getLineNumber() const { return getUnsignedField(7); } |
| 266 | DIType getType() const { return getFieldAs<DIType>(8); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 267 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 268 | /// isLocalToUnit - Return true if this subprogram is local to the current |
| 269 | /// compile unit, like 'static' in C. |
| 270 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 271 | unsigned isDefinition() const { return getUnsignedField(10); } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 272 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 273 | /// dump - print global. |
| 274 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 275 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 276 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 277 | /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). |
| 278 | class DISubprogram : public DIGlobal { |
| 279 | public: |
| 280 | explicit DISubprogram(GlobalVariable *GV = 0); |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 281 | DICompositeType getType() const { return getFieldAs<DICompositeType>(8); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 282 | |
| 283 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 284 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 285 | |
| 286 | /// dump - print subprogram. |
| 287 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 288 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 289 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 290 | /// DIGlobalVariable - This is a wrapper for a global variable. |
| 291 | class DIGlobalVariable : public DIGlobal { |
| 292 | public: |
| 293 | explicit DIGlobalVariable(GlobalVariable *GV = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 294 | GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 295 | |
| 296 | /// Verify - Verify that a global variable descriptor is well formed. |
| 297 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 298 | |
| 299 | /// dump - print global variable. |
| 300 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 301 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 302 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 303 | /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, |
| 304 | /// global etc). |
| 305 | class DIVariable : public DIDescriptor { |
| 306 | public: |
| 307 | explicit DIVariable(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 308 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 309 | DIDescriptor getContext() const { return getDescriptorField(1); } |
| 310 | std::string getName() const { return getStringField(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 311 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 312 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 313 | DIType getType() const { return getFieldAs<DIType>(5); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 314 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 315 | /// isVariable - Return true if the specified tag is legal for DIVariable. |
| 316 | static bool isVariable(unsigned Tag); |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 317 | |
| 318 | /// Verify - Verify that a variable descriptor is well formed. |
| 319 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 320 | |
| 321 | /// dump - print variable. |
| 322 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 323 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 324 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 325 | /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc). |
| 326 | class DIBlock : public DIDescriptor { |
| 327 | public: |
| 328 | explicit DIBlock(GlobalVariable *GV = 0); |
| 329 | |
| 330 | DIDescriptor getContext() const { return getDescriptorField(1); } |
| 331 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 332 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 333 | /// DIFactory - This object assists with the construction of the various |
| 334 | /// descriptors. |
| 335 | class DIFactory { |
| 336 | Module &M; |
| 337 | // Cached values for uniquing and faster lookups. |
| 338 | DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 339 | const Type *EmptyStructPtr; // "{}*". |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 340 | Function *StopPointFn; // llvm.dbg.stoppoint |
| 341 | Function *FuncStartFn; // llvm.dbg.func.start |
| 342 | Function *RegionStartFn; // llvm.dbg.region.start |
| 343 | Function *RegionEndFn; // llvm.dbg.region.end |
| 344 | Function *DeclareFn; // llvm.dbg.declare |
| 345 | StringMap<Constant*> StringCache; |
| 346 | DenseMap<Constant*, DIDescriptor> SimpleConstantCache; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 347 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 348 | DIFactory(const DIFactory &); // DO NOT IMPLEMENT |
| 349 | void operator=(const DIFactory&); // DO NOT IMPLEMENT |
| 350 | public: |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 351 | explicit DIFactory(Module &m); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 352 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 353 | /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units, |
| 354 | /// creating a new one if there isn't already one in the module. |
| 355 | DIAnchor GetOrCreateCompileUnitAnchor(); |
| 356 | |
| 357 | /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms, |
| 358 | /// creating a new one if there isn't already one in the module. |
| 359 | DIAnchor GetOrCreateSubprogramAnchor(); |
| 360 | |
| 361 | /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals, |
| 362 | /// creating a new one if there isn't already one in the module. |
| 363 | DIAnchor GetOrCreateGlobalVariableAnchor(); |
| 364 | |
| 365 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
| 366 | /// This implicitly uniques the arrays created. |
| 367 | DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys); |
| 368 | |
| 369 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 370 | /// implicitly uniques the values returned. |
| 371 | DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 372 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 373 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 374 | /// unit. |
| 375 | DICompileUnit CreateCompileUnit(unsigned LangID, |
| 376 | const std::string &Filename, |
| 377 | const std::string &Directory, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 378 | const std::string &Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 379 | bool isMain = false, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 380 | bool isOptimized = false, |
| 381 | const char *Flags = ""); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 382 | |
| 383 | /// CreateEnumerator - Create a single enumerator value. |
| 384 | DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 385 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 386 | /// CreateBasicType - Create a basic type like int, float, etc. |
| 387 | DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name, |
| 388 | DICompileUnit CompileUnit, unsigned LineNumber, |
| 389 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 390 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 391 | unsigned Encoding); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 392 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 393 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 394 | /// pointer, typedef, etc. |
| 395 | DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context, |
| 396 | const std::string &Name, |
| 397 | DICompileUnit CompileUnit, |
| 398 | unsigned LineNumber, |
| 399 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 400 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 401 | DIType DerivedFrom); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 402 | |
| 403 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 404 | DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context, |
| 405 | const std::string &Name, |
| 406 | DICompileUnit CompileUnit, |
| 407 | unsigned LineNumber, |
| 408 | uint64_t SizeInBits, |
| 409 | uint64_t AlignInBits, |
| 410 | uint64_t OffsetInBits, unsigned Flags, |
| 411 | DIType DerivedFrom, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 412 | DIArray Elements); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 413 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 414 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 415 | /// See comments in DISubprogram for descriptions of these fields. |
| 416 | DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name, |
| 417 | const std::string &DisplayName, |
| 418 | const std::string &LinkageName, |
| 419 | DICompileUnit CompileUnit, unsigned LineNo, |
| 420 | DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 421 | bool isDefinition); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 422 | |
| 423 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 424 | DIGlobalVariable |
| 425 | CreateGlobalVariable(DIDescriptor Context, const std::string &Name, |
| 426 | const std::string &DisplayName, |
| 427 | const std::string &LinkageName, |
| 428 | DICompileUnit CompileUnit, |
| 429 | unsigned LineNo, DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 430 | bool isDefinition, llvm::GlobalVariable *GV); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 431 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 432 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 433 | DIVariable CreateVariable(unsigned Tag, DIDescriptor Context, |
| 434 | const std::string &Name, |
| 435 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 436 | DIType Type); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 437 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 438 | /// CreateBlock - This creates a descriptor for a lexical block with the |
| 439 | /// specified parent context. |
| 440 | DIBlock CreateBlock(DIDescriptor Context); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 441 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 442 | /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, |
| 443 | /// inserting it at the end of the specified basic block. |
| 444 | void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo, |
| 445 | BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 446 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 447 | /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to |
| 448 | /// mark the start of the specified subprogram. |
| 449 | void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB); |
| 450 | |
| 451 | /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to |
| 452 | /// mark the start of a region for the specified scoping descriptor. |
| 453 | void InsertRegionStart(DIDescriptor D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 454 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 455 | /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to |
| 456 | /// mark the end of a region for the specified scoping descriptor. |
| 457 | void InsertRegionEnd(DIDescriptor D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 458 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 459 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 460 | void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 461 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 462 | private: |
| 463 | Constant *GetTagConstant(unsigned TAG); |
| 464 | Constant *GetStringConstant(const std::string &String); |
| 465 | DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 466 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 467 | /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'. |
| 468 | Constant *getCastToEmpty(DIDescriptor D); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 469 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 470 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 471 | /// Finds the stoppoint coressponding to this instruction, that is the |
| 472 | /// stoppoint that dominates this instruction |
| 473 | const DbgStopPointInst *findStopPoint(const Instruction *Inst); |
| 474 | |
| 475 | /// Finds the stoppoint corresponding to first real (non-debug intrinsic) |
| 476 | /// instruction in this Basic Block, and returns the stoppoint for it. |
| 477 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB); |
| 478 | |
| 479 | /// Finds the dbg.declare intrinsic corresponding to this value if any. |
| 480 | /// It looks through pointer casts too. |
| 481 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 482 | } // end namespace llvm |
| 483 | |
| 484 | #endif |