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