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 |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 11 | // walking debug info in LLVM IR form. They essentially provide wrappers around |
| 12 | // the information in the global variables that's needed when constructing the |
| 13 | // DWARF information. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Evan Cheng | 891415b | 2009-01-26 07:31:20 +0000 | [diff] [blame] | 17 | #ifndef LLVM_ANALYSIS_DEBUGINFO_H |
| 18 | #define LLVM_ANALYSIS_DEBUGINFO_H |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 19 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 20 | #include "llvm/Metadata.h" |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringMap.h" |
| 23 | #include "llvm/ADT/DenseMap.h" |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallPtrSet.h" |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 27 | |
| 28 | namespace llvm { |
| 29 | class BasicBlock; |
| 30 | class Constant; |
| 31 | class Function; |
| 32 | class GlobalVariable; |
| 33 | class Module; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 34 | class Type; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 35 | class Value; |
Cedric Venet | aff9c27 | 2009-02-14 16:06:42 +0000 | [diff] [blame] | 36 | struct DbgStopPointInst; |
| 37 | struct DbgDeclareInst; |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 38 | struct DbgFuncStartInst; |
| 39 | struct DbgRegionStartInst; |
| 40 | struct DbgRegionEndInst; |
| 41 | class DebugLoc; |
Daniel Dunbar | 460d16e | 2009-07-12 22:46:08 +0000 | [diff] [blame] | 42 | struct DebugLocTracker; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 43 | class Instruction; |
Benjamin Kramer | 12ddd40 | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 44 | class LLVMContext; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 45 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 46 | class DIDescriptor { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 47 | protected: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 48 | MDNode *DbgNode; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 49 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 50 | /// DIDescriptor constructor. If the specified node is non-null, check |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 51 | /// to make sure that the tag in the descriptor matches 'RequiredTag'. If |
| 52 | /// not, the debug info is corrupt and we ignore it. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 53 | DIDescriptor(MDNode *N, unsigned RequiredTag); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 54 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 55 | const std::string &getStringField(unsigned Elt, std::string &Result) const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 56 | unsigned getUnsignedField(unsigned Elt) const { |
| 57 | return (unsigned)getUInt64Field(Elt); |
| 58 | } |
| 59 | uint64_t getUInt64Field(unsigned Elt) const; |
| 60 | DIDescriptor getDescriptorField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 61 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 62 | template <typename DescTy> |
| 63 | DescTy getFieldAs(unsigned Elt) const { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 64 | return DescTy(getDescriptorField(Elt).getNode()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 65 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 66 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 67 | GlobalVariable *getGlobalVariableField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 68 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 69 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 70 | explicit DIDescriptor() : DbgNode(0) {} |
| 71 | explicit DIDescriptor(MDNode *N) : DbgNode(N) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 72 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 73 | bool isNull() const { return DbgNode == 0; } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 74 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 75 | MDNode *getNode() const { return DbgNode; } |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 76 | |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 77 | unsigned getVersion() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 78 | return getUnsignedField(0) & LLVMDebugVersionMask; |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 79 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 80 | |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 81 | unsigned getTag() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 82 | return getUnsignedField(0) & ~LLVMDebugVersionMask; |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 83 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 84 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 85 | /// ValidDebugInfo - Return true if N represents valid debug info value. |
| 86 | static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel); |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 87 | |
Bill Wendling | 16de013 | 2009-05-05 22:19:25 +0000 | [diff] [blame] | 88 | /// dump - print descriptor. |
| 89 | void dump() const; |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 90 | |
| 91 | bool isDerivedType() const; |
| 92 | bool isCompositeType() const; |
| 93 | bool isBasicType() const; |
| 94 | bool isVariable() const; |
| 95 | bool isSubprogram() const; |
| 96 | bool isGlobalVariable() const; |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame^] | 97 | bool isScope() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 98 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 99 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 100 | /// DISubrange - This is used to represent ranges, for array bounds. |
| 101 | class DISubrange : public DIDescriptor { |
| 102 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 103 | explicit DISubrange(MDNode *N = 0) |
| 104 | : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 105 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 106 | int64_t getLo() const { return (int64_t)getUInt64Field(1); } |
| 107 | int64_t getHi() const { return (int64_t)getUInt64Field(2); } |
| 108 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 109 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 110 | /// DIArray - This descriptor holds an array of descriptors. |
| 111 | class DIArray : public DIDescriptor { |
| 112 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 113 | explicit DIArray(MDNode *N = 0) |
| 114 | : DIDescriptor(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 115 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 116 | unsigned getNumElements() const; |
Devang Patel | a22d57d | 2009-01-05 19:55:07 +0000 | [diff] [blame] | 117 | DIDescriptor getElement(unsigned Idx) const { |
| 118 | return getDescriptorField(Idx); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 119 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 120 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 121 | |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame^] | 122 | /// DIScope - A base class for various scopes. |
| 123 | class DIScope : public DIDescriptor { |
| 124 | public: |
| 125 | explicit DIScope(MDNode *N = 0) : DIDescriptor (N) { |
| 126 | if (DbgNode && !isScope()) |
| 127 | DbgNode = 0; |
| 128 | } |
| 129 | }; |
| 130 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 131 | /// DICompileUnit - A wrapper for a compile unit. |
| 132 | class DICompileUnit : public DIDescriptor { |
| 133 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 134 | explicit DICompileUnit(MDNode *N = 0) |
| 135 | : DIDescriptor(N, dwarf::DW_TAG_compile_unit) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 136 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 137 | unsigned getLanguage() const { return getUnsignedField(2); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 138 | const std::string &getFilename(std::string &F) const { |
| 139 | return getStringField(3, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 140 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 141 | const std::string &getDirectory(std::string &F) const { |
| 142 | return getStringField(4, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 143 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 144 | const std::string &getProducer(std::string &F) const { |
| 145 | return getStringField(5, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 146 | } |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 147 | |
| 148 | /// isMain - Each input file is encoded as a separate compile unit in LLVM |
| 149 | /// debugging information output. However, many target specific tool chains |
| 150 | /// prefer to encode only one compile unit in an object file. In this |
| 151 | /// situation, the LLVM code generator will include debugging information |
| 152 | /// entities in the compile unit that is marked as main compile unit. The |
| 153 | /// code generator accepts maximum one main compile unit per module. If a |
| 154 | /// module does not contain any main compile unit then the code generator |
| 155 | /// will emit multiple compile units in the output object file. |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 156 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 157 | bool isMain() const { return getUnsignedField(6); } |
| 158 | bool isOptimized() const { return getUnsignedField(7); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 159 | const std::string &getFlags(std::string &F) const { |
| 160 | return getStringField(8, F); |
| 161 | } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 162 | unsigned getRunTimeVersion() const { return getUnsignedField(9); } |
Devang Patel | ce31b02 | 2009-01-20 18:13:03 +0000 | [diff] [blame] | 163 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 164 | /// Verify - Verify that a compile unit is well formed. |
| 165 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 166 | |
| 167 | /// dump - print compile unit. |
| 168 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). |
| 172 | /// FIXME: it seems strange that this doesn't have either a reference to the |
| 173 | /// type/precision or a file/line pair for location info. |
| 174 | class DIEnumerator : public DIDescriptor { |
| 175 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 176 | explicit DIEnumerator(MDNode *N = 0) |
| 177 | : DIDescriptor(N, dwarf::DW_TAG_enumerator) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 178 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 179 | const std::string &getName(std::string &F) const { |
| 180 | return getStringField(1, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 181 | } |
Devang Patel | c69bf2c | 2009-01-05 18:38:38 +0000 | [diff] [blame] | 182 | uint64_t getEnumValue() const { return getUInt64Field(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 183 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 184 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 185 | /// DIType - This is a wrapper for a type. |
| 186 | /// FIXME: Types should be factored much better so that CV qualifiers and |
| 187 | /// others do not require a huge and empty descriptor full of zeros. |
| 188 | class DIType : public DIDescriptor { |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 189 | public: |
| 190 | enum { |
Devang Patel | a1ba269 | 2009-08-27 23:51:51 +0000 | [diff] [blame] | 191 | FlagPrivate = 1 << 0, |
| 192 | FlagProtected = 1 << 1, |
| 193 | FlagFwdDecl = 1 << 2, |
| 194 | FlagAppleBlock = 1 << 3 |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 197 | protected: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 198 | DIType(MDNode *N, unsigned Tag) |
| 199 | : DIDescriptor(N, Tag) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 200 | // This ctor is used when the Tag has already been validated by a derived |
| 201 | // ctor. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 202 | DIType(MDNode *N, bool, bool) : DIDescriptor(N) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 203 | |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 204 | public: |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 205 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 206 | /// Verify - Verify that a type descriptor is well formed. |
| 207 | bool Verify() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 208 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 209 | explicit DIType(MDNode *N); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 210 | explicit DIType() {} |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 211 | virtual ~DIType() {} |
| 212 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 213 | DIDescriptor getContext() const { return getDescriptorField(1); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 214 | const std::string &getName(std::string &F) const { |
| 215 | return getStringField(2, F); |
| 216 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 217 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 218 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 219 | uint64_t getSizeInBits() const { return getUInt64Field(5); } |
| 220 | uint64_t getAlignInBits() const { return getUInt64Field(6); } |
| 221 | // FIXME: Offset is only used for DW_TAG_member nodes. Making every type |
| 222 | // carry this is just plain insane. |
| 223 | uint64_t getOffsetInBits() const { return getUInt64Field(7); } |
| 224 | unsigned getFlags() const { return getUnsignedField(8); } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 225 | bool isPrivate() const { |
| 226 | return (getFlags() & FlagPrivate) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 227 | } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 228 | bool isProtected() const { |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 229 | return (getFlags() & FlagProtected) != 0; |
| 230 | } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 231 | bool isForwardDecl() const { |
| 232 | return (getFlags() & FlagFwdDecl) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 233 | } |
Devang Patel | a1ba269 | 2009-08-27 23:51:51 +0000 | [diff] [blame] | 234 | // isAppleBlock - Return true if this is the Apple Blocks extension. |
| 235 | bool isAppleBlockExtension() const { |
| 236 | return (getFlags() & FlagAppleBlock) != 0; |
Devang Patel | 8af76bd | 2009-08-26 00:39:50 +0000 | [diff] [blame] | 237 | } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 238 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 239 | /// dump - print type. |
| 240 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 241 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 242 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 243 | /// DIBasicType - A basic type, like 'int' or 'float'. |
| 244 | class DIBasicType : public DIType { |
| 245 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 246 | explicit DIBasicType(MDNode *N = 0) |
| 247 | : DIType(N, dwarf::DW_TAG_base_type) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 248 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 249 | unsigned getEncoding() const { return getUnsignedField(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 250 | |
| 251 | /// dump - print basic type. |
| 252 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 253 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 254 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 255 | /// DIDerivedType - A simple derived type, like a const qualified type, |
| 256 | /// a typedef, a pointer or reference, etc. |
| 257 | class DIDerivedType : public DIType { |
| 258 | protected: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 259 | explicit DIDerivedType(MDNode *N, bool, bool) |
| 260 | : DIType(N, true, true) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 261 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 262 | explicit DIDerivedType(MDNode *N = 0) |
| 263 | : DIType(N, true, true) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 264 | if (DbgNode && !isDerivedType()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 265 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 268 | DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 269 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 270 | /// getOriginalTypeSize - If this type is derived from a base type then |
| 271 | /// return base type size. |
| 272 | uint64_t getOriginalTypeSize() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 273 | /// dump - print derived type. |
| 274 | void dump() const; |
Devang Patel | c4999d7 | 2009-07-22 18:23:44 +0000 | [diff] [blame] | 275 | |
| 276 | /// replaceAllUsesWith - Replace all uses of debug info referenced by |
| 277 | /// this descriptor. After this completes, the current debug info value |
| 278 | /// is erased. |
| 279 | void replaceAllUsesWith(DIDescriptor &D); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 280 | }; |
| 281 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 282 | /// DICompositeType - This descriptor holds a type that can refer to multiple |
| 283 | /// other types, like a function or struct. |
| 284 | /// FIXME: Why is this a DIDerivedType?? |
| 285 | class DICompositeType : public DIDerivedType { |
| 286 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 287 | explicit DICompositeType(MDNode *N = 0) |
| 288 | : DIDerivedType(N, true, true) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 289 | if (N && !isCompositeType()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 290 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 293 | DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 294 | unsigned getRunTimeLang() const { return getUnsignedField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 295 | |
| 296 | /// Verify - Verify that a composite type descriptor is well formed. |
| 297 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 298 | |
| 299 | /// dump - print composite type. |
| 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 | /// DIGlobal - This is a common class for global variables and subprograms. |
| 304 | class DIGlobal : public DIDescriptor { |
| 305 | protected: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 306 | explicit DIGlobal(MDNode *N, unsigned RequiredTag) |
| 307 | : DIDescriptor(N, RequiredTag) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 308 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 309 | public: |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 310 | virtual ~DIGlobal() {} |
| 311 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 312 | DIDescriptor getContext() const { return getDescriptorField(2); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 313 | const std::string &getName(std::string &F) const { |
| 314 | return getStringField(3, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 315 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 316 | const std::string &getDisplayName(std::string &F) const { |
| 317 | return getStringField(4, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 318 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 319 | const std::string &getLinkageName(std::string &F) const { |
| 320 | return getStringField(5, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 321 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 322 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); } |
| 323 | unsigned getLineNumber() const { return getUnsignedField(7); } |
| 324 | DIType getType() const { return getFieldAs<DIType>(8); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 325 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 326 | /// isLocalToUnit - Return true if this subprogram is local to the current |
| 327 | /// compile unit, like 'static' in C. |
| 328 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 329 | unsigned isDefinition() const { return getUnsignedField(10); } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 330 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 331 | /// dump - print global. |
| 332 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 333 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 334 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 335 | /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). |
| 336 | class DISubprogram : public DIGlobal { |
| 337 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 338 | explicit DISubprogram(MDNode *N = 0) |
| 339 | : DIGlobal(N, dwarf::DW_TAG_subprogram) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 340 | |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 341 | DICompositeType getType() const { return getFieldAs<DICompositeType>(8); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 342 | |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 343 | /// getReturnTypeName - Subprogram return types are encoded either as |
| 344 | /// DIType or as DICompositeType. |
| 345 | const std::string &getReturnTypeName(std::string &F) const { |
| 346 | DICompositeType DCT(getFieldAs<DICompositeType>(8)); |
| 347 | if (!DCT.isNull()) { |
| 348 | DIArray A = DCT.getTypeArray(); |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 349 | DIType T(A.getElement(0).getNode()); |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 350 | return T.getName(F); |
| 351 | } |
| 352 | DIType T(getFieldAs<DIType>(8)); |
| 353 | return T.getName(F); |
| 354 | } |
| 355 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 356 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 357 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 358 | |
| 359 | /// dump - print subprogram. |
| 360 | void dump() const; |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 361 | |
| 362 | /// describes - Return true if this subprogram provides debugging |
| 363 | /// information for the function F. |
| 364 | bool describes(const Function *F); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 365 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 366 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 367 | /// DIGlobalVariable - This is a wrapper for a global variable. |
| 368 | class DIGlobalVariable : public DIGlobal { |
| 369 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 370 | explicit DIGlobalVariable(MDNode *N = 0) |
| 371 | : DIGlobal(N, dwarf::DW_TAG_variable) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 372 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 373 | GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 374 | |
| 375 | /// Verify - Verify that a global variable descriptor is well formed. |
| 376 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 377 | |
| 378 | /// dump - print global variable. |
| 379 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 380 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 381 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 382 | /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, |
| 383 | /// global etc). |
| 384 | class DIVariable : public DIDescriptor { |
| 385 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 386 | explicit DIVariable(MDNode *N = 0) |
| 387 | : DIDescriptor(N) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 388 | if (DbgNode && !isVariable()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 389 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 390 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 391 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 392 | DIDescriptor getContext() const { return getDescriptorField(1); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 393 | const std::string &getName(std::string &F) const { |
| 394 | return getStringField(2, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 395 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 396 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 397 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 398 | DIType getType() const { return getFieldAs<DIType>(5); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 399 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 400 | |
| 401 | /// Verify - Verify that a variable descriptor is well formed. |
| 402 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 403 | |
| 404 | /// dump - print variable. |
| 405 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 406 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 407 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 408 | /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc). |
| 409 | class DIBlock : public DIDescriptor { |
| 410 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 411 | explicit DIBlock(MDNode *N = 0) |
| 412 | : DIDescriptor(N, dwarf::DW_TAG_lexical_block) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 413 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 414 | DIDescriptor getContext() const { return getDescriptorField(1); } |
| 415 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 416 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 417 | /// DIFactory - This object assists with the construction of the various |
| 418 | /// descriptors. |
| 419 | class DIFactory { |
| 420 | Module &M; |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 421 | LLVMContext& VMContext; |
| 422 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 423 | // Cached values for uniquing and faster lookups. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 424 | const Type *EmptyStructPtr; // "{}*". |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 425 | Function *StopPointFn; // llvm.dbg.stoppoint |
| 426 | Function *FuncStartFn; // llvm.dbg.func.start |
| 427 | Function *RegionStartFn; // llvm.dbg.region.start |
| 428 | Function *RegionEndFn; // llvm.dbg.region.end |
| 429 | Function *DeclareFn; // llvm.dbg.declare |
| 430 | StringMap<Constant*> StringCache; |
| 431 | DenseMap<Constant*, DIDescriptor> SimpleConstantCache; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 432 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 433 | DIFactory(const DIFactory &); // DO NOT IMPLEMENT |
| 434 | void operator=(const DIFactory&); // DO NOT IMPLEMENT |
| 435 | public: |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 436 | explicit DIFactory(Module &m); |
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 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
| 439 | /// This implicitly uniques the arrays created. |
| 440 | DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys); |
| 441 | |
| 442 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 443 | /// implicitly uniques the values returned. |
| 444 | DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 445 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 446 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 447 | /// unit. |
| 448 | DICompileUnit CreateCompileUnit(unsigned LangID, |
| 449 | const std::string &Filename, |
| 450 | const std::string &Directory, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 451 | const std::string &Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 452 | bool isMain = false, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 453 | bool isOptimized = false, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 454 | const char *Flags = "", |
| 455 | unsigned RunTimeVer = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 456 | |
| 457 | /// CreateEnumerator - Create a single enumerator value. |
| 458 | DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 459 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 460 | /// CreateBasicType - Create a basic type like int, float, etc. |
| 461 | DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name, |
| 462 | DICompileUnit CompileUnit, unsigned LineNumber, |
| 463 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 464 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 465 | unsigned Encoding); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 466 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 467 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 468 | /// pointer, typedef, etc. |
| 469 | DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context, |
| 470 | const std::string &Name, |
| 471 | DICompileUnit CompileUnit, |
| 472 | unsigned LineNumber, |
| 473 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 474 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 475 | DIType DerivedFrom); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 476 | |
| 477 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 478 | DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context, |
| 479 | const std::string &Name, |
| 480 | DICompileUnit CompileUnit, |
| 481 | unsigned LineNumber, |
| 482 | uint64_t SizeInBits, |
| 483 | uint64_t AlignInBits, |
| 484 | uint64_t OffsetInBits, unsigned Flags, |
| 485 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 486 | DIArray Elements, |
| 487 | unsigned RunTimeLang = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 488 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 489 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 490 | /// See comments in DISubprogram for descriptions of these fields. |
| 491 | DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name, |
| 492 | const std::string &DisplayName, |
| 493 | const std::string &LinkageName, |
| 494 | DICompileUnit CompileUnit, unsigned LineNo, |
| 495 | DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 496 | bool isDefinition); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 497 | |
| 498 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 499 | DIGlobalVariable |
| 500 | CreateGlobalVariable(DIDescriptor Context, const std::string &Name, |
| 501 | const std::string &DisplayName, |
| 502 | const std::string &LinkageName, |
| 503 | DICompileUnit CompileUnit, |
| 504 | unsigned LineNo, DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 505 | bool isDefinition, llvm::GlobalVariable *GV); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 506 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 507 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 508 | DIVariable CreateVariable(unsigned Tag, DIDescriptor Context, |
| 509 | const std::string &Name, |
| 510 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 511 | DIType Type); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 512 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 513 | /// CreateBlock - This creates a descriptor for a lexical block with the |
| 514 | /// specified parent context. |
| 515 | DIBlock CreateBlock(DIDescriptor Context); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 516 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 517 | /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, |
| 518 | /// inserting it at the end of the specified basic block. |
| 519 | void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo, |
| 520 | BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 521 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 522 | /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to |
| 523 | /// mark the start of the specified subprogram. |
| 524 | void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB); |
| 525 | |
| 526 | /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to |
| 527 | /// mark the start of a region for the specified scoping descriptor. |
| 528 | void InsertRegionStart(DIDescriptor D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 529 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 530 | /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to |
| 531 | /// mark the end of a region for the specified scoping descriptor. |
| 532 | void InsertRegionEnd(DIDescriptor D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 533 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 534 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 535 | void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 536 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 537 | private: |
| 538 | Constant *GetTagConstant(unsigned TAG); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 539 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 540 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 541 | /// Finds the stoppoint coressponding to this instruction, that is the |
| 542 | /// stoppoint that dominates this instruction |
| 543 | const DbgStopPointInst *findStopPoint(const Instruction *Inst); |
| 544 | |
| 545 | /// Finds the stoppoint corresponding to first real (non-debug intrinsic) |
| 546 | /// instruction in this Basic Block, and returns the stoppoint for it. |
| 547 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB); |
| 548 | |
| 549 | /// Finds the dbg.declare intrinsic corresponding to this value if any. |
| 550 | /// It looks through pointer casts too. |
| 551 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 552 | |
| 553 | /// Find the debug info descriptor corresponding to this global variable. |
| 554 | Value *findDbgGlobalDeclare(GlobalVariable *V); |
| 555 | |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 556 | bool getLocationInfo(const Value *V, std::string &DisplayName, |
| 557 | std::string &Type, unsigned &LineNo, std::string &File, |
| 558 | std::string &Dir); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 559 | |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 560 | /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 561 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 562 | bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI, |
| 563 | CodeGenOpt::Level OptLev); |
| 564 | |
| 565 | /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 566 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 567 | bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI, |
| 568 | CodeGenOpt::Level OptLev); |
| 569 | |
| 570 | /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 571 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 572 | bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI, |
| 573 | CodeGenOpt::Level OptLev); |
| 574 | |
| 575 | /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 576 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 577 | bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI, |
| 578 | CodeGenOpt::Level OptLev); |
| 579 | |
| 580 | /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 581 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 582 | bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI, |
| 583 | CodeGenOpt::Level OptLev); |
| 584 | |
| 585 | /// ExtractDebugLocation - Extract debug location information |
| 586 | /// from llvm.dbg.stoppoint intrinsic. |
| 587 | DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 588 | DebugLocTracker &DebugLocInfo); |
| 589 | |
| 590 | /// ExtractDebugLocation - Extract debug location information |
| 591 | /// from llvm.dbg.func_start intrinsic. |
| 592 | DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 593 | DebugLocTracker &DebugLocInfo); |
| 594 | |
| 595 | /// isInlinedFnStart - Return true if FSI is starting an inlined function. |
| 596 | bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn); |
| 597 | |
| 598 | /// isInlinedFnEnd - Return true if REI is ending an inlined function. |
| 599 | bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn); |
Devang Patel | 27a201d | 2009-08-06 15:39:34 +0000 | [diff] [blame] | 600 | /// DebugInfoFinder - This object collects DebugInfo from a module. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 601 | class DebugInfoFinder { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 602 | |
| 603 | public: |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 604 | /// processModule - Process entire module and collect debug info |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 605 | /// anchors. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 606 | void processModule(Module &M); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 607 | |
| 608 | private: |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 609 | /// processType - Process DIType. |
| 610 | void processType(DIType DT); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 611 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 612 | /// processSubprogram - Enumberate DISubprogram. |
| 613 | void processSubprogram(DISubprogram SP); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 614 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 615 | /// processStopPoint - Process DbgStopPointInst. |
| 616 | void processStopPoint(DbgStopPointInst *SPI); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 617 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 618 | /// processFuncStart - Process DbgFuncStartInst. |
| 619 | void processFuncStart(DbgFuncStartInst *FSI); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 620 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 621 | /// processRegionStart - Process DbgRegionStart. |
| 622 | void processRegionStart(DbgRegionStartInst *DRS); |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 623 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 624 | /// processRegionEnd - Process DbgRegionEnd. |
| 625 | void processRegionEnd(DbgRegionEndInst *DRE); |
Devang Patel | e802f1c | 2009-07-30 17:30:23 +0000 | [diff] [blame] | 626 | |
Devang Patel | b4d3130 | 2009-07-31 18:18:52 +0000 | [diff] [blame] | 627 | /// processDeclare - Process DbgDeclareInst. |
| 628 | void processDeclare(DbgDeclareInst *DDI); |
| 629 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 630 | /// addCompileUnit - Add compile unit into CUs. |
| 631 | bool addCompileUnit(DICompileUnit CU); |
| 632 | |
| 633 | /// addGlobalVariable - Add global variable into GVs. |
| 634 | bool addGlobalVariable(DIGlobalVariable DIG); |
| 635 | |
| 636 | // addSubprogram - Add subprgoram into SPs. |
| 637 | bool addSubprogram(DISubprogram SP); |
| 638 | |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 639 | /// addType - Add type into Tys. |
| 640 | bool addType(DIType DT); |
| 641 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 642 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 643 | typedef SmallVector<MDNode *, 8>::iterator iterator; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 644 | iterator compile_unit_begin() { return CUs.begin(); } |
| 645 | iterator compile_unit_end() { return CUs.end(); } |
| 646 | iterator subprogram_begin() { return SPs.begin(); } |
| 647 | iterator subprogram_end() { return SPs.end(); } |
| 648 | iterator global_variable_begin() { return GVs.begin(); } |
| 649 | iterator global_variable_end() { return GVs.end(); } |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 650 | iterator type_begin() { return TYs.begin(); } |
| 651 | iterator type_end() { return TYs.end(); } |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 652 | |
| 653 | unsigned compile_unit_count() { return CUs.size(); } |
| 654 | unsigned global_variable_count() { return GVs.size(); } |
| 655 | unsigned subprogram_count() { return SPs.size(); } |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 656 | unsigned type_count() { return TYs.size(); } |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 657 | |
| 658 | private: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 659 | SmallVector<MDNode *, 8> CUs; // Compile Units |
| 660 | SmallVector<MDNode *, 8> SPs; // Subprograms |
| 661 | SmallVector<MDNode *, 8> GVs; // Global Variables; |
| 662 | SmallVector<MDNode *, 8> TYs; // Types |
| 663 | SmallPtrSet<MDNode *, 64> NodesSeen; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 664 | }; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 665 | } // end namespace llvm |
| 666 | |
| 667 | #endif |