More working CellSPU tests:
[oota-llvm.git] / test / Feature / indirectcall.ll
1 ; 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
5 implementation
6
7 declare int "atoi"(sbyte *)
8
9 ulong "fib"(ulong %n)
10 begin
11   setlt ulong %n, 2       ; {bool}:0
12   br bool %0, label %BaseCase, label %RecurseCase
13
14 BaseCase:
15   ret ulong 1
16
17 RecurseCase:
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
24 end
25
26 ulong "realmain"(int %argc, sbyte ** %argv)
27 begin
28   seteq int %argc, 2      ; {bool}:0
29   br bool %0, label %HasArg, label %Continue
30 HasArg:
31   ; %n1 = atoi(argv[1])
32   %n1 = add int 1, 1
33   br label %Continue
34
35 Continue:
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
40 end
41
42 ulong "trampoline"(ulong %n, ulong(ulong)* %fibfunc)
43 begin
44   %F = call ulong(ulong) *%fibfunc(ulong %n)
45   ret ulong %F
46 end
47
48 int "main"()
49 begin
50   %Result = call ulong %trampoline(ulong 10, ulong(ulong) *%fib)
51   %Result = cast ulong %Result to int
52   ret int %Result
53 end
54