Created
May 7, 2015 14:03
-
-
Save waywardmonkeys/b0934fb1593c316e1f5e to your computer and use it in GitHub Desktop.
fib in Dylan and the LLVM backend
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
define function fib (n :: <integer>) => (fib :: <integer>) | |
if (n < 2) | |
n | |
else | |
fib(n - 1) + fib(n - 2) | |
end if | |
end; | |
format-out("%d ", fib(50)) |
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
define fastcc %struct.MV @KfibVfibI(i8* %nF1, i8* %.next, i8* %.function) { | |
bb.entry: | |
call void @llvm.dbg.value(metadata !{i8* %nF1}, i64 0, metadata !23) #0, !dbg !24 | |
%0 = ptrtoint i8* %nF1 to i64, !dbg !25 | |
%1 = icmp slt i64 %0, 9, !dbg !25 | |
%2 = select i1 %1, i8* bitcast (%KLbooleanGVKd* @KPtrueVKi to i8*), i8* bitcast (%KLbooleanGVKd* @KPfalseVKi to i8*), !dbg !25 | |
%3 = icmp ne i8* %2, bitcast (%KLbooleanGVKd* @KPfalseVKi to i8*), !dbg !25 | |
br i1 %3, label %4, label %5, !dbg !25 | |
; <label>:4 ; preds = %bb.entry | |
br label %34, !dbg !26 | |
; <label>:5 ; preds = %bb.entry | |
%6 = call { i64, i1 } @llvm.ssub.with.overflow.i64(i64 %0, i64 4) #0, !dbg !27 | |
%7 = extractvalue { i64, i1 } %6, 0, !dbg !27 | |
%8 = extractvalue { i64, i1 } %6, 1, !dbg !27 | |
br i1 %8, label %9, label %11, !dbg !27 | |
; <label>:9 ; preds = %5 | |
%10 = tail call fastcc %struct.MV @Kmachine_word_overflowVKmI(i8* undef, i8* undef), !dbg !27 | |
unreachable, !dbg !27 | |
; <label>:11 ; preds = %5 | |
%12 = inttoptr i64 %7 to i8*, !dbg !27 | |
%13 = call fastcc %struct.MV @KfibVfibI(i8* %12, i8* undef, i8* undef), !dbg !27 | |
%14 = extractvalue %struct.MV %13, 0, !dbg !27 | |
%15 = call { i64, i1 } @llvm.ssub.with.overflow.i64(i64 %0, i64 8) #0, !dbg !27 | |
%16 = extractvalue { i64, i1 } %15, 0, !dbg !27 | |
%17 = extractvalue { i64, i1 } %15, 1, !dbg !27 | |
br i1 %17, label %18, label %20, !dbg !27 | |
; <label>:18 ; preds = %11 | |
%19 = tail call fastcc %struct.MV @Kmachine_word_overflowVKmI(i8* undef, i8* undef), !dbg !27 | |
unreachable, !dbg !27 | |
; <label>:20 ; preds = %11 | |
%21 = inttoptr i64 %16 to i8*, !dbg !27 | |
%22 = call fastcc %struct.MV @KfibVfibI(i8* %21, i8* undef, i8* undef), !dbg !27 | |
%23 = extractvalue %struct.MV %22, 0, !dbg !27 | |
%24 = ptrtoint i8* %14 to i64, !dbg !27 | |
%25 = ptrtoint i8* %23 to i64, !dbg !27 | |
%26 = xor i64 %25, 1, !dbg !27 | |
%27 = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %24, i64 %26) #0, !dbg !27 | |
%28 = extractvalue { i64, i1 } %27, 0, !dbg !27 | |
%29 = extractvalue { i64, i1 } %27, 1, !dbg !27 | |
br i1 %29, label %30, label %32, !dbg !27 | |
; <label>:30 ; preds = %20 | |
%31 = tail call fastcc %struct.MV @Kmachine_word_overflowVKmI(i8* undef, i8* undef), !dbg !27 | |
unreachable, !dbg !27 | |
; <label>:32 ; preds = %20 | |
%33 = inttoptr i64 %28 to i8*, !dbg !27 | |
br label %34, !dbg !27 | |
; <label>:34 ; preds = %32, %4 | |
%35 = phi i8* [ %nF1, %4 ], [ %33, %32 ], !dbg !27 | |
%36 = insertvalue %struct.MV undef, i8* %35, 0, !dbg !24 | |
%37 = insertvalue %struct.MV %36, i8 1, 1, !dbg !24 | |
ret %struct.MV %37, !dbg !24 | |
} |
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
libfib.dylib`KfibVfibI: | |
0x100003e40 <+0>: pushq %rbp | |
0x100003e41 <+1>: movq %rsp, %rbp | |
0x100003e44 <+4>: pushq %r14 | |
0x100003e46 <+6>: pushq %rbx | |
0x100003e47 <+7>: movq %rdi, %rbx | |
0x100003e4a <+10>: cmpq $0x9, %rbx | |
0x100003e4e <+14>: jl 0x100003e7b ; <+59> at fib.dylan:10 | |
0x100003e50 <+16>: movq %rbx, %rdi | |
0x100003e53 <+19>: subq $0x4, %rdi | |
0x100003e57 <+23>: jo 0x100003e85 ; <+69> at fib.dylan:10 | |
0x100003e59 <+25>: callq 0x100003e40 ; <+0> at fib.dylan:6 | |
-> 0x100003e5e <+30>: movq %rax, %r14 | |
0x100003e61 <+33>: subq $0x8, %rbx | |
0x100003e65 <+37>: jo 0x100003e85 ; <+69> at fib.dylan:10 | |
0x100003e67 <+39>: movq %rbx, %rdi | |
0x100003e6a <+42>: callq 0x100003e40 ; <+0> at fib.dylan:6 | |
0x100003e6f <+47>: xorq $0x1, %rax | |
0x100003e73 <+51>: addq %rax, %r14 | |
0x100003e76 <+54>: jo 0x100003e85 ; <+69> at fib.dylan:10 | |
0x100003e78 <+56>: movq %r14, %rbx | |
0x100003e7b <+59>: movb $0x1, %dl | |
0x100003e7d <+61>: movq %rbx, %rax | |
0x100003e80 <+64>: popq %rbx | |
0x100003e81 <+65>: popq %r14 | |
0x100003e83 <+67>: popq %rbp | |
0x100003e84 <+68>: retq | |
0x100003e85 <+69>: callq 0x100003ee2 ; symbol stub for: Kmachine_word_overflowVKmI | |
0x100003e8a <+74>: nopw (%rax,%rax) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment