From: David Blaikie Date: Mon, 5 May 2014 21:21:39 +0000 (+0000) Subject: Simplify replacement map by avoiding duplicate values and ensuring the values it... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6197f101bd0d753866f39268fb1f63e03eadce6f;p=clang Simplify replacement map by avoiding duplicate values and ensuring the values it does contain are necessary. Items were being redundantly added to the replacement map (both when the declaration was created, and then again when its definition was constructed) which caused extra handling to be required when walking the map (as elements may've already been replaced due to prior entries). By avoiding adding the duplicates, the checks in the replacement handling can be replaced with assertions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208000 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index f41fac80a2..4d763508ad 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2093,9 +2093,7 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) { // types. We should probably just pull that out as a special case for the // "else" block below & skip the otherwise needless lookup. llvm::DIType TC = getTypeOrNull(Ty); - if (TC && TC.isForwardDecl()) - ReplaceMap.push_back(std::make_pair(TyPtr, static_cast(TC))); - else if (ObjCInterfaceDecl* Decl = getObjCInterfaceDecl(Ty)) { + if (ObjCInterfaceDecl *Decl = getObjCInterfaceDecl(Ty)) { // Interface types may have elements added to them by a // subsequent implementation or extension, so we keep them in // the ObjCInterfaceCache together with a checksum. Instead of @@ -3382,21 +3380,17 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) { void CGDebugInfo::finalize() { for (std::vector >::const_iterator VI = ReplaceMap.begin(), VE = ReplaceMap.end(); VI != VE; ++VI) { - llvm::DIType Ty, RepTy; - // Verify that the debug info still exists. - if (llvm::Value *V = VI->second) - Ty = llvm::DIType(cast(V)); + assert(VI->second); + llvm::DIType Ty(cast(VI->second)); + assert(Ty.isForwardDecl()); llvm::DenseMap::iterator it = - TypeCache.find(VI->first); - if (it != TypeCache.end()) { - // Verify that the debug info still exists. - if (llvm::Value *V = it->second) - RepTy = llvm::DIType(cast(V)); - } + TypeCache.find(VI->first); + assert(it != TypeCache.end()); + assert(it->second); + llvm::DIType RepTy(cast(it->second)); - if (Ty && Ty.isForwardDecl() && RepTy) - Ty.replaceAllUsesWith(RepTy); + Ty.replaceAllUsesWith(RepTy); } // We keep our own list of retained types, because we need to look