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