Skip to content

Commit 40d3db0

Browse files
author
tnowicki
committed
[Coroutines] Revised again with reviewer feedback.
1 parent 61f98d8 commit 40d3db0

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

llvm/lib/Transforms/Coroutines/CoroShape.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
5858
SmallVector<CoroAwaitSuspendInst *, 4> CoroAwaitSuspends;
5959
SmallVector<CallInst *, 2> SymmetricTransfers;
6060

61-
// Values invalidated by invalidateCoroutine() and cleanCoroutine()
62-
SmallVector<CoroFrameInst *, 8> CoroFrames;
63-
SmallVector<CoroSaveInst *, 2> UnusedCoroSaves;
64-
6561
// Values invalidated by replaceSwiftErrorOps()
6662
SmallVector<CallInst *, 2> SwiftErrorOps;
6763

@@ -74,9 +70,6 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
7470
CoroAwaitSuspends.clear();
7571
SymmetricTransfers.clear();
7672

77-
CoroFrames.clear();
78-
UnusedCoroSaves.clear();
79-
8073
SwiftErrorOps.clear();
8174

8275
FrameTy = nullptr;
@@ -85,13 +78,16 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
8578
}
8679

8780
// Scan the function and collect the above intrinsics for later processing
88-
void analyze(Function &F);
81+
void analyze(Function &F, SmallVectorImpl<CoroFrameInst *> &CoroFrames,
82+
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves);
8983
// If for some reason, we were not able to find coro.begin, bailout.
90-
void invalidateCoroutine(Function &F);
84+
void invalidateCoroutine(Function &F,
85+
SmallVectorImpl<CoroFrameInst *> &CoroFrames);
9186
// Perform ABI related initial transformation
9287
void initABI();
9388
// Remove orphaned and unnecessary intrinsics
94-
void cleanCoroutine();
89+
void cleanCoroutine(SmallVectorImpl<CoroFrameInst *> &CoroFrames,
90+
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves);
9591

9692
// Field indexes for special fields in the switch lowering.
9793
struct SwitchFieldIndex {
@@ -271,13 +267,16 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
271267
Shape() = default;
272268
explicit Shape(Function &F, bool OptimizeFrame = false)
273269
: OptimizeFrame(OptimizeFrame) {
274-
analyze(F);
270+
SmallVector<CoroFrameInst *, 8> CoroFrames;
271+
SmallVector<CoroSaveInst *, 2> UnusedCoroSaves;
272+
273+
analyze(F, CoroFrames, UnusedCoroSaves);
275274
if (!CoroBegin) {
276-
invalidateCoroutine(F);
275+
invalidateCoroutine(F, CoroFrames);
277276
return;
278277
}
279278
initABI();
280-
cleanCoroutine();
279+
cleanCoroutine(CoroFrames, UnusedCoroSaves);
281280
}
282281
};
283282

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ static CoroSaveInst *createCoroSave(CoroBeginInst *CoroBegin,
189189
}
190190

191191
// Collect "interesting" coroutine intrinsics.
192-
void coro::Shape::analyze(Function &F) {
192+
void coro::Shape::analyze(Function &F,
193+
SmallVectorImpl<CoroFrameInst *> &CoroFrames,
194+
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves) {
193195
clear();
194196

195197
bool HasFinalSuspend = false;
@@ -341,7 +343,8 @@ void coro::Shape::analyze(Function &F) {
341343
}
342344

343345
// If for some reason, we were not able to find coro.begin, bailout.
344-
void coro::Shape::invalidateCoroutine(Function &F) {
346+
void coro::Shape::invalidateCoroutine(
347+
Function &F, SmallVectorImpl<CoroFrameInst *> &CoroFrames) {
345348
assert(!CoroBegin);
346349
{
347350
// Replace coro.frame which are supposed to be lowered to the result of
@@ -474,7 +477,9 @@ void coro::Shape::initABI() {
474477
}
475478
}
476479

477-
void coro::Shape::cleanCoroutine() {
480+
void coro::Shape::cleanCoroutine(
481+
SmallVectorImpl<CoroFrameInst *> &CoroFrames,
482+
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves) {
478483
// The coro.frame intrinsic is always lowered to the result of coro.begin.
479484
for (CoroFrameInst *CF : CoroFrames) {
480485
CF->replaceAllUsesWith(CoroBegin);

0 commit comments

Comments
 (0)