Skip to content

Commit

Permalink
[SOL] Add tests for call (anza-xyz#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jan 30, 2024
1 parent e3f1399 commit 9e213d9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Target/SBF/SBFTargetFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def FeatureRelocAbs64 : SubtargetFeature<"reloc-abs64", "UseRelocAbs64", "true",
"Fix 64bit data relocations">;

def FeatureStaticSyscalls : SubtargetFeature<"static-syscalls", "HasStaticSyscalls", "true",
"Marker feature used for conditional compilation">;
"Enable static syscalls">;

def FeatureDisableNeg : SubtargetFeature<"no-neg", "DisableNeg", "true",
"Disable the neg instruction">;
Expand Down
46 changes: 46 additions & 0 deletions llvm/test/CodeGen/SBF/call_internal.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
; RUN: llc < %s -march=sbf --show-mc-encoding | FileCheck --check-prefix=CHECK-ASM %s
; RUN: llc -march=sbf --filetype=obj -o - %s | llvm-objdump -d - | FileCheck --check-prefix=CHECK-OBJ %s
; RUN: llc < %s -march=sbf -mcpu=sbfv2 --show-mc-encoding | FileCheck --check-prefix=CHECK-ASM %s
; RUN: llc -march=sbf -mcpu=sbfv2 --filetype=obj -o - %s | llvm-objdump -d -
; | FileCheck --check-prefix=CHECK-OBJ %s

@.str = private unnamed_addr constant [5 x i8] c"foo\0A\00", align 1

; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none)
define dso_local i64 @sum(i64 noundef %a, i64 noundef %b) local_unnamed_addr #0 {
entry:
%add = add i64 %b, %a
ret i64 %add
}

; Function Attrs: nounwind
define dso_local i64 @entrypoint(ptr noundef %input) local_unnamed_addr #1 {
entry:
; CHECK-ASM: call 1811268606 # encoding: [0x85,0x00,0x00,0x00,0xfe,0xc3,0xf5,0x6b]
; CHECK-OBJ: 85 00 00 00 fe c3 f5 6b call 0x6bf5c3fe

tail call void inttoptr (i64 1811268606 to ptr)(ptr noundef nonnull @.str, i64 noundef 4) #3
%add.ptr = getelementptr inbounds i8, ptr %input, i64 4

; CHECK-ASM: call invoke_c # encoding: [0x85'A',A,A,A,0x00,0x00,0x00,0x00]
; CHECK-ASM: fixup A - offset: 0, value: invoke_c, kind: FK_PCRel_4
; CHECK-OBJ: 85 10 00 00 ff ff ff ff call -0x1

tail call void @invoke_c(ptr noundef %input) #3
%0 = load i64, ptr %input, align 8, !tbaa !3
%1 = load i64, ptr %add.ptr, align 8, !tbaa !3

; CHECK-ASM: call sum # encoding: [0x85'A',A,A,A,0x00,0x00,0x00,0x00]
; CHECK-ASM: fixup A - offset: 0, value: sum, kind: FK_PCRel_4
; CHECK-OBJ: 85 10 00 00 ff ff ff ff call -0x1

%call = tail call i64 @sum(i64 noundef %0, i64 noundef %1)
ret i64 %call
}

declare dso_local void @invoke_c(ptr noundef) local_unnamed_addr #2


!3 = !{!4, !4, i64 0}
!4 = !{!"long", !5, i64 0}
!5 = !{!"omnipotent char"}
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 @@ -145,5 +145,8 @@
# CHECK-NEW: callx r4
0x8d,0x00,0x00,0x00,0x04,0x00,0x00,0x00

# CHECK-NEW: call -1
0x85,0x10,0x00,0x00,0xff,0xff,0xff,0xff

# CHECK-NEW: exit
0x95,0x00,0x00,0x00,0x00,0x00,0x00,0x00
10 changes: 10 additions & 0 deletions llvm/test/MC/SBF/call.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# RUN: llvm-mc -triple=sbf-solana-solana -filetype=obj -o %t %s
# RUN: llvm-objdump -d -r %t | FileCheck --check-prefix=CHECK %s
# 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

call 1823123
call sum

// CHECK: 85 00 00 00 93 d1 1b 00 call 0x1bd193
// CHECK: 85 10 00 00 ff ff ff ff call -0x1

0 comments on commit 9e213d9

Please sign in to comment.