Skip to content

Commit 642a993

Browse files
committed
[ownership] Rename Operand::isConsumingUse() -> Operand::isLifetimeEnding().
This makes it clearer that isConsumingUse() is not an owned oriented API and returns also for instructions that end the lifetime of guaranteed values like end_borrow.
1 parent 2ef7a21 commit 642a993

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

include/swift/SIL/SILValue.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ class Operand {
700700

701701
/// Returns true if this operand acts as a use that consumes its associated
702702
/// value.
703-
bool isConsumingUse() const {
703+
bool isLifetimeEnding() const {
704704
// Type dependent uses can never be consuming and do not have valid
705705
// ownership maps since they do not participate in the ownership system.
706706
if (isTypeDependent())
@@ -795,9 +795,9 @@ class ConsumingUseIterator : public ValueBaseUseIterator {
795795
explicit ConsumingUseIterator(Operand *cur) : ValueBaseUseIterator(cur) {}
796796
ConsumingUseIterator &operator++() {
797797
assert(Cur && "incrementing past end()!");
798-
assert(Cur->isConsumingUse());
798+
assert(Cur->isLifetimeEnding());
799799
while ((Cur = Cur->NextUse)) {
800-
if (Cur->isConsumingUse())
800+
if (Cur->isLifetimeEnding())
801801
break;
802802
}
803803
return *this;
@@ -813,7 +813,7 @@ class ConsumingUseIterator : public ValueBaseUseIterator {
813813
inline ValueBase::consuming_use_iterator
814814
ValueBase::consuming_use_begin() const {
815815
auto cur = FirstUse;
816-
while (cur && !cur->isConsumingUse()) {
816+
while (cur && !cur->isLifetimeEnding()) {
817817
cur = cur->NextUse;
818818
}
819819
return ValueBase::consuming_use_iterator(cur);
@@ -828,9 +828,9 @@ class NonConsumingUseIterator : public ValueBaseUseIterator {
828828
explicit NonConsumingUseIterator(Operand *cur) : ValueBaseUseIterator(cur) {}
829829
NonConsumingUseIterator &operator++() {
830830
assert(Cur && "incrementing past end()!");
831-
assert(!Cur->isConsumingUse());
831+
assert(!Cur->isLifetimeEnding());
832832
while ((Cur = Cur->NextUse)) {
833-
if (!Cur->isConsumingUse())
833+
if (!Cur->isLifetimeEnding())
834834
break;
835835
}
836836
return *this;
@@ -846,7 +846,7 @@ class NonConsumingUseIterator : public ValueBaseUseIterator {
846846
inline ValueBase::non_consuming_use_iterator
847847
ValueBase::non_consuming_use_begin() const {
848848
auto cur = FirstUse;
849-
while (cur && cur->isConsumingUse()) {
849+
while (cur && cur->isLifetimeEnding()) {
850850
cur = cur->NextUse;
851851
}
852852
return ValueBase::non_consuming_use_iterator(cur);
@@ -883,7 +883,7 @@ inline Operand *ValueBase::getSingleUse() const {
883883
inline Operand *ValueBase::getSingleConsumingUse() const {
884884
Operand *result = nullptr;
885885
for (auto *op : getUses()) {
886-
if (op->isConsumingUse()) {
886+
if (op->isLifetimeEnding()) {
887887
if (result) {
888888
return nullptr;
889889
}

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void BorrowingOperand::visitLocalEndScopeInstructions(
177177
switch (kind) {
178178
case BorrowingOperandKind::BeginBorrow:
179179
for (auto *use : cast<BeginBorrowInst>(op->getUser())->getUses()) {
180-
if (use->isConsumingUse()) {
180+
if (use->isLifetimeEnding()) {
181181
func(use);
182182
}
183183
}
@@ -248,7 +248,7 @@ void BorrowingOperand::visitUserResultConsumingUses(
248248
if (!ti) {
249249
for (SILValue result : op->getUser()->getResults()) {
250250
for (auto *use : result->getUses()) {
251-
if (use->isConsumingUse()) {
251+
if (use->isLifetimeEnding()) {
252252
visitor(use);
253253
}
254254
}
@@ -259,7 +259,7 @@ void BorrowingOperand::visitUserResultConsumingUses(
259259
for (auto *succBlock : ti->getSuccessorBlocks()) {
260260
auto *arg = succBlock->getArgument(op->getOperandNumber());
261261
for (auto *use : arg->getUses()) {
262-
if (use->isConsumingUse()) {
262+
if (use->isLifetimeEnding()) {
263263
visitor(use);
264264
}
265265
}
@@ -311,8 +311,8 @@ void BorrowedValue::getLocalScopeEndingInstructions(
311311
case BorrowedValueKind::LoadBorrow:
312312
case BorrowedValueKind::Phi:
313313
for (auto *use : value->getUses()) {
314-
if (use->isConsumingUse()) {
315-
scopeEndingInsts.push_back(use->getUser());
314+
if (use->isLifetimeEnding()) {
315+
scopeEndingInsts.push_back(use->getUser());
316316
}
317317
}
318318
return;
@@ -330,7 +330,7 @@ void BorrowedValue::visitLocalScopeEndingUses(
330330
case BorrowedValueKind::BeginBorrow:
331331
case BorrowedValueKind::Phi:
332332
for (auto *use : value->getUses()) {
333-
if (use->isConsumingUse()) {
333+
if (use->isLifetimeEnding()) {
334334
visitor(use);
335335
}
336336
}
@@ -385,7 +385,7 @@ bool BorrowedValue::visitLocalScopeTransitiveEndingUses(
385385
SmallVector<Operand *, 32> worklist;
386386
SmallPtrSet<Operand *, 16> beenInWorklist;
387387
for (auto *use : value->getUses()) {
388-
if (!use->isConsumingUse())
388+
if (!use->isLifetimeEnding())
389389
continue;
390390
worklist.push_back(use);
391391
beenInWorklist.insert(use);
@@ -394,7 +394,7 @@ bool BorrowedValue::visitLocalScopeTransitiveEndingUses(
394394
bool foundError = false;
395395
while (!worklist.empty()) {
396396
auto *op = worklist.pop_back_val();
397-
assert(op->isConsumingUse() && "Expected only consuming uses");
397+
assert(op->isLifetimeEnding() && "Expected only consuming uses");
398398

399399
// See if we have a borrow scope operand. If we do not, then we know we are
400400
// a final consumer of our borrow scope introducer. Visit it and continue.
@@ -406,7 +406,7 @@ bool BorrowedValue::visitLocalScopeTransitiveEndingUses(
406406

407407
scopeOperand->visitConsumingUsesOfBorrowIntroducingUserResults(
408408
[&](Operand *op) {
409-
assert(op->isConsumingUse() && "Expected only consuming uses");
409+
assert(op->isLifetimeEnding() && "Expected only consuming uses");
410410
// Make sure we haven't visited this consuming operand yet. If we
411411
// have, signal an error and bail without re-visiting the operand.
412412
if (!beenInWorklist.insert(op).second) {

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ bool SILValueOwnershipChecker::gatherNonGuaranteedUsers(
242242

243243
// First do a quick check if we have a consuming use. If so, stash the value
244244
// and continue.
245-
if (op->isConsumingUse()) {
245+
if (op->isLifetimeEnding()) {
246246
LLVM_DEBUG(llvm::dbgs() << "Lifetime Ending User: " << *user);
247247
lifetimeEndingUsers.push_back(op);
248248
continue;
@@ -343,7 +343,7 @@ bool SILValueOwnershipChecker::gatherUsers(
343343
// Now check if we have a non guaranteed forwarding inst...
344344
if (!isGuaranteedForwardingInst(user)) {
345345
// First check if we are visiting an operand that is a consuming use...
346-
if (op->isConsumingUse()) {
346+
if (op->isLifetimeEnding()) {
347347
// If its underlying value is our original value, then this is a true
348348
// lifetime ending use. Otherwise, we have a guaranteed value that has
349349
// an end_borrow on a forwarded value which is not supported in any

lib/SILOptimizer/SemanticARC/BorrowScopeOpts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool SemanticARCOptVisitor::visitBeginBorrowInst(BeginBorrowInst *bbi) {
2727
auto kind = bbi->getOperand().getOwnershipKind();
2828
SmallVector<EndBorrowInst *, 16> endBorrows;
2929
for (auto *op : bbi->getUses()) {
30-
if (!op->isConsumingUse()) {
30+
if (!op->isLifetimeEnding()) {
3131
// Make sure that this operand can accept our arguments kind.
3232
auto map = op->getOwnershipKindMap();
3333
if (map.canAcceptKind(kind))

lib/SILOptimizer/SemanticARC/OwnershipLiveRange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ OwnershipLiveRange::OwnershipLiveRange(SILValue value)
4848
// can also accept something that is guaranteed. Any non-consuming use of
4949
// an owned value should be able to take a guaranteed parameter as well
5050
// (modulo bugs). We assert to catch these.
51-
if (!op->isConsumingUse()) {
51+
if (!op->isLifetimeEnding()) {
5252
continue;
5353
}
5454

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class LivenessInfo {
222222
//
223223
// This call cannot be allowed to destroy %val.
224224
void recordUser(Operand *use) {
225-
bool consume = use->isConsumingUse();
225+
bool consume = use->isLifetimeEnding();
226226
auto iterAndSuccess = users.try_emplace(use->getUser(), consume);
227227
if (!iterAndSuccess.second)
228228
iterAndSuccess.first->second &= consume;
@@ -429,7 +429,7 @@ static bool computeLiveness(CopyPropagationState &pass) {
429429
continue;
430430
}
431431

432-
if (use->isConsumingUse()) {
432+
if (use->isLifetimeEnding()) {
433433
pass.liveness.recordOriginalDestroy(use);
434434
// Destroying a values does not force liveness.
435435
if (isa<DestroyValueInst>(user))
@@ -622,7 +622,7 @@ static void rewriteCopies(CopyPropagationState &pass) {
622622
}
623623

624624
// Nonconsuming uses do not need copies and cannot be marked as destroys.
625-
if (!use->isConsumingUse())
625+
if (!use->isLifetimeEnding())
626626
return;
627627

628628
// If this use was marked as a final destroy *and* this is the first

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ static void destroyConsumedOperandOfDeadInst(Operand &operand) {
403403
assert(!isEndOfScopeMarker(deadInst) && !isa<DestroyValueInst>(deadInst) &&
404404
!isa<DestroyAddrInst>(deadInst) &&
405405
"lifetime ending instruction is deleted without its operand");
406-
if (operand.isConsumingUse()) {
406+
if (operand.isLifetimeEnding()) {
407407
// Since deadInst cannot be an end-of-scope instruction (asserted above),
408408
// this must be a consuming use of an owned value.
409409
assert(operandValue.getOwnershipKind() == ValueOwnershipKind::Owned);

0 commit comments

Comments
 (0)