X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FPrologEpilogInserter.cpp;h=4ebf742a4c316cb6040dfc426ac4e94453c9f963;hb=8ac0d4b4fb10406278cd600214cd3ee6d76620cd;hp=2469c8e000c4fdacafeb27d20c9e187701b60901;hpb=f6a9988ceab0ca660fa4f4e89d8d683f487118eb;p=oota-llvm.git diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp index 2469c8e000c..4ebf742a4c3 100644 --- a/lib/CodeGen/PrologEpilogInserter.cpp +++ b/lib/CodeGen/PrologEpilogInserter.cpp @@ -273,10 +273,10 @@ void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) { MBB = FI; I = MBB->end(); --I; - // Skip over all "return" instructions, which are part of the return + // Skip over all terminator instructions, which are part of the return // sequence. MachineBasicBlock::iterator I2 = I; - while (I2 != MBB->begin() && (--I2)->getDesc().isReturn()) + while (I2 != MBB->begin() && (--I2)->getDesc().isTerminator()) I = I2; bool AtStart = I == MBB->begin(); @@ -306,6 +306,32 @@ void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) { } } +/// AdjustStackOffset - Helper function used to adjust the stack frame offset. +static inline void +AdjustStackOffset(MachineFrameInfo *FFI, int FrameIdx, + bool StackGrowsDown, int64_t &Offset, + unsigned &MaxAlign) { + // If stack grows down, we need to add size of find the lowest address of the + // object. + if (StackGrowsDown) + Offset += FFI->getObjectSize(FrameIdx); + + unsigned Align = FFI->getObjectAlignment(FrameIdx); + + // If the alignment of this object is greater than that of the stack, then + // increase the stack alignment to match. + MaxAlign = std::max(MaxAlign, Align); + + // Adjust to alignment boundary. + Offset = (Offset + Align - 1) / Align * Align; + + if (StackGrowsDown) { + FFI->setObjectOffset(FrameIdx, -Offset); // Set the computed offset + } else { + FFI->setObjectOffset(FrameIdx, Offset); + Offset += FFI->getObjectSize(FrameIdx); + } +} /// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the /// abstract stack objects. @@ -387,25 +413,16 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo(); if (RS && RegInfo->hasFP(Fn)) { int SFI = RS->getScavengingFrameIndex(); - if (SFI >= 0) { - // If stack grows down, we need to add size of the lowest - // address of the object. - if (StackGrowsDown) - Offset += FFI->getObjectSize(SFI); - - unsigned Align = FFI->getObjectAlignment(SFI); - // Adjust to alignment boundary - Offset = (Offset+Align-1)/Align*Align; - - if (StackGrowsDown) { - FFI->setObjectOffset(SFI, -Offset); // Set the computed offset - } else { - FFI->setObjectOffset(SFI, Offset); - Offset += FFI->getObjectSize(SFI); - } - } + if (SFI >= 0) + AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign); } + // Make sure that the stack protector comes before the local variables on the + // stack. + if (FFI->getStackProtectorIndex() >= 0) + AdjustStackOffset(FFI, FFI->getStackProtectorIndex(), StackGrowsDown, + Offset, MaxAlign); + // Then assign frame offsets to stack objects that are not used to spill // callee saved registers. for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) { @@ -415,51 +432,18 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { continue; if (FFI->isDeadObjectIndex(i)) continue; + if (FFI->getStackProtectorIndex() == (int)i) + continue; - // If stack grows down, we need to add size of find the lowest - // address of the object. - if (StackGrowsDown) - Offset += FFI->getObjectSize(i); - - unsigned Align = FFI->getObjectAlignment(i); - // If the alignment of this object is greater than that of the stack, then - // increase the stack alignment to match. - MaxAlign = std::max(MaxAlign, Align); - // Adjust to alignment boundary - Offset = (Offset+Align-1)/Align*Align; - - if (StackGrowsDown) { - FFI->setObjectOffset(i, -Offset); // Set the computed offset - } else { - FFI->setObjectOffset(i, Offset); - Offset += FFI->getObjectSize(i); - } + AdjustStackOffset(FFI, i, StackGrowsDown, Offset, MaxAlign); } // Make sure the special register scavenging spill slot is closest to the // stack pointer. if (RS && !RegInfo->hasFP(Fn)) { int SFI = RS->getScavengingFrameIndex(); - if (SFI >= 0) { - // If stack grows down, we need to add size of find the lowest - // address of the object. - if (StackGrowsDown) - Offset += FFI->getObjectSize(SFI); - - unsigned Align = FFI->getObjectAlignment(SFI); - // If the alignment of this object is greater than that of the - // stack, then increase the stack alignment to match. - MaxAlign = std::max(MaxAlign, Align); - // Adjust to alignment boundary - Offset = (Offset+Align-1)/Align*Align; - - if (StackGrowsDown) { - FFI->setObjectOffset(SFI, -Offset); // Set the computed offset - } else { - FFI->setObjectOffset(SFI, Offset); - Offset += FFI->getObjectSize(SFI); - } - } + if (SFI >= 0) + AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign); } // Round up the size to a multiple of the alignment, but only if there are