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 i8* @f() "coroutine.presplit"="1" {
8 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* 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 i8* @malloc(i32 %size)
18 %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
19 %hdl = call i8* @llvm.coro.begin(token %id, i8* %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 i8* @llvm.coro.free(token %id, i8* %hdl)
30 call void @free(i8* %mem)
33 call i1 @llvm.coro.end(i8* %hdl, i1 0)
37 ; CHECK-LABEL: hidden{{.*}}@f(
38 ; CHECK: call i8* @malloc
39 ; CHECK: @llvm.coro.begin(token %id, i8* %phi)
40 ; CHECK: store void (%f.Frame*)* @f.resume, void (%f.Frame*)** %resume.addr
41 ; CHECK: %[[SEL:.+]] = select i1 %need.alloc, void (%f.Frame*)* @f.destroy, void (%f.Frame*)* @f.cleanup
42 ; CHECK: store void (%f.Frame*)* %[[SEL]], void (%f.Frame*)** %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 i8* @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 i8* @malloc
58 ; CHECK-NOT: call void @print(
59 ; CHECK: call void @free(
62 ; CHECK-LABEL: internal{{.*}}@f.cleanup(
63 ; CHECK-NOT: call i8* @malloc
64 ; CHECK-NOT: call void @print(
65 ; CHECK-NOT: call void @free(
68 declare i8* @llvm.coro.free(token, i8*)
69 declare i32 @llvm.coro.size.i32()
70 declare i8 @llvm.coro.suspend(token, i1)
71 declare void @llvm.coro.resume(i8*)
72 declare void @llvm.coro.destroy(i8*)
74 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
75 declare i1 @llvm.coro.alloc(token)
76 declare i8* @llvm.coro.begin(token, i8*)
77 declare i1 @llvm.coro.end(i8*, i1)
79 declare noalias i8* @malloc(i32)
80 declare void @print(i32)
81 declare void @free(i8*) willreturn