[SystemZ] Fix common-code users of stack size

On SystemZ we need to provide a register save area of 160 bytes to
any called function.  This size needs to be added when allocating
stack in the function prologue.  However, it was not accounted for
as part of MachineFrameInfo::getStackSize(); instead the back-end
used a private routine getAllocatedStackSize().

This is OK for code-gen purposes, but it breaks other users of
the getStackSize() routine, in particular it breaks the recently-
added -stack-size-section feature.

Fix this by updating the main stack size tracked by common code
(in emitPrologue) instead of using the private routine.

No change in code generation intended.

llvm-svn: 326610
This commit is contained in:
Ulrich Weigand 2018-03-02 20:38:41 +00:00
parent 18f6930fef
commit 3206388870
3 changed files with 49 additions and 47 deletions

View File

@ -371,7 +371,15 @@ void SystemZFrameLowering::emitPrologue(MachineFunction &MF,
}
}
uint64_t StackSize = getAllocatedStackSize(MF);
uint64_t StackSize = MFFrame.getStackSize();
// We need to allocate the ABI-defined 160-byte base area whenever
// we allocate stack space for our own use and whenever we call another
// function.
if (StackSize || MFFrame.hasVarSizedObjects() || MFFrame.hasCalls()) {
StackSize += SystemZMC::CallFrameSize;
MFFrame.setStackSize(StackSize);
}
if (StackSize) {
// Determine if we want to store a backchain.
bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain");
@ -454,11 +462,12 @@ void SystemZFrameLowering::emitEpilogue(MachineFunction &MF,
auto *ZII =
static_cast<const SystemZInstrInfo *>(MF.getSubtarget().getInstrInfo());
SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
MachineFrameInfo &MFFrame = MF.getFrameInfo();
// Skip the return instruction.
assert(MBBI->isReturn() && "Can only insert epilogue into returning blocks");
uint64_t StackSize = getAllocatedStackSize(MF);
uint64_t StackSize = MFFrame.getStackSize();
if (ZFI->getLowSavedGPR()) {
--MBBI;
unsigned Opcode = MBBI->getOpcode();
@ -495,46 +504,6 @@ bool SystemZFrameLowering::hasFP(const MachineFunction &MF) const {
MF.getInfo<SystemZMachineFunctionInfo>()->getManipulatesSP());
}
int SystemZFrameLowering::getFrameIndexReference(const MachineFunction &MF,
int FI,
unsigned &FrameReg) const {
const MachineFrameInfo &MFFrame = MF.getFrameInfo();
const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
// Fill in FrameReg output argument.
FrameReg = RI->getFrameRegister(MF);
// Start with the offset of FI from the top of the caller-allocated frame
// (i.e. the top of the 160 bytes allocated by the caller). This initial
// offset is therefore negative.
int64_t Offset = (MFFrame.getObjectOffset(FI) +
MFFrame.getOffsetAdjustment());
// Make the offset relative to the incoming stack pointer.
Offset -= getOffsetOfLocalArea();
// Make the offset relative to the bottom of the frame.
Offset += getAllocatedStackSize(MF);
return Offset;
}
uint64_t SystemZFrameLowering::
getAllocatedStackSize(const MachineFunction &MF) const {
const MachineFrameInfo &MFFrame = MF.getFrameInfo();
// Start with the size of the local variables and spill slots.
uint64_t StackSize = MFFrame.getStackSize();
// We need to allocate the ABI-defined 160-byte base area whenever
// we allocate stack space for our own use and whenever we call another
// function.
if (StackSize || MFFrame.hasVarSizedObjects() || MFFrame.hasCalls())
StackSize += SystemZMC::CallFrameSize;
return StackSize;
}
bool
SystemZFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
// The ABI requires us to allocate 160 bytes of stack space for the callee,

View File

@ -43,16 +43,11 @@ public:
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
bool hasFP(const MachineFunction &MF) const override;
int getFrameIndexReference(const MachineFunction &MF, int FI,
unsigned &FrameReg) const override;
bool hasReservedCallFrame(const MachineFunction &MF) const override;
MachineBasicBlock::iterator
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const override;
// Return the number of bytes in the callee-allocated part of the frame.
uint64_t getAllocatedStackSize(const MachineFunction &MF) const;
// Return the byte offset from the incoming stack pointer of Reg's
// ABI-defined save slot. Return 0 if no slot is defined for Reg.
unsigned getRegSpillOffset(unsigned Reg) const {

View File

@ -0,0 +1,38 @@
; RUN: llc < %s -mtriple=s390x-linux-gnu -stack-size-section | FileCheck %s
; CHECK-LABEL: func1:
; CHECK: .section .stack_sizes,"",@progbits
; CHECK-NEXT: .quad func1
; CHECK-NEXT: .byte 0
define void @func1(i32, i32) #0 {
ret void
}
; CHECK-LABEL: func2:
; CHECK: .section .stack_sizes,"",@progbits
; CHECK-NEXT: .quad func2
; CHECK-NEXT: .ascii "\250\001"
define void @func2(i32, i32) #0 {
alloca i32, align 4
alloca i32, align 4
ret void
}
; CHECK-LABEL: func3:
; CHECK: .section .stack_sizes,"",@progbits
; CHECK-NEXT: .quad func3
; CHECK-NEXT: .ascii "\250\001"
define void @func3() #0 {
alloca i32, align 4
call void @func1(i32 1, i32 2)
ret void
}
; CHECK-LABEL: dynalloc:
; CHECK-NOT: .section .stack_sizes
define void @dynalloc(i32 %N) #0 {
alloca i32, i32 %N
ret void
}
attributes #0 = { "no-frame-pointer-elim"="true" }