[PowerPC] ELFv2 stack space reduction
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Sun, 20 Jul 2014 23:43:15 +0000 (23:43 +0000)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Sun, 20 Jul 2014 23:43:15 +0000 (23:43 +0000)
commit7fc5011e8ddb6b96050c1f51d424e118e2602e9f
treec6ac115501910ee1228b697a7e78938b8c58da6f
parentedfd4f18bc18f702271dc7c14dec68ffd2d10417
[PowerPC] ELFv2 stack space reduction

The ELFv2 ABI reduces the amount of stack required to implement an
ABI-compliant function call in two ways:
* the "linkage area" is reduced from 48 bytes to 32 bytes by
  eliminating two unused doublewords
* the 64-byte "parameter save area" is now optional and need not be
  present in certain cases (it remains mandatory in functions with
  variable arguments, and functions that have any parameter that is
  passed on the stack)

The following patch implements this required changes:
- reducing the linkage area, and associated relocation of the TOC save
  slot, in getLinkageSize / getTOCSaveOffset (this requires updating all
  callers of these routines to pass in the isELFv2ABI flag).
- (partially) handling the case where the parameter save are is optional

This latter part requires some extra explanation:  Currently, we still
always allocate the parameter save area when *calling* a function.
That is certainly always compliant with the ABI, but may cause code to
allocate stack unnecessarily.  This can be addressed by a follow-on
optimization patch.

On the *callee* side, in LowerFormalArguments, we *must* track
correctly whether the ABI guarantees that the caller has allocated
the parameter save area for our use, and the patch does so. However,
there is one complication: the code that handles incoming "byval"
arguments will currently *always* write to the parameter save area,
because it has to force incoming register arguments to the stack since
it must return an *address* to implement the byval semantics.

To fix this, the patch changes the LowerFormalArguments code to write
arguments to a freshly allocated stack slot on the function's own stack
frame instead of the argument save area in those cases where that area
is not present.

Reviewed by Hal Finkel.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213490 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/PowerPC/PPCFastISel.cpp
lib/Target/PowerPC/PPCFrameLowering.cpp
lib/Target/PowerPC/PPCFrameLowering.h
lib/Target/PowerPC/PPCISelLowering.cpp
test/CodeGen/PowerPC/ppc64le-calls.ll
test/CodeGen/PowerPC/ppc64le-smallarg.ll