Skip to content

[M68k] Emit RTE for interrupt handler. #72787

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

Merged
merged 1 commit into from
Dec 4, 2023
Merged
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
11 changes: 5 additions & 6 deletions llvm/lib/Target/M68k/M68kExpandPseudo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,11 @@ bool M68kExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
return true;
}
case M68k::RET: {
// Adjust stack to erase error code
int64_t StackAdj = MBBI->getOperand(0).getImm();
MachineInstrBuilder MIB;

if (StackAdj == 0) {
MIB = BuildMI(MBB, MBBI, DL, TII->get(M68k::RTS));
if (MBB.getParent()->getFunction().getCallingConv() ==
CallingConv::M68k_INTR) {
BuildMI(MBB, MBBI, DL, TII->get(M68k::RTE));
} else if (int64_t StackAdj = MBBI->getOperand(0).getImm(); StackAdj == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just } else if (MBBI->getOperand(0).getImm() == 0) { ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, such a blunder.

BuildMI(MBB, MBBI, DL, TII->get(M68k::RTS));
} else {
// Copy return address from stack to a free address(A0 or A1) register
// TODO check if pseudo expand uses free address register
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/M68k/M68kInstrControl.td
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ def RTS : MxInst<(outs), (ins), "rts", []> {
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0101);
}

def RTE: MxInst<(outs), (ins), "rte", []> {
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0011);
}

let isCodeGenOnly = 1 in
def RET : MxPseudo<(outs), (ins i32imm:$adj, variable_ops),
[(MxRet timm:$adj)]>;
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/M68k/CConv/rte.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
; RUN: llc -mtriple m68k -o - %s | FileCheck %s

define cc101 void @interrupt_handler() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note for future us: we should probably give this CC a more descriptive name.

; CHECK-LABEL: interrupt_handler:
; CHECK: .cfi_startproc
; CHECK-NEXT: ; %bb.0: ; %entry
; CHECK-NEXT: rte
entry:
ret void
}