mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 16:24:23 +00:00
Refactor code that adjusts the offsets of stack objects.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58829 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -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
|
/// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
|
||||||
/// abstract stack objects.
|
/// abstract stack objects.
|
||||||
@ -387,51 +413,15 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
|||||||
const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
|
const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
|
||||||
if (RS && RegInfo->hasFP(Fn)) {
|
if (RS && RegInfo->hasFP(Fn)) {
|
||||||
int SFI = RS->getScavengingFrameIndex();
|
int SFI = RS->getScavengingFrameIndex();
|
||||||
if (SFI >= 0) {
|
if (SFI >= 0)
|
||||||
// If stack grows down, we need to add size of the lowest
|
AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the stack protector comes before the local variables on the
|
// Make sure that the stack protector comes before the local variables on the
|
||||||
// stack.
|
// stack.
|
||||||
if (FFI->getStackProtectorIndex() >= 0) {
|
if (FFI->getStackProtectorIndex() >= 0)
|
||||||
int FI = FFI->getStackProtectorIndex();
|
AdjustStackOffset(FFI, FFI->getStackProtectorIndex(), StackGrowsDown,
|
||||||
|
Offset, MaxAlign);
|
||||||
// If stack grows down, we need to add size of find the lowest
|
|
||||||
// address of the object.
|
|
||||||
if (StackGrowsDown)
|
|
||||||
Offset += FFI->getObjectSize(FI);
|
|
||||||
|
|
||||||
unsigned Align = FFI->getObjectAlignment(FI);
|
|
||||||
|
|
||||||
// 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(FI, -Offset); // Set the computed offset
|
|
||||||
} else {
|
|
||||||
FFI->setObjectOffset(FI, Offset);
|
|
||||||
Offset += FFI->getObjectSize(FI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then assign frame offsets to stack objects that are not used to spill
|
// Then assign frame offsets to stack objects that are not used to spill
|
||||||
// callee saved registers.
|
// callee saved registers.
|
||||||
@ -445,50 +435,15 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
|||||||
if (FFI->getStackProtectorIndex() == (int)i)
|
if (FFI->getStackProtectorIndex() == (int)i)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If stack grows down, we need to add size of find the lowest
|
AdjustStackOffset(FFI, i, StackGrowsDown, Offset, MaxAlign);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the special register scavenging spill slot is closest to the
|
// Make sure the special register scavenging spill slot is closest to the
|
||||||
// stack pointer.
|
// stack pointer.
|
||||||
if (RS && !RegInfo->hasFP(Fn)) {
|
if (RS && !RegInfo->hasFP(Fn)) {
|
||||||
int SFI = RS->getScavengingFrameIndex();
|
int SFI = RS->getScavengingFrameIndex();
|
||||||
if (SFI >= 0) {
|
if (SFI >= 0)
|
||||||
// If stack grows down, we need to add size of find the lowest
|
AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round up the size to a multiple of the alignment, but only if there are
|
// Round up the size to a multiple of the alignment, but only if there are
|
||||||
|
Reference in New Issue
Block a user