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