Skip to content

Commit e652845

Browse files
jchauziAdam Harries
jchauzi
authored and
Adam Harries
committed
dpu: llvm: fix issue with stack size info
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
1 parent 02a70af commit e652845

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

llvm/lib/Target/DPU/DPUFrameLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,21 @@ void DPUFrameLowering::emitPrologue(MachineFunction &MF,
5252
const DPUInstrInfo &TII =
5353
*static_cast<const DPUInstrInfo *>(STI.getInstrInfo());
5454
DebugLoc DL;
55-
unsigned CFIIndex, StackSize;
55+
unsigned CFIIndex, StackSize, ActualStackSize;
5656

5757
if (!MFI.hasCalls()) {
5858
StackSize = 0;
59+
ActualStackSize = MFI.getStackSize();
5960
} else {
6061
// We reserve manually 8 bytes to store d22 (r22r23) at the end of the stack
6162
// for debug purpose. Not at the beginning because we do not have a frame
6263
// pointer (pointing at the beginning of the stack) but only a stack pointer
6364
// (pointing at the end of the stack)
6465
StackSize =
6566
alignTo(MFI.getStackSize() + STACK_SIZE_FOR_D22, getStackAlignment());
67+
ActualStackSize = StackSize;
6668
}
67-
MFI.setStackSize(StackSize);
69+
MFI.setStackSize(ActualStackSize);
6870

6971
CFIIndex =
7072
MF.addFrameInst(MCCFIInstruction::createDefCfaOffset(nullptr, StackSize));

llvm/lib/Target/DPU/DPUMachineFunctionInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ int DPUMachineFunctionInfo::getOffsetFromFrameIndex(int FrameIndex) {
2222
frameIndexOffsetSet.insert(FrameIndex);
2323
if (FrameIndex < 0)
2424
Offset -= STACK_SIZE_FOR_D22;
25-
Offset -= MFI.getStackSize();
25+
if (MFI.hasCalls()) {
26+
Offset -= MFI.getStackSize();
27+
}
2628
MFI.setObjectOffset(FrameIndex, Offset);
2729
return Offset;
2830
}

0 commit comments

Comments
 (0)