r302915 - Simplify DINamespace caching in CGDebugInfo
Adrian Prantl via cfe-commits
cfe-commits at lists.llvm.org
Fri May 12 09:23:54 PDT 2017
Author: adrian
Date: Fri May 12 11:23:53 2017
New Revision: 302915
URL: http://llvm.org/viewvc/llvm-project?rev=302915&view=rev
Log:
Simplify DINamespace caching in CGDebugInfo
This addresses review feedback from r302840.
By not canonicalizing namespace decls and using lexical decl context
instead of lookuing up the semantic decl context we can take advantage
of the fact that DINamespaces a reuniqued. This way non-module debug
info is unchanged and module debug info still gets distinct namespace
declarations when they ocur in different modules.
Thanks to Richard Smith for pointing this out!
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=302915&r1=302914&r2=302915&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri May 12 11:23:53 2017
@@ -208,10 +208,8 @@ llvm::DIScope *CGDebugInfo::getContextDe
}
// Check namespace.
- if (const auto *NSDecl = dyn_cast<NamespaceDecl>(Context)) {
- auto *ParentModule = dyn_cast<llvm::DIModule>(Default);
- return getOrCreateNamespace(NSDecl, ParentModule);
- }
+ if (const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
+ return getOrCreateNamespace(NSDecl);
if (const auto *RDecl = dyn_cast<RecordDecl>(Context))
if (!RDecl->isDependentType())
@@ -2862,8 +2860,8 @@ void CGDebugInfo::collectFunctionDeclPro
if (DebugKind >= codegenoptions::LimitedDebugInfo) {
if (const NamespaceDecl *NSDecl =
- dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
- FDContext = getOrCreateNamespace(NSDecl, getParentModuleOrNull(FD));
+ dyn_cast_or_null<NamespaceDecl>(FD->getLexicalDeclContext()))
+ FDContext = getOrCreateNamespace(NSDecl);
else if (const RecordDecl *RDecl =
dyn_cast_or_null<RecordDecl>(FD->getDeclContext())) {
llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
@@ -3963,7 +3961,7 @@ void CGDebugInfo::EmitUsingDirective(con
CGM.getCodeGenOpts().DebugExplicitImport) {
DBuilder.createImportedModule(
getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
- getOrCreateNamespace(NSDecl, getParentModuleOrNull(&UD)),
+ getOrCreateNamespace(NSDecl),
getLineNumber(UD.getLocation()));
}
}
@@ -4023,32 +4021,26 @@ CGDebugInfo::EmitNamespaceAlias(const Na
else
R = DBuilder.createImportedDeclaration(
getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
- getOrCreateNamespace(cast<NamespaceDecl>(NA.getAliasedNamespace()),
- getParentModuleOrNull(&NA)),
+ getOrCreateNamespace(cast<NamespaceDecl>(NA.getAliasedNamespace())),
getLineNumber(NA.getLocation()), NA.getName());
VH.reset(R);
return R;
}
llvm::DINamespace *
-CGDebugInfo::getOrCreateNamespace(const NamespaceDecl *NSDecl,
- llvm::DIModule *ParentModule) {
- NSDecl = NSDecl->getCanonicalDecl();
- // The AST merges NamespaceDecls, but for module debug info it is important to
- // put a namespace decl (or rather its children) into the correct
- // (sub-)module, so use the parent module of the decl that triggered this
- // namespace to be serialized as a second key.
- NamespaceKey Key = {NSDecl, ParentModule};
- auto I = NamespaceCache.find(Key);
+CGDebugInfo::getOrCreateNamespace(const NamespaceDecl *NSDecl) {
+ // Don't canonicalize the NamespaceDecl here: The DINamespace will be uniqued
+ // if necessary, and this way multiple declarations of the same namespace in
+ // different parent modules stay distinct.
+ auto I = NamespaceCache.find(NSDecl);
if (I != NamespaceCache.end())
return cast<llvm::DINamespace>(I->second);
llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
// Don't trust the context if it is a DIModule (see comment above).
- llvm::DINamespace *NS = DBuilder.createNameSpace(
- isa<llvm::DIModule>(Context) ? ParentModule : Context, NSDecl->getName(),
- NSDecl->isInline());
- NamespaceCache[Key].reset(NS);
+ llvm::DINamespace *NS =
+ DBuilder.createNameSpace(Context, NSDecl->getName(), NSDecl->isInline());
+ NamespaceCache[NSDecl].reset(NS);
return NS;
}
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=302915&r1=302914&r2=302915&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri May 12 11:23:53 2017
@@ -125,8 +125,7 @@ class CGDebugInfo {
/// Cache declarations relevant to DW_TAG_imported_declarations (C++
/// using declarations) that aren't covered by other more specific caches.
llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
- typedef std::pair<const NamespaceDecl *, const llvm::DIModule *> NamespaceKey;
- llvm::DenseMap<NamespaceKey, llvm::TrackingMDRef> NamespaceCache;
+ llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
NamespaceAliasCache;
llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
@@ -197,13 +196,7 @@ class CGDebugInfo {
llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
/// \return namespace descriptor for the given namespace decl.
- ///
- /// \return namespace descriptor for the given namespace decl.
- /// \param ParentModule The parent module (or nullptr) of this particular
- /// namespace decl. This needs to be passed in because
- /// the AST merges namespace decls.
- llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N,
- llvm::DIModule *ParentModule);
+ llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
QualType PointeeTy, llvm::DIFile *F);
llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
More information about the cfe-commits
mailing list