Skip to content

Commit c47e7d2

Browse files
committed
[NFC] SIL: Clarified deinit barrier APIs.
An instruction is a deinit barrier whenever one of three component predicates is true for it. In the case of applies, it is true whenever one of those three predicates is true for any of the instructions in any of its callees; that fact is cached in the side-effect analysis of every function. If side-effect analysis or callee analysis is unavailable, in order to define each of those three component predicates on a FullApplySite, it would be necessary to define them to conservatively return true: it isn't known whether any of the instructions in any of the callees were deinit barriers. Refactored the two versions of the deinit barrier predicate (namely `Instruction.isDeinitBarrier(_:) and `swift::mayBeDeinitBarrierNotConsideringSideEffects`) to handle `FullApplySite`s specially first (to look up the side-effect and to conservatively bail, respectively). Asserted that the three component predicates are not called with `FullApplySite`s. Callers should instead use the `isDeinitBarrier` APIs. An alternative would be to conservatively return true from the three components. That seems more likely to result in directly calls to these member predicates, however, and at the moment at least there is no reason for such calls to exist.
1 parent 77fd37b commit c47e7d2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/Analysis/CalleeAnalysis.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,16 @@ extension FullApplySite {
108108
}
109109

110110
extension Instruction {
111-
public final func maySynchronize(_ analysis: CalleeAnalysis) -> Bool {
112-
if let site = self as? FullApplySite {
113-
return site.isBarrier(analysis)
114-
}
115-
return maySynchronize
116-
}
117-
118111
/// Whether lifetime ends of lexical values may safely be hoisted over this
119112
/// instruction.
120113
///
121114
/// Deinitialization barriers constrain variable lifetimes. Lexical
122115
/// end_borrow, destroy_value, and destroy_addr cannot be hoisted above them.
123116
public final func isDeinitBarrier(_ analysis: CalleeAnalysis) -> Bool {
124-
return mayAccessPointer || mayLoadWeakOrUnowned || maySynchronize(analysis)
117+
if let site = self as? FullApplySite {
118+
return site.isBarrier(analysis)
119+
}
120+
return mayAccessPointer || mayLoadWeakOrUnowned || maySynchronize
125121
}
126122
}
127123

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ bool swift::isLetAddress(SILValue address) {
437437
//===----------------------------------------------------------------------===//
438438

439439
bool swift::mayAccessPointer(SILInstruction *instruction) {
440+
assert(!FullApplySite::isa(instruction));
440441
if (!instruction->mayReadOrWriteMemory())
441442
return false;
442443
if (isa<BuiltinInst>(instruction)) {
@@ -455,6 +456,7 @@ bool swift::mayAccessPointer(SILInstruction *instruction) {
455456
}
456457

457458
bool swift::mayLoadWeakOrUnowned(SILInstruction *instruction) {
459+
assert(!FullApplySite::isa(instruction));
458460
return isa<LoadWeakInst>(instruction)
459461
|| isa<LoadUnownedInst>(instruction)
460462
|| isa<StrongCopyUnownedValueInst>(instruction)
@@ -464,13 +466,17 @@ bool swift::mayLoadWeakOrUnowned(SILInstruction *instruction) {
464466
/// Conservatively, whether this instruction could involve a synchronization
465467
/// point like a memory barrier, lock or syscall.
466468
bool swift::maySynchronize(SILInstruction *instruction) {
469+
assert(!FullApplySite::isa(instruction));
467470
return FullApplySite::isa(instruction)
468471
|| isa<EndApplyInst>(instruction)
469472
|| isa<AbortApplyInst>(instruction)
470473
|| isa<HopToExecutorInst>(instruction);
471474
}
472475

473476
bool swift::mayBeDeinitBarrierNotConsideringSideEffects(SILInstruction *instruction) {
477+
if (FullApplySite::isa(instruction)) {
478+
return true;
479+
}
474480
bool retval = mayAccessPointer(instruction)
475481
|| mayLoadWeakOrUnowned(instruction)
476482
|| maySynchronize(instruction);

0 commit comments

Comments
 (0)