[X86] Split out the logic to select the stack probe function (NFC)

Patch 1 of 11 in 'Add a "probe-stack" attribute' review thread.

Patch by: <john.kare.alsaker@gmail.com>



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216233 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Philip Reames 2014-08-21 22:15:20 +00:00
parent a204592582
commit ecad452885
2 changed files with 25 additions and 11 deletions

View File

@ -352,6 +352,23 @@ static bool usesTheStack(const MachineFunction &MF) {
return false;
}
void X86FrameLowering::getStackProbeFunction(const X86Subtarget &STI,
unsigned &CallOp,
const char *&Symbol) {
CallOp = STI.is64Bit() ? X86::W64ALLOCA : X86::CALLpcrel32;
if (STI.is64Bit()) {
if (STI.isTargetCygMing()) {
Symbol = "___chkstk_ms";
} else {
Symbol = "__chkstk";
}
} else if (STI.isTargetCygMing())
Symbol = "_alloca";
else
Symbol = "_chkstk";
}
/// emitPrologue - Push callee-saved registers onto the stack, which
/// automatically adjust the stack pointer. Adjust the stack pointer to allocate
/// space for local variables. Also emit labels used by the exception handler to
@ -668,17 +685,9 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
// virtual memory manager are allocated in correct sequence.
if (NumBytes >= 4096 && STI.isOSWindows() && !STI.isTargetMacho()) {
const char *StackProbeSymbol;
unsigned CallOp;
if (Is64Bit) {
if (STI.isTargetCygMing()) {
StackProbeSymbol = "___chkstk_ms";
} else {
StackProbeSymbol = "__chkstk";
}
} else if (STI.isTargetCygMing())
StackProbeSymbol = "_alloca";
else
StackProbeSymbol = "_chkstk";
getStackProbeFunction(STI, CallOp, StackProbeSymbol);
// Check whether EAX is livein for this function.
bool isEAXAlive = isEAXLiveIn(MF);
@ -709,7 +718,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
}
BuildMI(MBB, MBBI, DL,
TII.get(Is64Bit ? X86::W64ALLOCA : X86::CALLpcrel32))
TII.get(CallOp))
.addExternalSymbol(StackProbeSymbol)
.addReg(StackPtr, RegState::Define | RegState::Implicit)
.addReg(X86::EFLAGS, RegState::Define | RegState::Implicit)

View File

@ -20,12 +20,17 @@ namespace llvm {
class MCSymbol;
class X86TargetMachine;
class X86Subtarget;
class X86FrameLowering : public TargetFrameLowering {
public:
explicit X86FrameLowering(StackDirection D, unsigned StackAl, int LAO)
: TargetFrameLowering(StackGrowsDown, StackAl, LAO) {}
static void getStackProbeFunction(const X86Subtarget &STI,
unsigned &CallOp,
const char *&Symbol);
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
DebugLoc DL) const;