r246210 - CGDebugInfo: Factor out a getOrCreateStandaloneType() method.

Adrian Prantl via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 14:35:27 PDT 2015


> On Aug 27, 2015, at 2:25 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Thu, Aug 27, 2015 at 2:21 PM, Adrian Prantl via cfe-commits <cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>> wrote:
> Author: adrian
> Date: Thu Aug 27 16:21:19 2015
> New Revision: 246210
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=246210&view=rev <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D246210-26view-3Drev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=aJRwlazZQeqQe80mCWYKzjxquHaBvqmkRAL1J7k0HoE&e=>
> Log:
> 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().
> 
> I don't quite understand why the new uniquing code is required - what is it about this new codepath that necessitates that?

getOrCreateStandaloneType() invokes getOrCreateType() and adds the DIType to RetainedTypes so it doesn’t get lost. If getOrCreateType() was in fact a cache hit, it is possible that the type was already retained when it was initially created. Thinking of it, it is probably better to make getOrCreateStandalaoneType() replicate getOrCreateType()’s logic and have it only retain the type if it was a cache miss. I’ll fix that.

-- adrian

>  
> 
> 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=246210&r1=246209&r2=246210&view=diff <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CGDebugInfo.cpp-3Frev-3D246210-26r1-3D246209-26r2-3D246210-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=tu3fprD1M6lqLHkpJc-IasxvMhIesAykH_SLNHiYl8g&e=>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug 27 16:21:19 2015
> @@ -1398,8 +1398,15 @@ llvm::DIType *CGDebugInfo::getOrCreateRe
> 
>  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<void *>::const_iterator RI = RetainedTypes.begin(),
> -         RE = RetainedTypes.end(); RI != RE; ++RI)
> -    DBuilder.retainType(cast<llvm::DIType>(TypeCache[*RI]));
> +  llvm::DenseSet<void *> UniqueTypes;
> +  UniqueTypes.resize(RetainedTypes.size() * 2);
> +  for (auto &RT : RetainedTypes) {
> +    if (!UniqueTypes.insert(RT).second)
> +      continue;
> +    if (auto MD = TypeCache[RT])
> +      DBuilder.retainType(cast<llvm::DIType>(MD));
> +  }
> 
>    DBuilder.finalize();
>  }
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=246210&r1=246209&r2=246210&view=diff <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CGDebugInfo.h-3Frev-3D246210-26r1-3D246209-26r2-3D246210-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=wP5t1N1vlukZeQ4hJZIPNg3aK6A2hiDY3de2dsFzjzQ&e=>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Aug 27 16:21:19 2015
> @@ -344,6 +344,9 @@ public:
>    /// Emit an Objective-C interface type standalone debug info.
>    llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
> 
> +  /// Emit standalone debug info for a type.
> +  llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
> +
>    void completeType(const EnumDecl *ED);
>    void completeType(const RecordDecl *RD);
>    void completeRequiredType(const RecordDecl *RD);
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits <https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=KP-TI2iE4gchlGzoSv2inSkjBdaf_Vm8z5phvDG_pyk&e=>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150827/25c2b03c/attachment.html>


More information about the cfe-commits mailing list