Skip to content

Commit

Permalink
dpu: llvm: fix issue with stack size info
Browse files Browse the repository at this point in the history
In case of a leaf function, we do not move the Stack Pointer.
To do so previously, we tricked the MachineFrameInfo by setting the StackSize to 0. This worked, but when emiting the .stack_sizes section, the information was incorrect.

Now StackSize in MachineFrameInfo is always correct. We are using the MachineFrameInfo::hasCalls method to check if we need to change the offset when doing stack accesses (in DPUMachineFunctionInfo::getOffsetFromFrameIndex).

fix #1
  • Loading branch information
jchauzi committed Aug 5, 2020
1 parent 10cb20b commit 9abd8af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/Target/DPU/DPUFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ void DPUFrameLowering::emitPrologue(MachineFunction &MF,
const DPUInstrInfo &TII =
*static_cast<const DPUInstrInfo *>(STI.getInstrInfo());
DebugLoc DL;
unsigned CFIIndex, StackSize;
unsigned CFIIndex, StackSize, ActualStackSize;

if (!MFI.hasCalls()) {
StackSize = 0;
ActualStackSize = MFI.getStackSize();
} else {
// We reserve manually 8 bytes to store d22 (r22r23) at the end of the stack
// for debug purpose. Not at the beginning because we do not have a frame
// pointer (pointing at the beginning of the stack) but only a stack pointer
// (pointing at the end of the stack)
StackSize =
alignTo(MFI.getStackSize() + STACK_SIZE_FOR_D22, getStackAlignment());
ActualStackSize = StackSize;
}
MFI.setStackSize(StackSize);
MFI.setStackSize(ActualStackSize);

CFIIndex =
MF.addFrameInst(MCCFIInstruction::createDefCfaOffset(nullptr, StackSize));
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/DPU/DPUMachineFunctionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ int DPUMachineFunctionInfo::getOffsetFromFrameIndex(int FrameIndex) {
frameIndexOffsetSet.insert(FrameIndex);
if (FrameIndex < 0)
Offset -= STACK_SIZE_FOR_D22;
Offset -= MFI.getStackSize();
if (MFI.hasCalls()) {
Offset -= MFI.getStackSize();
}
MFI.setObjectOffset(FrameIndex, Offset);
return Offset;
}

0 comments on commit 9abd8af

Please sign in to comment.