| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 1 | //===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- 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 | // Declarations for metadata specific to debug info. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_IR_DEBUGINFOMETADATA_H |
| 15 | #define LLVM_IR_DEBUGINFOMETADATA_H |
| 16 | |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/ArrayRef.h" |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/BitmaskEnum.h" |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/None.h" |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Optional.h" |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/STLExtras.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame^] | 22 | #include "llvm/ADT/SmallVector.h" |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringRef.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame^] | 24 | #include "llvm/ADT/iterator_range.h" |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Metadata.h" |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Casting.h" |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Dwarf.h" |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 28 | #include <cassert> |
| 29 | #include <climits> |
| 30 | #include <cstddef> |
| 31 | #include <cstdint> |
| 32 | #include <iterator> |
| 33 | #include <type_traits> |
| 34 | #include <vector> |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 35 | |
| Duncan P. N. Exon Smith | 61e62a5 | 2015-02-02 19:55:21 +0000 | [diff] [blame] | 36 | // Helper macros for defining get() overrides. |
| 37 | #define DEFINE_MDNODE_GET_UNPACK_IMPL(...) __VA_ARGS__ |
| 38 | #define DEFINE_MDNODE_GET_UNPACK(ARGS) DEFINE_MDNODE_GET_UNPACK_IMPL ARGS |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 39 | #define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) \ |
| Duncan P. N. Exon Smith | 61e62a5 | 2015-02-02 19:55:21 +0000 | [diff] [blame] | 40 | static CLASS *getDistinct(LLVMContext &Context, \ |
| 41 | DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \ |
| 42 | return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Distinct); \ |
| 43 | } \ |
| 44 | static Temp##CLASS getTemporary(LLVMContext &Context, \ |
| 45 | DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \ |
| 46 | return Temp##CLASS( \ |
| 47 | getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Temporary)); \ |
| 48 | } |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 49 | #define DEFINE_MDNODE_GET(CLASS, FORMAL, ARGS) \ |
| 50 | static CLASS *get(LLVMContext &Context, DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \ |
| 51 | return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued); \ |
| 52 | } \ |
| 53 | static CLASS *getIfExists(LLVMContext &Context, \ |
| 54 | DEFINE_MDNODE_GET_UNPACK(FORMAL)) { \ |
| 55 | return getImpl(Context, DEFINE_MDNODE_GET_UNPACK(ARGS), Uniqued, \ |
| 56 | /* ShouldCreate */ false); \ |
| 57 | } \ |
| 58 | DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) |
| Duncan P. N. Exon Smith | 61e62a5 | 2015-02-02 19:55:21 +0000 | [diff] [blame] | 59 | |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 60 | namespace llvm { |
| 61 | |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 62 | /// Holds a subclass of DINode. |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 63 | /// |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 64 | /// FIXME: This class doesn't currently make much sense. Previously it was a |
| 65 | /// union beteen MDString (for ODR-uniqued types) and things like DIType. To |
| 66 | /// support CodeView work, it wasn't deleted outright when MDString-based type |
| 67 | /// references were deleted; we'll soon need a similar concept for CodeView |
| 68 | /// DITypeIndex. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 69 | template <class T> class TypedDINodeRef { |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 70 | const Metadata *MD = nullptr; |
| 71 | |
| 72 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 73 | TypedDINodeRef() = default; |
| 74 | TypedDINodeRef(std::nullptr_t) {} |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 75 | TypedDINodeRef(const T *MD) : MD(MD) {} |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 76 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 77 | explicit TypedDINodeRef(const Metadata *MD) : MD(MD) { |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 78 | assert((!MD || isa<T>(MD)) && "Expected valid type ref"); |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | template <class U> |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 82 | TypedDINodeRef( |
| 83 | const TypedDINodeRef<U> &X, |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 84 | typename std::enable_if<std::is_convertible<U *, T *>::value>::type * = |
| 85 | nullptr) |
| 86 | : MD(X) {} |
| 87 | |
| 88 | operator Metadata *() const { return const_cast<Metadata *>(MD); } |
| 89 | |
| Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 90 | T *resolve() const { return const_cast<T *>(cast_or_null<T>(MD)); } |
| 91 | |
| Hans Wennborg | 13958b7 | 2015-07-22 20:46:11 +0000 | [diff] [blame] | 92 | bool operator==(const TypedDINodeRef<T> &X) const { return MD == X.MD; } |
| 93 | bool operator!=(const TypedDINodeRef<T> &X) const { return MD != X.MD; } |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 96 | using DINodeRef = TypedDINodeRef<DINode>; |
| 97 | using DIScopeRef = TypedDINodeRef<DIScope>; |
| 98 | using DITypeRef = TypedDINodeRef<DIType>; |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 99 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 100 | class DITypeRefArray { |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 101 | const MDTuple *N = nullptr; |
| 102 | |
| 103 | public: |
| Duncan P. N. Exon Smith | 0660bcd | 2015-08-28 21:38:24 +0000 | [diff] [blame] | 104 | DITypeRefArray() = default; |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 105 | DITypeRefArray(const MDTuple *N) : N(N) {} |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 106 | |
| 107 | explicit operator bool() const { return get(); } |
| 108 | explicit operator MDTuple *() const { return get(); } |
| 109 | |
| 110 | MDTuple *get() const { return const_cast<MDTuple *>(N); } |
| 111 | MDTuple *operator->() const { return get(); } |
| 112 | MDTuple &operator*() const { return *get(); } |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 113 | |
| Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 114 | // FIXME: Fix callers and remove condition on N. |
| 115 | unsigned size() const { return N ? N->getNumOperands() : 0u; } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 116 | DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); } |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 117 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 118 | class iterator : std::iterator<std::input_iterator_tag, DITypeRef, |
| 119 | std::ptrdiff_t, void, DITypeRef> { |
| Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 120 | MDNode::op_iterator I = nullptr; |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 121 | |
| 122 | public: |
| Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 123 | iterator() = default; |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 124 | explicit iterator(MDNode::op_iterator I) : I(I) {} |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 125 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 126 | DITypeRef operator*() const { return DITypeRef(*I); } |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 127 | |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 128 | iterator &operator++() { |
| 129 | ++I; |
| 130 | return *this; |
| 131 | } |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 132 | |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 133 | iterator operator++(int) { |
| 134 | iterator Temp(*this); |
| 135 | ++I; |
| 136 | return Temp; |
| 137 | } |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 138 | |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 139 | bool operator==(const iterator &X) const { return I == X.I; } |
| 140 | bool operator!=(const iterator &X) const { return I != X.I; } |
| 141 | }; |
| 142 | |
| Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 143 | // FIXME: Fix callers and remove condition on N. |
| 144 | iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); } |
| 145 | iterator end() const { return N ? iterator(N->op_end()) : iterator(); } |
| Duncan P. N. Exon Smith | 62e9362 | 2015-04-06 19:48:50 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 148 | /// Tagged DWARF-like metadata node. |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 149 | /// |
| 150 | /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 151 | /// defined in llvm/Support/Dwarf.h). Called \a DINode because it's |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 152 | /// potentially used for non-DWARF output. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 153 | class DINode : public MDNode { |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 154 | friend class LLVMContextImpl; |
| 155 | friend class MDNode; |
| 156 | |
| 157 | protected: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 158 | DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, |
| 159 | ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None) |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 160 | : MDNode(C, ID, Storage, Ops1, Ops2) { |
| 161 | assert(Tag < 1u << 16); |
| 162 | SubclassData16 = Tag; |
| 163 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 164 | ~DINode() = default; |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 165 | |
| Duncan P. N. Exon Smith | 252b62d | 2015-02-05 01:07:47 +0000 | [diff] [blame] | 166 | template <class Ty> Ty *getOperandAs(unsigned I) const { |
| 167 | return cast_or_null<Ty>(getOperand(I)); |
| 168 | } |
| 169 | |
| Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 170 | StringRef getStringOperand(unsigned I) const { |
| Duncan P. N. Exon Smith | 252b62d | 2015-02-05 01:07:47 +0000 | [diff] [blame] | 171 | if (auto *S = getOperandAs<MDString>(I)) |
| Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 172 | return S->getString(); |
| 173 | return StringRef(); |
| 174 | } |
| 175 | |
| Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 176 | static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) { |
| 177 | if (S.empty()) |
| 178 | return nullptr; |
| 179 | return MDString::get(Context, S); |
| 180 | } |
| 181 | |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 182 | /// Allow subclasses to mutate the tag. |
| 183 | void setTag(unsigned Tag) { SubclassData16 = Tag; } |
| 184 | |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 185 | public: |
| 186 | unsigned getTag() const { return SubclassData16; } |
| 187 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 188 | /// Debug info flags. |
| Duncan P. N. Exon Smith | 3744fd0 | 2015-03-31 01:19:51 +0000 | [diff] [blame] | 189 | /// |
| 190 | /// The three accessibility flags are mutually exclusive and rolled together |
| 191 | /// in the first two bits. |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 192 | enum DIFlags : uint32_t { |
| Duncan P. N. Exon Smith | 3744fd0 | 2015-03-31 01:19:51 +0000 | [diff] [blame] | 193 | #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = ID, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 194 | #define DI_FLAG_LARGEST_NEEDED |
| Duncan P. N. Exon Smith | 3744fd0 | 2015-03-31 01:19:51 +0000 | [diff] [blame] | 195 | #include "llvm/IR/DebugInfoFlags.def" |
| Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 196 | FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic, |
| 197 | FlagPtrToMemberRep = FlagSingleInheritance | FlagMultipleInheritance | |
| 198 | FlagVirtualInheritance, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 199 | LLVM_MARK_AS_BITMASK_ENUM(FlagLargest) |
| Duncan P. N. Exon Smith | 3744fd0 | 2015-03-31 01:19:51 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 202 | static DIFlags getFlag(StringRef Flag); |
| Mehdi Amini | f42ec79 | 2016-10-01 05:57:50 +0000 | [diff] [blame] | 203 | static StringRef getFlagString(DIFlags Flag); |
| Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 204 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 205 | /// Split up a flags bitfield. |
| Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 206 | /// |
| 207 | /// Split \c Flags into \c SplitFlags, a vector of its components. Returns |
| 208 | /// any remaining (unrecognized) bits. |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 209 | static DIFlags splitFlags(DIFlags Flags, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 210 | SmallVectorImpl<DIFlags> &SplitFlags); |
| Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 211 | |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 212 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 213 | switch (MD->getMetadataID()) { |
| 214 | default: |
| 215 | return false; |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 216 | case GenericDINodeKind: |
| 217 | case DISubrangeKind: |
| 218 | case DIEnumeratorKind: |
| 219 | case DIBasicTypeKind: |
| 220 | case DIDerivedTypeKind: |
| 221 | case DICompositeTypeKind: |
| 222 | case DISubroutineTypeKind: |
| 223 | case DIFileKind: |
| 224 | case DICompileUnitKind: |
| 225 | case DISubprogramKind: |
| 226 | case DILexicalBlockKind: |
| 227 | case DILexicalBlockFileKind: |
| 228 | case DINamespaceKind: |
| 229 | case DITemplateTypeParameterKind: |
| 230 | case DITemplateValueParameterKind: |
| 231 | case DIGlobalVariableKind: |
| 232 | case DILocalVariableKind: |
| 233 | case DIObjCPropertyKind: |
| 234 | case DIImportedEntityKind: |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 235 | case DIModuleKind: |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 236 | return true; |
| 237 | } |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 238 | } |
| 239 | }; |
| 240 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 241 | template <class T> struct simplify_type<const TypedDINodeRef<T>> { |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 242 | using SimpleType = Metadata *; |
| 243 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 244 | static SimpleType getSimplifiedValue(const TypedDINodeRef<T> &MD) { |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 245 | return MD; |
| 246 | } |
| 247 | }; |
| 248 | |
| 249 | template <class T> |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 250 | struct simplify_type<TypedDINodeRef<T>> |
| 251 | : simplify_type<const TypedDINodeRef<T>> {}; |
| Duncan P. N. Exon Smith | 930f388 | 2015-04-06 18:02:43 +0000 | [diff] [blame] | 252 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 253 | /// Generic tagged DWARF-like metadata node. |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 254 | /// |
| 255 | /// An un-specialized DWARF-like metadata node. The first operand is a |
| 256 | /// (possibly empty) null-separated \a MDString header that contains arbitrary |
| 257 | /// fields. The remaining operands are \a dwarf_operands(), and are pointers |
| 258 | /// to other metadata. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 259 | class GenericDINode : public DINode { |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 260 | friend class LLVMContextImpl; |
| 261 | friend class MDNode; |
| 262 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 263 | GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash, |
| 264 | unsigned Tag, ArrayRef<Metadata *> Ops1, |
| 265 | ArrayRef<Metadata *> Ops2) |
| 266 | : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) { |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 267 | setHash(Hash); |
| 268 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 269 | ~GenericDINode() { dropAllReferences(); } |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 270 | |
| 271 | void setHash(unsigned Hash) { SubclassData32 = Hash; } |
| 272 | void recalculateHash(); |
| 273 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 274 | static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag, |
| 275 | StringRef Header, ArrayRef<Metadata *> DwarfOps, |
| 276 | StorageType Storage, bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 277 | return getImpl(Context, Tag, getCanonicalMDString(Context, Header), |
| 278 | DwarfOps, Storage, ShouldCreate); |
| 279 | } |
| 280 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 281 | static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag, |
| 282 | MDString *Header, ArrayRef<Metadata *> DwarfOps, |
| 283 | StorageType Storage, bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 284 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 285 | TempGenericDINode cloneImpl() const { |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 286 | return getTemporary( |
| 287 | getContext(), getTag(), getHeader(), |
| 288 | SmallVector<Metadata *, 4>(dwarf_op_begin(), dwarf_op_end())); |
| 289 | } |
| 290 | |
| 291 | public: |
| 292 | unsigned getHash() const { return SubclassData32; } |
| 293 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 294 | DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header, |
| 295 | ArrayRef<Metadata *> DwarfOps), |
| Duncan P. N. Exon Smith | 61e62a5 | 2015-02-02 19:55:21 +0000 | [diff] [blame] | 296 | (Tag, Header, DwarfOps)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 297 | DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header, |
| 298 | ArrayRef<Metadata *> DwarfOps), |
| Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 299 | (Tag, Header, DwarfOps)) |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 300 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 301 | /// Return a (temporary) clone of this. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 302 | TempGenericDINode clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 303 | |
| 304 | unsigned getTag() const { return SubclassData16; } |
| Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 305 | StringRef getHeader() const { return getStringOperand(0); } |
| Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 306 | MDString *getRawHeader() const { return getOperandAs<MDString>(0); } |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 307 | |
| 308 | op_iterator dwarf_op_begin() const { return op_begin() + 1; } |
| 309 | op_iterator dwarf_op_end() const { return op_end(); } |
| 310 | op_range dwarf_operands() const { |
| 311 | return op_range(dwarf_op_begin(), dwarf_op_end()); |
| 312 | } |
| 313 | |
| 314 | unsigned getNumDwarfOperands() const { return getNumOperands() - 1; } |
| 315 | const MDOperand &getDwarfOperand(unsigned I) const { |
| 316 | return getOperand(I + 1); |
| 317 | } |
| 318 | void replaceDwarfOperandWith(unsigned I, Metadata *New) { |
| 319 | replaceOperandWith(I + 1, New); |
| 320 | } |
| 321 | |
| 322 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 323 | return MD->getMetadataID() == GenericDINodeKind; |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 324 | } |
| 325 | }; |
| 326 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 327 | /// Array subrange. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 328 | /// |
| 329 | /// TODO: Merge into node for DW_TAG_array_type, which should have a custom |
| 330 | /// type. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 331 | class DISubrange : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 332 | friend class LLVMContextImpl; |
| 333 | friend class MDNode; |
| 334 | |
| 335 | int64_t Count; |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 336 | int64_t LowerBound; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 337 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 338 | DISubrange(LLVMContext &C, StorageType Storage, int64_t Count, |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 339 | int64_t LowerBound) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 340 | : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, None), |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 341 | Count(Count), LowerBound(LowerBound) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 342 | ~DISubrange() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 343 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 344 | static DISubrange *getImpl(LLVMContext &Context, int64_t Count, |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 345 | int64_t LowerBound, StorageType Storage, |
| 346 | bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 347 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 348 | TempDISubrange cloneImpl() const { |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 349 | return getTemporary(getContext(), getCount(), getLowerBound()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 353 | DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0), |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 354 | (Count, LowerBound)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 355 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 356 | TempDISubrange clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 357 | |
| Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 358 | int64_t getLowerBound() const { return LowerBound; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 359 | int64_t getCount() const { return Count; } |
| 360 | |
| 361 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 362 | return MD->getMetadataID() == DISubrangeKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 363 | } |
| 364 | }; |
| 365 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 366 | /// Enumeration value. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 367 | /// |
| 368 | /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no |
| 369 | /// longer creates a type cycle. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 370 | class DIEnumerator : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 371 | friend class LLVMContextImpl; |
| 372 | friend class MDNode; |
| 373 | |
| 374 | int64_t Value; |
| 375 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 376 | DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 377 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 378 | : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 379 | Value(Value) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 380 | ~DIEnumerator() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 381 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 382 | static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 383 | StringRef Name, StorageType Storage, |
| 384 | bool ShouldCreate = true) { |
| 385 | return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage, |
| 386 | ShouldCreate); |
| 387 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 388 | static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 389 | MDString *Name, StorageType Storage, |
| 390 | bool ShouldCreate = true); |
| 391 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 392 | TempDIEnumerator cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 393 | return getTemporary(getContext(), getValue(), getName()); |
| 394 | } |
| 395 | |
| 396 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 397 | DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, StringRef Name), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 398 | (Value, Name)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 399 | DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, MDString *Name), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 400 | (Value, Name)) |
| 401 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 402 | TempDIEnumerator clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 403 | |
| 404 | int64_t getValue() const { return Value; } |
| 405 | StringRef getName() const { return getStringOperand(0); } |
| 406 | |
| Duncan P. N. Exon Smith | 8775476 | 2015-02-13 01:14:11 +0000 | [diff] [blame] | 407 | MDString *getRawName() const { return getOperandAs<MDString>(0); } |
| 408 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 409 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 410 | return MD->getMetadataID() == DIEnumeratorKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 411 | } |
| 412 | }; |
| 413 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 414 | /// Base class for scope-like contexts. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 415 | /// |
| 416 | /// Base class for lexical scopes and types (which are also declaration |
| 417 | /// contexts). |
| 418 | /// |
| 419 | /// TODO: Separate the concepts of declaration contexts and lexical scopes. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 420 | class DIScope : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 421 | protected: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 422 | DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 423 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 424 | : DINode(C, ID, Storage, Tag, Ops) {} |
| 425 | ~DIScope() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 426 | |
| 427 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 428 | DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 429 | |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 430 | inline StringRef getFilename() const; |
| 431 | inline StringRef getDirectory() const; |
| 432 | |
| Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 433 | StringRef getName() const; |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 434 | DIScopeRef getScope() const; |
| Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 435 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 436 | /// Return the raw underlying file. |
| Duncan P. N. Exon Smith | 2c6a0a9 | 2015-02-28 21:47:02 +0000 | [diff] [blame] | 437 | /// |
| Saleem Abdulrasool | 2dc8cb9 | 2017-04-28 17:18:28 +0000 | [diff] [blame] | 438 | /// A \a DIFile is a \a DIScope, but it doesn't point at a separate file |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 439 | /// (it\em is the file). If \c this is an \a DIFile, we need to return \c |
| Duncan P. N. Exon Smith | 2c6a0a9 | 2015-02-28 21:47:02 +0000 | [diff] [blame] | 440 | /// this. Otherwise, return the first operand, which is where all other |
| 441 | /// subclasses store their file pointer. |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 442 | Metadata *getRawFile() const { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 443 | return isa<DIFile>(this) ? const_cast<DIScope *>(this) |
| Duncan P. N. Exon Smith | 3a46c14 | 2015-02-28 21:58:10 +0000 | [diff] [blame] | 444 | : static_cast<Metadata *>(getOperand(0)); |
| Duncan P. N. Exon Smith | 2c6a0a9 | 2015-02-28 21:47:02 +0000 | [diff] [blame] | 445 | } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 446 | |
| 447 | static bool classof(const Metadata *MD) { |
| 448 | switch (MD->getMetadataID()) { |
| 449 | default: |
| 450 | return false; |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 451 | case DIBasicTypeKind: |
| 452 | case DIDerivedTypeKind: |
| 453 | case DICompositeTypeKind: |
| 454 | case DISubroutineTypeKind: |
| 455 | case DIFileKind: |
| 456 | case DICompileUnitKind: |
| 457 | case DISubprogramKind: |
| 458 | case DILexicalBlockKind: |
| 459 | case DILexicalBlockFileKind: |
| 460 | case DINamespaceKind: |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 461 | case DIModuleKind: |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 462 | return true; |
| 463 | } |
| 464 | } |
| 465 | }; |
| 466 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 467 | /// File. |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 468 | /// |
| 469 | /// TODO: Merge with directory/file node (including users). |
| 470 | /// TODO: Canonicalize paths on creation. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 471 | class DIFile : public DIScope { |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 472 | friend class LLVMContextImpl; |
| 473 | friend class MDNode; |
| 474 | |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 475 | public: |
| 476 | enum ChecksumKind { |
| 477 | CSK_None, |
| 478 | CSK_MD5, |
| 479 | CSK_SHA1, |
| 480 | CSK_Last = CSK_SHA1 // Should be last enumeration. |
| 481 | }; |
| 482 | |
| 483 | private: |
| 484 | ChecksumKind CSKind; |
| 485 | |
| 486 | DIFile(LLVMContext &C, StorageType Storage, ChecksumKind CSK, |
| 487 | ArrayRef<Metadata *> Ops) |
| 488 | : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops), |
| 489 | CSKind(CSK) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 490 | ~DIFile() = default; |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 491 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 492 | static DIFile *getImpl(LLVMContext &Context, StringRef Filename, |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 493 | StringRef Directory, ChecksumKind CSK, StringRef CS, |
| 494 | StorageType Storage, bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 495 | return getImpl(Context, getCanonicalMDString(Context, Filename), |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 496 | getCanonicalMDString(Context, Directory), CSK, |
| 497 | getCanonicalMDString(Context, CS), Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 498 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 499 | static DIFile *getImpl(LLVMContext &Context, MDString *Filename, |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 500 | MDString *Directory, ChecksumKind CSK, MDString *CS, |
| 501 | StorageType Storage, bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 502 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 503 | TempDIFile cloneImpl() const { |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 504 | return getTemporary(getContext(), getFilename(), getDirectory(), |
| 505 | getChecksumKind(), getChecksum()); |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | public: |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 509 | DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory, |
| 510 | ChecksumKind CSK = CSK_None, |
| 511 | StringRef CS = StringRef()), |
| 512 | (Filename, Directory, CSK, CS)) |
| 513 | DEFINE_MDNODE_GET(DIFile, (MDString *Filename, MDString *Directory, |
| 514 | ChecksumKind CSK = CSK_None, |
| 515 | MDString *CS = nullptr), |
| 516 | (Filename, Directory, CSK, CS)) |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 517 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 518 | TempDIFile clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 519 | |
| 520 | StringRef getFilename() const { return getStringOperand(0); } |
| 521 | StringRef getDirectory() const { return getStringOperand(1); } |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 522 | StringRef getChecksum() const { return getStringOperand(2); } |
| 523 | ChecksumKind getChecksumKind() const { return CSKind; } |
| 524 | StringRef getChecksumKindAsString() const; |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 525 | |
| 526 | MDString *getRawFilename() const { return getOperandAs<MDString>(0); } |
| 527 | MDString *getRawDirectory() const { return getOperandAs<MDString>(1); } |
| Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 528 | MDString *getRawChecksum() const { return getOperandAs<MDString>(2); } |
| 529 | |
| 530 | static ChecksumKind getChecksumKind(StringRef CSKindStr); |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 531 | |
| 532 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 533 | return MD->getMetadataID() == DIFileKind; |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 534 | } |
| 535 | }; |
| 536 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 537 | StringRef DIScope::getFilename() const { |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 538 | if (auto *F = getFile()) |
| 539 | return F->getFilename(); |
| 540 | return ""; |
| 541 | } |
| 542 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 543 | StringRef DIScope::getDirectory() const { |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 544 | if (auto *F = getFile()) |
| 545 | return F->getDirectory(); |
| 546 | return ""; |
| 547 | } |
| 548 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 549 | /// Base class for types. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 550 | /// |
| 551 | /// TODO: Remove the hardcoded name and context, since many types don't use |
| 552 | /// them. |
| 553 | /// TODO: Split up flags. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 554 | class DIType : public DIScope { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 555 | unsigned Line; |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 556 | DIFlags Flags; |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 557 | uint64_t SizeInBits; |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 558 | uint64_t OffsetInBits; |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 559 | uint32_t AlignInBits; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 560 | |
| 561 | protected: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 562 | DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 563 | unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 564 | uint64_t OffsetInBits, DIFlags Flags, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 565 | : DIScope(C, ID, Storage, Tag, Ops) { |
| 566 | init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags); |
| 567 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 568 | ~DIType() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 569 | |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 570 | void init(unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 571 | uint64_t OffsetInBits, DIFlags Flags) { |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 572 | this->Line = Line; |
| 573 | this->Flags = Flags; |
| 574 | this->SizeInBits = SizeInBits; |
| 575 | this->AlignInBits = AlignInBits; |
| 576 | this->OffsetInBits = OffsetInBits; |
| 577 | } |
| 578 | |
| 579 | /// Change fields in place. |
| 580 | void mutate(unsigned Tag, unsigned Line, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 581 | uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags) { |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 582 | assert(isDistinct() && "Only distinct nodes can mutate"); |
| 583 | setTag(Tag); |
| 584 | init(Line, SizeInBits, AlignInBits, OffsetInBits, Flags); |
| 585 | } |
| 586 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 587 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 588 | TempDIType clone() const { |
| 589 | return TempDIType(cast<DIType>(MDNode::clone().release())); |
| Duncan P. N. Exon Smith | b353849 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 592 | unsigned getLine() const { return Line; } |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 593 | uint64_t getSizeInBits() const { return SizeInBits; } |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 594 | uint32_t getAlignInBits() const { return AlignInBits; } |
| 595 | uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; } |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 596 | uint64_t getOffsetInBits() const { return OffsetInBits; } |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 597 | DIFlags getFlags() const { return Flags; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 598 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 599 | DIScopeRef getScope() const { return DIScopeRef(getRawScope()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 600 | StringRef getName() const { return getStringOperand(2); } |
| 601 | |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 602 | |
| 603 | Metadata *getRawScope() const { return getOperand(1); } |
| Duncan P. N. Exon Smith | 09e03f3 | 2015-02-13 01:14:58 +0000 | [diff] [blame] | 604 | MDString *getRawName() const { return getOperandAs<MDString>(2); } |
| 605 | |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 606 | void setFlags(DIFlags NewFlags) { |
| Duncan P. N. Exon Smith | b353849 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 607 | assert(!isUniqued() && "Cannot set flags on uniqued nodes"); |
| 608 | Flags = NewFlags; |
| 609 | } |
| 610 | |
| Duncan P. N. Exon Smith | aecab7a | 2015-04-07 01:24:30 +0000 | [diff] [blame] | 611 | bool isPrivate() const { |
| 612 | return (getFlags() & FlagAccessibility) == FlagPrivate; |
| 613 | } |
| 614 | bool isProtected() const { |
| 615 | return (getFlags() & FlagAccessibility) == FlagProtected; |
| 616 | } |
| 617 | bool isPublic() const { |
| 618 | return (getFlags() & FlagAccessibility) == FlagPublic; |
| 619 | } |
| 620 | bool isForwardDecl() const { return getFlags() & FlagFwdDecl; } |
| 621 | bool isAppleBlockExtension() const { return getFlags() & FlagAppleBlock; } |
| 622 | bool isBlockByrefStruct() const { return getFlags() & FlagBlockByrefStruct; } |
| 623 | bool isVirtual() const { return getFlags() & FlagVirtual; } |
| 624 | bool isArtificial() const { return getFlags() & FlagArtificial; } |
| 625 | bool isObjectPointer() const { return getFlags() & FlagObjectPointer; } |
| 626 | bool isObjcClassComplete() const { |
| 627 | return getFlags() & FlagObjcClassComplete; |
| 628 | } |
| 629 | bool isVector() const { return getFlags() & FlagVector; } |
| David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 630 | bool isBitField() const { return getFlags() & FlagBitField; } |
| Duncan P. N. Exon Smith | aecab7a | 2015-04-07 01:24:30 +0000 | [diff] [blame] | 631 | bool isStaticMember() const { return getFlags() & FlagStaticMember; } |
| 632 | bool isLValueReference() const { return getFlags() & FlagLValueReference; } |
| 633 | bool isRValueReference() const { return getFlags() & FlagRValueReference; } |
| 634 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 635 | static bool classof(const Metadata *MD) { |
| 636 | switch (MD->getMetadataID()) { |
| 637 | default: |
| 638 | return false; |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 639 | case DIBasicTypeKind: |
| 640 | case DIDerivedTypeKind: |
| 641 | case DICompositeTypeKind: |
| 642 | case DISubroutineTypeKind: |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 643 | return true; |
| 644 | } |
| 645 | } |
| 646 | }; |
| 647 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 648 | /// Basic type, like 'int' or 'float'. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 649 | /// |
| 650 | /// TODO: Split out DW_TAG_unspecified_type. |
| 651 | /// TODO: Drop unused accessors. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 652 | class DIBasicType : public DIType { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 653 | friend class LLVMContextImpl; |
| 654 | friend class MDNode; |
| 655 | |
| 656 | unsigned Encoding; |
| 657 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 658 | DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 659 | uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 660 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 661 | : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 662 | FlagZero, Ops), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 663 | Encoding(Encoding) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 664 | ~DIBasicType() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 665 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 666 | static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag, |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 667 | StringRef Name, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 668 | uint32_t AlignInBits, unsigned Encoding, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 669 | StorageType Storage, bool ShouldCreate = true) { |
| 670 | return getImpl(Context, Tag, getCanonicalMDString(Context, Name), |
| 671 | SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate); |
| 672 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 673 | static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag, |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 674 | MDString *Name, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 675 | uint32_t AlignInBits, unsigned Encoding, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 676 | StorageType Storage, bool ShouldCreate = true); |
| 677 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 678 | TempDIBasicType cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 679 | return getTemporary(getContext(), getTag(), getName(), getSizeInBits(), |
| 680 | getAlignInBits(), getEncoding()); |
| 681 | } |
| 682 | |
| 683 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 684 | DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name), |
| Duncan P. N. Exon Smith | b353849 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 685 | (Tag, Name, 0, 0, 0)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 686 | DEFINE_MDNODE_GET(DIBasicType, |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 687 | (unsigned Tag, StringRef Name, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 688 | uint32_t AlignInBits, unsigned Encoding), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 689 | (Tag, Name, SizeInBits, AlignInBits, Encoding)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 690 | DEFINE_MDNODE_GET(DIBasicType, |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 691 | (unsigned Tag, MDString *Name, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 692 | uint32_t AlignInBits, unsigned Encoding), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 693 | (Tag, Name, SizeInBits, AlignInBits, Encoding)) |
| 694 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 695 | TempDIBasicType clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 696 | |
| 697 | unsigned getEncoding() const { return Encoding; } |
| 698 | |
| 699 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 700 | return MD->getMetadataID() == DIBasicTypeKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 701 | } |
| 702 | }; |
| 703 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 704 | /// Derived types. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 705 | /// |
| 706 | /// This includes qualified types, pointers, references, friends, typedefs, and |
| 707 | /// class members. |
| 708 | /// |
| 709 | /// TODO: Split out members (inheritance, fields, methods, etc.). |
| Duncan P. N. Exon Smith | 338aef0 | 2015-07-24 20:16:36 +0000 | [diff] [blame] | 710 | class DIDerivedType : public DIType { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 711 | friend class LLVMContextImpl; |
| 712 | friend class MDNode; |
| 713 | |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 714 | /// \brief The DWARF address space of the memory pointed to or referenced by a |
| 715 | /// pointer or reference type respectively. |
| 716 | Optional<unsigned> DWARFAddressSpace; |
| 717 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 718 | DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 719 | unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 720 | uint64_t OffsetInBits, Optional<unsigned> DWARFAddressSpace, |
| 721 | DIFlags Flags, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | 338aef0 | 2015-07-24 20:16:36 +0000 | [diff] [blame] | 722 | : DIType(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 723 | AlignInBits, OffsetInBits, Flags, Ops), |
| 724 | DWARFAddressSpace(DWARFAddressSpace) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 725 | ~DIDerivedType() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 726 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 727 | static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag, |
| 728 | StringRef Name, DIFile *File, unsigned Line, |
| 729 | DIScopeRef Scope, DITypeRef BaseType, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 730 | uint64_t SizeInBits, uint32_t AlignInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 731 | uint64_t OffsetInBits, |
| 732 | Optional<unsigned> DWARFAddressSpace, |
| 733 | DIFlags Flags, Metadata *ExtraData, |
| 734 | StorageType Storage, bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 735 | return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File, |
| 736 | Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 737 | DWARFAddressSpace, Flags, ExtraData, Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 738 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 739 | static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 740 | MDString *Name, Metadata *File, unsigned Line, |
| 741 | Metadata *Scope, Metadata *BaseType, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 742 | uint64_t SizeInBits, uint32_t AlignInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 743 | uint64_t OffsetInBits, |
| 744 | Optional<unsigned> DWARFAddressSpace, |
| 745 | DIFlags Flags, Metadata *ExtraData, |
| 746 | StorageType Storage, bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 747 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 748 | TempDIDerivedType cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 749 | return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(), |
| 750 | getScope(), getBaseType(), getSizeInBits(), |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 751 | getAlignInBits(), getOffsetInBits(), |
| 752 | getDWARFAddressSpace(), getFlags(), getExtraData()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 756 | DEFINE_MDNODE_GET(DIDerivedType, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 757 | (unsigned Tag, MDString *Name, Metadata *File, |
| 758 | unsigned Line, Metadata *Scope, Metadata *BaseType, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 759 | uint64_t SizeInBits, uint32_t AlignInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 760 | uint64_t OffsetInBits, |
| 761 | Optional<unsigned> DWARFAddressSpace, DIFlags Flags, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 762 | Metadata *ExtraData = nullptr), |
| 763 | (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 764 | AlignInBits, OffsetInBits, DWARFAddressSpace, Flags, |
| 765 | ExtraData)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 766 | DEFINE_MDNODE_GET(DIDerivedType, |
| 767 | (unsigned Tag, StringRef Name, DIFile *File, unsigned Line, |
| 768 | DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 769 | uint32_t AlignInBits, uint64_t OffsetInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 770 | Optional<unsigned> DWARFAddressSpace, DIFlags Flags, |
| 771 | Metadata *ExtraData = nullptr), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 772 | (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 773 | AlignInBits, OffsetInBits, DWARFAddressSpace, Flags, |
| 774 | ExtraData)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 775 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 776 | TempDIDerivedType clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 777 | |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 778 | /// Get the base type this is derived from. |
| Duncan P. N. Exon Smith | 338aef0 | 2015-07-24 20:16:36 +0000 | [diff] [blame] | 779 | DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); } |
| 780 | Metadata *getRawBaseType() const { return getOperand(3); } |
| 781 | |
| Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 782 | /// \returns The DWARF address space of the memory pointed to or referenced by |
| 783 | /// a pointer or reference type respectively. |
| 784 | Optional<unsigned> getDWARFAddressSpace() const { return DWARFAddressSpace; } |
| 785 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 786 | /// Get extra data associated with this derived type. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 787 | /// |
| 788 | /// Class type for pointer-to-members, objective-c property node for ivars, |
| 789 | /// or global constant wrapper for static members. |
| 790 | /// |
| 791 | /// TODO: Separate out types that need this extra operand: pointer-to-member |
| 792 | /// types and member fields (static members and ivars). |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 793 | Metadata *getExtraData() const { return getRawExtraData(); } |
| 794 | Metadata *getRawExtraData() const { return getOperand(4); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 795 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 796 | /// Get casted version of extra data. |
| Duncan P. N. Exon Smith | 0bf8d4c | 2015-04-13 23:36:36 +0000 | [diff] [blame] | 797 | /// @{ |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 798 | DITypeRef getClassType() const { |
| Duncan P. N. Exon Smith | 0bf8d4c | 2015-04-13 23:36:36 +0000 | [diff] [blame] | 799 | assert(getTag() == dwarf::DW_TAG_ptr_to_member_type); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 800 | return DITypeRef(getExtraData()); |
| Duncan P. N. Exon Smith | 0bf8d4c | 2015-04-13 23:36:36 +0000 | [diff] [blame] | 801 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 802 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 803 | DIObjCProperty *getObjCProperty() const { |
| 804 | return dyn_cast_or_null<DIObjCProperty>(getExtraData()); |
| Duncan P. N. Exon Smith | 0bf8d4c | 2015-04-13 23:36:36 +0000 | [diff] [blame] | 805 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 806 | |
| David Majnemer | 9319cbc | 2016-06-30 03:00:20 +0000 | [diff] [blame] | 807 | Constant *getStorageOffsetInBits() const { |
| 808 | assert(getTag() == dwarf::DW_TAG_member && isBitField()); |
| 809 | if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData())) |
| 810 | return C->getValue(); |
| 811 | return nullptr; |
| 812 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 813 | |
| Duncan P. N. Exon Smith | 0bf8d4c | 2015-04-13 23:36:36 +0000 | [diff] [blame] | 814 | Constant *getConstant() const { |
| 815 | assert(getTag() == dwarf::DW_TAG_member && isStaticMember()); |
| 816 | if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData())) |
| 817 | return C->getValue(); |
| 818 | return nullptr; |
| 819 | } |
| 820 | /// @} |
| 821 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 822 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 823 | return MD->getMetadataID() == DIDerivedTypeKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 824 | } |
| 825 | }; |
| 826 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 827 | /// Composite types. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 828 | /// |
| 829 | /// TODO: Detach from DerivedTypeBase (split out MDEnumType?). |
| 830 | /// TODO: Create a custom, unrelated node for DW_TAG_array_type. |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 831 | class DICompositeType : public DIType { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 832 | friend class LLVMContextImpl; |
| 833 | friend class MDNode; |
| 834 | |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 835 | unsigned RuntimeLang; |
| 836 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 837 | DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag, |
| Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 838 | unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 839 | uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 840 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 841 | : DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits, |
| 842 | AlignInBits, OffsetInBits, Flags, Ops), |
| 843 | RuntimeLang(RuntimeLang) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 844 | ~DICompositeType() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 845 | |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 846 | /// Change fields in place. |
| 847 | void mutate(unsigned Tag, unsigned Line, unsigned RuntimeLang, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 848 | uint64_t SizeInBits, uint32_t AlignInBits, |
| 849 | uint64_t OffsetInBits, DIFlags Flags) { |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 850 | assert(isDistinct() && "Only distinct nodes can mutate"); |
| 851 | assert(getRawIdentifier() && "Only ODR-uniqued nodes should mutate"); |
| 852 | this->RuntimeLang = RuntimeLang; |
| 853 | DIType::mutate(Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags); |
| 854 | } |
| 855 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 856 | static DICompositeType * |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 857 | getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 858 | unsigned Line, DIScopeRef Scope, DITypeRef BaseType, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 859 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 860 | DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 861 | DITypeRef VTableHolder, DITemplateParameterArray TemplateParams, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 862 | StringRef Identifier, StorageType Storage, bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 863 | return getImpl( |
| 864 | Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope, |
| 865 | BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(), |
| 866 | RuntimeLang, VTableHolder, TemplateParams.get(), |
| 867 | getCanonicalMDString(Context, Identifier), Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 868 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 869 | static DICompositeType * |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 870 | getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, |
| 871 | unsigned Line, Metadata *Scope, Metadata *BaseType, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 872 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 873 | DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 874 | Metadata *VTableHolder, Metadata *TemplateParams, |
| 875 | MDString *Identifier, StorageType Storage, bool ShouldCreate = true); |
| 876 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 877 | TempDICompositeType cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 878 | return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(), |
| 879 | getScope(), getBaseType(), getSizeInBits(), |
| 880 | getAlignInBits(), getOffsetInBits(), getFlags(), |
| 881 | getElements(), getRuntimeLang(), getVTableHolder(), |
| 882 | getTemplateParams(), getIdentifier()); |
| 883 | } |
| 884 | |
| 885 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 886 | DEFINE_MDNODE_GET(DICompositeType, |
| 887 | (unsigned Tag, StringRef Name, DIFile *File, unsigned Line, |
| 888 | DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 889 | uint32_t AlignInBits, uint64_t OffsetInBits, |
| 890 | DIFlags Flags, DINodeArray Elements, unsigned RuntimeLang, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 891 | DITypeRef VTableHolder, |
| 892 | DITemplateParameterArray TemplateParams = nullptr, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 893 | StringRef Identifier = ""), |
| 894 | (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 895 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 896 | VTableHolder, TemplateParams, Identifier)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 897 | DEFINE_MDNODE_GET(DICompositeType, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 898 | (unsigned Tag, MDString *Name, Metadata *File, |
| 899 | unsigned Line, Metadata *Scope, Metadata *BaseType, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 900 | uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 901 | uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 902 | unsigned RuntimeLang, Metadata *VTableHolder, |
| 903 | Metadata *TemplateParams = nullptr, |
| 904 | MDString *Identifier = nullptr), |
| 905 | (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 906 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 907 | VTableHolder, TemplateParams, Identifier)) |
| 908 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 909 | TempDICompositeType clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 910 | |
| Duncan P. N. Exon Smith | 0b0271e | 2016-04-19 14:55:09 +0000 | [diff] [blame] | 911 | /// Get a DICompositeType with the given ODR identifier. |
| 912 | /// |
| 913 | /// If \a LLVMContext::isODRUniquingDebugTypes(), gets the mapped |
| 914 | /// DICompositeType for the given ODR \c Identifier. If none exists, creates |
| 915 | /// a new node. |
| 916 | /// |
| 917 | /// Else, returns \c nullptr. |
| 918 | static DICompositeType * |
| 919 | getODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, |
| 920 | MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 921 | Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 922 | uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, |
| Duncan P. N. Exon Smith | 0b0271e | 2016-04-19 14:55:09 +0000 | [diff] [blame] | 923 | unsigned RuntimeLang, Metadata *VTableHolder, |
| 924 | Metadata *TemplateParams); |
| 925 | static DICompositeType *getODRTypeIfExists(LLVMContext &Context, |
| 926 | MDString &Identifier); |
| 927 | |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 928 | /// Build a DICompositeType with the given ODR identifier. |
| 929 | /// |
| 930 | /// Looks up the mapped DICompositeType for the given ODR \c Identifier. If |
| 931 | /// it doesn't exist, creates a new one. If it does exist and \a |
| 932 | /// isForwardDecl(), and the new arguments would be a definition, mutates the |
| 933 | /// the type in place. In either case, returns the type. |
| 934 | /// |
| 935 | /// If not \a LLVMContext::isODRUniquingDebugTypes(), this function returns |
| 936 | /// nullptr. |
| 937 | static DICompositeType * |
| 938 | buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, |
| 939 | MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, |
| Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 940 | Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 941 | uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, |
| Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 942 | unsigned RuntimeLang, Metadata *VTableHolder, |
| 943 | Metadata *TemplateParams); |
| 944 | |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 945 | DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); } |
| 946 | DINodeArray getElements() const { |
| 947 | return cast_or_null<MDTuple>(getRawElements()); |
| 948 | } |
| 949 | DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); } |
| 950 | DITemplateParameterArray getTemplateParams() const { |
| 951 | return cast_or_null<MDTuple>(getRawTemplateParams()); |
| 952 | } |
| 953 | StringRef getIdentifier() const { return getStringOperand(7); } |
| 954 | unsigned getRuntimeLang() const { return RuntimeLang; } |
| 955 | |
| 956 | Metadata *getRawBaseType() const { return getOperand(3); } |
| 957 | Metadata *getRawElements() const { return getOperand(4); } |
| 958 | Metadata *getRawVTableHolder() const { return getOperand(5); } |
| 959 | Metadata *getRawTemplateParams() const { return getOperand(6); } |
| 960 | MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); } |
| 961 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 962 | /// Replace operands. |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 963 | /// |
| 964 | /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision |
| 965 | /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track |
| 966 | /// of its movement if necessary. |
| 967 | /// @{ |
| 968 | void replaceElements(DINodeArray Elements) { |
| 969 | #ifndef NDEBUG |
| 970 | for (DINode *Op : getElements()) |
| David Majnemer | 4253126 | 2016-08-12 03:55:06 +0000 | [diff] [blame] | 971 | assert(is_contained(Elements->operands(), Op) && |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 972 | "Lost a member during member list replacement"); |
| 973 | #endif |
| 974 | replaceOperandWith(4, Elements.get()); |
| 975 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 976 | |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 977 | void replaceVTableHolder(DITypeRef VTableHolder) { |
| 978 | replaceOperandWith(5, VTableHolder); |
| 979 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 980 | |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 981 | void replaceTemplateParams(DITemplateParameterArray TemplateParams) { |
| 982 | replaceOperandWith(6, TemplateParams.get()); |
| 983 | } |
| 984 | /// @} |
| 985 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 986 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 987 | return MD->getMetadataID() == DICompositeTypeKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 988 | } |
| 989 | }; |
| 990 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 991 | /// Type array for a subprogram. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 992 | /// |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 993 | /// TODO: Fold the array of types in directly as operands. |
| 994 | class DISubroutineType : public DIType { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 995 | friend class LLVMContextImpl; |
| 996 | friend class MDNode; |
| 997 | |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 998 | /// The calling convention used with DW_AT_calling_convention. Actually of |
| 999 | /// type dwarf::CallingConvention. |
| 1000 | uint8_t CC; |
| 1001 | |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1002 | DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags, |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1003 | uint8_t CC, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 1004 | : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1005 | 0, 0, 0, 0, Flags, Ops), |
| 1006 | CC(CC) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1007 | ~DISubroutineType() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1008 | |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1009 | static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags, |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1010 | uint8_t CC, DITypeRefArray TypeArray, |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1011 | StorageType Storage, |
| 1012 | bool ShouldCreate = true) { |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1013 | return getImpl(Context, Flags, CC, TypeArray.get(), Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1014 | } |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1015 | static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags, |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1016 | uint8_t CC, Metadata *TypeArray, |
| 1017 | StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1018 | bool ShouldCreate = true); |
| 1019 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1020 | TempDISubroutineType cloneImpl() const { |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1021 | return getTemporary(getContext(), getFlags(), getCC(), getTypeArray()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1025 | DEFINE_MDNODE_GET(DISubroutineType, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1026 | (DIFlags Flags, uint8_t CC, DITypeRefArray TypeArray), |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1027 | (Flags, CC, TypeArray)) |
| 1028 | DEFINE_MDNODE_GET(DISubroutineType, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1029 | (DIFlags Flags, uint8_t CC, Metadata *TypeArray), |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1030 | (Flags, CC, TypeArray)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1031 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1032 | TempDISubroutineType clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1033 | |
| Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1034 | uint8_t getCC() const { return CC; } |
| 1035 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1036 | DITypeRefArray getTypeArray() const { |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1037 | return cast_or_null<MDTuple>(getRawTypeArray()); |
| 1038 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 1039 | |
| Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 1040 | Metadata *getRawTypeArray() const { return getOperand(3); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1041 | |
| 1042 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1043 | return MD->getMetadataID() == DISubroutineTypeKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1044 | } |
| 1045 | }; |
| 1046 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1047 | /// Compile unit. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1048 | class DICompileUnit : public DIScope { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1049 | friend class LLVMContextImpl; |
| 1050 | friend class MDNode; |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 1051 | |
| Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1052 | public: |
| 1053 | enum DebugEmissionKind : unsigned { |
| 1054 | NoDebug = 0, |
| 1055 | FullDebug, |
| 1056 | LineTablesOnly, |
| 1057 | LastEmissionKind = LineTablesOnly |
| 1058 | }; |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 1059 | |
| Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1060 | static Optional<DebugEmissionKind> getEmissionKind(StringRef Str); |
| 1061 | static const char *EmissionKindString(DebugEmissionKind EK); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1062 | |
| Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1063 | private: |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1064 | unsigned SourceLanguage; |
| 1065 | bool IsOptimized; |
| 1066 | unsigned RuntimeVersion; |
| 1067 | unsigned EmissionKind; |
| Adrian Prantl | 1f599f9 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1068 | uint64_t DWOId; |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1069 | bool SplitDebugInlining; |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1070 | bool DebugInfoForProfiling; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1071 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1072 | DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1073 | bool IsOptimized, unsigned RuntimeVersion, |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1074 | unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1075 | bool DebugInfoForProfiling, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1076 | : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1077 | SourceLanguage(SourceLanguage), IsOptimized(IsOptimized), |
| Adrian Prantl | 1f599f9 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1078 | RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1079 | DWOId(DWOId), SplitDebugInlining(SplitDebugInlining), |
| 1080 | DebugInfoForProfiling(DebugInfoForProfiling) { |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1081 | assert(Storage != Uniqued); |
| 1082 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1083 | ~DICompileUnit() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1084 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1085 | static DICompileUnit * |
| 1086 | getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1087 | StringRef Producer, bool IsOptimized, StringRef Flags, |
| 1088 | unsigned RuntimeVersion, StringRef SplitDebugFilename, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1089 | unsigned EmissionKind, DICompositeTypeArray EnumTypes, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1090 | DIScopeArray RetainedTypes, |
| 1091 | DIGlobalVariableExpressionArray GlobalVariables, |
| Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1092 | DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1093 | uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, |
| 1094 | StorageType Storage, bool ShouldCreate = true) { |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1095 | return getImpl(Context, SourceLanguage, File, |
| 1096 | getCanonicalMDString(Context, Producer), IsOptimized, |
| 1097 | getCanonicalMDString(Context, Flags), RuntimeVersion, |
| 1098 | getCanonicalMDString(Context, SplitDebugFilename), |
| 1099 | EmissionKind, EnumTypes.get(), RetainedTypes.get(), |
| 1100 | GlobalVariables.get(), ImportedEntities.get(), Macros.get(), |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1101 | DWOId, SplitDebugInlining, DebugInfoForProfiling, Storage, |
| 1102 | ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1103 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1104 | static DICompileUnit * |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1105 | getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File, |
| 1106 | MDString *Producer, bool IsOptimized, MDString *Flags, |
| 1107 | unsigned RuntimeVersion, MDString *SplitDebugFilename, |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1108 | unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes, |
| Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1109 | Metadata *GlobalVariables, Metadata *ImportedEntities, |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1110 | Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1111 | bool DebugInfoForProfiling, StorageType Storage, |
| 1112 | bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1113 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1114 | TempDICompileUnit cloneImpl() const { |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1115 | return getTemporary(getContext(), getSourceLanguage(), getFile(), |
| 1116 | getProducer(), isOptimized(), getFlags(), |
| 1117 | getRuntimeVersion(), getSplitDebugFilename(), |
| 1118 | getEmissionKind(), getEnumTypes(), getRetainedTypes(), |
| 1119 | getGlobalVariables(), getImportedEntities(), |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1120 | getMacros(), DWOId, getSplitDebugInlining(), |
| 1121 | getDebugInfoForProfiling()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 1124 | public: |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1125 | static void get() = delete; |
| 1126 | static void getIfExists() = delete; |
| 1127 | |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1128 | DEFINE_MDNODE_GET_DISTINCT_TEMPORARY( |
| 1129 | DICompileUnit, |
| 1130 | (unsigned SourceLanguage, DIFile *File, StringRef Producer, |
| 1131 | bool IsOptimized, StringRef Flags, unsigned RuntimeVersion, |
| Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1132 | StringRef SplitDebugFilename, DebugEmissionKind EmissionKind, |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1133 | DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1134 | DIGlobalVariableExpressionArray GlobalVariables, |
| Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1135 | DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1136 | uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling), |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1137 | (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion, |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1138 | SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1139 | GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining, |
| 1140 | DebugInfoForProfiling)) |
| Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1141 | DEFINE_MDNODE_GET_DISTINCT_TEMPORARY( |
| Adrian Prantl | 1f599f9 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1142 | DICompileUnit, |
| 1143 | (unsigned SourceLanguage, Metadata *File, MDString *Producer, |
| 1144 | bool IsOptimized, MDString *Flags, unsigned RuntimeVersion, |
| 1145 | MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes, |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1146 | Metadata *RetainedTypes, Metadata *GlobalVariables, |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1147 | Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1148 | bool SplitDebugInlining, bool DebugInfoForProfiling), |
| Adrian Prantl | 1f599f9 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1149 | (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion, |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1150 | SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes, |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1151 | GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining, |
| 1152 | DebugInfoForProfiling)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1153 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1154 | TempDICompileUnit clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1155 | |
| 1156 | unsigned getSourceLanguage() const { return SourceLanguage; } |
| 1157 | bool isOptimized() const { return IsOptimized; } |
| 1158 | unsigned getRuntimeVersion() const { return RuntimeVersion; } |
| Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1159 | DebugEmissionKind getEmissionKind() const { |
| 1160 | return (DebugEmissionKind)EmissionKind; |
| 1161 | } |
| Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1162 | bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1163 | StringRef getProducer() const { return getStringOperand(1); } |
| 1164 | StringRef getFlags() const { return getStringOperand(2); } |
| 1165 | StringRef getSplitDebugFilename() const { return getStringOperand(3); } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1166 | DICompositeTypeArray getEnumTypes() const { |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1167 | return cast_or_null<MDTuple>(getRawEnumTypes()); |
| 1168 | } |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1169 | DIScopeArray getRetainedTypes() const { |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1170 | return cast_or_null<MDTuple>(getRawRetainedTypes()); |
| 1171 | } |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1172 | DIGlobalVariableExpressionArray getGlobalVariables() const { |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1173 | return cast_or_null<MDTuple>(getRawGlobalVariables()); |
| 1174 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1175 | DIImportedEntityArray getImportedEntities() const { |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1176 | return cast_or_null<MDTuple>(getRawImportedEntities()); |
| 1177 | } |
| Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1178 | DIMacroNodeArray getMacros() const { |
| 1179 | return cast_or_null<MDTuple>(getRawMacros()); |
| 1180 | } |
| Adrian Prantl | fbfc58e | 2015-09-22 23:21:03 +0000 | [diff] [blame] | 1181 | uint64_t getDWOId() const { return DWOId; } |
| Adrian Prantl | 4410392 | 2015-09-22 23:21:06 +0000 | [diff] [blame] | 1182 | void setDWOId(uint64_t DwoId) { DWOId = DwoId; } |
| David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 1183 | bool getSplitDebugInlining() const { return SplitDebugInlining; } |
| 1184 | void setSplitDebugInlining(bool SplitDebugInlining) { |
| 1185 | this->SplitDebugInlining = SplitDebugInlining; |
| 1186 | } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1187 | |
| Duncan P. N. Exon Smith | c1f1acc | 2015-02-13 01:25:10 +0000 | [diff] [blame] | 1188 | MDString *getRawProducer() const { return getOperandAs<MDString>(1); } |
| 1189 | MDString *getRawFlags() const { return getOperandAs<MDString>(2); } |
| 1190 | MDString *getRawSplitDebugFilename() const { |
| 1191 | return getOperandAs<MDString>(3); |
| 1192 | } |
| Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1193 | Metadata *getRawEnumTypes() const { return getOperand(4); } |
| 1194 | Metadata *getRawRetainedTypes() const { return getOperand(5); } |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1195 | Metadata *getRawGlobalVariables() const { return getOperand(6); } |
| 1196 | Metadata *getRawImportedEntities() const { return getOperand(7); } |
| 1197 | Metadata *getRawMacros() const { return getOperand(8); } |
| Duncan P. N. Exon Smith | c1f1acc | 2015-02-13 01:25:10 +0000 | [diff] [blame] | 1198 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1199 | /// Replace arrays. |
| Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1200 | /// |
| 1201 | /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and |
| 1202 | /// deleted on a uniquing collision. In practice, uniquing collisions on \a |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1203 | /// DICompileUnit should be fairly rare. |
| Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1204 | /// @{ |
| Adrian Prantl | 4afc1f4 | 2015-07-06 16:22:07 +0000 | [diff] [blame] | 1205 | void replaceEnumTypes(DICompositeTypeArray N) { |
| Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 1206 | replaceOperandWith(4, N.get()); |
| 1207 | } |
| Adrian Prantl | 4afc1f4 | 2015-07-06 16:22:07 +0000 | [diff] [blame] | 1208 | void replaceRetainedTypes(DITypeArray N) { |
| Adrian Prantl | 18c073a | 2015-07-02 22:32:52 +0000 | [diff] [blame] | 1209 | replaceOperandWith(5, N.get()); |
| 1210 | } |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1211 | void replaceGlobalVariables(DIGlobalVariableExpressionArray N) { |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1212 | replaceOperandWith(6, N.get()); |
| 1213 | } |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1214 | void replaceImportedEntities(DIImportedEntityArray N) { |
| Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1215 | replaceOperandWith(7, N.get()); |
| 1216 | } |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1217 | void replaceMacros(DIMacroNodeArray N) { replaceOperandWith(8, N.get()); } |
| Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1218 | /// @} |
| 1219 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1220 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1221 | return MD->getMetadataID() == DICompileUnitKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1222 | } |
| 1223 | }; |
| 1224 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1225 | /// A scope for locals. |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1226 | /// |
| 1227 | /// A legal scope for lexical blocks, local variables, and debug info |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1228 | /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a |
| 1229 | /// DILexicalBlockFile. |
| 1230 | class DILocalScope : public DIScope { |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1231 | protected: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1232 | DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1233 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1234 | : DIScope(C, ID, Storage, Tag, Ops) {} |
| 1235 | ~DILocalScope() = default; |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1236 | |
| 1237 | public: |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1238 | /// Get the subprogram for this scope. |
| Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 1239 | /// |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1240 | /// Return this if it's an \a DISubprogram; otherwise, look up the scope |
| Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 1241 | /// chain. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1242 | DISubprogram *getSubprogram() const; |
| Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 1243 | |
| Amjad Aboud | a5ba991 | 2016-04-21 16:58:49 +0000 | [diff] [blame] | 1244 | /// Get the first non DILexicalBlockFile scope of this scope. |
| 1245 | /// |
| 1246 | /// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the |
| 1247 | /// scope chain. |
| 1248 | DILocalScope *getNonLexicalBlockFileScope() const; |
| 1249 | |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1250 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1251 | return MD->getMetadataID() == DISubprogramKind || |
| 1252 | MD->getMetadataID() == DILexicalBlockKind || |
| 1253 | MD->getMetadataID() == DILexicalBlockFileKind; |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1254 | } |
| 1255 | }; |
| 1256 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1257 | /// Debug location. |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1258 | /// |
| 1259 | /// A debug location in source code, used for debug info and otherwise. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1260 | class DILocation : public MDNode { |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1261 | friend class LLVMContextImpl; |
| 1262 | friend class MDNode; |
| 1263 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1264 | DILocation(LLVMContext &C, StorageType Storage, unsigned Line, |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1265 | unsigned Column, ArrayRef<Metadata *> MDs); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1266 | ~DILocation() { dropAllReferences(); } |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1267 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1268 | static DILocation *getImpl(LLVMContext &Context, unsigned Line, |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1269 | unsigned Column, Metadata *Scope, |
| 1270 | Metadata *InlinedAt, StorageType Storage, |
| 1271 | bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1272 | static DILocation *getImpl(LLVMContext &Context, unsigned Line, |
| 1273 | unsigned Column, DILocalScope *Scope, |
| 1274 | DILocation *InlinedAt, StorageType Storage, |
| Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 1275 | bool ShouldCreate = true) { |
| 1276 | return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope), |
| 1277 | static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate); |
| 1278 | } |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1279 | |
| Dehao Chen | 726da62 | 2017-02-15 17:54:39 +0000 | [diff] [blame] | 1280 | /// With a given unsigned int \p U, use up to 13 bits to represent it. |
| 1281 | /// old_bit 1~5 --> new_bit 1~5 |
| 1282 | /// old_bit 6~12 --> new_bit 7~13 |
| 1283 | /// new_bit_6 is 0 if higher bits (7~13) are all 0 |
| 1284 | static unsigned getPrefixEncodingFromUnsigned(unsigned U) { |
| 1285 | U &= 0xfff; |
| 1286 | return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U; |
| 1287 | } |
| 1288 | |
| 1289 | /// Reverse transformation as getPrefixEncodingFromUnsigned. |
| 1290 | static unsigned getUnsignedFromPrefixEncoding(unsigned U) { |
| 1291 | return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f); |
| 1292 | } |
| 1293 | |
| 1294 | /// Returns the next component stored in discriminator. |
| 1295 | static unsigned getNextComponentInDiscriminator(unsigned D) { |
| 1296 | if ((D & 1) == 0) |
| 1297 | return D >> ((D & 0x40) ? 14 : 7); |
| 1298 | else |
| 1299 | return D >> 1; |
| 1300 | } |
| 1301 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1302 | TempDILocation cloneImpl() const { |
| Teresa Johnson | d98152b6 | 2015-12-07 15:05:44 +0000 | [diff] [blame] | 1303 | // Get the raw scope/inlinedAt since it is possible to invoke this on |
| 1304 | // a DILocation containing temporary metadata. |
| 1305 | return getTemporary(getContext(), getLine(), getColumn(), getRawScope(), |
| 1306 | getRawInlinedAt()); |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 1309 | public: |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1310 | // Disallow replacing operands. |
| 1311 | void replaceOperandWith(unsigned I, Metadata *New) = delete; |
| 1312 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1313 | DEFINE_MDNODE_GET(DILocation, |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1314 | (unsigned Line, unsigned Column, Metadata *Scope, |
| 1315 | Metadata *InlinedAt = nullptr), |
| 1316 | (Line, Column, Scope, InlinedAt)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1317 | DEFINE_MDNODE_GET(DILocation, |
| 1318 | (unsigned Line, unsigned Column, DILocalScope *Scope, |
| 1319 | DILocation *InlinedAt = nullptr), |
| Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 1320 | (Line, Column, Scope, InlinedAt)) |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1321 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1322 | /// Return a (temporary) clone of this. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1323 | TempDILocation clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1324 | |
| 1325 | unsigned getLine() const { return SubclassData32; } |
| 1326 | unsigned getColumn() const { return SubclassData16; } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1327 | DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 1328 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1329 | DILocation *getInlinedAt() const { |
| 1330 | return cast_or_null<DILocation>(getRawInlinedAt()); |
| Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1333 | DIFile *getFile() const { return getScope()->getFile(); } |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 1334 | StringRef getFilename() const { return getScope()->getFilename(); } |
| 1335 | StringRef getDirectory() const { return getScope()->getDirectory(); } |
| 1336 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1337 | /// Get the scope where this is inlined. |
| Duncan P. N. Exon Smith | 8f7bc79 | 2015-03-30 17:41:24 +0000 | [diff] [blame] | 1338 | /// |
| 1339 | /// Walk through \a getInlinedAt() and return \a getScope() from the deepest |
| 1340 | /// location. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1341 | DILocalScope *getInlinedAtScope() const { |
| Duncan P. N. Exon Smith | 8f7bc79 | 2015-03-30 17:41:24 +0000 | [diff] [blame] | 1342 | if (auto *IA = getInlinedAt()) |
| 1343 | return IA->getInlinedAtScope(); |
| 1344 | return getScope(); |
| 1345 | } |
| 1346 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1347 | /// Check whether this can be discriminated from another location. |
| Duncan P. N. Exon Smith | 63ffa21 | 2015-04-11 01:00:47 +0000 | [diff] [blame] | 1348 | /// |
| 1349 | /// Check \c this can be discriminated from \c RHS in a linetable entry. |
| 1350 | /// Scope and inlined-at chains are not recorded in the linetable, so they |
| 1351 | /// cannot be used to distinguish basic blocks. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1352 | bool canDiscriminate(const DILocation &RHS) const { |
| Robert Lougher | 426851e | 2017-01-12 20:34:35 +0000 | [diff] [blame] | 1353 | return getLine() != RHS.getLine() || |
| 1354 | getColumn() != RHS.getColumn() || |
| 1355 | getDiscriminator() != RHS.getDiscriminator() || |
| 1356 | getFilename() != RHS.getFilename() || |
| 1357 | getDirectory() != RHS.getDirectory(); |
| Duncan P. N. Exon Smith | 63ffa21 | 2015-04-11 01:00:47 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1360 | /// Get the DWARF discriminator. |
| Duncan P. N. Exon Smith | 2c8291e | 2015-04-14 00:05:13 +0000 | [diff] [blame] | 1361 | /// |
| 1362 | /// DWARF discriminators distinguish identical file locations between |
| 1363 | /// instructions that are on different basic blocks. |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1364 | /// |
| 1365 | /// There are 3 components stored in discriminator, from lower bits: |
| 1366 | /// |
| 1367 | /// Base discriminator: assigned by AddDiscriminators pass to identify IRs |
| 1368 | /// that are defined by the same source line, but |
| 1369 | /// different basic blocks. |
| 1370 | /// Duplication factor: assigned by optimizations that will scale down |
| 1371 | /// the execution frequency of the original IR. |
| 1372 | /// Copy Identifier: assigned by optimizations that clones the IR. |
| 1373 | /// Each copy of the IR will be assigned an identifier. |
| 1374 | /// |
| 1375 | /// Encoding: |
| 1376 | /// |
| 1377 | /// The above 3 components are encoded into a 32bit unsigned integer in |
| 1378 | /// order. If the lowest bit is 1, the current component is empty, and the |
| 1379 | /// next component will start in the next bit. Otherwise, the the current |
| 1380 | /// component is non-empty, and its content starts in the next bit. The |
| 1381 | /// length of each components is either 5 bit or 12 bit: if the 7th bit |
| 1382 | /// is 0, the bit 2~6 (5 bits) are used to represent the component; if the |
| 1383 | /// 7th bit is 1, the bit 2~6 (5 bits) and 8~14 (7 bits) are combined to |
| 1384 | /// represent the component. |
| 1385 | |
| Duncan P. N. Exon Smith | 2c8291e | 2015-04-14 00:05:13 +0000 | [diff] [blame] | 1386 | inline unsigned getDiscriminator() const; |
| 1387 | |
| Dehao Chen | e713000 | 2016-10-26 15:48:45 +0000 | [diff] [blame] | 1388 | /// Returns a new DILocation with updated \p Discriminator. |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1389 | inline const DILocation *cloneWithDiscriminator(unsigned Discriminator) const; |
| 1390 | |
| 1391 | /// Returns a new DILocation with updated base discriminator \p BD. |
| 1392 | inline const DILocation *setBaseDiscriminator(unsigned BD) const; |
| 1393 | |
| 1394 | /// Returns the duplication factor stored in the discriminator. |
| 1395 | inline unsigned getDuplicationFactor() const; |
| 1396 | |
| 1397 | /// Returns the copy identifier stored in the discriminator. |
| 1398 | inline unsigned getCopyIdentifier() const; |
| 1399 | |
| 1400 | /// Returns the base discriminator stored in the discriminator. |
| 1401 | inline unsigned getBaseDiscriminator() const; |
| 1402 | |
| 1403 | /// Returns a new DILocation with duplication factor \p DF encoded in the |
| 1404 | /// discriminator. |
| 1405 | inline const DILocation *cloneWithDuplicationFactor(unsigned DF) const; |
| Dehao Chen | e713000 | 2016-10-26 15:48:45 +0000 | [diff] [blame] | 1406 | |
| Robert Lougher | 7bd04e3 | 2016-12-14 16:14:17 +0000 | [diff] [blame] | 1407 | /// When two instructions are combined into a single instruction we also |
| 1408 | /// need to combine the original locations into a single location. |
| 1409 | /// |
| 1410 | /// When the locations are the same we can use either location. When they |
| 1411 | /// differ, we need a third location which is distinct from either. If |
| 1412 | /// they have the same file/line but have a different discriminator we |
| 1413 | /// could create a location with a new discriminator. If they are from |
| 1414 | /// different files/lines the location is ambiguous and can't be |
| 1415 | /// represented in a single line entry. In this case, no location |
| 1416 | /// should be set. |
| 1417 | /// |
| Robert Lougher | 426851e | 2017-01-12 20:34:35 +0000 | [diff] [blame] | 1418 | /// Currently the function does not create a new location. If the locations |
| 1419 | /// are the same, or cannot be discriminated, the first location is returned. |
| 1420 | /// Otherwise an empty location will be used. |
| 1421 | static const DILocation *getMergedLocation(const DILocation *LocA, |
| 1422 | const DILocation *LocB) { |
| 1423 | if (LocA && LocB && (LocA == LocB || !LocA->canDiscriminate(*LocB))) |
| 1424 | return LocA; |
| Robert Lougher | 7bd04e3 | 2016-12-14 16:14:17 +0000 | [diff] [blame] | 1425 | return nullptr; |
| 1426 | } |
| 1427 | |
| Dehao Chen | 726da62 | 2017-02-15 17:54:39 +0000 | [diff] [blame] | 1428 | /// Returns the base discriminator for a given encoded discriminator \p D. |
| 1429 | static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) { |
| 1430 | if ((D & 1) == 0) |
| 1431 | return getUnsignedFromPrefixEncoding(D >> 1); |
| 1432 | else |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
| 1436 | /// Returns the duplication factor for a given encoded discriminator \p D. |
| 1437 | static unsigned getDuplicationFactorFromDiscriminator(unsigned D) { |
| 1438 | D = getNextComponentInDiscriminator(D); |
| 1439 | if (D == 0 || (D & 1)) |
| 1440 | return 1; |
| 1441 | else |
| 1442 | return getUnsignedFromPrefixEncoding(D >> 1); |
| 1443 | } |
| 1444 | |
| 1445 | /// Returns the copy identifier for a given encoded discriminator \p D. |
| 1446 | static unsigned getCopyIdentifierFromDiscriminator(unsigned D) { |
| 1447 | return getUnsignedFromPrefixEncoding(getNextComponentInDiscriminator( |
| 1448 | getNextComponentInDiscriminator(D))); |
| 1449 | } |
| 1450 | |
| 1451 | |
| Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 1452 | Metadata *getRawScope() const { return getOperand(0); } |
| 1453 | Metadata *getRawInlinedAt() const { |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1454 | if (getNumOperands() == 2) |
| 1455 | return getOperand(1); |
| 1456 | return nullptr; |
| 1457 | } |
| 1458 | |
| 1459 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1460 | return MD->getMetadataID() == DILocationKind; |
| Duncan P. N. Exon Smith | 7f9f7c8 | 2015-03-24 17:34:33 +0000 | [diff] [blame] | 1461 | } |
| 1462 | }; |
| 1463 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1464 | /// Subprogram description. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1465 | /// |
| 1466 | /// TODO: Remove DisplayName. It's always equal to Name. |
| 1467 | /// TODO: Split up flags. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1468 | class DISubprogram : public DILocalScope { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1469 | friend class LLVMContextImpl; |
| 1470 | friend class MDNode; |
| 1471 | |
| 1472 | unsigned Line; |
| 1473 | unsigned ScopeLine; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1474 | unsigned VirtualIndex; |
| Davide Italiano | 236e744 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1475 | |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1476 | /// In the MS ABI, the implicit 'this' parameter is adjusted in the prologue |
| 1477 | /// of method overrides from secondary bases by this amount. It may be |
| 1478 | /// negative. |
| 1479 | int ThisAdjustment; |
| 1480 | |
| Davide Italiano | 236e744 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1481 | // Virtuality can only assume three values, so we can pack |
| 1482 | // in 2 bits (none/pure/pure_virtual). |
| 1483 | unsigned Virtuality : 2; |
| 1484 | |
| Davide Italiano | 236e744 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1485 | // These are boolean flags so one bit is enough. |
| 1486 | // MSVC starts a new container field every time the base |
| 1487 | // type changes so we can't use 'bool' to ensure these bits |
| 1488 | // are packed. |
| 1489 | unsigned IsLocalToUnit : 1; |
| 1490 | unsigned IsDefinition : 1; |
| 1491 | unsigned IsOptimized : 1; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1492 | |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1493 | unsigned Padding : 3; |
| 1494 | |
| 1495 | DIFlags Flags; |
| 1496 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1497 | DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1498 | unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1499 | int ThisAdjustment, DIFlags Flags, bool IsLocalToUnit, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1500 | bool IsDefinition, bool IsOptimized, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1501 | : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, |
| Duncan P. N. Exon Smith | a65159a | 2015-03-24 16:44:29 +0000 | [diff] [blame] | 1502 | Ops), |
| Davide Italiano | 236e744 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1503 | Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex), |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1504 | ThisAdjustment(ThisAdjustment), Virtuality(Virtuality), |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1505 | IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition), |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1506 | IsOptimized(IsOptimized), Flags(Flags) { |
| Davide Italiano | 236e744 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1507 | static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range"); |
| 1508 | assert(Virtuality < 4 && "Virtuality out of range"); |
| Davide Italiano | 236e744 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1509 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1510 | ~DISubprogram() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1511 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1512 | static DISubprogram * |
| 1513 | getImpl(LLVMContext &Context, DIScopeRef Scope, StringRef Name, |
| 1514 | StringRef LinkageName, DIFile *File, unsigned Line, |
| 1515 | DISubroutineType *Type, bool IsLocalToUnit, bool IsDefinition, |
| 1516 | unsigned ScopeLine, DITypeRef ContainingType, unsigned Virtuality, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1517 | unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1518 | bool IsOptimized, DICompileUnit *Unit, |
| 1519 | DITemplateParameterArray TemplateParams, DISubprogram *Declaration, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1520 | DILocalVariableArray Variables, DITypeArray ThrownTypes, |
| 1521 | StorageType Storage, bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1522 | return getImpl(Context, Scope, getCanonicalMDString(Context, Name), |
| 1523 | getCanonicalMDString(Context, LinkageName), File, Line, Type, |
| 1524 | IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1525 | Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, |
| 1526 | Unit, TemplateParams.get(), Declaration, Variables.get(), |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1527 | ThrownTypes.get(), Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1528 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1529 | static DISubprogram * |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1530 | getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, |
| 1531 | MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, |
| 1532 | bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, |
| 1533 | Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1534 | int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit, |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1535 | Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1536 | Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1537 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1538 | TempDISubprogram cloneImpl() const { |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1539 | return getTemporary(getContext(), getScope(), getName(), getLinkageName(), |
| 1540 | getFile(), getLine(), getType(), isLocalToUnit(), |
| 1541 | isDefinition(), getScopeLine(), getContainingType(), |
| 1542 | getVirtuality(), getVirtualIndex(), getThisAdjustment(), |
| 1543 | getFlags(), isOptimized(), getUnit(), |
| 1544 | getTemplateParams(), getDeclaration(), getVariables(), |
| 1545 | getThrownTypes()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1549 | DEFINE_MDNODE_GET(DISubprogram, |
| 1550 | (DIScopeRef Scope, StringRef Name, StringRef LinkageName, |
| 1551 | DIFile *File, unsigned Line, DISubroutineType *Type, |
| Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1552 | bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1553 | DITypeRef ContainingType, unsigned Virtuality, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1554 | unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1555 | bool IsOptimized, DICompileUnit *Unit, |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1556 | DITemplateParameterArray TemplateParams = nullptr, |
| 1557 | DISubprogram *Declaration = nullptr, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1558 | DILocalVariableArray Variables = nullptr, |
| 1559 | DITypeArray ThrownTypes = nullptr), |
| Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1560 | (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 1561 | IsDefinition, ScopeLine, ContainingType, Virtuality, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1562 | VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1563 | TemplateParams, Declaration, Variables, ThrownTypes)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1564 | DEFINE_MDNODE_GET( |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1565 | DISubprogram, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1566 | (Metadata * Scope, MDString *Name, MDString *LinkageName, Metadata *File, |
| 1567 | unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, |
| 1568 | unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1569 | unsigned VirtualIndex, int ThisAdjustment, DIFlags Flags, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1570 | bool IsOptimized, Metadata *Unit, Metadata *TemplateParams = nullptr, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1571 | Metadata *Declaration = nullptr, Metadata *Variables = nullptr, |
| 1572 | Metadata *ThrownTypes = nullptr), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1573 | (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1574 | ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1575 | Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables, |
| 1576 | ThrownTypes)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1577 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1578 | TempDISubprogram clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1579 | |
| 1580 | public: |
| 1581 | unsigned getLine() const { return Line; } |
| 1582 | unsigned getVirtuality() const { return Virtuality; } |
| 1583 | unsigned getVirtualIndex() const { return VirtualIndex; } |
| Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1584 | int getThisAdjustment() const { return ThisAdjustment; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1585 | unsigned getScopeLine() const { return ScopeLine; } |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1586 | DIFlags getFlags() const { return Flags; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1587 | bool isLocalToUnit() const { return IsLocalToUnit; } |
| 1588 | bool isDefinition() const { return IsDefinition; } |
| 1589 | bool isOptimized() const { return IsOptimized; } |
| 1590 | |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1591 | bool isArtificial() const { return getFlags() & FlagArtificial; } |
| Duncan P. N. Exon Smith | a138491 | 2015-04-07 03:33:57 +0000 | [diff] [blame] | 1592 | bool isPrivate() const { |
| 1593 | return (getFlags() & FlagAccessibility) == FlagPrivate; |
| 1594 | } |
| 1595 | bool isProtected() const { |
| 1596 | return (getFlags() & FlagAccessibility) == FlagProtected; |
| 1597 | } |
| 1598 | bool isPublic() const { |
| 1599 | return (getFlags() & FlagAccessibility) == FlagPublic; |
| 1600 | } |
| 1601 | bool isExplicit() const { return getFlags() & FlagExplicit; } |
| 1602 | bool isPrototyped() const { return getFlags() & FlagPrototyped; } |
| David Blaikie | ce3c8ef | 2016-11-28 21:32:19 +0000 | [diff] [blame] | 1603 | bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; } |
| Duncan P. N. Exon Smith | a138491 | 2015-04-07 03:33:57 +0000 | [diff] [blame] | 1604 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1605 | /// Check if this is reference-qualified. |
| Duncan P. N. Exon Smith | a138491 | 2015-04-07 03:33:57 +0000 | [diff] [blame] | 1606 | /// |
| 1607 | /// Return true if this subprogram is a C++11 reference-qualified non-static |
| 1608 | /// member function (void foo() &). |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1609 | bool isLValueReference() const { return getFlags() & FlagLValueReference; } |
| Duncan P. N. Exon Smith | a138491 | 2015-04-07 03:33:57 +0000 | [diff] [blame] | 1610 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1611 | /// Check if this is rvalue-reference-qualified. |
| Duncan P. N. Exon Smith | a138491 | 2015-04-07 03:33:57 +0000 | [diff] [blame] | 1612 | /// |
| 1613 | /// Return true if this subprogram is a C++11 rvalue-reference-qualified |
| 1614 | /// non-static member function (void foo() &&). |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1615 | bool isRValueReference() const { return getFlags() & FlagRValueReference; } |
| Duncan P. N. Exon Smith | a138491 | 2015-04-07 03:33:57 +0000 | [diff] [blame] | 1616 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1617 | /// Check if this is marked as noreturn. |
| Adrian Prantl | c19dee7 | 2016-08-17 16:02:43 +0000 | [diff] [blame] | 1618 | /// |
| 1619 | /// Return true if this subprogram is C++11 noreturn or C11 _Noreturn |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1620 | bool isNoReturn() const { return getFlags() & FlagNoReturn; } |
| Adrian Prantl | c19dee7 | 2016-08-17 16:02:43 +0000 | [diff] [blame] | 1621 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1622 | DIScopeRef getScope() const { return DIScopeRef(getRawScope()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1623 | |
| 1624 | StringRef getName() const { return getStringOperand(2); } |
| Adrian Prantl | 9d2f019 | 2017-04-26 23:59:52 +0000 | [diff] [blame] | 1625 | StringRef getLinkageName() const { return getStringOperand(3); } |
| Duncan P. N. Exon Smith | 19fc5ed | 2015-02-13 01:26:47 +0000 | [diff] [blame] | 1626 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1627 | DISubroutineType *getType() const { |
| 1628 | return cast_or_null<DISubroutineType>(getRawType()); |
| Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1629 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1630 | DITypeRef getContainingType() const { |
| 1631 | return DITypeRef(getRawContainingType()); |
| Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1632 | } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1633 | |
| Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1634 | DICompileUnit *getUnit() const { |
| 1635 | return cast_or_null<DICompileUnit>(getRawUnit()); |
| 1636 | } |
| Adrian Prantl | 9d2f019 | 2017-04-26 23:59:52 +0000 | [diff] [blame] | 1637 | void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1638 | DITemplateParameterArray getTemplateParams() const { |
| Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1639 | return cast_or_null<MDTuple>(getRawTemplateParams()); |
| 1640 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1641 | DISubprogram *getDeclaration() const { |
| 1642 | return cast_or_null<DISubprogram>(getRawDeclaration()); |
| Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1643 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1644 | DILocalVariableArray getVariables() const { |
| Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1645 | return cast_or_null<MDTuple>(getRawVariables()); |
| 1646 | } |
| Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1647 | DITypeArray getThrownTypes() const { |
| 1648 | return cast_or_null<MDTuple>(getRawThrownTypes()); |
| 1649 | } |
| Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1650 | |
| 1651 | Metadata *getRawScope() const { return getOperand(1); } |
| Adrian Prantl | 9d2f019 | 2017-04-26 23:59:52 +0000 | [diff] [blame] | 1652 | MDString *getRawName() const { return getOperandAs<MDString>(2); } |
| 1653 | MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); } |
| 1654 | Metadata *getRawType() const { return getOperand(4); } |
| 1655 | Metadata *getRawUnit() const { return getOperand(5); } |
| 1656 | Metadata *getRawDeclaration() const { return getOperand(6); } |
| 1657 | Metadata *getRawVariables() const { return getOperand(7); } |
| 1658 | Metadata *getRawContainingType() const { |
| 1659 | return getNumOperands() > 8 ? getOperandAs<Metadata>(8) : nullptr; |
| 1660 | } |
| 1661 | Metadata *getRawTemplateParams() const { |
| 1662 | return getNumOperands() > 9 ? getOperandAs<Metadata>(9) : nullptr; |
| 1663 | } |
| 1664 | Metadata *getRawThrownTypes() const { |
| 1665 | return getNumOperands() > 10 ? getOperandAs<Metadata>(10) : nullptr; |
| 1666 | } |
| Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1667 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1668 | /// Check if this subprogram describes the given function. |
| Duncan P. N. Exon Smith | 3c2d704 | 2015-04-13 19:07:27 +0000 | [diff] [blame] | 1669 | /// |
| 1670 | /// FIXME: Should this be looking through bitcasts? |
| 1671 | bool describes(const Function *F) const; |
| 1672 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1673 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1674 | return MD->getMetadataID() == DISubprogramKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1675 | } |
| 1676 | }; |
| 1677 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1678 | class DILexicalBlockBase : public DILocalScope { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1679 | protected: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1680 | DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1681 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1682 | : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {} |
| 1683 | ~DILexicalBlockBase() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1684 | |
| 1685 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1686 | DILocalScope *getScope() const { return cast<DILocalScope>(getRawScope()); } |
| Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1687 | |
| 1688 | Metadata *getRawScope() const { return getOperand(1); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1689 | |
| 1690 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1691 | return MD->getMetadataID() == DILexicalBlockKind || |
| 1692 | MD->getMetadataID() == DILexicalBlockFileKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1693 | } |
| 1694 | }; |
| 1695 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1696 | class DILexicalBlock : public DILexicalBlockBase { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1697 | friend class LLVMContextImpl; |
| 1698 | friend class MDNode; |
| 1699 | |
| 1700 | unsigned Line; |
| Duncan P. N. Exon Smith | b09eb9f | 2015-08-28 22:58:50 +0000 | [diff] [blame] | 1701 | uint16_t Column; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1702 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1703 | DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1704 | unsigned Column, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1705 | : DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line), |
| Duncan P. N. Exon Smith | b09eb9f | 2015-08-28 22:58:50 +0000 | [diff] [blame] | 1706 | Column(Column) { |
| 1707 | assert(Column < (1u << 16) && "Expected 16-bit column"); |
| 1708 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1709 | ~DILexicalBlock() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1710 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1711 | static DILexicalBlock *getImpl(LLVMContext &Context, DILocalScope *Scope, |
| 1712 | DIFile *File, unsigned Line, unsigned Column, |
| Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1713 | StorageType Storage, |
| 1714 | bool ShouldCreate = true) { |
| 1715 | return getImpl(Context, static_cast<Metadata *>(Scope), |
| 1716 | static_cast<Metadata *>(File), Line, Column, Storage, |
| 1717 | ShouldCreate); |
| 1718 | } |
| 1719 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1720 | static DILexicalBlock *getImpl(LLVMContext &Context, Metadata *Scope, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1721 | Metadata *File, unsigned Line, unsigned Column, |
| 1722 | StorageType Storage, bool ShouldCreate = true); |
| 1723 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1724 | TempDILexicalBlock cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1725 | return getTemporary(getContext(), getScope(), getFile(), getLine(), |
| 1726 | getColumn()); |
| 1727 | } |
| 1728 | |
| 1729 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1730 | DEFINE_MDNODE_GET(DILexicalBlock, (DILocalScope * Scope, DIFile *File, |
| Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1731 | unsigned Line, unsigned Column), |
| 1732 | (Scope, File, Line, Column)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1733 | DEFINE_MDNODE_GET(DILexicalBlock, (Metadata * Scope, Metadata *File, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1734 | unsigned Line, unsigned Column), |
| 1735 | (Scope, File, Line, Column)) |
| 1736 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1737 | TempDILexicalBlock clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1738 | |
| 1739 | unsigned getLine() const { return Line; } |
| 1740 | unsigned getColumn() const { return Column; } |
| 1741 | |
| 1742 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1743 | return MD->getMetadataID() == DILexicalBlockKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1744 | } |
| 1745 | }; |
| 1746 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1747 | class DILexicalBlockFile : public DILexicalBlockBase { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1748 | friend class LLVMContextImpl; |
| 1749 | friend class MDNode; |
| 1750 | |
| 1751 | unsigned Discriminator; |
| 1752 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1753 | DILexicalBlockFile(LLVMContext &C, StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1754 | unsigned Discriminator, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1755 | : DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1756 | Discriminator(Discriminator) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1757 | ~DILexicalBlockFile() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1758 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1759 | static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope, |
| 1760 | DIFile *File, unsigned Discriminator, |
| Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1761 | StorageType Storage, |
| 1762 | bool ShouldCreate = true) { |
| 1763 | return getImpl(Context, static_cast<Metadata *>(Scope), |
| 1764 | static_cast<Metadata *>(File), Discriminator, Storage, |
| 1765 | ShouldCreate); |
| 1766 | } |
| 1767 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1768 | static DILexicalBlockFile *getImpl(LLVMContext &Context, Metadata *Scope, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1769 | Metadata *File, unsigned Discriminator, |
| 1770 | StorageType Storage, |
| 1771 | bool ShouldCreate = true); |
| 1772 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1773 | TempDILexicalBlockFile cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1774 | return getTemporary(getContext(), getScope(), getFile(), |
| 1775 | getDiscriminator()); |
| 1776 | } |
| 1777 | |
| 1778 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1779 | DEFINE_MDNODE_GET(DILexicalBlockFile, (DILocalScope * Scope, DIFile *File, |
| Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1780 | unsigned Discriminator), |
| 1781 | (Scope, File, Discriminator)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1782 | DEFINE_MDNODE_GET(DILexicalBlockFile, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1783 | (Metadata * Scope, Metadata *File, unsigned Discriminator), |
| 1784 | (Scope, File, Discriminator)) |
| 1785 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1786 | TempDILexicalBlockFile clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1787 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1788 | // TODO: Remove these once they're gone from DILexicalBlockBase. |
| Duncan P. N. Exon Smith | 5f88ba1 | 2015-04-14 02:50:07 +0000 | [diff] [blame] | 1789 | unsigned getLine() const = delete; |
| 1790 | unsigned getColumn() const = delete; |
| 1791 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1792 | unsigned getDiscriminator() const { return Discriminator; } |
| 1793 | |
| 1794 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1795 | return MD->getMetadataID() == DILexicalBlockFileKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1796 | } |
| 1797 | }; |
| 1798 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1799 | unsigned DILocation::getDiscriminator() const { |
| 1800 | if (auto *F = dyn_cast<DILexicalBlockFile>(getScope())) |
| Duncan P. N. Exon Smith | 2c8291e | 2015-04-14 00:05:13 +0000 | [diff] [blame] | 1801 | return F->getDiscriminator(); |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1805 | const DILocation * |
| 1806 | DILocation::cloneWithDiscriminator(unsigned Discriminator) const { |
| Dehao Chen | e713000 | 2016-10-26 15:48:45 +0000 | [diff] [blame] | 1807 | DIScope *Scope = getScope(); |
| 1808 | // Skip all parent DILexicalBlockFile that already have a discriminator |
| 1809 | // assigned. We do not want to have nested DILexicalBlockFiles that have |
| 1810 | // mutliple discriminators because only the leaf DILexicalBlockFile's |
| 1811 | // dominator will be used. |
| 1812 | for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope); |
| 1813 | LBF && LBF->getDiscriminator() != 0; |
| 1814 | LBF = dyn_cast<DILexicalBlockFile>(Scope)) |
| 1815 | Scope = LBF->getScope(); |
| 1816 | DILexicalBlockFile *NewScope = |
| 1817 | DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator); |
| 1818 | return DILocation::get(getContext(), getLine(), getColumn(), NewScope, |
| 1819 | getInlinedAt()); |
| 1820 | } |
| 1821 | |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1822 | unsigned DILocation::getBaseDiscriminator() const { |
| Dehao Chen | 726da62 | 2017-02-15 17:54:39 +0000 | [diff] [blame] | 1823 | return getBaseDiscriminatorFromDiscriminator(getDiscriminator()); |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | unsigned DILocation::getDuplicationFactor() const { |
| Dehao Chen | 726da62 | 2017-02-15 17:54:39 +0000 | [diff] [blame] | 1827 | return getDuplicationFactorFromDiscriminator(getDiscriminator()); |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | unsigned DILocation::getCopyIdentifier() const { |
| Dehao Chen | 726da62 | 2017-02-15 17:54:39 +0000 | [diff] [blame] | 1831 | return getCopyIdentifierFromDiscriminator(getDiscriminator()); |
| Dehao Chen | fb02f71 | 2017-02-10 21:09:07 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | const DILocation *DILocation::setBaseDiscriminator(unsigned D) const { |
| 1835 | if (D == 0) |
| 1836 | return this; |
| 1837 | else |
| 1838 | return cloneWithDiscriminator(getPrefixEncodingFromUnsigned(D) << 1); |
| 1839 | } |
| 1840 | |
| 1841 | const DILocation *DILocation::cloneWithDuplicationFactor(unsigned DF) const { |
| 1842 | DF *= getDuplicationFactor(); |
| 1843 | if (DF <= 1) |
| 1844 | return this; |
| 1845 | |
| 1846 | unsigned BD = getBaseDiscriminator(); |
| 1847 | unsigned CI = getCopyIdentifier() << (DF > 0x1f ? 14 : 7); |
| 1848 | unsigned D = CI | (getPrefixEncodingFromUnsigned(DF) << 1); |
| 1849 | |
| 1850 | if (BD == 0) |
| 1851 | D = (D << 1) | 1; |
| 1852 | else |
| 1853 | D = (D << (BD > 0x1f ? 14 : 7)) | (getPrefixEncodingFromUnsigned(BD) << 1); |
| 1854 | |
| 1855 | return cloneWithDiscriminator(D); |
| 1856 | } |
| 1857 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1858 | class DINamespace : public DIScope { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1859 | friend class LLVMContextImpl; |
| 1860 | friend class MDNode; |
| 1861 | |
| Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 1862 | unsigned ExportSymbols : 1; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1863 | |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 1864 | DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols, |
| 1865 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1866 | : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1867 | Ops), |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 1868 | ExportSymbols(ExportSymbols) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1869 | ~DINamespace() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1870 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1871 | static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope, |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 1872 | StringRef Name, bool ExportSymbols, |
| 1873 | StorageType Storage, bool ShouldCreate = true) { |
| 1874 | return getImpl(Context, Scope, getCanonicalMDString(Context, Name), |
| 1875 | ExportSymbols, Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1876 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1877 | static DINamespace *getImpl(LLVMContext &Context, Metadata *Scope, |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 1878 | MDString *Name, bool ExportSymbols, |
| 1879 | StorageType Storage, bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1880 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1881 | TempDINamespace cloneImpl() const { |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 1882 | return getTemporary(getContext(), getScope(), getName(), |
| 1883 | getExportSymbols()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | public: |
| Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 1887 | DEFINE_MDNODE_GET(DINamespace, |
| Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 1888 | (DIScope *Scope, StringRef Name, bool ExportSymbols), |
| 1889 | (Scope, Name, ExportSymbols)) |
| 1890 | DEFINE_MDNODE_GET(DINamespace, |
| 1891 | (Metadata *Scope, MDString *Name, bool ExportSymbols), |
| 1892 | (Scope, Name, ExportSymbols)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1893 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1894 | TempDINamespace clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1895 | |
| Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 1896 | bool getExportSymbols() const { return ExportSymbols; } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1897 | DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1898 | StringRef getName() const { return getStringOperand(2); } |
| 1899 | |
| Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1900 | Metadata *getRawScope() const { return getOperand(1); } |
| Duncan P. N. Exon Smith | e146000 | 2015-02-13 01:32:09 +0000 | [diff] [blame] | 1901 | MDString *getRawName() const { return getOperandAs<MDString>(2); } |
| 1902 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1903 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1904 | return MD->getMetadataID() == DINamespaceKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1905 | } |
| 1906 | }; |
| 1907 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1908 | /// A (clang) module that has been imported by the compile unit. |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 1909 | /// |
| 1910 | class DIModule : public DIScope { |
| 1911 | friend class LLVMContextImpl; |
| 1912 | friend class MDNode; |
| 1913 | |
| 1914 | DIModule(LLVMContext &Context, StorageType Storage, ArrayRef<Metadata *> Ops) |
| 1915 | : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {} |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 1916 | ~DIModule() = default; |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 1917 | |
| 1918 | static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, |
| 1919 | StringRef Name, StringRef ConfigurationMacros, |
| 1920 | StringRef IncludePath, StringRef ISysRoot, |
| 1921 | StorageType Storage, bool ShouldCreate = true) { |
| 1922 | return getImpl(Context, Scope, getCanonicalMDString(Context, Name), |
| 1923 | getCanonicalMDString(Context, ConfigurationMacros), |
| NAKAMURA Takumi | ff35c33 | 2015-07-06 00:48:17 +0000 | [diff] [blame] | 1924 | getCanonicalMDString(Context, IncludePath), |
| 1925 | getCanonicalMDString(Context, ISysRoot), |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 1926 | Storage, ShouldCreate); |
| 1927 | } |
| 1928 | static DIModule *getImpl(LLVMContext &Context, Metadata *Scope, |
| 1929 | MDString *Name, MDString *ConfigurationMacros, |
| NAKAMURA Takumi | ff35c33 | 2015-07-06 00:48:17 +0000 | [diff] [blame] | 1930 | MDString *IncludePath, MDString *ISysRoot, |
| 1931 | StorageType Storage, bool ShouldCreate = true); |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 1932 | |
| 1933 | TempDIModule cloneImpl() const { |
| 1934 | return getTemporary(getContext(), getScope(), getName(), |
| 1935 | getConfigurationMacros(), getIncludePath(), |
| 1936 | getISysRoot()); |
| 1937 | } |
| 1938 | |
| 1939 | public: |
| 1940 | DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name, |
| NAKAMURA Takumi | ff35c33 | 2015-07-06 00:48:17 +0000 | [diff] [blame] | 1941 | StringRef ConfigurationMacros, StringRef IncludePath, |
| 1942 | StringRef ISysRoot), |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 1943 | (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot)) |
| 1944 | DEFINE_MDNODE_GET(DIModule, |
| 1945 | (Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, |
| NAKAMURA Takumi | ff35c33 | 2015-07-06 00:48:17 +0000 | [diff] [blame] | 1946 | MDString *IncludePath, MDString *ISysRoot), |
| Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 1947 | (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot)) |
| 1948 | |
| 1949 | TempDIModule clone() const { return cloneImpl(); } |
| 1950 | |
| 1951 | DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } |
| 1952 | StringRef getName() const { return getStringOperand(1); } |
| 1953 | StringRef getConfigurationMacros() const { return getStringOperand(2); } |
| 1954 | StringRef getIncludePath() const { return getStringOperand(3); } |
| 1955 | StringRef getISysRoot() const { return getStringOperand(4); } |
| 1956 | |
| 1957 | Metadata *getRawScope() const { return getOperand(0); } |
| 1958 | MDString *getRawName() const { return getOperandAs<MDString>(1); } |
| 1959 | MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); } |
| 1960 | MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); } |
| 1961 | MDString *getRawISysRoot() const { return getOperandAs<MDString>(4); } |
| 1962 | |
| 1963 | static bool classof(const Metadata *MD) { |
| 1964 | return MD->getMetadataID() == DIModuleKind; |
| 1965 | } |
| 1966 | }; |
| 1967 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 1968 | /// Base class for template parameters. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1969 | class DITemplateParameter : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1970 | protected: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1971 | DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage, |
| Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1972 | unsigned Tag, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1973 | : DINode(Context, ID, Storage, Tag, Ops) {} |
| 1974 | ~DITemplateParameter() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1975 | |
| 1976 | public: |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1977 | StringRef getName() const { return getStringOperand(0); } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1978 | DITypeRef getType() const { return DITypeRef(getRawType()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1979 | |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1980 | MDString *getRawName() const { return getOperandAs<MDString>(0); } |
| Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1981 | Metadata *getRawType() const { return getOperand(1); } |
| Duncan P. N. Exon Smith | 2847f38 | 2015-02-13 01:34:32 +0000 | [diff] [blame] | 1982 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1983 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1984 | return MD->getMetadataID() == DITemplateTypeParameterKind || |
| 1985 | MD->getMetadataID() == DITemplateValueParameterKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1986 | } |
| 1987 | }; |
| 1988 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1989 | class DITemplateTypeParameter : public DITemplateParameter { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1990 | friend class LLVMContextImpl; |
| 1991 | friend class MDNode; |
| 1992 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1993 | DITemplateTypeParameter(LLVMContext &Context, StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1994 | ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1995 | : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage, |
| Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1996 | dwarf::DW_TAG_template_type_parameter, Ops) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1997 | ~DITemplateTypeParameter() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1998 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1999 | static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name, |
| 2000 | DITypeRef Type, StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2001 | bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2002 | return getImpl(Context, getCanonicalMDString(Context, Name), Type, Storage, |
| 2003 | ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2004 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2005 | static DITemplateTypeParameter *getImpl(LLVMContext &Context, MDString *Name, |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2006 | Metadata *Type, StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2007 | bool ShouldCreate = true); |
| 2008 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2009 | TempDITemplateTypeParameter cloneImpl() const { |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2010 | return getTemporary(getContext(), getName(), getType()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2014 | DEFINE_MDNODE_GET(DITemplateTypeParameter, (StringRef Name, DITypeRef Type), |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2015 | (Name, Type)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2016 | DEFINE_MDNODE_GET(DITemplateTypeParameter, (MDString * Name, Metadata *Type), |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2017 | (Name, Type)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2018 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2019 | TempDITemplateTypeParameter clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2020 | |
| 2021 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2022 | return MD->getMetadataID() == DITemplateTypeParameterKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2023 | } |
| 2024 | }; |
| 2025 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2026 | class DITemplateValueParameter : public DITemplateParameter { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2027 | friend class LLVMContextImpl; |
| 2028 | friend class MDNode; |
| 2029 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2030 | DITemplateValueParameter(LLVMContext &Context, StorageType Storage, |
| Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 2031 | unsigned Tag, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2032 | : DITemplateParameter(Context, DITemplateValueParameterKind, Storage, Tag, |
| Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 2033 | Ops) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2034 | ~DITemplateValueParameter() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2035 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2036 | static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag, |
| 2037 | StringRef Name, DITypeRef Type, |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2038 | Metadata *Value, StorageType Storage, |
| Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 2039 | bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2040 | return getImpl(Context, Tag, getCanonicalMDString(Context, Name), Type, |
| 2041 | Value, Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2042 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2043 | static DITemplateValueParameter *getImpl(LLVMContext &Context, unsigned Tag, |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2044 | MDString *Name, Metadata *Type, |
| 2045 | Metadata *Value, StorageType Storage, |
| Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 2046 | bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2047 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2048 | TempDITemplateValueParameter cloneImpl() const { |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2049 | return getTemporary(getContext(), getTag(), getName(), getType(), |
| 2050 | getValue()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2054 | DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, StringRef Name, |
| 2055 | DITypeRef Type, Metadata *Value), |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2056 | (Tag, Name, Type, Value)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2057 | DEFINE_MDNODE_GET(DITemplateValueParameter, (unsigned Tag, MDString *Name, |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2058 | Metadata *Type, Metadata *Value), |
| 2059 | (Tag, Name, Type, Value)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2060 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2061 | TempDITemplateValueParameter clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2062 | |
| Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2063 | Metadata *getValue() const { return getOperand(2); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2064 | |
| 2065 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2066 | return MD->getMetadataID() == DITemplateValueParameterKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2067 | } |
| 2068 | }; |
| 2069 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2070 | /// Base class for variables. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2071 | class DIVariable : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2072 | unsigned Line; |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2073 | uint32_t AlignInBits; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2074 | |
| 2075 | protected: |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2076 | DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2077 | ArrayRef<Metadata *> Ops, uint32_t AlignInBits = 0) |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2078 | : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line), |
| NAKAMURA Takumi | 7802984 | 2017-02-19 06:51:46 +0000 | [diff] [blame] | 2079 | AlignInBits(AlignInBits) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2080 | ~DIVariable() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2081 | |
| 2082 | public: |
| 2083 | unsigned getLine() const { return Line; } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2084 | DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2085 | StringRef getName() const { return getStringOperand(1); } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2086 | DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } |
| 2087 | DITypeRef getType() const { return DITypeRef(getRawType()); } |
| Victor Leschuk | 3c98998 | 2016-10-26 11:59:03 +0000 | [diff] [blame] | 2088 | uint32_t getAlignInBits() const { return AlignInBits; } |
| 2089 | uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2090 | |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 2091 | StringRef getFilename() const { |
| 2092 | if (auto *F = getFile()) |
| 2093 | return F->getFilename(); |
| 2094 | return ""; |
| 2095 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2096 | |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 2097 | StringRef getDirectory() const { |
| 2098 | if (auto *F = getFile()) |
| 2099 | return F->getDirectory(); |
| 2100 | return ""; |
| 2101 | } |
| 2102 | |
| Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2103 | Metadata *getRawScope() const { return getOperand(0); } |
| Duncan P. N. Exon Smith | c8f810a | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2104 | MDString *getRawName() const { return getOperandAs<MDString>(1); } |
| Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2105 | Metadata *getRawFile() const { return getOperand(2); } |
| 2106 | Metadata *getRawType() const { return getOperand(3); } |
| Duncan P. N. Exon Smith | c8f810a | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2107 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2108 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2109 | return MD->getMetadataID() == DILocalVariableKind || |
| 2110 | MD->getMetadataID() == DIGlobalVariableKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2111 | } |
| 2112 | }; |
| 2113 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2114 | /// DWARF expression. |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2115 | /// |
| 2116 | /// This is (almost) a DWARF expression that modifies the location of a |
| 2117 | /// variable, or the location of a single piece of a variable, or (when using |
| 2118 | /// DW_OP_stack_value) is the constant variable value. |
| 2119 | /// |
| 2120 | /// FIXME: Instead of DW_OP_plus taking an argument, this should use DW_OP_const |
| 2121 | /// and have DW_OP_plus consume the topmost elements on the stack. |
| 2122 | /// |
| 2123 | /// TODO: Co-allocate the expression elements. |
| 2124 | /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary |
| 2125 | /// storage types. |
| 2126 | class DIExpression : public MDNode { |
| 2127 | friend class LLVMContextImpl; |
| 2128 | friend class MDNode; |
| 2129 | |
| 2130 | std::vector<uint64_t> Elements; |
| 2131 | |
| 2132 | DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements) |
| 2133 | : MDNode(C, DIExpressionKind, Storage, None), |
| 2134 | Elements(Elements.begin(), Elements.end()) {} |
| 2135 | ~DIExpression() = default; |
| 2136 | |
| 2137 | static DIExpression *getImpl(LLVMContext &Context, |
| 2138 | ArrayRef<uint64_t> Elements, StorageType Storage, |
| 2139 | bool ShouldCreate = true); |
| 2140 | |
| 2141 | TempDIExpression cloneImpl() const { |
| 2142 | return getTemporary(getContext(), getElements()); |
| 2143 | } |
| 2144 | |
| 2145 | public: |
| 2146 | DEFINE_MDNODE_GET(DIExpression, (ArrayRef<uint64_t> Elements), (Elements)) |
| 2147 | |
| 2148 | TempDIExpression clone() const { return cloneImpl(); } |
| 2149 | |
| 2150 | ArrayRef<uint64_t> getElements() const { return Elements; } |
| 2151 | |
| 2152 | unsigned getNumElements() const { return Elements.size(); } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2153 | |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2154 | uint64_t getElement(unsigned I) const { |
| 2155 | assert(I < Elements.size() && "Index out of range"); |
| 2156 | return Elements[I]; |
| 2157 | } |
| 2158 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2159 | /// Determine whether this represents a standalone constant value. |
| 2160 | bool isConstant() const; |
| 2161 | |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2162 | using element_iterator = ArrayRef<uint64_t>::iterator; |
| 2163 | |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2164 | element_iterator elements_begin() const { return getElements().begin(); } |
| 2165 | element_iterator elements_end() const { return getElements().end(); } |
| 2166 | |
| 2167 | /// A lightweight wrapper around an expression operand. |
| 2168 | /// |
| 2169 | /// TODO: Store arguments directly and change \a DIExpression to store a |
| 2170 | /// range of these. |
| 2171 | class ExprOperand { |
| Adrian Prantl | 72845a5 | 2016-11-08 20:48:38 +0000 | [diff] [blame] | 2172 | const uint64_t *Op = nullptr; |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2173 | |
| 2174 | public: |
| Adrian Prantl | 72845a5 | 2016-11-08 20:48:38 +0000 | [diff] [blame] | 2175 | ExprOperand() = default; |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2176 | explicit ExprOperand(const uint64_t *Op) : Op(Op) {} |
| 2177 | |
| 2178 | const uint64_t *get() const { return Op; } |
| 2179 | |
| 2180 | /// Get the operand code. |
| 2181 | uint64_t getOp() const { return *Op; } |
| 2182 | |
| 2183 | /// Get an argument to the operand. |
| 2184 | /// |
| 2185 | /// Never returns the operand itself. |
| 2186 | uint64_t getArg(unsigned I) const { return Op[I + 1]; } |
| 2187 | |
| 2188 | unsigned getNumArgs() const { return getSize() - 1; } |
| 2189 | |
| 2190 | /// Return the size of the operand. |
| 2191 | /// |
| 2192 | /// Return the number of elements in the operand (1 + args). |
| 2193 | unsigned getSize() const; |
| 2194 | }; |
| 2195 | |
| 2196 | /// An iterator for expression operands. |
| 2197 | class expr_op_iterator |
| 2198 | : public std::iterator<std::input_iterator_tag, ExprOperand> { |
| 2199 | ExprOperand Op; |
| 2200 | |
| 2201 | public: |
| Adrian Prantl | 54286bd | 2016-11-02 16:12:20 +0000 | [diff] [blame] | 2202 | expr_op_iterator() = default; |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2203 | explicit expr_op_iterator(element_iterator I) : Op(I) {} |
| 2204 | |
| 2205 | element_iterator getBase() const { return Op.get(); } |
| 2206 | const ExprOperand &operator*() const { return Op; } |
| 2207 | const ExprOperand *operator->() const { return &Op; } |
| 2208 | |
| 2209 | expr_op_iterator &operator++() { |
| 2210 | increment(); |
| 2211 | return *this; |
| 2212 | } |
| 2213 | expr_op_iterator operator++(int) { |
| 2214 | expr_op_iterator T(*this); |
| 2215 | increment(); |
| 2216 | return T; |
| 2217 | } |
| 2218 | |
| 2219 | /// Get the next iterator. |
| 2220 | /// |
| 2221 | /// \a std::next() doesn't work because this is technically an |
| 2222 | /// input_iterator, but it's a perfectly valid operation. This is an |
| 2223 | /// accessor to provide the same functionality. |
| 2224 | expr_op_iterator getNext() const { return ++expr_op_iterator(*this); } |
| 2225 | |
| 2226 | bool operator==(const expr_op_iterator &X) const { |
| 2227 | return getBase() == X.getBase(); |
| 2228 | } |
| 2229 | bool operator!=(const expr_op_iterator &X) const { |
| 2230 | return getBase() != X.getBase(); |
| 2231 | } |
| 2232 | |
| 2233 | private: |
| 2234 | void increment() { Op = ExprOperand(getBase() + Op.getSize()); } |
| 2235 | }; |
| 2236 | |
| 2237 | /// Visit the elements via ExprOperand wrappers. |
| 2238 | /// |
| 2239 | /// These range iterators visit elements through \a ExprOperand wrappers. |
| 2240 | /// This is not guaranteed to be a valid range unless \a isValid() gives \c |
| 2241 | /// true. |
| 2242 | /// |
| 2243 | /// \pre \a isValid() gives \c true. |
| 2244 | /// @{ |
| 2245 | expr_op_iterator expr_op_begin() const { |
| 2246 | return expr_op_iterator(elements_begin()); |
| 2247 | } |
| 2248 | expr_op_iterator expr_op_end() const { |
| 2249 | return expr_op_iterator(elements_end()); |
| 2250 | } |
| Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 2251 | iterator_range<expr_op_iterator> expr_ops() const { |
| 2252 | return {expr_op_begin(), expr_op_end()}; |
| 2253 | } |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2254 | /// @} |
| 2255 | |
| 2256 | bool isValid() const; |
| 2257 | |
| 2258 | static bool classof(const Metadata *MD) { |
| 2259 | return MD->getMetadataID() == DIExpressionKind; |
| 2260 | } |
| 2261 | |
| Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 2262 | /// Return whether the first element a DW_OP_deref. |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2263 | bool startsWithDeref() const { |
| 2264 | return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref; |
| 2265 | } |
| Adrian Prantl | 49797ca | 2016-12-22 05:27:12 +0000 | [diff] [blame] | 2266 | |
| 2267 | /// Holds the characteristics of one fragment of a larger variable. |
| 2268 | struct FragmentInfo { |
| 2269 | uint64_t SizeInBits; |
| 2270 | uint64_t OffsetInBits; |
| 2271 | }; |
| 2272 | |
| 2273 | /// Retrieve the details of this fragment expression. |
| 2274 | static Optional<FragmentInfo> getFragmentInfo(expr_op_iterator Start, |
| NAKAMURA Takumi | 7802984 | 2017-02-19 06:51:46 +0000 | [diff] [blame] | 2275 | expr_op_iterator End); |
| Adrian Prantl | 49797ca | 2016-12-22 05:27:12 +0000 | [diff] [blame] | 2276 | |
| 2277 | /// Retrieve the details of this fragment expression. |
| 2278 | Optional<FragmentInfo> getFragmentInfo() const { |
| 2279 | return getFragmentInfo(expr_op_begin(), expr_op_end()); |
| 2280 | } |
| 2281 | |
| 2282 | /// Return whether this is a piece of an aggregate variable. |
| 2283 | bool isFragment() const { return getFragmentInfo().hasValue(); } |
| Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 2284 | |
| 2285 | /// Append \p Ops with operations to apply the \p Offset. |
| 2286 | static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset); |
| 2287 | |
| Reid Kleckner | b5fced7 | 2017-05-09 19:59:29 +0000 | [diff] [blame] | 2288 | /// If this is a constant offset, extract it. If there is no expression, |
| 2289 | /// return true with an offset of zero. |
| 2290 | bool extractIfOffset(int64_t &Offset) const; |
| 2291 | |
| Adrian Prantl | 109b236 | 2017-04-28 17:51:05 +0000 | [diff] [blame] | 2292 | /// Constants for DIExpression::prepend. |
| 2293 | enum { NoDeref = false, WithDeref = true, WithStackValue = true }; |
| 2294 | |
| Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 2295 | /// Prepend \p DIExpr with a deref and offset operation and optionally turn it |
| 2296 | /// into a stack value. |
| Adrian Prantl | 06d6096 | 2017-04-28 18:30:36 +0000 | [diff] [blame] | 2297 | static DIExpression *prepend(const DIExpression *DIExpr, bool Deref, |
| Adrian Prantl | 109b236 | 2017-04-28 17:51:05 +0000 | [diff] [blame] | 2298 | int64_t Offset = 0, bool StackValue = false); |
| Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2299 | }; |
| 2300 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2301 | /// Global variables. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2302 | /// |
| 2303 | /// TODO: Remove DisplayName. It's always equal to Name. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2304 | class DIGlobalVariable : public DIVariable { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2305 | friend class LLVMContextImpl; |
| 2306 | friend class MDNode; |
| 2307 | |
| 2308 | bool IsLocalToUnit; |
| 2309 | bool IsDefinition; |
| 2310 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2311 | DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2312 | bool IsLocalToUnit, bool IsDefinition, uint32_t AlignInBits, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2313 | ArrayRef<Metadata *> Ops) |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2314 | : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2315 | IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2316 | ~DIGlobalVariable() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2317 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2318 | static DIGlobalVariable *getImpl(LLVMContext &Context, DIScope *Scope, |
| 2319 | StringRef Name, StringRef LinkageName, |
| 2320 | DIFile *File, unsigned Line, DITypeRef Type, |
| 2321 | bool IsLocalToUnit, bool IsDefinition, |
| 2322 | DIDerivedType *StaticDataMemberDeclaration, |
| 2323 | uint32_t AlignInBits, StorageType Storage, |
| 2324 | bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2325 | return getImpl(Context, Scope, getCanonicalMDString(Context, Name), |
| 2326 | getCanonicalMDString(Context, LinkageName), File, Line, Type, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2327 | IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration, |
| 2328 | AlignInBits, Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2329 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2330 | static DIGlobalVariable * |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2331 | getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, |
| 2332 | MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2333 | bool IsLocalToUnit, bool IsDefinition, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2334 | Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2335 | StorageType Storage, bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2336 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2337 | TempDIGlobalVariable cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2338 | return getTemporary(getContext(), getScope(), getName(), getLinkageName(), |
| 2339 | getFile(), getLine(), getType(), isLocalToUnit(), |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2340 | isDefinition(), getStaticDataMemberDeclaration(), |
| 2341 | getAlignInBits()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2345 | DEFINE_MDNODE_GET(DIGlobalVariable, |
| 2346 | (DIScope * Scope, StringRef Name, StringRef LinkageName, |
| 2347 | DIFile *File, unsigned Line, DITypeRef Type, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2348 | bool IsLocalToUnit, bool IsDefinition, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2349 | DIDerivedType *StaticDataMemberDeclaration, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2350 | uint32_t AlignInBits), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2351 | (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2352 | IsDefinition, StaticDataMemberDeclaration, AlignInBits)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2353 | DEFINE_MDNODE_GET(DIGlobalVariable, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2354 | (Metadata * Scope, MDString *Name, MDString *LinkageName, |
| 2355 | Metadata *File, unsigned Line, Metadata *Type, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2356 | bool IsLocalToUnit, bool IsDefinition, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2357 | Metadata *StaticDataMemberDeclaration, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2358 | uint32_t AlignInBits), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2359 | (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2360 | IsDefinition, StaticDataMemberDeclaration, AlignInBits)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2361 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2362 | TempDIGlobalVariable clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2363 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2364 | bool isLocalToUnit() const { return IsLocalToUnit; } |
| 2365 | bool isDefinition() const { return IsDefinition; } |
| 2366 | StringRef getDisplayName() const { return getStringOperand(4); } |
| 2367 | StringRef getLinkageName() const { return getStringOperand(5); } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2368 | DIDerivedType *getStaticDataMemberDeclaration() const { |
| 2369 | return cast_or_null<DIDerivedType>(getRawStaticDataMemberDeclaration()); |
| Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2370 | } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2371 | |
| Duncan P. N. Exon Smith | c8f810a | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2372 | MDString *getRawLinkageName() const { return getOperandAs<MDString>(5); } |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2373 | Metadata *getRawStaticDataMemberDeclaration() const { return getOperand(6); } |
| Duncan P. N. Exon Smith | c8f810a | 2015-02-13 01:35:40 +0000 | [diff] [blame] | 2374 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2375 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2376 | return MD->getMetadataID() == DIGlobalVariableKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2377 | } |
| 2378 | }; |
| 2379 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2380 | /// Local variable. |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2381 | /// |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2382 | /// TODO: Split up flags. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2383 | class DILocalVariable : public DIVariable { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2384 | friend class LLVMContextImpl; |
| 2385 | friend class MDNode; |
| 2386 | |
| Davide Italiano | eb6bb3e | 2016-04-16 02:27:56 +0000 | [diff] [blame] | 2387 | unsigned Arg : 16; |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 2388 | DIFlags Flags; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2389 | |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2390 | DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2391 | unsigned Arg, DIFlags Flags, uint32_t AlignInBits, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2392 | ArrayRef<Metadata *> Ops) |
| 2393 | : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits), |
| 2394 | Arg(Arg), Flags(Flags) { |
| Davide Italiano | 0d2ef01 | 2016-04-16 03:23:48 +0000 | [diff] [blame] | 2395 | assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range"); |
| Davide Italiano | eb6bb3e | 2016-04-16 02:27:56 +0000 | [diff] [blame] | 2396 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2397 | ~DILocalVariable() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2398 | |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2399 | static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope, |
| 2400 | StringRef Name, DIFile *File, unsigned Line, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 2401 | DITypeRef Type, unsigned Arg, DIFlags Flags, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2402 | uint32_t AlignInBits, StorageType Storage, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2403 | bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2404 | return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File, |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2405 | Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2406 | } |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2407 | static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope, |
| 2408 | MDString *Name, Metadata *File, unsigned Line, |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 2409 | Metadata *Type, unsigned Arg, DIFlags Flags, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2410 | uint32_t AlignInBits, StorageType Storage, |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2411 | bool ShouldCreate = true); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2412 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2413 | TempDILocalVariable cloneImpl() const { |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2414 | return getTemporary(getContext(), getScope(), getName(), getFile(), |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2415 | getLine(), getType(), getArg(), getFlags(), |
| 2416 | getAlignInBits()); |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2420 | DEFINE_MDNODE_GET(DILocalVariable, |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2421 | (DILocalScope * Scope, StringRef Name, DIFile *File, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 2422 | unsigned Line, DITypeRef Type, unsigned Arg, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2423 | DIFlags Flags, uint32_t AlignInBits), |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2424 | (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2425 | DEFINE_MDNODE_GET(DILocalVariable, |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2426 | (Metadata * Scope, MDString *Name, Metadata *File, |
| Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 2427 | unsigned Line, Metadata *Type, unsigned Arg, |
| Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2428 | DIFlags Flags, uint32_t AlignInBits), |
| Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2429 | (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits)) |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2430 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2431 | TempDILocalVariable clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2432 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2433 | /// Get the local scope for this variable. |
| Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2434 | /// |
| 2435 | /// Variables must be defined in a local scope. |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2436 | DILocalScope *getScope() const { |
| 2437 | return cast<DILocalScope>(DIVariable::getScope()); |
| Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2440 | bool isParameter() const { return Arg; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2441 | unsigned getArg() const { return Arg; } |
| Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 2442 | DIFlags getFlags() const { return Flags; } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2443 | |
| Duncan P. N. Exon Smith | bd42d5d | 2015-04-07 03:55:30 +0000 | [diff] [blame] | 2444 | bool isArtificial() const { return getFlags() & FlagArtificial; } |
| 2445 | bool isObjectPointer() const { return getFlags() & FlagObjectPointer; } |
| 2446 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2447 | /// Check that a location is valid for this variable. |
| Duncan P. N. Exon Smith | 3bef6a3 | 2015-04-03 19:20:26 +0000 | [diff] [blame] | 2448 | /// |
| Duncan P. N. Exon Smith | f17f34e | 2015-04-15 22:15:46 +0000 | [diff] [blame] | 2449 | /// Check that \c DL exists, is in the same subprogram, and has the same |
| Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 2450 | /// inlined-at location as \c this. (Otherwise, it's not a valid attachment |
| Duncan P. N. Exon Smith | f17f34e | 2015-04-15 22:15:46 +0000 | [diff] [blame] | 2451 | /// to a \a DbgInfoIntrinsic.) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2452 | bool isValidLocationForIntrinsic(const DILocation *DL) const { |
| Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 2453 | return DL && getScope()->getSubprogram() == DL->getScope()->getSubprogram(); |
| Duncan P. N. Exon Smith | 3bef6a3 | 2015-04-03 19:20:26 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2456 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2457 | return MD->getMetadataID() == DILocalVariableKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2458 | } |
| 2459 | }; |
| 2460 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2461 | class DIObjCProperty : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2462 | friend class LLVMContextImpl; |
| 2463 | friend class MDNode; |
| 2464 | |
| 2465 | unsigned Line; |
| 2466 | unsigned Attributes; |
| 2467 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2468 | DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2469 | unsigned Attributes, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2470 | : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, |
| 2471 | Ops), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2472 | Line(Line), Attributes(Attributes) {} |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2473 | ~DIObjCProperty() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2474 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2475 | static DIObjCProperty * |
| 2476 | getImpl(LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2477 | StringRef GetterName, StringRef SetterName, unsigned Attributes, |
| Adrian Prantl | 8ff53b3 | 2015-06-15 23:18:03 +0000 | [diff] [blame] | 2478 | DITypeRef Type, StorageType Storage, bool ShouldCreate = true) { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2479 | return getImpl(Context, getCanonicalMDString(Context, Name), File, Line, |
| 2480 | getCanonicalMDString(Context, GetterName), |
| 2481 | getCanonicalMDString(Context, SetterName), Attributes, Type, |
| 2482 | Storage, ShouldCreate); |
| 2483 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2484 | static DIObjCProperty *getImpl(LLVMContext &Context, MDString *Name, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2485 | Metadata *File, unsigned Line, |
| 2486 | MDString *GetterName, MDString *SetterName, |
| 2487 | unsigned Attributes, Metadata *Type, |
| 2488 | StorageType Storage, bool ShouldCreate = true); |
| 2489 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2490 | TempDIObjCProperty cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2491 | return getTemporary(getContext(), getName(), getFile(), getLine(), |
| 2492 | getGetterName(), getSetterName(), getAttributes(), |
| 2493 | getType()); |
| 2494 | } |
| 2495 | |
| 2496 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2497 | DEFINE_MDNODE_GET(DIObjCProperty, |
| 2498 | (StringRef Name, DIFile *File, unsigned Line, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2499 | StringRef GetterName, StringRef SetterName, |
| Adrian Prantl | 8ff53b3 | 2015-06-15 23:18:03 +0000 | [diff] [blame] | 2500 | unsigned Attributes, DITypeRef Type), |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2501 | (Name, File, Line, GetterName, SetterName, Attributes, |
| 2502 | Type)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2503 | DEFINE_MDNODE_GET(DIObjCProperty, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2504 | (MDString * Name, Metadata *File, unsigned Line, |
| 2505 | MDString *GetterName, MDString *SetterName, |
| 2506 | unsigned Attributes, Metadata *Type), |
| 2507 | (Name, File, Line, GetterName, SetterName, Attributes, |
| 2508 | Type)) |
| 2509 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2510 | TempDIObjCProperty clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2511 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2512 | unsigned getLine() const { return Line; } |
| 2513 | unsigned getAttributes() const { return Attributes; } |
| 2514 | StringRef getName() const { return getStringOperand(0); } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2515 | DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2516 | StringRef getGetterName() const { return getStringOperand(2); } |
| 2517 | StringRef getSetterName() const { return getStringOperand(3); } |
| Adrian Prantl | 8ff53b3 | 2015-06-15 23:18:03 +0000 | [diff] [blame] | 2518 | DITypeRef getType() const { return DITypeRef(getRawType()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2519 | |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 2520 | StringRef getFilename() const { |
| 2521 | if (auto *F = getFile()) |
| 2522 | return F->getFilename(); |
| 2523 | return ""; |
| 2524 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2525 | |
| Duncan P. N. Exon Smith | 50c065b | 2015-04-11 00:39:43 +0000 | [diff] [blame] | 2526 | StringRef getDirectory() const { |
| 2527 | if (auto *F = getFile()) |
| 2528 | return F->getDirectory(); |
| 2529 | return ""; |
| 2530 | } |
| 2531 | |
| Duncan P. N. Exon Smith | d45ce96 | 2015-02-13 01:43:22 +0000 | [diff] [blame] | 2532 | MDString *getRawName() const { return getOperandAs<MDString>(0); } |
| Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2533 | Metadata *getRawFile() const { return getOperand(1); } |
| Duncan P. N. Exon Smith | d45ce96 | 2015-02-13 01:43:22 +0000 | [diff] [blame] | 2534 | MDString *getRawGetterName() const { return getOperandAs<MDString>(2); } |
| 2535 | MDString *getRawSetterName() const { return getOperandAs<MDString>(3); } |
| Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2536 | Metadata *getRawType() const { return getOperand(4); } |
| Duncan P. N. Exon Smith | d45ce96 | 2015-02-13 01:43:22 +0000 | [diff] [blame] | 2537 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2538 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2539 | return MD->getMetadataID() == DIObjCPropertyKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2540 | } |
| 2541 | }; |
| 2542 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2543 | /// An imported module (C++ using directive or similar). |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2544 | class DIImportedEntity : public DINode { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2545 | friend class LLVMContextImpl; |
| 2546 | friend class MDNode; |
| 2547 | |
| 2548 | unsigned Line; |
| 2549 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2550 | DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2551 | unsigned Line, ArrayRef<Metadata *> Ops) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2552 | : DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {} |
| 2553 | ~DIImportedEntity() = default; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2554 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2555 | static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag, |
| 2556 | DIScope *Scope, DINodeRef Entity, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2557 | unsigned Line, StringRef Name, |
| 2558 | StorageType Storage, |
| 2559 | bool ShouldCreate = true) { |
| 2560 | return getImpl(Context, Tag, Scope, Entity, Line, |
| 2561 | getCanonicalMDString(Context, Name), Storage, ShouldCreate); |
| 2562 | } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2563 | static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2564 | Metadata *Scope, Metadata *Entity, |
| 2565 | unsigned Line, MDString *Name, |
| 2566 | StorageType Storage, |
| 2567 | bool ShouldCreate = true); |
| 2568 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2569 | TempDIImportedEntity cloneImpl() const { |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2570 | return getTemporary(getContext(), getTag(), getScope(), getEntity(), |
| 2571 | getLine(), getName()); |
| 2572 | } |
| 2573 | |
| 2574 | public: |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2575 | DEFINE_MDNODE_GET(DIImportedEntity, |
| 2576 | (unsigned Tag, DIScope *Scope, DINodeRef Entity, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2577 | unsigned Line, StringRef Name = ""), |
| 2578 | (Tag, Scope, Entity, Line, Name)) |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2579 | DEFINE_MDNODE_GET(DIImportedEntity, |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2580 | (unsigned Tag, Metadata *Scope, Metadata *Entity, |
| 2581 | unsigned Line, MDString *Name), |
| 2582 | (Tag, Scope, Entity, Line, Name)) |
| 2583 | |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2584 | TempDIImportedEntity clone() const { return cloneImpl(); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2585 | |
| 2586 | unsigned getLine() const { return Line; } |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2587 | DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); } |
| 2588 | DINodeRef getEntity() const { return DINodeRef(getRawEntity()); } |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2589 | StringRef getName() const { return getStringOperand(2); } |
| 2590 | |
| Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2591 | Metadata *getRawScope() const { return getOperand(0); } |
| 2592 | Metadata *getRawEntity() const { return getOperand(1); } |
| Duncan P. N. Exon Smith | 1c93116 | 2015-02-13 01:46:02 +0000 | [diff] [blame] | 2593 | MDString *getRawName() const { return getOperandAs<MDString>(2); } |
| 2594 | |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2595 | static bool classof(const Metadata *MD) { |
| Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2596 | return MD->getMetadataID() == DIImportedEntityKind; |
| Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2597 | } |
| 2598 | }; |
| 2599 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2600 | /// A pair of DIGlobalVariable and DIExpression. |
| 2601 | class DIGlobalVariableExpression : public MDNode { |
| 2602 | friend class LLVMContextImpl; |
| 2603 | friend class MDNode; |
| 2604 | |
| 2605 | DIGlobalVariableExpression(LLVMContext &C, StorageType Storage, |
| 2606 | ArrayRef<Metadata *> Ops) |
| 2607 | : MDNode(C, DIGlobalVariableExpressionKind, Storage, Ops) {} |
| 2608 | ~DIGlobalVariableExpression() = default; |
| 2609 | |
| 2610 | static DIGlobalVariableExpression * |
| 2611 | getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Expression, |
| 2612 | StorageType Storage, bool ShouldCreate = true); |
| 2613 | |
| 2614 | TempDIGlobalVariableExpression cloneImpl() const { |
| 2615 | return getTemporary(getContext(), getVariable(), getExpression()); |
| 2616 | } |
| 2617 | |
| 2618 | public: |
| 2619 | DEFINE_MDNODE_GET(DIGlobalVariableExpression, |
| 2620 | (Metadata * Variable, Metadata *Expression), |
| 2621 | (Variable, Expression)) |
| 2622 | |
| 2623 | TempDIGlobalVariableExpression clone() const { return cloneImpl(); } |
| 2624 | |
| 2625 | Metadata *getRawVariable() const { return getOperand(0); } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2626 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2627 | DIGlobalVariable *getVariable() const { |
| 2628 | return cast_or_null<DIGlobalVariable>(getRawVariable()); |
| 2629 | } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2630 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2631 | Metadata *getRawExpression() const { return getOperand(1); } |
| Eugene Zelenko | d761e2c | 2017-05-15 21:57:41 +0000 | [diff] [blame] | 2632 | |
| Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2633 | DIExpression *getExpression() const { |
| 2634 | return cast_or_null<DIExpression>(getRawExpression()); |
| 2635 | } |
| 2636 | |
| 2637 | static bool classof(const Metadata *MD) { |
| 2638 | return MD->getMetadataID() == DIGlobalVariableExpressionKind; |
| 2639 | } |
| 2640 | }; |
| 2641 | |
| Adrian Prantl | 1687e01 | 2016-11-14 22:09:18 +0000 | [diff] [blame] | 2642 | /// Macro Info DWARF-like metadata node. |
| Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 2643 | /// |
| 2644 | /// A metadata node with a DWARF macro info (i.e., a constant named |
| 2645 | /// \c DW_MACINFO_*, defined in llvm/Support/Dwarf.h). Called \a DIMacroNode |
| 2646 | /// because it's potentially used for non-DWARF output. |
| 2647 | class DIMacroNode : public MDNode { |
| 2648 | friend class LLVMContextImpl; |
| 2649 | friend class MDNode; |
| 2650 | |
| 2651 | protected: |
| 2652 | DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType, |
| 2653 | ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None) |
| 2654 | : MDNode(C, ID, Storage, Ops1, Ops2) { |
| 2655 | assert(MIType < 1u << 16); |
| 2656 | SubclassData16 = MIType; |
| 2657 | } |
| 2658 | ~DIMacroNode() = default; |
| 2659 | |
| 2660 | template <class Ty> Ty *getOperandAs(unsigned I) const { |
| 2661 | return cast_or_null<Ty>(getOperand(I)); |
| 2662 | } |
| 2663 | |
| 2664 | StringRef getStringOperand(unsigned I) const { |
| 2665 | if (auto *S = getOperandAs<MDString>(I)) |
| 2666 | return S->getString(); |
| 2667 | return StringRef(); |
| 2668 | } |
| 2669 | |
| 2670 | static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) { |
| 2671 | if (S.empty()) |
| 2672 | return nullptr; |
| 2673 | return MDString::get(Context, S); |
| 2674 | } |
| 2675 | |
| 2676 | public: |
| 2677 | unsigned getMacinfoType() const { return SubclassData16; } |
| 2678 | |
| 2679 | static bool classof(const Metadata *MD) { |
| 2680 | switch (MD->getMetadataID()) { |
| 2681 | default: |
| 2682 | return false; |
| 2683 | case DIMacroKind: |
| 2684 | case DIMacroFileKind: |
| 2685 | return true; |
| 2686 | } |
| 2687 | } |
| 2688 | }; |
| 2689 | |
| 2690 | class DIMacro : public DIMacroNode { |
| 2691 | friend class LLVMContextImpl; |
| 2692 | friend class MDNode; |
| 2693 | |
| 2694 | unsigned Line; |
| 2695 | |
| 2696 | DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line, |
| 2697 | ArrayRef<Metadata *> Ops) |
| 2698 | : DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {} |
| 2699 | ~DIMacro() = default; |
| 2700 | |
| 2701 | static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line, |
| 2702 | StringRef Name, StringRef Value, StorageType Storage, |
| 2703 | bool ShouldCreate = true) { |
| 2704 | return getImpl(Context, MIType, Line, getCanonicalMDString(Context, Name), |
| 2705 | getCanonicalMDString(Context, Value), Storage, ShouldCreate); |
| 2706 | } |
| 2707 | static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line, |
| 2708 | MDString *Name, MDString *Value, StorageType Storage, |
| 2709 | bool ShouldCreate = true); |
| 2710 | |
| 2711 | TempDIMacro cloneImpl() const { |
| 2712 | return getTemporary(getContext(), getMacinfoType(), getLine(), getName(), |
| 2713 | getValue()); |
| 2714 | } |
| 2715 | |
| 2716 | public: |
| 2717 | DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, StringRef Name, |
| 2718 | StringRef Value = ""), |
| 2719 | (MIType, Line, Name, Value)) |
| 2720 | DEFINE_MDNODE_GET(DIMacro, (unsigned MIType, unsigned Line, MDString *Name, |
| 2721 | MDString *Value), |
| 2722 | (MIType, Line, Name, Value)) |
| 2723 | |
| 2724 | TempDIMacro clone() const { return cloneImpl(); } |
| 2725 | |
| 2726 | unsigned getLine() const { return Line; } |
| 2727 | |
| 2728 | StringRef getName() const { return getStringOperand(0); } |
| 2729 | StringRef getValue() const { return getStringOperand(1); } |
| 2730 | |
| 2731 | MDString *getRawName() const { return getOperandAs<MDString>(0); } |
| 2732 | MDString *getRawValue() const { return getOperandAs<MDString>(1); } |
| 2733 | |
| 2734 | static bool classof(const Metadata *MD) { |
| 2735 | return MD->getMetadataID() == DIMacroKind; |
| 2736 | } |
| 2737 | }; |
| 2738 | |
| 2739 | class DIMacroFile : public DIMacroNode { |
| 2740 | friend class LLVMContextImpl; |
| 2741 | friend class MDNode; |
| 2742 | |
| 2743 | unsigned Line; |
| 2744 | |
| 2745 | DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType, |
| 2746 | unsigned Line, ArrayRef<Metadata *> Ops) |
| 2747 | : DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {} |
| 2748 | ~DIMacroFile() = default; |
| 2749 | |
| 2750 | static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType, |
| 2751 | unsigned Line, DIFile *File, |
| 2752 | DIMacroNodeArray Elements, StorageType Storage, |
| 2753 | bool ShouldCreate = true) { |
| 2754 | return getImpl(Context, MIType, Line, static_cast<Metadata *>(File), |
| 2755 | Elements.get(), Storage, ShouldCreate); |
| 2756 | } |
| 2757 | |
| 2758 | static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType, |
| 2759 | unsigned Line, Metadata *File, Metadata *Elements, |
| 2760 | StorageType Storage, bool ShouldCreate = true); |
| 2761 | |
| 2762 | TempDIMacroFile cloneImpl() const { |
| 2763 | return getTemporary(getContext(), getMacinfoType(), getLine(), getFile(), |
| 2764 | getElements()); |
| 2765 | } |
| 2766 | |
| 2767 | public: |
| 2768 | DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, DIFile *File, |
| 2769 | DIMacroNodeArray Elements), |
| 2770 | (MIType, Line, File, Elements)) |
| 2771 | DEFINE_MDNODE_GET(DIMacroFile, (unsigned MIType, unsigned Line, |
| 2772 | Metadata *File, Metadata *Elements), |
| 2773 | (MIType, Line, File, Elements)) |
| 2774 | |
| 2775 | TempDIMacroFile clone() const { return cloneImpl(); } |
| 2776 | |
| 2777 | void replaceElements(DIMacroNodeArray Elements) { |
| 2778 | #ifndef NDEBUG |
| 2779 | for (DIMacroNode *Op : getElements()) |
| David Majnemer | 4253126 | 2016-08-12 03:55:06 +0000 | [diff] [blame] | 2780 | assert(is_contained(Elements->operands(), Op) && |
| Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 2781 | "Lost a macro node during macro node list replacement"); |
| 2782 | #endif |
| 2783 | replaceOperandWith(1, Elements.get()); |
| 2784 | } |
| 2785 | |
| 2786 | unsigned getLine() const { return Line; } |
| 2787 | DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } |
| 2788 | |
| 2789 | DIMacroNodeArray getElements() const { |
| 2790 | return cast_or_null<MDTuple>(getRawElements()); |
| 2791 | } |
| 2792 | |
| 2793 | Metadata *getRawFile() const { return getOperand(0); } |
| 2794 | Metadata *getRawElements() const { return getOperand(1); } |
| 2795 | |
| 2796 | static bool classof(const Metadata *MD) { |
| 2797 | return MD->getMetadataID() == DIMacroFileKind; |
| 2798 | } |
| 2799 | }; |
| 2800 | |
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 2801 | } // end namespace llvm |
| 2802 | |
| Duncan P. N. Exon Smith | 61e62a5 | 2015-02-02 19:55:21 +0000 | [diff] [blame] | 2803 | #undef DEFINE_MDNODE_GET_UNPACK_IMPL |
| 2804 | #undef DEFINE_MDNODE_GET_UNPACK |
| 2805 | #undef DEFINE_MDNODE_GET |
| 2806 | |
| Eugene Zelenko | 1aa40f4 | 2016-11-23 22:25:16 +0000 | [diff] [blame] | 2807 | #endif // LLVM_IR_DEBUGINFOMETADATA_H |