Skip to content

Commit

Permalink
Implement return instruction (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte authored Dec 16, 2024
1 parent dda6181 commit 0e7ed1d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 8 deletions.
23 changes: 20 additions & 3 deletions llvm/lib/Target/SBF/SBFInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def SBFExplicitSignExt : Predicate<"Subtarget->getHasExplicitSignExt()">;
def SBFNoExplicitSignExt : Predicate<"!Subtarget->getHasExplicitSignExt()">;
def SBFNewMemEncoding : Predicate<"Subtarget->getNewMemEncoding()">, AssemblerPredicate<(all_of FeatureNewMemEncoding)>;
def SBFOldMemEncoding : Predicate<"!Subtarget->getNewMemEncoding()">;
def SBFHasStaticSyscalls : Predicate<"Subtarget->getHasStaticSyscalls()">;
def SBFNoStaticSyscalls : Predicate<"!Subtarget->getHasStaticSyscalls()">;

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

class RET<string OpcodeStr>
class EXIT<string OpcodeStr>
: TYPE_ALU_JMP<SBF_EXIT.Value, SBF_K.Value,
(outs),
(ins),
Expand All @@ -865,8 +867,23 @@ class RET<string OpcodeStr>
}

let isReturn = 1, isTerminator = 1, hasDelaySlot=0, isBarrier = 1,
isNotDuplicable = 1 in {
def RET : RET<"exit">;
isNotDuplicable = 1, Predicates = [SBFNoStaticSyscalls] in {
def EXIT : EXIT<"exit">;
}

class RETURN<string OpcodeStr>
: TYPE_ALU_JMP<SBF_EXIT.Value, SBF_X.Value,
(outs),
(ins),
!strconcat(OpcodeStr, ""),
[(SBFretglue)]> {
let Inst{31-0} = 0;
let SBFClass = SBF_JMP;
}

let isReturn = 1, isTerminator = 1, hasDelaySlot=0, isBarrier = 1,
isNotDuplicable = 1, Predicates = [SBFHasStaticSyscalls] in {
def RETURN : RETURN<"return">;
}

// ADJCALLSTACKDOWN/UP pseudo insns
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SBF/SBFSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class SBFSubtarget : public SBFGenSubtargetInfo {
bool getHasStoreImm() const { return HasStoreImm; }
bool getHasExplicitSignExt() const { return HasExplicitSignExt; }
bool getNewMemEncoding() const { return NewMemEncoding; }
bool getHasStaticSyscalls() const { return HasStaticSyscalls; }
const SBFInstrInfo *getInstrInfo() const override { return &InstrInfo; }
const SBFFrameLowering *getFrameLowering() const override {
return &FrameLowering;
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SBF/objdump_cond_op.ll
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
%16 = phi i32 [ %14, %13 ], [ %10, %8 ]
ret i32 %16
; CHECK-LABEL: <LBB0_5>:
; CHECK: exit
; CHECK: return
}
attributes #0 = { norecurse nounwind }
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SBF/objdump_cond_op_2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ define i32 @test(i32, i32) local_unnamed_addr #0 {
%14 = phi i32 [ 0, %2 ], [ %9, %5 ]
ret i32 %14
; CHECK-LABEL: <LBB0_2>:
; CHECK: exit
; CHECK: return
}
attributes #0 = { norecurse nounwind readnone }
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SBF/objdump_static_var.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define dso_local i32 @test() local_unnamed_addr #0 {
%4 = add i32 %2, %3
; CHECK: add64 r0, r1
ret i32 %4
; CHECK: exit
; CHECK: return
}

attributes #0 = { norecurse nounwind }
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/SBF/objdump_trivial.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

; CHECK: jsgt r2, r1,
; CHECK: call 0x1
; CHECK: exit
; CHECK: return
; CHECK: call 0x2
; CHECK: exit
; CHECK: return

define void @foo(i32 %a) {
%b = icmp sgt i32 %a, -1
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/SBF/return_instr.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: llc < %s -march=sbf -show-mc-encoding | FileCheck --check-prefix=CHECK-V1 %s
; RUN: llc < %s -march=sbf -mattr=+static-syscalls -show-mc-encoding | FileCheck --check-prefix=CHECK-V2 %s

define dso_local i64 @rem(i64 %a) local_unnamed_addr #0 {
entry:
; CHECK-LABEL: rem
%rem = urem i64 %a, 15

; CHECK-V1: exit # encoding: [0x95,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
; CHECK-V2: return # encoding: [0x9d,0x00,0x00,0x00,0x00,0x00,0x00,0x00]


ret i64 %rem
}
3 changes: 3 additions & 0 deletions llvm/test/MC/Disassembler/SBF/sbf-jmp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@

# CHECK-NEW: exit
0x95,0x00,0x00,0x00,0x00,0x00,0x00,0x00

# CHECK-NEW: return
0x9d,0x00,0x00,0x00,0x00,0x00,0x00,0x00
6 changes: 6 additions & 0 deletions llvm/test/MC/SBF/sbf-return.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# RUN: llvm-mc -triple=sbf-solana-solana --mcpu=sbfv2 -filetype=obj -o %t %s
# RUN: llvm-objdump -d -r %t | FileCheck --check-prefix=CHECK %s

return

// CHECK: 9d 00 00 00 00 00 00 00 return

0 comments on commit 0e7ed1d

Please sign in to comment.