|
17 | 17 | #include "swift/AST/ProtocolConformance.h"
|
18 | 18 | #include "swift/AST/SubstitutionMap.h"
|
19 | 19 | #include "swift/AST/Types.h"
|
20 |
| -#include "swift/SIL/DebugUtils.h" |
21 | 20 | #include "swift/SIL/SILDeclRef.h"
|
22 | 21 | #include "swift/SIL/SILFunction.h"
|
23 | 22 | #include "swift/SIL/SILInstruction.h"
|
@@ -552,44 +551,6 @@ bool swift::canDevirtualizeClassMethod(FullApplySite AI,
|
552 | 551 | return true;
|
553 | 552 | }
|
554 | 553 |
|
555 |
| -// Remove any code that follows a I and set the block's |
556 |
| -// terminator to unreachable. |
557 |
| -static bool insertUnreachable(SILInstruction *I, SILBuilder &B) { |
558 |
| - assert(I); |
559 |
| - auto NextI = std::next(SILBasicBlock::iterator(I)); |
560 |
| - // Nothing more to do here. |
561 |
| - if (NextI != I->getParent()->end() && isa<UnreachableInst>(NextI)) |
562 |
| - return false; |
563 |
| - |
564 |
| - // Collect together all the instructions after this point. |
565 |
| - llvm::SmallVector<SILInstruction *, 32> ToRemove; |
566 |
| - for (auto Inst = I->getParent()->rbegin(); &*Inst != I; ++Inst) |
567 |
| - ToRemove.push_back(&*Inst); |
568 |
| - |
569 |
| - SILBasicBlock::iterator EndI; |
570 |
| - for (auto *Inst : ToRemove) { |
571 |
| - // Replace any still-remaining uses with undef and erase. |
572 |
| - Inst->replaceAllUsesWithUndef(); |
573 |
| - assert(onlyHaveDebugUses(Inst) && "Cannot erase instruction that is used!"); |
574 |
| - eraseFromParentWithDebugInsts(Inst, EndI); |
575 |
| - } |
576 |
| - |
577 |
| - // Add an `unreachable` to be the new terminator for this block. |
578 |
| - B.setInsertionPoint(I->getParent()); |
579 |
| - B.createUnreachable(ArtificialUnreachableLocation()); |
580 |
| - return true; |
581 |
| -} |
582 |
| - |
583 |
| -/// If this is a call of a NoReturn function and it is not a terminator |
584 |
| -/// instruction, it should be followed by an unreachable instruction. |
585 |
| -static void handleNoReturnFunction(FullApplySite AI, SILBuilder &B) { |
586 |
| - if (!AI.getSubstCalleeType()->isNoReturnFunction()) |
587 |
| - return; |
588 |
| - if (!AI.getInstruction() || isa<TermInst>(AI.getInstruction())) |
589 |
| - return; |
590 |
| - insertUnreachable(AI.getInstruction(), B); |
591 |
| -} |
592 |
| - |
593 | 554 | /// \brief Devirtualize an apply of a class method.
|
594 | 555 | ///
|
595 | 556 | /// \p AI is the apply to devirtualize.
|
@@ -733,17 +694,9 @@ DevirtualizationResult swift::devirtualizeClassMethod(FullApplySite AI,
|
733 | 694 | Use->set(ResultValue);
|
734 | 695 | }
|
735 | 696 | }
|
736 |
| - // Insert unreachable after the old apply instruction if required. |
737 |
| - // Do not remove the old instruction yet, because it is done later |
738 |
| - // elsewhere. |
739 |
| - handleNoReturnFunction(AI, B); |
740 | 697 | return std::make_pair(NewAI.getInstruction(), NewAI);
|
741 | 698 | }
|
742 | 699 |
|
743 |
| - // Insert unreachable after the old apply instruction if required. |
744 |
| - // Do not remove the old instruction yet, because it is done later |
745 |
| - // elsewhere. |
746 |
| - handleNoReturnFunction(AI, B); |
747 | 700 | // We need to return a pair of values here:
|
748 | 701 | // - the first one is the actual result of the devirtualized call, possibly
|
749 | 702 | // casted into an appropriate type. This SILValue may be a BB arg, if it
|
|
0 commit comments