blob: 190a31d55512651e2516adaa43ac08f1613849c3 [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"
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +000017#include "llvm/ADT/StringSwitch.h"
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +000018#include "llvm/IR/Function.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000019
20using namespace llvm;
21
22MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
23 unsigned Column, ArrayRef<Metadata *> MDs)
24 : MDNode(C, MDLocationKind, Storage, MDs) {
25 assert((MDs.size() == 1 || MDs.size() == 2) &&
26 "Expected a scope and optional inlined-at");
27
28 // Set line and column.
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000029 assert(Column < (1u << 16) && "Expected 16-bit column");
30
31 SubclassData32 = Line;
32 SubclassData16 = Column;
33}
34
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000035static void adjustColumn(unsigned &Column) {
36 // Set to unknown on overflow. We only have 16 bits to play with here.
37 if (Column >= (1u << 16))
38 Column = 0;
39}
40
41MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
42 unsigned Column, Metadata *Scope,
43 Metadata *InlinedAt, StorageType Storage,
44 bool ShouldCreate) {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +000045 // Fixup column.
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000046 adjustColumn(Column);
47
Duncan P. N. Exon Smithe2c61d92015-03-27 17:56:39 +000048 assert(Scope && "Expected scope");
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000049 if (Storage == Uniqued) {
50 if (auto *N =
51 getUniqued(Context.pImpl->MDLocations,
52 MDLocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
53 return N;
54 if (!ShouldCreate)
55 return nullptr;
56 } else {
57 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
58 }
59
60 SmallVector<Metadata *, 2> Ops;
61 Ops.push_back(Scope);
62 if (InlinedAt)
63 Ops.push_back(InlinedAt);
64 return storeImpl(new (Ops.size())
65 MDLocation(Context, Storage, Line, Column, Ops),
66 Storage, Context.pImpl->MDLocations);
67}
68
Duncan P. N. Exon Smith5261e4b2015-04-07 01:21:40 +000069unsigned DebugNode::getFlag(StringRef Flag) {
70 return StringSwitch<unsigned>(Flag)
71#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
72#include "llvm/IR/DebugInfoFlags.def"
73 .Default(0);
74}
75
76const char *DebugNode::getFlagString(unsigned Flag) {
77 switch (Flag) {
78 default:
79 return "";
80#define HANDLE_DI_FLAG(ID, NAME) \
81 case Flag##NAME: \
82 return "DIFlag" #NAME;
83#include "llvm/IR/DebugInfoFlags.def"
84 }
85}
86
87unsigned DebugNode::splitFlags(unsigned Flags,
88 SmallVectorImpl<unsigned> &SplitFlags) {
89 // Accessibility flags need to be specially handled, since they're packed
90 // together.
91 if (unsigned A = Flags & FlagAccessibility) {
92 if (A == FlagPrivate)
93 SplitFlags.push_back(FlagPrivate);
94 else if (A == FlagProtected)
95 SplitFlags.push_back(FlagProtected);
96 else
97 SplitFlags.push_back(FlagPublic);
98 Flags &= ~A;
99 }
100
101#define HANDLE_DI_FLAG(ID, NAME) \
102 if (unsigned Bit = Flags & ID) { \
103 SplitFlags.push_back(Bit); \
104 Flags &= ~Bit; \
105 }
106#include "llvm/IR/DebugInfoFlags.def"
107
108 return Flags;
109}
110
111
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000112static StringRef getString(const MDString *S) {
113 if (S)
114 return S->getString();
115 return StringRef();
116}
117
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000118#ifndef NDEBUG
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000119static bool isCanonical(const MDString *S) {
120 return !S || !S->getString().empty();
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000121}
Duncan P. N. Exon Smithc7e08132015-02-02 20:20:56 +0000122#endif
Duncan P. N. Exon Smith442ec022015-02-02 19:54:05 +0000123
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000124GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000125 MDString *Header,
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000126 ArrayRef<Metadata *> DwarfOps,
127 StorageType Storage,
128 bool ShouldCreate) {
129 unsigned Hash = 0;
130 if (Storage == Uniqued) {
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000131 GenericDebugNodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000132 if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
133 return N;
134 if (!ShouldCreate)
135 return nullptr;
136 Hash = Key.getHash();
137 } else {
138 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
139 }
140
141 // Use a nullptr for empty headers.
Duncan P. N. Exon Smith9146fc82015-02-02 20:01:03 +0000142 assert(isCanonical(Header) && "Expected canonical MDString");
143 Metadata *PreOps[] = {Header};
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +0000144 return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
145 Context, Storage, Hash, Tag, PreOps, DwarfOps),
146 Storage, Context.pImpl->GenericDebugNodes);
147}
148
149void GenericDebugNode::recalculateHash() {
150 setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this));
151}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000152
153#define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
154#define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
155#define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS) \
156 do { \
157 if (Storage == Uniqued) { \
158 if (auto *N = getUniqued(Context.pImpl->CLASS##s, \
159 CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS)))) \
160 return N; \
161 if (!ShouldCreate) \
162 return nullptr; \
163 } else { \
164 assert(ShouldCreate && \
165 "Expected non-uniqued nodes to always be created"); \
166 } \
167 } while (false)
168#define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS) \
169 return storeImpl(new (ArrayRef<Metadata *>(OPS).size()) \
170 CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \
171 Storage, Context.pImpl->CLASS##s)
172#define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS) \
173 return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)), \
174 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000175#define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS) \
176 return storeImpl(new (ArrayRef<Metadata *>(OPS).size()) \
177 CLASS(Context, Storage, OPS), \
178 Storage, Context.pImpl->CLASS##s)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000179
180MDSubrange *MDSubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
181 StorageType Storage, bool ShouldCreate) {
182 DEFINE_GETIMPL_LOOKUP(MDSubrange, (Count, Lo));
183 DEFINE_GETIMPL_STORE_NO_OPS(MDSubrange, (Count, Lo));
184}
185
186MDEnumerator *MDEnumerator::getImpl(LLVMContext &Context, int64_t Value,
187 MDString *Name, StorageType Storage,
188 bool ShouldCreate) {
189 assert(isCanonical(Name) && "Expected canonical MDString");
190 DEFINE_GETIMPL_LOOKUP(MDEnumerator, (Value, getString(Name)));
191 Metadata *Ops[] = {Name};
192 DEFINE_GETIMPL_STORE(MDEnumerator, (Value), Ops);
193}
194
195MDBasicType *MDBasicType::getImpl(LLVMContext &Context, unsigned Tag,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000196 MDString *Name, uint64_t SizeInBits,
197 uint64_t AlignInBits, unsigned Encoding,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000198 StorageType Storage, bool ShouldCreate) {
199 assert(isCanonical(Name) && "Expected canonical MDString");
200 DEFINE_GETIMPL_LOOKUP(
201 MDBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
202 Metadata *Ops[] = {nullptr, nullptr, Name};
203 DEFINE_GETIMPL_STORE(MDBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
204 Ops);
205}
206
207MDDerivedType *MDDerivedType::getImpl(
208 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000209 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
210 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000211 Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
212 assert(isCanonical(Name) && "Expected canonical MDString");
213 DEFINE_GETIMPL_LOOKUP(MDDerivedType, (Tag, getString(Name), File, Line, Scope,
214 BaseType, SizeInBits, AlignInBits,
215 OffsetInBits, Flags, ExtraData));
216 Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
217 DEFINE_GETIMPL_STORE(
218 MDDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
219 Ops);
220}
221
222MDCompositeType *MDCompositeType::getImpl(
223 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000224 unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
225 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000226 Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
227 Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
228 bool ShouldCreate) {
229 assert(isCanonical(Name) && "Expected canonical MDString");
230 DEFINE_GETIMPL_LOOKUP(MDCompositeType,
231 (Tag, getString(Name), File, Line, Scope, BaseType,
232 SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
233 RuntimeLang, VTableHolder, TemplateParams,
234 getString(Identifier)));
235 Metadata *Ops[] = {File, Scope, Name, BaseType,
236 Elements, VTableHolder, TemplateParams, Identifier};
237 DEFINE_GETIMPL_STORE(MDCompositeType, (Tag, Line, RuntimeLang, SizeInBits,
238 AlignInBits, OffsetInBits, Flags),
239 Ops);
240}
241
242MDSubroutineType *MDSubroutineType::getImpl(LLVMContext &Context,
243 unsigned Flags, Metadata *TypeArray,
244 StorageType Storage,
245 bool ShouldCreate) {
246 DEFINE_GETIMPL_LOOKUP(MDSubroutineType, (Flags, TypeArray));
247 Metadata *Ops[] = {nullptr, nullptr, nullptr, nullptr,
Duncan P. N. Exon Smitha9f0a8d2015-02-19 23:25:21 +0000248 TypeArray, nullptr, nullptr, nullptr};
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000249 DEFINE_GETIMPL_STORE(MDSubroutineType, (Flags), Ops);
250}
251
252MDFile *MDFile::getImpl(LLVMContext &Context, MDString *Filename,
253 MDString *Directory, StorageType Storage,
254 bool ShouldCreate) {
255 assert(isCanonical(Filename) && "Expected canonical MDString");
256 assert(isCanonical(Directory) && "Expected canonical MDString");
257 DEFINE_GETIMPL_LOOKUP(MDFile, (getString(Filename), getString(Directory)));
Duncan P. N. Exon Smitha5c57cc2015-02-20 20:35:17 +0000258 Metadata *Ops[] = {Filename, Directory};
259 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDFile, Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000260}
261
262MDCompileUnit *MDCompileUnit::getImpl(
263 LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
264 MDString *Producer, bool IsOptimized, MDString *Flags,
265 unsigned RuntimeVersion, MDString *SplitDebugFilename,
266 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
267 Metadata *Subprograms, Metadata *GlobalVariables,
268 Metadata *ImportedEntities, StorageType Storage, bool ShouldCreate) {
269 assert(isCanonical(Producer) && "Expected canonical MDString");
270 assert(isCanonical(Flags) && "Expected canonical MDString");
271 assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
272 DEFINE_GETIMPL_LOOKUP(
273 MDCompileUnit,
274 (SourceLanguage, File, getString(Producer), IsOptimized, getString(Flags),
275 RuntimeVersion, getString(SplitDebugFilename), EmissionKind, EnumTypes,
276 RetainedTypes, Subprograms, GlobalVariables, ImportedEntities));
277 Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
278 RetainedTypes, Subprograms, GlobalVariables,
279 ImportedEntities};
280 DEFINE_GETIMPL_STORE(
281 MDCompileUnit,
282 (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind), Ops);
283}
284
Duncan P. N. Exon Smithfd07a2a2015-03-30 21:32:28 +0000285MDSubprogram *MDLocalScope::getSubprogram() const {
286 if (auto *Block = dyn_cast<MDLexicalBlockBase>(this))
287 return Block->getScope()->getSubprogram();
288 return const_cast<MDSubprogram *>(cast<MDSubprogram>(this));
289}
290
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000291MDSubprogram *MDSubprogram::getImpl(
292 LLVMContext &Context, Metadata *Scope, MDString *Name,
293 MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
294 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
295 Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
296 unsigned Flags, bool IsOptimized, Metadata *Function,
297 Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
298 StorageType Storage, bool ShouldCreate) {
299 assert(isCanonical(Name) && "Expected canonical MDString");
300 assert(isCanonical(LinkageName) && "Expected canonical MDString");
301 DEFINE_GETIMPL_LOOKUP(MDSubprogram,
302 (Scope, getString(Name), getString(LinkageName), File,
303 Line, Type, IsLocalToUnit, IsDefinition, ScopeLine,
304 ContainingType, Virtuality, VirtualIndex, Flags,
305 IsOptimized, Function, TemplateParams, Declaration,
306 Variables));
307 Metadata *Ops[] = {File, Scope, Name, Name,
308 LinkageName, Type, ContainingType, Function,
309 TemplateParams, Declaration, Variables};
310 DEFINE_GETIMPL_STORE(MDSubprogram,
311 (Line, ScopeLine, Virtuality, VirtualIndex, Flags,
312 IsLocalToUnit, IsDefinition, IsOptimized),
313 Ops);
314}
315
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +0000316void MDSubprogram::replaceFunction(Function *F) {
317 replaceFunction(F ? ConstantAsMetadata::get(F)
318 : static_cast<ConstantAsMetadata *>(nullptr));
319}
320
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000321MDLexicalBlock *MDLexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
322 Metadata *File, unsigned Line,
323 unsigned Column, StorageType Storage,
324 bool ShouldCreate) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000325 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000326 DEFINE_GETIMPL_LOOKUP(MDLexicalBlock, (Scope, File, Line, Column));
327 Metadata *Ops[] = {File, Scope};
328 DEFINE_GETIMPL_STORE(MDLexicalBlock, (Line, Column), Ops);
329}
330
331MDLexicalBlockFile *MDLexicalBlockFile::getImpl(LLVMContext &Context,
332 Metadata *Scope, Metadata *File,
333 unsigned Discriminator,
334 StorageType Storage,
335 bool ShouldCreate) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000336 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000337 DEFINE_GETIMPL_LOOKUP(MDLexicalBlockFile, (Scope, File, Discriminator));
338 Metadata *Ops[] = {File, Scope};
339 DEFINE_GETIMPL_STORE(MDLexicalBlockFile, (Discriminator), Ops);
340}
341
342MDNamespace *MDNamespace::getImpl(LLVMContext &Context, Metadata *Scope,
343 Metadata *File, MDString *Name, unsigned Line,
344 StorageType Storage, bool ShouldCreate) {
345 assert(isCanonical(Name) && "Expected canonical MDString");
346 DEFINE_GETIMPL_LOOKUP(MDNamespace, (Scope, File, getString(Name), Line));
347 Metadata *Ops[] = {File, Scope, Name};
348 DEFINE_GETIMPL_STORE(MDNamespace, (Line), Ops);
349}
350
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000351MDTemplateTypeParameter *MDTemplateTypeParameter::getImpl(LLVMContext &Context,
352 MDString *Name,
353 Metadata *Type,
354 StorageType Storage,
355 bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000356 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000357 DEFINE_GETIMPL_LOOKUP(MDTemplateTypeParameter, (getString(Name), Type));
358 Metadata *Ops[] = {Name, Type};
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000359 DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDTemplateTypeParameter, Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000360}
361
362MDTemplateValueParameter *MDTemplateValueParameter::getImpl(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000363 LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
364 Metadata *Value, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000365 assert(isCanonical(Name) && "Expected canonical MDString");
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000366 DEFINE_GETIMPL_LOOKUP(MDTemplateValueParameter,
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000367 (Tag, getString(Name), Type, Value));
368 Metadata *Ops[] = {Name, Type, Value};
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +0000369 DEFINE_GETIMPL_STORE(MDTemplateValueParameter, (Tag), Ops);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000370}
371
372MDGlobalVariable *
373MDGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
374 MDString *LinkageName, Metadata *File, unsigned Line,
375 Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
376 Metadata *Variable,
377 Metadata *StaticDataMemberDeclaration,
378 StorageType Storage, bool ShouldCreate) {
379 assert(isCanonical(Name) && "Expected canonical MDString");
380 assert(isCanonical(LinkageName) && "Expected canonical MDString");
381 DEFINE_GETIMPL_LOOKUP(MDGlobalVariable,
382 (Scope, getString(Name), getString(LinkageName), File,
383 Line, Type, IsLocalToUnit, IsDefinition, Variable,
384 StaticDataMemberDeclaration));
385 Metadata *Ops[] = {Scope, Name, File, Type,
386 Name, LinkageName, Variable, StaticDataMemberDeclaration};
387 DEFINE_GETIMPL_STORE(MDGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
388 Ops);
389}
390
391MDLocalVariable *MDLocalVariable::getImpl(
392 LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name,
393 Metadata *File, unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags,
394 Metadata *InlinedAt, StorageType Storage, bool ShouldCreate) {
Duncan P. N. Exon Smith72fe2d02015-02-13 01:39:44 +0000395 // Truncate Arg to 8 bits.
396 //
397 // FIXME: This is gross (and should be changed to an assert or removed), but
398 // it matches historical behaviour for now.
399 Arg &= (1u << 8) - 1;
400
Duncan P. N. Exon Smithe2c61d92015-03-27 17:56:39 +0000401 assert(Scope && "Expected scope");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000402 assert(isCanonical(Name) && "Expected canonical MDString");
403 DEFINE_GETIMPL_LOOKUP(MDLocalVariable, (Tag, Scope, getString(Name), File,
404 Line, Type, Arg, Flags, InlinedAt));
405 Metadata *Ops[] = {Scope, Name, File, Type, InlinedAt};
406 DEFINE_GETIMPL_STORE(MDLocalVariable, (Tag, Line, Arg, Flags), Ops);
407}
408
409MDExpression *MDExpression::getImpl(LLVMContext &Context,
410 ArrayRef<uint64_t> Elements,
411 StorageType Storage, bool ShouldCreate) {
412 DEFINE_GETIMPL_LOOKUP(MDExpression, (Elements));
413 DEFINE_GETIMPL_STORE_NO_OPS(MDExpression, (Elements));
414}
415
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +0000416unsigned MDExpression::ExprOperand::getSize() const {
417 switch (getOp()) {
418 case dwarf::DW_OP_bit_piece:
419 return 3;
420 case dwarf::DW_OP_plus:
421 return 2;
422 default:
423 return 1;
424 }
425}
426
427bool MDExpression::isValid() const {
428 for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
429 // Check that there's space for the operand.
430 if (I->get() + I->getSize() > E->get())
431 return false;
432
433 // Check that the operand is valid.
434 switch (I->getOp()) {
435 default:
436 return false;
437 case dwarf::DW_OP_bit_piece:
438 // Piece expressions must be at the end.
439 return I->get() + I->getSize() == E->get();
440 case dwarf::DW_OP_plus:
441 case dwarf::DW_OP_deref:
442 break;
443 }
444 }
445 return true;
446}
447
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000448MDObjCProperty *MDObjCProperty::getImpl(
449 LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
450 MDString *GetterName, MDString *SetterName, unsigned Attributes,
451 Metadata *Type, StorageType Storage, bool ShouldCreate) {
452 assert(isCanonical(Name) && "Expected canonical MDString");
453 assert(isCanonical(GetterName) && "Expected canonical MDString");
454 assert(isCanonical(SetterName) && "Expected canonical MDString");
455 DEFINE_GETIMPL_LOOKUP(MDObjCProperty,
456 (getString(Name), File, Line, getString(GetterName),
457 getString(SetterName), Attributes, Type));
458 Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
459 DEFINE_GETIMPL_STORE(MDObjCProperty, (Line, Attributes), Ops);
460}
461
462MDImportedEntity *MDImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
463 Metadata *Scope, Metadata *Entity,
464 unsigned Line, MDString *Name,
465 StorageType Storage,
466 bool ShouldCreate) {
467 assert(isCanonical(Name) && "Expected canonical MDString");
468 DEFINE_GETIMPL_LOOKUP(MDImportedEntity,
469 (Tag, Scope, Entity, Line, getString(Name)));
470 Metadata *Ops[] = {Scope, Entity, Name};
471 DEFINE_GETIMPL_STORE(MDImportedEntity, (Tag, Line), Ops);
472}