Skip to content

Commit 75db9f4

Browse files
author
git apple-llvm automerger
committed
Merge commit '00c527abab3d' from llvm.org/main into next
2 parents 0d6173f + 00c527a commit 75db9f4

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

llvm/lib/Transforms/Coroutines/SpillUtils.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ namespace {
2424

2525
typedef SmallPtrSet<BasicBlock *, 8> VisitedBlocksSet;
2626

27-
// Check for structural coroutine intrinsics that should not be spilled into
28-
// the coroutine frame.
29-
static bool isCoroutineStructureIntrinsic(Instruction &I) {
30-
return isa<CoroIdInst>(&I) || isa<CoroSaveInst>(&I) ||
31-
isa<CoroSuspendInst>(&I);
27+
static bool isNonSpilledIntrinsic(Instruction &I) {
28+
// Structural coroutine intrinsics that should not be spilled into the
29+
// coroutine frame.
30+
return isa<CoroIdInst>(&I) || isa<CoroSaveInst>(&I);
3231
}
3332

3433
/// Does control flow starting at the given block ever reach a suspend
@@ -467,7 +466,7 @@ void collectSpillsAndAllocasFromInsts(
467466
for (Instruction &I : instructions(F)) {
468467
// Values returned from coroutine structure intrinsics should not be part
469468
// of the Coroutine Frame.
470-
if (isCoroutineStructureIntrinsic(I) || &I == Shape.CoroBegin)
469+
if (isNonSpilledIntrinsic(I) || &I == Shape.CoroBegin)
471470
continue;
472471

473472
// Handle alloca.alloc specially here.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; Check that the return value of @llvm.coro.suspend gets spilled to the frame
2+
; if it may be used across suspend points.
3+
; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4+
5+
6+
; %sp1 should be part of the frame (the i8 value).
7+
; CHECK: %f.Frame = type { ptr, ptr, i1, i8 }
8+
9+
; If the coro resumes, %sp1 is set to 0.
10+
; CHECK-LABEL: define{{.*}} void @f.resume
11+
; CHECK: AfterCoroSuspend:
12+
; CHECK: %sp1.spill.addr = getelementptr inbounds %f.Frame
13+
; CHECK: store i8 0, ptr %sp1.spill.addr
14+
15+
; In the coro destroy function, %sp1 is reloaded from the frame. Its value
16+
; depends on whether the coroutine was resumed or not.
17+
; CHECK-LABEL: define{{.*}} void @f.destroy
18+
; CHECK: cleanup:
19+
; CHECK: %sp1.reload.addr = getelementptr inbounds %f.Frame
20+
; CHECK: %sp1.reload = load i8, ptr %sp1.reload.addr
21+
; CHECK: call void @print(i8 %sp1.reload)
22+
23+
24+
define ptr @f(i32 %n) presplitcoroutine {
25+
entry:
26+
%id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
27+
%size = call i32 @llvm.coro.size.i32()
28+
%alloc = call ptr @malloc(i32 %size)
29+
%hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
30+
31+
%sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
32+
switch i8 %sp1, label %suspend [i8 0, label %resume1
33+
i8 1, label %cleanup]
34+
35+
resume1:
36+
%sp2 = call i8 @llvm.coro.suspend(token none, i1 false)
37+
switch i8 %sp2, label %suspend [i8 0, label %resume2
38+
i8 1, label %cleanup]
39+
40+
resume2:
41+
br label %cleanup
42+
43+
cleanup:
44+
; This use of %sp1 may cross a suspend point (%sp2).
45+
call void @print(i8 %sp1)
46+
47+
%mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
48+
call void @free(ptr %mem)
49+
br label %suspend
50+
51+
suspend:
52+
call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
53+
ret ptr %hdl
54+
}
55+
56+
57+
declare noalias ptr @malloc(i32)
58+
declare void @print(i8)
59+
declare void @free(ptr)

0 commit comments

Comments
 (0)