blob: de72edebc4c9a4b5d19e123ba8c143a610a7d036 [file] [log] [blame]
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +00001//===- 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 Blaikie2a813ef2018-08-23 22:35:58 +000017#include "llvm/ADT/SmallSet.h"
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +000018#include "llvm/ADT/StringSwitch.h"
Andrew Ng03e35b62017-04-28 08:44:30 +000019#include "llvm/IR/DIBuilder.h"
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +000020#include "llvm/IR/Function.h"
Vedant Kumar2b881f52017-11-06 23:15:21 +000021#include "llvm/IR/Instructions.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000022
23using namespace llvm;
24
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000025DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
Calixte Denizeteb7f6022018-09-20 08:53:06 +000026 unsigned Column, ArrayRef<Metadata *> MDs,
27 bool ImplicitCode)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000028 : MDNode(C, DILocationKind, Storage, MDs) {
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000029 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 Smithd9901ff2015-02-02 18:53:21 +000033 assert(Column < (1u << 16) && "Expected 16-bit column");
34
35 SubclassData32 = Line;
36 SubclassData16 = Column;
Calixte Denizeteb7f6022018-09-20 08:53:06 +000037
38 setImplicitCode(ImplicitCode);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000039}
40
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000041static 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 Smitha9308c42015-04-29 16:38:44 +000047DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000048 unsigned Column, Metadata *Scope,
Calixte Denizeteb7f6022018-09-20 08:53:06 +000049 Metadata *InlinedAt, bool ImplicitCode,
50 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +000051 // Fixup column.
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000052 adjustColumn(Column);
53
54 if (Storage == Uniqued) {
Calixte Denizeteb7f6022018-09-20 08:53:06 +000055 if (auto *N = getUniqued(Context.pImpl->DILocations,
56 DILocationInfo::KeyTy(Line, Column, Scope,
57 InlinedAt, ImplicitCode)))
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000058 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 Denizeteb7f6022018-09-20 08:53:06 +000069 return storeImpl(new (Ops.size()) DILocation(Context, Storage, Line, Column,
70 Ops, ImplicitCode),
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000071 Storage, Context.pImpl->DILocations);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000072}
73
Vedant Kumar65b0d4d2018-04-12 20:58:24 +000074const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
David Blaikie2a813ef2018-08-23 22:35:58 +000075 const DILocation *LocB) {
Vedant Kumar2b881f52017-11-06 23:15:21 +000076 if (!LocA || !LocB)
77 return nullptr;
78
David Blaikie2a813ef2018-08-23 22:35:58 +000079 if (LocA == LocB)
Vedant Kumar2b881f52017-11-06 23:15:21 +000080 return LocA;
81
Vedant Kumar2b881f52017-11-06 23:15:21 +000082 SmallPtrSet<DILocation *, 5> InlinedLocationsA;
83 for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
84 InlinedLocationsA.insert(L);
David Blaikie2a813ef2018-08-23 22:35:58 +000085 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 Kumar2b881f52017-11-06 23:15:21 +000095 }
David Blaikie2a813ef2018-08-23 22:35:58 +000096 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 Prantl4ddd0592018-08-24 23:30:57 +0000108
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 Blaikie2a813ef2018-08-23 22:35:58 +0000113 return DILocation::get(Result->getContext(), 0, 0, S, L);
Vedant Kumar2b881f52017-11-06 23:15:21 +0000114}
115
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000116DINode::DIFlags DINode::getFlag(StringRef Flag) {
117 return StringSwitch<DIFlags>(Flag)
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000118#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
119#include "llvm/IR/DebugInfoFlags.def"
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000120 .Default(DINode::FlagZero);
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000121}
122
Mehdi Aminif42ec792016-10-01 05:57:50 +0000123StringRef DINode::getFlagString(DIFlags Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000124 switch (Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000125#define HANDLE_DI_FLAG(ID, NAME) \
126 case Flag##NAME: \
127 return "DIFlag" #NAME;
128#include "llvm/IR/DebugInfoFlags.def"
129 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000130 return "";
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000131}
132
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000133DINode::DIFlags DINode::splitFlags(DIFlags Flags,
Leny Kholodov40c62352016-09-06 17:03:02 +0000134 SmallVectorImpl<DIFlags> &SplitFlags) {
Bob Haarman26a87bd2016-10-25 22:11:52 +0000135 // Flags that are packed together need to be specially handled, so
136 // that, for example, we emit "DIFlagPublic" and not
137 // "DIFlagPrivate | DIFlagProtected".
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000138 if (DIFlags A = Flags & FlagAccessibility) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000139 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 Kholodov5fcc4182016-09-06 10:46:28 +0000147 if (DIFlags R = Flags & FlagPtrToMemberRep) {
Reid Kleckner604105b2016-06-17 21:31:33 +0000148 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 Haarman26a87bd2016-10-25 22:11:52 +0000156 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
157 Flags &= ~FlagIndirectVirtualBase;
158 SplitFlags.push_back(FlagIndirectVirtualBase);
159 }
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000160
161#define HANDLE_DI_FLAG(ID, NAME) \
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000162 if (DIFlags Bit = Flags & Flag##NAME) { \
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000163 SplitFlags.push_back(Bit); \
164 Flags &= ~Bit; \
165 }
166#include "llvm/IR/DebugInfoFlags.def"
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000167 return Flags;
168}
169
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000170DIScopeRef DIScope::getScope() const {
171 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000172 return T->getScope();
173
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000174 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000175 return SP->getScope();
176
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000177 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000178 return LB->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000179
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000180 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000181 return NS->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000182
Adrian Prantlab1243f2015-06-29 23:03:47 +0000183 if (auto *M = dyn_cast<DIModule>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000184 return M->getScope();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000185
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000186 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000187 "Unhandled type of scope.");
188 return nullptr;
189}
190
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000191StringRef DIScope::getName() const {
192 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000193 return T->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000194 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000195 return SP->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000196 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000197 return NS->getName();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000198 if (auto *M = dyn_cast<DIModule>(this))
199 return M->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000200 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
201 isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000202 "Unhandled type of scope.");
203 return "";
204}
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000205
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000206#ifndef NDEBUG
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000207static bool isCanonical(const MDString *S) {
208 return !S || !S->getString().empty();
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000209}
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000210#endif
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000211
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000212GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
213 MDString *Header,
214 ArrayRef<Metadata *> DwarfOps,
215 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000216 unsigned Hash = 0;
217 if (Storage == Uniqued) {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000218 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000219 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000220 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 Smith9146fc82015-02-02 20:01:03 +0000229 assert(isCanonical(Header) && "Expected canonical MDString");
230 Metadata *PreOps[] = {Header};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000231 return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000232 Context, Storage, Hash, Tag, PreOps, DwarfOps),
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000233 Storage, Context.pImpl->GenericDINodes);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000234}
235
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000236void GenericDINode::recalculateHash() {
237 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000238}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000239
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 Blaikie6662d6a2016-04-13 17:42:56 +0000256 return storeImpl(new (array_lengthof(OPS)) \
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000257 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 Smithbd33d372015-02-10 01:59:57 +0000262#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000263 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000264 Storage, Context.pImpl->CLASS##s)
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000265#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 Smith01fc1762015-02-10 00:52:32 +0000269
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000270DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000271 StorageType Storage, bool ShouldCreate) {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000272 auto *CountNode = ConstantAsMetadata::get(
273 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
274 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
275}
276
277DISubrange *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 Smith01fc1762015-02-10 00:52:32 +0000283}
284
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000285DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000286 bool IsUnsigned, MDString *Name,
287 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000288 assert(isCanonical(Name) && "Expected canonical MDString");
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000289 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000290 Metadata *Ops[] = {Name};
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000291 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000292}
293
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000294DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000295 MDString *Name, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000296 uint32_t AlignInBits, unsigned Encoding,
Adrian Prantl55f42622018-08-14 19:35:34 +0000297 DIFlags Flags, StorageType Storage,
298 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000299 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000300 DEFINE_GETIMPL_LOOKUP(DIBasicType,
Adrian Prantl55f42622018-08-14 19:35:34 +0000301 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000302 Metadata *Ops[] = {nullptr, nullptr, Name};
Adrian Prantl55f42622018-08-14 19:35:34 +0000303 DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
304 Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000305}
306
Vedant Kumar6379a622018-07-06 17:32:39 +0000307Optional<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 Smitha9308c42015-04-29 16:38:44 +0000320DIDerivedType *DIDerivedType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000321 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000322 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000323 uint32_t AlignInBits, uint64_t OffsetInBits,
324 Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
325 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000326 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000327 DEFINE_GETIMPL_LOOKUP(DIDerivedType,
328 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000329 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
330 ExtraData));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000331 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
332 DEFINE_GETIMPL_STORE(
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000333 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
334 DWARFAddressSpace, Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000335}
336
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000337DICompositeType *DICompositeType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000338 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000339 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000340 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000341 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000342 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
343 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000344 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +0000345
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000346 // Keep this in sync with buildODRType.
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000347 DEFINE_GETIMPL_LOOKUP(
348 DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
349 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000350 VTableHolder, TemplateParams, Identifier, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000351 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000352 Elements, VTableHolder, TemplateParams, Identifier,
353 Discriminator};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000354 DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000355 AlignInBits, OffsetInBits, Flags),
356 Ops);
357}
358
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000359DICompositeType *DICompositeType::buildODRType(
360 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
361 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000362 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000363 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000364 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000365 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 Prantl8c599212018-02-06 23:45:59 +0000373 VTableHolder, TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000374
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 Prantl8c599212018-02-06 23:45:59 +0000384 Elements, VTableHolder, TemplateParams, &Identifier,
385 Discriminator};
Simon Pilgrim1ec7dc72016-05-02 16:45:02 +0000386 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000387 "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 Smith0b0271e2016-04-19 14:55:09 +0000394DICompositeType *DICompositeType::getODRType(
395 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
396 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000397 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000398 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000399 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000400 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 Prantl8c599212018-02-06 23:45:59 +0000408 TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000409 return CT;
410}
411
412DICompositeType *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 Kholodov40c62352016-09-06 17:03:02 +0000420DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
421 uint8_t CC, Metadata *TypeArray,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000422 StorageType Storage,
423 bool ShouldCreate) {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000424 DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
Duncan P. N. Exon Smithb9e045a2015-07-24 20:56:36 +0000425 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000426 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000427}
428
Reid Kleckner26fa1bf2017-09-19 18:14:45 +0000429// FIXME: Implement this string-enum correspondence with a .def file and macros,
430// so that the association is explicit rather than implied.
Scott Linder71603842018-02-12 19:45:54 +0000431static const char *ChecksumKindName[DIFile::CSK_Last] = {
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000432 "CSK_MD5",
433 "CSK_SHA1"
434};
435
Scott Linder71603842018-02-12 19:45:54 +0000436StringRef 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 Aboud7faeecc2016-12-25 10:12:09 +0000442}
443
Scott Linder71603842018-02-12 19:45:54 +0000444Optional<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 Aboud7faeecc2016-12-25 10:12:09 +0000449}
450
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000451DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
Scott Linder71603842018-02-12 19:45:54 +0000452 MDString *Directory,
453 Optional<DIFile::ChecksumInfo<MDString *>> CS,
Scott Linder16c7bda2018-02-23 23:01:06 +0000454 Optional<MDString *> Source, StorageType Storage,
455 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000456 assert(isCanonical(Filename) && "Expected canonical MDString");
457 assert(isCanonical(Directory) && "Expected canonical MDString");
Scott Linder71603842018-02-12 19:45:54 +0000458 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
Scott Linder16c7bda2018-02-23 23:01:06 +0000459 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 Smith01fc1762015-02-10 00:52:32 +0000464}
465
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000466DICompileUnit *DICompileUnit::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000467 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 Prantl75819ae2016-04-15 15:57:41 +0000471 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
Dehao Chen0944a8c2017-02-01 22:45:09 +0000472 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
David Blaikie66cf14d2018-08-16 21:29:55 +0000473 unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000474 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000475 assert(isCanonical(Producer) && "Expected canonical MDString");
476 assert(isCanonical(Flags) && "Expected canonical MDString");
477 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000478
Adrian Prantl75819ae2016-04-15 15:57:41 +0000479 Metadata *Ops[] = {
480 File, Producer, Flags, SplitDebugFilename,
481 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
482 Macros};
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000483 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
484 Context, Storage, SourceLanguage, IsOptimized,
485 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
David Blaikie66cf14d2018-08-16 21:29:55 +0000486 DebugInfoForProfiling, NameTableKind, Ops),
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000487 Storage);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000488}
489
Adrian Prantlb939a252016-03-31 23:56:58 +0000490Optional<DICompileUnit::DebugEmissionKind>
491DICompileUnit::getEmissionKind(StringRef Str) {
492 return StringSwitch<Optional<DebugEmissionKind>>(Str)
493 .Case("NoDebug", NoDebug)
494 .Case("FullDebug", FullDebug)
495 .Case("LineTablesOnly", LineTablesOnly)
Alexey Bataevd4dd7212018-08-01 19:38:20 +0000496 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
Adrian Prantlb939a252016-03-31 23:56:58 +0000497 .Default(None);
498}
499
David Blaikie66cf14d2018-08-16 21:29:55 +0000500Optional<DICompileUnit::DebugNameTableKind>
501DICompileUnit::getNameTableKind(StringRef Str) {
502 return StringSwitch<Optional<DebugNameTableKind>>(Str)
503 .Case("Default", DebugNameTableKind::Default)
504 .Case("GNU", DebugNameTableKind::GNU)
505 .Case("None", DebugNameTableKind::None)
506 .Default(None);
507}
508
Fangrui Song3c1b5db2018-07-06 19:26:00 +0000509const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
Adrian Prantlb939a252016-03-31 23:56:58 +0000510 switch (EK) {
511 case NoDebug: return "NoDebug";
512 case FullDebug: return "FullDebug";
513 case LineTablesOnly: return "LineTablesOnly";
Alexey Bataev075412d2018-08-23 17:43:40 +0000514 case DebugDirectivesOnly: return "DebugDirectivesOnly";
Adrian Prantlb939a252016-03-31 23:56:58 +0000515 }
516 return nullptr;
517}
518
David Blaikie66cf14d2018-08-16 21:29:55 +0000519const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
520 switch (NTK) {
521 case DebugNameTableKind::Default:
522 return nullptr;
523 case DebugNameTableKind::GNU:
524 return "GNU";
525 case DebugNameTableKind::None:
526 return "None";
527 }
528 return nullptr;
529}
530
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000531DISubprogram *DILocalScope::getSubprogram() const {
532 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000533 return Block->getScope()->getSubprogram();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000534 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000535}
536
Amjad Abouda5ba9912016-04-21 16:58:49 +0000537DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
538 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
539 return File->getScope()->getNonLexicalBlockFileScope();
540 return const_cast<DILocalScope *>(this);
541}
542
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000543DISubprogram *DISubprogram::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000544 LLVMContext &Context, Metadata *Scope, MDString *Name,
545 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
546 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
547 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000548 int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000549 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000550 Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000551 assert(isCanonical(Name) && "Expected canonical MDString");
552 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000553 DEFINE_GETIMPL_LOOKUP(
Adrian Prantl1d12b882017-04-26 22:56:44 +0000554 DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
555 IsDefinition, ScopeLine, ContainingType, Virtuality,
556 VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000557 TemplateParams, Declaration, RetainedNodes, ThrownTypes));
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000558 SmallVector<Metadata *, 11> Ops = {
Shiva Chen2c864552018-05-09 02:40:45 +0000559 File, Scope, Name, LinkageName, Type, Unit,
560 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000561 if (!ThrownTypes) {
562 Ops.pop_back();
563 if (!TemplateParams) {
564 Ops.pop_back();
565 if (!ContainingType)
566 Ops.pop_back();
567 }
568 }
569 DEFINE_GETIMPL_STORE_N(DISubprogram,
570 (Line, ScopeLine, Virtuality, VirtualIndex,
571 ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
572 IsOptimized),
573 Ops, Ops.size());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000574}
575
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000576bool DISubprogram::describes(const Function *F) const {
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000577 assert(F && "Invalid function");
Peter Collingbourned4bff302015-11-05 22:03:56 +0000578 if (F->getSubprogram() == this)
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000579 return true;
580 StringRef Name = getLinkageName();
581 if (Name.empty())
582 Name = getName();
583 return F->getName() == Name;
584}
585
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000586DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000587 Metadata *File, unsigned Line,
588 unsigned Column, StorageType Storage,
589 bool ShouldCreate) {
Duncan P. N. Exon Smithb09eb9f2015-08-28 22:58:50 +0000590 // Fixup column.
591 adjustColumn(Column);
592
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000593 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000594 DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000595 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000596 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000597}
598
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000599DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000600 Metadata *Scope, Metadata *File,
601 unsigned Discriminator,
602 StorageType Storage,
603 bool ShouldCreate) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000604 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000605 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000606 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000607 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000608}
609
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000610DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
Adrian Prantlfed4f392017-04-28 22:25:46 +0000611 MDString *Name, bool ExportSymbols,
612 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000613 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantlfed4f392017-04-28 22:25:46 +0000614 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
615 // The nullptr is for DIScope's File operand. This should be refactored.
616 Metadata *Ops[] = {nullptr, Scope, Name};
617 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000618}
619
Adrian Prantlab1243f2015-06-29 23:03:47 +0000620DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
621 MDString *Name, MDString *ConfigurationMacros,
622 MDString *IncludePath, MDString *ISysRoot,
623 StorageType Storage, bool ShouldCreate) {
624 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000625 DEFINE_GETIMPL_LOOKUP(
626 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
Adrian Prantlab1243f2015-06-29 23:03:47 +0000627 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
628 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
629}
630
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000631DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000632 MDString *Name,
633 Metadata *Type,
634 StorageType Storage,
635 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000636 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000637 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000638 Metadata *Ops[] = {Name, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000639 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000640}
641
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000642DITemplateValueParameter *DITemplateValueParameter::getImpl(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000643 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
644 Metadata *Value, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000645 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000646 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000647 Metadata *Ops[] = {Name, Type, Value};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000648 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000649}
650
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000651DIGlobalVariable *
652DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000653 MDString *LinkageName, Metadata *File, unsigned Line,
654 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000655 Metadata *StaticDataMemberDeclaration,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000656 uint32_t AlignInBits, StorageType Storage,
657 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000658 assert(isCanonical(Name) && "Expected canonical MDString");
659 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000660 DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000661 (Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000662 IsLocalToUnit, IsDefinition,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000663 StaticDataMemberDeclaration, AlignInBits));
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000664 Metadata *Ops[] = {
665 Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000666 DEFINE_GETIMPL_STORE(DIGlobalVariable,
667 (Line, IsLocalToUnit, IsDefinition, AlignInBits),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000668 Ops);
669}
670
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000671DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
672 MDString *Name, Metadata *File,
673 unsigned Line, Metadata *Type,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000674 unsigned Arg, DIFlags Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000675 uint32_t AlignInBits,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000676 StorageType Storage,
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000677 bool ShouldCreate) {
Duncan P. N. Exon Smith1ec75ae2015-04-28 01:07:33 +0000678 // 64K ought to be enough for any frontend.
679 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
Duncan P. N. Exon Smith72fe2d02015-02-13 01:39:44 +0000680
Duncan P. N. Exon Smithe2c61d92015-03-27 17:56:39 +0000681 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000682 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000683 DEFINE_GETIMPL_LOOKUP(DILocalVariable,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000684 (Scope, Name, File, Line, Type, Arg, Flags,
685 AlignInBits));
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000686 Metadata *Ops[] = {Scope, Name, File, Type};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000687 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000688}
689
Adrian Prantl3e0e1d02017-11-28 00:57:51 +0000690Optional<uint64_t> DIVariable::getSizeInBits() const {
691 // This is used by the Verifier so be mindful of broken types.
692 const Metadata *RawType = getRawType();
693 while (RawType) {
694 // Try to get the size directly.
695 if (auto *T = dyn_cast<DIType>(RawType))
696 if (uint64_t Size = T->getSizeInBits())
697 return Size;
698
699 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
700 // Look at the base type.
701 RawType = DT->getRawBaseType();
702 continue;
703 }
704
705 // Missing type or size.
706 break;
707 }
708
709 // Fail gracefully.
710 return None;
711}
712
Shiva Chen2c864552018-05-09 02:40:45 +0000713DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
714 MDString *Name, Metadata *File, unsigned Line,
715 StorageType Storage,
716 bool ShouldCreate) {
717 assert(Scope && "Expected scope");
718 assert(isCanonical(Name) && "Expected canonical MDString");
719 DEFINE_GETIMPL_LOOKUP(DILabel,
720 (Scope, Name, File, Line));
721 Metadata *Ops[] = {Scope, Name, File};
722 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
723}
724
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000725DIExpression *DIExpression::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000726 ArrayRef<uint64_t> Elements,
727 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000728 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
729 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000730}
731
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000732unsigned DIExpression::ExprOperand::getSize() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000733 switch (getOp()) {
Adrian Prantl941fa752016-12-05 18:04:47 +0000734 case dwarf::DW_OP_LLVM_fragment:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000735 return 3;
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000736 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000737 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000738 return 2;
739 default:
740 return 1;
741 }
742}
743
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000744bool DIExpression::isValid() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000745 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
746 // Check that there's space for the operand.
747 if (I->get() + I->getSize() > E->get())
748 return false;
749
750 // Check that the operand is valid.
751 switch (I->getOp()) {
752 default:
753 return false;
Adrian Prantl941fa752016-12-05 18:04:47 +0000754 case dwarf::DW_OP_LLVM_fragment:
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000755 // A fragment operator must appear at the end.
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000756 return I->get() + I->getSize() == E->get();
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000757 case dwarf::DW_OP_stack_value: {
758 // Must be the last one or followed by a DW_OP_LLVM_fragment.
759 if (I->get() + I->getSize() == E->get())
760 break;
761 auto J = I;
762 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
763 return false;
764 break;
765 }
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000766 case dwarf::DW_OP_swap: {
767 // Must be more than one implicit element on the stack.
768
769 // FIXME: A better way to implement this would be to add a local variable
770 // that keeps track of the stack depth and introduce something like a
771 // DW_LLVM_OP_implicit_location as a placeholder for the location this
772 // DIExpression is attached to, or else pass the number of implicit stack
773 // elements into isValid.
774 if (getNumElements() == 1)
775 return false;
776 break;
777 }
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000778 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000779 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000780 case dwarf::DW_OP_plus:
Evgeniy Stepanovf6081112015-09-30 19:55:43 +0000781 case dwarf::DW_OP_minus:
Strahinja Petrovic29202f62017-09-21 10:04:02 +0000782 case dwarf::DW_OP_mul:
Vedant Kumar4011c262018-02-13 01:09:52 +0000783 case dwarf::DW_OP_div:
784 case dwarf::DW_OP_mod:
Vedant Kumar04386d82018-02-09 19:19:55 +0000785 case dwarf::DW_OP_or:
Petar Jovanovic17689572018-02-14 13:10:35 +0000786 case dwarf::DW_OP_and:
Vedant Kumar96b7dc02018-02-13 01:09:46 +0000787 case dwarf::DW_OP_xor:
Vedant Kumar31ec3562018-02-13 01:09:49 +0000788 case dwarf::DW_OP_shl:
789 case dwarf::DW_OP_shr:
790 case dwarf::DW_OP_shra:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000791 case dwarf::DW_OP_deref:
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000792 case dwarf::DW_OP_xderef:
Vedant Kumar6379a622018-07-06 17:32:39 +0000793 case dwarf::DW_OP_lit0:
794 case dwarf::DW_OP_not:
795 case dwarf::DW_OP_dup:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000796 break;
797 }
798 }
799 return true;
800}
801
Adrian Prantl49797ca2016-12-22 05:27:12 +0000802Optional<DIExpression::FragmentInfo>
803DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
804 for (auto I = Start; I != End; ++I)
805 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
806 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
807 return Info;
808 }
809 return None;
Duncan P. N. Exon Smith86cc3322015-04-07 03:49:59 +0000810}
811
Andrew Ng03e35b62017-04-28 08:44:30 +0000812void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
813 int64_t Offset) {
814 if (Offset > 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000815 Ops.push_back(dwarf::DW_OP_plus_uconst);
Andrew Ng03e35b62017-04-28 08:44:30 +0000816 Ops.push_back(Offset);
817 } else if (Offset < 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000818 Ops.push_back(dwarf::DW_OP_constu);
Andrew Ng03e35b62017-04-28 08:44:30 +0000819 Ops.push_back(-Offset);
Florian Hahnffc498d2017-06-14 13:14:38 +0000820 Ops.push_back(dwarf::DW_OP_minus);
Andrew Ng03e35b62017-04-28 08:44:30 +0000821 }
822}
823
Reid Klecknerb5fced72017-05-09 19:59:29 +0000824bool DIExpression::extractIfOffset(int64_t &Offset) const {
825 if (getNumElements() == 0) {
826 Offset = 0;
827 return true;
828 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000829
830 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
Reid Klecknerb5fced72017-05-09 19:59:29 +0000831 Offset = Elements[1];
832 return true;
833 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000834
835 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
836 if (Elements[2] == dwarf::DW_OP_plus) {
837 Offset = Elements[1];
838 return true;
839 }
840 if (Elements[2] == dwarf::DW_OP_minus) {
841 Offset = -Elements[1];
842 return true;
843 }
Reid Klecknerb5fced72017-05-09 19:59:29 +0000844 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000845
Reid Klecknerb5fced72017-05-09 19:59:29 +0000846 return false;
847}
848
Adrian Prantld1317012017-12-08 21:58:18 +0000849DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
850 int64_t Offset, bool DerefAfter,
851 bool StackValue) {
Andrew Ng03e35b62017-04-28 08:44:30 +0000852 SmallVector<uint64_t, 8> Ops;
Adrian Prantld1317012017-12-08 21:58:18 +0000853 if (DerefBefore)
Andrew Ng03e35b62017-04-28 08:44:30 +0000854 Ops.push_back(dwarf::DW_OP_deref);
Bjorn Petterssonaa025802018-07-03 12:39:52 +0000855
Adrian Prantld1317012017-12-08 21:58:18 +0000856 appendOffset(Ops, Offset);
857 if (DerefAfter)
858 Ops.push_back(dwarf::DW_OP_deref);
859
Adrian Prantl210a29d2018-04-27 21:41:36 +0000860 return prependOpcodes(Expr, Ops, StackValue);
Vedant Kumar04386d82018-02-09 19:19:55 +0000861}
862
Adrian Prantl210a29d2018-04-27 21:41:36 +0000863DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
864 SmallVectorImpl<uint64_t> &Ops,
865 bool StackValue) {
Vedant Kumar8a368082018-07-06 21:06:20 +0000866 assert(Expr && "Can't prepend ops to this expression");
867
Bjorn Pettersson8dd6cf72018-07-03 11:29:00 +0000868 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
869 if (Ops.empty())
870 StackValue = false;
Vedant Kumar8a368082018-07-06 21:06:20 +0000871 for (auto Op : Expr->expr_ops()) {
872 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
873 if (StackValue) {
874 if (Op.getOp() == dwarf::DW_OP_stack_value)
875 StackValue = false;
876 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
877 Ops.push_back(dwarf::DW_OP_stack_value);
878 StackValue = false;
Andrew Ng03e35b62017-04-28 08:44:30 +0000879 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000880 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000881 Op.appendToVector(Ops);
Vedant Kumar8a368082018-07-06 21:06:20 +0000882 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000883 if (StackValue)
884 Ops.push_back(dwarf::DW_OP_stack_value);
Adrian Prantl109b2362017-04-28 17:51:05 +0000885 return DIExpression::get(Expr->getContext(), Ops);
Andrew Ng03e35b62017-04-28 08:44:30 +0000886}
887
Vedant Kumarb572f642018-07-26 20:56:53 +0000888DIExpression *DIExpression::append(const DIExpression *Expr,
889 ArrayRef<uint64_t> Ops) {
890 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
891
892 // Copy Expr's current op list.
893 SmallVector<uint64_t, 16> NewOps;
894 for (auto Op : Expr->expr_ops()) {
895 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
896 if (Op.getOp() == dwarf::DW_OP_stack_value ||
897 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
898 NewOps.append(Ops.begin(), Ops.end());
899
900 // Ensure that the new opcodes are only appended once.
901 Ops = None;
902 }
903 Op.appendToVector(NewOps);
904 }
905
906 NewOps.append(Ops.begin(), Ops.end());
907 return DIExpression::get(Expr->getContext(), NewOps);
908}
909
Vedant Kumar6379a622018-07-06 17:32:39 +0000910DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
911 ArrayRef<uint64_t> Ops) {
912 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
Vedant Kumarb572f642018-07-26 20:56:53 +0000913 assert(none_of(Ops,
914 [](uint64_t Op) {
915 return Op == dwarf::DW_OP_stack_value ||
916 Op == dwarf::DW_OP_LLVM_fragment;
917 }) &&
918 "Can't append this op");
Vedant Kumar6379a622018-07-06 17:32:39 +0000919
920 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
921 // has no DW_OP_stack_value.
922 //
923 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
924 Optional<FragmentInfo> FI = Expr->getFragmentInfo();
925 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
Vedant Kumarb572f642018-07-26 20:56:53 +0000926 ArrayRef<uint64_t> ExprOpsBeforeFragment =
927 Expr->getElements().drop_back(DropUntilStackValue);
928 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
929 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
930 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
Vedant Kumar6379a622018-07-06 17:32:39 +0000931
Vedant Kumarb572f642018-07-26 20:56:53 +0000932 // Append a DW_OP_deref after Expr's current op list if needed, then append
933 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
Vedant Kumar6379a622018-07-06 17:32:39 +0000934 SmallVector<uint64_t, 16> NewOps;
Vedant Kumar6379a622018-07-06 17:32:39 +0000935 if (NeedsDeref)
936 NewOps.push_back(dwarf::DW_OP_deref);
937 NewOps.append(Ops.begin(), Ops.end());
Vedant Kumarb572f642018-07-26 20:56:53 +0000938 if (NeedsStackValue)
939 NewOps.push_back(dwarf::DW_OP_stack_value);
940 return DIExpression::append(Expr, NewOps);
Vedant Kumar6379a622018-07-06 17:32:39 +0000941}
942
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000943Optional<DIExpression *> DIExpression::createFragmentExpression(
944 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
Adrian Prantlb192b542017-08-30 20:04:17 +0000945 SmallVector<uint64_t, 8> Ops;
946 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
947 if (Expr) {
948 for (auto Op : Expr->expr_ops()) {
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000949 switch (Op.getOp()) {
950 default: break;
951 case dwarf::DW_OP_plus:
952 case dwarf::DW_OP_minus:
953 // We can't safely split arithmetic into multiple fragments because we
954 // can't express carry-over between fragments.
955 //
956 // FIXME: We *could* preserve the lowest fragment of a constant offset
957 // operation if the offset fits into SizeInBits.
958 return None;
959 case dwarf::DW_OP_LLVM_fragment: {
Adrian Prantlb192b542017-08-30 20:04:17 +0000960 // Make the new offset point into the existing fragment.
961 uint64_t FragmentOffsetInBits = Op.getArg(0);
Bjorn Pettersson5479ad22018-05-03 17:04:21 +0000962 uint64_t FragmentSizeInBits = Op.getArg(1);
963 (void)FragmentSizeInBits;
964 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
Adrian Prantlb192b542017-08-30 20:04:17 +0000965 "new fragment outside of original fragment");
966 OffsetInBits += FragmentOffsetInBits;
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000967 continue;
968 }
Adrian Prantlb192b542017-08-30 20:04:17 +0000969 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000970 Op.appendToVector(Ops);
Adrian Prantlb192b542017-08-30 20:04:17 +0000971 }
972 }
973 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
974 Ops.push_back(OffsetInBits);
975 Ops.push_back(SizeInBits);
976 return DIExpression::get(Expr->getContext(), Ops);
977}
978
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000979bool DIExpression::isConstant() const {
980 // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
981 if (getNumElements() != 3 && getNumElements() != 6)
982 return false;
983 if (getElement(0) != dwarf::DW_OP_constu ||
984 getElement(2) != dwarf::DW_OP_stack_value)
985 return false;
986 if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
987 return false;
988 return true;
989}
990
991DIGlobalVariableExpression *
992DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
993 Metadata *Expression, StorageType Storage,
994 bool ShouldCreate) {
995 DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
996 Metadata *Ops[] = {Variable, Expression};
997 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
998}
999
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001000DIObjCProperty *DIObjCProperty::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001001 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
1002 MDString *GetterName, MDString *SetterName, unsigned Attributes,
1003 Metadata *Type, StorageType Storage, bool ShouldCreate) {
1004 assert(isCanonical(Name) && "Expected canonical MDString");
1005 assert(isCanonical(GetterName) && "Expected canonical MDString");
1006 assert(isCanonical(SetterName) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001007 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
1008 SetterName, Attributes, Type));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001009 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001010 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001011}
1012
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001013DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001014 Metadata *Scope, Metadata *Entity,
Adrian Prantld63bfd22017-07-19 00:09:54 +00001015 Metadata *File, unsigned Line,
1016 MDString *Name, StorageType Storage,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001017 bool ShouldCreate) {
1018 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantld63bfd22017-07-19 00:09:54 +00001019 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
1020 (Tag, Scope, Entity, File, Line, Name));
1021 Metadata *Ops[] = {Scope, Entity, Name, File};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001022 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001023}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001024
1025DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
1026 unsigned Line, MDString *Name, MDString *Value,
1027 StorageType Storage, bool ShouldCreate) {
1028 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001029 DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
Amjad Abouda9bcf162015-12-10 12:56:35 +00001030 Metadata *Ops[] = { Name, Value };
1031 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
1032}
1033
1034DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
1035 unsigned Line, Metadata *File,
1036 Metadata *Elements, StorageType Storage,
1037 bool ShouldCreate) {
1038 DEFINE_GETIMPL_LOOKUP(DIMacroFile,
1039 (MIType, Line, File, Elements));
1040 Metadata *Ops[] = { File, Elements };
1041 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
1042}