@@ -300,8 +300,7 @@ struct AvailableValue {
300
300
AvailableValue emitBeginBorrow (SILBuilder &b, SILLocation loc) const {
301
301
// If we do not have ownership or already are guaranteed, just return a copy
302
302
// of our state.
303
- if (!b.hasOwnership () ||
304
- Value->getOwnershipKind ().isCompatibleWith (OwnershipKind::Guaranteed)) {
303
+ if (Value->getOwnershipKind ().isCompatibleWith (OwnershipKind::Guaranteed)) {
305
304
return {Value, SubElementNumber, InsertionPoints};
306
305
}
307
306
@@ -439,8 +438,6 @@ static SILValue nonDestructivelyExtractSubElement(const AvailableValue &Val,
439
438
// load [copy] or a load [trivial], while in non-[ossa] SIL we will
440
439
// be replacing unqualified loads.
441
440
assert (SubElementNumber == 0 && " Miscalculation indexing subelements" );
442
- if (!B.hasOwnership ())
443
- return Val.getValue ();
444
441
return B.emitCopyValueOperation (Loc, Val.getValue ());
445
442
}
446
443
@@ -778,12 +775,6 @@ void AvailableValueAggregator::print(llvm::raw_ostream &os) const {
778
775
// address.
779
776
bool AvailableValueAggregator::canTake (SILType loadTy,
780
777
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
-
787
778
// If we are trivially fully available, just return true.
788
779
if (isFullyAvailable (loadTy, firstElt, AvailableValueList))
789
780
return true ;
@@ -888,13 +879,10 @@ SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
888
879
auto &val = AvailableValueList[FirstElt];
889
880
if (!val) {
890
881
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);
898
886
}());
899
887
Uses.emplace_back (load, PMOUseKind::Load);
900
888
return load;
@@ -2188,18 +2176,6 @@ bool OptimizeAllocLoads::promoteLoadCopy(LoadInst *li) {
2188
2176
LLVM_DEBUG (llvm::dbgs () << " To value: " << *newVal);
2189
2177
++NumLoadPromoted;
2190
2178
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
-
2203
2179
// If we inserted any copies, we created the copies at our stores. We know
2204
2180
// that in our load block, we will reform the aggregate as appropriate at the
2205
2181
// load implying that the value /must/ be fully consumed. If we promoted a +0
@@ -2946,9 +2922,6 @@ bool swift::optimizeMemoryAccesses(SILFunction *fn) {
2946
2922
}
2947
2923
2948
2924
bool swift::eliminateDeadAllocations (SILFunction *fn, DominanceInfo *domInfo) {
2949
- if (!fn->hasOwnership ())
2950
- return false ;
2951
-
2952
2925
bool changed = false ;
2953
2926
DeadEndBlocks deadEndBlocks (fn);
2954
2927
@@ -3000,6 +2973,9 @@ class PredictableMemoryAccessOptimizations : public SILFunctionTransform {
3000
2973
// / or has a pass order dependency on other early passes.
3001
2974
void run () override {
3002
2975
auto *func = getFunction ();
2976
+ if (!func->hasOwnership ())
2977
+ return ;
2978
+
3003
2979
LLVM_DEBUG (llvm::dbgs () << " Looking at: " << func->getName () << " \n " );
3004
2980
// TODO: Can we invalidate here just instructions?
3005
2981
if (optimizeMemoryAccesses (func))
@@ -3010,6 +2986,9 @@ class PredictableMemoryAccessOptimizations : public SILFunctionTransform {
3010
2986
class PredictableDeadAllocationElimination : public SILFunctionTransform {
3011
2987
void run () override {
3012
2988
auto *func = getFunction ();
2989
+ if (!func->hasOwnership ())
2990
+ return ;
2991
+
3013
2992
LLVM_DEBUG (llvm::dbgs () << " Looking at: " << func->getName () << " \n " );
3014
2993
auto *da = getAnalysis<DominanceAnalysis>();
3015
2994
// If we are already canonical or do not have ownership, just bail.
0 commit comments