LCOV - code coverage report
Current view: top level - lib/IR - DIBuilder.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 343 365 94.0 %
Date: 2017-09-14 15:23:50 Functions: 70 74 94.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
       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 DIBuilder.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/IR/DIBuilder.h"
      15             : #include "LLVMContextImpl.h"
      16             : #include "llvm/ADT/STLExtras.h"
      17             : #include "llvm/BinaryFormat/Dwarf.h"
      18             : #include "llvm/IR/Constants.h"
      19             : #include "llvm/IR/DebugInfo.h"
      20             : #include "llvm/IR/IntrinsicInst.h"
      21             : #include "llvm/IR/Module.h"
      22             : #include "llvm/Support/Debug.h"
      23             : 
      24             : using namespace llvm;
      25             : using namespace llvm::dwarf;
      26             : 
      27      608218 : DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
      28      608218 :   : M(m), VMContext(M.getContext()), CUNode(nullptr),
      29             :       DeclareFn(nullptr), ValueFn(nullptr),
      30     6082180 :       AllowUnresolvedNodes(AllowUnresolvedNodes) {}
      31             : 
      32       97522 : void DIBuilder::trackIfUnresolved(MDNode *N) {
      33       97522 :   if (!N)
      34             :     return;
      35      105896 :   if (N->isResolved())
      36             :     return;
      37             : 
      38             :   assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
      39        8374 :   UnresolvedNodes.emplace_back(N);
      40             : }
      41             : 
      42       54023 : void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
      43       54023 :   MDTuple *Temp = SP->getVariables().get();
      44       54023 :   if (!Temp || !Temp->isTemporary())
      45       26984 :     return;
      46             : 
      47       54078 :   SmallVector<Metadata *, 4> Variables;
      48             : 
      49       27039 :   auto PV = PreservedVariables.find(SP);
      50       81117 :   if (PV != PreservedVariables.end())
      51       12621 :     Variables.append(PV->second.begin(), PV->second.end());
      52             : 
      53       27039 :   DINodeArray AV = getOrCreateArray(Variables);
      54      135195 :   TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
      55             : }
      56             : 
      57         611 : void DIBuilder::finalize() {
      58         611 :   if (!CUNode) {
      59             :     assert(!AllowUnresolvedNodes &&
      60             :            "creating type nodes without a CU is not supported");
      61           0 :     return;
      62             :   }
      63             : 
      64        2444 :   CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
      65             : 
      66        1222 :   SmallVector<Metadata *, 16> RetainValues;
      67             :   // Declarations and definitions of the same type may be retained. Some
      68             :   // clients RAUW these pairs, leaving duplicates in the retained types
      69             :   // list. Use a set to remove the duplicates while we transform the
      70             :   // TrackingVHs back into Values.
      71        1222 :   SmallPtrSet<Metadata *, 16> RetainSet;
      72        2669 :   for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
      73        4341 :     if (RetainSet.insert(AllRetainTypes[I]).second)
      74        2142 :       RetainValues.push_back(AllRetainTypes[I]);
      75             : 
      76         611 :   if (!RetainValues.empty())
      77         464 :     CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
      78             : 
      79        2444 :   DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
      80       28841 :   for (auto *SP : SPs)
      81       27008 :     finalizeSubprogram(SP);
      82        2547 :   for (auto *N : RetainValues)
      83          31 :     if (auto *SP = dyn_cast<DISubprogram>(N))
      84          31 :       finalizeSubprogram(SP);
      85             : 
      86         611 :   if (!AllGVs.empty())
      87         644 :     CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
      88             : 
      89         611 :   if (!AllImportedModules.empty())
      90         148 :     CUNode->replaceImportedEntities(MDTuple::get(
      91         111 :         VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
      92             :                                                AllImportedModules.end())));
      93             : 
      94        2467 :   for (const auto &I : AllMacrosPerParent) {
      95             :     // DIMacroNode's with nullptr parent are DICompileUnit direct children.
      96          28 :     if (!I.first) {
      97          20 :       CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
      98           5 :       continue;
      99             :     }
     100             :     // Otherwise, it must be a temporary DIMacroFile that need to be resolved.
     101          36 :     auto *TMF = cast<DIMacroFile>(I.first);
     102          54 :     auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file,
     103             :                                 TMF->getLine(), TMF->getFile(),
     104          18 :                                 getOrCreateMacroArray(I.second.getArrayRef()));
     105          72 :     replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
     106             :   }
     107             : 
     108             :   // Now that all temp nodes have been replaced or deleted, resolve remaining
     109             :   // cycles.
     110       10207 :   for (const auto &N : UnresolvedNodes)
     111       16722 :     if (N && !N->isResolved())
     112           0 :       N->resolveCycles();
     113         611 :   UnresolvedNodes.clear();
     114             : 
     115             :   // Can't handle unresolved nodes anymore.
     116         611 :   AllowUnresolvedNodes = false;
     117             : }
     118             : 
     119             : /// If N is compile unit return NULL otherwise return N.
     120             : static DIScope *getNonCompileUnitScope(DIScope *N) {
     121      124785 :   if (!N || isa<DICompileUnit>(N))
     122             :     return nullptr;
     123             :   return cast<DIScope>(N);
     124             : }
     125             : 
     126         615 : DICompileUnit *DIBuilder::createCompileUnit(
     127             :     unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
     128             :     StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
     129             :     DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
     130             :     bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) {
     131             : 
     132             :   assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
     133             :           (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
     134             :          "Invalid Language tag");
     135             : 
     136             :   assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
     137        1230 :   CUNode = DICompileUnit::getDistinct(
     138             :       VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
     139             :       SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
     140             :       SplitDebugInlining, DebugInfoForProfiling, GnuPubnames);
     141             : 
     142             :   // Create a named metadata so that it is easier to find cu in a module.
     143        1230 :   NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
     144         615 :   NMD->addOperand(CUNode);
     145         615 :   trackIfUnresolved(CUNode);
     146         615 :   return CUNode;
     147             : }
     148             : 
     149             : static DIImportedEntity *
     150        6928 : createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
     151             :                      Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
     152             :                      SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
     153             :   if (Line)
     154             :     assert(File && "Source location has line number but no file");
     155       13856 :   unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
     156             :   auto *M =
     157       13856 :       DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), File, Line, Name);
     158       13856 :   if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
     159             :     // A new Imported Entity was just added to the context.
     160             :     // Add it to the Imported Modules list.
     161        6925 :     AllImportedModules.emplace_back(M);
     162        6928 :   return M;
     163             : }
     164             : 
     165          42 : DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
     166             :                                                   DINamespace *NS, DIFile *File,
     167             :                                                   unsigned Line) {
     168         126 :   return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
     169             :                                 Context, NS, File, Line, StringRef(),
     170         126 :                                 AllImportedModules);
     171             : }
     172             : 
     173           2 : DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
     174             :                                                   DIImportedEntity *NS,
     175             :                                                   DIFile *File, unsigned Line) {
     176           6 :   return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
     177             :                                 Context, NS, File, Line, StringRef(),
     178           6 :                                 AllImportedModules);
     179             : }
     180             : 
     181           0 : DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M,
     182             :                                                   DIFile *File, unsigned Line) {
     183           0 :   return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
     184             :                                 Context, M, File, Line, StringRef(),
     185           0 :                                 AllImportedModules);
     186             : }
     187             : 
     188        6884 : DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context,
     189             :                                                        DINode *Decl,
     190             :                                                        DIFile *File,
     191             :                                                        unsigned Line,
     192             :                                                        StringRef Name) {
     193             :   // Make sure to use the unique identifier based metadata reference for
     194             :   // types that have one.
     195        6884 :   return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
     196             :                                 Context, Decl, File, Line, Name,
     197        6884 :                                 AllImportedModules);
     198             : }
     199             : 
     200        8202 : DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory,
     201             :                               DIFile::ChecksumKind CSKind, StringRef Checksum) {
     202       16404 :   return DIFile::get(VMContext, Filename, Directory, CSKind, Checksum);
     203             : }
     204             : 
     205        1069 : DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
     206             :                                 unsigned MacroType, StringRef Name,
     207             :                                 StringRef Value) {
     208             :   assert(!Name.empty() && "Unable to create macro without name");
     209             :   assert((MacroType == dwarf::DW_MACINFO_undef ||
     210             :           MacroType == dwarf::DW_MACINFO_define) &&
     211             :          "Unexpected macro type");
     212        2138 :   auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
     213        1069 :   AllMacrosPerParent[Parent].insert(M);
     214        1069 :   return M;
     215             : }
     216             : 
     217          18 : DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent,
     218             :                                             unsigned LineNumber, DIFile *File) {
     219          54 :   auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file,
     220          18 :                                        LineNumber, File, DIMacroNodeArray())
     221          18 :                  .release();
     222          18 :   AllMacrosPerParent[Parent].insert(MF);
     223             :   // Add the new temporary DIMacroFile to the macro per parent map as a parent.
     224             :   // This is needed to assure DIMacroFile with no children to have an entry in
     225             :   // the map. Otherwise, it will not be resolved in DIBuilder::finalize().
     226          72 :   AllMacrosPerParent.insert({MF, {}});
     227          18 :   return MF;
     228             : }
     229             : 
     230         277 : DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
     231             :   assert(!Name.empty() && "Unable to create enumerator without name");
     232         554 :   return DIEnumerator::get(VMContext, Val, Name);
     233             : }
     234             : 
     235          39 : DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
     236             :   assert(!Name.empty() && "Unable to create type without name");
     237          78 :   return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
     238             : }
     239             : 
     240          39 : DIBasicType *DIBuilder::createNullPtrType() {
     241          39 :   return createUnspecifiedType("decltype(nullptr)");
     242             : }
     243             : 
     244         928 : DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
     245             :                                         unsigned Encoding) {
     246             :   assert(!Name.empty() && "Unable to create type without name");
     247         928 :   return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
     248         928 :                           0, Encoding);
     249             : }
     250             : 
     251        2064 : DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
     252        6192 :   return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
     253        4128 :                             0, 0, None, DINode::FlagZero);
     254             : }
     255             : 
     256       13675 : DIDerivedType *DIBuilder::createPointerType(
     257             :     DIType *PointeeTy,
     258             :     uint64_t SizeInBits,
     259             :     uint32_t AlignInBits,
     260             :     Optional<unsigned> DWARFAddressSpace,
     261             :     StringRef Name) {
     262             :   // FIXME: Why is there a name here?
     263       41025 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
     264             :                             nullptr, 0, nullptr, PointeeTy, SizeInBits,
     265             :                             AlignInBits, 0, DWARFAddressSpace,
     266       27350 :                             DINode::FlagZero);
     267             : }
     268             : 
     269          38 : DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
     270             :                                                   DIType *Base,
     271             :                                                   uint64_t SizeInBits,
     272             :                                                   uint32_t AlignInBits,
     273             :                                                   DINode::DIFlags Flags) {
     274         114 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
     275             :                             nullptr, 0, nullptr, PointeeTy, SizeInBits,
     276          76 :                             AlignInBits, 0, None, Flags, Base);
     277             : }
     278             : 
     279        3809 : DIDerivedType *DIBuilder::createReferenceType(
     280             :     unsigned Tag, DIType *RTy,
     281             :     uint64_t SizeInBits,
     282             :     uint32_t AlignInBits,
     283             :     Optional<unsigned> DWARFAddressSpace) {
     284             :   assert(RTy && "Unable to create reference type");
     285       11427 :   return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
     286             :                             SizeInBits, AlignInBits, 0, DWARFAddressSpace,
     287        7618 :                             DINode::FlagZero);
     288             : }
     289             : 
     290        4543 : DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
     291             :                                         DIFile *File, unsigned LineNo,
     292             :                                         DIScope *Context) {
     293       18172 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
     294        4543 :                             LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
     295        9086 :                             0, None, DINode::FlagZero);
     296             : }
     297             : 
     298           0 : DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
     299             :   assert(Ty && "Invalid type!");
     300             :   assert(FriendTy && "Invalid friend type!");
     301           0 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
     302           0 :                             FriendTy, 0, 0, 0, None, DINode::FlagZero);
     303             : }
     304             : 
     305         504 : DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
     306             :                                             uint64_t BaseOffset,
     307             :                                             DINode::DIFlags Flags) {
     308             :   assert(Ty && "Unable to create inheritance");
     309        1512 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
     310        1008 :                             0, Ty, BaseTy, 0, 0, BaseOffset, None, Flags);
     311             : }
     312             : 
     313        3363 : DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
     314             :                                            DIFile *File, unsigned LineNumber,
     315             :                                            uint64_t SizeInBits,
     316             :                                            uint32_t AlignInBits,
     317             :                                            uint64_t OffsetInBits,
     318             :                                            DINode::DIFlags Flags, DIType *Ty) {
     319       13452 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
     320        3363 :                             LineNumber, getNonCompileUnitScope(Scope), Ty,
     321        6726 :                             SizeInBits, AlignInBits, OffsetInBits, None, Flags);
     322             : }
     323             : 
     324             : static ConstantAsMetadata *getConstantOrNull(Constant *C) {
     325        1398 :   if (C)
     326        1335 :     return ConstantAsMetadata::get(C);
     327             :   return nullptr;
     328             : }
     329             : 
     330          14 : DIDerivedType *DIBuilder::createBitFieldMemberType(
     331             :     DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
     332             :     uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
     333             :     DINode::DIFlags Flags, DIType *Ty) {
     334          14 :   Flags |= DINode::FlagBitField;
     335          56 :   return DIDerivedType::get(
     336             :       VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
     337          14 :       getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
     338             :       OffsetInBits, None, Flags,
     339          28 :       ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
     340          28 :                                                StorageOffsetInBits)));
     341             : }
     342             : 
     343             : DIDerivedType *
     344         333 : DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
     345             :                                   unsigned LineNumber, DIType *Ty,
     346             :                                   DINode::DIFlags Flags, llvm::Constant *Val,
     347             :                                   uint32_t AlignInBits) {
     348         333 :   Flags |= DINode::FlagStaticMember;
     349        1332 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
     350         333 :                             LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
     351             :                             AlignInBits, 0, None, Flags,
     352         999 :                             getConstantOrNull(Val));
     353             : }
     354             : 
     355             : DIDerivedType *
     356          85 : DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber,
     357             :                           uint64_t SizeInBits, uint32_t AlignInBits,
     358             :                           uint64_t OffsetInBits, DINode::DIFlags Flags,
     359             :                           DIType *Ty, MDNode *PropertyNode) {
     360         340 :   return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
     361          85 :                             LineNumber, getNonCompileUnitScope(File), Ty,
     362             :                             SizeInBits, AlignInBits, OffsetInBits, None, Flags,
     363         170 :                             PropertyNode);
     364             : }
     365             : 
     366             : DIObjCProperty *
     367          76 : DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
     368             :                               StringRef GetterName, StringRef SetterName,
     369             :                               unsigned PropertyAttributes, DIType *Ty) {
     370          76 :   return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
     371          76 :                              SetterName, PropertyAttributes, Ty);
     372             : }
     373             : 
     374             : DITemplateTypeParameter *
     375        5519 : DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name,
     376             :                                        DIType *Ty) {
     377             :   assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
     378       11038 :   return DITemplateTypeParameter::get(VMContext, Name, Ty);
     379             : }
     380             : 
     381             : static DITemplateValueParameter *
     382             : createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
     383             :                                    DIScope *Context, StringRef Name, DIType *Ty,
     384             :                                    Metadata *MD) {
     385             :   assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
     386        2788 :   return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
     387             : }
     388             : 
     389             : DITemplateValueParameter *
     390        1065 : DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name,
     391             :                                         DIType *Ty, Constant *Val) {
     392        1065 :   return createTemplateValueParameterHelper(
     393             :       VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
     394        3195 :       getConstantOrNull(Val));
     395             : }
     396             : 
     397             : DITemplateValueParameter *
     398          31 : DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
     399             :                                            DIType *Ty, StringRef Val) {
     400          31 :   return createTemplateValueParameterHelper(
     401             :       VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
     402          93 :       MDString::get(VMContext, Val));
     403             : }
     404             : 
     405             : DITemplateValueParameter *
     406         298 : DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name,
     407             :                                        DIType *Ty, DINodeArray Val) {
     408         298 :   return createTemplateValueParameterHelper(
     409             :       VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
     410         894 :       Val.get());
     411             : }
     412             : 
     413           0 : DICompositeType *DIBuilder::createClassType(
     414             :     DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
     415             :     uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
     416             :     DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
     417             :     DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
     418             :   assert((!Context || isa<DIScope>(Context)) &&
     419             :          "createClassType should be called with a valid Context");
     420             : 
     421           0 :   auto *R = DICompositeType::get(
     422             :       VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
     423           0 :       getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
     424             :       OffsetInBits, Flags, Elements, 0, VTableHolder,
     425           0 :       cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
     426           0 :   trackIfUnresolved(R);
     427           0 :   return R;
     428             : }
     429             : 
     430         213 : DICompositeType *DIBuilder::createStructType(
     431             :     DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
     432             :     uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
     433             :     DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
     434             :     DIType *VTableHolder, StringRef UniqueIdentifier) {
     435         426 :   auto *R = DICompositeType::get(
     436             :       VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
     437         213 :       getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
     438         213 :       Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
     439         213 :   trackIfUnresolved(R);
     440         213 :   return R;
     441             : }
     442             : 
     443           0 : DICompositeType *DIBuilder::createUnionType(
     444             :     DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
     445             :     uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
     446             :     DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
     447           0 :   auto *R = DICompositeType::get(
     448             :       VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
     449           0 :       getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
     450           0 :       Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
     451           0 :   trackIfUnresolved(R);
     452           0 :   return R;
     453             : }
     454             : 
     455       47263 : DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes,
     456             :                                                   DINode::DIFlags Flags,
     457             :                                                   unsigned CC) {
     458       94526 :   return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
     459             : }
     460             : 
     461         115 : DICompositeType *DIBuilder::createEnumerationType(
     462             :     DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
     463             :     uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
     464             :     DIType *UnderlyingType, StringRef UniqueIdentifier) {
     465         230 :   auto *CTy = DICompositeType::get(
     466             :       VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
     467         115 :       getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
     468         115 :       DINode::FlagZero, Elements, 0, nullptr, nullptr, UniqueIdentifier);
     469         115 :   AllEnumTypes.push_back(CTy);
     470         115 :   trackIfUnresolved(CTy);
     471         115 :   return CTy;
     472             : }
     473             : 
     474         357 : DICompositeType *DIBuilder::createArrayType(uint64_t Size,
     475             :                                             uint32_t AlignInBits, DIType *Ty,
     476             :                                             DINodeArray Subscripts) {
     477         357 :   auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
     478             :                                  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
     479         357 :                                  DINode::FlagZero, Subscripts, 0, nullptr);
     480         357 :   trackIfUnresolved(R);
     481         357 :   return R;
     482             : }
     483             : 
     484          15 : DICompositeType *DIBuilder::createVectorType(uint64_t Size,
     485             :                                              uint32_t AlignInBits, DIType *Ty,
     486             :                                              DINodeArray Subscripts) {
     487          15 :   auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
     488             :                                  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
     489          15 :                                  DINode::FlagVector, Subscripts, 0, nullptr);
     490          15 :   trackIfUnresolved(R);
     491          15 :   return R;
     492             : }
     493             : 
     494       13372 : static DIType *createTypeWithFlags(LLVMContext &Context, DIType *Ty,
     495             :                                    DINode::DIFlags FlagsToSet) {
     496       26744 :   auto NewTy = Ty->clone();
     497       53488 :   NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
     498       66860 :   return MDNode::replaceWithUniqued(std::move(NewTy));
     499             : }
     500             : 
     501         127 : DIType *DIBuilder::createArtificialType(DIType *Ty) {
     502             :   // FIXME: Restrict this to the nodes where it's valid.
     503         127 :   if (Ty->isArtificial())
     504             :     return Ty;
     505         127 :   return createTypeWithFlags(VMContext, Ty, DINode::FlagArtificial);
     506             : }
     507             : 
     508       13245 : DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
     509             :   // FIXME: Restrict this to the nodes where it's valid.
     510       13245 :   if (Ty->isObjectPointer())
     511             :     return Ty;
     512       13245 :   DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
     513       13245 :   return createTypeWithFlags(VMContext, Ty, Flags);
     514             : }
     515             : 
     516        1447 : void DIBuilder::retainType(DIScope *T) {
     517             :   assert(T && "Expected non-null type");
     518             :   assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
     519             :                              cast<DISubprogram>(T)->isDefinition() == false)) &&
     520             :          "Expected type or subprogram declaration");
     521        1447 :   AllRetainTypes.emplace_back(T);
     522        1447 : }
     523             : 
     524         351 : DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
     525             : 
     526             : DICompositeType *
     527          71 : DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
     528             :                              DIFile *F, unsigned Line, unsigned RuntimeLang,
     529             :                              uint64_t SizeInBits, uint32_t AlignInBits,
     530             :                              StringRef UniqueIdentifier) {
     531             :   // FIXME: Define in terms of createReplaceableForwardDecl() by calling
     532             :   // replaceWithUniqued().
     533         142 :   auto *RetTy = DICompositeType::get(
     534          71 :       VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
     535             :       SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
     536          71 :       nullptr, nullptr, UniqueIdentifier);
     537          71 :   trackIfUnresolved(RetTy);
     538          71 :   return RetTy;
     539             : }
     540             : 
     541        3488 : DICompositeType *DIBuilder::createReplaceableCompositeType(
     542             :     unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
     543             :     unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
     544             :     DINode::DIFlags Flags, StringRef UniqueIdentifier) {
     545             :   auto *RetTy =
     546       13952 :       DICompositeType::getTemporary(
     547        3488 :           VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
     548             :           SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
     549             :           nullptr, UniqueIdentifier)
     550        3488 :           .release();
     551        3488 :   trackIfUnresolved(RetTy);
     552        3488 :   return RetTy;
     553             : }
     554             : 
     555       34531 : DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
     556       69062 :   return MDTuple::get(VMContext, Elements);
     557             : }
     558             : 
     559             : DIMacroNodeArray
     560          20 : DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) {
     561          40 :   return MDTuple::get(VMContext, Elements);
     562             : }
     563             : 
     564       47263 : DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
     565       94526 :   SmallVector<llvm::Metadata *, 16> Elts;
     566      117293 :   for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
     567      140060 :     if (Elements[i] && isa<MDNode>(Elements[i]))
     568      118760 :       Elts.push_back(cast<DIType>(Elements[i]));
     569             :     else
     570       10650 :       Elts.push_back(Elements[i]);
     571             :   }
     572      141789 :   return DITypeRefArray(MDNode::get(VMContext, Elts));
     573             : }
     574             : 
     575         380 : DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
     576         760 :   return DISubrange::get(VMContext, Count, Lo);
     577             : }
     578             : 
     579             : static void checkGlobalVariableScope(DIScope *Context) {
     580             : #ifndef NDEBUG
     581             :   if (auto *CT =
     582             :           dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
     583             :     assert(CT->getIdentifier().empty() &&
     584             :            "Context of a global variable should not be a type with identifier");
     585             : #endif
     586             : }
     587             : 
     588         517 : DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression(
     589             :     DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
     590             :     unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
     591             :     MDNode *Decl, uint32_t AlignInBits) {
     592         517 :   checkGlobalVariableScope(Context);
     593             : 
     594        1034 :   auto *GV = DIGlobalVariable::getDistinct(
     595             :       VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
     596             :       LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
     597         517 :       AlignInBits);
     598         517 :   if (!Expr)
     599         473 :     Expr = createExpression();
     600        1034 :   auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
     601         517 :   AllGVs.push_back(N);
     602         517 :   return N;
     603             : }
     604             : 
     605           8 : DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
     606             :     DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
     607             :     unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl,
     608             :     uint32_t AlignInBits) {
     609           8 :   checkGlobalVariableScope(Context);
     610             : 
     611          32 :   return DIGlobalVariable::getTemporary(
     612             :              VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
     613             :              LineNumber, Ty, isLocalToUnit, false,
     614             :              cast_or_null<DIDerivedType>(Decl), AlignInBits)
     615          16 :       .release();
     616             : }
     617             : 
     618       12632 : static DILocalVariable *createLocalVariable(
     619             :     LLVMContext &VMContext,
     620             :     DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
     621             :     DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
     622             :     unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
     623             :     uint32_t AlignInBits) {
     624             :   // FIXME: Why getNonCompileUnitScope()?
     625             :   // FIXME: Why is "!Context" okay here?
     626             :   // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
     627             :   // the only valid scopes)?
     628       12632 :   DIScope *Context = getNonCompileUnitScope(Scope);
     629             : 
     630             :   auto *Node =
     631       37896 :       DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
     632       12632 :                            File, LineNo, Ty, ArgNo, Flags, AlignInBits);
     633       12632 :   if (AlwaysPreserve) {
     634             :     // The optimizer may remove local variables. If there is an interest
     635             :     // to preserve variable info in such situation then stash it in a
     636             :     // named mdnode.
     637        9514 :     DISubprogram *Fn = getDISubprogram(Scope);
     638             :     assert(Fn && "Missing subprogram for local variable");
     639       19028 :     PreservedVariables[Fn].emplace_back(Node);
     640             :   }
     641       12632 :   return Node;
     642             : }
     643             : 
     644        2493 : DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
     645             :                                                DIFile *File, unsigned LineNo,
     646             :                                                DIType *Ty, bool AlwaysPreserve,
     647             :                                                DINode::DIFlags Flags,
     648             :                                                uint32_t AlignInBits) {
     649        2493 :   return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
     650             :                              /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
     651        2493 :                              Flags, AlignInBits);
     652             : }
     653             : 
     654       10139 : DILocalVariable *DIBuilder::createParameterVariable(
     655             :     DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
     656             :     unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
     657             :   assert(ArgNo && "Expected non-zero argument number for parameter");
     658       10139 :   return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
     659             :                              File, LineNo, Ty, AlwaysPreserve, Flags,
     660       10139 :                              /* AlignInBits */0);
     661             : }
     662             : 
     663       13157 : DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
     664       26314 :   return DIExpression::get(VMContext, Addr);
     665             : }
     666             : 
     667       12618 : DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
     668             :   // TODO: Remove the callers of this signed version and delete.
     669       37854 :   SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
     670       25236 :   return createExpression(Addr);
     671             : }
     672             : 
     673             : template <class... Ts>
     674       38534 : static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
     675       38534 :   if (IsDistinct)
     676       54016 :     return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
     677       23052 :   return DISubprogram::get(std::forward<Ts>(Args)...);
     678             : }
     679             : 
     680       27039 : DISubprogram *DIBuilder::createFunction(
     681             :     DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
     682             :     unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
     683             :     bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
     684             :     bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
     685             :     DITypeArray ThrownTypes) {
     686       81117 :   auto *Node = getSubprogram(
     687             :       /* IsDistinct = */ isDefinition, VMContext,
     688       54078 :       getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty,
     689             :       isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags,
     690       54078 :       isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
     691      162234 :       MDTuple::getTemporary(VMContext, None).release(), ThrownTypes);
     692             : 
     693       27039 :   if (isDefinition)
     694       27008 :     AllSubprograms.push_back(Node);
     695       27039 :   trackIfUnresolved(Node);
     696       27039 :   return Node;
     697             : }
     698             : 
     699        5805 : DISubprogram *DIBuilder::createTempFunctionFwdDecl(
     700             :     DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
     701             :     unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
     702             :     bool isDefinition, unsigned ScopeLine, DINode::DIFlags Flags,
     703             :     bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl,
     704             :     DITypeArray ThrownTypes) {
     705       23220 :   return DISubprogram::getTemporary(
     706        5805 :              VMContext, getNonCompileUnitScope(Context), Name, LinkageName,
     707             :              File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr,
     708             :              0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr,
     709             :              TParams, Decl, nullptr, ThrownTypes)
     710       11610 :       .release();
     711             : }
     712             : 
     713       11495 : DISubprogram *DIBuilder::createMethod(
     714             :     DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
     715             :     unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
     716             :     bool isDefinition, unsigned VK, unsigned VIndex, int ThisAdjustment,
     717             :     DIType *VTableHolder, DINode::DIFlags Flags, bool isOptimized,
     718             :     DITemplateParameterArray TParams, DITypeArray ThrownTypes) {
     719             :   assert(getNonCompileUnitScope(Context) &&
     720             :          "Methods should have both a Context and a context that isn't "
     721             :          "the compile unit.");
     722             :   // FIXME: Do we want to use different scope/lines?
     723       34485 :   auto *SP = getSubprogram(
     724       22990 :       /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name,
     725             :       LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
     726             :       VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized,
     727       34485 :       isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr, ThrownTypes);
     728             : 
     729       11495 :   if (isDefinition)
     730           0 :     AllSubprograms.push_back(SP);
     731       11495 :   trackIfUnresolved(SP);
     732       11495 :   return SP;
     733             : }
     734             : 
     735        1256 : DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
     736             :                                         bool ExportSymbols) {
     737             : 
     738             :   // It is okay to *not* make anonymous top-level namespaces distinct, because
     739             :   // all nodes that have an anonymous namespace as their parent scope are
     740             :   // guaranteed to be unique and/or are linked to their containing
     741             :   // DICompileUnit. This decision is an explicit tradeoff of link time versus
     742             :   // memory usage versus code simplicity and may get revisited in the future.
     743        2512 :   return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
     744        1256 :                           ExportSymbols);
     745             : }
     746             : 
     747          53 : DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
     748             :                                   StringRef ConfigurationMacros,
     749             :                                   StringRef IncludePath,
     750             :                                   StringRef ISysRoot) {
     751          53 :  return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
     752          53 :                       ConfigurationMacros, IncludePath, ISysRoot);
     753             : }
     754             : 
     755         332 : DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,
     756             :                                                       DIFile *File,
     757             :                                                       unsigned Discriminator) {
     758         664 :   return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
     759             : }
     760             : 
     761        3405 : DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
     762             :                                               unsigned Line, unsigned Col) {
     763             :   // Make these distinct, to avoid merging two lexical blocks on the same
     764             :   // file/line/column.
     765        3405 :   return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
     766        3405 :                                      File, Line, Col);
     767             : }
     768             : 
     769             : static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
     770             :   assert(V && "no value passed to dbg intrinsic");
     771       24893 :   return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
     772             : }
     773             : 
     774       24893 : static Instruction *withDebugLoc(Instruction *I, const DILocation *DL) {
     775       74679 :   I->setDebugLoc(const_cast<DILocation *>(DL));
     776       24893 :   return I;
     777             : }
     778             : 
     779         688 : Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
     780             :                                       DIExpression *Expr, const DILocation *DL,
     781             :                                       Instruction *InsertBefore) {
     782             :   assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
     783             :   assert(DL && "Expected debug loc");
     784             :   assert(DL->getScope()->getSubprogram() ==
     785             :              VarInfo->getScope()->getSubprogram() &&
     786             :          "Expected matching subprograms");
     787         688 :   if (!DeclareFn)
     788         571 :     DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
     789             : 
     790         688 :   trackIfUnresolved(VarInfo);
     791         688 :   trackIfUnresolved(Expr);
     792        1376 :   Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
     793         688 :                    MetadataAsValue::get(VMContext, VarInfo),
     794        1376 :                    MetadataAsValue::get(VMContext, Expr)};
     795        1376 :   return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
     796             : }
     797             : 
     798       12603 : Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
     799             :                                       DIExpression *Expr, const DILocation *DL,
     800             :                                       BasicBlock *InsertAtEnd) {
     801             :   assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
     802             :   assert(DL && "Expected debug loc");
     803             :   assert(DL->getScope()->getSubprogram() ==
     804             :              VarInfo->getScope()->getSubprogram() &&
     805             :          "Expected matching subprograms");
     806       12603 :   if (!DeclareFn)
     807         278 :     DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
     808             : 
     809       12603 :   trackIfUnresolved(VarInfo);
     810       12603 :   trackIfUnresolved(Expr);
     811       25206 :   Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
     812       12603 :                    MetadataAsValue::get(VMContext, VarInfo),
     813       25206 :                    MetadataAsValue::get(VMContext, Expr)};
     814             : 
     815             :   // If this block already has a terminator then insert this intrinsic
     816             :   // before the terminator.
     817       12603 :   if (TerminatorInst *T = InsertAtEnd->getTerminator())
     818           0 :     return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL);
     819       25206 :   return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL);
     820             : }
     821             : 
     822       11572 : Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
     823             :                                                 DILocalVariable *VarInfo,
     824             :                                                 DIExpression *Expr,
     825             :                                                 const DILocation *DL,
     826             :                                                 Instruction *InsertBefore) {
     827             :   assert(V && "no value passed to dbg.value");
     828             :   assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
     829             :   assert(DL && "Expected debug loc");
     830             :   assert(DL->getScope()->getSubprogram() ==
     831             :              VarInfo->getScope()->getSubprogram() &&
     832             :          "Expected matching subprograms");
     833       11572 :   if (!ValueFn)
     834        8958 :     ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
     835             : 
     836       11572 :   trackIfUnresolved(VarInfo);
     837       11572 :   trackIfUnresolved(Expr);
     838       23144 :   Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
     839       11572 :                    MetadataAsValue::get(VMContext, VarInfo),
     840       23144 :                    MetadataAsValue::get(VMContext, Expr)};
     841       23144 :   return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL);
     842             : }
     843             : 
     844          30 : Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
     845             :                                                 DILocalVariable *VarInfo,
     846             :                                                 DIExpression *Expr,
     847             :                                                 const DILocation *DL,
     848             :                                                 BasicBlock *InsertAtEnd) {
     849             :   assert(V && "no value passed to dbg.value");
     850             :   assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
     851             :   assert(DL && "Expected debug loc");
     852             :   assert(DL->getScope()->getSubprogram() ==
     853             :              VarInfo->getScope()->getSubprogram() &&
     854             :          "Expected matching subprograms");
     855          30 :   if (!ValueFn)
     856          21 :     ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
     857             : 
     858          30 :   trackIfUnresolved(VarInfo);
     859          30 :   trackIfUnresolved(Expr);
     860          60 :   Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
     861          30 :                    MetadataAsValue::get(VMContext, VarInfo),
     862          60 :                    MetadataAsValue::get(VMContext, Expr)};
     863             : 
     864          60 :   return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
     865             : }
     866             : 
     867        2404 : void DIBuilder::replaceVTableHolder(DICompositeType *&T,
     868             :                                     DICompositeType *VTableHolder) {
     869             :   {
     870        7212 :     TypedTrackingMDRef<DICompositeType> N(T);
     871        4808 :     N->replaceVTableHolder(VTableHolder);
     872        2404 :     T = N.get();
     873             :   }
     874             : 
     875             :   // If this didn't create a self-reference, just return.
     876        2404 :   if (T != VTableHolder)
     877             :     return;
     878             : 
     879             :   // Look for unresolved operands.  T will drop RAUW support, orphaning any
     880             :   // cycles underneath it.
     881         100 :   if (T->isResolved())
     882         500 :     for (const MDOperand &O : T->operands())
     883         112 :       if (auto *N = dyn_cast_or_null<MDNode>(O))
     884         112 :         trackIfUnresolved(N);
     885             : }
     886             : 
     887        6780 : void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
     888             :                               DINodeArray TParams) {
     889             :   {
     890       20340 :     TypedTrackingMDRef<DICompositeType> N(T);
     891        6780 :     if (Elements)
     892        2660 :       N->replaceElements(Elements);
     893        6780 :     if (TParams)
     894        4668 :       N->replaceTemplateParams(DITemplateParameterArray(TParams));
     895        6780 :     T = N.get();
     896             :   }
     897             : 
     898             :   // If T isn't resolved, there's no problem.
     899       13519 :   if (!T->isResolved())
     900             :     return;
     901             : 
     902             :   // If T is resolved, it may be due to a self-reference cycle.  Track the
     903             :   // arrays explicitly if they're unresolved, or else the cycles will be
     904             :   // orphaned.
     905        6739 :   if (Elements)
     906        2660 :     trackIfUnresolved(Elements.get());
     907        6739 :   if (TParams)
     908        1556 :     trackIfUnresolved(TParams.get());
     909             : }

Generated by: LCOV version 1.13