diff options
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 207 |
1 files changed, 98 insertions, 109 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 416f69e7c31..20603f44afb 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -126,13 +126,13 @@ void CGDebugInfo::setLocation(SourceLocation Loc) { LBF.getScope(), getOrCreateFile(CurLoc)); llvm::MDNode *N = D; LexicalBlockStack.pop_back(); - LexicalBlockStack.push_back(N); + LexicalBlockStack.emplace_back(N); } else if (Scope.isLexicalBlock() || Scope.isSubprogram()) { llvm::DIDescriptor D = DBuilder.createLexicalBlockFile(Scope, getOrCreateFile(CurLoc)); llvm::MDNode *N = D; LexicalBlockStack.pop_back(); - LexicalBlockStack.push_back(N); + LexicalBlockStack.emplace_back(N); } } @@ -141,10 +141,9 @@ llvm::DIScope CGDebugInfo::getContextDescriptor(const Decl *Context) { if (!Context) return TheCU; - llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator I = - RegionMap.find(Context); + auto I = RegionMap.find(Context); if (I != RegionMap.end()) { - llvm::Value *V = I->second; + llvm::Metadata *V = I->second; return llvm::DIScope(dyn_cast_or_null<llvm::MDNode>(V)); } @@ -256,18 +255,17 @@ llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) { // Cache the results. const char *fname = PLoc.getFilename(); - llvm::DenseMap<const char *, llvm::WeakVH>::iterator it = - DIFileCache.find(fname); + auto it = DIFileCache.find(fname); if (it != DIFileCache.end()) { // Verify that the information still exists. - if (llvm::Value *V = it->second) + if (llvm::Metadata *V = it->second) return llvm::DIFile(cast<llvm::MDNode>(V)); } llvm::DIFile F = DBuilder.createFile(PLoc.getFilename(), getCurrentDirname()); - DIFileCache[fname] = F; + DIFileCache[fname].reset(F); return F; } @@ -641,7 +639,9 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty, SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU); llvm::DICompositeType RetTy = DBuilder.createReplaceableForwardDecl( Tag, RDName, Ctx, DefUnit, Line, 0, 0, 0, FullName); - ReplaceMap.push_back(std::make_pair(Ty, static_cast<llvm::Value *>(RetTy))); + ReplaceMap.emplace_back( + std::piecewise_construct, std::make_tuple(Ty), + std::make_tuple(static_cast<llvm::Metadata *>(RetTy))); return RetTy; } @@ -680,7 +680,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, if (BlockLiteralGeneric) return BlockLiteralGeneric; - SmallVector<llvm::Value *, 8> EltTys; + SmallVector<llvm::Metadata *, 8> EltTys; llvm::DIType FieldTy; QualType FType; uint64_t FieldSize, FieldOffset; @@ -784,7 +784,7 @@ llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile Unit) { llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, llvm::DIFile Unit) { - SmallVector<llvm::Value *, 16> EltTys; + SmallVector<llvm::Metadata *, 16> EltTys; // Add the result type at least. EltTys.push_back(getOrCreateType(Ty->getReturnType(), Unit)); @@ -857,10 +857,9 @@ llvm::DIType CGDebugInfo::createFieldType( } /// CollectRecordLambdaFields - Helper for CollectRecordFields. -void -CGDebugInfo::CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl, - SmallVectorImpl<llvm::Value *> &elements, - llvm::DIType RecordTy) { +void CGDebugInfo::CollectRecordLambdaFields( + const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements, + llvm::DIType RecordTy) { // For C++11 Lambdas a Field will be the same as a Capture, but the Capture // has the name and the location of the variable so we should iterate over // both concurrently. @@ -928,14 +927,14 @@ llvm::DIDerivedType CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, unsigned Flags = getAccessFlag(Var->getAccess(), RD); llvm::DIDerivedType GV = DBuilder.createStaticMemberType( RecordTy, VName, VUnit, LineNumber, VTy, Flags, C); - StaticDataMemberCache[Var->getCanonicalDecl()] = llvm::WeakVH(GV); + StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); return GV; } /// CollectRecordNormalField - Helper for CollectRecordFields. void CGDebugInfo::CollectRecordNormalField( const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile tunit, - SmallVectorImpl<llvm::Value *> &elements, llvm::DIType RecordTy, + SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType RecordTy, const RecordDecl *RD) { StringRef name = field->getName(); QualType type = field->getType(); @@ -959,10 +958,10 @@ void CGDebugInfo::CollectRecordNormalField( /// CollectRecordFields - A helper function to collect debug info for /// record fields. This is used while creating debug info entry for a Record. -void CGDebugInfo::CollectRecordFields(const RecordDecl *record, - llvm::DIFile tunit, - SmallVectorImpl<llvm::Value *> &elements, - llvm::DICompositeType RecordTy) { +void CGDebugInfo::CollectRecordFields( + const RecordDecl *record, llvm::DIFile tunit, + SmallVectorImpl<llvm::Metadata *> &elements, + llvm::DICompositeType RecordTy) { const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(record); if (CXXDecl && CXXDecl->isLambda()) @@ -978,8 +977,7 @@ void CGDebugInfo::CollectRecordFields(const RecordDecl *record, for (const auto *I : record->decls()) if (const auto *V = dyn_cast<VarDecl>(I)) { // Reuse the existing static member declaration if one exists - llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator MI = - StaticDataMemberCache.find(V->getCanonicalDecl()); + auto MI = StaticDataMemberCache.find(V->getCanonicalDecl()); if (MI != StaticDataMemberCache.end()) { assert(MI->second && "Static data member declaration should still exist"); @@ -1019,7 +1017,7 @@ llvm::DICompositeType CGDebugInfo::getOrCreateInstanceMethodType( getOrCreateType(QualType(Func, 0), Unit)).getTypeArray(); assert(Args.getNumElements() && "Invalid number of arguments!"); - SmallVector<llvm::Value *, 16> Elts; + SmallVector<llvm::Metadata *, 16> Elts; // First element is always return type. For 'void' functions it is NULL. Elts.push_back(Args.getElement(0)); @@ -1036,7 +1034,7 @@ llvm::DICompositeType CGDebugInfo::getOrCreateInstanceMethodType( llvm::DIType PointeeType = getOrCreateType(PointeeTy, Unit); llvm::DIType ThisPtrType = DBuilder.createPointerType(PointeeType, Size, Align); - TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType; + TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType); // TODO: This and the artificial type below are misleading, the // types aren't artificial the argument is, but the current // metadata doesn't represent that. @@ -1044,7 +1042,7 @@ llvm::DICompositeType CGDebugInfo::getOrCreateInstanceMethodType( Elts.push_back(ThisPtrType); } else { llvm::DIType ThisPtrType = getOrCreateType(ThisPtr, Unit); - TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType; + TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType); ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType); Elts.push_back(ThisPtrType); } @@ -1147,7 +1145,7 @@ CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, /* isDefinition=*/false, Virtuality, VIndex, ContainingType, Flags, CGM.getLangOpts().Optimize, nullptr, TParamsArray); - SPCache[Method->getCanonicalDecl()] = llvm::WeakVH(SP); + SPCache[Method->getCanonicalDecl()].reset(SP); return SP; } @@ -1157,7 +1155,7 @@ CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, /// a Record. void CGDebugInfo::CollectCXXMemberFunctions( const CXXRecordDecl *RD, llvm::DIFile Unit, - SmallVectorImpl<llvm::Value *> &EltTys, llvm::DIType RecordTy) { + SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType RecordTy) { // Since we want more than just the individual member decls if we // have templated functions iterate over every declaration to gather @@ -1188,7 +1186,7 @@ void CGDebugInfo::CollectCXXMemberFunctions( auto MI = SPCache.find(Method->getCanonicalDecl()); EltTys.push_back(MI == SPCache.end() ? CreateCXXMemberFunction(Method, Unit, RecordTy) - : static_cast<llvm::Value *>(MI->second)); + : static_cast<llvm::Metadata *>(MI->second)); } } @@ -1196,7 +1194,7 @@ void CGDebugInfo::CollectCXXMemberFunctions( /// C++ base classes. This is used while creating debug info entry for /// a Record. void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit, - SmallVectorImpl<llvm::Value *> &EltTys, + SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType RecordTy) { const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); @@ -1238,7 +1236,7 @@ llvm::DIArray CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList, ArrayRef<TemplateArgument> TAList, llvm::DIFile Unit) { - SmallVector<llvm::Value *, 16> TemplateParams; + SmallVector<llvm::Metadata *, 16> TemplateParams; for (unsigned i = 0, e = TAList.size(); i != e; ++i) { const TemplateArgument &TA = TAList[i]; StringRef Name; @@ -1263,7 +1261,7 @@ CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList, const ValueDecl *D = TA.getAsDecl(); QualType T = TA.getParamTypeForDecl().getDesugaredType(CGM.getContext()); llvm::DIType TTy = getOrCreateType(T, Unit); - llvm::Value *V = nullptr; + llvm::Constant *V = nullptr; const CXXMethodDecl *MD; // Variable pointer template parameters have a value that is the address // of the variable. @@ -1295,7 +1293,7 @@ CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList, case TemplateArgument::NullPtr: { QualType T = TA.getNullPtrType(); llvm::DIType TTy = getOrCreateType(T, Unit); - llvm::Value *V = nullptr; + llvm::Constant *V = nullptr; // Special case member data pointer null values since they're actually -1 // instead of zero. if (const MemberPointerType *MPT = @@ -1332,7 +1330,7 @@ CGDebugInfo::CollectTemplateParams(const TemplateParameterList *TPList, QualType T = E->getType(); if (E->isGLValue()) T = CGM.getContext().getLValueReferenceType(T); - llvm::Value *V = CGM.EmitConstantExpr(E, T); + llvm::Constant *V = CGM.EmitConstantExpr(E, T); assert(V && "Expression in template argument isn't constant"); llvm::DIType TTy = getOrCreateType(T, Unit); llvm::DITemplateValueParameter TVP = @@ -1385,7 +1383,7 @@ llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) { ASTContext &Context = CGM.getContext(); /* Function type */ - llvm::Value *STy = getOrCreateType(Context.IntTy, Unit); + llvm::Metadata *STy = getOrCreateType(Context.IntTy, Unit); llvm::DITypeArray SElements = DBuilder.getOrCreateTypeArray(STy); llvm::DIType SubTy = DBuilder.createSubroutineType(Unit, SElements); unsigned Size = Context.getTypeSize(Context.VoidPtrTy); @@ -1404,7 +1402,7 @@ StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) { /// CollectVTableInfo - If the C++ class has vtable info then insert appropriate /// debug info entry in EltTys vector. void CGDebugInfo::CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit, - SmallVectorImpl<llvm::Value *> &EltTys) { + SmallVectorImpl<llvm::Metadata *> &EltTys) { const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); // If there is a primary base then it will hold vtable info. @@ -1447,12 +1445,11 @@ void CGDebugInfo::completeType(const EnumDecl *ED) { void *TyPtr = Ty.getAsOpaquePtr(); auto I = TypeCache.find(TyPtr); if (I == TypeCache.end() || - !llvm::DIType(cast<llvm::MDNode>(static_cast<llvm::Value *>(I->second))) - .isForwardDecl()) + !llvm::DIType(cast<llvm::MDNode>(I->second)).isForwardDecl()) return; llvm::DIType Res = CreateTypeDefinition(Ty->castAs<EnumType>()); assert(!Res.isForwardDecl()); - TypeCache[TyPtr] = Res; + TypeCache[TyPtr].reset(Res); } void CGDebugInfo::completeType(const RecordDecl *RD) { @@ -1482,12 +1479,11 @@ void CGDebugInfo::completeClassData(const RecordDecl *RD) { void *TyPtr = Ty.getAsOpaquePtr(); auto I = TypeCache.find(TyPtr); if (I != TypeCache.end() && - !llvm::DIType(cast<llvm::MDNode>(static_cast<llvm::Value *>(I->second))) - .isForwardDecl()) + !llvm::DIType(cast<llvm::MDNode>(I->second)).isForwardDecl()) return; llvm::DIType Res = CreateTypeDefinition(Ty->castAs<RecordType>()); assert(!Res.isForwardDecl()); - TypeCache[TyPtr] = Res; + TypeCache[TyPtr].reset(Res); } static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, @@ -1571,11 +1567,11 @@ llvm::DIType CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) { CollectContainingType(CXXDecl, FwdDecl); // Push the struct on region stack. - LexicalBlockStack.push_back(&*FwdDecl); - RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); + LexicalBlockStack.emplace_back(&*FwdDecl); + RegionMap[Ty->getDecl()].reset(FwdDecl); // Convert all the elements. - SmallVector<llvm::Value *, 16> EltTys; + SmallVector<llvm::Metadata *, 16> EltTys; // what about nested types? // Note: The split of CXXDecl information here is intentional, the @@ -1599,7 +1595,7 @@ llvm::DIType CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) { llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys); FwdDecl.setArrays(Elements); - RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); + RegionMap[Ty->getDecl()].reset(FwdDecl); return FwdDecl; } @@ -1680,14 +1676,14 @@ llvm::DIType CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty, llvm::DIArray(), RuntimeLang); QualType QTy(Ty, 0); - TypeCache[QTy.getAsOpaquePtr()] = RealDecl; + TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl); // Push the struct on region stack. - LexicalBlockStack.push_back(static_cast<llvm::MDNode *>(RealDecl)); - RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl); + LexicalBlockStack.emplace_back(static_cast<llvm::MDNode *>(RealDecl)); + RegionMap[Ty->getDecl()].reset(RealDecl); // Convert all the elements. - SmallVector<llvm::Value *, 16> EltTys; + SmallVector<llvm::Metadata *, 16> EltTys; ObjCInterfaceDecl *SClass = ID->getSuperClass(); if (SClass) { @@ -1813,7 +1809,7 @@ llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, llvm::DIFile Unit) { // Use Count == -1 to express such arrays. Count = -1; - llvm::Value *Subscript = DBuilder.getOrCreateSubrange(0, Count); + llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(0, Count); llvm::DIArray SubscriptArray = DBuilder.getOrCreateArray(Subscript); uint64_t Size = CGM.getContext().getTypeSize(Ty); @@ -1849,7 +1845,7 @@ llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIFile Unit) { // Add the dimensions of the array. FIXME: This loses CV qualifiers from // interior arrays, do we care? Why aren't nested arrays represented the // obvious/recursive way? - SmallVector<llvm::Value *, 8> Subscripts; + SmallVector<llvm::Metadata *, 8> Subscripts; QualType EltTy(Ty, 0); while ((Ty = dyn_cast<ArrayType>(EltTy))) { // If the number of elements is known, then count is that number. Otherwise, @@ -1932,7 +1928,9 @@ llvm::DIType CGDebugInfo::CreateEnumType(const EnumType *Ty) { llvm::DIType RetTy = DBuilder.createReplaceableForwardDecl( llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line, 0, Size, Align, FullName); - ReplaceMap.push_back(std::make_pair(Ty, static_cast<llvm::Value *>(RetTy))); + ReplaceMap.emplace_back( + std::piecewise_construct, std::make_tuple(Ty), + std::make_tuple(static_cast<llvm::Metadata *>(RetTy))); return RetTy; } @@ -1951,7 +1949,7 @@ llvm::DIType CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) { SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU); // Create DIEnumerator elements for each enumerator. - SmallVector<llvm::Value *, 16> Enumerators; + SmallVector<llvm::Metadata *, 16> Enumerators; ED = ED->getDefinition(); for (const auto *Enum : ED->enumerators()) { Enumerators.push_back(DBuilder.createEnumerator( @@ -2039,7 +2037,7 @@ llvm::DIType CGDebugInfo::getTypeOrNull(QualType Ty) { auto it = TypeCache.find(Ty.getAsOpaquePtr()); if (it != TypeCache.end()) { // Verify that the debug info still exists. - if (llvm::Value *V = it->second) + if (llvm::Metadata *V = it->second) return llvm::DIType(cast<llvm::MDNode>(V)); } @@ -2074,7 +2072,7 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) { void *TyPtr = Ty.getAsOpaquePtr(); // And update the type cache. - TypeCache[TyPtr] = Res; + TypeCache[TyPtr].reset(Res); return Res; } @@ -2209,7 +2207,7 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty, Res.setArrays(T.getElements()); // And update the type cache. - TypeCache[QTy.getAsOpaquePtr()] = Res; + TypeCache[QTy.getAsOpaquePtr()].reset(Res); return Res; } @@ -2257,8 +2255,8 @@ llvm::DICompositeType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { RDContext, RDName, DefUnit, Line, Size, Align, 0, llvm::DIType(), llvm::DIArray(), 0, llvm::DIType(), FullName); - RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl); - TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl; + RegionMap[Ty->getDecl()].reset(RealDecl); + TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl); if (const ClassTemplateSpecializationDecl *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) @@ -2401,8 +2399,9 @@ CGDebugInfo::getFunctionForwardDeclaration(const FunctionDecl *FD) { CGM.getLangOpts().Optimize, nullptr, TParamsArray, getFunctionDeclaration(FD)); const FunctionDecl *CanonDecl = cast<FunctionDecl>(FD->getCanonicalDecl()); - FwdDeclReplaceMap.push_back(std::make_pair(CanonDecl, - static_cast<llvm::Value *>(SP))); + FwdDeclReplaceMap.emplace_back( + std::piecewise_construct, std::make_tuple(CanonDecl), + std::make_tuple(static_cast<llvm::Metadata *>(SP))); return SP; } @@ -2421,8 +2420,10 @@ CGDebugInfo::getGlobalVariableForwardDeclaration(const VarDecl *VD) { Line, getOrCreateType(T, Unit), !VD->isExternallyVisible(), nullptr, nullptr); - FwdDeclReplaceMap.push_back(std::make_pair(cast<VarDecl>(VD->getCanonicalDecl()), - static_cast<llvm::Value *>(GV))); + FwdDeclReplaceMap.emplace_back( + std::piecewise_construct, + std::make_tuple(cast<VarDecl>(VD->getCanonicalDecl())), + std::make_tuple(static_cast<llvm::Metadata *>(GV))); return GV; } @@ -2434,13 +2435,10 @@ llvm::DIDescriptor CGDebugInfo::getDeclarationOrDefinition(const Decl *D) { if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) return getOrCreateType(CGM.getContext().getTypeDeclType(TD), getOrCreateFile(TD->getLocation())); - llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator I = - DeclCache.find(D->getCanonicalDecl()); + auto I = DeclCache.find(D->getCanonicalDecl()); - if (I != DeclCache.end()) { - llvm::Value *V = I->second; - return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(V)); - } + if (I != DeclCache.end()) + return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second)); // No definition for now. Emit a forward definition that might be // merged with a potential upcoming definition. @@ -2465,8 +2463,7 @@ llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) { // Setup context. llvm::DIScope S = getContextDescriptor(cast<Decl>(D->getDeclContext())); - llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator MI = - SPCache.find(FD->getCanonicalDecl()); + auto MI = SPCache.find(FD->getCanonicalDecl()); if (MI == SPCache.end()) { if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD->getCanonicalDecl())) { @@ -2477,18 +2474,15 @@ llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) { } } if (MI != SPCache.end()) { - llvm::Value *V = MI->second; - llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(V)); + llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(MI->second)); if (SP.isSubprogram() && !SP.isDefinition()) return SP; } for (auto NextFD : FD->redecls()) { - llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator MI = - SPCache.find(NextFD->getCanonicalDecl()); + auto MI = SPCache.find(NextFD->getCanonicalDecl()); if (MI != SPCache.end()) { - llvm::Value *V = MI->second; - llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(V)); + llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(MI->second)); if (SP.isSubprogram() && !SP.isDefinition()) return SP; } @@ -2513,7 +2507,7 @@ llvm::DICompositeType CGDebugInfo::getOrCreateFunctionType(const Decl *D, return getOrCreateMethodType(Method, F); if (const ObjCMethodDecl *OMethod = dyn_cast<ObjCMethodDecl>(D)) { // Add "self" and "_cmd" - SmallVector<llvm::Value *, 16> Elts; + SmallVector<llvm::Metadata *, 16> Elts; // First element is always return type. For 'void' functions it is NULL. QualType ResultTy = OMethod->getReturnType(); @@ -2546,7 +2540,7 @@ llvm::DICompositeType CGDebugInfo::getOrCreateFunctionType(const Decl *D, // unspecified parameter. if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) if (FD->isVariadic()) { - SmallVector<llvm::Value *, 16> EltTys; + SmallVector<llvm::Metadata *, 16> EltTys; EltTys.push_back(getOrCreateType(FD->getReturnType(), F)); if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FnType)) for (unsigned i = 0, e = FPT->getNumParams(); i != e; ++i) @@ -2581,15 +2575,13 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, LinkageName = Fn->getName(); } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { // If there is a DISubprogram for this function available then use it. - llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator FI = - SPCache.find(FD->getCanonicalDecl()); + auto FI = SPCache.find(FD->getCanonicalDecl()); if (FI != SPCache.end()) { - llvm::Value *V = FI->second; - llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(V)); + llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(FI->second)); if (SP.isSubprogram() && llvm::DISubprogram(SP).isDefinition()) { llvm::MDNode *SPN = SP; - LexicalBlockStack.push_back(SPN); - RegionMap[D] = llvm::WeakVH(SP); + LexicalBlockStack.emplace_back(SPN); + RegionMap[D].reset(SP); return; } } @@ -2629,14 +2621,14 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, // code for the initialization of globals. Do not record these decls // as they will overwrite the actual VarDecl Decl in the cache. if (HasDecl && isa<FunctionDecl>(D)) - DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(SP))); + DeclCache[D->getCanonicalDecl()].reset(static_cast<llvm::Metadata *>(SP)); // Push the function onto the lexical block stack. llvm::MDNode *SPN = SP; - LexicalBlockStack.push_back(SPN); + LexicalBlockStack.emplace_back(SPN); if (HasDecl) - RegionMap[D] = llvm::WeakVH(SP); + RegionMap[D].reset(SP); } /// EmitLocation - Emit metadata to indicate a change in line/column @@ -2676,7 +2668,7 @@ void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) { : LexicalBlockStack.back()), getOrCreateFile(CurLoc), getLineNumber(CurLoc), getColumnNumber(CurLoc)); llvm::MDNode *DN = D; - LexicalBlockStack.push_back(DN); + LexicalBlockStack.emplace_back(DN); } /// EmitLexicalBlockStart - Constructs the debug code for entering a declarative @@ -2732,7 +2724,7 @@ void CGDebugInfo::EmitFunctionEnd(CGBuilderTy &Builder) { llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD, uint64_t *XOffset) { - SmallVector<llvm::Value *, 5> EltTys; + SmallVector<llvm::Metadata *, 5> EltTys; QualType FType; uint64_t FieldSize, FieldOffset; unsigned FieldAlign; @@ -3047,7 +3039,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, const llvm::StructLayout *blockLayout = CGM.getDataLayout().getStructLayout(block.StructureType); - SmallVector<llvm::Value *, 16> fields; + SmallVector<llvm::Metadata *, 16> fields; fields.push_back(createFieldType("__isa", C.VoidPtrTy, 0, loc, AS_public, blockLayout->getElementOffsetInBits(0), tunit, tunit)); @@ -3181,8 +3173,7 @@ llvm::DIDerivedType CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { if (!D->isStaticDataMember()) return llvm::DIDerivedType(); - llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator MI = - StaticDataMemberCache.find(D->getCanonicalDecl()); + auto MI = StaticDataMemberCache.find(D->getCanonicalDecl()); if (MI != StaticDataMemberCache.end()) { assert(MI->second && "Static data member declaration should still exist"); return llvm::DIDerivedType(cast<llvm::MDNode>(MI->second)); @@ -3255,7 +3246,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, Var->hasInternalLinkage(), Var, getOrCreateStaticDataMemberDeclarationOrNull(D)); } - DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV))); + DeclCache[D->getCanonicalDecl()].reset(static_cast<llvm::Metadata *>(GV)); } /// EmitGlobalVariable - Emit global variable's debug info. @@ -3291,13 +3282,12 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, llvm::DIDescriptor DContext = getContextDescriptor(dyn_cast<Decl>(VD->getDeclContext())); - auto pair = DeclCache.insert(std::make_pair(VD, llvm::WeakVH())); - if (!pair.second) + auto &GV = DeclCache[VD]; + if (GV) return; - llvm::DIGlobalVariable GV = DBuilder.createGlobalVariable( + GV.reset(DBuilder.createGlobalVariable( DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty, - true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD)); - pair.first->second = llvm::WeakVH(GV); + true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD))); } llvm::DIScope CGDebugInfo::getCurrentContextDescriptor(const Decl *D) { @@ -3334,7 +3324,7 @@ llvm::DIImportedEntity CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) { if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo) return llvm::DIImportedEntity(nullptr); - llvm::WeakVH &VH = NamespaceAliasCache[&NA]; + auto &VH = NamespaceAliasCache[&NA]; if (VH) return llvm::DIImportedEntity(cast<llvm::MDNode>(VH)); llvm::DIImportedEntity R(nullptr); @@ -3350,7 +3340,7 @@ CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) { getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())), getOrCreateNameSpace(cast<NamespaceDecl>(NA.getAliasedNamespace())), getLineNumber(NA.getLocation()), NA.getName()); - VH = R; + VH.reset(R); return R; } @@ -3359,8 +3349,7 @@ CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) { llvm::DINameSpace CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) { NSDecl = NSDecl->getCanonicalDecl(); - llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = - NameSpaceCache.find(NSDecl); + auto I = NameSpaceCache.find(NSDecl); if (I != NameSpaceCache.end()) return llvm::DINameSpace(cast<llvm::MDNode>(I->second)); @@ -3370,7 +3359,7 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) { getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext())); llvm::DINameSpace NS = DBuilder.createNameSpace(Context, NSDecl->getName(), FileD, LineNo); - NameSpaceCache[NSDecl] = llvm::WeakVH(NS); + NameSpaceCache[NSDecl].reset(NS); return NS; } @@ -3401,19 +3390,19 @@ void CGDebugInfo::finalize() { for (const auto &p : FwdDeclReplaceMap) { assert(p.second); llvm::DIDescriptor FwdDecl(cast<llvm::MDNode>(p.second)); - llvm::WeakVH VH; + llvm::Metadata *Repl; auto it = DeclCache.find(p.first); // If there has been no definition for the declaration, call RAUV // with ourselves, that will destroy the temporary MDNode and // replace it with a standard one, avoiding leaking memory. if (it == DeclCache.end()) - VH = p.second; + Repl = p.second; else - VH = it->second; + Repl = it->second; FwdDecl.replaceAllUsesWith(CGM.getLLVMContext(), - llvm::DIDescriptor(cast<llvm::MDNode>(VH))); + llvm::DIDescriptor(cast<llvm::MDNode>(Repl))); } // We keep our own list of retained types, because we need to look |