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