Skip to content

Commit 4cfe1a3

Browse files
authored
Merge pull request #11321 from swiftix/devirtualizer-fixes
[sil-devirtualizer] Code clean-up. Simplify the previous patch.
2 parents 300c7aa + 786c7a7 commit 4cfe1a3

File tree

1 file changed

+0
-47
lines changed

1 file changed

+0
-47
lines changed

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "swift/AST/ProtocolConformance.h"
1818
#include "swift/AST/SubstitutionMap.h"
1919
#include "swift/AST/Types.h"
20-
#include "swift/SIL/DebugUtils.h"
2120
#include "swift/SIL/SILDeclRef.h"
2221
#include "swift/SIL/SILFunction.h"
2322
#include "swift/SIL/SILInstruction.h"
@@ -552,44 +551,6 @@ bool swift::canDevirtualizeClassMethod(FullApplySite AI,
552551
return true;
553552
}
554553

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-
593554
/// \brief Devirtualize an apply of a class method.
594555
///
595556
/// \p AI is the apply to devirtualize.
@@ -733,17 +694,9 @@ DevirtualizationResult swift::devirtualizeClassMethod(FullApplySite AI,
733694
Use->set(ResultValue);
734695
}
735696
}
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);
740697
return std::make_pair(NewAI.getInstruction(), NewAI);
741698
}
742699

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);
747700
// We need to return a pair of values here:
748701
// - the first one is the actual result of the devirtualized call, possibly
749702
// casted into an appropriate type. This SILValue may be a BB arg, if it

0 commit comments

Comments
 (0)