Skip to content

Commit 5c1a172

Browse files
committed
[CanonicalizeOSSALt] Extracted destroy pred.
Pulled out a simple check--that CanonicalizeOSSALifetime now uses to determine whether to continue hoisting a destroy_value instruction--into a predicate that can be used by LexicalDestroyFolding.
1 parent 2c0a35a commit 5c1a172

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

include/swift/SILOptimizer/Utils/CanonicalOSSALifetime.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,23 @@ class CanonicalizeOSSALifetime {
313313
CanonicalOSSAConsumeInfo consumes;
314314

315315
public:
316+
/// When rewriting destroys, is this an instruction which destroys should not
317+
/// be hoisted over to avoid churn and infinite looping.
318+
static bool ignoredByDestroyHoisting(SILInstructionKind kind) {
319+
switch (kind) {
320+
case SILInstructionKind::DestroyValueInst:
321+
case SILInstructionKind::CopyValueInst:
322+
case SILInstructionKind::BeginBorrowInst:
323+
case SILInstructionKind::EndBorrowInst:
324+
case SILInstructionKind::FunctionRefInst:
325+
case SILInstructionKind::EnumInst:
326+
case SILInstructionKind::StructInst:
327+
return true;
328+
default:
329+
return false;
330+
}
331+
}
332+
316333
void maybeNotifyMoveOnlyCopy(Operand *use) {
317334
if (!moveOnlyCopyValueNotification)
318335
return;

lib/SILOptimizer/Utils/CanonicalOSSALifetime.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,10 @@ void CanonicalizeOSSALifetime::findOrInsertDestroyInBlock(SILBasicBlock *bb) {
492492
return;
493493
}
494494
// This is not a potential last user. Keep scanning.
495-
// Allow lifetimes to be artificially extended up to the next call. The goal
496-
// is to prevent repeated destroy rewriting without inhibiting optimization.
497-
if (ApplySite::isa(inst)) {
495+
// Allow lifetimes to be artificially extended up to the next non-ignored
496+
// instruction. The goal is to prevent repeated destroy rewriting without
497+
// inhibiting optimization.
498+
if (!ignoredByDestroyHoisting(inst->getKind())) {
498499
existingDestroy = nullptr;
499500
} else if (!existingDestroy) {
500501
if (auto *destroy = dyn_cast<DestroyValueInst>(inst)) {

0 commit comments

Comments
 (0)