@@ -425,21 +425,25 @@ SILBasicBlock *getNthEdgeBlock(SwitchInstTy *S, unsigned EdgeIdx) {
425
425
426
426
static void getEdgeArgs (TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
427
427
SmallVectorImpl<SILValue> &Args) {
428
- if (auto Br = dyn_cast<BranchInst>(T)) {
428
+ switch (T->getKind ()) {
429
+ case SILInstructionKind::BranchInst: {
430
+ auto Br = cast<BranchInst>(T);
429
431
for (auto V : Br->getArgs ())
430
432
Args.push_back (V);
431
433
return ;
432
434
}
433
435
434
- if (auto CondBr = dyn_cast<CondBranchInst>(T)) {
436
+ case SILInstructionKind::CondBranchInst: {
437
+ auto CondBr = cast<CondBranchInst>(T);
435
438
assert (EdgeIdx < 2 );
436
439
auto OpdArgs = EdgeIdx ? CondBr->getFalseArgs () : CondBr->getTrueArgs ();
437
440
for (auto V: OpdArgs)
438
441
Args.push_back (V);
439
442
return ;
440
443
}
441
444
442
- if (auto SEI = dyn_cast<SwitchValueInst>(T)) {
445
+ case SILInstructionKind::SwitchValueInst: {
446
+ auto SEI = cast<SwitchValueInst>(T);
443
447
auto *SuccBB = getNthEdgeBlock (SEI, EdgeIdx);
444
448
assert (SuccBB->getNumArguments () == 0 && " Can't take an argument" );
445
449
(void ) SuccBB;
@@ -448,7 +452,9 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
448
452
449
453
// A switch_enum can implicitly pass the enum payload. We need to look at the
450
454
// destination block to figure this out.
451
- if (auto SEI = dyn_cast<SwitchEnumInstBase>(T)) {
455
+ case SILInstructionKind::SwitchEnumInst:
456
+ case SILInstructionKind::SwitchEnumAddrInst: {
457
+ auto SEI = cast<SwitchEnumInstBase>(T);
452
458
auto *SuccBB = getNthEdgeBlock (SEI, EdgeIdx);
453
459
assert (SuccBB->getNumArguments () < 2 && " Can take at most one argument" );
454
460
if (!SuccBB->getNumArguments ())
@@ -459,7 +465,8 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
459
465
}
460
466
461
467
// A dynamic_method_br passes the function to the first basic block.
462
- if (auto DMBI = dyn_cast<DynamicMethodBranchInst>(T)) {
468
+ case SILInstructionKind::DynamicMethodBranchInst: {
469
+ auto DMBI = cast<DynamicMethodBranchInst>(T);
463
470
auto *SuccBB =
464
471
(EdgeIdx == 0 ) ? DMBI->getHasMethodBB () : DMBI->getNoMethodBB ();
465
472
if (!SuccBB->getNumArguments ())
@@ -470,23 +477,26 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
470
477
}
471
478
472
479
// / A checked_cast_br passes the result of the cast to the first basic block.
473
- if (auto CBI = dyn_cast<CheckedCastBranchInst>(T)) {
480
+ case SILInstructionKind::CheckedCastBranchInst: {
481
+ auto CBI = cast<CheckedCastBranchInst>(T);
474
482
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB () : CBI->getFailureBB ();
475
483
if (!SuccBB->getNumArguments ())
476
484
return ;
477
485
Args.push_back (NewEdgeBB->createPHIArgument (
478
486
SuccBB->getArgument (0 )->getType (), ValueOwnershipKind::Owned));
479
487
return ;
480
488
}
481
- if (auto CBI = dyn_cast<CheckedCastAddrBranchInst>(T)) {
489
+ case SILInstructionKind::CheckedCastAddrBranchInst: {
490
+ auto CBI = cast<CheckedCastAddrBranchInst>(T);
482
491
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB () : CBI->getFailureBB ();
483
492
if (!SuccBB->getNumArguments ())
484
493
return ;
485
494
Args.push_back (NewEdgeBB->createPHIArgument (
486
495
SuccBB->getArgument (0 )->getType (), ValueOwnershipKind::Owned));
487
496
return ;
488
497
}
489
- if (auto CBI = dyn_cast<CheckedCastValueBranchInst>(T)) {
498
+ case SILInstructionKind::CheckedCastValueBranchInst: {
499
+ auto CBI = cast<CheckedCastValueBranchInst>(T);
490
500
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB () : CBI->getFailureBB ();
491
501
if (!SuccBB->getNumArguments ())
492
502
return ;
@@ -495,7 +505,8 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
495
505
return ;
496
506
}
497
507
498
- if (auto *TAI = dyn_cast<TryApplyInst>(T)) {
508
+ case SILInstructionKind::TryApplyInst: {
509
+ auto *TAI = cast<TryApplyInst>(T);
499
510
auto *SuccBB = EdgeIdx == 0 ? TAI->getNormalBB () : TAI->getErrorBB ();
500
511
if (!SuccBB->getNumArguments ())
501
512
return ;
@@ -504,9 +515,23 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
504
515
return ;
505
516
}
506
517
507
- // For now this utility is only used to split critical edges involving
508
- // cond_br.
509
- llvm_unreachable (" Not yet implemented" );
518
+ case SILInstructionKind::YieldInst:
519
+ // The edges from 'yield' never have branch arguments.
520
+ return ;
521
+
522
+ case SILInstructionKind::ReturnInst:
523
+ case SILInstructionKind::ThrowInst:
524
+ case SILInstructionKind::UnwindInst:
525
+ case SILInstructionKind::UnreachableInst:
526
+ llvm_unreachable (" terminator never has successors" );
527
+
528
+ #define TERMINATOR (ID, ...)
529
+ #define INST (ID, BASE ) \
530
+ case SILInstructionKind::ID:
531
+ #include " swift/SIL/SILNodes.def"
532
+ llvm_unreachable (" not a terminator" );
533
+ }
534
+ llvm_unreachable (" bad instruction kind" );
510
535
}
511
536
512
537
// / Splits the basic block at the iterator with an unconditional branch and
0 commit comments