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