LCOV - code coverage report
Current view: top level - lib/IR - DebugInfoMetadata.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 301 313 96.2 %
Date: 2017-09-14 15:23:50 Functions: 50 50 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/DIBuilder.h"
      19             : #include "llvm/IR/Function.h"
      20             : 
      21             : using namespace llvm;
      22             : 
      23      813081 : DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
      24      813081 :                        unsigned Column, ArrayRef<Metadata *> MDs)
      25     1626162 :     : MDNode(C, DILocationKind, Storage, MDs) {
      26             :   assert((MDs.size() == 1 || MDs.size() == 2) &&
      27             :          "Expected a scope and optional inlined-at");
      28             : 
      29             :   // Set line and column.
      30             :   assert(Column < (1u << 16) && "Expected 16-bit column");
      31             : 
      32      813081 :   SubclassData32 = Line;
      33      813081 :   SubclassData16 = Column;
      34      813081 : }
      35             : 
      36             : static void adjustColumn(unsigned &Column) {
      37             :   // Set to unknown on overflow.  We only have 16 bits to play with here.
      38     2356036 :   if (Column >= (1u << 16))
      39           4 :     Column = 0;
      40             : }
      41             : 
      42     2351557 : DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
      43             :                                 unsigned Column, Metadata *Scope,
      44             :                                 Metadata *InlinedAt, StorageType Storage,
      45             :                                 bool ShouldCreate) {
      46             :   // Fixup column.
      47     2351557 :   adjustColumn(Column);
      48             : 
      49     2351557 :   if (Storage == Uniqued) {
      50     1538476 :     if (auto *N =
      51     2208283 :             getUniqued(Context.pImpl->DILocations,
      52     6624849 :                        DILocationInfo::KeyTy(Line, Column, Scope, InlinedAt)))
      53             :       return N;
      54      669807 :     if (!ShouldCreate)
      55             :       return nullptr;
      56             :   } else {
      57             :     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
      58             :   }
      59             : 
      60      813081 :   SmallVector<Metadata *, 2> Ops;
      61      813081 :   Ops.push_back(Scope);
      62      813081 :   if (InlinedAt)
      63      434195 :     Ops.push_back(InlinedAt);
      64     3252324 :   return storeImpl(new (Ops.size())
      65      813081 :                        DILocation(Context, Storage, Line, Column, Ops),
      66     1626162 :                    Storage, Context.pImpl->DILocations);
      67             : }
      68             : 
      69        2616 : DINode::DIFlags DINode::getFlag(StringRef Flag) {
      70        2616 :   return StringSwitch<DIFlags>(Flag)
      71             : #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
      72             : #include "llvm/IR/DebugInfoFlags.def"
      73        7848 :       .Default(DINode::FlagZero);
      74             : }
      75             : 
      76        6564 : StringRef DINode::getFlagString(DIFlags Flag) {
      77        6564 :   switch (Flag) {
      78             : #define HANDLE_DI_FLAG(ID, NAME)                                               \
      79             :   case Flag##NAME:                                                             \
      80             :     return "DIFlag" #NAME;
      81             : #include "llvm/IR/DebugInfoFlags.def"
      82             :   }
      83           3 :   return "";
      84             : }
      85             : 
      86        5162 : DINode::DIFlags DINode::splitFlags(DIFlags Flags,
      87             :                                    SmallVectorImpl<DIFlags> &SplitFlags) {
      88             :   // Flags that are packed together need to be specially handled, so
      89             :   // that, for example, we emit "DIFlagPublic" and not
      90             :   // "DIFlagPrivate | DIFlagProtected".
      91       10324 :   if (DIFlags A = Flags & FlagAccessibility) {
      92         426 :     if (A == FlagPrivate)
      93          40 :       SplitFlags.push_back(FlagPrivate);
      94         386 :     else if (A == FlagProtected)
      95          55 :       SplitFlags.push_back(FlagProtected);
      96             :     else
      97         331 :       SplitFlags.push_back(FlagPublic);
      98         426 :     Flags &= ~A;
      99             :   }
     100       10324 :   if (DIFlags R = Flags & FlagPtrToMemberRep) {
     101          10 :     if (R == FlagSingleInheritance)
     102           6 :       SplitFlags.push_back(FlagSingleInheritance);
     103           4 :     else if (R == FlagMultipleInheritance)
     104           2 :       SplitFlags.push_back(FlagMultipleInheritance);
     105             :     else
     106           2 :       SplitFlags.push_back(FlagVirtualInheritance);
     107          10 :     Flags &= ~R;
     108             :   }
     109       10324 :   if ((Flags & FlagIndirectVirtualBase) == FlagIndirectVirtualBase) {
     110           2 :     Flags &= ~FlagIndirectVirtualBase;
     111           1 :     SplitFlags.push_back(FlagIndirectVirtualBase);
     112             :   }
     113             : 
     114             : #define HANDLE_DI_FLAG(ID, NAME)                                               \
     115             :   if (DIFlags Bit = Flags & Flag##NAME) {                                      \
     116             :     SplitFlags.push_back(Bit);                                                 \
     117             :     Flags &= ~Bit;                                                             \
     118             :   }
     119             : #include "llvm/IR/DebugInfoFlags.def"
     120        5162 :   return Flags;
     121             : }
     122             : 
     123       16587 : DIScopeRef DIScope::getScope() const {
     124       16587 :   if (auto *T = dyn_cast<DIType>(this))
     125             :     return T->getScope();
     126             : 
     127       12411 :   if (auto *SP = dyn_cast<DISubprogram>(this))
     128             :     return SP->getScope();
     129             : 
     130       12346 :   if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
     131        6732 :     return LB->getScope();
     132             : 
     133        5614 :   if (auto *NS = dyn_cast<DINamespace>(this))
     134        5261 :     return NS->getScope();
     135             : 
     136         353 :   if (auto *M = dyn_cast<DIModule>(this))
     137          12 :     return M->getScope();
     138             : 
     139             :   assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
     140             :          "Unhandled type of scope.");
     141         341 :   return nullptr;
     142             : }
     143             : 
     144        7330 : StringRef DIScope::getName() const {
     145        7330 :   if (auto *T = dyn_cast<DIType>(this))
     146             :     return T->getName();
     147        5054 :   if (auto *SP = dyn_cast<DISubprogram>(this))
     148             :     return SP->getName();
     149        5018 :   if (auto *NS = dyn_cast<DINamespace>(this))
     150             :     return NS->getName();
     151         349 :   if (auto *M = dyn_cast<DIModule>(this))
     152             :     return M->getName();
     153             :   assert((isa<DILexicalBlockBase>(this) || isa<DIFile>(this) ||
     154             :           isa<DICompileUnit>(this)) &&
     155             :          "Unhandled type of scope.");
     156         337 :   return "";
     157             : }
     158             : 
     159             : #ifndef NDEBUG
     160             : static bool isCanonical(const MDString *S) {
     161             :   return !S || !S->getString().empty();
     162             : }
     163             : #endif
     164             : 
     165          61 : GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag,
     166             :                                       MDString *Header,
     167             :                                       ArrayRef<Metadata *> DwarfOps,
     168             :                                       StorageType Storage, bool ShouldCreate) {
     169          61 :   unsigned Hash = 0;
     170          61 :   if (Storage == Uniqued) {
     171          49 :     GenericDINodeInfo::KeyTy Key(Tag, Header, DwarfOps);
     172          62 :     if (auto *N = getUniqued(Context.pImpl->GenericDINodes, Key))
     173          13 :       return N;
     174          36 :     if (!ShouldCreate)
     175             :       return nullptr;
     176          36 :     Hash = Key.getHash();
     177             :   } else {
     178             :     assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
     179             :   }
     180             : 
     181             :   // Use a nullptr for empty headers.
     182             :   assert(isCanonical(Header) && "Expected canonical MDString");
     183          48 :   Metadata *PreOps[] = {Header};
     184          96 :   return storeImpl(new (DwarfOps.size() + 1) GenericDINode(
     185         144 :                        Context, Storage, Hash, Tag, PreOps, DwarfOps),
     186          96 :                    Storage, Context.pImpl->GenericDINodes);
     187             : }
     188             : 
     189          15 : void GenericDINode::recalculateHash() {
     190          30 :   setHash(GenericDINodeInfo::KeyTy::calculateHash(this));
     191          15 : }
     192             : 
     193             : #define UNWRAP_ARGS_IMPL(...) __VA_ARGS__
     194             : #define UNWRAP_ARGS(ARGS) UNWRAP_ARGS_IMPL ARGS
     195             : #define DEFINE_GETIMPL_LOOKUP(CLASS, ARGS)                                     \
     196             :   do {                                                                         \
     197             :     if (Storage == Uniqued) {                                                  \
     198             :       if (auto *N = getUniqued(Context.pImpl->CLASS##s,                        \
     199             :                                CLASS##Info::KeyTy(UNWRAP_ARGS(ARGS))))         \
     200             :         return N;                                                              \
     201             :       if (!ShouldCreate)                                                       \
     202             :         return nullptr;                                                        \
     203             :     } else {                                                                   \
     204             :       assert(ShouldCreate &&                                                   \
     205             :              "Expected non-uniqued nodes to always be created");               \
     206             :     }                                                                          \
     207             :   } while (false)
     208             : #define DEFINE_GETIMPL_STORE(CLASS, ARGS, OPS)                                 \
     209             :   return storeImpl(new (array_lengthof(OPS))                                   \
     210             :                        CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS),        \
     211             :                    Storage, Context.pImpl->CLASS##s)
     212             : #define DEFINE_GETIMPL_STORE_NO_OPS(CLASS, ARGS)                               \
     213             :   return storeImpl(new (0u) CLASS(Context, Storage, UNWRAP_ARGS(ARGS)),        \
     214             :                    Storage, Context.pImpl->CLASS##s)
     215             : #define DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(CLASS, OPS)                   \
     216             :   return storeImpl(new (array_lengthof(OPS)) CLASS(Context, Storage, OPS),     \
     217             :                    Storage, Context.pImpl->CLASS##s)
     218             : #define DEFINE_GETIMPL_STORE_N(CLASS, ARGS, OPS, NUM_OPS)                      \
     219             :   return storeImpl(new (NUM_OPS)                                               \
     220             :                        CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS),        \
     221             :                    Storage, Context.pImpl->CLASS##s)
     222             : 
     223         561 : DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo,
     224             :                                 StorageType Storage, bool ShouldCreate) {
     225        1681 :   DEFINE_GETIMPL_LOOKUP(DISubrange, (Count, Lo));
     226         994 :   DEFINE_GETIMPL_STORE_NO_OPS(DISubrange, (Count, Lo));
     227             : }
     228             : 
     229        6078 : DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, int64_t Value,
     230             :                                     MDString *Name, StorageType Storage,
     231             :                                     bool ShouldCreate) {
     232             :   assert(isCanonical(Name) && "Expected canonical MDString");
     233       18232 :   DEFINE_GETIMPL_LOOKUP(DIEnumerator, (Value, Name));
     234        6065 :   Metadata *Ops[] = {Name};
     235       12130 :   DEFINE_GETIMPL_STORE(DIEnumerator, (Value), Ops);
     236             : }
     237             : 
     238        2255 : DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
     239             :                                   MDString *Name, uint64_t SizeInBits,
     240             :                                   uint32_t AlignInBits, unsigned Encoding,
     241             :                                   StorageType Storage, bool ShouldCreate) {
     242             :   assert(isCanonical(Name) && "Expected canonical MDString");
     243        6761 :   DEFINE_GETIMPL_LOOKUP(DIBasicType,
     244             :                         (Tag, Name, SizeInBits, AlignInBits, Encoding));
     245        2215 :   Metadata *Ops[] = {nullptr, nullptr, Name};
     246        4430 :   DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding),
     247             :                        Ops);
     248             : }
     249             : 
     250       43588 : DIDerivedType *DIDerivedType::getImpl(
     251             :     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
     252             :     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
     253             :     uint32_t AlignInBits, uint64_t OffsetInBits,
     254             :     Optional<unsigned> DWARFAddressSpace, DIFlags Flags, Metadata *ExtraData,
     255             :     StorageType Storage, bool ShouldCreate) {
     256             :   assert(isCanonical(Name) && "Expected canonical MDString");
     257      194613 :   DEFINE_GETIMPL_LOOKUP(DIDerivedType,
     258             :                         (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     259             :                          AlignInBits, OffsetInBits, DWARFAddressSpace, Flags,
     260             :                          ExtraData));
     261       31604 :   Metadata *Ops[] = {File, Scope, Name, BaseType, ExtraData};
     262      126416 :   DEFINE_GETIMPL_STORE(
     263             :       DIDerivedType, (Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
     264             :                       DWARFAddressSpace, Flags), Ops);
     265             : }
     266             : 
     267        5218 : DICompositeType *DICompositeType::getImpl(
     268             :     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
     269             :     unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
     270             :     uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags,
     271             :     Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
     272             :     Metadata *TemplateParams, MDString *Identifier, StorageType Storage,
     273             :     bool ShouldCreate) {
     274             :   assert(isCanonical(Name) && "Expected canonical MDString");
     275             : 
     276             :   // Keep this in sync with buildODRType.
     277        8036 :   DEFINE_GETIMPL_LOOKUP(
     278             :       DICompositeType, (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     279             :                         AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
     280             :                         VTableHolder, TemplateParams, Identifier));
     281             :   Metadata *Ops[] = {File,     Scope,        Name,           BaseType,
     282        5197 :                      Elements, VTableHolder, TemplateParams, Identifier};
     283       10394 :   DEFINE_GETIMPL_STORE(DICompositeType, (Tag, Line, RuntimeLang, SizeInBits,
     284             :                                          AlignInBits, OffsetInBits, Flags),
     285             :                        Ops);
     286             : }
     287             : 
     288         461 : DICompositeType *DICompositeType::buildODRType(
     289             :     LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
     290             :     Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
     291             :     uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
     292             :     DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
     293             :     Metadata *VTableHolder, Metadata *TemplateParams) {
     294             :   assert(!Identifier.getString().empty() && "Expected valid identifier");
     295         461 :   if (!Context.isODRUniquingDebugTypes())
     296             :     return nullptr;
     297         360 :   auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
     298         120 :   if (!CT)
     299          88 :     return CT = DICompositeType::getDistinct(
     300             :                Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     301             :                AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
     302          88 :                VTableHolder, TemplateParams, &Identifier);
     303             : 
     304             :   // Only mutate CT if it's a forward declaration and the new operands aren't.
     305             :   assert(CT->getRawIdentifier() == &Identifier && "Wrong ODR identifier?");
     306          75 :   if (!CT->isForwardDecl() || (Flags & DINode::FlagFwdDecl))
     307             :     return CT;
     308             : 
     309             :   // Mutate CT in place.  Keep this in sync with getImpl.
     310           8 :   CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
     311             :              Flags);
     312             :   Metadata *Ops[] = {File,     Scope,        Name,           BaseType,
     313           4 :                      Elements, VTableHolder, TemplateParams, &Identifier};
     314             :   assert((std::end(Ops) - std::begin(Ops)) == (int)CT->getNumOperands() &&
     315             :          "Mismatched number of operands");
     316          36 :   for (unsigned I = 0, E = CT->getNumOperands(); I != E; ++I)
     317          96 :     if (Ops[I] != CT->getOperand(I))
     318           9 :       CT->setOperand(I, Ops[I]);
     319           4 :   return CT;
     320             : }
     321             : 
     322           4 : DICompositeType *DICompositeType::getODRType(
     323             :     LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
     324             :     Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
     325             :     uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
     326             :     DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
     327             :     Metadata *VTableHolder, Metadata *TemplateParams) {
     328             :   assert(!Identifier.getString().empty() && "Expected valid identifier");
     329           4 :   if (!Context.isODRUniquingDebugTypes())
     330             :     return nullptr;
     331           9 :   auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier];
     332           3 :   if (!CT)
     333           1 :     CT = DICompositeType::getDistinct(
     334             :         Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
     335             :         AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
     336             :         TemplateParams, &Identifier);
     337           3 :   return CT;
     338             : }
     339             : 
     340           5 : DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context,
     341             :                                                      MDString &Identifier) {
     342             :   assert(!Identifier.getString().empty() && "Expected valid identifier");
     343           5 :   if (!Context.isODRUniquingDebugTypes())
     344             :     return nullptr;
     345          12 :   return Context.pImpl->DITypeMap->lookup(&Identifier);
     346             : }
     347             : 
     348       48992 : DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,
     349             :                                             uint8_t CC, Metadata *TypeArray,
     350             :                                             StorageType Storage,
     351             :                                             bool ShouldCreate) {
     352      146962 :   DEFINE_GETIMPL_LOOKUP(DISubroutineType, (Flags, CC, TypeArray));
     353       20955 :   Metadata *Ops[] = {nullptr, nullptr, nullptr, TypeArray};
     354       41910 :   DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops);
     355             : }
     356             : 
     357             : static const char *ChecksumKindName[DIFile::CSK_Last + 1] = {
     358             :   "CSK_None",
     359             :   "CSK_MD5",
     360             :   "CSK_SHA1"
     361             : };
     362             : 
     363          24 : DIFile::ChecksumKind DIFile::getChecksumKind(StringRef CSKindStr) {
     364          24 :   return StringSwitch<DIFile::ChecksumKind>(CSKindStr)
     365          72 :       .Case("CSK_MD5", DIFile::CSK_MD5)
     366          72 :       .Case("CSK_SHA1", DIFile::CSK_SHA1)
     367          72 :       .Default(DIFile::CSK_None);
     368             : }
     369             : 
     370          34 : StringRef DIFile::getChecksumKindAsString() const {
     371             :   assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind");
     372          68 :   return ChecksumKindName[CSKind];
     373             : }
     374             : 
     375       10785 : DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename,
     376             :                         MDString *Directory, DIFile::ChecksumKind CSKind,
     377             :                         MDString *Checksum, StorageType Storage,
     378             :                         bool ShouldCreate) {
     379             :   assert(isCanonical(Filename) && "Expected canonical MDString");
     380             :   assert(isCanonical(Directory) && "Expected canonical MDString");
     381             :   assert(isCanonical(Checksum) && "Expected canonical MDString");
     382       32287 :   DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CSKind, Checksum));
     383        6048 :   Metadata *Ops[] = {Filename, Directory, Checksum};
     384       12096 :   DEFINE_GETIMPL_STORE(DIFile, (CSKind), Ops);
     385             : }
     386             : 
     387        2545 : DICompileUnit *DICompileUnit::getImpl(
     388             :     LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
     389             :     MDString *Producer, bool IsOptimized, MDString *Flags,
     390             :     unsigned RuntimeVersion, MDString *SplitDebugFilename,
     391             :     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
     392             :     Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
     393             :     uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
     394             :     bool GnuPubnames, StorageType Storage, bool ShouldCreate) {
     395             :   assert(Storage != Uniqued && "Cannot unique DICompileUnit");
     396             :   assert(isCanonical(Producer) && "Expected canonical MDString");
     397             :   assert(isCanonical(Flags) && "Expected canonical MDString");
     398             :   assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
     399             : 
     400             :   Metadata *Ops[] = {
     401             :       File,      Producer,      Flags,           SplitDebugFilename,
     402             :       EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
     403        2545 :       Macros};
     404             :   return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
     405             :                        Context, Storage, SourceLanguage, IsOptimized,
     406             :                        RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
     407        5090 :                        DebugInfoForProfiling, GnuPubnames, Ops),
     408        2545 :                    Storage);
     409             : }
     410             : 
     411             : Optional<DICompileUnit::DebugEmissionKind>
     412        1249 : DICompileUnit::getEmissionKind(StringRef Str) {
     413        1249 :   return StringSwitch<Optional<DebugEmissionKind>>(Str)
     414        4996 :       .Case("NoDebug", NoDebug)
     415        4996 :       .Case("FullDebug", FullDebug)
     416        4996 :       .Case("LineTablesOnly", LineTablesOnly)
     417        4996 :       .Default(None);
     418             : }
     419             : 
     420         873 : const char *DICompileUnit::EmissionKindString(DebugEmissionKind EK) {
     421         873 :   switch (EK) {
     422             :   case NoDebug:        return "NoDebug";
     423         590 :   case FullDebug:      return "FullDebug";
     424         179 :   case LineTablesOnly: return "LineTablesOnly";
     425             :   }
     426           0 :   return nullptr;
     427             : }
     428             : 
     429     1327972 : DISubprogram *DILocalScope::getSubprogram() const {
     430       65160 :   if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
     431       65160 :     return Block->getScope()->getSubprogram();
     432             :   return const_cast<DISubprogram *>(cast<DISubprogram>(this));
     433             : }
     434             : 
     435     2669112 : DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
     436         390 :   if (auto *File = dyn_cast<DILexicalBlockFile>(this))
     437         780 :     return File->getScope()->getNonLexicalBlockFileScope();
     438             :   return const_cast<DILocalScope *>(this);
     439             : }
     440             : 
     441       46972 : DISubprogram *DISubprogram::getImpl(
     442             :     LLVMContext &Context, Metadata *Scope, MDString *Name,
     443             :     MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
     444             :     bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
     445             :     Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
     446             :     int ThisAdjustment, DIFlags Flags, bool IsOptimized, Metadata *Unit,
     447             :     Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
     448             :     Metadata *ThrownTypes, StorageType Storage, bool ShouldCreate) {
     449             :   assert(isCanonical(Name) && "Expected canonical MDString");
     450             :   assert(isCanonical(LinkageName) && "Expected canonical MDString");
     451       70914 :   DEFINE_GETIMPL_LOOKUP(
     452             :       DISubprogram, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
     453             :                      IsDefinition, ScopeLine, ContainingType, Virtuality,
     454             :                      VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit,
     455             :                      TemplateParams, Declaration, Variables, ThrownTypes));
     456             :   SmallVector<Metadata *, 11> Ops = {
     457             :       File,        Scope,     Name,           LinkageName,    Type,       Unit,
     458       93928 :       Declaration, Variables, ContainingType, TemplateParams, ThrownTypes};
     459       46964 :   if (!ThrownTypes) {
     460       46929 :     Ops.pop_back();
     461       46929 :     if (!TemplateParams) {
     462       44434 :       Ops.pop_back();
     463       44434 :       if (!ContainingType)
     464             :         Ops.pop_back();
     465             :     }
     466             :   }
     467      187856 :   DEFINE_GETIMPL_STORE_N(DISubprogram,
     468             :                          (Line, ScopeLine, Virtuality, VirtualIndex,
     469             :                           ThisAdjustment, Flags, IsLocalToUnit, IsDefinition,
     470             :                           IsOptimized),
     471             :                          Ops, Ops.size());
     472             : }
     473             : 
     474       16713 : bool DISubprogram::describes(const Function *F) const {
     475             :   assert(F && "Invalid function");
     476       16713 :   if (F->getSubprogram() == this)
     477             :     return true;
     478        9329 :   StringRef Name = getLinkageName();
     479        9329 :   if (Name.empty())
     480          45 :     Name = getName();
     481        9329 :   return F->getName() == Name;
     482             : }
     483             : 
     484        4479 : DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
     485             :                                         Metadata *File, unsigned Line,
     486             :                                         unsigned Column, StorageType Storage,
     487             :                                         bool ShouldCreate) {
     488             :   // Fixup column.
     489        4479 :   adjustColumn(Column);
     490             : 
     491             :   assert(Scope && "Expected scope");
     492        4561 :   DEFINE_GETIMPL_LOOKUP(DILexicalBlock, (Scope, File, Line, Column));
     493        4475 :   Metadata *Ops[] = {File, Scope};
     494        8950 :   DEFINE_GETIMPL_STORE(DILexicalBlock, (Line, Column), Ops);
     495             : }
     496             : 
     497         906 : DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
     498             :                                                 Metadata *Scope, Metadata *File,
     499             :                                                 unsigned Discriminator,
     500             :                                                 StorageType Storage,
     501             :                                                 bool ShouldCreate) {
     502             :   assert(Scope && "Expected scope");
     503        2716 :   DEFINE_GETIMPL_LOOKUP(DILexicalBlockFile, (Scope, File, Discriminator));
     504         456 :   Metadata *Ops[] = {File, Scope};
     505         912 :   DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops);
     506             : }
     507             : 
     508        1380 : DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
     509             :                                   MDString *Name, bool ExportSymbols,
     510             :                                   StorageType Storage, bool ShouldCreate) {
     511             :   assert(isCanonical(Name) && "Expected canonical MDString");
     512        4138 :   DEFINE_GETIMPL_LOOKUP(DINamespace, (Scope, Name, ExportSymbols));
     513             :   // The nullptr is for DIScope's File operand. This should be refactored.
     514         388 :   Metadata *Ops[] = {nullptr, Scope, Name};
     515         776 :   DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops);
     516             : }
     517             : 
     518          92 : DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *Scope,
     519             :                             MDString *Name, MDString *ConfigurationMacros,
     520             :                             MDString *IncludePath, MDString *ISysRoot,
     521             :                             StorageType Storage, bool ShouldCreate) {
     522             :   assert(isCanonical(Name) && "Expected canonical MDString");
     523         274 :   DEFINE_GETIMPL_LOOKUP(
     524             :       DIModule, (Scope, Name, ConfigurationMacros, IncludePath, ISysRoot));
     525          85 :   Metadata *Ops[] = {Scope, Name, ConfigurationMacros, IncludePath, ISysRoot};
     526         170 :   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIModule, Ops);
     527             : }
     528             : 
     529        5599 : DITemplateTypeParameter *DITemplateTypeParameter::getImpl(LLVMContext &Context,
     530             :                                                           MDString *Name,
     531             :                                                           Metadata *Type,
     532             :                                                           StorageType Storage,
     533             :                                                           bool ShouldCreate) {
     534             :   assert(isCanonical(Name) && "Expected canonical MDString");
     535       16793 :   DEFINE_GETIMPL_LOOKUP(DITemplateTypeParameter, (Name, Type));
     536        1893 :   Metadata *Ops[] = {Name, Type};
     537        3786 :   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DITemplateTypeParameter, Ops);
     538             : }
     539             : 
     540        1480 : DITemplateValueParameter *DITemplateValueParameter::getImpl(
     541             :     LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *Type,
     542             :     Metadata *Value, StorageType Storage, bool ShouldCreate) {
     543             :   assert(isCanonical(Name) && "Expected canonical MDString");
     544        4436 :   DEFINE_GETIMPL_LOOKUP(DITemplateValueParameter, (Tag, Name, Type, Value));
     545         653 :   Metadata *Ops[] = {Name, Type, Value};
     546        1306 :   DEFINE_GETIMPL_STORE(DITemplateValueParameter, (Tag), Ops);
     547             : }
     548             : 
     549             : DIGlobalVariable *
     550        1149 : DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
     551             :                           MDString *LinkageName, Metadata *File, unsigned Line,
     552             :                           Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
     553             :                           Metadata *StaticDataMemberDeclaration,
     554             :                           uint32_t AlignInBits, StorageType Storage,
     555             :                           bool ShouldCreate) {
     556             :   assert(isCanonical(Name) && "Expected canonical MDString");
     557             :   assert(isCanonical(LinkageName) && "Expected canonical MDString");
     558        2261 :   DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
     559             :                         (Scope, Name, LinkageName, File, Line, Type,
     560             :                          IsLocalToUnit, IsDefinition,
     561             :                          StaticDataMemberDeclaration, AlignInBits));
     562             :   Metadata *Ops[] = {
     563        1148 :       Scope, Name, File, Type, Name, LinkageName, StaticDataMemberDeclaration};
     564        2296 :   DEFINE_GETIMPL_STORE(DIGlobalVariable,
     565             :                        (Line, IsLocalToUnit, IsDefinition, AlignInBits),
     566             :                        Ops);
     567             : }
     568             : 
     569       14575 : DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
     570             :                                           MDString *Name, Metadata *File,
     571             :                                           unsigned Line, Metadata *Type,
     572             :                                           unsigned Arg, DIFlags Flags,
     573             :                                           uint32_t AlignInBits,
     574             :                                           StorageType Storage,
     575             :                                           bool ShouldCreate) {
     576             :   // 64K ought to be enough for any frontend.
     577             :   assert(Arg <= UINT16_MAX && "Expected argument number to fit in 16-bits");
     578             : 
     579             :   assert(Scope && "Expected scope");
     580             :   assert(isCanonical(Name) && "Expected canonical MDString");
     581       43683 :   DEFINE_GETIMPL_LOOKUP(DILocalVariable,
     582             :                         (Scope, Name, File, Line, Type, Arg, Flags,
     583             :                          AlignInBits));
     584       14488 :   Metadata *Ops[] = {Scope, Name, File, Type};
     585       28976 :   DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
     586             : }
     587             : 
     588       18593 : DIExpression *DIExpression::getImpl(LLVMContext &Context,
     589             :                                     ArrayRef<uint64_t> Elements,
     590             :                                     StorageType Storage, bool ShouldCreate) {
     591       55777 :   DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements));
     592        1849 :   DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements));
     593             : }
     594             : 
     595       28498 : unsigned DIExpression::ExprOperand::getSize() const {
     596       28498 :   switch (getOp()) {
     597             :   case dwarf::DW_OP_LLVM_fragment:
     598             :     return 3;
     599       15685 :   case dwarf::DW_OP_constu:
     600             :   case dwarf::DW_OP_plus_uconst:
     601       15685 :     return 2;
     602       11101 :   default:
     603       11101 :     return 1;
     604             :   }
     605             : }
     606             : 
     607       18020 : bool DIExpression::isValid() const {
     608       56056 :   for (auto I = expr_op_begin(), E = expr_op_end(); I != E; ++I) {
     609             :     // Check that there's space for the operand.
     610        2641 :     if (I->get() + I->getSize() > E->get())
     611         645 :       return false;
     612             : 
     613             :     // Check that the operand is valid.
     614        5276 :     switch (I->getOp()) {
     615             :     default:
     616             :       return false;
     617         635 :     case dwarf::DW_OP_LLVM_fragment:
     618             :       // A fragment operator must appear at the end.
     619         635 :       return I->get() + I->getSize() == E->get();
     620         208 :     case dwarf::DW_OP_stack_value: {
     621             :       // Must be the last one or followed by a DW_OP_LLVM_fragment.
     622         208 :       if (I->get() + I->getSize() == E->get())
     623             :         break;
     624          54 :       auto J = I;
     625         108 :       if ((++J)->getOp() != dwarf::DW_OP_LLVM_fragment)
     626           0 :         return false;
     627             :       break;
     628             :     }
     629         163 :     case dwarf::DW_OP_swap: {
     630             :       // Must be more than one implicit element on the stack.
     631             : 
     632             :       // FIXME: A better way to implement this would be to add a local variable
     633             :       // that keeps track of the stack depth and introduce something like a
     634             :       // DW_LLVM_OP_implicit_location as a placeholder for the location this
     635             :       // DIExpression is attached to, or else pass the number of implicit stack
     636             :       // elements into isValid.
     637         163 :       if (getNumElements() == 1)
     638             :         return false;
     639             :       break;
     640             :     }
     641             :     case dwarf::DW_OP_constu:
     642             :     case dwarf::DW_OP_plus_uconst:
     643             :     case dwarf::DW_OP_plus:
     644             :     case dwarf::DW_OP_minus:
     645             :     case dwarf::DW_OP_deref:
     646             :     case dwarf::DW_OP_xderef:
     647             :       break;
     648             :     }
     649             :   }
     650       17375 :   return true;
     651             : }
     652             : 
     653             : Optional<DIExpression::FragmentInfo>
     654       89904 : DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
     655      195436 :   for (auto I = Start; I != End; ++I)
     656       35862 :     if (I->getOp() == dwarf::DW_OP_LLVM_fragment) {
     657        6909 :       DIExpression::FragmentInfo Info = {I->getArg(1), I->getArg(0)};
     658        2303 :       return Info;
     659             :     }
     660             :   return None;
     661             : }
     662             : 
     663        3351 : void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
     664             :                                 int64_t Offset) {
     665        3351 :   if (Offset > 0) {
     666        1438 :     Ops.push_back(dwarf::DW_OP_plus_uconst);
     667        1438 :     Ops.push_back(Offset);
     668        1913 :   } else if (Offset < 0) {
     669          39 :     Ops.push_back(dwarf::DW_OP_constu);
     670          39 :     Ops.push_back(-Offset);
     671          39 :     Ops.push_back(dwarf::DW_OP_minus);
     672             :   }
     673        3351 : }
     674             : 
     675          95 : bool DIExpression::extractIfOffset(int64_t &Offset) const {
     676          95 :   if (getNumElements() == 0) {
     677          89 :     Offset = 0;
     678          89 :     return true;
     679             :   }
     680             : 
     681           6 :   if (getNumElements() == 2 && Elements[0] == dwarf::DW_OP_plus_uconst) {
     682           6 :     Offset = Elements[1];
     683           6 :     return true;
     684             :   }
     685             : 
     686           0 :   if (getNumElements() == 3 && Elements[0] == dwarf::DW_OP_constu) {
     687           0 :     if (Elements[2] == dwarf::DW_OP_plus) {
     688           0 :       Offset = Elements[1];
     689           0 :       return true;
     690             :     }
     691           0 :     if (Elements[2] == dwarf::DW_OP_minus) {
     692           0 :       Offset = -Elements[1];
     693           0 :       return true;
     694             :     }
     695             :   }
     696             : 
     697             :   return false;
     698             : }
     699             : 
     700        3349 : DIExpression *DIExpression::prepend(const DIExpression *Expr, bool Deref,
     701             :                                     int64_t Offset, bool StackValue) {
     702        6698 :   SmallVector<uint64_t, 8> Ops;
     703        3349 :   appendOffset(Ops, Offset);
     704        3349 :   if (Deref)
     705         396 :     Ops.push_back(dwarf::DW_OP_deref);
     706        3349 :   if (Expr)
     707        7877 :     for (auto Op : Expr->expr_ops()) {
     708             :       // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
     709        1179 :       if (StackValue) {
     710         941 :         if (Op.getOp() == dwarf::DW_OP_stack_value)
     711             :           StackValue = false;
     712         275 :         else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
     713           1 :           Ops.push_back(dwarf::DW_OP_stack_value);
     714           1 :           StackValue = false;
     715             :         }
     716             :       }
     717        1179 :       Ops.push_back(Op.getOp());
     718        2874 :       for (unsigned I = 0; I < Op.getNumArgs(); ++I)
     719         258 :         Ops.push_back(Op.getArg(I));
     720             :     }
     721        3349 :   if (StackValue)
     722        1310 :     Ops.push_back(dwarf::DW_OP_stack_value);
     723       13396 :   return DIExpression::get(Expr->getContext(), Ops);
     724             : }
     725             : 
     726         124 : DIExpression *DIExpression::createFragmentExpression(const DIExpression *Expr,
     727             :                                                      unsigned OffsetInBits,
     728             :                                                      unsigned SizeInBits) {
     729         248 :   SmallVector<uint64_t, 8> Ops;
     730             :   // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
     731         124 :   if (Expr) {
     732         248 :     for (auto Op : Expr->expr_ops()) {
     733          15 :       if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
     734             :         // Make the new offset point into the existing fragment.
     735          15 :         uint64_t FragmentOffsetInBits = Op.getArg(0);
     736             :         // Op.getArg(0) is FragmentOffsetInBits.
     737             :         // Op.getArg(1) is FragmentSizeInBits.
     738             :         assert((OffsetInBits + SizeInBits <= Op.getArg(0) + Op.getArg(1)) &&
     739             :                "new fragment outside of original fragment");
     740          15 :         OffsetInBits += FragmentOffsetInBits;
     741          15 :         break;
     742             :       }
     743           0 :       Ops.push_back(Op.getOp());
     744           0 :       for (unsigned I = 0; I < Op.getNumArgs(); ++I)
     745           0 :         Ops.push_back(Op.getArg(I));
     746             :     }
     747             :   }
     748         124 :   Ops.push_back(dwarf::DW_OP_LLVM_fragment);
     749         124 :   Ops.push_back(OffsetInBits);
     750         124 :   Ops.push_back(SizeInBits);
     751         496 :   return DIExpression::get(Expr->getContext(), Ops);
     752             : }
     753             : 
     754         862 : bool DIExpression::isConstant() const {
     755             :   // Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
     756        1715 :   if (getNumElements() != 3 && getNumElements() != 6)
     757             :     return false;
     758          37 :   if (getElement(0) != dwarf::DW_OP_constu ||
     759          17 :       getElement(2) != dwarf::DW_OP_stack_value)
     760             :     return false;
     761          28 :   if (getNumElements() == 6 && getElement(3) != dwarf::DW_OP_LLVM_fragment)
     762             :     return false;
     763             :   return true;
     764             : }
     765             : 
     766             : DIGlobalVariableExpression *
     767        1121 : DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
     768             :                                     Metadata *Expression, StorageType Storage,
     769             :                                     bool ShouldCreate) {
     770        3181 :   DEFINE_GETIMPL_LOOKUP(DIGlobalVariableExpression, (Variable, Expression));
     771        1119 :   Metadata *Ops[] = {Variable, Expression};
     772        2238 :   DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops);
     773             : }
     774             : 
     775         125 : DIObjCProperty *DIObjCProperty::getImpl(
     776             :     LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line,
     777             :     MDString *GetterName, MDString *SetterName, unsigned Attributes,
     778             :     Metadata *Type, StorageType Storage, bool ShouldCreate) {
     779             :   assert(isCanonical(Name) && "Expected canonical MDString");
     780             :   assert(isCanonical(GetterName) && "Expected canonical MDString");
     781             :   assert(isCanonical(SetterName) && "Expected canonical MDString");
     782         373 :   DEFINE_GETIMPL_LOOKUP(DIObjCProperty, (Name, File, Line, GetterName,
     783             :                                          SetterName, Attributes, Type));
     784          92 :   Metadata *Ops[] = {Name, File, GetterName, SetterName, Type};
     785         184 :   DEFINE_GETIMPL_STORE(DIObjCProperty, (Line, Attributes), Ops);
     786             : }
     787             : 
     788        7031 : DIImportedEntity *DIImportedEntity::getImpl(LLVMContext &Context, unsigned Tag,
     789             :                                             Metadata *Scope, Metadata *Entity,
     790             :                                             Metadata *File, unsigned Line,
     791             :                                             MDString *Name, StorageType Storage,
     792             :                                             bool ShouldCreate) {
     793             :   assert(isCanonical(Name) && "Expected canonical MDString");
     794       21091 :   DEFINE_GETIMPL_LOOKUP(DIImportedEntity,
     795             :                         (Tag, Scope, Entity, File, Line, Name));
     796        7025 :   Metadata *Ops[] = {Scope, Entity, Name, File};
     797       14050 :   DEFINE_GETIMPL_STORE(DIImportedEntity, (Tag, Line), Ops);
     798             : }
     799             : 
     800        1103 : DIMacro *DIMacro::getImpl(LLVMContext &Context, unsigned MIType,
     801             :                           unsigned Line, MDString *Name, MDString *Value,
     802             :                           StorageType Storage, bool ShouldCreate) {
     803             :   assert(isCanonical(Name) && "Expected canonical MDString");
     804        3309 :   DEFINE_GETIMPL_LOOKUP(DIMacro, (MIType, Line, Name, Value));
     805        1094 :   Metadata *Ops[] = { Name, Value };
     806        2188 :   DEFINE_GETIMPL_STORE(DIMacro, (MIType, Line), Ops);
     807             : }
     808             : 
     809          84 : DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType,
     810             :                                   unsigned Line, Metadata *File,
     811             :                                   Metadata *Elements, StorageType Storage,
     812             :                                   bool ShouldCreate) {
     813         216 :   DEFINE_GETIMPL_LOOKUP(DIMacroFile,
     814             :                         (MIType, Line, File, Elements));
     815          82 :   Metadata *Ops[] = { File, Elements };
     816         164 :   DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops);
     817             : }
     818             : 

Generated by: LCOV version 1.13