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