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