From 54eed36da595f09c46a46b2b0b15757ea486b4c1 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Wed, 27 Jul 2005 06:06:29 +0000 Subject: [PATCH] Implement the optimization for the Red Zone on Darwin. This removes the unnecessary SP manipulation in leaf routines that don't need it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22522 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PPCRegisterInfo.cpp | 11 ++++++++--- lib/Target/PowerPC/README.txt | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Target/PowerPC/PPCRegisterInfo.cpp b/lib/Target/PowerPC/PPCRegisterInfo.cpp index bbcf7c37ef9..7977a005001 100644 --- a/lib/Target/PowerPC/PPCRegisterInfo.cpp +++ b/lib/Target/PowerPC/PPCRegisterInfo.cpp @@ -245,8 +245,13 @@ void PPC32RegisterInfo::emitPrologue(MachineFunction &MF) const { NumBytes += MFI->getMaxCallFrameSize(); } - // Do we need to allocate space on the stack? - if (NumBytes == 0) return; + // If we are a leaf function, and use up to 224 bytes of stack space, + // and don't have a frame pointer, then we do not need to adjust the stack + // pointer (we fit in the Red Zone). + if ((NumBytes == 0) || (NumBytes <= 224 && !hasFP(MF) && !MFI->hasCalls())) { + MFI->setStackSize(0); + return; + } // Add the size of R1 to NumBytes size for the store of R1 to the bottom // of the stack and round the size to a multiple of the alignment. @@ -258,7 +263,7 @@ void PPC32RegisterInfo::emitPrologue(MachineFunction &MF) const { // Update frame info to pretend that this is part of the stack... MFI->setStackSize(NumBytes); - // adjust stack pointer: r1 -= numbytes + // If , adjust stack pointer: r1 -= numbytes. if (NumBytes <= 32768) { MI=BuildMI(PPC::STWU,3).addReg(PPC::R1).addSImm(-NumBytes).addReg(PPC::R1); MBB.insert(MBBI, MI); diff --git a/lib/Target/PowerPC/README.txt b/lib/Target/PowerPC/README.txt index b1d3028572b..8c11c19c1a8 100644 --- a/lib/Target/PowerPC/README.txt +++ b/lib/Target/PowerPC/README.txt @@ -3,7 +3,6 @@ TODO: * implement do-loop -> bdnz transform * implement powerpc-64 for darwin * use stfiwx in float->int -* take advantage of the darwin red zone in PPC32RegisterInfo.cpp * be able to combine sequences like the following into 2 instructions: lis r2, ha16(l2__ZTV4Cell) la r2, lo16(l2__ZTV4Cell)(r2)