@@ -292,8 +292,8 @@ void coro::Shape::analyze(Function &F) {
292
292
293
293
// Determination of ABI and initializing lowering info
294
294
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: {
297
297
ABI = coro::ABI::Switch;
298
298
SwitchLowering.HasFinalSuspend = HasFinalSuspend;
299
299
SwitchLowering.HasUnwindCoroEnd = HasUnwindCoroEnd;
@@ -307,7 +307,9 @@ void coro::Shape::analyze(Function &F) {
307
307
if (SwitchLowering.HasFinalSuspend &&
308
308
FinalSuspendIndex != CoroSuspends.size () - 1 )
309
309
std::swap (CoroSuspends[FinalSuspendIndex], CoroSuspends.back ());
310
- } else if (IntrID == Intrinsic::coro_id_async) {
310
+ break ;
311
+ }
312
+ case Intrinsic::coro_id_async: {
311
313
ABI = coro::ABI::Async;
312
314
auto *AsyncId = getAsyncCoroId ();
313
315
AsyncId->checkWellFormed ();
@@ -317,8 +319,10 @@ void coro::Shape::analyze(Function &F) {
317
319
AsyncLowering.ContextAlignment = AsyncId->getStorageAlignment ().value ();
318
320
AsyncLowering.AsyncFuncPointer = AsyncId->getAsyncFunctionPointer ();
319
321
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: {
322
326
ABI = IntrID == Intrinsic::coro_id_retcon ? coro::ABI::Retcon
323
327
: coro::ABI::RetconOnce;
324
328
auto ContinuationId = getRetconCoroId ();
@@ -329,7 +333,9 @@ void coro::Shape::analyze(Function &F) {
329
333
RetconLowering.Dealloc = ContinuationId->getDeallocFunction ();
330
334
RetconLowering.ReturnBlock = nullptr ;
331
335
RetconLowering.IsFrameInlineInStorage = false ;
332
- } else {
336
+ break ;
337
+ }
338
+ default :
333
339
llvm_unreachable (" coro.begin is not dependent on a coro.id call" );
334
340
}
335
341
}
@@ -345,6 +351,7 @@ void coro::Shape::invalidateCoroutine(Function &F) {
345
351
CF->replaceAllUsesWith (Undef);
346
352
CF->eraseFromParent ();
347
353
}
354
+ CoroFrames.clear ();
348
355
349
356
// Replace all coro.suspend with undef and remove related coro.saves if
350
357
// present.
@@ -354,6 +361,7 @@ void coro::Shape::invalidateCoroutine(Function &F) {
354
361
if (auto *CoroSave = CS->getCoroSave ())
355
362
CoroSave->eraseFromParent ();
356
363
}
364
+ CoroSuspends.clear ();
357
365
358
366
// Replace all coro.ends with unreachable instruction.
359
367
for (AnyCoroEndInst *CE : CoroEnds)
@@ -466,16 +474,18 @@ void coro::Shape::initABI() {
466
474
}
467
475
}
468
476
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.
471
479
for (CoroFrameInst *CF : CoroFrames) {
472
480
CF->replaceAllUsesWith (CoroBegin);
473
481
CF->eraseFromParent ();
474
482
}
483
+ CoroFrames.clear ();
475
484
476
485
// Remove orphaned coro.saves.
477
486
for (CoroSaveInst *CoroSave : UnusedCoroSaves)
478
487
CoroSave->eraseFromParent ();
488
+ UnusedCoroSaves.clear ();
479
489
}
480
490
481
491
static void propagateCallAttrsFromCallee (CallInst *Call, Function *Callee) {
0 commit comments