blob: 2d1855b9033e00252696ce68c21241fe136c8e22 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll
2; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
3; RUN: diff %t1.ll %t2.ll
4
5implementation
6
7declare int "atoi"(sbyte *)
8
9ulong "fib"(ulong %n)
10begin
11 setlt ulong %n, 2 ; {bool}:0
12 br bool %0, label %BaseCase, label %RecurseCase
13
14BaseCase:
15 ret ulong 1
16
17RecurseCase:
18 %n2 = sub ulong %n, 2
19 %n1 = sub ulong %n, 1
20 %f2 = call ulong(ulong) * %fib(ulong %n2)
21 %f1 = call ulong(ulong) * %fib(ulong %n1)
22 %result = add ulong %f2, %f1
23 ret ulong %result
24end
25
26ulong "realmain"(int %argc, sbyte ** %argv)
27begin
28 seteq int %argc, 2 ; {bool}:0
29 br bool %0, label %HasArg, label %Continue
30HasArg:
31 ; %n1 = atoi(argv[1])
32 %n1 = add int 1, 1
33 br label %Continue
34
35Continue:
36 %n = phi int [%n1, %HasArg], [1, %0]
37 %N = cast int %n to ulong
38 %F = call ulong(ulong) *%fib(ulong %N)
39 ret ulong %F
40end
41
42ulong "trampoline"(ulong %n, ulong(ulong)* %fibfunc)
43begin
44 %F = call ulong(ulong) *%fibfunc(ulong %n)
45 ret ulong %F
46end
47
48int "main"()
49begin
50 %Result = call ulong %trampoline(ulong 10, ulong(ulong) *%fib)
51 %Result = cast ulong %Result to int
52 ret int %Result
53end
54