From ad9a195ee9cacbcf12e32dcc2b991ca8a5f23143 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 27 Aug 2015 21:21:19 +0000 Subject: CGDebugInfo: Factor out a getOrCreateStandaloneType() method. Usually debug info is created on the fly while during codegen. With this API it becomes possible to create standalone debug info for types that are not referenced by any code, such as emitting debug info for a clang module or for implementing something like -gfull. Because on-the-fly debug info generation may still insert retained types on top of them, all RetainedTypes are uniqued in CGDebugInfo::finalize(). llvm-svn: 246210 --- clang/lib/CodeGen/CGDebugInfo.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp') diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index dd3f783cf4e..109829aa490 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1398,8 +1398,15 @@ llvm::DIType *CGDebugInfo::getOrCreateRecordType(QualType RTy, llvm::DIType *CGDebugInfo::getOrCreateInterfaceType(QualType D, SourceLocation Loc) { + return getOrCreateStandaloneType(D, Loc); +} + +llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D, + SourceLocation Loc) { assert(DebugKind >= CodeGenOptions::LimitedDebugInfo); + assert(!D.isNull() && "null type"); llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc)); + assert(T && "could not create debug info for type"); RetainedTypes.push_back(D.getAsOpaquePtr()); return T; } @@ -3360,9 +3367,14 @@ void CGDebugInfo::finalize() { // We keep our own list of retained types, because we need to look // up the final type in the type cache. - for (std::vector::const_iterator RI = RetainedTypes.begin(), - RE = RetainedTypes.end(); RI != RE; ++RI) - DBuilder.retainType(cast(TypeCache[*RI])); + llvm::DenseSet UniqueTypes; + UniqueTypes.resize(RetainedTypes.size() * 2); + for (auto &RT : RetainedTypes) { + if (!UniqueTypes.insert(RT).second) + continue; + if (auto MD = TypeCache[RT]) + DBuilder.retainType(cast(MD)); + } DBuilder.finalize(); } -- cgit v1.2.3