[llvm-commits] patch: teach deadargelim to work on externally visible functions!

Török Edwin edwintorok at gmail.com
Mon Jan 4 03:32:21 PST 2010


On 2010-01-04 04:02, Nick Lewycky wrote:
> This patch implements dead argument elimination for functions which
> are externally visible.  We can't modify the function signature, but
> we can find all direct callers and make sure they aren't doing any
> work to calculate the argument that's going to be discarded.

Since you already make optimizations based on the assumption that the
externally visible function you see
is the actual one [*] that is going to be called at runtime I think
there is a more general solution for this:
 - create a new externally visible function
 - RAUW the old function with the newly created one
 - set the old function's visibility to internal, CC to fastcc
 - change all direct callers of the new func back to the old one (and
adjust CC)
 - make the new function call the old one

Pro:
 + deadargelim will be able to remove any dead arguments from the
internal function
 + taking address doesn't prohibit optimization (it'll call the
externally visible wrapper func)
 + you don't need to go through the .plt to call functions in same TU
for shared libs

Cons:
 - this is like changing ELF visibility to protected, instead of default
"On ELF, default visibility means that the declaration is visible to
other modules and, in shared libraries, means that the declared entity
may be overridden"
" Protected visibility is like default visibility except that it
indicates that references within the defining module will bind to the
definition in that module."

[*] which may not be true, it could be overridden via LD_PRELOAD or
other means.
Your optimization (and the one suggested by me above) is like changing
the ELF visibility from 'default' to 'protected' I think.


> Please review!

Does this handle externally_available linkage?

Best regards,
--Edwin



More information about the llvm-commits mailing list