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