Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 1 | //===- DebugInfoMetadata.cpp - Implement debug info metadata --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the debug info Metadata classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/IR/DebugInfoMetadata.h" |
| 15 | #include "LLVMContextImpl.h" |
| 16 | #include "MetadataImpl.h" |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringSwitch.h" |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Function.h" |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
| 21 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 22 | DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line, |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 23 | unsigned Column, ArrayRef<Metadata *> MDs) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 24 | : MDNode(C, DILocationKind, Storage, MDs) { |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 25 | assert((MDs.size() == 1 || MDs.size() == 2) && |
| 26 | "Expected a scope and optional inlined-at"); |
| 27 | |
| 28 | // Set line and column. |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 29 | assert(Column < (1u << 16) && "Expected 16-bit column"); |
| 30 | |
| 31 | SubclassData32 = Line; |
| 32 | SubclassData16 = Column; |
| 33 | } |
| 34 | |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 35 | static void adjustColumn(unsigned &Column) { |
| 36 | // Set to unknown on overflow. We only have 16 bits to play with here. |
| 37 | if (Column >= (1u << 16)) |
| 38 | Column = 0; |
| 39 | } |
| 40 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 41 | DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line, |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 42 | unsigned Column, Metadata *Scope, |
| 43 | Metadata *InlinedAt, StorageType Storage, |
| 44 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 45 | // Fixup column. |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 46 | adjustColumn(Column); |
| 47 | |
| 48 | if (Storage == Uniqued) { |
| 49 | if (auto *N = |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 50 | getUniqued(Context.pImpl->DILocations, |
| 51 | DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt))) |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 52 | return N; |
| 53 | if (!ShouldCreate) |
| 54 | return nullptr; |
| 55 | } else { |
| 56 | assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); |
| 57 | } |
| 58 | |
| 59 | SmallVector<Metadata *, 2> Ops; |
| 60 | Ops.push_back(Scope); |
| 61 | if (InlinedAt) |
| 62 | Ops.push_back(InlinedAt); |
| 63 | return storeImpl(new (Ops.size()) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 64 | DILocation(Context, Storage, Line, Column, Ops), |
| 65 | Storage, Context.pImpl->DILocations); |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 68 | DINode::DIFlags DINode::getFlag(StringRef Flag) { |
| 69 | return StringSwitch<DIFlags>(Flag) |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 70 | #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME) |
| 71 | #include "llvm/IR/DebugInfoFlags.def" |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 72 | .Default(DINode::FlagZero); |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Mehdi Amini | f42ec79 | 2016-10-01 05:57:50 +0000 | [diff] [blame] | 75 | StringRef DINode::getFlagString(DIFlags Flag) { |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 76 | switch (Flag) { |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 77 | #define HANDLE_DI_FLAG(ID, NAME) \ |
| 78 | case Flag##NAME: \ |
| 79 | return "DIFlag" #NAME; |
| 80 | #include "llvm/IR/DebugInfoFlags.def" |
| 81 | } |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 82 | return ""; |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 85 | DINode::DIFlags DINode::splitFlags(DIFlags Flags, |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 86 | SmallVectorImpl<DIFlags> &SplitFlags) { |
Bob Haarman | 26a87bd | 2016-10-25 22:11:52 +0000 | [diff] [blame] | 87 | // Flags that are packed together need to be specially handled, so |
| 88 | // that, for example, we emit "DIFlagPublic" and not |
| 89 | // "DIFlagPrivate | DIFlagProtected". |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 90 | if (DIFlags A = Flags & FlagAccessibility) { |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 91 | if (A == FlagPrivate) |
| 92 | SplitFlags.push_back(FlagPrivate); |
| 93 | else if (A == FlagProtected) |
| 94 | SplitFlags.push_back(FlagProtected); |
| 95 | else |
| 96 | SplitFlags.push_back(FlagPublic); |
| 97 | Flags &= ~A; |
| 98 | } |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 99 | if (DIFlags R = Flags & FlagPtrToMemberRep) { |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 100 | if (R == FlagSingleInheritance) |
| 101 | SplitFlags.push_back(FlagSingleInheritance); |
| 102 | else if (R == FlagMultipleInheritance) |
| 103 | SplitFlags.push_back(FlagMultipleInheritance); |
| 104 | else |
| 105 | SplitFlags.push_back(FlagVirtualInheritance); |
| 106 | Flags &= ~R; |
| 107 | } |
Bob Haarman | 26a87bd | 2016-10-25 22:11:52 +0000 | [diff] [blame] | 108 | if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) { |
| 109 | Flags &= ~FlagIndirectVirtualBase; |
| 110 | SplitFlags.push_back(FlagIndirectVirtualBase); |
| 111 | } |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 112 | |
| 113 | #define HANDLE_DI_FLAG(ID, NAME) \ |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 114 | if (DIFlags Bit = Flags & Flag##NAME) { \ |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 115 | SplitFlags.push_back(Bit); \ |
| 116 | Flags &= ~Bit; \ |
| 117 | } |
| 118 | #include "llvm/IR/DebugInfoFlags.def" |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 119 | return Flags; |
| 120 | } |
| 121 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 122 | DIScopeRef DIScope::getScope() const { |
| 123 | if (auto *T = dyn_cast<DIType>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 124 | return T->getScope(); |
| 125 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 126 | if (auto *SP = dyn_cast<DISubprogram>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 127 | return SP->getScope(); |
| 128 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 129 | if (auto *LB = dyn_cast<DILexicalBlockBase>(this)) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 130 | return LB->getScope(); |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 131 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 132 | if (auto *NS = dyn_cast<DINamespace>(this)) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 133 | return NS->getScope(); |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 134 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 135 | if (auto *M = dyn_cast<DIModule>(this)) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 136 | return M->getScope(); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 137 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 138 | assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) && |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 139 | "Unhandled type of scope."); |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 143 | StringRef DIScope::getName() const { |
| 144 | if (auto *T = dyn_cast<DIType>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 145 | return T->getName(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 146 | if (auto *SP = dyn_cast<DISubprogram>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 147 | return SP->getName(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 148 | if (auto *NS = dyn_cast<DINamespace>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 149 | return NS->getName(); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 150 | if (auto *M = dyn_cast<DIModule>(this)) |
| 151 | return M->getName(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 152 | assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || |
| 153 | isa<DICompileUnit>(this)) && |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 154 | "Unhandled type of scope."); |
| 155 | return ""; |
| 156 | } |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 157 | |
Duncan P. N. Exon Smith | c7e0813 | 2015-02-02 20:20:56 +0000 | [diff] [blame] | 158 | #ifndef NDEBUG |
Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 159 | static bool isCanonical(const MDString *S) { |
| 160 | return !S || !S->getString().empty(); |
Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 161 | } |
Duncan P. N. Exon Smith | c7e0813 | 2015-02-02 20:20:56 +0000 | [diff] [blame] | 162 | #endif |
Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 163 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 164 | GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag, |
| 165 | MDString *Header, |
| 166 | ArrayRef<Metadata *> DwarfOps, |
| 167 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 168 | unsigned Hash = 0; |
| 169 | if (Storage == Uniqued) { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 170 | GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 171 | if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key)) |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 172 | return N; |
| 173 | if (!ShouldCreate) |
| 174 | return nullptr; |
| 175 | Hash = Key.getHash(); |
| 176 | } else { |
| 177 | assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); |
| 178 | } |
| 179 | |
| 180 | // Use a nullptr for empty headers. |
Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 181 | assert(isCanonical(Header) && "Expected canonical MDString"); |
| 182 | Metadata *PreOps[] = {Header}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 183 | return storeImpl(new (DwarfOps.size() + 1) GenericDINode( |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 184 | Context, Storage, Hash, Tag, PreOps, DwarfOps), |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 185 | Storage, Context.pImpl->GenericDINodes); |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 188 | void GenericDINode::recalculateHash() { |
| 189 | setHash(GenericDINodeInfo::KeyTy::calculateHash(this)); |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 190 | } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 191 | |
| 192 | #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__ |
| 193 | #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS |
| 194 | #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \ |
| 195 | do { \ |
| 196 | if (Storage == Uniqued) { \ |
| 197 | if (auto *N = getUniqued(Context.pImpl->CLASS##s, \ |
| 198 | CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \ |
| 199 | return N; \ |
| 200 | if (!ShouldCreate) \ |
| 201 | return nullptr; \ |
| 202 | } else { \ |
| 203 | assert(ShouldCreate && \ |
| 204 | "Expected non-uniqued nodes to always be created"); \ |
| 205 | } \ |
| 206 | } while (false) |
| 207 | #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \ |
David Blaikie | 6662d6a | 2016-04-13 17:42:56 +0000 | [diff] [blame] | 208 | return storeImpl(new (array_lengthof(OPS)) \ |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 209 | CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \ |
| 210 | Storage, Context.pImpl->CLASS##s) |
| 211 | #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \ |
| 212 | return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \ |
| 213 | Storage, Context.pImpl->CLASS##s) |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 214 | #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \ |
David Blaikie | 6662d6a | 2016-04-13 17:42:56 +0000 | [diff] [blame] | 215 | return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \ |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 216 | Storage, Context.pImpl->CLASS##s) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 217 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 218 | DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 219 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 220 | DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo)); |
| 221 | DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 224 | DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 225 | MDString *Name, StorageType Storage, |
| 226 | bool ShouldCreate) { |
| 227 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 228 | DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, Name)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 229 | Metadata *Ops[] = {Name}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 230 | DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 233 | DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 234 | MDString *Name, uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 235 | uint32_t AlignInBits, unsigned Encoding, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 236 | StorageType Storage, bool ShouldCreate) { |
| 237 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 238 | DEFINE_GETIMPL_LOOKUP(DIBasicType, |
| 239 | (Tag, Name, SizeInBits, AlignInBits, Encoding)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 240 | Metadata *Ops[] = {nullptr, nullptr, Name}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 241 | DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 242 | Ops); |
| 243 | } |
| 244 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 245 | DIDerivedType *DIDerivedType::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 246 | LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 247 | unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 248 | uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 249 | Metadata *ExtraData, StorageType Storage, bool ShouldCreate) { |
| 250 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 251 | DEFINE_GETIMPL_LOOKUP(DIDerivedType, |
| 252 | (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 253 | AlignInBits, OffsetInBits, Flags, ExtraData)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 254 | Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData}; |
| 255 | DEFINE_GETIMPL_STORE( |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 256 | DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 257 | Ops); |
| 258 | } |
| 259 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 260 | DICompositeType *DICompositeType::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 261 | LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 262 | unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 263 | uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 264 | Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, |
| 265 | Metadata *TemplateParams, MDString *Identifier, StorageType Storage, |
| 266 | bool ShouldCreate) { |
| 267 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | 5ab2be0 | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 268 | |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 269 | // Keep this in sync with buildODRType. |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 270 | DEFINE_GETIMPL_LOOKUP( |
| 271 | DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 272 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 273 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 274 | Metadata *Ops[] = {File, Scope, Name, BaseType, |
| 275 | Elements, VTableHolder, TemplateParams, Identifier}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 276 | DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 277 | AlignInBits, OffsetInBits, Flags), |
| 278 | Ops); |
| 279 | } |
| 280 | |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 281 | DICompositeType *DICompositeType::buildODRType( |
| 282 | LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, |
| 283 | Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 284 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 285 | DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 286 | Metadata *VTableHolder, Metadata *TemplateParams) { |
| 287 | assert(!Identifier.getString().empty() && "Expected valid identifier"); |
| 288 | if (!Context.isODRUniquingDebugTypes()) |
| 289 | return nullptr; |
| 290 | auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier]; |
| 291 | if (!CT) |
| 292 | return CT = DICompositeType::getDistinct( |
| 293 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 294 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 295 | VTableHolder, TemplateParams, &Identifier); |
| 296 | |
| 297 | // Only mutate CT if it's a forward declaration and the new operands aren't. |
| 298 | assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?"); |
| 299 | if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl)) |
| 300 | return CT; |
| 301 | |
| 302 | // Mutate CT in place. Keep this in sync with getImpl. |
| 303 | CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, |
| 304 | Flags); |
| 305 | Metadata *Ops[] = {File, Scope, Name, BaseType, |
| 306 | Elements, VTableHolder, TemplateParams, &Identifier}; |
Simon Pilgrim | 1ec7dc7 | 2016-05-02 16:45:02 +0000 | [diff] [blame] | 307 | assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() && |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 308 | "Mismatched number of operands"); |
| 309 | for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I) |
| 310 | if (Ops[I] != CT->getOperand(I)) |
| 311 | CT->setOperand(I, Ops[I]); |
| 312 | return CT; |
| 313 | } |
| 314 | |
Duncan P. N. Exon Smith | 0b0271e | 2016-04-19 14:55:09 +0000 | [diff] [blame] | 315 | DICompositeType *DICompositeType::getODRType( |
| 316 | LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, |
| 317 | Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 318 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 319 | DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, |
Duncan P. N. Exon Smith | 0b0271e | 2016-04-19 14:55:09 +0000 | [diff] [blame] | 320 | Metadata *VTableHolder, Metadata *TemplateParams) { |
| 321 | assert(!Identifier.getString().empty() && "Expected valid identifier"); |
| 322 | if (!Context.isODRUniquingDebugTypes()) |
| 323 | return nullptr; |
| 324 | auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier]; |
| 325 | if (!CT) |
| 326 | CT = DICompositeType::getDistinct( |
| 327 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 328 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, |
| 329 | TemplateParams, &Identifier); |
| 330 | return CT; |
| 331 | } |
| 332 | |
| 333 | DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context, |
| 334 | MDString &Identifier) { |
| 335 | assert(!Identifier.getString().empty() && "Expected valid identifier"); |
| 336 | if (!Context.isODRUniquingDebugTypes()) |
| 337 | return nullptr; |
| 338 | return Context.pImpl->DITypeMap->lookup(&Identifier); |
| 339 | } |
| 340 | |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 341 | DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags, |
| 342 | uint8_t CC, Metadata *TypeArray, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 343 | StorageType Storage, |
| 344 | bool ShouldCreate) { |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 345 | DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray)); |
Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 346 | Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray}; |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 347 | DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 350 | DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 351 | MDString *Directory, StorageType Storage, |
| 352 | bool ShouldCreate) { |
| 353 | assert(isCanonical(Filename) && "Expected canonical MDString"); |
| 354 | assert(isCanonical(Directory) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 355 | DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory)); |
Duncan P. N. Exon Smith | a5c57cc | 2015-02-20 20:35:17 +0000 | [diff] [blame] | 356 | Metadata *Ops[] = {Filename, Directory}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 357 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIFile, Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 360 | DICompileUnit *DICompileUnit::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 361 | LLVMContext &Context, unsigned SourceLanguage, Metadata *File, |
| 362 | MDString *Producer, bool IsOptimized, MDString *Flags, |
| 363 | unsigned RuntimeVersion, MDString *SplitDebugFilename, |
| 364 | unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes, |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 365 | Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros, |
David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 366 | uint64_t DWOId, bool SplitDebugInlining, StorageType Storage, |
| 367 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 368 | assert(Storage != Uniqued && "Cannot unique DICompileUnit"); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 369 | assert(isCanonical(Producer) && "Expected canonical MDString"); |
| 370 | assert(isCanonical(Flags) && "Expected canonical MDString"); |
| 371 | assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 372 | |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 373 | Metadata *Ops[] = { |
| 374 | File, Producer, Flags, SplitDebugFilename, |
| 375 | EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities, |
| 376 | Macros}; |
David Blaikie | a01f295 | 2016-08-24 18:29:49 +0000 | [diff] [blame] | 377 | return storeImpl(new (array_lengthof(Ops)) |
| 378 | DICompileUnit(Context, Storage, SourceLanguage, |
| 379 | IsOptimized, RuntimeVersion, EmissionKind, |
| 380 | DWOId, SplitDebugInlining, Ops), |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 381 | Storage); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 384 | Optional<DICompileUnit::DebugEmissionKind> |
| 385 | DICompileUnit::getEmissionKind(StringRef Str) { |
| 386 | return StringSwitch<Optional<DebugEmissionKind>>(Str) |
| 387 | .Case("NoDebug", NoDebug) |
| 388 | .Case("FullDebug", FullDebug) |
| 389 | .Case("LineTablesOnly", LineTablesOnly) |
| 390 | .Default(None); |
| 391 | } |
| 392 | |
| 393 | const char *DICompileUnit::EmissionKindString(DebugEmissionKind EK) { |
| 394 | switch (EK) { |
| 395 | case NoDebug: return "NoDebug"; |
| 396 | case FullDebug: return "FullDebug"; |
| 397 | case LineTablesOnly: return "LineTablesOnly"; |
| 398 | } |
| 399 | return nullptr; |
| 400 | } |
| 401 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 402 | DISubprogram *DILocalScope::getSubprogram() const { |
| 403 | if (auto *Block = dyn_cast<DILexicalBlockBase>(this)) |
Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 404 | return Block->getScope()->getSubprogram(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 405 | return const_cast<DISubprogram *>(cast<DISubprogram>(this)); |
Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Amjad Aboud | a5ba991 | 2016-04-21 16:58:49 +0000 | [diff] [blame] | 408 | DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const { |
| 409 | if (auto *File = dyn_cast<DILexicalBlockFile>(this)) |
| 410 | return File->getScope()->getNonLexicalBlockFileScope(); |
| 411 | return const_cast<DILocalScope *>(this); |
| 412 | } |
| 413 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 414 | DISubprogram *DISubprogram::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 415 | LLVMContext &Context, Metadata *Scope, MDString *Name, |
| 416 | MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, |
| 417 | bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, |
| 418 | Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 419 | int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit, |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 420 | Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables, |
| 421 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 422 | assert(isCanonical(Name) && "Expected canonical MDString"); |
| 423 | assert(isCanonical(LinkageName) && "Expected canonical MDString"); |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 424 | DEFINE_GETIMPL_LOOKUP( |
| 425 | DISubprogram, |
| 426 | (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, |
| 427 | ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, |
| 428 | Flags, IsOptimized, Unit, TemplateParams, Declaration, Variables)); |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 429 | Metadata *Ops[] = {File, Scope, Name, Name, |
| 430 | LinkageName, Type, ContainingType, Unit, |
| 431 | TemplateParams, Declaration, Variables}; |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 432 | DEFINE_GETIMPL_STORE(DISubprogram, (Line, ScopeLine, Virtuality, VirtualIndex, |
| 433 | ThisAdjustment, Flags, IsLocalToUnit, |
| 434 | IsDefinition, IsOptimized), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 435 | Ops); |
| 436 | } |
| 437 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 438 | bool DISubprogram::describes(const Function *F) const { |
Duncan P. N. Exon Smith | 3c2d704 | 2015-04-13 19:07:27 +0000 | [diff] [blame] | 439 | assert(F && "Invalid function"); |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 440 | if (F->getSubprogram() == this) |
Duncan P. N. Exon Smith | 3c2d704 | 2015-04-13 19:07:27 +0000 | [diff] [blame] | 441 | return true; |
| 442 | StringRef Name = getLinkageName(); |
| 443 | if (Name.empty()) |
| 444 | Name = getName(); |
| 445 | return F->getName() == Name; |
| 446 | } |
| 447 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 448 | DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 449 | Metadata *File, unsigned Line, |
| 450 | unsigned Column, StorageType Storage, |
| 451 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | b09eb9f | 2015-08-28 22:58:50 +0000 | [diff] [blame] | 452 | // Fixup column. |
| 453 | adjustColumn(Column); |
| 454 | |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 455 | assert(Scope && "Expected scope"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 456 | DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 457 | Metadata *Ops[] = {File, Scope}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 458 | DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 461 | DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 462 | Metadata *Scope, Metadata *File, |
| 463 | unsigned Discriminator, |
| 464 | StorageType Storage, |
| 465 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 466 | assert(Scope && "Expected scope"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 467 | DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 468 | Metadata *Ops[] = {File, Scope}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 469 | DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 472 | DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 473 | Metadata *File, MDString *Name, unsigned Line, |
Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 474 | bool ExportSymbols, StorageType Storage, |
| 475 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 476 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 477 | DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, Name, Line, ExportSymbols)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 478 | Metadata *Ops[] = {File, Scope, Name}; |
Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 479 | DEFINE_GETIMPL_STORE(DINamespace, (Line, ExportSymbols), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 482 | DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope, |
| 483 | MDString *Name, MDString *ConfigurationMacros, |
| 484 | MDString *IncludePath, MDString *ISysRoot, |
| 485 | StorageType Storage, bool ShouldCreate) { |
| 486 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 487 | DEFINE_GETIMPL_LOOKUP( |
| 488 | DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot)); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 489 | Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot}; |
| 490 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops); |
| 491 | } |
| 492 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 493 | DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context, |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 494 | MDString *Name, |
| 495 | Metadata *Type, |
| 496 | StorageType Storage, |
| 497 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 498 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 499 | DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type)); |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 500 | Metadata *Ops[] = {Name, Type}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 501 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 504 | DITemplateValueParameter *DITemplateValueParameter::getImpl( |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 505 | LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type, |
| 506 | Metadata *Value, StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 507 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 508 | DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value)); |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 509 | Metadata *Ops[] = {Name, Type, Value}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 510 | DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 513 | DIGlobalVariable * |
| 514 | DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 515 | MDString *LinkageName, Metadata *File, unsigned Line, |
| 516 | Metadata *Type, bool IsLocalToUnit, bool IsDefinition, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 517 | Metadata *StaticDataMemberDeclaration, |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 518 | uint32_t AlignInBits, StorageType Storage, |
| 519 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 520 | assert(isCanonical(Name) && "Expected canonical MDString"); |
| 521 | assert(isCanonical(LinkageName) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 522 | DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 523 | (Scope, Name, LinkageName, File, Line, Type, |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 524 | IsLocalToUnit, IsDefinition, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 525 | StaticDataMemberDeclaration, AlignInBits)); |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 526 | Metadata *Ops[] = { |
| 527 | Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration}; |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 528 | DEFINE_GETIMPL_STORE(DIGlobalVariable, |
| 529 | (Line, IsLocalToUnit, IsDefinition, AlignInBits), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 530 | Ops); |
| 531 | } |
| 532 | |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 533 | DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, |
| 534 | MDString *Name, Metadata *File, |
| 535 | unsigned Line, Metadata *Type, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 536 | unsigned Arg, DIFlags Flags, |
Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 537 | uint32_t AlignInBits, |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 538 | StorageType Storage, |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 539 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 1ec75ae | 2015-04-28 01:07:33 +0000 | [diff] [blame] | 540 | // 64K ought to be enough for any frontend. |
| 541 | assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits"); |
Duncan P. N. Exon Smith | 72fe2d0 | 2015-02-13 01:39:44 +0000 | [diff] [blame] | 542 | |
Duncan P. N. Exon Smith | e2c61d9 | 2015-03-27 17:56:39 +0000 | [diff] [blame] | 543 | assert(Scope && "Expected scope"); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 544 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 545 | DEFINE_GETIMPL_LOOKUP(DILocalVariable, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 546 | (Scope, Name, File, Line, Type, Arg, Flags, |
| 547 | AlignInBits)); |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 548 | Metadata *Ops[] = {Scope, Name, File, Type}; |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 549 | DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 552 | DIExpression *DIExpression::getImpl(LLVMContext &Context, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 553 | ArrayRef<uint64_t> Elements, |
| 554 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 555 | DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements)); |
| 556 | DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 559 | unsigned DIExpression::ExprOperand::getSize() const { |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 560 | switch (getOp()) { |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 561 | case dwarf::DW_OP_LLVM_fragment: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 562 | return 3; |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 563 | case dwarf::DW_OP_constu: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 564 | case dwarf::DW_OP_plus: |
Evgeniy Stepanov | f608111 | 2015-09-30 19:55:43 +0000 | [diff] [blame] | 565 | case dwarf::DW_OP_minus: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 566 | return 2; |
| 567 | default: |
| 568 | return 1; |
| 569 | } |
| 570 | } |
| 571 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 572 | bool DIExpression::isValid() const { |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 573 | for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) { |
| 574 | // Check that there's space for the operand. |
| 575 | if (I->get() + I->getSize() > E->get()) |
| 576 | return false; |
| 577 | |
| 578 | // Check that the operand is valid. |
| 579 | switch (I->getOp()) { |
| 580 | default: |
| 581 | return false; |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 582 | case dwarf::DW_OP_LLVM_fragment: |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 583 | // A fragment operator must appear at the end. |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 584 | return I->get() + I->getSize() == E->get(); |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 585 | case dwarf::DW_OP_stack_value: { |
| 586 | // Must be the last one or followed by a DW_OP_LLVM_fragment. |
| 587 | if (I->get() + I->getSize() == E->get()) |
| 588 | break; |
| 589 | auto J = I; |
| 590 | if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment) |
| 591 | return false; |
| 592 | break; |
| 593 | } |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 594 | case dwarf::DW_OP_constu: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 595 | case dwarf::DW_OP_plus: |
Evgeniy Stepanov | f608111 | 2015-09-30 19:55:43 +0000 | [diff] [blame] | 596 | case dwarf::DW_OP_minus: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 597 | case dwarf::DW_OP_deref: |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | return true; |
| 602 | } |
| 603 | |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 604 | bool DIExpression::isFragment() const { |
Duncan P. N. Exon Smith | 86cc332 | 2015-04-07 03:49:59 +0000 | [diff] [blame] | 605 | assert(isValid() && "Expected valid expression"); |
| 606 | if (unsigned N = getNumElements()) |
| 607 | if (N >= 3) |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 608 | return getElement(N - 3) == dwarf::DW_OP_LLVM_fragment; |
Duncan P. N. Exon Smith | 86cc332 | 2015-04-07 03:49:59 +0000 | [diff] [blame] | 609 | return false; |
| 610 | } |
| 611 | |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 612 | uint64_t DIExpression::getFragmentOffsetInBits() const { |
| 613 | assert(isFragment() && "Expected fragment"); |
Duncan P. N. Exon Smith | 86cc332 | 2015-04-07 03:49:59 +0000 | [diff] [blame] | 614 | return getElement(getNumElements() - 2); |
| 615 | } |
| 616 | |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 617 | uint64_t DIExpression::getFragmentSizeInBits() const { |
| 618 | assert(isFragment() && "Expected fragment"); |
Duncan P. N. Exon Smith | 86cc332 | 2015-04-07 03:49:59 +0000 | [diff] [blame] | 619 | return getElement(getNumElements() - 1); |
| 620 | } |
| 621 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 622 | bool DIExpression::isConstant() const { |
| 623 | // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?. |
| 624 | if (getNumElements() != 3 && getNumElements() != 6) |
| 625 | return false; |
| 626 | if (getElement(0) != dwarf::DW_OP_constu || |
| 627 | getElement(2) != dwarf::DW_OP_stack_value) |
| 628 | return false; |
| 629 | if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment) |
| 630 | return false; |
| 631 | return true; |
| 632 | } |
| 633 | |
| 634 | DIGlobalVariableExpression * |
| 635 | DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable, |
| 636 | Metadata *Expression, StorageType Storage, |
| 637 | bool ShouldCreate) { |
| 638 | DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression)); |
| 639 | Metadata *Ops[] = {Variable, Expression}; |
| 640 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops); |
| 641 | } |
| 642 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 643 | DIObjCProperty *DIObjCProperty::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 644 | LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line, |
| 645 | MDString *GetterName, MDString *SetterName, unsigned Attributes, |
| 646 | Metadata *Type, StorageType Storage, bool ShouldCreate) { |
| 647 | assert(isCanonical(Name) && "Expected canonical MDString"); |
| 648 | assert(isCanonical(GetterName) && "Expected canonical MDString"); |
| 649 | assert(isCanonical(SetterName) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 650 | DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName, |
| 651 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 652 | Metadata *Ops[] = {Name, File, GetterName, SetterName, Type}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 653 | DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 656 | DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 657 | Metadata *Scope, Metadata *Entity, |
| 658 | unsigned Line, MDString *Name, |
| 659 | StorageType Storage, |
| 660 | bool ShouldCreate) { |
| 661 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 662 | DEFINE_GETIMPL_LOOKUP(DIImportedEntity, (Tag, Scope, Entity, Line, Name)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 663 | Metadata *Ops[] = {Scope, Entity, Name}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 664 | DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 665 | } |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 666 | |
| 667 | DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, |
| 668 | unsigned Line, MDString *Name, MDString *Value, |
| 669 | StorageType Storage, bool ShouldCreate) { |
| 670 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 671 | DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value)); |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 672 | Metadata *Ops[] = { Name, Value }; |
| 673 | DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops); |
| 674 | } |
| 675 | |
| 676 | DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType, |
| 677 | unsigned Line, Metadata *File, |
| 678 | Metadata *Elements, StorageType Storage, |
| 679 | bool ShouldCreate) { |
| 680 | DEFINE_GETIMPL_LOOKUP(DIMacroFile, |
| 681 | (MIType, Line, File, Elements)); |
| 682 | Metadata *Ops[] = { File, Elements }; |
| 683 | DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops); |
| 684 | } |
| 685 | |