Skip to content

Commit 96331dd

Browse files
committed
[NFC] OwnershipLiveRange: Track UsePoints.
Instead of tracking Operands, track UsePoints, i.e. `Either<Operand, SILInstruction>`s. For now, all use points wil remain operands. This change is necessary to allow tracking terminators in dead-end region as implicit uses.
1 parent cbe3835 commit 96331dd

File tree

3 files changed

+43
-52
lines changed

3 files changed

+43
-52
lines changed

lib/SILOptimizer/SemanticARC/CopyValueOpts.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
170170
return borrowScope.isLocalScope();
171171
});
172172

173-
auto destroys = lr.getDestroyingUses();
173+
auto destroys = lr.getDestroyingInsts();
174174
if (destroys.empty() && haveAnyLocalScopes) {
175175
return false;
176176
}
@@ -196,8 +196,8 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
196196
// block.
197197
{
198198
if (llvm::any_of(borrowScopeIntroducers, [&](BorrowedValue borrowScope) {
199-
return !borrowScope.areUsesWithinExtendedScope(
200-
lr.getAllConsumingUses(), nullptr);
199+
return !borrowScope.areWithinExtendedScope(lr.getAllConsumingInsts(),
200+
nullptr);
201201
})) {
202202
LLVM_DEBUG(llvm::dbgs() << "copy_value is extending borrow introducer "
203203
"lifetime, bailing out\n");
@@ -238,8 +238,8 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
238238
}
239239

240240
if (llvm::any_of(borrowScopeIntroducers, [&](BorrowedValue borrowScope) {
241-
return !borrowScope.areUsesWithinExtendedScope(
242-
phiArgLR.getAllConsumingUses(), nullptr);
241+
return !borrowScope.areWithinExtendedScope(
242+
phiArgLR.getAllConsumingInsts(), nullptr);
243243
})) {
244244
return false;
245245
}

lib/SILOptimizer/SemanticARC/OwnershipLiveRange.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ OwnershipLiveRange::OwnershipLiveRange(SILValue value)
2626
assert(introducer);
2727
assert(introducer.value->getOwnershipKind() == OwnershipKind::Owned);
2828

29-
SmallVector<Operand *, 32> tmpDestroyingUses;
30-
SmallVector<Operand *, 32> tmpForwardingConsumingUses;
31-
SmallVector<Operand *, 32> tmpUnknownConsumingUses;
29+
SmallVector<UsePoint, 32> tmpDestroyingUses;
30+
SmallVector<UsePoint, 32> tmpForwardingConsumingUses;
31+
SmallVector<UsePoint, 32> tmpUnknownConsumingUses;
3232

3333
// We know that our silvalue produces an @owned value. Look through all of our
3434
// uses and classify them as either consuming or not.
@@ -248,7 +248,8 @@ void OwnershipLiveRange::insertEndBorrowsAtDestroys(
248248

249249
void OwnershipLiveRange::convertOwnedGeneralForwardingUsesToGuaranteed() && {
250250
while (!ownershipForwardingUses.empty()) {
251-
auto *use = ownershipForwardingUses.back();
251+
auto point = ownershipForwardingUses.back();
252+
auto *use = point.getOperand();
252253
ownershipForwardingUses = ownershipForwardingUses.drop_back();
253254
ForwardingOperand operand(use);
254255
operand.replaceOwnershipKind(OwnershipKind::Owned,
@@ -260,9 +261,10 @@ void OwnershipLiveRange::convertToGuaranteedAndRAUW(
260261
SILValue newGuaranteedValue, InstModCallbacks callbacks) && {
261262
auto *value = cast<SingleValueInstruction>(introducer.value);
262263
while (!destroyingUses.empty()) {
263-
auto *d = destroyingUses.back();
264+
auto point = destroyingUses.back();
265+
auto *destroy = point.getInstruction();
264266
destroyingUses = destroyingUses.drop_back();
265-
callbacks.deleteInst(d->getUser());
267+
callbacks.deleteInst(destroy);
266268
}
267269

268270
callbacks.eraseAndRAUWSingleValueInst(value, newGuaranteedValue);
@@ -318,9 +320,10 @@ void OwnershipLiveRange::convertJoinedLiveRangePhiToGuaranteed(
318320

319321
// Then eliminate all of the destroys...
320322
while (!destroyingUses.empty()) {
321-
auto *d = destroyingUses.back();
323+
auto point = destroyingUses.back();
324+
auto *destroy = point.getInstruction();
322325
destroyingUses = destroyingUses.drop_back();
323-
callbacks.deleteInst(d->getUser());
326+
callbacks.deleteInst(destroy);
324327
}
325328

326329
// and change all of our guaranteed forwarding insts to have guaranteed
@@ -362,15 +365,3 @@ OwnershipLiveRange::hasUnknownConsumingUse(bool assumingAtFixPoint) const {
362365
// to our introducer.
363366
return HasConsumingUse_t::YesButAllPhiArgs;
364367
}
365-
366-
SILInstruction::OperandUserRange
367-
OwnershipLiveRange::getDestroyingInsts() const {
368-
return SILInstruction::OperandUserRange(getDestroyingUses(),
369-
SILInstruction::OperandToUser());
370-
}
371-
372-
SILInstruction::OperandUserRange
373-
OwnershipLiveRange::getAllConsumingInsts() const {
374-
return SILInstruction::OperandUserRange(consumingUses,
375-
SILInstruction::OperandToUser());
376-
}

lib/SILOptimizer/SemanticARC/OwnershipLiveRange.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ class LLVM_LIBRARY_VISIBILITY OwnershipLiveRange {
5454
/// order. This is why it is important not to mutate consumingUses after we
5555
/// construct the LiveRange since going from small -> large could invalidate
5656
/// the uses.
57-
SmallVector<Operand *, 6> consumingUses;
57+
///
58+
/// These UsePoints may be Operands or SILInstructions (terminators of blocks
59+
/// in dead-end regions along the value's availability boundary).
60+
SmallVector<UsePoint, 6> consumingUses;
5861

5962
/// A list of destroy_values of the live range.
6063
///
61-
/// This is just a view into consuming uses.
62-
ArrayRef<Operand *> destroyingUses;
64+
/// This is just a view into consumingUses.
65+
///
66+
/// These UsePoints may be Operands or SILInstructions (terminators of blocks
67+
/// in dead-end regions along the value's availability boundary).
68+
ArrayRef<UsePoint> destroyingUses;
6369

6470
/// A list of forwarding instructions that forward owned ownership, but that
6571
/// are also able to be converted to guaranteed ownership.
@@ -76,12 +82,16 @@ class LLVM_LIBRARY_VISIBILITY OwnershipLiveRange {
7682
/// "consumingUses" array the true lifetime of the OwnershipLiveRange.
7783
///
7884
/// Corresponds to isOwnershipForwardingInst(...).
79-
ArrayRef<Operand *> ownershipForwardingUses;
85+
///
86+
/// These UsePoints must all be Operands.
87+
ArrayRef<UsePoint> ownershipForwardingUses;
8088

8189
/// Consuming uses that we were not able to understand as a forwarding
8290
/// instruction or a destroy_value. These must be passed a strongly control
8391
/// equivalent +1 value.
84-
ArrayRef<Operand *> unknownConsumingUses;
92+
///
93+
/// These UsePoints must all be Operands.
94+
ArrayRef<UsePoint> unknownConsumingUses;
8595

8696
public:
8797
OwnershipLiveRange(SILValue value);
@@ -102,28 +112,17 @@ class LLVM_LIBRARY_VISIBILITY OwnershipLiveRange {
102112
HasConsumingUse_t
103113
hasUnknownConsumingUse(bool assumingFixedPoint = false) const;
104114

105-
/// Return an array ref to /all/ consuming uses. Will include all 3 sorts of
106-
/// consuming uses: destroying uses, forwarding consuming uses, and unknown
107-
/// forwarding instruction.
108-
ArrayRef<Operand *> getAllConsumingUses() const { return consumingUses; }
109-
110-
ArrayRef<Operand *> getDestroyingUses() const { return destroyingUses; }
111-
112-
ArrayRef<Operand *> getUnknownConsumingUses() const {
113-
return unknownConsumingUses;
115+
UsePointInstructionRange getDestroyingInsts() const {
116+
return UsePointInstructionRange(destroyingUses, UsePointToInstruction());
114117
}
115118

116-
SILInstruction::OperandUserRange getDestroyingInsts() const;
117-
118-
SILInstruction::OperandUserRange getAllConsumingInsts() const;
119+
UsePointInstructionRange getUnknownConsumingInsts() const {
120+
return UsePointInstructionRange(unknownConsumingUses,
121+
UsePointToInstruction());
122+
}
119123

120-
/// If this LiveRange has a single destroying use, return that use. Otherwise,
121-
/// return nullptr.
122-
Operand *getSingleDestroyingUse() const {
123-
if (destroyingUses.size() != 1) {
124-
return nullptr;
125-
}
126-
return destroyingUses.front();
124+
UsePointInstructionRange getAllConsumingInsts() const {
125+
return UsePointInstructionRange(consumingUses, UsePointToInstruction());
127126
}
128127

129128
/// If this LiveRange has a single unknown destroying use, return that
@@ -132,13 +131,14 @@ class LLVM_LIBRARY_VISIBILITY OwnershipLiveRange {
132131
if (unknownConsumingUses.size() != 1) {
133132
return nullptr;
134133
}
135-
return unknownConsumingUses.front();
134+
auto point = unknownConsumingUses.front();
135+
return point.getOperand();
136136
}
137137

138138
OwnedValueIntroducer getIntroducer() const { return introducer; }
139139

140-
ArrayRef<Operand *> getOwnershipForwardingUses() const {
141-
return ownershipForwardingUses;
140+
PointOperandRange getOwnershipForwardingUses() const {
141+
return PointOperandRange(ownershipForwardingUses, PointToOperand());
142142
}
143143

144144
void convertOwnedGeneralForwardingUsesToGuaranteed() &&;

0 commit comments

Comments
 (0)