DebugInfo: Migrate DISubprogram::describes() to new hierarchy, NFC
[oota-llvm.git] / lib / IR / DebugInfoMetadata.cpp
1 //===- 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"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/IR/Function.h"
19
20 using namespace llvm;
21
22 MDLocation::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.
29   assert(Column < (1u << 16) && "Expected 16-bit column");
30
31   SubclassData32 = Line;
32   SubclassData16 = Column;
33 }
34
35 static 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
41 MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
42                                 unsigned Column, Metadata *Scope,
43                                 Metadata *InlinedAt, StorageType Storage,
44                                 bool ShouldCreate) {
45   // Fixup column.
46   adjustColumn(Column);
47
48   assert(Scope && "Expected scope");
49   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
69 unsigned 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
76 const 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
87 unsigned 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 MDScopeRef MDScope::getScope() const {
112   if (auto *T = dyn_cast<MDType>(this))
113     return T->getScope();
114
115   if (auto *SP = dyn_cast<MDSubprogram>(this))
116     return SP->getScope();
117
118   if (auto *LB = dyn_cast<MDLexicalBlockBase>(this))
119     return MDScopeRef(LB->getScope());
120
121   if (auto *NS = dyn_cast<MDNamespace>(this))
122     return MDScopeRef(NS->getScope());
123
124   assert((isa<MDFile>(this) || isa<MDCompileUnit>(this)) &&
125          "Unhandled type of scope.");
126   return nullptr;
127 }
128
129 StringRef MDScope::getName() const {
130   if (auto *T = dyn_cast<MDType>(this))
131     return T->getName();
132   if (auto *SP = dyn_cast<MDSubprogram>(this))
133     return SP->getName();
134   if (auto *NS = dyn_cast<MDNamespace>(this))
135     return NS->getName();
136   assert((isa<MDLexicalBlockBase>(this) || isa<MDFile>(this) ||
137           isa<MDCompileUnit>(this)) &&
138          "Unhandled type of scope.");
139   return "";
140 }
141
142 static StringRef getString(const MDString *S) {
143   if (S)
144     return S->getString();
145   return StringRef();
146 }
147
148 #ifndef NDEBUG
149 static bool isCanonical(const MDString *S) {
150   return !S || !S->getString().empty();
151 }
152 #endif
153
154 GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
155                                             MDString *Header,
156                                             ArrayRef<Metadata *> DwarfOps,
157                                             StorageType Storage,
158                                             bool ShouldCreate) {
159   unsigned Hash = 0;
160   if (Storage == Uniqued) {
161     GenericDebugNodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
162     if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
163       return N;
164     if (!ShouldCreate)
165       return nullptr;
166     Hash = Key.getHash();
167   } else {
168     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
169   }
170
171   // Use a nullptr for empty headers.
172   assert(isCanonical(Header) && "Expected canonical MDString");
173   Metadata *PreOps[] = {Header};
174   return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
175                        Context, Storage, Hash, Tag, PreOps, DwarfOps),
176                    Storage, Context.pImpl->GenericDebugNodes);
177 }
178
179 void GenericDebugNode::recalculateHash() {
180   setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this));
181 }
182
183 #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
184 #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
185 #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)                                     \
186   do {                                                                         \
187     if (Storage == Uniqued) {                                                  \
188       if (auto *N = getUniqued(Context.pImpl->CLASS##s,                        \
189                                CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS))))         \
190         return N;                                                              \
191       if (!ShouldCreate)                                                       \
192         return nullptr;                                                        \
193     } else {                                                                   \
194       assert(ShouldCreate &&                                                   \
195              "Expected non-uniqued nodes to always be created");               \
196     }                                                                          \
197   } while (false)
198 #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)                                 \
199   return storeImpl(new (ArrayRef<Metadata *>(OPS).size())                      \
200                        CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS),        \
201                    Storage, Context.pImpl->CLASS##s)
202 #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)                               \
203   return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)),        \
204                    Storage, Context.pImpl->CLASS##s)
205 #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)                   \
206   return storeImpl(new (ArrayRef<Metadata *>(OPS).size())                      \
207                        CLASS(Context, Storage, OPS),                           \
208                    Storage, Context.pImpl->CLASS##s)
209
210 MDSubrange *MDSubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
211                                 StorageType Storage, bool ShouldCreate) {
212   DEFINE_GETIMPL_LOOKUP(MDSubrange, (Count, Lo));
213   DEFINE_GETIMPL_STORE_NO_OPS(MDSubrange, (Count, Lo));
214 }
215
216 MDEnumerator *MDEnumerator::getImpl(LLVMContext &Context, int64_t Value,
217                                     MDString *Name, StorageType Storage,
218                                     bool ShouldCreate) {
219   assert(isCanonical(Name) && "Expected canonical MDString");
220   DEFINE_GETIMPL_LOOKUP(MDEnumerator, (Value, getString(Name)));
221   Metadata *Ops[] = {Name};
222   DEFINE_GETIMPL_STORE(MDEnumerator, (Value), Ops);
223 }
224
225 MDBasicType *MDBasicType::getImpl(LLVMContext &Context, unsigned Tag,
226                                   MDString *Name, uint64_t SizeInBits,
227                                   uint64_t AlignInBits, unsigned Encoding,
228                                   StorageType Storage, bool ShouldCreate) {
229   assert(isCanonical(Name) && "Expected canonical MDString");
230   DEFINE_GETIMPL_LOOKUP(
231       MDBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
232   Metadata *Ops[] = {nullptr, nullptr, Name};
233   DEFINE_GETIMPL_STORE(MDBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
234                        Ops);
235 }
236
237 MDDerivedType *MDDerivedType::getImpl(
238     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
239     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
240     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
241     Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
242   assert(isCanonical(Name) && "Expected canonical MDString");
243   DEFINE_GETIMPL_LOOKUP(MDDerivedType, (Tag, getString(Name), File, Line, Scope,
244                                         BaseType, SizeInBits, AlignInBits,
245                                         OffsetInBits, Flags, ExtraData));
246   Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
247   DEFINE_GETIMPL_STORE(
248       MDDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
249       Ops);
250 }
251
252 MDCompositeType *MDCompositeType::getImpl(
253     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
254     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
255     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
256     Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
257     Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
258     bool ShouldCreate) {
259   assert(isCanonical(Name) && "Expected canonical MDString");
260   DEFINE_GETIMPL_LOOKUP(MDCompositeType,
261                         (Tag, getString(Name), File, Line, Scope, BaseType,
262                          SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
263                          RuntimeLang, VTableHolder, TemplateParams,
264                          getString(Identifier)));
265   Metadata *Ops[] = {File,     Scope,        Name,           BaseType,
266                      Elements, VTableHolder, TemplateParams, Identifier};
267   DEFINE_GETIMPL_STORE(MDCompositeType, (Tag, Line, RuntimeLang, SizeInBits,
268                                          AlignInBits, OffsetInBits, Flags),
269                        Ops);
270 }
271
272 MDSubroutineType *MDSubroutineType::getImpl(LLVMContext &Context,
273                                             unsigned Flags, Metadata *TypeArray,
274                                             StorageType Storage,
275                                             bool ShouldCreate) {
276   DEFINE_GETIMPL_LOOKUP(MDSubroutineType, (Flags, TypeArray));
277   Metadata *Ops[] = {nullptr,   nullptr, nullptr, nullptr,
278                      TypeArray, nullptr, nullptr, nullptr};
279   DEFINE_GETIMPL_STORE(MDSubroutineType, (Flags), Ops);
280 }
281
282 MDFile *MDFile::getImpl(LLVMContext &Context, MDString *Filename,
283                         MDString *Directory, StorageType Storage,
284                         bool ShouldCreate) {
285   assert(isCanonical(Filename) && "Expected canonical MDString");
286   assert(isCanonical(Directory) && "Expected canonical MDString");
287   DEFINE_GETIMPL_LOOKUP(MDFile, (getString(Filename), getString(Directory)));
288   Metadata *Ops[] = {Filename, Directory};
289   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDFile, Ops);
290 }
291
292 MDCompileUnit *MDCompileUnit::getImpl(
293     LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
294     MDString *Producer, bool IsOptimized, MDString *Flags,
295     unsigned RuntimeVersion, MDString *SplitDebugFilename,
296     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
297     Metadata *Subprograms, Metadata *GlobalVariables,
298     Metadata *ImportedEntities, StorageType Storage, bool ShouldCreate) {
299   assert(isCanonical(Producer) && "Expected canonical MDString");
300   assert(isCanonical(Flags) && "Expected canonical MDString");
301   assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
302   DEFINE_GETIMPL_LOOKUP(
303       MDCompileUnit,
304       (SourceLanguage, File, getString(Producer), IsOptimized, getString(Flags),
305        RuntimeVersion, getString(SplitDebugFilename), EmissionKind, EnumTypes,
306        RetainedTypes, Subprograms, GlobalVariables, ImportedEntities));
307   Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
308                      RetainedTypes, Subprograms, GlobalVariables,
309                      ImportedEntities};
310   DEFINE_GETIMPL_STORE(
311       MDCompileUnit,
312       (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind), Ops);
313 }
314
315 MDSubprogram *MDLocalScope::getSubprogram() const {
316   if (auto *Block = dyn_cast<MDLexicalBlockBase>(this))
317     return Block->getScope()->getSubprogram();
318   return const_cast<MDSubprogram *>(cast<MDSubprogram>(this));
319 }
320
321 MDSubprogram *MDSubprogram::getImpl(
322     LLVMContext &Context, Metadata *Scope, MDString *Name,
323     MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
324     bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
325     Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
326     unsigned Flags, bool IsOptimized, Metadata *Function,
327     Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
328     StorageType Storage, bool ShouldCreate) {
329   assert(isCanonical(Name) && "Expected canonical MDString");
330   assert(isCanonical(LinkageName) && "Expected canonical MDString");
331   DEFINE_GETIMPL_LOOKUP(MDSubprogram,
332                         (Scope, getString(Name), getString(LinkageName), File,
333                          Line, Type, IsLocalToUnit, IsDefinition, ScopeLine,
334                          ContainingType, Virtuality, VirtualIndex, Flags,
335                          IsOptimized, Function, TemplateParams, Declaration,
336                          Variables));
337   Metadata *Ops[] = {File,           Scope,       Name,           Name,
338                      LinkageName,    Type,        ContainingType, Function,
339                      TemplateParams, Declaration, Variables};
340   DEFINE_GETIMPL_STORE(MDSubprogram,
341                        (Line, ScopeLine, Virtuality, VirtualIndex, Flags,
342                         IsLocalToUnit, IsDefinition, IsOptimized),
343                        Ops);
344 }
345
346 Function *MDSubprogram::getFunction() const {
347   // FIXME: Should this be looking through bitcasts?
348   return dyn_cast_or_null<Function>(getFunctionConstant());
349 }
350
351 bool MDSubprogram::describes(const Function *F) const {
352   assert(F && "Invalid function");
353   if (F == getFunction())
354     return true;
355   StringRef Name = getLinkageName();
356   if (Name.empty())
357     Name = getName();
358   return F->getName() == Name;
359 }
360
361 void MDSubprogram::replaceFunction(Function *F) {
362   replaceFunction(F ? ConstantAsMetadata::get(F)
363                     : static_cast<ConstantAsMetadata *>(nullptr));
364 }
365
366 MDLexicalBlock *MDLexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
367                                         Metadata *File, unsigned Line,
368                                         unsigned Column, StorageType Storage,
369                                         bool ShouldCreate) {
370   assert(Scope && "Expected scope");
371   DEFINE_GETIMPL_LOOKUP(MDLexicalBlock, (Scope, File, Line, Column));
372   Metadata *Ops[] = {File, Scope};
373   DEFINE_GETIMPL_STORE(MDLexicalBlock, (Line, Column), Ops);
374 }
375
376 MDLexicalBlockFile *MDLexicalBlockFile::getImpl(LLVMContext &Context,
377                                                 Metadata *Scope, Metadata *File,
378                                                 unsigned Discriminator,
379                                                 StorageType Storage,
380                                                 bool ShouldCreate) {
381   assert(Scope && "Expected scope");
382   DEFINE_GETIMPL_LOOKUP(MDLexicalBlockFile, (Scope, File, Discriminator));
383   Metadata *Ops[] = {File, Scope};
384   DEFINE_GETIMPL_STORE(MDLexicalBlockFile, (Discriminator), Ops);
385 }
386
387 MDNamespace *MDNamespace::getImpl(LLVMContext &Context, Metadata *Scope,
388                                   Metadata *File, MDString *Name, unsigned Line,
389                                   StorageType Storage, bool ShouldCreate) {
390   assert(isCanonical(Name) && "Expected canonical MDString");
391   DEFINE_GETIMPL_LOOKUP(MDNamespace, (Scope, File, getString(Name), Line));
392   Metadata *Ops[] = {File, Scope, Name};
393   DEFINE_GETIMPL_STORE(MDNamespace, (Line), Ops);
394 }
395
396 MDTemplateTypeParameter *MDTemplateTypeParameter::getImpl(LLVMContext &Context,
397                                                           MDString *Name,
398                                                           Metadata *Type,
399                                                           StorageType Storage,
400                                                           bool ShouldCreate) {
401   assert(isCanonical(Name) && "Expected canonical MDString");
402   DEFINE_GETIMPL_LOOKUP(MDTemplateTypeParameter, (getString(Name), Type));
403   Metadata *Ops[] = {Name, Type};
404   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(MDTemplateTypeParameter, Ops);
405 }
406
407 MDTemplateValueParameter *MDTemplateValueParameter::getImpl(
408     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
409     Metadata *Value, StorageType Storage, bool ShouldCreate) {
410   assert(isCanonical(Name) && "Expected canonical MDString");
411   DEFINE_GETIMPL_LOOKUP(MDTemplateValueParameter,
412                         (Tag, getString(Name), Type, Value));
413   Metadata *Ops[] = {Name, Type, Value};
414   DEFINE_GETIMPL_STORE(MDTemplateValueParameter, (Tag), Ops);
415 }
416
417 MDGlobalVariable *
418 MDGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
419                           MDString *LinkageName, Metadata *File, unsigned Line,
420                           Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
421                           Metadata *Variable,
422                           Metadata *StaticDataMemberDeclaration,
423                           StorageType Storage, bool ShouldCreate) {
424   assert(isCanonical(Name) && "Expected canonical MDString");
425   assert(isCanonical(LinkageName) && "Expected canonical MDString");
426   DEFINE_GETIMPL_LOOKUP(MDGlobalVariable,
427                         (Scope, getString(Name), getString(LinkageName), File,
428                          Line, Type, IsLocalToUnit, IsDefinition, Variable,
429                          StaticDataMemberDeclaration));
430   Metadata *Ops[] = {Scope, Name,        File,     Type,
431                      Name,  LinkageName, Variable, StaticDataMemberDeclaration};
432   DEFINE_GETIMPL_STORE(MDGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
433                        Ops);
434 }
435
436 MDLocalVariable *MDLocalVariable::getImpl(
437     LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name,
438     Metadata *File, unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags,
439     Metadata *InlinedAt, StorageType Storage, bool ShouldCreate) {
440   // Truncate Arg to 8 bits.
441   //
442   // FIXME: This is gross (and should be changed to an assert or removed), but
443   // it matches historical behaviour for now.
444   Arg &= (1u << 8) - 1;
445
446   assert(Scope && "Expected scope");
447   assert(isCanonical(Name) && "Expected canonical MDString");
448   DEFINE_GETIMPL_LOOKUP(MDLocalVariable, (Tag, Scope, getString(Name), File,
449                                           Line, Type, Arg, Flags, InlinedAt));
450   Metadata *Ops[] = {Scope, Name, File, Type, InlinedAt};
451   DEFINE_GETIMPL_STORE(MDLocalVariable, (Tag, Line, Arg, Flags), Ops);
452 }
453
454 MDExpression *MDExpression::getImpl(LLVMContext &Context,
455                                     ArrayRef<uint64_t> Elements,
456                                     StorageType Storage, bool ShouldCreate) {
457   DEFINE_GETIMPL_LOOKUP(MDExpression, (Elements));
458   DEFINE_GETIMPL_STORE_NO_OPS(MDExpression, (Elements));
459 }
460
461 unsigned MDExpression::ExprOperand::getSize() const {
462   switch (getOp()) {
463   case dwarf::DW_OP_bit_piece:
464     return 3;
465   case dwarf::DW_OP_plus:
466     return 2;
467   default:
468     return 1;
469   }
470 }
471
472 bool MDExpression::isValid() const {
473   for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
474     // Check that there's space for the operand.
475     if (I->get() + I->getSize() > E->get())
476       return false;
477
478     // Check that the operand is valid.
479     switch (I->getOp()) {
480     default:
481       return false;
482     case dwarf::DW_OP_bit_piece:
483       // Piece expressions must be at the end.
484       return I->get() + I->getSize() == E->get();
485     case dwarf::DW_OP_plus:
486     case dwarf::DW_OP_deref:
487       break;
488     }
489   }
490   return true;
491 }
492
493 bool MDExpression::isBitPiece() const {
494   assert(isValid() && "Expected valid expression");
495   if (unsigned N = getNumElements())
496     if (N >= 3)
497       return getElement(N - 3) == dwarf::DW_OP_bit_piece;
498   return false;
499 }
500
501 uint64_t MDExpression::getBitPieceOffset() const {
502   assert(isBitPiece() && "Expected bit piece");
503   return getElement(getNumElements() - 2);
504 }
505
506 uint64_t MDExpression::getBitPieceSize() const {
507   assert(isBitPiece() && "Expected bit piece");
508   return getElement(getNumElements() - 1);
509 }
510
511 MDObjCProperty *MDObjCProperty::getImpl(
512     LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
513     MDString *GetterName, MDString *SetterName, unsigned Attributes,
514     Metadata *Type, StorageType Storage, bool ShouldCreate) {
515   assert(isCanonical(Name) && "Expected canonical MDString");
516   assert(isCanonical(GetterName) && "Expected canonical MDString");
517   assert(isCanonical(SetterName) && "Expected canonical MDString");
518   DEFINE_GETIMPL_LOOKUP(MDObjCProperty,
519                         (getString(Name), File, Line, getString(GetterName),
520                          getString(SetterName), Attributes, Type));
521   Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
522   DEFINE_GETIMPL_STORE(MDObjCProperty, (Line, Attributes), Ops);
523 }
524
525 MDImportedEntity *MDImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
526                                             Metadata *Scope, Metadata *Entity,
527                                             unsigned Line, MDString *Name,
528                                             StorageType Storage,
529                                             bool ShouldCreate) {
530   assert(isCanonical(Name) && "Expected canonical MDString");
531   DEFINE_GETIMPL_LOOKUP(MDImportedEntity,
532                         (Tag, Scope, Entity, Line, getString(Name)));
533   Metadata *Ops[] = {Scope, Entity, Name};
534   DEFINE_GETIMPL_STORE(MDImportedEntity, (Tag, Line), Ops);
535 }