2012-02-18 12:03:15 +00:00
|
|
|
//===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-08-14 22:16:36 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-08-14 22:16:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//
|
2005-10-16 05:39:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-14 22:16:36 +00:00
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
|
|
|
|
#define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
|
2004-08-14 22:16:36 +00:00
|
|
|
|
2005-10-14 23:51:18 +00:00
|
|
|
#include "PPC.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2004-08-14 22:16:36 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2014-06-12 20:54:11 +00:00
|
|
|
class PPCSubtarget;
|
2004-08-14 22:16:36 +00:00
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
class PPCFrameLowering: public TargetFrameLowering {
|
2010-11-15 00:06:54 +00:00
|
|
|
const PPCSubtarget &Subtarget;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-08-14 22:16:36 +00:00
|
|
|
public:
|
2014-06-12 20:54:11 +00:00
|
|
|
PPCFrameLowering(const PPCSubtarget &STI);
|
2004-08-14 22:16:36 +00:00
|
|
|
|
2013-03-15 05:06:04 +00:00
|
|
|
unsigned determineFrameLayout(MachineFunction &MF,
|
|
|
|
bool UpdateMF = true,
|
|
|
|
bool UseEstimate = false) const;
|
2010-11-15 00:06:54 +00:00
|
|
|
|
|
|
|
/// emitProlog/emitEpilog - These methods insert prolog and epilog code into
|
|
|
|
/// the function.
|
2014-04-29 07:57:37 +00:00
|
|
|
void emitPrologue(MachineFunction &MF) const override;
|
|
|
|
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
|
2010-11-15 00:06:54 +00:00
|
|
|
|
2014-04-29 07:57:37 +00:00
|
|
|
bool hasFP(const MachineFunction &MF) const override;
|
2010-12-18 19:53:14 +00:00
|
|
|
bool needsFP(const MachineFunction &MF) const;
|
2013-03-21 19:03:19 +00:00
|
|
|
void replaceFPWithRealFP(MachineFunction &MF) const;
|
2010-11-18 21:19:35 +00:00
|
|
|
|
2010-11-27 23:05:25 +00:00
|
|
|
void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
|
2014-04-29 07:57:37 +00:00
|
|
|
RegScavenger *RS = nullptr) const override;
|
2013-03-14 20:33:40 +00:00
|
|
|
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
2014-04-29 07:57:37 +00:00
|
|
|
RegScavenger *RS = nullptr) const override;
|
2013-03-15 05:06:04 +00:00
|
|
|
void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
|
2010-11-27 23:05:25 +00:00
|
|
|
|
2012-09-12 14:47:47 +00:00
|
|
|
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
2014-04-29 07:57:37 +00:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2012-09-12 14:47:47 +00:00
|
|
|
|
2013-02-21 20:05:00 +00:00
|
|
|
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
2014-04-29 07:57:37 +00:00
|
|
|
MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const override;
|
2013-02-21 20:05:00 +00:00
|
|
|
|
2012-09-12 14:47:47 +00:00
|
|
|
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
2014-04-29 07:57:37 +00:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2012-09-12 14:47:47 +00:00
|
|
|
|
2010-11-15 00:06:54 +00:00
|
|
|
/// targetHandlesStackFrameRounding - Returns true if the target is
|
|
|
|
/// responsible for rounding up the stack frame (probably at emitPrologue
|
|
|
|
/// time).
|
2014-04-29 07:57:37 +00:00
|
|
|
bool targetHandlesStackFrameRounding() const override { return true; }
|
2010-11-15 00:06:54 +00:00
|
|
|
|
2006-12-06 17:42:06 +00:00
|
|
|
/// getReturnSaveOffset - Return the previous frame offset to save the
|
|
|
|
/// return address.
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
|
2009-07-03 06:47:08 +00:00
|
|
|
if (isDarwinABI)
|
2009-08-15 11:54:46 +00:00
|
|
|
return isPPC64 ? 16 : 8;
|
2009-07-03 06:47:08 +00:00
|
|
|
// SVR4 ABI:
|
2009-08-15 11:54:46 +00:00
|
|
|
return isPPC64 ? 16 : 4;
|
2004-08-14 22:16:36 +00:00
|
|
|
}
|
2006-12-06 17:42:06 +00:00
|
|
|
|
[PowerPC] Simplify and improve loading into TOC register
During an indirect function call sequence on the 64-bit SVR4 ABI,
generate code must load and then restore the TOC register.
This does not use a regular LOAD instruction since the TOC
register r2 is marked as reserved. Instead, the are two
special instruction patterns:
let RST = 2, DS = 2 in
def LDinto_toc: DSForm_1a<58, 0, (outs), (ins g8rc:$reg),
"ld 2, 8($reg)", IIC_LdStLD,
[(PPCload_toc i64:$reg)]>, isPPC64;
let RST = 2, DS = 10, RA = 1 in
def LDtoc_restore : DSForm_1a<58, 0, (outs), (ins),
"ld 2, 40(1)", IIC_LdStLD,
[(PPCtoc_restore)]>, isPPC64;
Note that these not only restrict the destination of the
load to r2, but they also restrict the *source* of the
load to particular address combinations. The latter is
a problem when we want to support the ELFv2 ABI, since
there the TOC save slot is no longer at 40(1).
This patch replaces those two instructions with a single
instruction pattern that only hard-codes r2 as destination,
but supports generic addresses as source. This will allow
supporting the ELFv2 ABI, and also helps generate more
efficient code for calls to absolute addresses (allowing
simplification of the ppc64-calls.ll test case).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211193 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-18 17:52:49 +00:00
|
|
|
/// getTOCSaveOffset - Return the previous frame offset to save the
|
|
|
|
/// TOC register -- 64-bit SVR4 ABI only.
|
[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
2014-07-20 23:43:15 +00:00
|
|
|
static unsigned getTOCSaveOffset(bool isELFv2ABI) {
|
|
|
|
return isELFv2ABI ? 24 : 40;
|
[PowerPC] Simplify and improve loading into TOC register
During an indirect function call sequence on the 64-bit SVR4 ABI,
generate code must load and then restore the TOC register.
This does not use a regular LOAD instruction since the TOC
register r2 is marked as reserved. Instead, the are two
special instruction patterns:
let RST = 2, DS = 2 in
def LDinto_toc: DSForm_1a<58, 0, (outs), (ins g8rc:$reg),
"ld 2, 8($reg)", IIC_LdStLD,
[(PPCload_toc i64:$reg)]>, isPPC64;
let RST = 2, DS = 10, RA = 1 in
def LDtoc_restore : DSForm_1a<58, 0, (outs), (ins),
"ld 2, 40(1)", IIC_LdStLD,
[(PPCtoc_restore)]>, isPPC64;
Note that these not only restrict the destination of the
load to r2, but they also restrict the *source* of the
load to particular address combinations. The latter is
a problem when we want to support the ELFv2 ABI, since
there the TOC save slot is no longer at 40(1).
This patch replaces those two instructions with a single
instruction pattern that only hard-codes r2 as destination,
but supports generic addresses as source. This will allow
supporting the ELFv2 ABI, and also helps generate more
efficient code for calls to absolute addresses (allowing
simplification of the ppc64-calls.ll test case).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211193 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-18 17:52:49 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
/// getFramePointerSaveOffset - Return the previous frame offset to save the
|
|
|
|
/// frame pointer.
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
|
2009-07-03 06:47:08 +00:00
|
|
|
// For the Darwin ABI:
|
2009-11-24 22:59:02 +00:00
|
|
|
// We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
|
|
|
|
// for saving the frame pointer (if needed.) While the published ABI has
|
|
|
|
// not used this slot since at least MacOSX 10.2, there is older code
|
|
|
|
// around that does use it, and that needs to continue to work.
|
2009-07-03 06:47:08 +00:00
|
|
|
if (isDarwinABI)
|
2009-11-24 22:59:02 +00:00
|
|
|
return isPPC64 ? -8U : -4U;
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2009-08-15 11:54:46 +00:00
|
|
|
// SVR4 ABI: First slot in the general register save area.
|
2009-12-18 13:00:34 +00:00
|
|
|
return isPPC64 ? -8U : -4U;
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2013-07-17 00:45:52 +00:00
|
|
|
/// getBasePointerSaveOffset - Return the previous frame offset to save the
|
|
|
|
/// base pointer.
|
2014-07-18 23:29:49 +00:00
|
|
|
static unsigned getBasePointerSaveOffset(bool isPPC64,
|
|
|
|
bool isDarwinABI,
|
|
|
|
bool isPIC) {
|
2013-07-17 00:45:52 +00:00
|
|
|
if (isDarwinABI)
|
|
|
|
return isPPC64 ? -16U : -8U;
|
|
|
|
|
|
|
|
// SVR4 ABI: First slot in the general register save area.
|
2014-07-18 23:29:49 +00:00
|
|
|
return isPPC64 ? -16U : isPIC ? -12U : -8U;
|
2013-07-17 00:45:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
/// getLinkageSize - Return the size of the PowerPC ABI linkage area.
|
|
|
|
///
|
[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
2014-07-20 23:43:15 +00:00
|
|
|
static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
|
|
|
|
bool isELFv2ABI) {
|
2009-08-15 11:54:46 +00:00
|
|
|
if (isDarwinABI || isPPC64)
|
[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
2014-07-20 23:43:15 +00:00
|
|
|
return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2009-07-03 06:47:08 +00:00
|
|
|
// SVR4 ABI:
|
2007-04-03 12:35:28 +00:00
|
|
|
return 8;
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 17:58:47 +00:00
|
|
|
const SpillSlot *
|
2014-06-12 20:54:11 +00:00
|
|
|
getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
|
2004-08-14 22:16:36 +00:00
|
|
|
};
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|