Skip to content
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
7 changes: 3 additions & 4 deletions src/irgenerator/GenTargetDependent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ std::string IRGenerator::getSysCallAsmString(uint8_t numRegs) const {
if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) {
static constexpr const char *regs[] = {"%rax", "%rdi", "%rsi", "%rdx", "%r10", "%r8", "%r9"};
for (uint8_t i = 0; i < numRegs; i++) {
// macOS syscall numbers are offset by 0x2000000
asmString << "movq $" << std::to_string(i) << ", " << regs[i] << "\n";
// macOS x86_64 syscall numbers are offset by 0x2000000 (BSD syscall class). "$$" emits a literal '$'.
if (i == 0)
asmString << "movq $(" << std::to_string(0x2000000) << " + " << std::to_string(i) << "), " << regs[i] << "\n";
else
asmString << "movq $" << std::to_string(i) << ", " << regs[i] << "\n";
asmString << "addq $$" << std::to_string(0x2000000) << ", %rax\n";
}
asmString << "syscall\n";
} else if (targetTriple.isAArch64()) {
Expand Down
29 changes: 29 additions & 0 deletions std/os/syscall_darwin_x86_64.spice
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Syscall numbers
public const unsigned short SYSCALL_READ = 3us;
public const unsigned short SYSCALL_WRITE = 4us;
public const unsigned short SYSCALL_OPEN = 5us;
public const unsigned short SYSCALL_CLOSE = 6us;
public const unsigned short SYSCALL_WAIT4 = 7us;
public const unsigned short SYSCALL_LINK = 9us;
public const unsigned short SYSCALL_UNLINK = 10us;
public const unsigned short SYSCALL_CHDIR = 12us;
public const unsigned short SYSCALL_FCHDIR = 13us;
public const unsigned short SYSCALL_MKNOD = 14us;
public const unsigned short SYSCALL_CHMOD = 15us;
public const unsigned short SYSCALL_CHOWN = 16us;
public const unsigned short SYSCALL_GETFSSTAT = 18us;
public const unsigned short SYSCALL_GETDTABLESIZE = 19us;
public const unsigned short SYSCALL_DUP = 20us;
public const unsigned short SYSCALL_PIPE = 21us;
public const unsigned short SYSCALL_GETPID = 39us;
public const unsigned short SYSCALL_KILL = 37us;
public const unsigned short SYSCALL_CREATE = 57us;
public const unsigned short SYSCALL_REMOVE = 58us;
public const unsigned short SYSCALL_EXECVE = 59us;
public const unsigned short SYSCALL_CHDIR_ROOT = 61us;
public const unsigned short SYSCALL_FCNTL = 62us;
public const unsigned short SYSCALL_DUP2 = 90us;
public const unsigned short SYSCALL_READV = 120us;
public const unsigned short SYSCALL_WRITEV = 121us;
public const unsigned short SYSCALL_PREAD = 140us;
public const unsigned short SYSCALL_PWRITE = 141us;
173 changes: 173 additions & 0 deletions test/test-files/benchmark/success-pidigits/ir-code-macos-amd64.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
; ModuleID = 'source.spice'
source_filename = "source.spice"

@printf.str.0 = private unnamed_addr constant [3 x i8] c"%d\00", align 4
@printf.str.1 = private unnamed_addr constant [2 x i8] c".\00", align 4

; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
define dso_local noundef i32 @main() #0 {
%result = alloca i32, align 4
%q = alloca i64, align 8
%q_new = alloca i64, align 8
%r = alloca i64, align 8
%r_new = alloca i64, align 8
%t = alloca i64, align 8
%t_new = alloca i64, align 8
%k = alloca i64, align 8
%k_new = alloca i64, align 8
%m = alloca i64, align 8
%x = alloca i64, align 8
%iterations = alloca i32, align 4
%printedDigits = alloca i32, align 4
%i = alloca i32, align 4
store i32 0, ptr %result, align 4
store i64 1, ptr %q, align 8
store i64 0, ptr %q_new, align 8
store i64 0, ptr %r, align 8
store i64 0, ptr %r_new, align 8
store i64 1, ptr %t, align 8
store i64 0, ptr %t_new, align 8
store i64 1, ptr %k, align 8
store i64 0, ptr %k_new, align 8
store i64 3, ptr %m, align 8
store i64 3, ptr %x, align 8
store i32 20, ptr %iterations, align 4
store i32 0, ptr %printedDigits, align 4
store i32 0, ptr %i, align 4
br label %for.head.L19

for.head.L19: ; preds = %for.tail.L19, %0
%1 = load i32, ptr %i, align 4
%2 = load i32, ptr %iterations, align 4
%3 = icmp slt i32 %1, %2
br i1 %3, label %for.body.L19, label %for.exit.L19

for.body.L19: ; preds = %for.head.L19
%4 = load i64, ptr %q, align 8
%5 = mul nsw i64 4, %4
%6 = load i64, ptr %r, align 8
%7 = add nsw i64 %5, %6
%8 = load i64, ptr %t, align 8
%9 = sub nsw i64 %7, %8
%10 = load i64, ptr %m, align 8
%11 = load i64, ptr %t, align 8
%12 = mul nsw i64 %10, %11
%13 = icmp slt i64 %9, %12
br i1 %13, label %if.then.L20, label %if.else.L20

if.then.L20: ; preds = %for.body.L19
%14 = load i64, ptr %m, align 8
%15 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i64 noundef %14)
%16 = load i32, ptr %printedDigits, align 4
%17 = icmp eq i32 %16, 0
br i1 %17, label %if.then.L22, label %if.exit.L22

