blob: 33bf8edf08a8b4fa841463544aa0a8f24d6ff6d7 [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"
Vedant Kumar2b881f52017-11-06 23:15:21 +000017#include "llvm/ADT/SmallPtrSet.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,
72 const DILocation *LocB,
73 bool GenerateLocation) {
Vedant Kumar2b881f52017-11-06 23:15:21 +000074 if (!LocA || !LocB)
75 return nullptr;
76
77 if (LocA == LocB || !LocA->canDiscriminate(*LocB))
78 return LocA;
79
Vedant Kumar65b0d4d2018-04-12 20:58:24 +000080 if (!GenerateLocation)
Vedant Kumar2b881f52017-11-06 23:15:21 +000081 return nullptr;
82
83 SmallPtrSet<DILocation *, 5> InlinedLocationsA;
84 for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
85 InlinedLocationsA.insert(L);
86 const DILocation *Result = LocB;
87 for (DILocation *L = LocB->getInlinedAt(); L; L = L->getInlinedAt()) {
88 Result = L;
89 if (InlinedLocationsA.count(L))
90 break;
91 }
92 return DILocation::get(Result->getContext(), 0, 0, Result->getScope(),
93 Result->getInlinedAt());
94}
95
Leny Kholodov5fcc4182016-09-06 10:46:28 +000096DINode::DIFlags DINode::getFlag(StringRef Flag) {
97 return StringSwitch<DIFlags>(Flag)
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +000098#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
99#include "llvm/IR/DebugInfoFlags.def"
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000100 .Default(DINode::FlagZero);
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000101}
102
Mehdi Aminif42ec792016-10-01 05:57:50 +0000103StringRef DINode::getFlagString(DIFlags Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000104 switch (Flag) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000105#define HANDLE_DI_FLAG(ID, NAME) \
106 case Flag##NAME: \
107 return "DIFlag" #NAME;
108#include "llvm/IR/DebugInfoFlags.def"
109 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000110 return "";
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000111}
112
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000113DINode::DIFlags DINode::splitFlags(DIFlags Flags,
Leny Kholodov40c62352016-09-06 17:03:02 +0000114 SmallVectorImpl<DIFlags> &SplitFlags) {
Bob Haarman26a87bd2016-10-25 22:11:52 +0000115 // Flags that are packed together need to be specially handled, so
116 // that, for example, we emit "DIFlagPublic" and not
117 // "DIFlagPrivate | DIFlagProtected".
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000118 if (DIFlags A = Flags & FlagAccessibility) {
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000119 if (A == FlagPrivate)
120 SplitFlags.push_back(FlagPrivate);
121 else if (A == FlagProtected)
122 SplitFlags.push_back(FlagProtected);
123 else
124 SplitFlags.push_back(FlagPublic);
125 Flags &= ~A;
126 }
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000127 if (DIFlags R = Flags & FlagPtrToMemberRep) {
Reid Kleckner604105b2016-06-17 21:31:33 +0000128 if (R == FlagSingleInheritance)
129 SplitFlags.push_back(FlagSingleInheritance);
130 else if (R == FlagMultipleInheritance)
131 SplitFlags.push_back(FlagMultipleInheritance);
132 else
133 SplitFlags.push_back(FlagVirtualInheritance);
134 Flags &= ~R;
135 }
Bob Haarman26a87bd2016-10-25 22:11:52 +0000136 if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
137 Flags &= ~FlagIndirectVirtualBase;
138 SplitFlags.push_back(FlagIndirectVirtualBase);
139 }
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000140
141#define HANDLE_DI_FLAG(ID, NAME) \
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000142 if (DIFlags Bit = Flags & Flag##NAME) { \
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000143 SplitFlags.push_back(Bit); \
144 Flags &= ~Bit; \
145 }
146#include "llvm/IR/DebugInfoFlags.def"
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000147 return Flags;
148}
149
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000150DIScopeRef DIScope::getScope() const {
151 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000152 return T->getScope();
153
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000154 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000155 return SP->getScope();
156
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000157 if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000158 return LB->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000159
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000160 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000161 return NS->getScope();
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000162
Adrian Prantlab1243f2015-06-29 23:03:47 +0000163 if (auto *M = dyn_cast<DIModule>(this))
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000164 return M->getScope();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000165
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000166 assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000167 "Unhandled type of scope.");
168 return nullptr;
169}
170
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000171StringRef DIScope::getName() const {
172 if (auto *T = dyn_cast<DIType>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000173 return T->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000174 if (auto *SP = dyn_cast<DISubprogram>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000175 return SP->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000176 if (auto *NS = dyn_cast<DINamespace>(this))
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000177 return NS->getName();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000178 if (auto *M = dyn_cast<DIModule>(this))
179 return M->getName();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000180 assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
181 isa<DICompileUnit>(this)) &&
Duncan P. N. Exon Smithf0d81a52015-04-11 17:37:23 +0000182 "Unhandled type of scope.");
183 return "";
184}
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +0000185
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000186#ifndef NDEBUG
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000187static bool isCanonical(const MDString *S) {
188 return !S || !S->getString().empty();
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000189}
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000190#endif
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000191
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000192GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
193 MDString *Header,
194 ArrayRef<Metadata *> DwarfOps,
195 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000196 unsigned Hash = 0;
197 if (Storage == Uniqued) {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000198 GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000199 if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000200 return N;
201 if (!ShouldCreate)
202 return nullptr;
203 Hash = Key.getHash();
204 } else {
205 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
206 }
207
208 // Use a nullptr for empty headers.
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000209 assert(isCanonical(Header) && "Expected canonical MDString");
210 Metadata *PreOps[] = {Header};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000211 return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000212 Context, Storage, Hash, Tag, PreOps, DwarfOps),
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000213 Storage, Context.pImpl->GenericDINodes);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000214}
215
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000216void GenericDINode::recalculateHash() {
217 setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000218}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000219
220#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
221#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
222#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
223 do { \
224 if (Storage == Uniqued) { \
225 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
226 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
227 return N; \
228 if (!ShouldCreate) \
229 return nullptr; \
230 } else { \
231 assert(ShouldCreate && \
232 "Expected non-uniqued nodes to always be created"); \
233 } \
234 } while (false)
235#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000236 return storeImpl(new (array_lengthof(OPS)) \
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000237 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
238 Storage, Context.pImpl->CLASS##s)
239#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
240 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
241 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000242#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
David Blaikie6662d6a2016-04-13 17:42:56 +0000243 return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS), \
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000244 Storage, Context.pImpl->CLASS##s)
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000245#define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS) \
246 return storeImpl(new (NUM_OPS) \
247 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
248 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000249
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000250DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000251 StorageType Storage, bool ShouldCreate) {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000252 auto *CountNode = ConstantAsMetadata::get(
253 ConstantInt::getSigned(Type::getInt64Ty(Context), Count));
254 return getImpl(Context, CountNode, Lo, Storage, ShouldCreate);
255}
256
257DISubrange *DISubrange::getImpl(LLVMContext &Context, Metadata *CountNode,
258 int64_t Lo, StorageType Storage,
259 bool ShouldCreate) {
260 DEFINE_GETIMPL_LOOKUP(DISubrange, (CountNode, Lo));
261 Metadata *Ops[] = { CountNode };
262 DEFINE_GETIMPL_STORE(DISubrange, (CountNode, Lo), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000263}
264
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000265DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000266 bool IsUnsigned, MDString *Name,
267 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000268 assert(isCanonical(Name) && "Expected canonical MDString");
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000269 DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, IsUnsigned, Name));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000270 Metadata *Ops[] = {Name};
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000271 DEFINE_GETIMPL_STORE(DIEnumerator, (Value, IsUnsigned), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000272}
273
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000274DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000275 MDString *Name, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000276 uint32_t AlignInBits, unsigned Encoding,
Adrian Prantl55f42622018-08-14 19:35:34 +0000277 DIFlags Flags, StorageType Storage,
278 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000279 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000280 DEFINE_GETIMPL_LOOKUP(DIBasicType,
Adrian Prantl55f42622018-08-14 19:35:34 +0000281 (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000282 Metadata *Ops[] = {nullptr, nullptr, Name};
Adrian Prantl55f42622018-08-14 19:35:34 +0000283 DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding,
284 Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000285}
286
Vedant Kumar6379a622018-07-06 17:32:39 +0000287Optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
288 switch (getEncoding()) {
289 case dwarf::DW_ATE_signed:
290 case dwarf::DW_ATE_signed_char:
291 return Signedness::Signed;
292 case dwarf::DW_ATE_unsigned:
293 case dwarf::DW_ATE_unsigned_char:
294 return Signedness::Unsigned;
295 default:
296 return None;
297 }
298}
299
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000300DIDerivedType *DIDerivedType::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000301 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000302 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000303 uint32_t AlignInBits, uint64_t OffsetInBits,
304 Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
305 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000306 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000307 DEFINE_GETIMPL_LOOKUP(DIDerivedType,
308 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000309 AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
310 ExtraData));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000311 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
312 DEFINE_GETIMPL_STORE(
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000313 DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
314 DWARFAddressSpace, Flags), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000315}
316
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000317DICompositeType *DICompositeType::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,
Victor Leschuk197aa312016-10-18 14:31:22 +0000320 uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000321 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000322 Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
323 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000324 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +0000325
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000326 // Keep this in sync with buildODRType.
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000327 DEFINE_GETIMPL_LOOKUP(
328 DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
329 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000330 VTableHolder, TemplateParams, Identifier, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000331 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000332 Elements, VTableHolder, TemplateParams, Identifier,
333 Discriminator};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334 DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000335 AlignInBits, OffsetInBits, Flags),
336 Ops);
337}
338
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000339DICompositeType *DICompositeType::buildODRType(
340 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
341 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000342 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000343 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000344 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000345 assert(!Identifier.getString().empty() && "Expected valid identifier");
346 if (!Context.isODRUniquingDebugTypes())
347 return nullptr;
348 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
349 if (!CT)
350 return CT = DICompositeType::getDistinct(
351 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
352 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000353 VTableHolder, TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000354
355 // Only mutate CT if it's a forward declaration and the new operands aren't.
356 assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
357 if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
358 return CT;
359
360 // Mutate CT in place. Keep this in sync with getImpl.
361 CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
362 Flags);
363 Metadata *Ops[] = {File, Scope, Name, BaseType,
Adrian Prantl8c599212018-02-06 23:45:59 +0000364 Elements, VTableHolder, TemplateParams, &Identifier,
365 Discriminator};
Simon Pilgrim1ec7dc72016-05-02 16:45:02 +0000366 assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
Duncan P. N. Exon Smith97386022016-04-19 18:00:19 +0000367 "Mismatched number of operands");
368 for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
369 if (Ops[I] != CT->getOperand(I))
370 CT->setOperand(I, Ops[I]);
371 return CT;
372}
373
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000374DICompositeType *DICompositeType::getODRType(
375 LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
376 Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
Victor Leschuk197aa312016-10-18 14:31:22 +0000377 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000378 DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
Adrian Prantl8c599212018-02-06 23:45:59 +0000379 Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator) {
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000380 assert(!Identifier.getString().empty() && "Expected valid identifier");
381 if (!Context.isODRUniquingDebugTypes())
382 return nullptr;
383 auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
384 if (!CT)
385 CT = DICompositeType::getDistinct(
386 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
387 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
Adrian Prantl8c599212018-02-06 23:45:59 +0000388 TemplateParams, &Identifier, Discriminator);
Duncan P. N. Exon Smith0b0271e2016-04-19 14:55:09 +0000389 return CT;
390}
391
392DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
393 MDString &Identifier) {
394 assert(!Identifier.getString().empty() && "Expected valid identifier");
395 if (!Context.isODRUniquingDebugTypes())
396 return nullptr;
397 return Context.pImpl->DITypeMap->lookup(&Identifier);
398}
399
Leny Kholodov40c62352016-09-06 17:03:02 +0000400DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
401 uint8_t CC, Metadata *TypeArray,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000402 StorageType Storage,
403 bool ShouldCreate) {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000404 DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
Duncan P. N. Exon Smithb9e045a2015-07-24 20:56:36 +0000405 Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000406 DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000407}
408
Reid Kleckner26fa1bf2017-09-19 18:14:45 +0000409// FIXME: Implement this string-enum correspondence with a .def file and macros,
410// so that the association is explicit rather than implied.
Scott Linder71603842018-02-12 19:45:54 +0000411static const char *ChecksumKindName[DIFile::CSK_Last] = {
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000412 "CSK_MD5",
413 "CSK_SHA1"
414};
415
Scott Linder71603842018-02-12 19:45:54 +0000416StringRef DIFile::getChecksumKindAsString(ChecksumKind CSKind) {
417 assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
418 // The first space was originally the CSK_None variant, which is now
419 // obsolete, but the space is still reserved in ChecksumKind, so we account
420 // for it here.
421 return ChecksumKindName[CSKind - 1];
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000422}
423
Scott Linder71603842018-02-12 19:45:54 +0000424Optional<DIFile::ChecksumKind> DIFile::getChecksumKind(StringRef CSKindStr) {
425 return StringSwitch<Optional<DIFile::ChecksumKind>>(CSKindStr)
426 .Case("CSK_MD5", DIFile::CSK_MD5)
427 .Case("CSK_SHA1", DIFile::CSK_SHA1)
428 .Default(None);
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000429}
430
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000431DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
Scott Linder71603842018-02-12 19:45:54 +0000432 MDString *Directory,
433 Optional<DIFile::ChecksumInfo<MDString *>> CS,
Scott Linder16c7bda2018-02-23 23:01:06 +0000434 Optional<MDString *> Source, StorageType Storage,
435 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000436 assert(isCanonical(Filename) && "Expected canonical MDString");
437 assert(isCanonical(Directory) && "Expected canonical MDString");
Scott Linder71603842018-02-12 19:45:54 +0000438 assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString");
Scott Linder16c7bda2018-02-23 23:01:06 +0000439 assert((!Source || isCanonical(*Source)) && "Expected canonical MDString");
440 DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source));
441 Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr,
442 Source.getValueOr(nullptr)};
443 DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000444}
445
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000446DICompileUnit *DICompileUnit::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000447 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
448 MDString *Producer, bool IsOptimized, MDString *Flags,
449 unsigned RuntimeVersion, MDString *SplitDebugFilename,
450 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Adrian Prantl75819ae2016-04-15 15:57:41 +0000451 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
Dehao Chen0944a8c2017-02-01 22:45:09 +0000452 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
David Blaikie66cf14d2018-08-16 21:29:55 +0000453 unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000454 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000455 assert(isCanonical(Producer) && "Expected canonical MDString");
456 assert(isCanonical(Flags) && "Expected canonical MDString");
457 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000458
Adrian Prantl75819ae2016-04-15 15:57:41 +0000459 Metadata *Ops[] = {
460 File, Producer, Flags, SplitDebugFilename,
461 EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
462 Macros};
Peter Collingbourneb52e2362017-09-12 21:50:41 +0000463 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
464 Context, Storage, SourceLanguage, IsOptimized,
465 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
David Blaikie66cf14d2018-08-16 21:29:55 +0000466 DebugInfoForProfiling, NameTableKind, Ops),
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000467 Storage);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000468}
469
Adrian Prantlb939a252016-03-31 23:56:58 +0000470Optional<DICompileUnit::DebugEmissionKind>
471DICompileUnit::getEmissionKind(StringRef Str) {
472 return StringSwitch<Optional<DebugEmissionKind>>(Str)
473 .Case("NoDebug", NoDebug)
474 .Case("FullDebug", FullDebug)
475 .Case("LineTablesOnly", LineTablesOnly)
Alexey Bataevd4dd7212018-08-01 19:38:20 +0000476 .Case("DebugDirectivesOnly", DebugDirectivesOnly)
Adrian Prantlb939a252016-03-31 23:56:58 +0000477 .Default(None);
478}
479
David Blaikie66cf14d2018-08-16 21:29:55 +0000480Optional<DICompileUnit::DebugNameTableKind>
481DICompileUnit::getNameTableKind(StringRef Str) {
482 return StringSwitch<Optional<DebugNameTableKind>>(Str)
483 .Case("Default", DebugNameTableKind::Default)
484 .Case("GNU", DebugNameTableKind::GNU)
485 .Case("None", DebugNameTableKind::None)
486 .Default(None);
487}
488
Fangrui Song3c1b5db2018-07-06 19:26:00 +0000489const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
Adrian Prantlb939a252016-03-31 23:56:58 +0000490 switch (EK) {
491 case NoDebug: return "NoDebug";
492 case FullDebug: return "FullDebug";
493 case LineTablesOnly: return "LineTablesOnly";
Alexey Bataev075412d2018-08-23 17:43:40 +0000494 case DebugDirectivesOnly: return "DebugDirectivesOnly";
Adrian Prantlb939a252016-03-31 23:56:58 +0000495 }
496 return nullptr;
497}
498
David Blaikie66cf14d2018-08-16 21:29:55 +0000499const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
500 switch (NTK) {
501 case DebugNameTableKind::Default:
502 return nullptr;
503 case DebugNameTableKind::GNU:
504 return "GNU";
505 case DebugNameTableKind::None:
506 return "None";
507 }
508 return nullptr;
509}
510
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000511DISubprogram *DILocalScope::getSubprogram() const {
512 if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000513 return Block->getScope()->getSubprogram();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000514 return const_cast<DISubprogram *>(cast<DISubprogram>(this));
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000515}
516
Amjad Abouda5ba9912016-04-21 16:58:49 +0000517DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
518 if (auto *File = dyn_cast<DILexicalBlockFile>(this))
519 return File->getScope()->getNonLexicalBlockFileScope();
520 return const_cast<DILocalScope *>(this);
521}
522
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000523DISubprogram *DISubprogram::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000524 LLVMContext &Context, Metadata *Scope, MDString *Name,
525 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
526 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
527 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000528 int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000529 Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000530 Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000531 assert(isCanonical(Name) && "Expected canonical MDString");
532 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000533 DEFINE_GETIMPL_LOOKUP(
Adrian Prantl1d12b882017-04-26 22:56:44 +0000534 DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
535 IsDefinition, ScopeLine, ContainingType, Virtuality,
536 VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
Shiva Chen2c864552018-05-09 02:40:45 +0000537 TemplateParams, Declaration, RetainedNodes, ThrownTypes));
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000538 SmallVector<Metadata *, 11> Ops = {
Shiva Chen2c864552018-05-09 02:40:45 +0000539 File, Scope, Name, LinkageName, Type, Unit,
540 Declaration, RetainedNodes, ContainingType, TemplateParams, ThrownTypes};
Adrian Prantl9d2f0192017-04-26 23:59:52 +0000541 if (!ThrownTypes) {
542 Ops.pop_back();
543 if (!TemplateParams) {
544 Ops.pop_back();
545 if (!ContainingType)
546 Ops.pop_back();
547 }
548 }
549 DEFINE_GETIMPL_STORE_N(DISubprogram,
550 (Line, ScopeLine, Virtuality, VirtualIndex,
551 ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
552 IsOptimized),
553 Ops, Ops.size());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000554}
555
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000556bool DISubprogram::describes(const Function *F) const {
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000557 assert(F && "Invalid function");
Peter Collingbourned4bff302015-11-05 22:03:56 +0000558 if (F->getSubprogram() == this)
Duncan P. N. Exon Smith3c2d7042015-04-13 19:07:27 +0000559 return true;
560 StringRef Name = getLinkageName();
561 if (Name.empty())
562 Name = getName();
563 return F->getName() == Name;
564}
565
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000566DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000567 Metadata *File, unsigned Line,
568 unsigned Column, StorageType Storage,
569 bool ShouldCreate) {
Duncan P. N. Exon Smithb09eb9f2015-08-28 22:58:50 +0000570 // Fixup column.
571 adjustColumn(Column);
572
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000573 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000574 DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000575 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000576 DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000577}
578
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000579DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000580 Metadata *Scope, Metadata *File,
581 unsigned Discriminator,
582 StorageType Storage,
583 bool ShouldCreate) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000584 assert(Scope && "Expected scope");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000585 DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000586 Metadata *Ops[] = {File, Scope};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000587 DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000588}
589
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000590DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
Adrian Prantlfed4f392017-04-28 22:25:46 +0000591 MDString *Name, bool ExportSymbols,
592 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000593 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantlfed4f392017-04-28 22:25:46 +0000594 DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
595 // The nullptr is for DIScope's File operand. This should be refactored.
596 Metadata *Ops[] = {nullptr, Scope, Name};
597 DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000598}
599
Adrian Prantlab1243f2015-06-29 23:03:47 +0000600DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
601 MDString *Name, MDString *ConfigurationMacros,
602 MDString *IncludePath, MDString *ISysRoot,
603 StorageType Storage, bool ShouldCreate) {
604 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000605 DEFINE_GETIMPL_LOOKUP(
606 DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
Adrian Prantlab1243f2015-06-29 23:03:47 +0000607 Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
608 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
609}
610
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000611DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000612 MDString *Name,
613 Metadata *Type,
614 StorageType Storage,
615 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000616 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000617 DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000618 Metadata *Ops[] = {Name, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000619 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000620}
621
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000622DITemplateValueParameter *DITemplateValueParameter::getImpl(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000623 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
624 Metadata *Value, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000625 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000626 DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000627 Metadata *Ops[] = {Name, Type, Value};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000628 DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000629}
630
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000631DIGlobalVariable *
632DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000633 MDString *LinkageName, Metadata *File, unsigned Line,
634 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000635 Metadata *StaticDataMemberDeclaration,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000636 uint32_t AlignInBits, StorageType Storage,
637 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000638 assert(isCanonical(Name) && "Expected canonical MDString");
639 assert(isCanonical(LinkageName) && "Expected canonical MDString");
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000640 DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000641 (Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000642 IsLocalToUnit, IsDefinition,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000643 StaticDataMemberDeclaration, AlignInBits));
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000644 Metadata *Ops[] = {
645 Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000646 DEFINE_GETIMPL_STORE(DIGlobalVariable,
647 (Line, IsLocalToUnit, IsDefinition, AlignInBits),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000648 Ops);
649}
650
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000651DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
652 MDString *Name, Metadata *File,
653 unsigned Line, Metadata *Type,
Leny Kholodov5fcc4182016-09-06 10:46:28 +0000654 unsigned Arg, DIFlags Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000655 uint32_t AlignInBits,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000656 StorageType Storage,
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000657 bool ShouldCreate) {
Duncan P. N. Exon Smith1ec75ae2015-04-28 01:07:33 +0000658 // 64K ought to be enough for any frontend.
659 assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
Duncan P. N. Exon Smith72fe2d02015-02-13 01:39:44 +0000660
Duncan P. N. Exon Smithe2c61d92015-03-27 17:56:39 +0000661 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000662 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000663 DEFINE_GETIMPL_LOOKUP(DILocalVariable,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000664 (Scope, Name, File, Line, Type, Arg, Flags,
665 AlignInBits));
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000666 Metadata *Ops[] = {Scope, Name, File, Type};
Victor Leschuk2ede1262016-10-20 00:13:12 +0000667 DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000668}
669
Adrian Prantl3e0e1d02017-11-28 00:57:51 +0000670Optional<uint64_t> DIVariable::getSizeInBits() const {
671 // This is used by the Verifier so be mindful of broken types.
672 const Metadata *RawType = getRawType();
673 while (RawType) {
674 // Try to get the size directly.
675 if (auto *T = dyn_cast<DIType>(RawType))
676 if (uint64_t Size = T->getSizeInBits())
677 return Size;
678
679 if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
680 // Look at the base type.
681 RawType = DT->getRawBaseType();
682 continue;
683 }
684
685 // Missing type or size.
686 break;
687 }
688
689 // Fail gracefully.
690 return None;
691}
692
Shiva Chen2c864552018-05-09 02:40:45 +0000693DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope,
694 MDString *Name, Metadata *File, unsigned Line,
695 StorageType Storage,
696 bool ShouldCreate) {
697 assert(Scope && "Expected scope");
698 assert(isCanonical(Name) && "Expected canonical MDString");
699 DEFINE_GETIMPL_LOOKUP(DILabel,
700 (Scope, Name, File, Line));
701 Metadata *Ops[] = {Scope, Name, File};
702 DEFINE_GETIMPL_STORE(DILabel, (Line), Ops);
703}
704
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000705DIExpression *DIExpression::getImpl(LLVMContext &Context,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000706 ArrayRef<uint64_t> Elements,
707 StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000708 DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
709 DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000710}
711
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000712unsigned DIExpression::ExprOperand::getSize() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000713 switch (getOp()) {
Adrian Prantl941fa752016-12-05 18:04:47 +0000714 case dwarf::DW_OP_LLVM_fragment:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000715 return 3;
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000716 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000717 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000718 return 2;
719 default:
720 return 1;
721 }
722}
723
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000724bool DIExpression::isValid() const {
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000725 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
726 // Check that there's space for the operand.
727 if (I->get() + I->getSize() > E->get())
728 return false;
729
730 // Check that the operand is valid.
731 switch (I->getOp()) {
732 default:
733 return false;
Adrian Prantl941fa752016-12-05 18:04:47 +0000734 case dwarf::DW_OP_LLVM_fragment:
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000735 // A fragment operator must appear at the end.
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000736 return I->get() + I->getSize() == E->get();
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000737 case dwarf::DW_OP_stack_value: {
738 // Must be the last one or followed by a DW_OP_LLVM_fragment.
739 if (I->get() + I->getSize() == E->get())
740 break;
741 auto J = I;
742 if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
743 return false;
744 break;
745 }
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000746 case dwarf::DW_OP_swap: {
747 // Must be more than one implicit element on the stack.
748
749 // FIXME: A better way to implement this would be to add a local variable
750 // that keeps track of the stack depth and introduce something like a
751 // DW_LLVM_OP_implicit_location as a placeholder for the location this
752 // DIExpression is attached to, or else pass the number of implicit stack
753 // elements into isValid.
754 if (getNumElements() == 1)
755 return false;
756 break;
757 }
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000758 case dwarf::DW_OP_constu:
Florian Hahnc9c403c2017-06-13 16:54:44 +0000759 case dwarf::DW_OP_plus_uconst:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000760 case dwarf::DW_OP_plus:
Evgeniy Stepanovf6081112015-09-30 19:55:43 +0000761 case dwarf::DW_OP_minus:
Strahinja Petrovic29202f62017-09-21 10:04:02 +0000762 case dwarf::DW_OP_mul:
Vedant Kumar4011c262018-02-13 01:09:52 +0000763 case dwarf::DW_OP_div:
764 case dwarf::DW_OP_mod:
Vedant Kumar04386d82018-02-09 19:19:55 +0000765 case dwarf::DW_OP_or:
Petar Jovanovic17689572018-02-14 13:10:35 +0000766 case dwarf::DW_OP_and:
Vedant Kumar96b7dc02018-02-13 01:09:46 +0000767 case dwarf::DW_OP_xor:
Vedant Kumar31ec3562018-02-13 01:09:49 +0000768 case dwarf::DW_OP_shl:
769 case dwarf::DW_OP_shr:
770 case dwarf::DW_OP_shra:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000771 case dwarf::DW_OP_deref:
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +0000772 case dwarf::DW_OP_xderef:
Vedant Kumar6379a622018-07-06 17:32:39 +0000773 case dwarf::DW_OP_lit0:
774 case dwarf::DW_OP_not:
775 case dwarf::DW_OP_dup:
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000776 break;
777 }
778 }
779 return true;
780}
781
Adrian Prantl49797ca2016-12-22 05:27:12 +0000782Optional<DIExpression::FragmentInfo>
783DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
784 for (auto I = Start; I != End; ++I)
785 if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
786 DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
787 return Info;
788 }
789 return None;
Duncan P. N. Exon Smith86cc3322015-04-07 03:49:59 +0000790}
791
Andrew Ng03e35b62017-04-28 08:44:30 +0000792void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
793 int64_t Offset) {
794 if (Offset > 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000795 Ops.push_back(dwarf::DW_OP_plus_uconst);
Andrew Ng03e35b62017-04-28 08:44:30 +0000796 Ops.push_back(Offset);
797 } else if (Offset < 0) {
Florian Hahnffc498d2017-06-14 13:14:38 +0000798 Ops.push_back(dwarf::DW_OP_constu);
Andrew Ng03e35b62017-04-28 08:44:30 +0000799 Ops.push_back(-Offset);
Florian Hahnffc498d2017-06-14 13:14:38 +0000800 Ops.push_back(dwarf::DW_OP_minus);
Andrew Ng03e35b62017-04-28 08:44:30 +0000801 }
802}
803
Reid Klecknerb5fced72017-05-09 19:59:29 +0000804bool DIExpression::extractIfOffset(int64_t &Offset) const {
805 if (getNumElements() == 0) {
806 Offset = 0;
807 return true;
808 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000809
810 if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
Reid Klecknerb5fced72017-05-09 19:59:29 +0000811 Offset = Elements[1];
812 return true;
813 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000814
815 if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
816 if (Elements[2] == dwarf::DW_OP_plus) {
817 Offset = Elements[1];
818 return true;
819 }
820 if (Elements[2] == dwarf::DW_OP_minus) {
821 Offset = -Elements[1];
822 return true;
823 }
Reid Klecknerb5fced72017-05-09 19:59:29 +0000824 }
Florian Hahnffc498d2017-06-14 13:14:38 +0000825
Reid Klecknerb5fced72017-05-09 19:59:29 +0000826 return false;
827}
828
Adrian Prantld1317012017-12-08 21:58:18 +0000829DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
830 int64_t Offset, bool DerefAfter,
831 bool StackValue) {
Andrew Ng03e35b62017-04-28 08:44:30 +0000832 SmallVector<uint64_t, 8> Ops;
Adrian Prantld1317012017-12-08 21:58:18 +0000833 if (DerefBefore)
Andrew Ng03e35b62017-04-28 08:44:30 +0000834 Ops.push_back(dwarf::DW_OP_deref);
Bjorn Petterssonaa025802018-07-03 12:39:52 +0000835
Adrian Prantld1317012017-12-08 21:58:18 +0000836 appendOffset(Ops, Offset);
837 if (DerefAfter)
838 Ops.push_back(dwarf::DW_OP_deref);
839
Adrian Prantl210a29d2018-04-27 21:41:36 +0000840 return prependOpcodes(Expr, Ops, StackValue);
Vedant Kumar04386d82018-02-09 19:19:55 +0000841}
842
Adrian Prantl210a29d2018-04-27 21:41:36 +0000843DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
844 SmallVectorImpl<uint64_t> &Ops,
845 bool StackValue) {
Vedant Kumar8a368082018-07-06 21:06:20 +0000846 assert(Expr && "Can't prepend ops to this expression");
847
Bjorn Pettersson8dd6cf72018-07-03 11:29:00 +0000848 // If there are no ops to prepend, do not even add the DW_OP_stack_value.
849 if (Ops.empty())
850 StackValue = false;
Vedant Kumar8a368082018-07-06 21:06:20 +0000851 for (auto Op : Expr->expr_ops()) {
852 // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
853 if (StackValue) {
854 if (Op.getOp() == dwarf::DW_OP_stack_value)
855 StackValue = false;
856 else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
857 Ops.push_back(dwarf::DW_OP_stack_value);
858 StackValue = false;
Andrew Ng03e35b62017-04-28 08:44:30 +0000859 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000860 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000861 Op.appendToVector(Ops);
Vedant Kumar8a368082018-07-06 21:06:20 +0000862 }
Andrew Ng03e35b62017-04-28 08:44:30 +0000863 if (StackValue)
864 Ops.push_back(dwarf::DW_OP_stack_value);
Adrian Prantl109b2362017-04-28 17:51:05 +0000865 return DIExpression::get(Expr->getContext(), Ops);
Andrew Ng03e35b62017-04-28 08:44:30 +0000866}
867
Vedant Kumarb572f642018-07-26 20:56:53 +0000868DIExpression *DIExpression::append(const DIExpression *Expr,
869 ArrayRef<uint64_t> Ops) {
870 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
871
872 // Copy Expr's current op list.
873 SmallVector<uint64_t, 16> NewOps;
874 for (auto Op : Expr->expr_ops()) {
875 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
876 if (Op.getOp() == dwarf::DW_OP_stack_value ||
877 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
878 NewOps.append(Ops.begin(), Ops.end());
879
880 // Ensure that the new opcodes are only appended once.
881 Ops = None;
882 }
883 Op.appendToVector(NewOps);
884 }
885
886 NewOps.append(Ops.begin(), Ops.end());
887 return DIExpression::get(Expr->getContext(), NewOps);
888}
889
Vedant Kumar6379a622018-07-06 17:32:39 +0000890DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
891 ArrayRef<uint64_t> Ops) {
892 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
Vedant Kumarb572f642018-07-26 20:56:53 +0000893 assert(none_of(Ops,
894 [](uint64_t Op) {
895 return Op == dwarf::DW_OP_stack_value ||
896 Op == dwarf::DW_OP_LLVM_fragment;
897 }) &&
898 "Can't append this op");
Vedant Kumar6379a622018-07-06 17:32:39 +0000899
900 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
901 // has no DW_OP_stack_value.
902 //
903 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
904 Optional<FragmentInfo> FI = Expr->getFragmentInfo();
905 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
Vedant Kumarb572f642018-07-26 20:56:53 +0000906 ArrayRef<uint64_t> ExprOpsBeforeFragment =
907 Expr->getElements().drop_back(DropUntilStackValue);
908 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
909 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
910 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
Vedant Kumar6379a622018-07-06 17:32:39 +0000911
Vedant Kumarb572f642018-07-26 20:56:53 +0000912 // Append a DW_OP_deref after Expr's current op list if needed, then append
913 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
Vedant Kumar6379a622018-07-06 17:32:39 +0000914 SmallVector<uint64_t, 16> NewOps;
Vedant Kumar6379a622018-07-06 17:32:39 +0000915 if (NeedsDeref)
916 NewOps.push_back(dwarf::DW_OP_deref);
917 NewOps.append(Ops.begin(), Ops.end());
Vedant Kumarb572f642018-07-26 20:56:53 +0000918 if (NeedsStackValue)
919 NewOps.push_back(dwarf::DW_OP_stack_value);
920 return DIExpression::append(Expr, NewOps);
Vedant Kumar6379a622018-07-06 17:32:39 +0000921}
922
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000923Optional<DIExpression *> DIExpression::createFragmentExpression(
924 const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits) {
Adrian Prantlb192b542017-08-30 20:04:17 +0000925 SmallVector<uint64_t, 8> Ops;
926 // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
927 if (Expr) {
928 for (auto Op : Expr->expr_ops()) {
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000929 switch (Op.getOp()) {
930 default: break;
931 case dwarf::DW_OP_plus:
932 case dwarf::DW_OP_minus:
933 // We can't safely split arithmetic into multiple fragments because we
934 // can't express carry-over between fragments.
935 //
936 // FIXME: We *could* preserve the lowest fragment of a constant offset
937 // operation if the offset fits into SizeInBits.
938 return None;
939 case dwarf::DW_OP_LLVM_fragment: {
Adrian Prantlb192b542017-08-30 20:04:17 +0000940 // Make the new offset point into the existing fragment.
941 uint64_t FragmentOffsetInBits = Op.getArg(0);
Bjorn Pettersson5479ad22018-05-03 17:04:21 +0000942 uint64_t FragmentSizeInBits = Op.getArg(1);
943 (void)FragmentSizeInBits;
944 assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
Adrian Prantlb192b542017-08-30 20:04:17 +0000945 "new fragment outside of original fragment");
946 OffsetInBits += FragmentOffsetInBits;
Adrian Prantl25a09dd2017-11-07 00:45:34 +0000947 continue;
948 }
Adrian Prantlb192b542017-08-30 20:04:17 +0000949 }
Vedant Kumar71c7c432018-07-06 21:06:21 +0000950 Op.appendToVector(Ops);
Adrian Prantlb192b542017-08-30 20:04:17 +0000951 }
952 }
953 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
954 Ops.push_back(OffsetInBits);
955 Ops.push_back(SizeInBits);
956 return DIExpression::get(Expr->getContext(), Ops);
957}
958
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000959bool DIExpression::isConstant() const {
960 // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
961 if (getNumElements() != 3 && getNumElements() != 6)
962 return false;
963 if (getElement(0) != dwarf::DW_OP_constu ||
964 getElement(2) != dwarf::DW_OP_stack_value)
965 return false;
966 if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
967 return false;
968 return true;
969}
970
971DIGlobalVariableExpression *
972DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
973 Metadata *Expression, StorageType Storage,
974 bool ShouldCreate) {
975 DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
976 Metadata *Ops[] = {Variable, Expression};
977 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
978}
979
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000980DIObjCProperty *DIObjCProperty::getImpl(
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000981 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
982 MDString *GetterName, MDString *SetterName, unsigned Attributes,
983 Metadata *Type, StorageType Storage, bool ShouldCreate) {
984 assert(isCanonical(Name) && "Expected canonical MDString");
985 assert(isCanonical(GetterName) && "Expected canonical MDString");
986 assert(isCanonical(SetterName) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000987 DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
988 SetterName, Attributes, Type));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000989 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000990 DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000991}
992
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000993DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000994 Metadata *Scope, Metadata *Entity,
Adrian Prantld63bfd22017-07-19 00:09:54 +0000995 Metadata *File, unsigned Line,
996 MDString *Name, StorageType Storage,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000997 bool ShouldCreate) {
998 assert(isCanonical(Name) && "Expected canonical MDString");
Adrian Prantld63bfd22017-07-19 00:09:54 +0000999 DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
1000 (Tag, Scope, Entity, File, Line, Name));
1001 Metadata *Ops[] = {Scope, Entity, Name, File};
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001002 DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001003}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001004
1005DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
1006 unsigned Line, MDString *Name, MDString *Value,
1007 StorageType Storage, bool ShouldCreate) {
1008 assert(isCanonical(Name) && "Expected canonical MDString");
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001009 DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
Amjad Abouda9bcf162015-12-10 12:56:35 +00001010 Metadata *Ops[] = { Name, Value };
1011 DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
1012}
1013
1014DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
1015 unsigned Line, Metadata *File,
1016 Metadata *Elements, StorageType Storage,
1017 bool ShouldCreate) {
1018 DEFINE_GETIMPL_LOOKUP(DIMacroFile,
1019 (MIType, Line, File, Elements));
1020 Metadata *Ops[] = { File, Elements };
1021 DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
1022}