Skip to content

Commit c39c16e

Browse files
committed
---
yaml --- r: 344958 b: refs/heads/master c: d82d3e4 h: refs/heads/master
1 parent 304a538 commit c39c16e

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3bcffac402a87d75621754e4121e81f166b09a96
2+
refs/heads/master: d82d3e4ca71a3ea4edef5ee81b4c81608225641c
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/SILOptimizer/Utils/CFG.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,21 +425,25 @@ SILBasicBlock *getNthEdgeBlock(SwitchInstTy *S, unsigned EdgeIdx) {
425425

426426
static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
427427
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);
429431
for (auto V : Br->getArgs())
430432
Args.push_back(V);
431433
return;
432434
}
433435

434-
if (auto CondBr = dyn_cast<CondBranchInst>(T)) {
436+
case SILInstructionKind::CondBranchInst: {
437+
auto CondBr = cast<CondBranchInst>(T);
435438
assert(EdgeIdx < 2);
436439
auto OpdArgs = EdgeIdx ? CondBr->getFalseArgs() : CondBr->getTrueArgs();
437440
for (auto V: OpdArgs)
438441
Args.push_back(V);
439442
return;
440443
}
441444

442-
if (auto SEI = dyn_cast<SwitchValueInst>(T)) {
445+
case SILInstructionKind::SwitchValueInst: {
446+
auto SEI = cast<SwitchValueInst>(T);
443447
auto *SuccBB = getNthEdgeBlock(SEI, EdgeIdx);
444448
assert(SuccBB->getNumArguments() == 0 && "Can't take an argument");
445449
(void) SuccBB;
@@ -448,7 +452,9 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
448452

449453
// A switch_enum can implicitly pass the enum payload. We need to look at the
450454
// 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);
452458
auto *SuccBB = getNthEdgeBlock(SEI, EdgeIdx);
453459
assert(SuccBB->getNumArguments() < 2 && "Can take at most one argument");
454460
if (!SuccBB->getNumArguments())
@@ -459,7 +465,8 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
459465
}
460466

461467
// 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);
463470
auto *SuccBB =
464471
(EdgeIdx == 0) ? DMBI->getHasMethodBB() : DMBI->getNoMethodBB();
465472
if (!SuccBB->getNumArguments())
@@ -470,23 +477,26 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
470477
}
471478

472479
/// 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);
474482
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB() : CBI->getFailureBB();
475483
if (!SuccBB->getNumArguments())
476484
return;
477485
Args.push_back(NewEdgeBB->createPHIArgument(
478486
SuccBB->getArgument(0)->getType(), ValueOwnershipKind::Owned));
479487
return;
480488
}
481-
if (auto CBI = dyn_cast<CheckedCastAddrBranchInst>(T)) {
489+
case SILInstructionKind::CheckedCastAddrBranchInst: {
490+
auto CBI = cast<CheckedCastAddrBranchInst>(T);
482491
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB() : CBI->getFailureBB();
483492
if (!SuccBB->getNumArguments())
484493
return;
485494
Args.push_back(NewEdgeBB->createPHIArgument(
486495
SuccBB->getArgument(0)->getType(), ValueOwnershipKind::Owned));
487496
return;
488497
}
489-
if (auto CBI = dyn_cast<CheckedCastValueBranchInst>(T)) {
498+
case SILInstructionKind::CheckedCastValueBranchInst: {
499+
auto CBI = cast<CheckedCastValueBranchInst>(T);
490500
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB() : CBI->getFailureBB();
491501
if (!SuccBB->getNumArguments())
492502
return;
@@ -495,7 +505,8 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
495505
return;
496506
}
497507

498-
if (auto *TAI = dyn_cast<TryApplyInst>(T)) {
508+
case SILInstructionKind::TryApplyInst: {
509+
auto *TAI = cast<TryApplyInst>(T);
499510
auto *SuccBB = EdgeIdx == 0 ? TAI->getNormalBB() : TAI->getErrorBB();
500511
if (!SuccBB->getNumArguments())
501512
return;
@@ -504,9 +515,23 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
504515
return;
505516
}
506517

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");
510535
}
511536

512537
/// Splits the basic block at the iterator with an unconditional branch and

0 commit comments

Comments
 (0)