Skip to content

Commit 3e08f51

Browse files
committed
[CanonicalizeBorrowScope] Adopted BitfieldRef.
1 parent 8882c92 commit 3e08f51

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ class CanonicalizeBorrowScope {
6060
// The borrow that begins this scope.
6161
BorrowedValue borrowedValue;
6262

63+
/// The function containing this scope.
64+
SILFunction *function;
65+
6366
/// Pruned liveness for the extended live range including copies. For this
6467
/// purpose, only consuming instructions are considered "lifetime
6568
/// ending". end_borrows do not end a liverange that may include owned copies.
66-
SSAPrunedLiveness liveness;
69+
BitfieldRef<SSAPrunedLiveness> liveness;
6770

6871
InstructionDeleter &deleter;
6972

@@ -86,11 +89,11 @@ class CanonicalizeBorrowScope {
8689

8790
public:
8891
CanonicalizeBorrowScope(SILFunction *function, InstructionDeleter &deleter)
89-
: liveness(function), deleter(deleter) {}
92+
: function(function), deleter(deleter) {}
9093

9194
BorrowedValue getBorrowedValue() const { return borrowedValue; }
9295

93-
const SSAPrunedLiveness &getLiveness() const { return liveness; }
96+
const SSAPrunedLiveness &getLiveness() const { return *liveness; }
9497

9598
InstructionDeleter &getDeleter() { return deleter; }
9699

@@ -136,11 +139,13 @@ class CanonicalizeBorrowScope {
136139

137140
protected:
138141
void initBorrow(BorrowedValue borrow) {
139-
assert(borrow && liveness.empty() && persistentCopies.empty());
142+
assert(borrow && persistentCopies.empty() &&
143+
(!liveness || liveness->empty()));
140144

141145
updatedCopies.clear();
142146
borrowedValue = borrow;
143-
liveness.initializeDef(borrowedValue.value);
147+
if (liveness)
148+
liveness->initializeDef(borrowedValue.value);
144149
}
145150

146151
bool computeBorrowLiveness();

lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ bool CanonicalizeBorrowScope::computeBorrowLiveness() {
180180
// the reborrowed value will not be rewritten when canonicalizing the current
181181
// borrow scope because they are "hidden" behind the reborrow.
182182
borrowedValue.visitLocalScopeEndingUses([this](Operand *use) {
183-
liveness.updateForUse(use->getUser(), /*lifetimeEnding*/ true);
183+
liveness->updateForUse(use->getUser(), /*lifetimeEnding*/ true);
184184
return true;
185185
});
186186
return true;
@@ -837,12 +837,13 @@ bool CanonicalizeBorrowScope::canonicalizeFunctionArgument(
837837
/// forwarding operations.
838838
bool CanonicalizeBorrowScope::
839839
canonicalizeBorrowScope(BorrowedValue borrowedValue) {
840+
BitfieldRef<SSAPrunedLiveness>::StackState livenessBitfieldContainer(
841+
liveness, function);
842+
840843
LLVM_DEBUG(llvm::dbgs() << "*** Canonicalize Borrow: " << borrowedValue);
841844

842845
initBorrow(borrowedValue);
843846

844-
SWIFT_DEFER { liveness.invalidate(); };
845-
846847
if (!computeBorrowLiveness())
847848
return false;
848849

0 commit comments

Comments
 (0)