Skip to content

Commit 2d91316

Browse files
authored
Merge pull request #63485 from atrick/fix-inner-adjacent
Add visitInnerAdjacentPhis OSSA helper
2 parents c67e22e + 4224d94 commit 2d91316

File tree

6 files changed

+128
-320
lines changed

6 files changed

+128
-320
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,6 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
///
13-
/// Terminology:
14-
///
15-
/// Simple liveness:
16-
/// - Ends at lifetime-ending operations.
17-
/// - Transitively follows guaranteed forwarding operations and address uses
18-
/// within the current scope.
19-
/// - Assumes inner scopes are complete, including borrow and address scopes
20-
/// - Rarely returns AddressUseKind::PointerEscape.
21-
/// - Per-definition dominance holds
22-
/// - Insulates outer scopes from inner scope details. Maintains the
23-
/// invariant that inlining cannot pessimize optimization.
24-
///
25-
/// Transitive liveness
26-
/// - Transitively follows uses within inner scopes, including forwarding
27-
/// operations and address uses.
28-
/// - Much more likely to returns AddressUseKind::PointerEscape
29-
/// - Per-definition dominance holds
30-
/// - Does not assume that any scopes are complete.
31-
///
32-
/// Extended liveness (copy-extension and reborrow-extension)
33-
/// - Extends a live range across lifetime-ending operations
34-
/// - Depending on context: owned values are extended across copies or
35-
/// guaranteed values are extended across reborrows
36-
/// - Copy-extension is used to canonicalize an OSSA lifetime
37-
/// - Reborrow-extension is used to check borrow scopes relative to its inner
38-
/// uses and outer lifetime
39-
/// - Per-definition dominance does not hold
40-
///
41-
//===----------------------------------------------------------------------===//
4212

4313
#ifndef SWIFT_SIL_OWNERSHIPUTILS_H
4414
#define SWIFT_SIL_OWNERSHIPUTILS_H
@@ -255,6 +225,10 @@ bool findUsesOfSimpleValue(SILValue value,
255225
bool visitGuaranteedForwardingPhisForSSAValue(
256226
SILValue value, function_ref<bool(Operand *)> func);
257227

228+
//===----------------------------------------------------------------------===//
229+
// Abstractions
230+
//===----------------------------------------------------------------------===//
231+
258232
/// An operand that forwards ownership to one or more results.
259233
class ForwardingOperand {
260234
Operand *use = nullptr;
@@ -1312,13 +1286,16 @@ void visitExtendedGuaranteedForwardingPhiBaseValuePairs(
13121286
bool visitForwardedGuaranteedOperands(
13131287
SILValue value, function_ref<void(Operand *)> visitOperand);
13141288

1315-
/// Visit the phis in the same block as \p phi which are reborrows of a borrow
1316-
/// of one of the values reaching \p phi.
1289+
1290+
/// Return true of the lifetime of \p innerPhiVal depends on \p outerPhiVal.
1291+
bool isInnerAdjacentPhi(SILArgument *innerPhiVal, SILArgument *outerPhiVal);
1292+
1293+
/// Visit the phis in the same block as \p phi whose lifetime depends on \p phi.
13171294
///
13181295
/// If the visitor returns false, stops visiting and returns false. Otherwise,
13191296
/// returns true.
1320-
bool visitAdjacentReborrowsOfPhi(SILPhiArgument *phi,
1321-
function_ref<bool(SILPhiArgument *)> visitor);
1297+
bool visitInnerAdjacentPhis(SILArgument *phi,
1298+
function_ref<bool(SILArgument *)> visitor);
13221299

13231300
/// Visit each definition of a scope that immediately encloses a guaranteed
13241301
/// value. The guaranteed value effectively keeps these scopes alive.

0 commit comments

Comments
 (0)