Skip to content

Commit 44796c4

Browse files
committed
[ownership] Change BorrowScopeIntroducingValue::{visit,gather}LocalScopeEndingUses to use isConsumingUse instead of checking for isa<EndBorrowInst>().
I am going to be adding support for branch insts/SILPhiArgument to be able to merge borrow scopes. Thus, the end lifetime for a borrow scope introducing value, may not be an end_borrow. Luckily, in both cases of br and end_borrow we model the end of lifetime as a consuming use, so checking for a consuming use will work both before/after the change.
1 parent 2f263a9 commit 44796c4

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/SIL/OwnershipUtils.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ void BorrowScopeIntroducingValue::getLocalScopeEndingInstructions(
120120
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
121121
llvm_unreachable("Should only call this with a local scope");
122122
case BorrowScopeIntroducingValueKind::BeginBorrow:
123-
llvm::copy(cast<BeginBorrowInst>(value)->getEndBorrows(),
124-
std::back_inserter(scopeEndingInsts));
125-
return;
126123
case BorrowScopeIntroducingValueKind::LoadBorrow:
127-
llvm::copy(cast<LoadBorrowInst>(value)->getEndBorrows(),
128-
std::back_inserter(scopeEndingInsts));
124+
for (auto *use : value->getUses()) {
125+
if (use->isConsumingUse()) {
126+
scopeEndingInsts.push_back(use->getUser());
127+
}
128+
}
129129
return;
130130
}
131131
llvm_unreachable("Covered switch isn't covered?!");
@@ -137,16 +137,10 @@ void BorrowScopeIntroducingValue::visitLocalScopeEndingUses(
137137
switch (kind) {
138138
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
139139
llvm_unreachable("Should only call this with a local scope");
140-
case BorrowScopeIntroducingValueKind::BeginBorrow:
141-
for (auto *use : value->getUses()) {
142-
if (isa<EndBorrowInst>(use->getUser())) {
143-
visitor(use);
144-
}
145-
}
146-
return;
147140
case BorrowScopeIntroducingValueKind::LoadBorrow:
141+
case BorrowScopeIntroducingValueKind::BeginBorrow:
148142
for (auto *use : value->getUses()) {
149-
if (isa<EndBorrowInst>(use->getUser())) {
143+
if (use->isConsumingUse()) {
150144
visitor(use);
151145
}
152146
}

0 commit comments

Comments
 (0)