1 ; Tests that coro-split can convert functions with hidden visibility.
2 ; These may be generated by a frontend such as Clang, when inlining with
3 ; '-fvisibility-inlines-hidden'.
4 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
6 define hidden ptr @f() presplitcoroutine {
8 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
9 %need.alloc = call i1 @llvm.coro.alloc(token %id)
10 br i1 %need.alloc, label %dyn.alloc, label %begin
13 %size = call i32 @llvm.coro.size.i32()
14 %alloc = call ptr @malloc(i32 %size)
18 %phi = phi ptr [ null, %entry ], [ %alloc, %dyn.alloc ]
19 %hdl = call ptr @llvm.coro.begin(token %id, ptr %phi)
20 call void @print(i32 0)
21 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
22 switch i8 %0, label %suspend [i8 0, label %resume
25 call void @print(i32 1)
29 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
30 call void @free(ptr %mem)
33 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
37 ; CHECK-LABEL: hidden{{.*}}@f(
38 ; CHECK: call ptr @malloc
39 ; CHECK: @llvm.coro.begin(token %id, ptr %phi)
40 ; CHECK: store ptr @f.resume, ptr %hdl
41 ; CHECK: %[[SEL:.+]] = select i1 %need.alloc, ptr @f.destroy, ptr @f.cleanup
42 ; CHECK: store ptr %[[SEL]], ptr %destroy.addr
43 ; CHECK: call void @print(i32 0)
44 ; CHECK-NOT: call void @print(i32 1)
45 ; CHECK-NOT: call void @free(
48 ; CHECK-LABEL: internal{{.*}}@f.resume(
49 ; CHECK-NOT: call ptr @malloc
50 ; CHECK-NOT: call void @print(i32 0)
51 ; CHECK: call void @print(i32 1)
52 ; CHECK-NOT: call void @print(i32 0)
53 ; CHECK: call void @free(
56 ; CHECK-LABEL: internal{{.*}}@f.destroy(
57 ; CHECK-NOT: call ptr @malloc
58 ; CHECK-NOT: call void @print(
59 ; CHECK: call void @free(
62 ; CHECK-LABEL: internal{{.*}}@f.cleanup(
63 ; CHECK-NOT: call ptr @malloc
64 ; CHECK-NOT: call void @print(
65 ; CHECK-NOT: call void @free(
68 declare ptr @llvm.coro.free(token, ptr)
69 declare i32 @llvm.coro.size.i32()
70 declare i8 @llvm.coro.suspend(token, i1)
71 declare void @llvm.coro.resume(ptr)
72 declare void @llvm.coro.destroy(ptr)
74 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
75 declare i1 @llvm.coro.alloc(token)
76 declare ptr @llvm.coro.begin(token, ptr)
77 declare i1 @llvm.coro.end(ptr, i1, token)
79 declare noalias ptr @malloc(i32) allockind("alloc,uninitialized")
80 declare void @print(i32)
81 declare void @free(ptr) willreturn allockind("free")