Skip to content

Commit 46379e7

Browse files
committed
NFC: [OSSACompleteLifetime] Allow forced verifying
1 parent 1218eec commit 46379e7

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

include/swift/SIL/OSSALifetimeCompletion.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@ class OSSALifetimeCompletion {
5757
/// Extend trivial variables for lifetime diagnostics (only in SILGenCleanup).
5858
HandleTrivialVariable_t handleTrivialVariable;
5959

60+
/// Whether verification of the computed liveness should be run even when the
61+
/// global setting is off.
62+
/// TODO: Remove this option.
63+
bool ForceLivenessVerification;
64+
6065
public:
61-
OSSALifetimeCompletion(SILFunction *function, const DominanceInfo *domInfo,
62-
DeadEndBlocks &deadEndBlocks,
63-
HandleTrivialVariable_t handleTrivialVariable = IgnoreTrivialVariable)
66+
OSSALifetimeCompletion(
67+
SILFunction *function, const DominanceInfo *domInfo,
68+
DeadEndBlocks &deadEndBlocks,
69+
HandleTrivialVariable_t handleTrivialVariable = IgnoreTrivialVariable,
70+
bool forceLivenessVerification = false)
6471
: domInfo(domInfo), deadEndBlocks(deadEndBlocks),
65-
completedValues(function), handleTrivialVariable(handleTrivialVariable) {}
72+
completedValues(function), handleTrivialVariable(handleTrivialVariable),
73+
ForceLivenessVerification(forceLivenessVerification) {}
6674

6775
/// The kind of boundary at which to complete the lifetime.
6876
///

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,9 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(
501501
};
502502
Walker walker(*this, scopedAddress, boundary, liveness);
503503
AddressUseKind result = walker.walk(scopedAddress.value);
504-
if (VerifyLifetimeCompletion && boundary != Boundary::Availability
505-
&& result != AddressUseKind::NonEscaping) {
504+
if ((VerifyLifetimeCompletion || ForceLivenessVerification) &&
505+
boundary != Boundary::Availability &&
506+
result != AddressUseKind::NonEscaping) {
506507
llvm::errs() << "Incomplete liveness for:\n" << scopedAddress.value;
507508
if (auto *escapingUse = walker.getEscapingUse()) {
508509
llvm::errs() << " escapes at:\n";

test/SILOptimizer/dead_code_elimination_ossa.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ class C {}
1515

1616
sil @getC : $@convention(thin) () -> @owned C
1717
sil @barrier : $@convention(thin) () -> ()
18+
sil @initC : $@convention(thin) (Builtin.Word) -> (@owned C, Builtin.RawPointer)
19+
sil [readnone] @finalC : $@convention(thin) (@owned C) -> @owned C
1820

1921
struct CAndBit {
2022
var c: C
2123
var bit: Int1
2224
}
2325

26+
struct Bool {
27+
var _value: Builtin.Int1
28+
}
29+
2430
struct MO: ~Copyable {
2531
var x: Int
2632
deinit
@@ -507,3 +513,28 @@ bb0(%0 : @owned $Outer):
507513
return %6 : $()
508514
}
509515

516+
// CHECK-LABEL: sil [ossa] @dont_remove_lifetime_end_of_escaping_value
517+
// CHECK: [[FINALIZE:%[^,]+]] = function_ref @finalC
518+
// CHECK: apply [[FINALIZE]]
519+
// CHECK-LABEL: } // end sil function 'dont_remove_lifetime_end_of_escaping_value'
520+
sil [ossa] @dont_remove_lifetime_end_of_escaping_value : $@convention(thin) (Bool) -> () {
521+
bb0(%0 : $Bool):
522+
%1 = integer_literal $Builtin.Word, 1
523+
%2 = function_ref @initC : $@convention(thin) (Builtin.Word) -> (@owned C, Builtin.RawPointer)
524+
%3 = apply %2(%1) : $@convention(thin) (Builtin.Word) -> (@owned C, Builtin.RawPointer)
525+
(%4, %5) = destructure_tuple %3
526+
%6 = mark_dependence %5 on %4
527+
%7 = pointer_to_address %6 to [strict] $*Bool
528+
store %0 to [trivial] %7
529+
br bb1
530+
531+
bb1:
532+
%13 = function_ref @finalC : $@convention(thin) (@owned C) -> @owned C
533+
%14 = apply %13(%4) : $@convention(thin) (@owned C) -> @owned C
534+
destroy_value %14
535+
br bb2
536+
537+
bb2:
538+
%17 = tuple ()
539+
return %17
540+
}

0 commit comments

Comments
 (0)