Round number of bytes allocated on the stack up to a multiple of 4 so that the
authorChris Lattner <sabre@nondot.org>
Tue, 17 Dec 2002 03:15:26 +0000 (03:15 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Dec 2002 03:15:26 +0000 (03:15 +0000)
stack remains aligned

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5095 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86RegisterInfo.cpp

index fc87a02e3b367146a9871bbdd01f9737e1649af5..909a79cee708f525cdbfe9ee208d1ce2f3f9700e 100644 (file)
@@ -113,10 +113,13 @@ const unsigned* X86RegisterInfo::getCallerSaveRegs() const {
 }
 
 void X86RegisterInfo::emitPrologue(MachineFunction &MF,
-                                   unsigned numBytes) const {
+                                   unsigned NumBytes) const {
   MachineBasicBlock &MBB = MF.front();   // Prolog goes in entry BB
   MachineBasicBlock::iterator MBBI = MBB.begin();
 
+  // Round stack allocation up to a nice alignment to keep the stack aligned
+  NumBytes = (NumBytes + 3) & ~3;
+
   // PUSH ebp
   MachineInstr *MI = BuildMI(X86::PUSHr32, 1).addReg(X86::EBP);
   MBBI = ++MBB.insert(MBBI, MI);
@@ -126,7 +129,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF,
   MBBI = ++MBB.insert(MBBI, MI);
 
   // adjust stack pointer: ESP -= numbytes
-  MI  = BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(numBytes);
+  MI  = BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes);
   MBBI = ++MBB.insert(MBBI, MI);
 }