aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-06-13 05:14:44 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-06-13 05:14:44 +0000
commit004fb92615b23e661da9d0bfd883296094b8b777 (patch)
tree33dd655633b6fbd8fecd8f50e3c23c4e3062a8c1
parent9686ae7f4ea5f19ce77e31e64e0916db41a82662 (diff)
Cygwin support: use _alloca to allocate stack if > 4k. Patch by Anton Korobeynikov.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28764 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/X86RegisterInfo.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index 86e9151ea3..a27ca95563 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -740,7 +740,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
const Function* Fn = MF.getFunction();
const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>();
MachineInstr *MI;
-
+
// Get the number of bytes to allocate from the FrameInfo
unsigned NumBytes = MFI->getStackSize();
if (MFI->hasCalls() || MF.getFrameInfo()->hasVarSizedObjects()) {
@@ -760,9 +760,20 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
MFI->setStackSize(NumBytes);
if (NumBytes) { // adjust stack pointer: ESP -= numbytes
- unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri;
- MI = BuildMI(Opc, 1, X86::ESP,MachineOperand::UseAndDef).addImm(NumBytes);
- MBB.insert(MBBI, MI);
+ if (NumBytes >= 4096 && Subtarget->TargetType == X86Subtarget::isCygwin) {
+ // Function prologue calls _alloca to probe the stack when allocating
+ // more than 4k bytes in one go. Touching the stack at 4K increments is
+ // necessary to ensure that the guard pages used by the OS virtual memory
+ // manager are allocated in correct sequence.
+ MI = BuildMI(X86::MOV32ri, 2, X86::EAX).addImm(NumBytes);
+ MBB.insert(MBBI, MI);
+ MI = BuildMI(X86::CALLpcrel32, 1).addExternalSymbol("_alloca");
+ MBB.insert(MBBI, MI);
+ } else {
+ unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri;
+ MI = BuildMI(Opc, 1, X86::ESP,MachineOperand::UseAndDef).addImm(NumBytes);
+ MBB.insert(MBBI, MI);
+ }
}
if (hasFP(MF)) {
@@ -789,6 +800,12 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
Subtarget->TargetType == X86Subtarget::isCygwin) {
MI = BuildMI(X86::AND32ri, 2, X86::ESP).addImm(-Align);
MBB.insert(MBBI, MI);
+
+ // Probe the stack
+ MI = BuildMI(X86::MOV32ri, 2, X86::EAX).addImm(Align);
+ MBB.insert(MBBI, MI);
+ MI = BuildMI(X86::CALLpcrel32, 1).addExternalSymbol("_alloca");
+ MBB.insert(MBBI, MI);
}
}