blob: 7a6160244ecaa443ba8e38f9e280529279b933ed [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,
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000026 unsigned Column, ArrayRef<Metadata *> MDs)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000027 : MDNode(C, DILocationKind, Storage, MDs) {
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000028 assert((MDs.size() == 1 || MDs.size() == 2) &&
29 "Expected a scope and optional inlined-at");
30
31 // Set line and column.
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000032 assert(Column < (1u << 16) && "Expected 16-bit column");
33
34 SubclassData32 = Line;
35 SubclassData16 = Column;
36}
37
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000038static void adjustColumn(unsigned &Column) {
39 // Set to unknown on overflow. We only have 16 bits to play with here.
40 if (Column >= (1u << 16))
41 Column = 0;
42}
43
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000044DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000045 unsigned Column, Metadata *Scope,
46 Metadata *InlinedAt, StorageType Storage,
47 bool ShouldCreate) {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +000048 // Fixup column.
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000049 adjustColumn(Column);
50
51 if (Storage == Uniqued) {
52 if (auto *N =
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000053 getUniqued(Context.pImpl->DILocations,
54 DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000055 return N;
56 if (!ShouldCreate)
57 return nullptr;
58 } else {
59 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
60 }
61
62 SmallVector<Metadata *, 2> Ops;
63 Ops.push_back(Scope);
64 if (InlinedAt)
65 Ops.push_back(InlinedAt);
66 return storeImpl(new (Ops.size())
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000067 DILocation(Context, Storage, Line, Column, Ops),
68 Storage, Context.pImpl->DILocations);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000069}
70
Vedant Kumar65b0d4d2018-04-12 20:58:24 +000071const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
David Blaikie2a813ef2018-08-23 22:35:58 +000072 const DILocation *LocB) {
Vedant Kumar2b881f52017-11-06 23:15:21 +000073 if (!LocA || !LocB)
74 return nullptr;
75
David Blaikie2a813ef2018-08-23 22:35:58 +000076 if (LocA == LocB)
Vedant Kumar2b881f52017-11-06 23:15:21 +000077 return LocA;
78
Vedant Kumar2b881f52017-11-06 23:15:21 +000079 SmallPtrSet<DILocation *, 5> InlinedLocationsA;
80 for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
81 InlinedLocationsA.insert(L);
David Blaikie2a813ef2018-08-23 22:35:58 +000082 SmallSet<std::pair<DIScope *, DILocation *>, 5> Locations;
83 DIScope *S = LocA->getScope();
84 DILocation *L = LocA->getInlinedAt();
85 while (S) {
86 Locations.insert(std::make_pair(S, L));
87 S = S->getScope().resolve();
88 if (!S && L) {
89 S = L->getScope();
90 L = L->getInlinedAt();
91 }
Vedant Kumar2b881f52017-11-06 23:15:21 +000092 }
David Blaikie2a813ef2018-08-23 22:35:58 +000093 const DILocation *Result = LocB;
94 S = LocB->getScope();
95 L = LocB->getInlinedAt();
96 while (S) {
97 if (Locations.count(std::make_pair(S, L)))
98 break;
99 S = S->getScope().resolve();
100 if (!S && L) {
101 S = L->getScope();
102 L = L->getInlinedAt();
103 }
104 }
Adrian Prantl4ddd0592018-08-24 23:30:57 +0000105
106 // If the two locations are irreconsilable, just pick one. This is misleading,
107 // but on the other hand, it's a "line 0" location.
108 if (!S || !isa<DILocalScope>(S))
109 S = LocA->getScope();
David Blaikie2a813ef2018-08-23 22:35:58 +0000110 return DILocation::get(Result->getContext(), 0, 0, S, L);
Vedant Kumar2b881f52017-11-06 23:15:21 +0000111}
112
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000113DINode::DIFlags DINode::getFlag(StringRef Flag) {
114 return StringSwitch<DIFlags>(Flag)
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000115#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
116#include "llvm/IR/DebugInfoFlags.def"
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000117 .Default(DINode::FlagZero);
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000118}
119
Mehdi Aminif42ec792016-10-01 05:57:50 +0000120StringRef DINode::getFlagString(DIFlags Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000121 switch (Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000122#define HANDLE_DI_FLAG(ID, NAME) \
123 case Flag##NAME: \
124 return "DIFlag" #NAME;
125#include "llvm/IR/DebugInfoFlags.def"
126 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000127 return "";
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000128}
129
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000130DINode::DIFlags DINode::splitFlags(DIFlags Flags,
Leny Kholodov40c62352016-09-06 17:03:02 +0000131 SmallVectorImpl<DIFlags> &SplitFlags) {
Bob Haarman26a87bd2016-10-25 22:11:52 +0000132 // Flags that are packed together need to be specially handled, so
133 // that, for example, we emit "DIFlagPublic" and not
134 // "DIFlagPrivate | DIFlagProtected".
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000135 if (DIFlags A = Flags & FlagAccessibility) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000136 if (A == FlagPrivate)
137 SplitFlags.push_back(FlagPrivate);
138 else if (A == FlagProtected)
139 SplitFlags.push_back(FlagProtected);
140 else
141 SplitFlags.push_back(FlagPublic);
142 Flags &= ~A;
143 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000144 if (DIFlags R = Flags & FlagPtrToMemberRep) {
Reid Kleckner604105b2016-06-17 21:31:33 +0000145 if (R == FlagSingleInheritance)
146 SplitFlags.push_back(FlagSingleInheritance);
147 else if (R == FlagMultipleInheritance)
148 SplitFlags.push_back(FlagMultipleInheritance);
149 else
150 SplitFlags.push_back(FlagVirtualInheritance);
151 Flags &= ~R;
152 }
Bob Haarman26a87bd2016-10-25 22:11:52 +0000153 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
154 Flags &= ~FlagIndirectVirtualBase;
155 SplitFlags.push_back(FlagIndirectVirtualBase);
156 }
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000157
158#define HANDLE_DI_FLAG(ID, NAME) \
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000159 if (DIFlags Bit = Flags & Flag##NAME) { \
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000160 SplitFlags.push_back(Bit); \
161 Flags &= ~Bit; \
162 }
163#include "llvm/IR/DebugInfoFlags.def"
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000164 return Flags;
165}
166
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000167DIScopeRef DIScope::getScope() const {
168 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000169 return T->getScope();
170
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000171 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000172 return SP->getScope();
173
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000174 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000175 return LB->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000176
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000177 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000178 return NS->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000179
Adrian Prantlab1243f2015-06-29 23:03:47 +0000180 if (auto *M = dyn_cast<DIModule>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000181 return M->getScope();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000182
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000183 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000184 "Unhandled type of scope.");
185 return nullptr;
186}
187
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000188StringRef DIScope::getName() const {
189 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000190 return T->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000191 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000192 return SP->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000193 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000194 return NS->getName();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000195 if (auto *M = dyn_cast<DIModule>(this))
196 return M->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000197 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
198 isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000199 "Unhandled type of scope.");
200 return "";
201}
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000202
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000203#ifndef NDEBUG
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000204static bool isCanonical(const MDString *S) {
205 return !S || !S->getString().empty();
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000206}
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000207#endif
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000208
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000209GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
210 MDString *Header,
211 ArrayRef<Metadata *> DwarfOps,
212 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000213 unsigned Hash = 0;
214 if (Storage == Uniqued) {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000215 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000216 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000217 return N;
218 if (!ShouldCreate)
219 return nullptr;
220 Hash = Key.getHash();
221 } else {
222 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
223 }
224
225 // Use a nullptr for empty headers.
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000226 assert(isCanonical(Header) && "Expected canonical MDString");
227 Metadata *PreOps[] = {Header};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000228 return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000229 Context, Storage, Hash, Tag, PreOps, DwarfOps),
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000230 Storage, Context.pImpl->GenericDINodes);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000231}
232
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000233void GenericDINode::recalculateHash() {
234 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000235}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000236
237#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
238#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
239#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
240 do { \
241 if (Storage == Uniqued) { \
242 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
243 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
244 return N; \
245 if (!ShouldCreate) \
246 return nullptr; \
247 } else { \
248 assert(ShouldCreate && \
249 "Expected non-uniqued nodes to always be created"); \
250 } \
251 } while (false)
252#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000253 return storeImpl(new (array_lengthof(OPS)) \
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000254 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
255 Storage, Context.pImpl->CLASS##s)
256#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
257 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
258 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000259#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000260 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000261 Storage, Context.pImpl->CLASS##s)
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000262#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
263 return storeImpl(new (NUM_OPS) \
264 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
265 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000266
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000267DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000268 StorageType Storage, bool ShouldCreate) {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000269 auto *CountNode = ConstantAsMetadata::get(
270 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
271 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
272}
273
274DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
275 int64_t Lo, StorageType Storage,
276 bool ShouldCreate) {
277 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, Lo));
278 Metadata *Ops[] = { CountNode };
279 DEFINE_GETIMPL_STORE(DISubrange, (CountNode, Lo), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000280}
281
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000282DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000283 bool IsUnsigned, MDString *Name,
284 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000285 assert(isCanonical(Name) && "Expected canonical MDString");
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000286 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000287 Metadata *Ops[] = {Name};
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000288 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000289}
290
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000291DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000292 MDString *Name, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000293 uint32_t AlignInBits, unsigned Encoding,
Adrian Prantl55f42622018-08-14 19:35:34 +0000294 DIFlags Flags, StorageType Storage,
295 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000296 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000297 DEFINE_GETIMPL_LOOKUP(DIBasicType,
Adrian Prantl55f42622018-08-14 19:35:34 +0000298 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000299 Metadata *Ops[] = {nullptr, nullptr, Name};
Adrian Prantl55f42622018-08-14 19:35:34 +0000300 DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
301 Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000302}
303
Vedant Kumar6379a622018-07-06 17:32:39 +0000304Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
305 switch (getEncoding()) {
306 case dwarf::DW_ATE_signed:
307 case dwarf::DW_ATE_signed_char:
308 return Signedness::Signed;
309 case dwarf::DW_ATE_unsigned:
310 case dwarf::DW_ATE_unsigned_char:
311 return Signedness::Unsigned;
312 default:
313 return None;
314 }
315}
316
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000317DIDerivedType *DIDerivedType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000318 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000319 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000320 uint32_t AlignInBits, uint64_t OffsetInBits,
321 Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
322 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000323 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000324 DEFINE_GETIMPL_LOOKUP(DIDerivedType,
325 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000326 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
327 ExtraData));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000328 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
329 DEFINE_GETIMPL_STORE(
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000330 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
331 DWARFAddressSpace, Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000332}
333
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334DICompositeType *DICompositeType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000335 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000336 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000337 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000338 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000339 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
340 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000341 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +0000342
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000343 // Keep this in sync with buildODRType.
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000344 DEFINE_GETIMPL_LOOKUP(
345 DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
346 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000347 VTableHolder, TemplateParams, Identifier, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000348 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000349 Elements, VTableHolder, TemplateParams, Identifier,
350 Discriminator};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000351 DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000352 AlignInBits, OffsetInBits, Flags),
353 Ops);
354}
355
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000356DICompositeType *DICompositeType::buildODRType(
357 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
358 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000359 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000360 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000361 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000362 assert(!Identifier.getString().empty() && "Expected valid identifier");
363 if (!Context.isODRUniquingDebugTypes())
364 return nullptr;
365 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
366 if (!CT)
367 return CT = DICompositeType::getDistinct(
368 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
369 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000370 VTableHolder, TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000371
372 // Only mutate CT if it's a forward declaration and the new operands aren't.
373 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
374 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
375 return CT;
376
377 // Mutate CT in place. Keep this in sync with getImpl.
378 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
379 Flags);
380 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000381 Elements, VTableHolder, TemplateParams, &Identifier,
382 Discriminator};
Simon Pilgrim1ec7dc72016-05-02 16:45:02 +0000383 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000384 "Mismatched number of operands");
385 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
386 if (Ops[I] != CT->getOperand(I))
387 CT->setOperand(I, Ops[I]);
388 return CT;
389}
390
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000391DICompositeType *DICompositeType::getODRType(
392 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
393 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000394 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000395 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000396 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000397 assert(!Identifier.getString().empty() && "Expected valid identifier");
398 if (!Context.isODRUniquingDebugTypes())
399 return nullptr;
400 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
401 if (!CT)
402 CT = DICompositeType::getDistinct(
403 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
404 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000405 TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000406 return CT;
407}
408
409DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
410 MDString &Identifier) {
411 assert(!Identifier.getString().empty() && "Expected valid identifier");
412 if (!Context.isODRUniquingDebugTypes())
413 return nullptr;
414 return Context.pImpl->DITypeMap->lookup(&Identifier);
415}
416
Leny Kholodov40c62352016-09-06 17:03:02 +0000417DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
418 uint8_t CC, Metadata *TypeArray,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000419 StorageType Storage,
420 bool ShouldCreate) {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000421 DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
Duncan P. N. Exon Smithb9e045a2015-07-24 20:56:36 +0000422 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000423 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000424}
425
Reid Kleckner26fa1bf2017-09-19 18:14:45 +0000426// FIXME: Implement this string-enum correspondence with a .def file and macros,
427// so that the association is explicit rather than implied.
Scott Linder71603842018-02-12 19:45:54 +0000428static const char *ChecksumKindName[DIFile::CSK_Last] = {
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000429 "CSK_MD5",
430 "CSK_SHA1"
431};
432
Scott Linder71603842018-02-12 19:45:54 +0000433StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
434 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
435 // The first space was originally the CSK_None variant, which is now
436 // obsolete, but the space is still reserved in ChecksumKind, so we account
437 // for it here.
438 return ChecksumKindName[CSKind - 1];
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000439}
440
Scott Linder71603842018-02-12 19:45:54 +0000441Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
442 return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
443 .Case("CSK_MD5", DIFile::CSK_MD5)
444 .Case("CSK_SHA1", DIFile::CSK_SHA1)
445 .Default(None);
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000446}
447
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000448DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
Scott Linder71603842018-02-12 19:45:54 +0000449 MDString *Directory,
450 Optional<DIFile::ChecksumInfo<MDString *>> CS,
Scott Linder16c7bda2018-02-23 23:01:06 +0000451 Optional<MDString *> Source, StorageType Storage,
452 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000453 assert(isCanonical(Filename) && "Expected canonical MDString");
454 assert(isCanonical(Directory) && "Expected canonical MDString");
Scott Linder71603842018-02-12 19:45:54 +0000455 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
Scott Linder16c7bda2018-02-23 23:01:06 +0000456 assert((!Source || isCanonical(*Source)) && "Expected canonical MDString");
457 DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source));
458 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
459 Source.getValueOr(nullptr)};
460 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000461}
462
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000463DICompileUnit *DICompileUnit::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000464 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
465 MDString *Producer, bool IsOptimized, MDString *Flags,
466 unsigned RuntimeVersion, MDString *SplitDebugFilename,
467 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Adrian Prantl75819ae2016-04-15 15:57:41 +0000468 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
Dehao Chen0944a8c2017-02-01 22:45:09 +0000469 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
David Blaikie66cf14d2018-08-16 21:29:55 +0000470 unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000471 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000472 assert(isCanonical(Producer) && "Expected canonical MDString");
473 assert(isCanonical(Flags) && "Expected canonical MDString");
474 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000475
Adrian Prantl75819ae2016-04-15 15:57:41 +0000476 Metadata *Ops[] = {
477 File, Producer, Flags, SplitDebugFilename,
478 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
479 Macros};
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000480 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
481 Context, Storage, SourceLanguage, IsOptimized,
482 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
David Blaikie66cf14d2018-08-16 21:29:55 +0000483 DebugInfoForProfiling, NameTableKind, Ops),
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000484 Storage);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000485}
486
Adrian Prantlb939a252016-03-31 23:56:58 +0000487Optional<DICompileUnit::DebugEmissionKind>
488DICompileUnit::getEmissionKind(StringRef Str) {
489 return StringSwitch<Optional<DebugEmissionKind>>(Str)
490 .Case("NoDebug", NoDebug)
491 .Case("FullDebug", FullDebug)
492 .Case("LineTablesOnly", LineTablesOnly)
Alexey Bataevd4dd7212018-08-01 19:38:20 +0000493 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
Adrian Prantlb939a252016-03-31 23:56:58 +0000494 .Default(None);
495}
496
David Blaikie66cf14d2018-08-16 21:29:55 +0000497Optional<DICompileUnit::DebugNameTableKind>
498DICompileUnit::getNameTableKind(StringRef Str) {
499 return StringSwitch<Optional<DebugNameTableKind>>(Str)
500 .Case("Default", DebugNameTableKind::Default)
501 .Case("GNU", DebugNameTableKind::GNU)
502 .Case("None", DebugNameTableKind::None)
503 .Default(None);
504}
505
Fangrui Song3c1b5db2018-07-06 19:26:00 +0000506const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
Adrian Prantlb939a252016-03-31 23:56:58 +0000507 switch (EK) {
508 case NoDebug: return "NoDebug";
509 case FullDebug: return "FullDebug";
510 case LineTablesOnly: return "LineTablesOnly";
Alexey Bataev075412d2018-08-23 17:43:40 +0000511 case DebugDirectivesOnly: return "DebugDirectivesOnly";
Adrian Prantlb939a252016-03-31 23:56:58 +0000512 }
513 return nullptr;
514}
515
David Blaikie66cf14d2018-08-16 21:29:55 +0000516const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
517 switch (NTK) {
518 case DebugNameTableKind::Default:
519 return nullptr;
520 case DebugNameTableKind::GNU:
521 return "GNU";
522 case DebugNameTableKind::None:
523 return "None";
524 }
525 return nullptr;
526}
527
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000528DISubprogram *DILocalScope::getSubprogram() const {
529 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000530 return Block->getScope()->getSubprogram();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000531 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000532}
533
Amjad Abouda5ba9912016-04-21 16:58:49 +0000534DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
535 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
536 return File->getScope()->getNonLexicalBlockFileScope();
537 return const_cast<DILocalScope *>(this);
538}
539
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000540DISubprogram *DISubprogram::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000541 LLVMContext &Context, Metadata *Scope, MDString *Name,
542 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
543 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
544 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000545 int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000546 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000547 Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000548 assert(isCanonical(Name) && "Expected canonical MDString");
549 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000550 DEFINE_GETIMPL_LOOKUP(
Adrian Prantl1d12b882017-04-26 22:56:44 +0000551 DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
552 IsDefinition, ScopeLine, ContainingType, Virtuality,
553 VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000554 TemplateParams, Declaration, RetainedNodes, ThrownTypes));
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000555 SmallVector<Metadata *, 11> Ops = {
Shiva Chen2c864552018-05-09 02:40:45 +0000556 File, Scope, Name, LinkageName, Type, Unit,
557 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000558 if (!ThrownTypes) {
559 Ops.pop_back();
560 if (!TemplateParams) {
561 Ops.pop_back();
562 if (!ContainingType)
563 Ops.pop_back();
564 }
565 }
566 DEFINE_GETIMPL_STORE_N(DISubprogram,
567 (Line, ScopeLine, Virtuality, VirtualIndex,
568 ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
569 IsOptimized),
570 Ops, Ops.size());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000571}
572
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000573bool DISubprogram::describes(const Function *F) const {
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000574 assert(F && "Invalid function");
Peter Collingbourned4bff302015-11-05 22:03:56 +0000575 if (F->getSubprogram() == this)
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000576 return true;
577 StringRef Name = getLinkageName();
578 if (Name.empty())
579 Name = getName();
580 return F->getName() == Name;
581}
582
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000583DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000584 Metadata *File, unsigned Line,
585 unsigned Column, StorageType Storage,
586 bool ShouldCreate) {
Duncan P. N. Exon Smithb09eb9f2015-08-28 22:58:50 +0000587 // Fixup column.
588 adjustColumn(Column);
589
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000590 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000591 DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000592 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000593 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000594}
595
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000596DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000597 Metadata *Scope, Metadata *File,
598 unsigned Discriminator,
599 StorageType Storage,
600 bool ShouldCreate) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000601 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000602 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000603 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000604 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000605}
606
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000607DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
Adrian Prantlfed4f392017-04-28 22:25:46 +0000608 MDString *Name, bool ExportSymbols,
609 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000610 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantlfed4f392017-04-28 22:25:46 +0000611 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
612 // The nullptr is for DIScope's File operand. This should be refactored.
613 Metadata *Ops[] = {nullptr, Scope, Name};
614 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000615}
616
Adrian Prantlab1243f2015-06-29 23:03:47 +0000617DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
618 MDString *Name, MDString *ConfigurationMacros,
619 MDString *IncludePath, MDString *ISysRoot,
620 StorageType Storage, bool ShouldCreate) {
621 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000622 DEFINE_GETIMPL_LOOKUP(
623 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
Adrian Prantlab1243f2015-06-29 23:03:47 +0000624 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
625 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
626}
627
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000628DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000629 MDString *Name,
630 Metadata *Type,
631 StorageType Storage,
632 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000633 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000634 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000635 Metadata *Ops[] = {Name, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000636 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000637}
638
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000639DITemplateValueParameter *DITemplateValueParameter::getImpl(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000640 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
641 Metadata *Value, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000642 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000643 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000644 Metadata *Ops[] = {Name, Type, Value};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000645 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000646}
647
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000648DIGlobalVariable *
649DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000650 MDString *LinkageName, Metadata *File, unsigned Line,
651 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000652 Metadata *StaticDataMemberDeclaration,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000653 uint32_t AlignInBits, StorageType Storage,
654 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000655 assert(isCanonical(Name) && "Expected canonical MDString");
656 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000657 DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000658 (Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000659 IsLocalToUnit, IsDefinition,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000660 StaticDataMemberDeclaration, AlignInBits));
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000661 Metadata *Ops[] = {
662 Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000663 DEFINE_GETIMPL_STORE(DIGlobalVariable,
664 (Line, IsLocalToUnit, IsDefinition, AlignInBits),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000665 Ops);
666}
667
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000668DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
669 MDString *Name, Metadata *File,
670 unsigned Line, Metadata *Type,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000671 unsigned Arg, DIFlags Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000672 uint32_t AlignInBits,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000673 StorageType Storage,
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000674 bool ShouldCreate) {
Duncan P. N. Exon Smith1ec75ae2015-04-28 01:07:33 +0000675 // 64K ought to be enough for any frontend.
676 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
Duncan P. N. Exon Smith72fe2d02015-02-13 01:39:44 +0000677
Duncan P. N. Exon Smithe2c61d92015-03-27 17:56:39 +0000678 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000679 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000680 DEFINE_GETIMPL_LOOKUP(DILocalVariable,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000681 (Scope, Name, File, Line, Type, Arg, Flags,
682 AlignInBits));
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000683 Metadata *Ops[] = {Scope, Name, File, Type};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000684 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000685}
686
Adrian Prantl3e0e1d02017-11-28 00:57:51 +0000687Optional<uint64_t> DIVariable::getSizeInBits() const {
688 // This is used by the Verifier so be mindful of broken types.
689 const Metadata *RawType = getRawType();
690 while (RawType) {
691 // Try to get the size directly.
692 if (auto *T = dyn_cast<DIType>(RawType))
693 if (uint64_t Size = T->getSizeInBits())
694 return Size;
695
696 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
697 // Look at the base type.
698 RawType = DT->getRawBaseType();
699 continue;
700 }
701
702 // Missing type or size.
703 break;
704 }
705
706 // Fail gracefully.
707 return None;
708}
709
Shiva Chen2c864552018-05-09 02:40:45 +0000710DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
711 MDString *Name, Metadata *File, unsigned Line,
712 StorageType Storage,
713 bool ShouldCreate) {
714 assert(Scope && "Expected scope");
715 assert(isCanonical(Name) && "Expected canonical MDString");
716 DEFINE_GETIMPL_LOOKUP(DILabel,
717 (Scope, Name, File, Line));
718 Metadata *Ops[] = {Scope, Name, File};
719 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
720}
721
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000722DIExpression *DIExpression::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000723 ArrayRef<uint64_t> Elements,
724 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000725 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
726 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000727}
728
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000729unsigned DIExpression::ExprOperand::getSize() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000730 switch (getOp()) {
Adrian Prantl941fa752016-12-05 18:04:47 +0000731 case dwarf::DW_OP_LLVM_fragment:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000732 return 3;
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000733 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000734 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000735 return 2;
736 default:
737 return 1;
738 }
739}
740
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000741bool DIExpression::isValid() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000742 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
743 // Check that there's space for the operand.
744 if (I->get() + I->getSize() > E->get())
745 return false;
746
747 // Check that the operand is valid.
748 switch (I->getOp()) {
749 default:
750 return false;
Adrian Prantl941fa752016-12-05 18:04:47 +0000751 case dwarf::DW_OP_LLVM_fragment:
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000752 // A fragment operator must appear at the end.
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000753 return I->get() + I->getSize() == E->get();
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000754 case dwarf::DW_OP_stack_value: {
755 // Must be the last one or followed by a DW_OP_LLVM_fragment.
756 if (I->get() + I->getSize() == E->get())
757 break;
758 auto J = I;
759 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
760 return false;
761 break;
762 }
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000763 case dwarf::DW_OP_swap: {
764 // Must be more than one implicit element on the stack.
765
766 // FIXME: A better way to implement this would be to add a local variable
767 // that keeps track of the stack depth and introduce something like a
768 // DW_LLVM_OP_implicit_location as a placeholder for the location this
769 // DIExpression is attached to, or else pass the number of implicit stack
770 // elements into isValid.
771 if (getNumElements() == 1)
772 return false;
773 break;
774 }
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000775 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000776 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000777 case dwarf::DW_OP_plus:
Evgeniy Stepanovf6081112015-09-30 19:55:43 +0000778 case dwarf::DW_OP_minus:
Strahinja Petrovic29202f62017-09-21 10:04:02 +0000779 case dwarf::DW_OP_mul:
Vedant Kumar4011c262018-02-13 01:09:52 +0000780 case dwarf::DW_OP_div:
781 case dwarf::DW_OP_mod:
Vedant Kumar04386d82018-02-09 19:19:55 +0000782 case dwarf::DW_OP_or:
Petar Jovanovic17689572018-02-14 13:10:35 +0000783 case dwarf::DW_OP_and:
Vedant Kumar96b7dc02018-02-13 01:09:46 +0000784 case dwarf::DW_OP_xor:
Vedant Kumar31ec3562018-02-13 01:09:49 +0000785 case dwarf::DW_OP_shl:
786 case dwarf::DW_OP_shr:
787 case dwarf::DW_OP_shra:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000788 case dwarf::DW_OP_deref:
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000789 case dwarf::DW_OP_xderef:
Vedant Kumar6379a622018-07-06 17:32:39 +0000790 case dwarf::DW_OP_lit0:
791 case dwarf::DW_OP_not:
792 case dwarf::DW_OP_dup:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000793 break;
794 }
795 }
796 return true;
797}
798
Adrian Prantl49797ca2016-12-22 05:27:12 +0000799Optional<DIExpression::FragmentInfo>
800DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
801 for (auto I = Start; I != End; ++I)
802 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
803 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
804 return Info;
805 }
806 return None;
Duncan P. N. Exon Smith86cc3322015-04-07 03:49:59 +0000807}
808
Andrew Ng03e35b62017-04-28 08:44:30 +0000809void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
810 int64_t Offset) {
811 if (Offset > 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000812 Ops.push_back(dwarf::DW_OP_plus_uconst);
Andrew Ng03e35b62017-04-28 08:44:30 +0000813 Ops.push_back(Offset);
814 } else if (Offset < 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000815 Ops.push_back(dwarf::DW_OP_constu);
Andrew Ng03e35b62017-04-28 08:44:30 +0000816 Ops.push_back(-Offset);
Florian Hahnffc498d2017-06-14 13:14:38 +0000817 Ops.push_back(dwarf::DW_OP_minus);
Andrew Ng03e35b62017-04-28 08:44:30 +0000818 }
819}
820
Reid Klecknerb5fced72017-05-09 19:59:29 +0000821bool DIExpression::extractIfOffset(int64_t &Offset) const {
822 if (getNumElements() == 0) {
823 Offset = 0;
824 return true;
825 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000826
827 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
Reid Klecknerb5fced72017-05-09 19:59:29 +0000828 Offset = Elements[1];
829 return true;
830 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000831
832 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
833 if (Elements[2] == dwarf::DW_OP_plus) {
834 Offset = Elements[1];
835 return true;
836 }
837 if (Elements[2] == dwarf::DW_OP_minus) {
838 Offset = -Elements[1];
839 return true;
840 }
Reid Klecknerb5fced72017-05-09 19:59:29 +0000841 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000842
Reid Klecknerb5fced72017-05-09 19:59:29 +0000843 return false;
844}
845
Adrian Prantld1317012017-12-08 21:58:18 +0000846DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
847 int64_t Offset, bool DerefAfter,
848 bool StackValue) {
Andrew Ng03e35b62017-04-28 08:44:30 +0000849 SmallVector<uint64_t, 8> Ops;
Adrian Prantld1317012017-12-08 21:58:18 +0000850 if (DerefBefore)
Andrew Ng03e35b62017-04-28 08:44:30 +0000851 Ops.push_back(dwarf::DW_OP_deref);
Bjorn Petterssonaa025802018-07-03 12:39:52 +0000852
Adrian Prantld1317012017-12-08 21:58:18 +0000853 appendOffset(Ops, Offset);
854 if (DerefAfter)
855 Ops.push_back(dwarf::DW_OP_deref);
856
Adrian Prantl210a29d2018-04-27 21:41:36 +0000857 return prependOpcodes(Expr, Ops, StackValue);
Vedant Kumar04386d82018-02-09 19:19:55 +0000858}
859
Adrian Prantl210a29d2018-04-27 21:41:36 +0000860DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
861 SmallVectorImpl<uint64_t> &Ops,
862 bool StackValue) {
Vedant Kumar8a368082018-07-06 21:06:20 +0000863 assert(Expr && "Can't prepend ops to this expression");
864
Bjorn Pettersson8dd6cf72018-07-03 11:29:00 +0000865 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
866 if (Ops.empty())
867 StackValue = false;
Vedant Kumar8a368082018-07-06 21:06:20 +0000868 for (auto Op : Expr->expr_ops()) {
869 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
870 if (StackValue) {
871 if (Op.getOp() == dwarf::DW_OP_stack_value)
872 StackValue = false;
873 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
874 Ops.push_back(dwarf::DW_OP_stack_value);
875 StackValue = false;
Andrew Ng03e35b62017-04-28 08:44:30 +0000876 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000877 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000878 Op.appendToVector(Ops);
Vedant Kumar8a368082018-07-06 21:06:20 +0000879 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000880 if (StackValue)
881 Ops.push_back(dwarf::DW_OP_stack_value);
Adrian Prantl109b2362017-04-28 17:51:05 +0000882 return DIExpression::get(Expr->getContext(), Ops);
Andrew Ng03e35b62017-04-28 08:44:30 +0000883}
884
Vedant Kumarb572f642018-07-26 20:56:53 +0000885DIExpression *DIExpression::append(const DIExpression *Expr,
886 ArrayRef<uint64_t> Ops) {
887 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
888
889 // Copy Expr's current op list.
890 SmallVector<uint64_t, 16> NewOps;
891 for (auto Op : Expr->expr_ops()) {
892 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
893 if (Op.getOp() == dwarf::DW_OP_stack_value ||
894 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
895 NewOps.append(Ops.begin(), Ops.end());
896
897 // Ensure that the new opcodes are only appended once.
898 Ops = None;
899 }
900 Op.appendToVector(NewOps);
901 }
902
903 NewOps.append(Ops.begin(), Ops.end());
904 return DIExpression::get(Expr->getContext(), NewOps);
905}
906
Vedant Kumar6379a622018-07-06 17:32:39 +0000907DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
908 ArrayRef<uint64_t> Ops) {
909 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
Vedant Kumarb572f642018-07-26 20:56:53 +0000910 assert(none_of(Ops,
911 [](uint64_t Op) {
912 return Op == dwarf::DW_OP_stack_value ||
913 Op == dwarf::DW_OP_LLVM_fragment;
914 }) &&
915 "Can't append this op");
Vedant Kumar6379a622018-07-06 17:32:39 +0000916
917 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
918 // has no DW_OP_stack_value.
919 //
920 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
921 Optional<FragmentInfo> FI = Expr->getFragmentInfo();
922 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
Vedant Kumarb572f642018-07-26 20:56:53 +0000923 ArrayRef<uint64_t> ExprOpsBeforeFragment =
924 Expr->getElements().drop_back(DropUntilStackValue);
925 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
926 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
927 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
Vedant Kumar6379a622018-07-06 17:32:39 +0000928
Vedant Kumarb572f642018-07-26 20:56:53 +0000929 // Append a DW_OP_deref after Expr's current op list if needed, then append
930 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
Vedant Kumar6379a622018-07-06 17:32:39 +0000931 SmallVector<uint64_t, 16> NewOps;
Vedant Kumar6379a622018-07-06 17:32:39 +0000932 if (NeedsDeref)
933 NewOps.push_back(dwarf::DW_OP_deref);
934 NewOps.append(Ops.begin(), Ops.end());
Vedant Kumarb572f642018-07-26 20:56:53 +0000935 if (NeedsStackValue)
936 NewOps.push_back(dwarf::DW_OP_stack_value);
937 return DIExpression::append(Expr, NewOps);
Vedant Kumar6379a622018-07-06 17:32:39 +0000938}
939
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000940Optional<DIExpression *> DIExpression::createFragmentExpression(
941 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
Adrian Prantlb192b542017-08-30 20:04:17 +0000942 SmallVector<uint64_t, 8> Ops;
943 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
944 if (Expr) {
945 for (auto Op : Expr->expr_ops()) {
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000946 switch (Op.getOp()) {
947 default: break;
948 case dwarf::DW_OP_plus:
949 case dwarf::DW_OP_minus:
950 // We can't safely split arithmetic into multiple fragments because we
951 // can't express carry-over between fragments.
952 //
953 // FIXME: We *could* preserve the lowest fragment of a constant offset
954 // operation if the offset fits into SizeInBits.
955 return None;
956 case dwarf::DW_OP_LLVM_fragment: {
Adrian Prantlb192b542017-08-30 20:04:17 +0000957 // Make the new offset point into the existing fragment.
958 uint64_t FragmentOffsetInBits = Op.getArg(0);
Bjorn Pettersson5479ad22018-05-03 17:04:21 +0000959 uint64_t FragmentSizeInBits = Op.getArg(1);
960 (void)FragmentSizeInBits;
961 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
Adrian Prantlb192b542017-08-30 20:04:17 +0000962 "new fragment outside of original fragment");
963 OffsetInBits += FragmentOffsetInBits;
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000964 continue;
965 }
Adrian Prantlb192b542017-08-30 20:04:17 +0000966 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000967 Op.appendToVector(Ops);
Adrian Prantlb192b542017-08-30 20:04:17 +0000968 }
969 }
970 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
971 Ops.push_back(OffsetInBits);
972 Ops.push_back(SizeInBits);
973 return DIExpression::get(Expr->getContext(), Ops);
974}
975
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000976bool DIExpression::isConstant() const {
977 // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
978 if (getNumElements() != 3 && getNumElements() != 6)
979 return false;
980 if (getElement(0) != dwarf::DW_OP_constu ||
981 getElement(2) != dwarf::DW_OP_stack_value)
982 return false;
983 if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
984 return false;
985 return true;
986}
987
988DIGlobalVariableExpression *
989DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
990 Metadata *Expression, StorageType Storage,
991 bool ShouldCreate) {
992 DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
993 Metadata *Ops[] = {Variable, Expression};
994 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
995}
996
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000997DIObjCProperty *DIObjCProperty::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000998 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
999 MDString *GetterName, MDString *SetterName, unsigned Attributes,
1000 Metadata *Type, StorageType Storage, bool ShouldCreate) {
1001 assert(isCanonical(Name) && "Expected canonical MDString");
1002 assert(isCanonical(GetterName) && "Expected canonical MDString");
1003 assert(isCanonical(SetterName) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001004 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
1005 SetterName, Attributes, Type));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001006 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001007 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001008}
1009
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001010DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001011 Metadata *Scope, Metadata *Entity,
Adrian Prantld63bfd22017-07-19 00:09:54 +00001012 Metadata *File, unsigned Line,
1013 MDString *Name, StorageType Storage,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001014 bool ShouldCreate) {
1015 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantld63bfd22017-07-19 00:09:54 +00001016 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
1017 (Tag, Scope, Entity, File, Line, Name));
1018 Metadata *Ops[] = {Scope, Entity, Name, File};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001019 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001020}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001021
1022DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
1023 unsigned Line, MDString *Name, MDString *Value,
1024 StorageType Storage, bool ShouldCreate) {
1025 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001026 DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
Amjad Abouda9bcf162015-12-10 12:56:35 +00001027 Metadata *Ops[] = { Name, Value };
1028 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
1029}
1030
1031DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
1032 unsigned Line, Metadata *File,
1033 Metadata *Elements, StorageType Storage,
1034 bool ShouldCreate) {
1035 DEFINE_GETIMPL_LOOKUP(DIMacroFile,
1036 (MIType, Line, File, Elements));
1037 Metadata *Ops[] = { File, Elements };
1038 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
1039}