[patch] Teach GlobalDCE how to remove empty global_ctor entries

Nico Weber thakis at chromium.org
Thu May 1 19:08:17 PDT 2014


On Thu, May 1, 2014 at 6:53 PM, Nico Weber <thakis at chromium.org> wrote:
> Hi,
>
> the attached patch moves most of GlobalOpt's constructor optimization
> code out of GlobalOpt into Transforms/Utils/CDtorUtils.{h,cpp}. The
> public interface is a single function:
>
>   /// Call "Remove" for every entry in M's global_ctor list and remove
> the entries
>   /// for which it returns true.  Return true if anything changed.
>   bool OptimizeGlobalCtorsList(Module &M, std::function<bool(Function
> *)> Remove);
>
> GlobalOpt calls this with a function that statically evaluates all
> constructors, just like it did before. (These parts of the patch are
> all behavior-preserving and mostly just move code out of GlobalOpt.cpp
> – since that file is > 3000 lines, this is a nice refactoring in
> itself.)
>
> The patch also adds a call to this with a filter that removes global
> constructors that contain a "ret" instruction and nothing else – this
> fixes the ctor part of PR19590 (the binary size of the program in that
> bug drops from 8k to 4k due to this patch on my OS X system with -O2).
> I'd like to do the dtor part in a follow-up.

Actually, I can't think of a way how the same thing could happen for
dtors, so pretend that the new file is called CtorUtils and that the
file comment doesn't advertise "various" methods :-)




More information about the llvm-commits mailing list