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 DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
23                        unsigned Column, ArrayRef<Metadata *> MDs)
24     : MDNode(C, DILocationKind, 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 DILocation *DILocation::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->DILocations,
52                        DILocationInfo::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                        DILocation(Context, Storage, Line, Column, Ops),
66                    Storage, Context.pImpl->DILocations);
67 }
68 
69 unsigned DINode::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 *DINode::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 DINode::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 DIScopeRef DIScope::getScope() const {
112   if (auto *T = dyn_cast<DIType>(this))
113     return T->getScope();
114 
115   if (auto *SP = dyn_cast<DISubprogram>(this))
116     return SP->getScope();
117 
118   if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
119     return DIScopeRef(LB->getScope());
120 
121   if (auto *NS = dyn_cast<DINamespace>(this))
122     return DIScopeRef(NS->getScope());
123 
124   if (auto *M = dyn_cast<DIModule>(this))
125     return DIScopeRef(M->getScope());
126 
127   assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
128          "Unhandled type of scope.");
129   return nullptr;
130 }
131 
132 StringRef DIScope::getName() const {
133   if (auto *T = dyn_cast<DIType>(this))
134     return T->getName();
135   if (auto *SP = dyn_cast<DISubprogram>(this))
136     return SP->getName();
137   if (auto *NS = dyn_cast<DINamespace>(this))
138     return NS->getName();
139   if (auto *M = dyn_cast<DIModule>(this))
140     return M->getName();
141   assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
142           isa<DICompileUnit>(this)) &&
143          "Unhandled type of scope.");
144   return "";
145 }
146 
147 static StringRef getString(const MDString *S) {
148   if (S)
149     return S->getString();
150   return StringRef();
151 }
152 
153 #ifndef NDEBUG
154 static bool isCanonical(const MDString *S) {
155   return !S || !S->getString().empty();
156 }
157 #endif
158 
159 GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
160                                       MDString *Header,
161                                       ArrayRef<Metadata *> DwarfOps,
162                                       StorageType Storage, bool ShouldCreate) {
163   unsigned Hash = 0;
164   if (Storage == Uniqued) {
165     GenericDINodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
166     if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
167       return N;
168     if (!ShouldCreate)
169       return nullptr;
170     Hash = Key.getHash();
171   } else {
172     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
173   }
174 
175   // Use a nullptr for empty headers.
176   assert(isCanonical(Header) && "Expected canonical MDString");
177   Metadata *PreOps[] = {Header};
178   return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
179                        Context, Storage, Hash, Tag, PreOps, DwarfOps),
180                    Storage, Context.pImpl->GenericDINodes);
181 }
182 
183 void GenericDINode::recalculateHash() {
184   setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
185 }
186 
187 #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
188 #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
189 #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)                                     \
190   do {                                                                         \
191     if (Storage == Uniqued) {                                                  \
192       if (auto *N = getUniqued(Context.pImpl->CLASS##s,                        \
193                                CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS))))         \
194         return N;                                                              \
195       if (!ShouldCreate)                                                       \
196         return nullptr;                                                        \
197     } else {                                                                   \
198       assert(ShouldCreate &&                                                   \
199              "Expected non-uniqued nodes to always be created");               \
200     }                                                                          \
201   } while (false)
202 #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)                                 \
203   return storeImpl(new (ArrayRef<Metadata *>(OPS).size())                      \
204                        CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS),        \
205                    Storage, Context.pImpl->CLASS##s)
206 #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)                               \
207   return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)),        \
208                    Storage, Context.pImpl->CLASS##s)
209 #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)                   \
210   return storeImpl(new (ArrayRef<Metadata *>(OPS).size())                      \
211                        CLASS(Context, Storage, OPS),                           \
212                    Storage, Context.pImpl->CLASS##s)
213 
214 DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
215                                 StorageType Storage, bool ShouldCreate) {
216   DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
217   DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo));
218 }
219 
220 DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
221                                     MDString *Name, StorageType Storage,
222                                     bool ShouldCreate) {
223   assert(isCanonical(Name) && "Expected canonical MDString");
224   DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, getString(Name)));
225   Metadata *Ops[] = {Name};
226   DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
227 }
228 
229 DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
230                                   MDString *Name, uint64_t SizeInBits,
231                                   uint64_t AlignInBits, unsigned Encoding,
232                                   StorageType Storage, bool ShouldCreate) {
233   assert(isCanonical(Name) && "Expected canonical MDString");
234   DEFINE_GETIMPL_LOOKUP(
235       DIBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
236   Metadata *Ops[] = {nullptr, nullptr, Name};
237   DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
238                        Ops);
239 }
240 
241 DIDerivedType *DIDerivedType::getImpl(
242     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
243     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
244     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
245     Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
246   assert(isCanonical(Name) && "Expected canonical MDString");
247   DEFINE_GETIMPL_LOOKUP(DIDerivedType, (Tag, getString(Name), File, Line, Scope,
248                                         BaseType, SizeInBits, AlignInBits,
249                                         OffsetInBits, Flags, ExtraData));
250   Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
251   DEFINE_GETIMPL_STORE(
252       DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
253       Ops);
254 }
255 
256 DICompositeType *DICompositeType::getImpl(
257     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
258     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
259     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
260     Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
261     Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
262     bool ShouldCreate) {
263   assert(isCanonical(Name) && "Expected canonical MDString");
264   DEFINE_GETIMPL_LOOKUP(DICompositeType,
265                         (Tag, getString(Name), File, Line, Scope, BaseType,
266                          SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
267                          RuntimeLang, VTableHolder, TemplateParams,
268                          getString(Identifier)));
269   Metadata *Ops[] = {File,     Scope,        Name,           BaseType,
270                      Elements, VTableHolder, TemplateParams, Identifier};
271   DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
272                                          AlignInBits, OffsetInBits, Flags),
273                        Ops);
274 }
275 
276 DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context,
277                                             unsigned Flags, Metadata *TypeArray,
278                                             StorageType Storage,
279                                             bool ShouldCreate) {
280   DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, TypeArray));
281   Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
282   DEFINE_GETIMPL_STORE(DISubroutineType, (Flags), Ops);
283 }
284 
285 DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
286                         MDString *Directory, StorageType Storage,
287                         bool ShouldCreate) {
288   assert(isCanonical(Filename) && "Expected canonical MDString");
289   assert(isCanonical(Directory) && "Expected canonical MDString");
290   DEFINE_GETIMPL_LOOKUP(DIFile, (getString(Filename), getString(Directory)));
291   Metadata *Ops[] = {Filename, Directory};
292   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIFile, Ops);
293 }
294 
295 DICompileUnit *DICompileUnit::getImpl(
296     LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
297     MDString *Producer, bool IsOptimized, MDString *Flags,
298     unsigned RuntimeVersion, MDString *SplitDebugFilename,
299     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
300     Metadata *Subprograms, Metadata *GlobalVariables,
301     Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
302     StorageType Storage, bool ShouldCreate) {
303   assert(Storage != Uniqued && "Cannot unique DICompileUnit");
304   assert(isCanonical(Producer) && "Expected canonical MDString");
305   assert(isCanonical(Flags) && "Expected canonical MDString");
306   assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
307 
308   Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
309                      RetainedTypes, Subprograms, GlobalVariables,
310                      ImportedEntities, Macros};
311   return storeImpl(new (ArrayRef<Metadata *>(Ops).size()) DICompileUnit(
312                        Context, Storage, SourceLanguage, IsOptimized,
313                        RuntimeVersion, EmissionKind, DWOId, Ops),
314                    Storage);
315 }
316 
317 DISubprogram *DILocalScope::getSubprogram() const {
318   if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
319     return Block->getScope()->getSubprogram();
320   return const_cast<DISubprogram *>(cast<DISubprogram>(this));
321 }
322 
323 DISubprogram *DISubprogram::getImpl(
324     LLVMContext &Context, Metadata *Scope, MDString *Name,
325     MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
326     bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
327     Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
328     unsigned Flags, bool IsOptimized, Metadata *TemplateParams,
329     Metadata *Declaration, Metadata *Variables, StorageType Storage,
330     bool ShouldCreate) {
331   assert(isCanonical(Name) && "Expected canonical MDString");
332   assert(isCanonical(LinkageName) && "Expected canonical MDString");
333   DEFINE_GETIMPL_LOOKUP(DISubprogram,
334                         (Scope, getString(Name), getString(LinkageName), File,
335                          Line, Type, IsLocalToUnit, IsDefinition, ScopeLine,
336                          ContainingType, Virtuality, VirtualIndex, Flags,
337                          IsOptimized, TemplateParams, Declaration, Variables));
338   Metadata *Ops[] = {File,        Scope,    Name,           Name,
339                      LinkageName, Type,     ContainingType, TemplateParams,
340                      Declaration, Variables};
341   DEFINE_GETIMPL_STORE(DISubprogram,
342                        (Line, ScopeLine, Virtuality, VirtualIndex, Flags,
343                         IsLocalToUnit, IsDefinition, IsOptimized),
344                        Ops);
345 }
346 
347 bool DISubprogram::describes(const Function *F) const {
348   assert(F && "Invalid function");
349   if (F->getSubprogram() == this)
350     return true;
351   StringRef Name = getLinkageName();
352   if (Name.empty())
353     Name = getName();
354   return F->getName() == Name;
355 }
356 
357 DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
358                                         Metadata *File, unsigned Line,
359                                         unsigned Column, StorageType Storage,
360                                         bool ShouldCreate) {
361   // Fixup column.
362   adjustColumn(Column);
363 
364   assert(Scope && "Expected scope");
365   DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
366   Metadata *Ops[] = {File, Scope};
367   DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
368 }
369 
370 DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
371                                                 Metadata *Scope, Metadata *File,
372                                                 unsigned Discriminator,
373                                                 StorageType Storage,
374                                                 bool ShouldCreate) {
375   assert(Scope && "Expected scope");
376   DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
377   Metadata *Ops[] = {File, Scope};
378   DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
379 }
380 
381 DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
382                                   Metadata *File, MDString *Name, unsigned Line,
383                                   StorageType Storage, bool ShouldCreate) {
384   assert(isCanonical(Name) && "Expected canonical MDString");
385   DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, getString(Name), Line));
386   Metadata *Ops[] = {File, Scope, Name};
387   DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
388 }
389 
390 DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
391                             MDString *Name, MDString *ConfigurationMacros,
392                             MDString *IncludePath, MDString *ISysRoot,
393                             StorageType Storage, bool ShouldCreate) {
394   assert(isCanonical(Name) && "Expected canonical MDString");
395   DEFINE_GETIMPL_LOOKUP(DIModule,
396     (Scope, getString(Name), getString(ConfigurationMacros),
397      getString(IncludePath), getString(ISysRoot)));
398   Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
399   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
400 }
401 
402 DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
403                                                           MDString *Name,
404                                                           Metadata *Type,
405                                                           StorageType Storage,
406                                                           bool ShouldCreate) {
407   assert(isCanonical(Name) && "Expected canonical MDString");
408   DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (getString(Name), Type));
409   Metadata *Ops[] = {Name, Type};
410   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
411 }
412 
413 DITemplateValueParameter *DITemplateValueParameter::getImpl(
414     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
415     Metadata *Value, StorageType Storage, bool ShouldCreate) {
416   assert(isCanonical(Name) && "Expected canonical MDString");
417   DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,
418                         (Tag, getString(Name), Type, Value));
419   Metadata *Ops[] = {Name, Type, Value};
420   DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
421 }
422 
423 DIGlobalVariable *
424 DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
425                           MDString *LinkageName, Metadata *File, unsigned Line,
426                           Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
427                           Metadata *Variable,
428                           Metadata *StaticDataMemberDeclaration,
429                           StorageType Storage, bool ShouldCreate) {
430   assert(isCanonical(Name) && "Expected canonical MDString");
431   assert(isCanonical(LinkageName) && "Expected canonical MDString");
432   DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
433                         (Scope, getString(Name), getString(LinkageName), File,
434                          Line, Type, IsLocalToUnit, IsDefinition, Variable,
435                          StaticDataMemberDeclaration));
436   Metadata *Ops[] = {Scope, Name,        File,     Type,
437                      Name,  LinkageName, Variable, StaticDataMemberDeclaration};
438   DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
439                        Ops);
440 }
441 
442 DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
443                                           MDString *Name, Metadata *File,
444                                           unsigned Line, Metadata *Type,
445                                           unsigned Arg, unsigned Flags,
446                                           StorageType Storage,
447                                           bool ShouldCreate) {
448   // 64K ought to be enough for any frontend.
449   assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
450 
451   assert(Scope && "Expected scope");
452   assert(isCanonical(Name) && "Expected canonical MDString");
453   DEFINE_GETIMPL_LOOKUP(DILocalVariable,
454                         (Scope, getString(Name), File, Line, Type, Arg, Flags));
455   Metadata *Ops[] = {Scope, Name, File, Type};
456   DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags), Ops);
457 }
458 
459 DIExpression *DIExpression::getImpl(LLVMContext &Context,
460                                     ArrayRef<uint64_t> Elements,
461                                     StorageType Storage, bool ShouldCreate) {
462   DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
463   DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
464 }
465 
466 unsigned DIExpression::ExprOperand::getSize() const {
467   switch (getOp()) {
468   case dwarf::DW_OP_bit_piece:
469     return 3;
470   case dwarf::DW_OP_plus:
471   case dwarf::DW_OP_minus:
472     return 2;
473   default:
474     return 1;
475   }
476 }
477 
478 bool DIExpression::isValid() const {
479   for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
480     // Check that there's space for the operand.
481     if (I->get() + I->getSize() > E->get())
482       return false;
483 
484     // Check that the operand is valid.
485     switch (I->getOp()) {
486     default:
487       return false;
488     case dwarf::DW_OP_bit_piece:
489       // Piece expressions must be at the end.
490       return I->get() + I->getSize() == E->get();
491     case dwarf::DW_OP_plus:
492     case dwarf::DW_OP_minus:
493     case dwarf::DW_OP_deref:
494       break;
495     }
496   }
497   return true;
498 }
499 
500 bool DIExpression::isBitPiece() const {
501   assert(isValid() && "Expected valid expression");
502   if (unsigned N = getNumElements())
503     if (N >= 3)
504       return getElement(N - 3) == dwarf::DW_OP_bit_piece;
505   return false;
506 }
507 
508 uint64_t DIExpression::getBitPieceOffset() const {
509   assert(isBitPiece() && "Expected bit piece");
510   return getElement(getNumElements() - 2);
511 }
512 
513 uint64_t DIExpression::getBitPieceSize() const {
514   assert(isBitPiece() && "Expected bit piece");
515   return getElement(getNumElements() - 1);
516 }
517 
518 DIObjCProperty *DIObjCProperty::getImpl(
519     LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
520     MDString *GetterName, MDString *SetterName, unsigned Attributes,
521     Metadata *Type, StorageType Storage, bool ShouldCreate) {
522   assert(isCanonical(Name) && "Expected canonical MDString");
523   assert(isCanonical(GetterName) && "Expected canonical MDString");
524   assert(isCanonical(SetterName) && "Expected canonical MDString");
525   DEFINE_GETIMPL_LOOKUP(DIObjCProperty,
526                         (getString(Name), File, Line, getString(GetterName),
527                          getString(SetterName), Attributes, Type));
528   Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
529   DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
530 }
531 
532 DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
533                                             Metadata *Scope, Metadata *Entity,
534                                             unsigned Line, MDString *Name,
535                                             StorageType Storage,
536                                             bool ShouldCreate) {
537   assert(isCanonical(Name) && "Expected canonical MDString");
538   DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
539                         (Tag, Scope, Entity, Line, getString(Name)));
540   Metadata *Ops[] = {Scope, Entity, Name};
541   DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
542 }
543 
544 DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
545                           unsigned Line, MDString *Name, MDString *Value,
546                           StorageType Storage, bool ShouldCreate) {
547   assert(isCanonical(Name) && "Expected canonical MDString");
548   DEFINE_GETIMPL_LOOKUP(DIMacro,
549                         (MIType, Line, getString(Name), getString(Value)));
550   Metadata *Ops[] = { Name, Value };
551   DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
552 }
553 
554 DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
555                                   unsigned Line, Metadata *File,
556                                   Metadata *Elements, StorageType Storage,
557                                   bool ShouldCreate) {
558   DEFINE_GETIMPL_LOOKUP(DIMacroFile,
559                         (MIType, Line, File, Elements));
560   Metadata *Ops[] = { File, Elements };
561   DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
562 }
563 
564