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