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