forked from rust-lang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SOL] Implement syscall instruction (#121)
* Implement static syscalls * Rename syscall and return * Remove external call from v3 and use pointer value directly
- Loading branch information
Showing
12 changed files
with
143 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,8 @@ enum NodeType : unsigned { | |
SELECT_CC, | ||
BR_CC, | ||
Wrapper, | ||
MEMCPY | ||
MEMCPY, | ||
SYSCALL, | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
; RUN: llc -march=sbf < %s | FileCheck --check-prefix=CHECK-V0 %s | ||
; RUN: llc -march=sbf -mattr=+static-syscalls -show-mc-encoding < %s | FileCheck --check-prefix=CHECK-V3 %s | ||
|
||
|
||
; Function Attrs: nounwind | ||
define dso_local i32 @test(i32 noundef %a, i32 noundef %b) { | ||
entry: | ||
; CHECK-LABEL: test | ||
|
||
; CHECK-V0: call 2 | ||
; CHECK-V3 syscall 2 # encoding: [0x95,0x00,0x00,0x00,0x01,0x00,0x00,0x00] | ||
%syscall_1 = tail call i32 inttoptr (i64 2 to ptr)(i32 noundef %a, i32 noundef %b) | ||
|
||
; CHECK-V0: call 11 | ||
; CHECK-V3: syscall 11 # encoding: [0x95,0x00,0x00,0x00,0x0b,0x00,0x00,0x00] | ||
%syscall_2 = tail call i32 inttoptr (i64 11 to ptr)(i32 noundef %a, i32 noundef %b) | ||
|
||
; CHECK-V0: call 112 | ||
; CHECK-V3: syscall 112 | ||
%syscall_3 = tail call i32 inttoptr (i64 112 to ptr)(i32 noundef %a, i32 noundef %b) | ||
|
||
%add_1 = add i32 %syscall_1, %syscall_2 | ||
%add_2 = add i32 %add_1, %syscall_3 | ||
ret i32 %add_1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
; RUN: llc -march=sbf -mattr=+static-syscalls < %s | FileCheck --check-prefix=CHECK %s | ||
|
||
; Syscall declaration in C: | ||
; | ||
; int c_declaration(int a, int b) { | ||
; int (*const syscall)(int a, int b) = (void*)50; | ||
; return syscall(a, b); | ||
; } | ||
; The following is the unoptimized output from clang: | ||
|
||
define dso_local i32 @c_declaration(i32 noundef %a, i32 noundef %b) #0 { | ||
entry: | ||
%a.addr = alloca i32, align 4 | ||
%b.addr = alloca i32, align 4 | ||
%syscall = alloca ptr, align 8 | ||
store i32 %a, ptr %a.addr, align 4 | ||
store i32 %b, ptr %b.addr, align 4 | ||
store ptr inttoptr (i64 50 to ptr), ptr %syscall, align 8 | ||
%0 = load i32, ptr %a.addr, align 4 | ||
%1 = load i32, ptr %b.addr, align 4 | ||
|
||
; Ensure the syscall instruction is emitted | ||
; CHECK: syscall 50 | ||
|
||
%call = call i32 inttoptr (i64 50 to ptr)(i32 noundef %0, i32 noundef %1) | ||
ret i32 %call | ||
} | ||
|
||
; Syscall declaration in Rust: | ||
; | ||
; #[no_mangle] | ||
; pub unsafe fn rust_declaration(b: u64) -> u32 { | ||
; let syscall : extern "C" fn(b: u64) -> u32 = core::mem::transmute(60u64); | ||
; return syscall(b); | ||
; } | ||
; The following is the unoptimized output from rustc: | ||
|
||
define i32 @rust_declaration(i64 %b) unnamed_addr { | ||
start: | ||
%syscall.dbg.spill = alloca [8 x i8], align 8 | ||
%b.dbg.spill = alloca [8 x i8], align 8 | ||
store i64 %b, ptr %b.dbg.spill, align 8 | ||
store ptr getelementptr (i8, ptr null, i64 60), ptr %syscall.dbg.spill, align 8 | ||
|
||
; Ensure the syscall instruction is emitted | ||
; CHECK: syscall 60 | ||
|
||
%_0 = call i32 getelementptr (i8, ptr null, i64 60)(i64 %b) | ||
ret i32 %_0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
llvm/test/MC/SBF/sbf-return.s → llvm/test/MC/SBF/sbf-return-syscall.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# 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 | ||
|
||
syscall 9 | ||
return | ||
|
||
// CHECK: 95 00 00 00 09 00 00 00 syscall 0x9 | ||
// CHECK: 9d 00 00 00 00 00 00 00 return |