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