[LLVMdev] Removing AvailableExternal values in GlobalDCE (was Re: RFC: ThinLTO Impementation Plan)

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Jun 4 15:58:34 PDT 2015


> On 2015 Jun 4, at 14:37, Reid Kleckner <rnk at google.com> wrote:
> 
> On Thu, Jun 4, 2015 at 11:27 AM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> Since the compiler is always free to delete available_externally
> functions, I think you could just add a pass to the -flto=thin pipeline
> that deletes all of them (referenced or not) -- it's just a single loop
> through all the functions deleting the bodies of those with the right
> linkage.  I imagine there are other pass pipelines that might want to do
> something similar.  I don't really like having GlobalDCE delete them
> (even behind a flag) because they aren't actually dead, and I think a
> separate pass makes it easier to test and all that.  (I haven't actually
> worked much with pass pipelines, though, so there's a chance I'm on my
> own here?)
> 
> It's possible to get into situations where available_externally functions or globals (dllimported vftable) reference linkonce_odr functions (virtual destructor thunks), so a single pass to drop available_externally function bodies isn't as strong as adding a flag to GlobalDCE.

Unless I'm missing something, running the pass to drop
available_externally function bodies just before running GlobalDCE
is equivalent to incorporating it into GlobalDCE.

> 
> Personally, I think the right approach is to add a bool to createGlobalDCEPass defaulting to true named something like IsAfterInlining. In most standard pass pipelines, GlobalDCE runs after inlining for obvious reasons, so the default makes sense. The special case is the LTO pass pipeline, where the code will be reloaded and reoptimized later. IMO it's natural to put the customization there.

That's a good point.  But I still like these as separate passes.



More information about the llvm-dev mailing list