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" |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DIBuilder.h" |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Function.h" |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 23 | DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line, |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 24 | unsigned Column, ArrayRef<Metadata *> MDs) |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 25 | : MDNode(C, DILocationKind, Storage, MDs) { |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 26 | assert((MDs.size() == 1 || MDs.size() == 2) && |
| 27 | "Expected a scope and optional inlined-at"); |
| 28 | |
| 29 | // Set line and column. |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 30 | assert(Column < (1u << 16) && "Expected 16-bit column"); |
| 31 | |
| 32 | SubclassData32 = Line; |
| 33 | SubclassData16 = Column; |
| 34 | } |
| 35 | |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 36 | static void adjustColumn(unsigned &Column) { |
| 37 | // Set to unknown on overflow. We only have 16 bits to play with here. |
| 38 | if (Column >= (1u << 16)) |
| 39 | Column = 0; |
| 40 | } |
| 41 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 42 | DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line, |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 43 | unsigned Column, Metadata *Scope, |
| 44 | Metadata *InlinedAt, StorageType Storage, |
| 45 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 46 | // Fixup column. |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 47 | adjustColumn(Column); |
| 48 | |
| 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 | |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 69 | DINode::DIFlags DINode::getFlag(StringRef Flag) { |
| 70 | return StringSwitch<DIFlags>(Flag) |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 71 | #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME) |
| 72 | #include "llvm/IR/DebugInfoFlags.def" |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 73 | .Default(DINode::FlagZero); |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Mehdi Amini | f42ec79 | 2016-10-01 05:57:50 +0000 | [diff] [blame] | 76 | StringRef DINode::getFlagString(DIFlags Flag) { |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 77 | switch (Flag) { |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 78 | #define HANDLE_DI_FLAG(ID, NAME) \ |
| 79 | case Flag##NAME: \ |
| 80 | return "DIFlag" #NAME; |
| 81 | #include "llvm/IR/DebugInfoFlags.def" |
| 82 | } |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 83 | return ""; |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 86 | DINode::DIFlags DINode::splitFlags(DIFlags Flags, |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 87 | SmallVectorImpl<DIFlags> &SplitFlags) { |
Bob Haarman | 26a87bd | 2016-10-25 22:11:52 +0000 | [diff] [blame] | 88 | // Flags that are packed together need to be specially handled, so |
| 89 | // that, for example, we emit "DIFlagPublic" and not |
| 90 | // "DIFlagPrivate | DIFlagProtected". |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 91 | if (DIFlags A = Flags & FlagAccessibility) { |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 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 | } |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 100 | if (DIFlags R = Flags & FlagPtrToMemberRep) { |
Reid Kleckner | 604105b | 2016-06-17 21:31:33 +0000 | [diff] [blame] | 101 | if (R == FlagSingleInheritance) |
| 102 | SplitFlags.push_back(FlagSingleInheritance); |
| 103 | else if (R == FlagMultipleInheritance) |
| 104 | SplitFlags.push_back(FlagMultipleInheritance); |
| 105 | else |
| 106 | SplitFlags.push_back(FlagVirtualInheritance); |
| 107 | Flags &= ~R; |
| 108 | } |
Bob Haarman | 26a87bd | 2016-10-25 22:11:52 +0000 | [diff] [blame] | 109 | if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) { |
| 110 | Flags &= ~FlagIndirectVirtualBase; |
| 111 | SplitFlags.push_back(FlagIndirectVirtualBase); |
| 112 | } |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 113 | |
| 114 | #define HANDLE_DI_FLAG(ID, NAME) \ |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 115 | if (DIFlags Bit = Flags & Flag##NAME) { \ |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 116 | SplitFlags.push_back(Bit); \ |
| 117 | Flags &= ~Bit; \ |
| 118 | } |
| 119 | #include "llvm/IR/DebugInfoFlags.def" |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 120 | return Flags; |
| 121 | } |
| 122 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 123 | DIScopeRef DIScope::getScope() const { |
| 124 | if (auto *T = dyn_cast<DIType>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 125 | return T->getScope(); |
| 126 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 127 | if (auto *SP = dyn_cast<DISubprogram>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 128 | return SP->getScope(); |
| 129 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 130 | if (auto *LB = dyn_cast<DILexicalBlockBase>(this)) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 131 | return LB->getScope(); |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 132 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 133 | if (auto *NS = dyn_cast<DINamespace>(this)) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 134 | return NS->getScope(); |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 135 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 136 | if (auto *M = dyn_cast<DIModule>(this)) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 137 | return M->getScope(); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 138 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 139 | assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) && |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 140 | "Unhandled type of scope."); |
| 141 | return nullptr; |
| 142 | } |
| 143 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 144 | StringRef DIScope::getName() const { |
| 145 | if (auto *T = dyn_cast<DIType>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 146 | return T->getName(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 147 | if (auto *SP = dyn_cast<DISubprogram>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 148 | return SP->getName(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 149 | if (auto *NS = dyn_cast<DINamespace>(this)) |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 150 | return NS->getName(); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 151 | if (auto *M = dyn_cast<DIModule>(this)) |
| 152 | return M->getName(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 153 | assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) || |
| 154 | isa<DICompileUnit>(this)) && |
Duncan P. N. Exon Smith | f0d81a5 | 2015-04-11 17:37:23 +0000 | [diff] [blame] | 155 | "Unhandled type of scope."); |
| 156 | return ""; |
| 157 | } |
Duncan P. N. Exon Smith | 5261e4b | 2015-04-07 01:21:40 +0000 | [diff] [blame] | 158 | |
Duncan P. N. Exon Smith | c7e0813 | 2015-02-02 20:20:56 +0000 | [diff] [blame] | 159 | #ifndef NDEBUG |
Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 160 | static bool isCanonical(const MDString *S) { |
| 161 | return !S || !S->getString().empty(); |
Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 162 | } |
Duncan P. N. Exon Smith | c7e0813 | 2015-02-02 20:20:56 +0000 | [diff] [blame] | 163 | #endif |
Duncan P. N. Exon Smith | 442ec02 | 2015-02-02 19:54:05 +0000 | [diff] [blame] | 164 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 165 | GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag, |
| 166 | MDString *Header, |
| 167 | ArrayRef<Metadata *> DwarfOps, |
| 168 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 169 | unsigned Hash = 0; |
| 170 | if (Storage == Uniqued) { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 171 | GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 172 | if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key)) |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 173 | return N; |
| 174 | if (!ShouldCreate) |
| 175 | return nullptr; |
| 176 | Hash = Key.getHash(); |
| 177 | } else { |
| 178 | assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); |
| 179 | } |
| 180 | |
| 181 | // Use a nullptr for empty headers. |
Duncan P. N. Exon Smith | 9146fc8 | 2015-02-02 20:01:03 +0000 | [diff] [blame] | 182 | assert(isCanonical(Header) && "Expected canonical MDString"); |
| 183 | Metadata *PreOps[] = {Header}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 184 | return storeImpl(new (DwarfOps.size() + 1) GenericDINode( |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 185 | Context, Storage, Hash, Tag, PreOps, DwarfOps), |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 186 | Storage, Context.pImpl->GenericDINodes); |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 189 | void GenericDINode::recalculateHash() { |
| 190 | setHash(GenericDINodeInfo::KeyTy::calculateHash(this)); |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 191 | } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 192 | |
| 193 | #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__ |
| 194 | #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS |
| 195 | #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \ |
| 196 | do { \ |
| 197 | if (Storage == Uniqued) { \ |
| 198 | if (auto *N = getUniqued(Context.pImpl->CLASS##s, \ |
| 199 | CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \ |
| 200 | return N; \ |
| 201 | if (!ShouldCreate) \ |
| 202 | return nullptr; \ |
| 203 | } else { \ |
| 204 | assert(ShouldCreate && \ |
| 205 | "Expected non-uniqued nodes to always be created"); \ |
| 206 | } \ |
| 207 | } while (false) |
| 208 | #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \ |
David Blaikie | 6662d6a | 2016-04-13 17:42:56 +0000 | [diff] [blame] | 209 | return storeImpl(new (array_lengthof(OPS)) \ |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 210 | CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \ |
| 211 | Storage, Context.pImpl->CLASS##s) |
| 212 | #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \ |
| 213 | return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \ |
| 214 | Storage, Context.pImpl->CLASS##s) |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 215 | #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \ |
David Blaikie | 6662d6a | 2016-04-13 17:42:56 +0000 | [diff] [blame] | 216 | 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] | 217 | Storage, Context.pImpl->CLASS##s) |
Adrian Prantl | 9d2f019 | 2017-04-26 23:59:52 +0000 | [diff] [blame] | 218 | #define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \ |
| 219 | return storeImpl(new (NUM_OPS) \ |
| 220 | CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \ |
| 221 | Storage, Context.pImpl->CLASS##s) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 222 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 223 | 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] | 224 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 225 | DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo)); |
| 226 | DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 229 | DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 230 | MDString *Name, StorageType Storage, |
| 231 | bool ShouldCreate) { |
| 232 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 233 | DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, Name)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 234 | Metadata *Ops[] = {Name}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 235 | DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 238 | DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 239 | MDString *Name, uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 240 | uint32_t AlignInBits, unsigned Encoding, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 241 | StorageType Storage, bool ShouldCreate) { |
| 242 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 243 | DEFINE_GETIMPL_LOOKUP(DIBasicType, |
| 244 | (Tag, Name, SizeInBits, AlignInBits, Encoding)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 245 | Metadata *Ops[] = {nullptr, nullptr, Name}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 246 | DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 247 | Ops); |
| 248 | } |
| 249 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 250 | DIDerivedType *DIDerivedType::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 251 | LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 252 | unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 253 | uint32_t AlignInBits, uint64_t OffsetInBits, |
| 254 | Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData, |
| 255 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 256 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 257 | DEFINE_GETIMPL_LOOKUP(DIDerivedType, |
| 258 | (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 259 | AlignInBits, OffsetInBits, DWARFAddressSpace, Flags, |
| 260 | ExtraData)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 261 | Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData}; |
| 262 | DEFINE_GETIMPL_STORE( |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 263 | DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, |
| 264 | DWARFAddressSpace, Flags), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 267 | DICompositeType *DICompositeType::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 268 | LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 269 | unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 270 | uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 271 | Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, |
| 272 | Metadata *TemplateParams, MDString *Identifier, StorageType Storage, |
| 273 | bool ShouldCreate) { |
| 274 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | 5ab2be0 | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 275 | |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 276 | // Keep this in sync with buildODRType. |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 277 | DEFINE_GETIMPL_LOOKUP( |
| 278 | DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 279 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 280 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 281 | Metadata *Ops[] = {File, Scope, Name, BaseType, |
| 282 | Elements, VTableHolder, TemplateParams, Identifier}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 283 | DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 284 | AlignInBits, OffsetInBits, Flags), |
| 285 | Ops); |
| 286 | } |
| 287 | |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 288 | DICompositeType *DICompositeType::buildODRType( |
| 289 | LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, |
| 290 | Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 291 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 292 | DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, |
Duncan P. N. Exon Smith | 9738602 | 2016-04-19 18:00:19 +0000 | [diff] [blame] | 293 | Metadata *VTableHolder, Metadata *TemplateParams) { |
| 294 | assert(!Identifier.getString().empty() && "Expected valid identifier"); |
| 295 | if (!Context.isODRUniquingDebugTypes()) |
| 296 | return nullptr; |
| 297 | auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier]; |
| 298 | if (!CT) |
| 299 | return CT = DICompositeType::getDistinct( |
| 300 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 301 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 302 | VTableHolder, TemplateParams, &Identifier); |
| 303 | |
| 304 | // Only mutate CT if it's a forward declaration and the new operands aren't. |
| 305 | assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?"); |
| 306 | if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl)) |
| 307 | return CT; |
| 308 | |
| 309 | // Mutate CT in place. Keep this in sync with getImpl. |
| 310 | CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, |
| 311 | Flags); |
| 312 | Metadata *Ops[] = {File, Scope, Name, BaseType, |
| 313 | Elements, VTableHolder, TemplateParams, &Identifier}; |
Simon Pilgrim | 1ec7dc7 | 2016-05-02 16:45:02 +0000 | [diff] [blame] | 314 | 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] | 315 | "Mismatched number of operands"); |
| 316 | for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I) |
| 317 | if (Ops[I] != CT->getOperand(I)) |
| 318 | CT->setOperand(I, Ops[I]); |
| 319 | return CT; |
| 320 | } |
| 321 | |
Duncan P. N. Exon Smith | 0b0271e | 2016-04-19 14:55:09 +0000 | [diff] [blame] | 322 | DICompositeType *DICompositeType::getODRType( |
| 323 | LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, |
| 324 | Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 325 | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 326 | DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, |
Duncan P. N. Exon Smith | 0b0271e | 2016-04-19 14:55:09 +0000 | [diff] [blame] | 327 | Metadata *VTableHolder, Metadata *TemplateParams) { |
| 328 | assert(!Identifier.getString().empty() && "Expected valid identifier"); |
| 329 | if (!Context.isODRUniquingDebugTypes()) |
| 330 | return nullptr; |
| 331 | auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier]; |
| 332 | if (!CT) |
| 333 | CT = DICompositeType::getDistinct( |
| 334 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 335 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, |
| 336 | TemplateParams, &Identifier); |
| 337 | return CT; |
| 338 | } |
| 339 | |
| 340 | DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context, |
| 341 | MDString &Identifier) { |
| 342 | assert(!Identifier.getString().empty() && "Expected valid identifier"); |
| 343 | if (!Context.isODRUniquingDebugTypes()) |
| 344 | return nullptr; |
| 345 | return Context.pImpl->DITypeMap->lookup(&Identifier); |
| 346 | } |
| 347 | |
Leny Kholodov | 40c6235 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 348 | DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags, |
| 349 | uint8_t CC, Metadata *TypeArray, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 350 | StorageType Storage, |
| 351 | bool ShouldCreate) { |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 352 | DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray)); |
Duncan P. N. Exon Smith | b9e045a | 2015-07-24 20:56:36 +0000 | [diff] [blame] | 353 | Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray}; |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 354 | DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Reid Kleckner | 26fa1bf | 2017-09-19 18:14:45 +0000 | [diff] [blame] | 357 | // FIXME: Implement this string-enum correspondence with a .def file and macros, |
| 358 | // so that the association is explicit rather than implied. |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 359 | static const char *ChecksumKindName[DIFile::CSK_Last + 1] = { |
| 360 | "CSK_None", |
| 361 | "CSK_MD5", |
| 362 | "CSK_SHA1" |
| 363 | }; |
| 364 | |
| 365 | DIFile::ChecksumKind DIFile::getChecksumKind(StringRef CSKindStr) { |
| 366 | return StringSwitch<DIFile::ChecksumKind>(CSKindStr) |
| 367 | .Case("CSK_MD5", DIFile::CSK_MD5) |
| 368 | .Case("CSK_SHA1", DIFile::CSK_SHA1) |
| 369 | .Default(DIFile::CSK_None); |
| 370 | } |
| 371 | |
| 372 | StringRef DIFile::getChecksumKindAsString() const { |
| 373 | assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind"); |
| 374 | return ChecksumKindName[CSKind]; |
| 375 | } |
| 376 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 377 | DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename, |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 378 | MDString *Directory, DIFile::ChecksumKind CSKind, |
| 379 | MDString *Checksum, StorageType Storage, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 380 | bool ShouldCreate) { |
| 381 | assert(isCanonical(Filename) && "Expected canonical MDString"); |
| 382 | assert(isCanonical(Directory) && "Expected canonical MDString"); |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 383 | assert(isCanonical(Checksum) && "Expected canonical MDString"); |
| 384 | DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CSKind, Checksum)); |
| 385 | Metadata *Ops[] = {Filename, Directory, Checksum}; |
| 386 | DEFINE_GETIMPL_STORE(DIFile, (CSKind), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 389 | DICompileUnit *DICompileUnit::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 390 | LLVMContext &Context, unsigned SourceLanguage, Metadata *File, |
| 391 | MDString *Producer, bool IsOptimized, MDString *Flags, |
| 392 | unsigned RuntimeVersion, MDString *SplitDebugFilename, |
| 393 | unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes, |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 394 | Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros, |
Dehao Chen | 0944a8c | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 395 | uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 396 | bool GnuPubnames, StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 397 | assert(Storage != Uniqued && "Cannot unique DICompileUnit"); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 398 | assert(isCanonical(Producer) && "Expected canonical MDString"); |
| 399 | assert(isCanonical(Flags) && "Expected canonical MDString"); |
| 400 | assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 401 | |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 402 | Metadata *Ops[] = { |
| 403 | File, Producer, Flags, SplitDebugFilename, |
| 404 | EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities, |
| 405 | Macros}; |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 406 | return storeImpl(new (array_lengthof(Ops)) DICompileUnit( |
| 407 | Context, Storage, SourceLanguage, IsOptimized, |
| 408 | RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining, |
| 409 | DebugInfoForProfiling, GnuPubnames, Ops), |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 410 | Storage); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Adrian Prantl | b939a25 | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 413 | Optional<DICompileUnit::DebugEmissionKind> |
| 414 | DICompileUnit::getEmissionKind(StringRef Str) { |
| 415 | return StringSwitch<Optional<DebugEmissionKind>>(Str) |
| 416 | .Case("NoDebug", NoDebug) |
| 417 | .Case("FullDebug", FullDebug) |
| 418 | .Case("LineTablesOnly", LineTablesOnly) |
| 419 | .Default(None); |
| 420 | } |
| 421 | |
| 422 | const char *DICompileUnit::EmissionKindString(DebugEmissionKind EK) { |
| 423 | switch (EK) { |
| 424 | case NoDebug: return "NoDebug"; |
| 425 | case FullDebug: return "FullDebug"; |
| 426 | case LineTablesOnly: return "LineTablesOnly"; |
| 427 | } |
| 428 | return nullptr; |
| 429 | } |
| 430 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 431 | DISubprogram *DILocalScope::getSubprogram() const { |
| 432 | if (auto *Block = dyn_cast<DILexicalBlockBase>(this)) |
Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 433 | return Block->getScope()->getSubprogram(); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 434 | return const_cast<DISubprogram *>(cast<DISubprogram>(this)); |
Duncan P. N. Exon Smith | fd07a2a | 2015-03-30 21:32:28 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Amjad Aboud | a5ba991 | 2016-04-21 16:58:49 +0000 | [diff] [blame] | 437 | DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const { |
| 438 | if (auto *File = dyn_cast<DILexicalBlockFile>(this)) |
| 439 | return File->getScope()->getNonLexicalBlockFileScope(); |
| 440 | return const_cast<DILocalScope *>(this); |
| 441 | } |
| 442 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 443 | DISubprogram *DISubprogram::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 444 | LLVMContext &Context, Metadata *Scope, MDString *Name, |
| 445 | MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, |
| 446 | bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, |
| 447 | Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 448 | int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit, |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 449 | Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables, |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 450 | Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 451 | assert(isCanonical(Name) && "Expected canonical MDString"); |
| 452 | assert(isCanonical(LinkageName) && "Expected canonical MDString"); |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 453 | DEFINE_GETIMPL_LOOKUP( |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 454 | DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 455 | IsDefinition, ScopeLine, ContainingType, Virtuality, |
| 456 | VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit, |
| 457 | TemplateParams, Declaration, Variables, ThrownTypes)); |
Adrian Prantl | 9d2f019 | 2017-04-26 23:59:52 +0000 | [diff] [blame] | 458 | SmallVector<Metadata *, 11> Ops = { |
| 459 | File, Scope, Name, LinkageName, Type, Unit, |
| 460 | Declaration, Variables, ContainingType, TemplateParams, ThrownTypes}; |
| 461 | if (!ThrownTypes) { |
| 462 | Ops.pop_back(); |
| 463 | if (!TemplateParams) { |
| 464 | Ops.pop_back(); |
| 465 | if (!ContainingType) |
| 466 | Ops.pop_back(); |
| 467 | } |
| 468 | } |
| 469 | DEFINE_GETIMPL_STORE_N(DISubprogram, |
| 470 | (Line, ScopeLine, Virtuality, VirtualIndex, |
| 471 | ThisAdjustment, Flags, IsLocalToUnit, IsDefinition, |
| 472 | IsOptimized), |
| 473 | Ops, Ops.size()); |
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 | bool DISubprogram::describes(const Function *F) const { |
Duncan P. N. Exon Smith | 3c2d704 | 2015-04-13 19:07:27 +0000 | [diff] [blame] | 477 | assert(F && "Invalid function"); |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 478 | if (F->getSubprogram() == this) |
Duncan P. N. Exon Smith | 3c2d704 | 2015-04-13 19:07:27 +0000 | [diff] [blame] | 479 | return true; |
| 480 | StringRef Name = getLinkageName(); |
| 481 | if (Name.empty()) |
| 482 | Name = getName(); |
| 483 | return F->getName() == Name; |
| 484 | } |
| 485 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 486 | DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 487 | Metadata *File, unsigned Line, |
| 488 | unsigned Column, StorageType Storage, |
| 489 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | b09eb9f | 2015-08-28 22:58:50 +0000 | [diff] [blame] | 490 | // Fixup column. |
| 491 | adjustColumn(Column); |
| 492 | |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 493 | assert(Scope && "Expected scope"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 494 | DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 495 | Metadata *Ops[] = {File, Scope}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 496 | DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 499 | DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 500 | Metadata *Scope, Metadata *File, |
| 501 | unsigned Discriminator, |
| 502 | StorageType Storage, |
| 503 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 504 | assert(Scope && "Expected scope"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 505 | DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 506 | Metadata *Ops[] = {File, Scope}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 507 | DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), 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 | DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope, |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 511 | MDString *Name, bool ExportSymbols, |
| 512 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 513 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 514 | DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols)); |
| 515 | // The nullptr is for DIScope's File operand. This should be refactored. |
| 516 | Metadata *Ops[] = {nullptr, Scope, Name}; |
| 517 | DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 520 | DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope, |
| 521 | MDString *Name, MDString *ConfigurationMacros, |
| 522 | MDString *IncludePath, MDString *ISysRoot, |
| 523 | StorageType Storage, bool ShouldCreate) { |
| 524 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 525 | DEFINE_GETIMPL_LOOKUP( |
| 526 | DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot)); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 527 | Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot}; |
| 528 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops); |
| 529 | } |
| 530 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 531 | DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context, |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 532 | MDString *Name, |
| 533 | Metadata *Type, |
| 534 | StorageType Storage, |
| 535 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 536 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 537 | DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type)); |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 538 | Metadata *Ops[] = {Name, Type}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 539 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 542 | DITemplateValueParameter *DITemplateValueParameter::getImpl( |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 543 | LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type, |
| 544 | Metadata *Value, StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 545 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 546 | DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value)); |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 547 | Metadata *Ops[] = {Name, Type, Value}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 548 | DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 551 | DIGlobalVariable * |
| 552 | DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 553 | MDString *LinkageName, Metadata *File, unsigned Line, |
| 554 | Metadata *Type, bool IsLocalToUnit, bool IsDefinition, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 555 | Metadata *StaticDataMemberDeclaration, |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 556 | uint32_t AlignInBits, StorageType Storage, |
| 557 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 558 | assert(isCanonical(Name) && "Expected canonical MDString"); |
| 559 | assert(isCanonical(LinkageName) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 560 | DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 561 | (Scope, Name, LinkageName, File, Line, Type, |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 562 | IsLocalToUnit, IsDefinition, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 563 | StaticDataMemberDeclaration, AlignInBits)); |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 564 | Metadata *Ops[] = { |
| 565 | Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration}; |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 566 | DEFINE_GETIMPL_STORE(DIGlobalVariable, |
| 567 | (Line, IsLocalToUnit, IsDefinition, AlignInBits), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 568 | Ops); |
| 569 | } |
| 570 | |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 571 | DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, |
| 572 | MDString *Name, Metadata *File, |
| 573 | unsigned Line, Metadata *Type, |
Leny Kholodov | 5fcc418 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 574 | unsigned Arg, DIFlags Flags, |
Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 575 | uint32_t AlignInBits, |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 576 | StorageType Storage, |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 577 | bool ShouldCreate) { |
Duncan P. N. Exon Smith | 1ec75ae | 2015-04-28 01:07:33 +0000 | [diff] [blame] | 578 | // 64K ought to be enough for any frontend. |
| 579 | 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] | 580 | |
Duncan P. N. Exon Smith | e2c61d9 | 2015-03-27 17:56:39 +0000 | [diff] [blame] | 581 | assert(Scope && "Expected scope"); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 582 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 583 | DEFINE_GETIMPL_LOOKUP(DILocalVariable, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 584 | (Scope, Name, File, Line, Type, Arg, Flags, |
| 585 | AlignInBits)); |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 586 | Metadata *Ops[] = {Scope, Name, File, Type}; |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 587 | DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 590 | DIExpression *DIExpression::getImpl(LLVMContext &Context, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 591 | ArrayRef<uint64_t> Elements, |
| 592 | StorageType Storage, bool ShouldCreate) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 593 | DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements)); |
| 594 | DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 597 | unsigned DIExpression::ExprOperand::getSize() const { |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 598 | switch (getOp()) { |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 599 | case dwarf::DW_OP_LLVM_fragment: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 600 | return 3; |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 601 | case dwarf::DW_OP_constu: |
Florian Hahn | c9c403c | 2017-06-13 16:54:44 +0000 | [diff] [blame] | 602 | case dwarf::DW_OP_plus_uconst: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 603 | return 2; |
| 604 | default: |
| 605 | return 1; |
| 606 | } |
| 607 | } |
| 608 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 609 | bool DIExpression::isValid() const { |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 610 | for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) { |
| 611 | // Check that there's space for the operand. |
| 612 | if (I->get() + I->getSize() > E->get()) |
| 613 | return false; |
| 614 | |
| 615 | // Check that the operand is valid. |
| 616 | switch (I->getOp()) { |
| 617 | default: |
| 618 | return false; |
Adrian Prantl | 941fa75 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 619 | case dwarf::DW_OP_LLVM_fragment: |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 620 | // A fragment operator must appear at the end. |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 621 | return I->get() + I->getSize() == E->get(); |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 622 | case dwarf::DW_OP_stack_value: { |
| 623 | // Must be the last one or followed by a DW_OP_LLVM_fragment. |
| 624 | if (I->get() + I->getSize() == E->get()) |
| 625 | break; |
| 626 | auto J = I; |
| 627 | if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment) |
| 628 | return false; |
| 629 | break; |
| 630 | } |
Konstantin Zhuravlyov | f9b41cd | 2017-03-08 00:28:57 +0000 | [diff] [blame] | 631 | case dwarf::DW_OP_swap: { |
| 632 | // Must be more than one implicit element on the stack. |
| 633 | |
| 634 | // FIXME: A better way to implement this would be to add a local variable |
| 635 | // that keeps track of the stack depth and introduce something like a |
| 636 | // DW_LLVM_OP_implicit_location as a placeholder for the location this |
| 637 | // DIExpression is attached to, or else pass the number of implicit stack |
| 638 | // elements into isValid. |
| 639 | if (getNumElements() == 1) |
| 640 | return false; |
| 641 | break; |
| 642 | } |
Peter Collingbourne | d4135bb | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 643 | case dwarf::DW_OP_constu: |
Florian Hahn | c9c403c | 2017-06-13 16:54:44 +0000 | [diff] [blame] | 644 | case dwarf::DW_OP_plus_uconst: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 645 | case dwarf::DW_OP_plus: |
Evgeniy Stepanov | f608111 | 2015-09-30 19:55:43 +0000 | [diff] [blame] | 646 | case dwarf::DW_OP_minus: |
Strahinja Petrovic | 29202f6 | 2017-09-21 10:04:02 +0000 | [diff] [blame^] | 647 | case dwarf::DW_OP_mul: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 648 | case dwarf::DW_OP_deref: |
Konstantin Zhuravlyov | f9b41cd | 2017-03-08 00:28:57 +0000 | [diff] [blame] | 649 | case dwarf::DW_OP_xderef: |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 650 | break; |
| 651 | } |
| 652 | } |
| 653 | return true; |
| 654 | } |
| 655 | |
Adrian Prantl | 49797ca | 2016-12-22 05:27:12 +0000 | [diff] [blame] | 656 | Optional<DIExpression::FragmentInfo> |
| 657 | DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) { |
| 658 | for (auto I = Start; I != End; ++I) |
| 659 | if (I->getOp() == dwarf::DW_OP_LLVM_fragment) { |
| 660 | DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)}; |
| 661 | return Info; |
| 662 | } |
| 663 | return None; |
Duncan P. N. Exon Smith | 86cc332 | 2015-04-07 03:49:59 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 666 | void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops, |
| 667 | int64_t Offset) { |
| 668 | if (Offset > 0) { |
Florian Hahn | ffc498d | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 669 | Ops.push_back(dwarf::DW_OP_plus_uconst); |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 670 | Ops.push_back(Offset); |
| 671 | } else if (Offset < 0) { |
Florian Hahn | ffc498d | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 672 | Ops.push_back(dwarf::DW_OP_constu); |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 673 | Ops.push_back(-Offset); |
Florian Hahn | ffc498d | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 674 | Ops.push_back(dwarf::DW_OP_minus); |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Reid Kleckner | b5fced7 | 2017-05-09 19:59:29 +0000 | [diff] [blame] | 678 | bool DIExpression::extractIfOffset(int64_t &Offset) const { |
| 679 | if (getNumElements() == 0) { |
| 680 | Offset = 0; |
| 681 | return true; |
| 682 | } |
Florian Hahn | ffc498d | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 683 | |
| 684 | if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) { |
Reid Kleckner | b5fced7 | 2017-05-09 19:59:29 +0000 | [diff] [blame] | 685 | Offset = Elements[1]; |
| 686 | return true; |
| 687 | } |
Florian Hahn | ffc498d | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 688 | |
| 689 | if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) { |
| 690 | if (Elements[2] == dwarf::DW_OP_plus) { |
| 691 | Offset = Elements[1]; |
| 692 | return true; |
| 693 | } |
| 694 | if (Elements[2] == dwarf::DW_OP_minus) { |
| 695 | Offset = -Elements[1]; |
| 696 | return true; |
| 697 | } |
Reid Kleckner | b5fced7 | 2017-05-09 19:59:29 +0000 | [diff] [blame] | 698 | } |
Florian Hahn | ffc498d | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 699 | |
Reid Kleckner | b5fced7 | 2017-05-09 19:59:29 +0000 | [diff] [blame] | 700 | return false; |
| 701 | } |
| 702 | |
Adrian Prantl | 06d6096 | 2017-04-28 18:30:36 +0000 | [diff] [blame] | 703 | DIExpression *DIExpression::prepend(const DIExpression *Expr, bool Deref, |
Adrian Prantl | 109b236 | 2017-04-28 17:51:05 +0000 | [diff] [blame] | 704 | int64_t Offset, bool StackValue) { |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 705 | SmallVector<uint64_t, 8> Ops; |
| 706 | appendOffset(Ops, Offset); |
| 707 | if (Deref) |
| 708 | Ops.push_back(dwarf::DW_OP_deref); |
Adrian Prantl | 109b236 | 2017-04-28 17:51:05 +0000 | [diff] [blame] | 709 | if (Expr) |
| 710 | for (auto Op : Expr->expr_ops()) { |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 711 | // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment. |
| 712 | if (StackValue) { |
| 713 | if (Op.getOp() == dwarf::DW_OP_stack_value) |
| 714 | StackValue = false; |
| 715 | else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) { |
| 716 | Ops.push_back(dwarf::DW_OP_stack_value); |
| 717 | StackValue = false; |
| 718 | } |
| 719 | } |
| 720 | Ops.push_back(Op.getOp()); |
| 721 | for (unsigned I = 0; I < Op.getNumArgs(); ++I) |
| 722 | Ops.push_back(Op.getArg(I)); |
| 723 | } |
| 724 | if (StackValue) |
| 725 | Ops.push_back(dwarf::DW_OP_stack_value); |
Adrian Prantl | 109b236 | 2017-04-28 17:51:05 +0000 | [diff] [blame] | 726 | return DIExpression::get(Expr->getContext(), Ops); |
Andrew Ng | 03e35b6 | 2017-04-28 08:44:30 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Adrian Prantl | b192b54 | 2017-08-30 20:04:17 +0000 | [diff] [blame] | 729 | DIExpression *DIExpression::createFragmentExpression(const DIExpression *Expr, |
| 730 | unsigned OffsetInBits, |
| 731 | unsigned SizeInBits) { |
| 732 | SmallVector<uint64_t, 8> Ops; |
| 733 | // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment. |
| 734 | if (Expr) { |
| 735 | for (auto Op : Expr->expr_ops()) { |
| 736 | if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) { |
| 737 | // Make the new offset point into the existing fragment. |
| 738 | uint64_t FragmentOffsetInBits = Op.getArg(0); |
| 739 | // Op.getArg(0) is FragmentOffsetInBits. |
| 740 | // Op.getArg(1) is FragmentSizeInBits. |
| 741 | assert((OffsetInBits + SizeInBits <= Op.getArg(0) + Op.getArg(1)) && |
| 742 | "new fragment outside of original fragment"); |
| 743 | OffsetInBits += FragmentOffsetInBits; |
| 744 | break; |
| 745 | } |
| 746 | Ops.push_back(Op.getOp()); |
| 747 | for (unsigned I = 0; I < Op.getNumArgs(); ++I) |
| 748 | Ops.push_back(Op.getArg(I)); |
| 749 | } |
| 750 | } |
| 751 | Ops.push_back(dwarf::DW_OP_LLVM_fragment); |
| 752 | Ops.push_back(OffsetInBits); |
| 753 | Ops.push_back(SizeInBits); |
| 754 | return DIExpression::get(Expr->getContext(), Ops); |
| 755 | } |
| 756 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 757 | bool DIExpression::isConstant() const { |
| 758 | // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?. |
| 759 | if (getNumElements() != 3 && getNumElements() != 6) |
| 760 | return false; |
| 761 | if (getElement(0) != dwarf::DW_OP_constu || |
| 762 | getElement(2) != dwarf::DW_OP_stack_value) |
| 763 | return false; |
| 764 | if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment) |
| 765 | return false; |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | DIGlobalVariableExpression * |
| 770 | DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable, |
| 771 | Metadata *Expression, StorageType Storage, |
| 772 | bool ShouldCreate) { |
| 773 | DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression)); |
| 774 | Metadata *Ops[] = {Variable, Expression}; |
| 775 | DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops); |
| 776 | } |
| 777 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 778 | DIObjCProperty *DIObjCProperty::getImpl( |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 779 | LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line, |
| 780 | MDString *GetterName, MDString *SetterName, unsigned Attributes, |
| 781 | Metadata *Type, StorageType Storage, bool ShouldCreate) { |
| 782 | assert(isCanonical(Name) && "Expected canonical MDString"); |
| 783 | assert(isCanonical(GetterName) && "Expected canonical MDString"); |
| 784 | assert(isCanonical(SetterName) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 785 | DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName, |
| 786 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 787 | Metadata *Ops[] = {Name, File, GetterName, SetterName, Type}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 788 | DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 791 | DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 792 | Metadata *Scope, Metadata *Entity, |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 793 | Metadata *File, unsigned Line, |
| 794 | MDString *Name, StorageType Storage, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 795 | bool ShouldCreate) { |
| 796 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 797 | DEFINE_GETIMPL_LOOKUP(DIImportedEntity, |
| 798 | (Tag, Scope, Entity, File, Line, Name)); |
| 799 | Metadata *Ops[] = {Scope, Entity, Name, File}; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 800 | DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 801 | } |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 802 | |
| 803 | DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType, |
| 804 | unsigned Line, MDString *Name, MDString *Value, |
| 805 | StorageType Storage, bool ShouldCreate) { |
| 806 | assert(isCanonical(Name) && "Expected canonical MDString"); |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 807 | DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value)); |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 808 | Metadata *Ops[] = { Name, Value }; |
| 809 | DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops); |
| 810 | } |
| 811 | |
| 812 | DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType, |
| 813 | unsigned Line, Metadata *File, |
| 814 | Metadata *Elements, StorageType Storage, |
| 815 | bool ShouldCreate) { |
| 816 | DEFINE_GETIMPL_LOOKUP(DIMacroFile, |
| 817 | (MIType, Line, File, Elements)); |
| 818 | Metadata *Ops[] = { File, Elements }; |
| 819 | DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops); |
| 820 | } |
| 821 | |