Skip to content

Commit 14a9dcb

Browse files
committed
[pmo] Refactor into helper isFullyAvailable the fully available check from aggregateFullyAvailableValue.
This is NFC. I am going to use this check in another part of the code to verify that we can split up destroy_addr without needing to destructure available values.
1 parent feddd1d commit 14a9dcb

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,14 @@ class AvailableValueAggregator {
411411
void dump() const LLVM_ATTRIBUTE_USED;
412412

413413
private:
414-
SILValue aggregateFullyAvailableValue(SILType LoadTy, unsigned FirstElt);
415-
SILValue aggregateTupleSubElts(TupleType *TT, SILType LoadTy,
416-
SILValue Address, unsigned FirstElt);
417-
SILValue aggregateStructSubElts(StructDecl *SD, SILType LoadTy,
418-
SILValue Address, unsigned FirstElt);
419-
SILValue handlePrimitiveValue(SILType LoadTy, SILValue Address,
420-
unsigned FirstElt);
414+
SILValue aggregateFullyAvailableValue(SILType loadTy, unsigned firstElt);
415+
SILValue aggregateTupleSubElts(TupleType *tt, SILType loadTy,
416+
SILValue address, unsigned firstElt);
417+
SILValue aggregateStructSubElts(StructDecl *sd, SILType loadTy,
418+
SILValue address, unsigned firstElt);
419+
SILValue handlePrimitiveValue(SILType loadTy, SILValue address,
420+
unsigned firstElt);
421+
bool isFullyAvailable(SILType loadTy, unsigned firstElt) const;
421422
};
422423

423424
} // end anonymous namespace
@@ -432,6 +433,26 @@ void AvailableValueAggregator::print(llvm::raw_ostream &os) const {
432433
}
433434
}
434435

436+
bool AvailableValueAggregator::isFullyAvailable(SILType loadTy,
437+
unsigned firstElt) const {
438+
if (firstElt >= AvailableValueList.size()) { // #Elements may be zero.
439+
return false;
440+
}
441+
442+
auto &firstVal = AvailableValueList[firstElt];
443+
444+
// Make sure that the first element is available and is the correct type.
445+
if (!firstVal || firstVal.getType() != loadTy)
446+
return false;
447+
448+
return llvm::all_of(range(getNumSubElements(loadTy, M)),
449+
[&](unsigned index) -> bool {
450+
auto &val = AvailableValueList[firstElt + index];
451+
return val.getValue() == firstVal.getValue() &&
452+
val.getSubElementNumber() == index;
453+
});
454+
}
455+
435456
/// Given a bunch of primitive subelement values, build out the right aggregate
436457
/// type (LoadTy) by emitting tuple and struct instructions as necessary.
437458
SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
@@ -463,26 +484,13 @@ SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
463484
SILValue
464485
AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
465486
unsigned firstElt) {
466-
if (firstElt >= AvailableValueList.size()) { // #Elements may be zero.
487+
// Check if our underlying type is fully available. If it isn't, bail.
488+
if (!isFullyAvailable(loadTy, firstElt))
467489
return SILValue();
468-
}
469490

491+
// Ok, grab out first value. (note: any actually will do).
470492
auto &firstVal = AvailableValueList[firstElt];
471493

472-
// Make sure that the first element is available and is the correct type.
473-
if (!firstVal || firstVal.getType() != loadTy)
474-
return SILValue();
475-
476-
// If the first element of this value is available, check that any extra
477-
// available values are from the same place as our first value.
478-
if (llvm::any_of(range(getNumSubElements(loadTy, M)),
479-
[&](unsigned index) -> bool {
480-
auto &val = AvailableValueList[firstElt + index];
481-
return val.getValue() != firstVal.getValue() ||
482-
val.getSubElementNumber() != index;
483-
}))
484-
return SILValue();
485-
486494
// Ok, we know that all of our available values are all parts of the same
487495
// value. Without ownership, we can just return the underlying first value.
488496
if (!B.hasOwnership())

0 commit comments

Comments
 (0)