Skip to content

Commit 0e7ed1d

Browse files
authored
Implement return instruction (#120)
1 parent dda6181 commit 0e7ed1d

File tree

9 files changed

+49
-8
lines changed

9 files changed

+49
-8
lines changed

llvm/lib/Target/SBF/SBFInstrInfo.td

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def SBFExplicitSignExt : Predicate<"Subtarget->getHasExplicitSignExt()">;
6969
def SBFNoExplicitSignExt : Predicate<"!Subtarget->getHasExplicitSignExt()">;
7070
def SBFNewMemEncoding : Predicate<"Subtarget->getNewMemEncoding()">, AssemblerPredicate<(all_of FeatureNewMemEncoding)>;
7171
def SBFOldMemEncoding : Predicate<"!Subtarget->getNewMemEncoding()">;
72+
def SBFHasStaticSyscalls : Predicate<"Subtarget->getHasStaticSyscalls()">;
73+
def SBFNoStaticSyscalls : Predicate<"!Subtarget->getHasStaticSyscalls()">;
7274

7375
def brtarget : Operand<OtherVT> {
7476
let PrintMethod = "printBrTargetOperand";
@@ -854,7 +856,7 @@ class NOP_I<string OpcodeStr>
854856
let hasSideEffects = 0, isCodeGenOnly = 1 in
855857
def NOP : NOP_I<"nop">;
856858

857-
class RET<string OpcodeStr>
859+
class EXIT<string OpcodeStr>
858860
: TYPE_ALU_JMP<SBF_EXIT.Value, SBF_K.Value,
859861
(outs),
860862
(ins),
@@ -865,8 +867,23 @@ class RET<string OpcodeStr>
865867
}
866868

867869
let isReturn = 1, isTerminator = 1, hasDelaySlot=0, isBarrier = 1,
868-
isNotDuplicable = 1 in {
869-
def RET : RET<"exit">;
870+
isNotDuplicable = 1, Predicates = [SBFNoStaticSyscalls] in {
871+
def EXIT : EXIT<"exit">;
872+
}
873+
874+
class RETURN<string OpcodeStr>
875+
: TYPE_ALU_JMP<SBF_EXIT.Value, SBF_X.Value,
876+
(outs),
877+
(ins),
878+
!strconcat(OpcodeStr, ""),
879+
[(SBFretglue)]> {
880+
let Inst{31-0} = 0;
881+
let SBFClass = SBF_JMP;
882+
}
883+
884+
let isReturn = 1, isTerminator = 1, hasDelaySlot=0, isBarrier = 1,
885+
isNotDuplicable = 1, Predicates = [SBFHasStaticSyscalls] in {
886+
def RETURN : RETURN<"return">;
870887
}
871888

872889
// ADJCALLSTACKDOWN/UP pseudo insns

llvm/lib/Target/SBF/SBFSubtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class SBFSubtarget : public SBFGenSubtargetInfo {
107107
bool getHasStoreImm() const { return HasStoreImm; }
108108
bool getHasExplicitSignExt() const { return HasExplicitSignExt; }
109109
bool getNewMemEncoding() const { return NewMemEncoding; }
110+
bool getHasStaticSyscalls() const { return HasStaticSyscalls; }
110111
const SBFInstrInfo *getInstrInfo() const override { return &InstrInfo; }
111112
const SBFFrameLowering *getFrameLowering() const override {
112113
return &FrameLowering;

llvm/test/CodeGen/SBF/objdump_cond_op.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
6767
%16 = phi i32 [ %14, %13 ], [ %10, %8 ]
6868
ret i32 %16
6969
; CHECK-LABEL: <LBB0_5>:
70-
; CHECK: exit
70+
; CHECK: return
7171
}
7272
attributes #0 = { norecurse nounwind }

llvm/test/CodeGen/SBF/objdump_cond_op_2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
3333
%14 = phi i32 [ 0, %2 ], [ %9, %5 ]
3434
ret i32 %14
3535
; CHECK-LABEL: <LBB0_2>:
36-
; CHECK: exit
36+
; CHECK: return
3737
}
3838
attributes #0 = { norecurse nounwind readnone }

llvm/test/CodeGen/SBF/objdump_static_var.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ define dso_local i32 @test() local_unnamed_addr #0 {
2323
%4 = add i32 %2, %3
2424
; CHECK: add64 r0, r1
2525
ret i32 %4
26-
; CHECK: exit
26+
; CHECK: return
2727
}
2828

2929
attributes #0 = { norecurse nounwind }

llvm/test/CodeGen/SBF/objdump_trivial.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
; CHECK: jsgt r2, r1,
44
; CHECK: call 0x1
5-
; CHECK: exit
5+
; CHECK: return
66
; CHECK: call 0x2
7-
; CHECK: exit
7+
; CHECK: return
88

99
define void @foo(i32 %a) {
1010
%b = icmp sgt i32 %a, -1

llvm/test/CodeGen/SBF/return_instr.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc < %s -march=sbf -show-mc-encoding | FileCheck --check-prefix=CHECK-V1 %s
2+
; RUN: llc < %s -march=sbf -mattr=+static-syscalls -show-mc-encoding | FileCheck --check-prefix=CHECK-V2 %s
3+
4+
define dso_local i64 @rem(i64 %a) local_unnamed_addr #0 {
5+
entry:
6+
; CHECK-LABEL: rem
7+
%rem = urem i64 %a, 15
8+
9+
; CHECK-V1: exit # encoding: [0x95,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
10+
; CHECK-V2: return # encoding: [0x9d,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
11+
12+
13+
ret i64 %rem
14+
}

llvm/test/MC/Disassembler/SBF/sbf-jmp.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,6 @@
108108

109109
# CHECK-NEW: exit
110110
0x95,0x00,0x00,0x00,0x00,0x00,0x00,0x00
111+
112+
# CHECK-NEW: return
113+
0x9d,0x00,0x00,0x00,0x00,0x00,0x00,0x00

llvm/test/MC/SBF/sbf-return.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# RUN: llvm-mc -triple=sbf-solana-solana --mcpu=sbfv2 -filetype=obj -o %t %s
2+
# RUN: llvm-objdump -d -r %t | FileCheck --check-prefix=CHECK %s
3+
4+
return
5+
6+
// CHECK: 9d 00 00 00 00 00 00 00 return

0 commit comments

Comments
 (0)