Skip to content

Commit cc6dd6e

Browse files
tnowickiTylerNowicki
authored andcommitted
[Coroutines] Revise with reviewer feedback.
1 parent d72b087 commit cc6dd6e

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

llvm/lib/Transforms/Coroutines/CoroShape.h

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

61-
// Values invalidated by invalidateCoroutine() and tidyCoroutine()
61+
// Values invalidated by invalidateCoroutine() and cleanCoroutine()
6262
SmallVector<CoroFrameInst *, 8> CoroFrames;
6363
SmallVector<CoroSaveInst *, 2> UnusedCoroSaves;
6464

@@ -91,7 +91,7 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
9191
// Perform ABI related initial transformation
9292
void initABI();
9393
// Remove orphaned and unnecessary intrinsics
94-
void tidyCoroutine();
94+
void cleanCoroutine();
9595

9696
// Field indexes for special fields in the switch lowering.
9797
struct SwitchFieldIndex {
@@ -277,7 +277,7 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
277277
return;
278278
}
279279
initABI();
280-
tidyCoroutine();
280+
cleanCoroutine();
281281
}
282282
};
283283

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ void coro::Shape::analyze(Function &F) {
292292

293293
// Determination of ABI and initializing lowering info
294294
auto Id = CoroBegin->getId();
295-
auto IntrID = Id->getIntrinsicID();
296-
if (IntrID == Intrinsic::coro_id) {
295+
switch (auto IntrID = Id->getIntrinsicID()) {
296+
case Intrinsic::coro_id: {
297297
ABI = coro::ABI::Switch;
298298
SwitchLowering.HasFinalSuspend = HasFinalSuspend;
299299
SwitchLowering.HasUnwindCoroEnd = HasUnwindCoroEnd;
@@ -307,7 +307,9 @@ void coro::Shape::analyze(Function &F) {
307307
if (SwitchLowering.HasFinalSuspend &&
308308
FinalSuspendIndex != CoroSuspends.size() - 1)
309309
std::swap(CoroSuspends[FinalSuspendIndex], CoroSuspends.back());
310-
} else if (IntrID == Intrinsic::coro_id_async) {
310+
break;
311+
}
312+
case Intrinsic::coro_id_async: {
311313
ABI = coro::ABI::Async;
312314
auto *AsyncId = getAsyncCoroId();
313315
AsyncId->checkWellFormed();
@@ -317,8 +319,10 @@ void coro::Shape::analyze(Function &F) {
317319
AsyncLowering.ContextAlignment = AsyncId->getStorageAlignment().value();
318320
AsyncLowering.AsyncFuncPointer = AsyncId->getAsyncFunctionPointer();
319321
AsyncLowering.AsyncCC = F.getCallingConv();
320-
} else if (IntrID == Intrinsic::coro_id_retcon ||
321-
IntrID == Intrinsic::coro_id_retcon_once) {
322+
break;
323+
}
324+
case Intrinsic::coro_id_retcon:
325+
case Intrinsic::coro_id_retcon_once: {
322326
ABI = IntrID == Intrinsic::coro_id_retcon ? coro::ABI::Retcon
323327
: coro::ABI::RetconOnce;
324328
auto ContinuationId = getRetconCoroId();
@@ -329,7 +333,9 @@ void coro::Shape::analyze(Function &F) {
329333
RetconLowering.Dealloc = ContinuationId->getDeallocFunction();
330334
RetconLowering.ReturnBlock = nullptr;
331335
RetconLowering.IsFrameInlineInStorage = false;
332-
} else {
336+
break;
337+
}
338+
default:
333339
llvm_unreachable("coro.begin is not dependent on a coro.id call");
334340
}
335341
}
@@ -345,6 +351,7 @@ void coro::Shape::invalidateCoroutine(Function &F) {
345351
CF->replaceAllUsesWith(Undef);
346352
CF->eraseFromParent();
347353
}
354+
CoroFrames.clear();
348355

349356
// Replace all coro.suspend with undef and remove related coro.saves if
350357
// present.
@@ -354,6 +361,7 @@ void coro::Shape::invalidateCoroutine(Function &F) {
354361
if (auto *CoroSave = CS->getCoroSave())
355362
CoroSave->eraseFromParent();
356363
}
364+
CoroSuspends.clear();
357365

358366
// Replace all coro.ends with unreachable instruction.
359367
for (AnyCoroEndInst *CE : CoroEnds)
@@ -466,16 +474,18 @@ void coro::Shape::initABI() {
466474
}
467475
}
468476

469-
void coro::Shape::tidyCoroutine() {
470-
// The coro.free intrinsic is always lowered to the result of coro.begin.
477+
void coro::Shape::cleanCoroutine() {
478+
// The coro.frame intrinsic is always lowered to the result of coro.begin.
471479
for (CoroFrameInst *CF : CoroFrames) {
472480
CF->replaceAllUsesWith(CoroBegin);
473481
CF->eraseFromParent();
474482
}
483+
CoroFrames.clear();
475484

476485
// Remove orphaned coro.saves.
477486
for (CoroSaveInst *CoroSave : UnusedCoroSaves)
478487
CoroSave->eraseFromParent();
488+
UnusedCoroSaves.clear();
479489
}
480490

481491
static void propagateCallAttrsFromCallee(CallInst *Call, Function *Callee) {

0 commit comments

Comments
 (0)