blob: 0ceded076796142f6a8b28c57a76f615334b1678 [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 }
105 return DILocation::get(Result->getContext(), 0, 0, S, L);
Vedant Kumar2b881f52017-11-06 23:15:21 +0000106}
107
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000108DINode::DIFlags DINode::getFlag(StringRef Flag) {
109 return StringSwitch<DIFlags>(Flag)
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000110#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
111#include "llvm/IR/DebugInfoFlags.def"
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000112 .Default(DINode::FlagZero);
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000113}
114
Mehdi Aminif42ec792016-10-01 05:57:50 +0000115StringRef DINode::getFlagString(DIFlags Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000116 switch (Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000117#define HANDLE_DI_FLAG(ID, NAME) \
118 case Flag##NAME: \
119 return "DIFlag" #NAME;
120#include "llvm/IR/DebugInfoFlags.def"
121 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000122 return "";
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000123}
124
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000125DINode::DIFlags DINode::splitFlags(DIFlags Flags,
Leny Kholodov40c62352016-09-06 17:03:02 +0000126 SmallVectorImpl<DIFlags> &SplitFlags) {
Bob Haarman26a87bd2016-10-25 22:11:52 +0000127 // Flags that are packed together need to be specially handled, so
128 // that, for example, we emit "DIFlagPublic" and not
129 // "DIFlagPrivate | DIFlagProtected".
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000130 if (DIFlags A = Flags & FlagAccessibility) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000131 if (A == FlagPrivate)
132 SplitFlags.push_back(FlagPrivate);
133 else if (A == FlagProtected)
134 SplitFlags.push_back(FlagProtected);
135 else
136 SplitFlags.push_back(FlagPublic);
137 Flags &= ~A;
138 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000139 if (DIFlags R = Flags & FlagPtrToMemberRep) {
Reid Kleckner604105b2016-06-17 21:31:33 +0000140 if (R == FlagSingleInheritance)
141 SplitFlags.push_back(FlagSingleInheritance);
142 else if (R == FlagMultipleInheritance)
143 SplitFlags.push_back(FlagMultipleInheritance);
144 else
145 SplitFlags.push_back(FlagVirtualInheritance);
146 Flags &= ~R;
147 }
Bob Haarman26a87bd2016-10-25 22:11:52 +0000148 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
149 Flags &= ~FlagIndirectVirtualBase;
150 SplitFlags.push_back(FlagIndirectVirtualBase);
151 }
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000152
153#define HANDLE_DI_FLAG(ID, NAME) \
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000154 if (DIFlags Bit = Flags & Flag##NAME) { \
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000155 SplitFlags.push_back(Bit); \
156 Flags &= ~Bit; \
157 }
158#include "llvm/IR/DebugInfoFlags.def"
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000159 return Flags;
160}
161
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000162DIScopeRef DIScope::getScope() const {
163 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000164 return T->getScope();
165
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000166 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000167 return SP->getScope();
168
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000169 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000170 return LB->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000171
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000172 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000173 return NS->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000174
Adrian Prantlab1243f2015-06-29 23:03:47 +0000175 if (auto *M = dyn_cast<DIModule>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000176 return M->getScope();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000177
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000178 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000179 "Unhandled type of scope.");
180 return nullptr;
181}
182
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000183StringRef DIScope::getName() const {
184 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000185 return T->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000186 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000187 return SP->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000188 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000189 return NS->getName();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000190 if (auto *M = dyn_cast<DIModule>(this))
191 return M->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000192 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
193 isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000194 "Unhandled type of scope.");
195 return "";
196}
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000197
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000198#ifndef NDEBUG
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000199static bool isCanonical(const MDString *S) {
200 return !S || !S->getString().empty();
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000201}
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000202#endif
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000203
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000204GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
205 MDString *Header,
206 ArrayRef<Metadata *> DwarfOps,
207 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000208 unsigned Hash = 0;
209 if (Storage == Uniqued) {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000210 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000211 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000212 return N;
213 if (!ShouldCreate)
214 return nullptr;
215 Hash = Key.getHash();
216 } else {
217 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
218 }
219
220 // Use a nullptr for empty headers.
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000221 assert(isCanonical(Header) && "Expected canonical MDString");
222 Metadata *PreOps[] = {Header};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000223 return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000224 Context, Storage, Hash, Tag, PreOps, DwarfOps),
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000225 Storage, Context.pImpl->GenericDINodes);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000226}
227
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000228void GenericDINode::recalculateHash() {
229 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000230}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000231
232#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
233#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
234#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
235 do { \
236 if (Storage == Uniqued) { \
237 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
238 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
239 return N; \
240 if (!ShouldCreate) \
241 return nullptr; \
242 } else { \
243 assert(ShouldCreate && \
244 "Expected non-uniqued nodes to always be created"); \
245 } \
246 } while (false)
247#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000248 return storeImpl(new (array_lengthof(OPS)) \
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000249 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
250 Storage, Context.pImpl->CLASS##s)
251#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
252 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
253 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000254#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000255 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000256 Storage, Context.pImpl->CLASS##s)
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000257#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
258 return storeImpl(new (NUM_OPS) \
259 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
260 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000261
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000262DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000263 StorageType Storage, bool ShouldCreate) {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000264 auto *CountNode = ConstantAsMetadata::get(
265 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
266 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
267}
268
269DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
270 int64_t Lo, StorageType Storage,
271 bool ShouldCreate) {
272 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, Lo));
273 Metadata *Ops[] = { CountNode };
274 DEFINE_GETIMPL_STORE(DISubrange, (CountNode, Lo), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000275}
276
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000277DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000278 bool IsUnsigned, MDString *Name,
279 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000280 assert(isCanonical(Name) && "Expected canonical MDString");
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000281 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000282 Metadata *Ops[] = {Name};
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000283 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000284}
285
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000286DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000287 MDString *Name, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000288 uint32_t AlignInBits, unsigned Encoding,
Adrian Prantl55f42622018-08-14 19:35:34 +0000289 DIFlags Flags, StorageType Storage,
290 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000291 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000292 DEFINE_GETIMPL_LOOKUP(DIBasicType,
Adrian Prantl55f42622018-08-14 19:35:34 +0000293 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000294 Metadata *Ops[] = {nullptr, nullptr, Name};
Adrian Prantl55f42622018-08-14 19:35:34 +0000295 DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
296 Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000297}
298
Vedant Kumar6379a622018-07-06 17:32:39 +0000299Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
300 switch (getEncoding()) {
301 case dwarf::DW_ATE_signed:
302 case dwarf::DW_ATE_signed_char:
303 return Signedness::Signed;
304 case dwarf::DW_ATE_unsigned:
305 case dwarf::DW_ATE_unsigned_char:
306 return Signedness::Unsigned;
307 default:
308 return None;
309 }
310}
311
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000312DIDerivedType *DIDerivedType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000313 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000314 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000315 uint32_t AlignInBits, uint64_t OffsetInBits,
316 Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
317 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000318 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000319 DEFINE_GETIMPL_LOOKUP(DIDerivedType,
320 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000321 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
322 ExtraData));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000323 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
324 DEFINE_GETIMPL_STORE(
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000325 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
326 DWARFAddressSpace, Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000327}
328
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000329DICompositeType *DICompositeType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000330 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000331 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000332 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000333 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000334 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
335 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000336 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +0000337
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000338 // Keep this in sync with buildODRType.
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000339 DEFINE_GETIMPL_LOOKUP(
340 DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
341 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000342 VTableHolder, TemplateParams, Identifier, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000343 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000344 Elements, VTableHolder, TemplateParams, Identifier,
345 Discriminator};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000346 DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000347 AlignInBits, OffsetInBits, Flags),
348 Ops);
349}
350
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000351DICompositeType *DICompositeType::buildODRType(
352 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
353 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000354 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000355 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000356 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000357 assert(!Identifier.getString().empty() && "Expected valid identifier");
358 if (!Context.isODRUniquingDebugTypes())
359 return nullptr;
360 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
361 if (!CT)
362 return CT = DICompositeType::getDistinct(
363 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
364 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000365 VTableHolder, TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000366
367 // Only mutate CT if it's a forward declaration and the new operands aren't.
368 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
369 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
370 return CT;
371
372 // Mutate CT in place. Keep this in sync with getImpl.
373 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
374 Flags);
375 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000376 Elements, VTableHolder, TemplateParams, &Identifier,
377 Discriminator};
Simon Pilgrim1ec7dc72016-05-02 16:45:02 +0000378 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000379 "Mismatched number of operands");
380 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
381 if (Ops[I] != CT->getOperand(I))
382 CT->setOperand(I, Ops[I]);
383 return CT;
384}
385
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000386DICompositeType *DICompositeType::getODRType(
387 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
388 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000389 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000390 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000391 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000392 assert(!Identifier.getString().empty() && "Expected valid identifier");
393 if (!Context.isODRUniquingDebugTypes())
394 return nullptr;
395 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
396 if (!CT)
397 CT = DICompositeType::getDistinct(
398 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
399 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000400 TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000401 return CT;
402}
403
404DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
405 MDString &Identifier) {
406 assert(!Identifier.getString().empty() && "Expected valid identifier");
407 if (!Context.isODRUniquingDebugTypes())
408 return nullptr;
409 return Context.pImpl->DITypeMap->lookup(&Identifier);
410}
411
Leny Kholodov40c62352016-09-06 17:03:02 +0000412DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
413 uint8_t CC, Metadata *TypeArray,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000414 StorageType Storage,
415 bool ShouldCreate) {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000416 DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
Duncan P. N. Exon Smithb9e045a2015-07-24 20:56:36 +0000417 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000418 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000419}
420
Reid Kleckner26fa1bf2017-09-19 18:14:45 +0000421// FIXME: Implement this string-enum correspondence with a .def file and macros,
422// so that the association is explicit rather than implied.
Scott Linder71603842018-02-12 19:45:54 +0000423static const char *ChecksumKindName[DIFile::CSK_Last] = {
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000424 "CSK_MD5",
425 "CSK_SHA1"
426};
427
Scott Linder71603842018-02-12 19:45:54 +0000428StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
429 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
430 // The first space was originally the CSK_None variant, which is now
431 // obsolete, but the space is still reserved in ChecksumKind, so we account
432 // for it here.
433 return ChecksumKindName[CSKind - 1];
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000434}
435
Scott Linder71603842018-02-12 19:45:54 +0000436Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
437 return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
438 .Case("CSK_MD5", DIFile::CSK_MD5)
439 .Case("CSK_SHA1", DIFile::CSK_SHA1)
440 .Default(None);
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000441}
442
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000443DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
Scott Linder71603842018-02-12 19:45:54 +0000444 MDString *Directory,
445 Optional<DIFile::ChecksumInfo<MDString *>> CS,
Scott Linder16c7bda2018-02-23 23:01:06 +0000446 Optional<MDString *> Source, StorageType Storage,
447 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000448 assert(isCanonical(Filename) && "Expected canonical MDString");
449 assert(isCanonical(Directory) && "Expected canonical MDString");
Scott Linder71603842018-02-12 19:45:54 +0000450 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
Scott Linder16c7bda2018-02-23 23:01:06 +0000451 assert((!Source || isCanonical(*Source)) && "Expected canonical MDString");
452 DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source));
453 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
454 Source.getValueOr(nullptr)};
455 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000456}
457
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000458DICompileUnit *DICompileUnit::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000459 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
460 MDString *Producer, bool IsOptimized, MDString *Flags,
461 unsigned RuntimeVersion, MDString *SplitDebugFilename,
462 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Adrian Prantl75819ae2016-04-15 15:57:41 +0000463 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
Dehao Chen0944a8c2017-02-01 22:45:09 +0000464 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
David Blaikie66cf14d2018-08-16 21:29:55 +0000465 unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000466 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000467 assert(isCanonical(Producer) && "Expected canonical MDString");
468 assert(isCanonical(Flags) && "Expected canonical MDString");
469 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000470
Adrian Prantl75819ae2016-04-15 15:57:41 +0000471 Metadata *Ops[] = {
472 File, Producer, Flags, SplitDebugFilename,
473 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
474 Macros};
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000475 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
476 Context, Storage, SourceLanguage, IsOptimized,
477 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
David Blaikie66cf14d2018-08-16 21:29:55 +0000478 DebugInfoForProfiling, NameTableKind, Ops),
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000479 Storage);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000480}
481
Adrian Prantlb939a252016-03-31 23:56:58 +0000482Optional<DICompileUnit::DebugEmissionKind>
483DICompileUnit::getEmissionKind(StringRef Str) {
484 return StringSwitch<Optional<DebugEmissionKind>>(Str)
485 .Case("NoDebug", NoDebug)
486 .Case("FullDebug", FullDebug)
487 .Case("LineTablesOnly", LineTablesOnly)
Alexey Bataevd4dd7212018-08-01 19:38:20 +0000488 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
Adrian Prantlb939a252016-03-31 23:56:58 +0000489 .Default(None);
490}
491
David Blaikie66cf14d2018-08-16 21:29:55 +0000492Optional<DICompileUnit::DebugNameTableKind>
493DICompileUnit::getNameTableKind(StringRef Str) {
494 return StringSwitch<Optional<DebugNameTableKind>>(Str)
495 .Case("Default", DebugNameTableKind::Default)
496 .Case("GNU", DebugNameTableKind::GNU)
497 .Case("None", DebugNameTableKind::None)
498 .Default(None);
499}
500
Fangrui Song3c1b5db2018-07-06 19:26:00 +0000501const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
Adrian Prantlb939a252016-03-31 23:56:58 +0000502 switch (EK) {
503 case NoDebug: return "NoDebug";
504 case FullDebug: return "FullDebug";
505 case LineTablesOnly: return "LineTablesOnly";
Alexey Bataev075412d2018-08-23 17:43:40 +0000506 case DebugDirectivesOnly: return "DebugDirectivesOnly";
Adrian Prantlb939a252016-03-31 23:56:58 +0000507 }
508 return nullptr;
509}
510
David Blaikie66cf14d2018-08-16 21:29:55 +0000511const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
512 switch (NTK) {
513 case DebugNameTableKind::Default:
514 return nullptr;
515 case DebugNameTableKind::GNU:
516 return "GNU";
517 case DebugNameTableKind::None:
518 return "None";
519 }
520 return nullptr;
521}
522
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000523DISubprogram *DILocalScope::getSubprogram() const {
524 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000525 return Block->getScope()->getSubprogram();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000526 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000527}
528
Amjad Abouda5ba9912016-04-21 16:58:49 +0000529DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
530 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
531 return File->getScope()->getNonLexicalBlockFileScope();
532 return const_cast<DILocalScope *>(this);
533}
534
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000535DISubprogram *DISubprogram::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000536 LLVMContext &Context, Metadata *Scope, MDString *Name,
537 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
538 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
539 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000540 int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000541 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000542 Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000543 assert(isCanonical(Name) && "Expected canonical MDString");
544 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000545 DEFINE_GETIMPL_LOOKUP(
Adrian Prantl1d12b882017-04-26 22:56:44 +0000546 DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
547 IsDefinition, ScopeLine, ContainingType, Virtuality,
548 VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000549 TemplateParams, Declaration, RetainedNodes, ThrownTypes));
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000550 SmallVector<Metadata *, 11> Ops = {
Shiva Chen2c864552018-05-09 02:40:45 +0000551 File, Scope, Name, LinkageName, Type, Unit,
552 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000553 if (!ThrownTypes) {
554 Ops.pop_back();
555 if (!TemplateParams) {
556 Ops.pop_back();
557 if (!ContainingType)
558 Ops.pop_back();
559 }
560 }
561 DEFINE_GETIMPL_STORE_N(DISubprogram,
562 (Line, ScopeLine, Virtuality, VirtualIndex,
563 ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
564 IsOptimized),
565 Ops, Ops.size());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000566}
567
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000568bool DISubprogram::describes(const Function *F) const {
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000569 assert(F && "Invalid function");
Peter Collingbourned4bff302015-11-05 22:03:56 +0000570 if (F->getSubprogram() == this)
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000571 return true;
572 StringRef Name = getLinkageName();
573 if (Name.empty())
574 Name = getName();
575 return F->getName() == Name;
576}
577
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000578DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000579 Metadata *File, unsigned Line,
580 unsigned Column, StorageType Storage,
581 bool ShouldCreate) {
Duncan P. N. Exon Smithb09eb9f2015-08-28 22:58:50 +0000582 // Fixup column.
583 adjustColumn(Column);
584
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000585 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000586 DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000587 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000588 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000589}
590
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000591DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000592 Metadata *Scope, Metadata *File,
593 unsigned Discriminator,
594 StorageType Storage,
595 bool ShouldCreate) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000596 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000597 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000598 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000599 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000600}
601
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000602DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
Adrian Prantlfed4f392017-04-28 22:25:46 +0000603 MDString *Name, bool ExportSymbols,
604 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000605 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantlfed4f392017-04-28 22:25:46 +0000606 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
607 // The nullptr is for DIScope's File operand. This should be refactored.
608 Metadata *Ops[] = {nullptr, Scope, Name};
609 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000610}
611
Adrian Prantlab1243f2015-06-29 23:03:47 +0000612DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
613 MDString *Name, MDString *ConfigurationMacros,
614 MDString *IncludePath, MDString *ISysRoot,
615 StorageType Storage, bool ShouldCreate) {
616 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000617 DEFINE_GETIMPL_LOOKUP(
618 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
Adrian Prantlab1243f2015-06-29 23:03:47 +0000619 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
620 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
621}
622
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000623DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000624 MDString *Name,
625 Metadata *Type,
626 StorageType Storage,
627 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000628 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000629 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000630 Metadata *Ops[] = {Name, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000631 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000632}
633
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000634DITemplateValueParameter *DITemplateValueParameter::getImpl(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000635 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
636 Metadata *Value, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000637 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000638 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000639 Metadata *Ops[] = {Name, Type, Value};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000640 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000641}
642
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000643DIGlobalVariable *
644DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000645 MDString *LinkageName, Metadata *File, unsigned Line,
646 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000647 Metadata *StaticDataMemberDeclaration,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000648 uint32_t AlignInBits, StorageType Storage,
649 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000650 assert(isCanonical(Name) && "Expected canonical MDString");
651 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000652 DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000653 (Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000654 IsLocalToUnit, IsDefinition,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000655 StaticDataMemberDeclaration, AlignInBits));
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000656 Metadata *Ops[] = {
657 Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000658 DEFINE_GETIMPL_STORE(DIGlobalVariable,
659 (Line, IsLocalToUnit, IsDefinition, AlignInBits),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000660 Ops);
661}
662
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000663DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
664 MDString *Name, Metadata *File,
665 unsigned Line, Metadata *Type,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000666 unsigned Arg, DIFlags Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000667 uint32_t AlignInBits,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000668 StorageType Storage,
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000669 bool ShouldCreate) {
Duncan P. N. Exon Smith1ec75ae2015-04-28 01:07:33 +0000670 // 64K ought to be enough for any frontend.
671 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
Duncan P. N. Exon Smith72fe2d02015-02-13 01:39:44 +0000672
Duncan P. N. Exon Smithe2c61d92015-03-27 17:56:39 +0000673 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000674 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000675 DEFINE_GETIMPL_LOOKUP(DILocalVariable,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000676 (Scope, Name, File, Line, Type, Arg, Flags,
677 AlignInBits));
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000678 Metadata *Ops[] = {Scope, Name, File, Type};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000679 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000680}
681
Adrian Prantl3e0e1d02017-11-28 00:57:51 +0000682Optional<uint64_t> DIVariable::getSizeInBits() const {
683 // This is used by the Verifier so be mindful of broken types.
684 const Metadata *RawType = getRawType();
685 while (RawType) {
686 // Try to get the size directly.
687 if (auto *T = dyn_cast<DIType>(RawType))
688 if (uint64_t Size = T->getSizeInBits())
689 return Size;
690
691 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
692 // Look at the base type.
693 RawType = DT->getRawBaseType();
694 continue;
695 }
696
697 // Missing type or size.
698 break;
699 }
700
701 // Fail gracefully.
702 return None;
703}
704
Shiva Chen2c864552018-05-09 02:40:45 +0000705DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
706 MDString *Name, Metadata *File, unsigned Line,
707 StorageType Storage,
708 bool ShouldCreate) {
709 assert(Scope && "Expected scope");
710 assert(isCanonical(Name) && "Expected canonical MDString");
711 DEFINE_GETIMPL_LOOKUP(DILabel,
712 (Scope, Name, File, Line));
713 Metadata *Ops[] = {Scope, Name, File};
714 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
715}
716
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000717DIExpression *DIExpression::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000718 ArrayRef<uint64_t> Elements,
719 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000720 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
721 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000722}
723
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000724unsigned DIExpression::ExprOperand::getSize() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000725 switch (getOp()) {
Adrian Prantl941fa752016-12-05 18:04:47 +0000726 case dwarf::DW_OP_LLVM_fragment:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000727 return 3;
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000728 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000729 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000730 return 2;
731 default:
732 return 1;
733 }
734}
735
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000736bool DIExpression::isValid() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000737 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
738 // Check that there's space for the operand.
739 if (I->get() + I->getSize() > E->get())
740 return false;
741
742 // Check that the operand is valid.
743 switch (I->getOp()) {
744 default:
745 return false;
Adrian Prantl941fa752016-12-05 18:04:47 +0000746 case dwarf::DW_OP_LLVM_fragment:
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000747 // A fragment operator must appear at the end.
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000748 return I->get() + I->getSize() == E->get();
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000749 case dwarf::DW_OP_stack_value: {
750 // Must be the last one or followed by a DW_OP_LLVM_fragment.
751 if (I->get() + I->getSize() == E->get())
752 break;
753 auto J = I;
754 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
755 return false;
756 break;
757 }
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000758 case dwarf::DW_OP_swap: {
759 // Must be more than one implicit element on the stack.
760
761 // FIXME: A better way to implement this would be to add a local variable
762 // that keeps track of the stack depth and introduce something like a
763 // DW_LLVM_OP_implicit_location as a placeholder for the location this
764 // DIExpression is attached to, or else pass the number of implicit stack
765 // elements into isValid.
766 if (getNumElements() == 1)
767 return false;
768 break;
769 }
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000770 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000771 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000772 case dwarf::DW_OP_plus:
Evgeniy Stepanovf6081112015-09-30 19:55:43 +0000773 case dwarf::DW_OP_minus:
Strahinja Petrovic29202f62017-09-21 10:04:02 +0000774 case dwarf::DW_OP_mul:
Vedant Kumar4011c262018-02-13 01:09:52 +0000775 case dwarf::DW_OP_div:
776 case dwarf::DW_OP_mod:
Vedant Kumar04386d82018-02-09 19:19:55 +0000777 case dwarf::DW_OP_or:
Petar Jovanovic17689572018-02-14 13:10:35 +0000778 case dwarf::DW_OP_and:
Vedant Kumar96b7dc02018-02-13 01:09:46 +0000779 case dwarf::DW_OP_xor:
Vedant Kumar31ec3562018-02-13 01:09:49 +0000780 case dwarf::DW_OP_shl:
781 case dwarf::DW_OP_shr:
782 case dwarf::DW_OP_shra:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000783 case dwarf::DW_OP_deref:
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000784 case dwarf::DW_OP_xderef:
Vedant Kumar6379a622018-07-06 17:32:39 +0000785 case dwarf::DW_OP_lit0:
786 case dwarf::DW_OP_not:
787 case dwarf::DW_OP_dup:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000788 break;
789 }
790 }
791 return true;
792}
793
Adrian Prantl49797ca2016-12-22 05:27:12 +0000794Optional<DIExpression::FragmentInfo>
795DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
796 for (auto I = Start; I != End; ++I)
797 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
798 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
799 return Info;
800 }
801 return None;
Duncan P. N. Exon Smith86cc3322015-04-07 03:49:59 +0000802}
803
Andrew Ng03e35b62017-04-28 08:44:30 +0000804void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
805 int64_t Offset) {
806 if (Offset > 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000807 Ops.push_back(dwarf::DW_OP_plus_uconst);
Andrew Ng03e35b62017-04-28 08:44:30 +0000808 Ops.push_back(Offset);
809 } else if (Offset < 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000810 Ops.push_back(dwarf::DW_OP_constu);
Andrew Ng03e35b62017-04-28 08:44:30 +0000811 Ops.push_back(-Offset);
Florian Hahnffc498d2017-06-14 13:14:38 +0000812 Ops.push_back(dwarf::DW_OP_minus);
Andrew Ng03e35b62017-04-28 08:44:30 +0000813 }
814}
815
Reid Klecknerb5fced72017-05-09 19:59:29 +0000816bool DIExpression::extractIfOffset(int64_t &Offset) const {
817 if (getNumElements() == 0) {
818 Offset = 0;
819 return true;
820 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000821
822 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
Reid Klecknerb5fced72017-05-09 19:59:29 +0000823 Offset = Elements[1];
824 return true;
825 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000826
827 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
828 if (Elements[2] == dwarf::DW_OP_plus) {
829 Offset = Elements[1];
830 return true;
831 }
832 if (Elements[2] == dwarf::DW_OP_minus) {
833 Offset = -Elements[1];
834 return true;
835 }
Reid Klecknerb5fced72017-05-09 19:59:29 +0000836 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000837
Reid Klecknerb5fced72017-05-09 19:59:29 +0000838 return false;
839}
840
Adrian Prantld1317012017-12-08 21:58:18 +0000841DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
842 int64_t Offset, bool DerefAfter,
843 bool StackValue) {
Andrew Ng03e35b62017-04-28 08:44:30 +0000844 SmallVector<uint64_t, 8> Ops;
Adrian Prantld1317012017-12-08 21:58:18 +0000845 if (DerefBefore)
Andrew Ng03e35b62017-04-28 08:44:30 +0000846 Ops.push_back(dwarf::DW_OP_deref);
Bjorn Petterssonaa025802018-07-03 12:39:52 +0000847
Adrian Prantld1317012017-12-08 21:58:18 +0000848 appendOffset(Ops, Offset);
849 if (DerefAfter)
850 Ops.push_back(dwarf::DW_OP_deref);
851
Adrian Prantl210a29d2018-04-27 21:41:36 +0000852 return prependOpcodes(Expr, Ops, StackValue);
Vedant Kumar04386d82018-02-09 19:19:55 +0000853}
854
Adrian Prantl210a29d2018-04-27 21:41:36 +0000855DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
856 SmallVectorImpl<uint64_t> &Ops,
857 bool StackValue) {
Vedant Kumar8a368082018-07-06 21:06:20 +0000858 assert(Expr && "Can't prepend ops to this expression");
859
Bjorn Pettersson8dd6cf72018-07-03 11:29:00 +0000860 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
861 if (Ops.empty())
862 StackValue = false;
Vedant Kumar8a368082018-07-06 21:06:20 +0000863 for (auto Op : Expr->expr_ops()) {
864 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
865 if (StackValue) {
866 if (Op.getOp() == dwarf::DW_OP_stack_value)
867 StackValue = false;
868 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
869 Ops.push_back(dwarf::DW_OP_stack_value);
870 StackValue = false;
Andrew Ng03e35b62017-04-28 08:44:30 +0000871 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000872 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000873 Op.appendToVector(Ops);
Vedant Kumar8a368082018-07-06 21:06:20 +0000874 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000875 if (StackValue)
876 Ops.push_back(dwarf::DW_OP_stack_value);
Adrian Prantl109b2362017-04-28 17:51:05 +0000877 return DIExpression::get(Expr->getContext(), Ops);
Andrew Ng03e35b62017-04-28 08:44:30 +0000878}
879
Vedant Kumarb572f642018-07-26 20:56:53 +0000880DIExpression *DIExpression::append(const DIExpression *Expr,
881 ArrayRef<uint64_t> Ops) {
882 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
883
884 // Copy Expr's current op list.
885 SmallVector<uint64_t, 16> NewOps;
886 for (auto Op : Expr->expr_ops()) {
887 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
888 if (Op.getOp() == dwarf::DW_OP_stack_value ||
889 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
890 NewOps.append(Ops.begin(), Ops.end());
891
892 // Ensure that the new opcodes are only appended once.
893 Ops = None;
894 }
895 Op.appendToVector(NewOps);
896 }
897
898 NewOps.append(Ops.begin(), Ops.end());
899 return DIExpression::get(Expr->getContext(), NewOps);
900}
901
Vedant Kumar6379a622018-07-06 17:32:39 +0000902DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
903 ArrayRef<uint64_t> Ops) {
904 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
Vedant Kumarb572f642018-07-26 20:56:53 +0000905 assert(none_of(Ops,
906 [](uint64_t Op) {
907 return Op == dwarf::DW_OP_stack_value ||
908 Op == dwarf::DW_OP_LLVM_fragment;
909 }) &&
910 "Can't append this op");
Vedant Kumar6379a622018-07-06 17:32:39 +0000911
912 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
913 // has no DW_OP_stack_value.
914 //
915 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
916 Optional<FragmentInfo> FI = Expr->getFragmentInfo();
917 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
Vedant Kumarb572f642018-07-26 20:56:53 +0000918 ArrayRef<uint64_t> ExprOpsBeforeFragment =
919 Expr->getElements().drop_back(DropUntilStackValue);
920 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
921 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
922 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
Vedant Kumar6379a622018-07-06 17:32:39 +0000923
Vedant Kumarb572f642018-07-26 20:56:53 +0000924 // Append a DW_OP_deref after Expr's current op list if needed, then append
925 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
Vedant Kumar6379a622018-07-06 17:32:39 +0000926 SmallVector<uint64_t, 16> NewOps;
Vedant Kumar6379a622018-07-06 17:32:39 +0000927 if (NeedsDeref)
928 NewOps.push_back(dwarf::DW_OP_deref);
929 NewOps.append(Ops.begin(), Ops.end());
Vedant Kumarb572f642018-07-26 20:56:53 +0000930 if (NeedsStackValue)
931 NewOps.push_back(dwarf::DW_OP_stack_value);
932 return DIExpression::append(Expr, NewOps);
Vedant Kumar6379a622018-07-06 17:32:39 +0000933}
934
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000935Optional<DIExpression *> DIExpression::createFragmentExpression(
936 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
Adrian Prantlb192b542017-08-30 20:04:17 +0000937 SmallVector<uint64_t, 8> Ops;
938 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
939 if (Expr) {
940 for (auto Op : Expr->expr_ops()) {
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000941 switch (Op.getOp()) {
942 default: break;
943 case dwarf::DW_OP_plus:
944 case dwarf::DW_OP_minus:
945 // We can't safely split arithmetic into multiple fragments because we
946 // can't express carry-over between fragments.
947 //
948 // FIXME: We *could* preserve the lowest fragment of a constant offset
949 // operation if the offset fits into SizeInBits.
950 return None;
951 case dwarf::DW_OP_LLVM_fragment: {
Adrian Prantlb192b542017-08-30 20:04:17 +0000952 // Make the new offset point into the existing fragment.
953 uint64_t FragmentOffsetInBits = Op.getArg(0);
Bjorn Pettersson5479ad22018-05-03 17:04:21 +0000954 uint64_t FragmentSizeInBits = Op.getArg(1);
955 (void)FragmentSizeInBits;
956 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
Adrian Prantlb192b542017-08-30 20:04:17 +0000957 "new fragment outside of original fragment");
958 OffsetInBits += FragmentOffsetInBits;
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000959 continue;
960 }
Adrian Prantlb192b542017-08-30 20:04:17 +0000961 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000962 Op.appendToVector(Ops);
Adrian Prantlb192b542017-08-30 20:04:17 +0000963 }
964 }
965 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
966 Ops.push_back(OffsetInBits);
967 Ops.push_back(SizeInBits);
968 return DIExpression::get(Expr->getContext(), Ops);
969}
970
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000971bool DIExpression::isConstant() const {
972 // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
973 if (getNumElements() != 3 && getNumElements() != 6)
974 return false;
975 if (getElement(0) != dwarf::DW_OP_constu ||
976 getElement(2) != dwarf::DW_OP_stack_value)
977 return false;
978 if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
979 return false;
980 return true;
981}
982
983DIGlobalVariableExpression *
984DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
985 Metadata *Expression, StorageType Storage,
986 bool ShouldCreate) {
987 DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
988 Metadata *Ops[] = {Variable, Expression};
989 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
990}
991
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000992DIObjCProperty *DIObjCProperty::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000993 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
994 MDString *GetterName, MDString *SetterName, unsigned Attributes,
995 Metadata *Type, StorageType Storage, bool ShouldCreate) {
996 assert(isCanonical(Name) && "Expected canonical MDString");
997 assert(isCanonical(GetterName) && "Expected canonical MDString");
998 assert(isCanonical(SetterName) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000999 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
1000 SetterName, Attributes, Type));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001001 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001002 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001003}
1004
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001005DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001006 Metadata *Scope, Metadata *Entity,
Adrian Prantld63bfd22017-07-19 00:09:54 +00001007 Metadata *File, unsigned Line,
1008 MDString *Name, StorageType Storage,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001009 bool ShouldCreate) {
1010 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantld63bfd22017-07-19 00:09:54 +00001011 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
1012 (Tag, Scope, Entity, File, Line, Name));
1013 Metadata *Ops[] = {Scope, Entity, Name, File};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001014 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001015}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001016
1017DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
1018 unsigned Line, MDString *Name, MDString *Value,
1019 StorageType Storage, bool ShouldCreate) {
1020 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001021 DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
Amjad Abouda9bcf162015-12-10 12:56:35 +00001022 Metadata *Ops[] = { Name, Value };
1023 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
1024}
1025
1026DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
1027 unsigned Line, Metadata *File,
1028 Metadata *Elements, StorageType Storage,
1029 bool ShouldCreate) {
1030 DEFINE_GETIMPL_LOOKUP(DIMacroFile,
1031 (MIType, Line, File, Elements));
1032 Metadata *Ops[] = { File, Elements };
1033 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
1034}