Fix relocation selection for foo-. on mips.
[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 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 DILocation::computeNewDiscriminator() const {
70   // FIXME: This seems completely wrong.
71   //
72   //  1. If two modules are generated in the same context, then the second
73   //     Module will get different discriminators than it would have if it were
74   //     generated in its own context.
75   //  2. If this function is called after round-tripping to bitcode instead of
76   //     before, it will give a different (and potentially incorrect!) return.
77   //
78   // The discriminator should instead be calculated from local information
79   // where it's actually needed.  This logic should be moved to
80   // AddDiscriminators::runOnFunction(), where it doesn't pollute the
81   // LLVMContext.
82   std::pair<const char *, unsigned> Key(getFilename().data(), getLine());
83   return ++getContext().pImpl->DiscriminatorTable[Key];
84 }
85
86 unsigned DINode::getFlag(StringRef Flag) {
87   return StringSwitch<unsigned>(Flag)
88 #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
89 #include "llvm/IR/DebugInfoFlags.def"
90       .Default(0);
91 }
92
93 const char *DINode::getFlagString(unsigned Flag) {
94   switch (Flag) {
95   default:
96     return "";
97 #define HANDLE_DI_FLAG(ID, NAME)                                               \
98   case Flag##NAME:                                                             \
99     return "DIFlag" #NAME;
100 #include "llvm/IR/DebugInfoFlags.def"
101   }
102 }
103
104 unsigned DINode::splitFlags(unsigned Flags,
105                             SmallVectorImpl<unsigned> &SplitFlags) {
106   // Accessibility flags need to be specially handled, since they're packed
107   // together.
108   if (unsigned A = Flags & FlagAccessibility) {
109     if (A == FlagPrivate)
110       SplitFlags.push_back(FlagPrivate);
111     else if (A == FlagProtected)
112       SplitFlags.push_back(FlagProtected);
113     else
114       SplitFlags.push_back(FlagPublic);
115     Flags &= ~A;
116   }
117
118 #define HANDLE_DI_FLAG(ID, NAME)                                               \
119   if (unsigned Bit = Flags & ID) {                                             \
120     SplitFlags.push_back(Bit);                                                 \
121     Flags &= ~Bit;                                                             \
122   }
123 #include "llvm/IR/DebugInfoFlags.def"
124
125   return Flags;
126 }
127
128 DIScopeRef DIScope::getScope() const {
129   if (auto *T = dyn_cast<DIType>(this))
130     return T->getScope();
131
132   if (auto *SP = dyn_cast<DISubprogram>(this))
133     return SP->getScope();
134
135   if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
136     return DIScopeRef(LB->getScope());
137
138   if (auto *NS = dyn_cast<DINamespace>(this))
139     return DIScopeRef(NS->getScope());
140
141   assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
142          "Unhandled type of scope.");
143   return nullptr;
144 }
145
146 StringRef DIScope::getName() const {
147   if (auto *T = dyn_cast<DIType>(this))
148     return T->getName();
149   if (auto *SP = dyn_cast<DISubprogram>(this))
150     return SP->getName();
151   if (auto *NS = dyn_cast<DINamespace>(this))
152     return NS->getName();
153   assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
154           isa<DICompileUnit>(this)) &&
155          "Unhandled type of scope.");
156   return "";
157 }
158
159 static StringRef getString(const MDString *S) {
160   if (S)
161     return S->getString();
162   return StringRef();
163 }
164
165 #ifndef NDEBUG
166 static bool isCanonical(const MDString *S) {
167   return !S || !S->getString().empty();
168 }
169 #endif
170
171 GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
172                                       MDString *Header,
173                                       ArrayRef<Metadata *> DwarfOps,
174                                       StorageType Storage, bool ShouldCreate) {
175   unsigned Hash = 0;
176   if (Storage == Uniqued) {
177     GenericDINodeInfo::KeyTy Key(Tag, getString(Header), DwarfOps);
178     if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
179       return N;
180     if (!ShouldCreate)
181       return nullptr;
182     Hash = Key.getHash();
183   } else {
184     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
185   }
186
187   // Use a nullptr for empty headers.
188   assert(isCanonical(Header) && "Expected canonical MDString");
189   Metadata *PreOps[] = {Header};
190   return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
191                        Context, Storage, Hash, Tag, PreOps, DwarfOps),
192                    Storage, Context.pImpl->GenericDINodes);
193 }
194
195 void GenericDINode::recalculateHash() {
196   setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
197 }
198
199 #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
200 #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
201 #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)                                     \
202   do {                                                                         \
203     if (Storage == Uniqued) {                                                  \
204       if (auto *N = getUniqued(Context.pImpl->CLASS##s,                        \
205                                CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS))))         \
206         return N;                                                              \
207       if (!ShouldCreate)                                                       \
208         return nullptr;                                                        \
209     } else {                                                                   \
210       assert(ShouldCreate &&                                                   \
211              "Expected non-uniqued nodes to always be created");               \
212     }                                                                          \
213   } while (false)
214 #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)                                 \
215   return storeImpl(new (ArrayRef<Metadata *>(OPS).size())                      \
216                        CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS),        \
217                    Storage, Context.pImpl->CLASS##s)
218 #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)                               \
219   return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)),        \
220                    Storage, Context.pImpl->CLASS##s)
221 #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)                   \
222   return storeImpl(new (ArrayRef<Metadata *>(OPS).size())                      \
223                        CLASS(Context, Storage, OPS),                           \
224                    Storage, Context.pImpl->CLASS##s)
225
226 DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
227                                 StorageType Storage, bool ShouldCreate) {
228   DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
229   DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo));
230 }
231
232 DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
233                                     MDString *Name, StorageType Storage,
234                                     bool ShouldCreate) {
235   assert(isCanonical(Name) && "Expected canonical MDString");
236   DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, getString(Name)));
237   Metadata *Ops[] = {Name};
238   DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
239 }
240
241 DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
242                                   MDString *Name, uint64_t SizeInBits,
243                                   uint64_t AlignInBits, unsigned Encoding,
244                                   StorageType Storage, bool ShouldCreate) {
245   assert(isCanonical(Name) && "Expected canonical MDString");
246   DEFINE_GETIMPL_LOOKUP(
247       DIBasicType, (Tag, getString(Name), SizeInBits, AlignInBits, Encoding));
248   Metadata *Ops[] = {nullptr, nullptr, Name};
249   DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
250                        Ops);
251 }
252
253 DIDerivedType *DIDerivedType::getImpl(
254     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
255     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
256     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
257     Metadata *ExtraData, StorageType Storage, bool ShouldCreate) {
258   assert(isCanonical(Name) && "Expected canonical MDString");
259   DEFINE_GETIMPL_LOOKUP(DIDerivedType, (Tag, getString(Name), File, Line, Scope,
260                                         BaseType, SizeInBits, AlignInBits,
261                                         OffsetInBits, Flags, ExtraData));
262   Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
263   DEFINE_GETIMPL_STORE(
264       DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits, Flags),
265       Ops);
266 }
267
268 DICompositeType *DICompositeType::getImpl(
269     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
270     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
271     uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
272     Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
273     Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
274     bool ShouldCreate) {
275   assert(isCanonical(Name) && "Expected canonical MDString");
276   DEFINE_GETIMPL_LOOKUP(DICompositeType,
277                         (Tag, getString(Name), File, Line, Scope, BaseType,
278                          SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
279                          RuntimeLang, VTableHolder, TemplateParams,
280                          getString(Identifier)));
281   Metadata *Ops[] = {File,     Scope,        Name,           BaseType,
282                      Elements, VTableHolder, TemplateParams, Identifier};
283   DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
284                                          AlignInBits, OffsetInBits, Flags),
285                        Ops);
286 }
287
288 DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context,
289                                             unsigned Flags, Metadata *TypeArray,
290                                             StorageType Storage,
291                                             bool ShouldCreate) {
292   DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, TypeArray));
293   Metadata *Ops[] = {nullptr,   nullptr, nullptr, nullptr,
294                      TypeArray, nullptr, nullptr, nullptr};
295   DEFINE_GETIMPL_STORE(DISubroutineType, (Flags), Ops);
296 }
297
298 DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
299                         MDString *Directory, StorageType Storage,
300                         bool ShouldCreate) {
301   assert(isCanonical(Filename) && "Expected canonical MDString");
302   assert(isCanonical(Directory) && "Expected canonical MDString");
303   DEFINE_GETIMPL_LOOKUP(DIFile, (getString(Filename), getString(Directory)));
304   Metadata *Ops[] = {Filename, Directory};
305   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIFile, Ops);
306 }
307
308 DICompileUnit *DICompileUnit::getImpl(
309     LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
310     MDString *Producer, bool IsOptimized, MDString *Flags,
311     unsigned RuntimeVersion, MDString *SplitDebugFilename,
312     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
313     Metadata *Subprograms, Metadata *GlobalVariables,
314     Metadata *ImportedEntities, uint64_t DWOId,
315     StorageType Storage, bool ShouldCreate) {
316   assert(isCanonical(Producer) && "Expected canonical MDString");
317   assert(isCanonical(Flags) && "Expected canonical MDString");
318   assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
319   DEFINE_GETIMPL_LOOKUP(
320       DICompileUnit,
321       (SourceLanguage, File, getString(Producer), IsOptimized, getString(Flags),
322        RuntimeVersion, getString(SplitDebugFilename), EmissionKind, EnumTypes,
323        RetainedTypes, Subprograms, GlobalVariables, ImportedEntities, DWOId));
324   Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
325                      RetainedTypes, Subprograms, GlobalVariables,
326                      ImportedEntities};
327   DEFINE_GETIMPL_STORE(
328       DICompileUnit,
329       (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind, DWOId), Ops);
330 }
331
332 DISubprogram *DILocalScope::getSubprogram() const {
333   if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
334     return Block->getScope()->getSubprogram();
335   return const_cast<DISubprogram *>(cast<DISubprogram>(this));
336 }
337
338 DISubprogram *DISubprogram::getImpl(
339     LLVMContext &Context, Metadata *Scope, MDString *Name,
340     MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
341     bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
342     Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
343     unsigned Flags, bool IsOptimized, Metadata *Function,
344     Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
345     StorageType Storage, bool ShouldCreate) {
346   assert(isCanonical(Name) && "Expected canonical MDString");
347   assert(isCanonical(LinkageName) && "Expected canonical MDString");
348   DEFINE_GETIMPL_LOOKUP(DISubprogram,
349                         (Scope, getString(Name), getString(LinkageName), File,
350                          Line, Type, IsLocalToUnit, IsDefinition, ScopeLine,
351                          ContainingType, Virtuality, VirtualIndex, Flags,
352                          IsOptimized, Function, TemplateParams, Declaration,
353                          Variables));
354   Metadata *Ops[] = {File,           Scope,       Name,           Name,
355                      LinkageName,    Type,        ContainingType, Function,
356                      TemplateParams, Declaration, Variables};
357   DEFINE_GETIMPL_STORE(DISubprogram,
358                        (Line, ScopeLine, Virtuality, VirtualIndex, Flags,
359                         IsLocalToUnit, IsDefinition, IsOptimized),
360                        Ops);
361 }
362
363 Function *DISubprogram::getFunction() const {
364   // FIXME: Should this be looking through bitcasts?
365   return dyn_cast_or_null<Function>(getFunctionConstant());
366 }
367
368 bool DISubprogram::describes(const Function *F) const {
369   assert(F && "Invalid function");
370   if (F == getFunction())
371     return true;
372   StringRef Name = getLinkageName();
373   if (Name.empty())
374     Name = getName();
375   return F->getName() == Name;
376 }
377
378 void DISubprogram::replaceFunction(Function *F) {
379   replaceFunction(F ? ConstantAsMetadata::get(F)
380                     : static_cast<ConstantAsMetadata *>(nullptr));
381 }
382
383 DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
384                                         Metadata *File, unsigned Line,
385                                         unsigned Column, StorageType Storage,
386                                         bool ShouldCreate) {
387   assert(Scope && "Expected scope");
388   DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
389   Metadata *Ops[] = {File, Scope};
390   DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
391 }
392
393 DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
394                                                 Metadata *Scope, Metadata *File,
395                                                 unsigned Discriminator,
396                                                 StorageType Storage,
397                                                 bool ShouldCreate) {
398   assert(Scope && "Expected scope");
399   DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
400   Metadata *Ops[] = {File, Scope};
401   DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
402 }
403
404 DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
405                                   Metadata *File, MDString *Name, unsigned Line,
406                                   StorageType Storage, bool ShouldCreate) {
407   assert(isCanonical(Name) && "Expected canonical MDString");
408   DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, File, getString(Name), Line));
409   Metadata *Ops[] = {File, Scope, Name};
410   DEFINE_GETIMPL_STORE(DINamespace, (Line), Ops);
411 }
412
413 DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
414                                                           MDString *Name,
415                                                           Metadata *Type,
416                                                           StorageType Storage,
417                                                           bool ShouldCreate) {
418   assert(isCanonical(Name) && "Expected canonical MDString");
419   DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (getString(Name), Type));
420   Metadata *Ops[] = {Name, Type};
421   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
422 }
423
424 DITemplateValueParameter *DITemplateValueParameter::getImpl(
425     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
426     Metadata *Value, StorageType Storage, bool ShouldCreate) {
427   assert(isCanonical(Name) && "Expected canonical MDString");
428   DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter,
429                         (Tag, getString(Name), Type, Value));
430   Metadata *Ops[] = {Name, Type, Value};
431   DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
432 }
433
434 DIGlobalVariable *
435 DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
436                           MDString *LinkageName, Metadata *File, unsigned Line,
437                           Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
438                           Metadata *Variable,
439                           Metadata *StaticDataMemberDeclaration,
440                           StorageType Storage, bool ShouldCreate) {
441   assert(isCanonical(Name) && "Expected canonical MDString");
442   assert(isCanonical(LinkageName) && "Expected canonical MDString");
443   DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
444                         (Scope, getString(Name), getString(LinkageName), File,
445                          Line, Type, IsLocalToUnit, IsDefinition, Variable,
446                          StaticDataMemberDeclaration));
447   Metadata *Ops[] = {Scope, Name,        File,     Type,
448                      Name,  LinkageName, Variable, StaticDataMemberDeclaration};
449   DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition),
450                        Ops);
451 }
452
453 DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, unsigned Tag,
454                                           Metadata *Scope, MDString *Name,
455                                           Metadata *File, unsigned Line,
456                                           Metadata *Type, unsigned Arg,
457                                           unsigned Flags, StorageType Storage,
458                                           bool ShouldCreate) {
459   // 64K ought to be enough for any frontend.
460   assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
461
462   assert(Scope && "Expected scope");
463   assert(isCanonical(Name) && "Expected canonical MDString");
464   DEFINE_GETIMPL_LOOKUP(DILocalVariable, (Tag, Scope, getString(Name), File,
465                                           Line, Type, Arg, Flags));
466   Metadata *Ops[] = {Scope, Name, File, Type};
467   DEFINE_GETIMPL_STORE(DILocalVariable, (Tag, Line, Arg, Flags), Ops);
468 }
469
470 DIExpression *DIExpression::getImpl(LLVMContext &Context,
471                                     ArrayRef<uint64_t> Elements,
472                                     StorageType Storage, bool ShouldCreate) {
473   DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
474   DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
475 }
476
477 unsigned DIExpression::ExprOperand::getSize() const {
478   switch (getOp()) {
479   case dwarf::DW_OP_bit_piece:
480     return 3;
481   case dwarf::DW_OP_plus:
482     return 2;
483   default:
484     return 1;
485   }
486 }
487
488 bool DIExpression::isValid() const {
489   for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
490     // Check that there's space for the operand.
491     if (I->get() + I->getSize() > E->get())
492       return false;
493
494     // Check that the operand is valid.
495     switch (I->getOp()) {
496     default:
497       return false;
498     case dwarf::DW_OP_bit_piece:
499       // Piece expressions must be at the end.
500       return I->get() + I->getSize() == E->get();
501     case dwarf::DW_OP_plus:
502     case dwarf::DW_OP_deref:
503       break;
504     }
505   }
506   return true;
507 }
508
509 bool DIExpression::isBitPiece() const {
510   assert(isValid() && "Expected valid expression");
511   if (unsigned N = getNumElements())
512     if (N >= 3)
513       return getElement(N - 3) == dwarf::DW_OP_bit_piece;
514   return false;
515 }
516
517 uint64_t DIExpression::getBitPieceOffset() const {
518   assert(isBitPiece() && "Expected bit piece");
519   return getElement(getNumElements() - 2);
520 }
521
522 uint64_t DIExpression::getBitPieceSize() const {
523   assert(isBitPiece() && "Expected bit piece");
524   return getElement(getNumElements() - 1);
525 }
526
527 DIObjCProperty *DIObjCProperty::getImpl(
528     LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
529     MDString *GetterName, MDString *SetterName, unsigned Attributes,
530     Metadata *Type, StorageType Storage, bool ShouldCreate) {
531   assert(isCanonical(Name) && "Expected canonical MDString");
532   assert(isCanonical(GetterName) && "Expected canonical MDString");
533   assert(isCanonical(SetterName) && "Expected canonical MDString");
534   DEFINE_GETIMPL_LOOKUP(DIObjCProperty,
535                         (getString(Name), File, Line, getString(GetterName),
536                          getString(SetterName), Attributes, Type));
537   Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
538   DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
539 }
540
541 DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
542                                             Metadata *Scope, Metadata *Entity,
543                                             unsigned Line, MDString *Name,
544                                             StorageType Storage,
545                                             bool ShouldCreate) {
546   assert(isCanonical(Name) && "Expected canonical MDString");
547   DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
548                         (Tag, Scope, Entity, Line, getString(Name)));
549   Metadata *Ops[] = {Scope, Entity, Name};
550   DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
551 }