if.then.L22: ; preds = %if.then.L20
%18 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1)
br label %if.exit.L22

if.exit.L22: ; preds = %if.then.L22, %if.then.L20
%19 = load i32, ptr %printedDigits, align 4
%20 = add nsw i32 %19, 1
store i32 %20, ptr %printedDigits, align 4
%21 = load i64, ptr %q, align 8
%22 = mul nsw i64 10, %21
store i64 %22, ptr %q_new, align 8
%23 = load i64, ptr %m, align 8
%24 = load i64, ptr %t, align 8
%25 = mul nsw i64 %23, %24
%26 = load i64, ptr %r, align 8
%27 = sub nsw i64 %26, %25
%28 = mul nsw i64 10, %27
store i64 %28, ptr %r_new, align 8
%29 = load i64, ptr %q, align 8
%30 = mul nsw i64 3, %29
%31 = load i64, ptr %r, align 8
%32 = add nsw i64 %30, %31
%33 = mul nsw i64 10, %32
%34 = load i64, ptr %t, align 8
%35 = sdiv i64 %33, %34
%36 = load i64, ptr %m, align 8
%37 = mul nsw i64 10, %36
%38 = sub nsw i64 %35, %37
store i64 %38, ptr %m, align 8
%39 = load i64, ptr %q_new, align 8
store i64 %39, ptr %q, align 8
%40 = load i64, ptr %r_new, align 8
store i64 %40, ptr %r, align 8
br label %if.exit.L20

if.else.L20: ; preds = %for.body.L19
%41 = load i64, ptr %q, align 8
%42 = load i64, ptr %k, align 8
%43 = mul nsw i64 %41, %42
store i64 %43, ptr %q_new, align 8
%44 = load i64, ptr %q, align 8
%45 = mul nsw i64 2, %44
%46 = load i64, ptr %r, align 8
%47 = add nsw i64 %45, %46
%48 = load i64, ptr %x, align 8
%49 = mul nsw i64 %47, %48
store i64 %49, ptr %r_new, align 8
%50 = load i64, ptr %t, align 8
%51 = load i64, ptr %x, align 8
%52 = mul nsw i64 %50, %51
store i64 %52, ptr %t_new, align 8
%53 = load i64, ptr %k, align 8
%54 = add nsw i64 %53, 1
store i64 %54, ptr %k_new, align 8
%55 = load i64, ptr %k, align 8
%56 = mul nsw i64 7, %55
%57 = add nsw i64 %56, 2
%58 = load i64, ptr %q, align 8
%59 = mul nsw i64 %58, %57
%60 = load i64, ptr %r, align 8
%61 = load i64, ptr %x, align 8
%62 = mul nsw i64 %60, %61
%63 = add nsw i64 %59, %62
%64 = load i64, ptr %t, align 8
%65 = load i64, ptr %x, align 8
%66 = mul nsw i64 %64, %65
%67 = sdiv i64 %63, %66
store i64 %67, ptr %m, align 8
%68 = load i64, ptr %x, align 8
%69 = add nsw i64 %68, 2
store i64 %69, ptr %x, align 8
%70 = load i64, ptr %q_new, align 8
store i64 %70, ptr %q, align 8
%71 = load i64, ptr %r_new, align 8
store i64 %71, ptr %r, align 8
%72 = load i64, ptr %t_new, align 8
store i64 %72, ptr %t, align 8
%73 = load i64, ptr %k_new, align 8
store i64 %73, ptr %k, align 8
br label %if.exit.L20

