Skip to content

[WIP] Emit tail calls to __mspabi_func_epilog_X #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions llvm/lib/Target/MSP430/MSP430FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,31 @@ bool MSP430FrameLowering::spillCalleeSavedRegisters(
return true;
}

const char *MSP430FrameLowering::tailCallNameForRestoringCalleSavedRegisters(MutableArrayRef<CalleeSavedInfo> CSI) const {
static unsigned Registers[] = {
/*MSP430::R4, ??? */ MSP430::R5, MSP430::R6, MSP430::R7,
MSP430::R8, MSP430::R9, MSP430::R10,
};
static const char *RestorerNames[] = {
nullptr,
"__mspabi_func_epilog_1",
"__mspabi_func_epilog_2",
"__mspabi_func_epilog_3",
"__mspabi_func_epilog_4",
"__mspabi_func_epilog_5",
"__mspabi_func_epilog_6",
"__mspabi_func_epilog_7",
};
const unsigned TotalCount = sizeof(Registers) / sizeof(Registers[0]);
const unsigned PoppedCount = CSI.size();
for (unsigned i = 0; i < PoppedCount; ++i) {
if (CSI[i].getReg() != Registers[TotalCount - PoppedCount + i]) {
return nullptr;
}
}
return RestorerNames[PoppedCount];
}

bool MSP430FrameLowering::restoreCalleeSavedRegisters(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
MutableArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
Expand All @@ -212,6 +237,12 @@ bool MSP430FrameLowering::restoreCalleeSavedRegisters(
MachineFunction &MF = *MBB.getParent();
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();

const char *RestorerName = tailCallNameForRestoringCalleSavedRegisters(CSI);
if (RestorerName != nullptr) {
BuildMI(MBB, MI, DL, TII.get(MSP430::JMP)).addExternalSymbol(RestorerName);
return true;
}

for (unsigned i = 0, e = CSI.size(); i != e; ++i)
BuildMI(MBB, MI, DL, TII.get(MSP430::POP16r), CSI[i].getReg());

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/MSP430/MSP430FrameLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MSP430FrameLowering : public TargetFrameLowering {
MachineBasicBlock::iterator MI,
ArrayRef<CalleeSavedInfo> CSI,
const TargetRegisterInfo *TRI) const override;
const char *tailCallNameForRestoringCalleSavedRegisters(MutableArrayRef<CalleeSavedInfo> CSI) const;
bool
restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/MSP430/epilog-spilled-restore.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: llc < %s | FileCheck %s

target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"
target triple = "msp430"

; TODO check other counts
; TODO check 7 regs! (something strange happens...)

define void @pops_4_regs() nounwind {
; CHECK-LABEL: pops_4_regs
call void asm sideeffect "", "~{r7},~{r8},~{r9},~{r10}"()
ret void
; CHECK: jmp __mspabi_func_epilog_4
}