|
| 1 | +; Tests that coro-split will convert coro.resume followed by a suspend to a |
| 2 | +; musttail call. |
| 3 | +; RUN: opt < %s -coro-split -S | FileCheck %s |
| 4 | +; RUN: opt < %s -passes=coro-split -S | FileCheck %s |
| 5 | + |
| 6 | +define void @fakeresume1(i8*) { |
| 7 | +entry: |
| 8 | + ret void; |
| 9 | +} |
| 10 | + |
| 11 | +define void @fakeresume2(i64*) { |
| 12 | +entry: |
| 13 | + ret void; |
| 14 | +} |
| 15 | + |
| 16 | +define void @g() #0 { |
| 17 | +entry: |
| 18 | + %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null) |
| 19 | + %alloc = call i8* @malloc(i64 16) #3 |
| 20 | + %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc) |
| 21 | + |
| 22 | + %save = call token @llvm.coro.save(i8* null) |
| 23 | + call fastcc void @fakeresume1(i8* null) |
| 24 | + |
| 25 | + %suspend = call i8 @llvm.coro.suspend(token %save, i1 false) |
| 26 | + switch i8 %suspend, label %exit [ |
| 27 | + i8 0, label %await.ready |
| 28 | + i8 1, label %exit |
| 29 | + ] |
| 30 | +await.ready: |
| 31 | + %save2 = call token @llvm.coro.save(i8* null) |
| 32 | + call fastcc void @fakeresume2(i64* null) |
| 33 | + |
| 34 | + %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false) |
| 35 | + switch i8 %suspend2, label %exit [ |
| 36 | + i8 0, label %exit |
| 37 | + i8 1, label %exit |
| 38 | + ] |
| 39 | +exit: |
| 40 | + call i1 @llvm.coro.end(i8* null, i1 false) |
| 41 | + ret void |
| 42 | +} |
| 43 | + |
| 44 | +; Verify that in the initial function resume is not marked with musttail. |
| 45 | +; CHECK-LABEL: @g( |
| 46 | +; CHECK-NOT: musttail call fastcc void @fakeresume1(i8* null) |
| 47 | + |
| 48 | +; Verify that in the resume part resume call is marked with musttail. |
| 49 | +; CHECK-LABEL: @g.resume( |
| 50 | +; CHECK: musttail call fastcc void @fakeresume2(i64* null) |
| 51 | +; CHECK-NEXT: ret void |
| 52 | + |
| 53 | +declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1 |
| 54 | +declare i1 @llvm.coro.alloc(token) #2 |
| 55 | +declare i64 @llvm.coro.size.i64() #3 |
| 56 | +declare i8* @llvm.coro.begin(token, i8* writeonly) #2 |
| 57 | +declare token @llvm.coro.save(i8*) #2 |
| 58 | +declare i8* @llvm.coro.frame() #3 |
| 59 | +declare i8 @llvm.coro.suspend(token, i1) #2 |
| 60 | +declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1 |
| 61 | +declare i1 @llvm.coro.end(i8*, i1) #2 |
| 62 | +declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1 |
| 63 | +declare i8* @malloc(i64) |
| 64 | + |
| 65 | +attributes #0 = { "coroutine.presplit"="1" } |
| 66 | +attributes #1 = { argmemonly nounwind readonly } |
| 67 | +attributes #2 = { nounwind } |
| 68 | +attributes #3 = { nounwind readnone } |
0 commit comments