1 ; RUN: opt -S %s -verify | FileCheck %s 2 3 declare void @use(...) 4 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32) 5 declare i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token, i32, i32) 6 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) 7 declare i32 @"personality_function"() 8 9 ;; Basic usage 10 define i64 addrspace(1)* @test1(i8 addrspace(1)* %arg) gc "statepoint-example" { 11 entry: 12 %cast = bitcast i8 addrspace(1)* %arg to i64 addrspace(1)* 13 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 10, i32 0, i8 addrspace(1)* %arg, i64 addrspace(1)* %cast, i8 addrspace(1)* %arg, i8 addrspace(1)* %arg) 14 %reloc = call i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token %safepoint_token, i32 12, i32 13) 15 ;; It is perfectly legal to relocate the same value multiple times... 16 %reloc2 = call i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token %safepoint_token, i32 12, i32 13) 17 %reloc3 = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 13, i32 12) 18 ret i64 addrspace(1)* %reloc 19 ; CHECK-LABEL: test1 20 ; CHECK: statepoint 21 ; CHECK: gc.relocate 22 ; CHECK: gc.relocate 23 ; CHECK: gc.relocate 24 ; CHECK: ret i64 addrspace(1)* %reloc 25 } 26 27 ; This test catches two cases where the verifier was too strict: 28 ; 1) A base doesn't need to be relocated if it's never used again 29 ; 2) A value can be replaced by one which is known equal. This 30 ; means a potentially derived pointer can be known base and that 31 ; we can't check that derived pointer are never bases. 32 define void @test2(i8 addrspace(1)* %arg, i64 addrspace(1)* %arg2) gc "statepoint-example" { 33 entry: 34 %cast = bitcast i8 addrspace(1)* %arg to i64 addrspace(1)* 35 %c = icmp eq i64 addrspace(1)* %cast, %arg2 36 br i1 %c, label %equal, label %notequal 37 38 notequal: 39 ret void 40 41 equal: 42 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 10, i32 0, i8 addrspace(1)* %arg, i64 addrspace(1)* %cast, i8 addrspace(1)* %arg, i8 addrspace(1)* %arg) 43 %reloc = call i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token %safepoint_token, i32 12, i32 13) 44 call void undef(i64 addrspace(1)* %reloc) 45 ret void 46 ; CHECK-LABEL: test2 47 ; CHECK-LABEL: equal 48 ; CHECK: statepoint 49 ; CHECK-NEXT: %reloc = call 50 ; CHECK-NEXT: call 51 ; CHECK-NEXT: ret voi 52 } 53 54 ; Basic test for invoke statepoints 55 define i8 addrspace(1)* @test3(i8 addrspace(1)* %obj, i8 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @"personality_function" { 56 ; CHECK-LABEL: test3 57 entry: 58 ; CHECK-LABEL: entry 59 ; CHECK: statepoint 60 %0 = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i8 addrspace(1)* %obj, i8 addrspace(1)* %obj1) 61 to label %normal_dest unwind label %exceptional_return 62 63 normal_dest: 64 ; CHECK-LABEL: normal_dest: 65 ; CHECK: gc.relocate 66 ; CHECK: gc.relocate 67 ; CHECK: ret 68 %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %0, i32 12, i32 12) 69 %obj1.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %0, i32 12, i32 12) 70 ret i8 addrspace(1)* %obj.relocated 71 72 exceptional_return: 73 ; CHECK-LABEL: exceptional_return 74 ; CHECK: gc.relocate 75 ; CHECK: gc.relocate 76 %landing_pad = landingpad token 77 cleanup 78 %obj.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %landing_pad, i32 12, i32 12) 79 %obj1.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %landing_pad, i32 12, i32 12) 80 ret i8 addrspace(1)* %obj1.relocated1 81 } 82