DebugInfo: Split out the implementation of getStaticDataMemberDeclaration for future use

llvm-svn: 188498
This commit is contained in:
David Blaikie 2013-08-15 22:30:23 +00:00
parent f63f0bf395
commit 6dc689670c
2 changed files with 24 additions and 19 deletions

View File

@ -2998,19 +2998,25 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
DbgDecl->setDebugLoc(llvm::DebugLoc::get(line, column, scope)); DbgDecl->setDebugLoc(llvm::DebugLoc::get(line, column, scope));
} }
/// getStaticDataMemberDeclaration - If D is an out-of-class definition of /// If D is an out-of-class definition of a static data member of a class, find
/// a static data member of a class, find its corresponding in-class /// its corresponding in-class declaration.
/// declaration. llvm::DIDerivedType
llvm::DIDerivedType CGDebugInfo::getStaticDataMemberDeclaration(const VarDecl *D) { CGDebugInfo::getStaticDataMemberDeclarationOrNull(const VarDecl *D) {
if (D->isStaticDataMember()) { if (!D->isStaticDataMember())
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator return llvm::DIDerivedType();
MI = StaticDataMemberCache.find(D->getCanonicalDecl()); return getStaticDataMemberDeclaration(D);
if (MI != StaticDataMemberCache.end()) }
// Verify the info still exists.
if (llvm::Value *V = MI->second) llvm::DIDerivedType
return llvm::DIDerivedType(cast<llvm::MDNode>(V)); CGDebugInfo::getStaticDataMemberDeclaration(const VarDecl *D) {
} llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
return llvm::DIDerivedType(); MI = StaticDataMemberCache.find(D->getCanonicalDecl());
if (MI != StaticDataMemberCache.end())
// Verify the info still exists.
if (llvm::Value *V = MI->second)
return llvm::DIDerivedType(cast<llvm::MDNode>(V));
llvm_unreachable(
"A static data member declaration should be available at this point");
} }
/// EmitGlobalVariable - Emit information about a global variable. /// EmitGlobalVariable - Emit information about a global variable.
@ -3042,11 +3048,9 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
LinkageName = StringRef(); LinkageName = StringRef();
llvm::DIDescriptor DContext = llvm::DIDescriptor DContext =
getContextDescriptor(dyn_cast<Decl>(D->getDeclContext())); getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()));
llvm::DIGlobalVariable GV = llvm::DIGlobalVariable GV = DBuilder.createStaticVariable(
DBuilder.createStaticVariable(DContext, DeclName, LinkageName, Unit, DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
LineNo, getOrCreateType(T, Unit), Var->hasInternalLinkage(), Var, getStaticDataMemberDeclarationOrNull(D));
Var->hasInternalLinkage(), Var,
getStaticDataMemberDeclaration(D));
DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV))); DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV)));
} }
@ -3094,7 +3098,7 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
return; return;
llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( llvm::DIGlobalVariable GV = DBuilder.createStaticVariable(
Unit, Name, Name, Unit, getLineNumber(VD->getLocation()), Ty, true, Init, Unit, Name, Name, Unit, getLineNumber(VD->getLocation()), Ty, true, Init,
getStaticDataMemberDeclaration(cast<VarDecl>(VD))); getStaticDataMemberDeclarationOrNull(cast<VarDecl>(VD)));
DeclCache.insert(std::make_pair(VD->getCanonicalDecl(), llvm::WeakVH(GV))); DeclCache.insert(std::make_pair(VD->getCanonicalDecl(), llvm::WeakVH(GV)));
} }

View File

@ -357,6 +357,7 @@ private:
/// getStaticDataMemberDeclaration - Return debug info descriptor to /// getStaticDataMemberDeclaration - Return debug info descriptor to
/// describe in-class static data member declaration for the given /// describe in-class static data member declaration for the given
/// out-of-class definition. /// out-of-class definition.
llvm::DIDerivedType getStaticDataMemberDeclarationOrNull(const VarDecl *D);
llvm::DIDerivedType getStaticDataMemberDeclaration(const VarDecl *D); llvm::DIDerivedType getStaticDataMemberDeclaration(const VarDecl *D);
/// getFunctionName - Get function name for the given FunctionDecl. If the /// getFunctionName - Get function name for the given FunctionDecl. If the