2004-11-06 21:11:04 +00:00
|
|
|
; RUN: llvm-as < %s | llc
|
|
|
|
|
2004-05-23 21:24:50 +00:00
|
|
|
implementation
|
|
|
|
|
|
|
|
declare sbyte* %llvm_gc_allocate(uint)
|
2004-05-27 05:51:00 +00:00
|
|
|
declare void %llvm_gc_initialize(uint)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
declare void %llvm.gcroot(sbyte**, sbyte*)
|
2004-07-22 05:48:38 +00:00
|
|
|
declare void %llvm.gcwrite(sbyte*, sbyte*, sbyte**)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
int %main() {
|
|
|
|
entry:
|
|
|
|
%A = alloca sbyte*
|
|
|
|
%B = alloca sbyte**
|
|
|
|
|
2004-05-27 05:51:00 +00:00
|
|
|
call void %llvm_gc_initialize(uint 1048576) ; Start with 1MB heap
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
;; void *A;
|
|
|
|
call void %llvm.gcroot(sbyte** %A, sbyte* null)
|
|
|
|
|
|
|
|
;; A = gcalloc(10);
|
|
|
|
%Aptr = call sbyte* %llvm_gc_allocate(uint 10)
|
|
|
|
store sbyte* %Aptr, sbyte** %A
|
|
|
|
|
|
|
|
;; void **B;
|
|
|
|
%tmp.1 = cast sbyte*** %B to sbyte **
|
|
|
|
call void %llvm.gcroot(sbyte** %tmp.1, sbyte* null)
|
|
|
|
|
|
|
|
;; B = gcalloc(4);
|
|
|
|
%B = call sbyte* %llvm_gc_allocate(uint 8)
|
|
|
|
%tmp.2 = cast sbyte* %B to sbyte**
|
|
|
|
store sbyte** %tmp.2, sbyte*** %B
|
|
|
|
|
|
|
|
;; *B = A;
|
|
|
|
%B.1 = load sbyte*** %B
|
|
|
|
%A.1 = load sbyte** %A
|
2004-07-22 05:48:38 +00:00
|
|
|
call void %llvm.gcwrite(sbyte* %A.1, sbyte* %B, sbyte** %B.1)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
br label %AllocLoop
|
|
|
|
|
|
|
|
AllocLoop:
|
|
|
|
%i = phi uint [ 0, %entry ], [ %indvar.next, %AllocLoop ]
|
|
|
|
;; Allocated mem: allocated memory is immediately dead.
|
|
|
|
call sbyte* %llvm_gc_allocate(uint 100)
|
|
|
|
|
|
|
|
%indvar.next = add uint %i, 1
|
|
|
|
%exitcond = seteq uint %indvar.next, 10000000
|
|
|
|
br bool %exitcond, label %Exit, label %AllocLoop
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
ret int 0
|
|
|
|
}
|
|
|
|
|
|
|
|
declare void %__main()
|