Skip to content

Commit 09cfcbf

Browse files
committed
[semantic-arc-opts] Rename LiveRange::has{,Unknown}ConsumingUse.
We are checking the unknown consuming use vector, so the name makes this clearer and makes it clear we are not talking about destroying consumers. I also eliminated the phiToIncomingValueMultiMap being passed in favor of a bool argument since that is how we are using it today. That was a vestige of an earlier version of the patch that had to be sunk.
1 parent 4842e23 commit 09cfcbf

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/SILOptimizer/Transforms/SemanticARCOpts.cpp

+18-20
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class LiveRange {
8484
/// Semantically this implies that a value is never passed off as +1 to memory
8585
/// or another function implying it can be used everywhere at +0.
8686
HasConsumingUse_t
87-
hasConsumingUse(FrozenMultiMap<SILPhiArgument *, OwnedValueIntroducer>
88-
*phiToIncomingValueMultiMap = nullptr) const;
87+
hasUnknownConsumingUse(bool assumingFixedPoint = false) const;
8988

9089
ArrayRef<Operand *> getDestroyingUses() const { return destroyingUses; }
9190

@@ -440,9 +439,8 @@ void LiveRange::convertArgToGuaranteed(DeadEndBlocks &deadEndBlocks,
440439
convertOwnedGeneralForwardingUsesToGuaranteed();
441440
}
442441

443-
LiveRange::HasConsumingUse_t LiveRange::hasConsumingUse(
444-
FrozenMultiMap<SILPhiArgument *, OwnedValueIntroducer>
445-
*phiToIncomingValueMultiMap) const {
442+
LiveRange::HasConsumingUse_t
443+
LiveRange::hasUnknownConsumingUse(bool assumingAtFixPoint) const {
446444
// First do a quick check if we have /any/ unknown consuming
447445
// uses. If we do not have any, return false early.
448446
if (unknownConsumingUses.empty()) {
@@ -451,7 +449,7 @@ LiveRange::HasConsumingUse_t LiveRange::hasConsumingUse(
451449

452450
// Ok, we do have some unknown consuming uses. If we aren't asked to
453451
// update phiToIncomingValueMultiMap, then just return true quickly.
454-
if (!phiToIncomingValueMultiMap) {
452+
if (!assumingAtFixPoint) {
455453
return HasConsumingUse_t::Yes;
456454
}
457455

@@ -832,7 +830,6 @@ static bool canEliminatePhi(
832830
if (!introducer.isConvertableToGuaranteed()) {
833831
return false;
834832
}
835-
836833
// If this linear search is too slow, we can change the
837834
// multimap to sort the mapped to list by pointer
838835
// instead of insertion order. In such a case, we could
@@ -874,17 +871,17 @@ bool SemanticARCOptVisitor::performPostPeepholeOwnedArgElimination() {
874871
// First compute the LiveRange for our phi argument. For simplicity, we only
875872
// handle cases now where our phi argument does not have any phi unknown
876873
// consumers.
877-
SILPhiArgument *phiArg = pair.first;
878-
LiveRange phiArgLiveRange(phiArg);
879-
if (bool(phiArgLiveRange.hasConsumingUse())) {
874+
SILPhiArgument *phi = pair.first;
875+
LiveRange phiLiveRange(phi);
876+
if (bool(phiLiveRange.hasUnknownConsumingUse())) {
880877
continue;
881878
}
882879

883880
// Ok, we know that our phi argument /could/ be converted to guaranteed if
884881
// our incoming values are able to be converted to guaranteed. Now for each
885882
// incoming value, compute the incoming values ownership roots and see if
886883
// all of the ownership roots are in our owned incoming value array.
887-
if (!phiArg->getIncomingPhiOperands(incomingValueOperandList)) {
884+
if (!phi->getIncomingPhiOperands(incomingValueOperandList)) {
888885
continue;
889886
}
890887

@@ -907,7 +904,7 @@ bool SemanticARCOptVisitor::performPostPeepholeOwnedArgElimination() {
907904
for (Operand *incomingValueOperand : incomingValueOperandList) {
908905
originalIncomingValues.push_back(incomingValueOperand->get());
909906
SILType type = incomingValueOperand->get()->getType();
910-
auto *undef = SILUndef::get(type, *phiArg->getFunction());
907+
auto *undef = SILUndef::get(type, *phi->getFunction());
911908
incomingValueOperand->set(undef);
912909
}
913910

@@ -960,7 +957,7 @@ bool SemanticARCOptVisitor::performPostPeepholeOwnedArgElimination() {
960957
}
961958

962959
// Then convert the phi's live range to be guaranteed.
963-
std::move(phiArgLiveRange)
960+
std::move(phiLiveRange)
964961
.convertArgToGuaranteed(getDeadEndBlocks(), lifetimeFrontier,
965962
getCallbacks());
966963

@@ -984,7 +981,7 @@ bool SemanticARCOptVisitor::performPostPeepholeOwnedArgElimination() {
984981

985982
madeChange = true;
986983
if (VerifyAfterTransform) {
987-
phiArg->getFunction()->verify();
984+
phi->getFunction()->verify();
988985
}
989986
}
990987

@@ -1179,9 +1176,9 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(CopyValueInst
11791176
// forwarding or a user that truly represents a necessary consume of the value
11801177
// (e.x. storing into memory).
11811178
LiveRange lr(cvi);
1182-
auto hasConsumingUseState =
1183-
lr.hasConsumingUse(getPhiToIncomingValueMultiMap());
1184-
if (hasConsumingUseState == LiveRange::HasConsumingUse_t::Yes) {
1179+
auto hasUnknownConsumingUseState =
1180+
lr.hasUnknownConsumingUse(getPhiToIncomingValueMultiMap());
1181+
if (hasUnknownConsumingUseState == LiveRange::HasConsumingUse_t::Yes) {
11851182
return false;
11861183
}
11871184

@@ -1290,7 +1287,8 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(CopyValueInst
12901287
// was consumed, the hasConsumedUse code updated phiToIncomingValueMultiMap
12911288
// for us before returning its prognosis. After we reach a fixed point, we
12921289
// will try to eliminate this value then.
1293-
if (hasConsumingUseState == LiveRange::HasConsumingUse_t::YesButAllPhiArgs) {
1290+
if (hasUnknownConsumingUseState ==
1291+
LiveRange::HasConsumingUse_t::YesButAllPhiArgs) {
12941292
auto *op = lr.getSingleUnknownConsumingUse();
12951293
assert(op);
12961294
unsigned opNum = op->getOperandNumber();
@@ -1306,7 +1304,7 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(CopyValueInst
13061304

13071305
auto *arg = succBlock->getSILPhiArguments()[opNum];
13081306
LiveRange phiArgLR(arg);
1309-
if (bool(phiArgLR.hasConsumingUse())) {
1307+
if (bool(phiArgLR.hasUnknownConsumingUse())) {
13101308
return false;
13111309
}
13121310

@@ -1788,7 +1786,7 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
17881786
// -> load_borrow if we can put a copy_value on a cold path and thus
17891787
// eliminate RR traffic on a hot path.
17901788
LiveRange lr(li);
1791-
if (bool(lr.hasConsumingUse()))
1789+
if (bool(lr.hasUnknownConsumingUse()))
17921790
return false;
17931791

17941792
// Then check if our address is ever written to. If it is, then we cannot use

0 commit comments

Comments
 (0)