Skip to content

Commit 2fd9e5e

Browse files
committed
PredictableMemOpt: remove non-OSSA support
PredictableMemOpt only runs with OSSA. The recent refactoring did not preserve non-OSSA conditions because it adds complexity. This commit just makes it official. In the near future, this pass will be replaced by an OSSA-only pass anyway, so this brings us one small step closer to that.
1 parent 60cb13e commit 2fd9e5e

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ struct AvailableValue {
300300
AvailableValue emitBeginBorrow(SILBuilder &b, SILLocation loc) const {
301301
// If we do not have ownership or already are guaranteed, just return a copy
302302
// of our state.
303-
if (!b.hasOwnership() ||
304-
Value->getOwnershipKind().isCompatibleWith(OwnershipKind::Guaranteed)) {
303+
if (Value->getOwnershipKind().isCompatibleWith(OwnershipKind::Guaranteed)) {
305304
return {Value, SubElementNumber, InsertionPoints};
306305
}
307306

@@ -439,8 +438,6 @@ static SILValue nonDestructivelyExtractSubElement(const AvailableValue &Val,
439438
// load [copy] or a load [trivial], while in non-[ossa] SIL we will
440439
// be replacing unqualified loads.
441440
assert(SubElementNumber == 0 && "Miscalculation indexing subelements");
442-
if (!B.hasOwnership())
443-
return Val.getValue();
444441
return B.emitCopyValueOperation(Loc, Val.getValue());
445442
}
446443

@@ -778,12 +775,6 @@ void AvailableValueAggregator::print(llvm::raw_ostream &os) const {
778775
// address.
779776
bool AvailableValueAggregator::canTake(SILType loadTy,
780777
unsigned firstElt) const {
781-
// If we do not have ownership, we can always take since we do not need to
782-
// keep any ownership invariants up to date. In the future, we should be able
783-
// to chop up larger values before they are being stored.
784-
if (!B.hasOwnership())
785-
return true;
786-
787778
// If we are trivially fully available, just return true.
788779
if (isFullyAvailable(loadTy, firstElt, AvailableValueList))
789780
return true;
@@ -888,13 +879,10 @@ SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
888879
auto &val = AvailableValueList[FirstElt];
889880
if (!val) {
890881
LoadInst *load = ([&]() {
891-
if (B.hasOwnership()) {
892-
SILBuilderWithScope builder(&*B.getInsertionPoint(),
893-
&ownershipFixup.insertedInsts);
894-
return builder.createTrivialLoadOr(Loc, Address,
895-
LoadOwnershipQualifier::Copy);
896-
}
897-
return B.createLoad(Loc, Address, LoadOwnershipQualifier::Unqualified);
882+
SILBuilderWithScope builder(&*B.getInsertionPoint(),
883+
&ownershipFixup.insertedInsts);
884+
return builder.createTrivialLoadOr(Loc, Address,
885+
LoadOwnershipQualifier::Copy);
898886
}());
899887
Uses.emplace_back(load, PMOUseKind::Load);
900888
return load;
@@ -2188,18 +2176,6 @@ bool OptimizeAllocLoads::promoteLoadCopy(LoadInst *li) {
21882176
LLVM_DEBUG(llvm::dbgs() << " To value: " << *newVal);
21892177
++NumLoadPromoted;
21902178

2191-
// If we did not have ownership, we did not insert extra copies at our stores,
2192-
// so we can just RAUW and return.
2193-
if (!li->getFunction()->hasOwnership()) {
2194-
li->replaceAllUsesWith(newVal);
2195-
2196-
SILValue addr = li->getOperand();
2197-
deleter.forceDelete(li);
2198-
if (auto *addrI = addr->getDefiningInstruction())
2199-
deleter.deleteIfDead(addrI);
2200-
return true;
2201-
}
2202-
22032179
// If we inserted any copies, we created the copies at our stores. We know
22042180
// that in our load block, we will reform the aggregate as appropriate at the
22052181
// load implying that the value /must/ be fully consumed. If we promoted a +0
@@ -2946,9 +2922,6 @@ bool swift::optimizeMemoryAccesses(SILFunction *fn) {
29462922
}
29472923

29482924
bool swift::eliminateDeadAllocations(SILFunction *fn, DominanceInfo *domInfo) {
2949-
if (!fn->hasOwnership())
2950-
return false;
2951-
29522925
bool changed = false;
29532926
DeadEndBlocks deadEndBlocks(fn);
29542927

@@ -3000,6 +2973,9 @@ class PredictableMemoryAccessOptimizations : public SILFunctionTransform {
30002973
/// or has a pass order dependency on other early passes.
30012974
void run() override {
30022975
auto *func = getFunction();
2976+
if (!func->hasOwnership())
2977+
return;
2978+
30032979
LLVM_DEBUG(llvm::dbgs() << "Looking at: " << func->getName() << "\n");
30042980
// TODO: Can we invalidate here just instructions?
30052981
if (optimizeMemoryAccesses(func))
@@ -3010,6 +2986,9 @@ class PredictableMemoryAccessOptimizations : public SILFunctionTransform {
30102986
class PredictableDeadAllocationElimination : public SILFunctionTransform {
30112987
void run() override {
30122988
auto *func = getFunction();
2989+
if (!func->hasOwnership())
2990+
return;
2991+
30132992
LLVM_DEBUG(llvm::dbgs() << "Looking at: " << func->getName() << "\n");
30142993
auto *da = getAnalysis<DominanceAnalysis>();
30152994
// If we are already canonical or do not have ownership, just bail.

0 commit comments

Comments
 (0)