Add a simple testcase for garbage collection support
[oota-llvm.git] / test / CodeGen / Generic / GC / alloc_loop.ll
1 implementation
2
3 declare sbyte* %llvm_gc_allocate(uint)
4 declare void %llvm_gc_initialize()
5
6 declare void %llvm.gcroot(sbyte**, sbyte*)
7 declare void %llvm.gcwrite(sbyte*, sbyte**)
8
9 int %main() {
10 entry:
11         %A = alloca sbyte*
12         %B = alloca sbyte**
13
14         call void %llvm_gc_initialize()
15
16         ;; void *A;
17         call void %llvm.gcroot(sbyte** %A, sbyte* null)
18
19         ;; A = gcalloc(10);
20         %Aptr = call sbyte* %llvm_gc_allocate(uint 10)
21         store sbyte* %Aptr, sbyte** %A
22
23         ;; void **B;
24         %tmp.1 = cast sbyte*** %B to sbyte **
25         call void %llvm.gcroot(sbyte** %tmp.1, sbyte* null)
26
27         ;; B = gcalloc(4);
28         %B = call sbyte* %llvm_gc_allocate(uint 8)
29         %tmp.2 = cast sbyte* %B to sbyte**
30         store sbyte** %tmp.2, sbyte*** %B
31
32         ;; *B = A;
33         %B.1 = load sbyte*** %B
34         %A.1 = load sbyte** %A
35         call void %llvm.gcwrite(sbyte* %A.1, sbyte** %B.1)
36         
37         br label %AllocLoop
38
39 AllocLoop:
40         %i = phi uint [ 0, %entry ], [ %indvar.next, %AllocLoop ]
41         ;; Allocated mem: allocated memory is immediately dead.
42         call sbyte* %llvm_gc_allocate(uint 100)
43         
44         %indvar.next = add uint %i, 1
45         %exitcond = seteq uint %indvar.next, 10000000
46         br bool %exitcond, label %Exit, label %AllocLoop
47
48 Exit:
49         ret int 0
50 }
51
52 declare void %__main()