1; RUN: opt -S %s -verify | FileCheck %s 2 3declare void @use(...) 4declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32, i32, i32) 5declare i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(i32, i32, i32) 6declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) 7declare i32 @"personality_function"() 8 9;; Basic usage 10define i64 addrspace(1)* @test1(i8 addrspace(1)* %arg) gc "statepoint-example" { 11entry: 12 %cast = bitcast i8 addrspace(1)* %arg to i64 addrspace(1)* 13 %safepoint_token = call i32 (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(i32 %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(i32 %safepoint_token, i32 12, i32 13) 17 %reloc3 = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %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. 32define void @test2(i8 addrspace(1)* %arg, i64 addrspace(1)* %arg2) gc "statepoint-example" { 33entry: 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 38notequal: 39 ret void 40 41equal: 42 %safepoint_token = call i32 (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(i32 %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 55define i8 addrspace(1)* @test3(i8 addrspace(1)* %obj, i8 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @"personality_function" { 56; CHECK-LABEL: test3 57entry: 58 ; CHECK-LABEL: entry 59 ; CHECK: statepoint 60 %0 = invoke i32 (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 63normal_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(i32 %0, i32 12, i32 12) 69 %obj1.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %0, i32 12, i32 12) 70 ret i8 addrspace(1)* %obj.relocated 71 72exceptional_return: 73 ; CHECK-LABEL: exceptional_return 74 ; CHECK: gc.relocate 75 ; CHECK: gc.relocate 76 %landing_pad = landingpad { i8*, i32 } 77 cleanup 78 %relocate_token = extractvalue { i8*, i32 } %landing_pad, 1 79 %obj.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %relocate_token, i32 12, i32 12) 80 %obj1.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %relocate_token, i32 12, i32 12) 81 ret i8 addrspace(1)* %obj1.relocated1 82} 83