[PATCH] Allow CodeGen to take advantage of functions that always return arguments

Bill Wendling wendling at apple.com
Thu Apr 18 13:19:22 PDT 2013


Committed. Thanks!

-bw

On Apr 18, 2013, at 12:13 PM, Stephen Lin <swlin at post.harvard.edu> wrote:

> Hi,
> 
> This patch adds a target-independent parameter attribute 'returned'
> (I'm very open to renaming it, just couldn't think of anything
> better...), which indicates to the caller that a function's return
> value is always equal to (a bitcast of) the parameter value, allowing
> tail call optimization and possibly save/restore elision. It is the
> callee's responsibility to ensure that this contract is fulfilled.
> 
> The initial intended use case is for C++ constructors and destructors
> that are ABI-guaranteed to return 'this'; however, I've made it
> flexible enough to apply to any parameter position or even multiple
> parameters, since there's no real technical reason not to (although
> obviously the contract can only be fulfilled in the latter case if
> multiple arguments are always equal for some reason...)
> 
> For now, the attribute is taken advantage of in two places:
> 
> 1. SelectionDAGBuilder::LowerCallTo will detect a tail call
> opportunity through 'returned' arguments (subject to target-dependent
> requirements checked later).
> 
> 2. The ARM backend, in ARMTargetLowering::LowerCall, will avoid
> save/restoring R0 when 'returned' is on the first argument and the
> argument's type lowers to MVT::i32, as R0 is used for both the first
> argument and the return value in that case.
> 
> Eventually, support can be added to the register allocator to take
> advantage of the 'returned' guarantee to do better register allocation
> on all targets, although apparently this is non-trivial.
> 
> Please kindly review.
> 
> Stephen
> 
> P.S. This patch depends on two previous patches, which have yet to be committed:
> 
>    http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130415/171948.html
> (only the first patch)
> 
> and
> 
>    http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130415/171945.html
> <return-argument.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list