if.exit.L20: ; preds = %if.else.L20, %if.exit.L22
br label %for.tail.L19

for.tail.L19: ; preds = %if.exit.L20
%74 = load i32, ptr %i, align 4
%75 = add nsw i32 %74, 1
store i32 %75, ptr %i, align 4
br label %for.head.L19

for.exit.L19: ; preds = %for.head.L19
%76 = load i32, ptr %result, align 4
ret i32 %76
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1

attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable }
attributes #1 = { nofree nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIE Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 2}
!3 = !{i32 7, !"frame-pointer", i32 2}
!4 = !{!"spice version dev (https://github.com/spicelang/spice)"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
; ModuleID = 'source.spice'
source_filename = "source.spice"

@printf.str.0 = private unnamed_addr constant [15 x i8] c"Cell [1,3]: %d\00", align 4

; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
define dso_local noundef i32 @main() #0 {
%result = alloca i32, align 4
%a = alloca [10 x [10 x i32]], align 4
%i = alloca i32, align 4
%j = alloca i32, align 4
store i32 0, ptr %result, align 4
store [10 x [10 x i32]] zeroinitializer, ptr %a, align 4
store i32 0, ptr %i, align 4
br label %for.head.L3

for.head.L3: ; preds = %for.tail.L3, %0
%1 = load i32, ptr %i, align 4
%2 = icmp slt i32 %1, 10
br i1 %2, label %for.body.L3, label %for.exit.L3

for.body.L3: ; preds = %for.head.L3
store i32 0, ptr %j, align 4
br label %for.head.L4

for.head.L4: ; preds = %for.tail.L4, %for.body.L3
%3 = load i32, ptr %j, align 4
%4 = icmp slt i32 %3, 10
br i1 %4, label %for.body.L4, label %for.exit.L4

for.body.L4: ; preds = %for.head.L4
%5 = load i32, ptr %i, align 4
%6 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i64 0, i32 %5
%7 = load i32, ptr %j, align 4
%8 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i32 %7
%9 = load i32, ptr %i, align 4
%10 = load i32, ptr %j, align 4
%11 = mul nsw i32 %9, %10
store i32 %11, ptr %8, align 4
br label %for.tail.L4

for.tail.L4: ; preds = %for.body.L4
%12 = load i32, ptr %j, align 4
%13 = add nsw i32 %12, 1
store i32 %13, ptr %j, align 4
br label %for.head.L4

for.exit.L4: ; preds = %for.head.L4
br label %for.tail.L3

for.tail.L3: ; preds = %for.exit.L4
%14 = load i32, ptr %i, align 4
%15 = add nsw i32 %14, 1
store i32 %15, ptr %i, align 4
br label %for.head.L3

for.exit.L3: ; preds = %for.head.L3
%16 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i64 0, i32 1
%17 = getelementptr inbounds [10 x i32], ptr %16, i64 0, i32 3
%18 = load i32, ptr %17, align 4
%19 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i32 noundef %18)
%20 = load i32, ptr %result, align 4
ret i32 %20
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1

attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable }
attributes #1 = { nofree nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIE Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 2}
!3 = !{i32 7, !"frame-pointer", i32 2}
!4 = !{!"spice version dev (https://github.com/spicelang/spice)"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; ModuleID = 'source.spice'
source_filename = "source.spice"

@printf.str.1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 4

; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
%1 = tail call noundef i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @printf.str.1, i64 noundef 5535379567501308475)
%2 = tail call noundef i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @printf.str.1, i64 noundef 5535379567501308475)
ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1

attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable }
attributes #1 = { nofree nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIE Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 2}
!3 = !{i32 7, !"frame-pointer", i32 2}
!4 = !{!"spice version dev (https://github.com/spicelang/spice)"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; ModuleID = 'source.spice'
source_filename = "source.spice"

@printf.str.0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 4
@printf.str.1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 4

; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
define dso_local noundef i32 @main() #0 {
%result = alloca i32, align 4
store i32 0, ptr %result, align 4
%1 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.0, i64 noundef 5535379567501308475)
%2 = call noundef i32 (ptr, ...) @printf(ptr noundef @printf.str.1, i64 noundef 5535379567501308475)
%3 = load i32, ptr %result, align 4
ret i32 %3
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1

attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable }
attributes #1 = { nofree nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIE Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 2}
!3 = !{i32 7, !"frame-pointer", i32 2}
!4 = !{!"spice version dev (https://github.com/spicelang/spice)"}
Loading
Loading