diff --git a/lib/SILGen/ManagedValue.cpp b/lib/SILGen/ManagedValue.cpp index 7c9ac26b386..f09d72ff736 100644 --- a/lib/SILGen/ManagedValue.cpp +++ b/lib/SILGen/ManagedValue.cpp @@ -200,7 +200,6 @@ ManagedValue ManagedValue::materialize(SILGenFunction &SGF, auto temporary = SGF.emitTemporaryAllocation(loc, getType()); bool hadCleanup = hasCleanup(); - // The temporary memory is +0 if the value was. if (hadCleanup) { SGF.B.emitStoreValueOperation(loc, forward(SGF), temporary, StoreOwnershipQualifier::Init); @@ -218,9 +217,37 @@ ManagedValue ManagedValue::materialize(SILGenFunction &SGF, return ManagedValue::forOwnedAddressRValue( temporary, SGF.enterDestroyCleanup(temporary)); } + // The temporary memory is +0 if the value was. auto object = SGF.emitManagedBeginBorrow(loc, getValue()); - SGF.emitManagedStoreBorrow(loc, object.getValue(), temporary); - return ManagedValue::forBorrowedAddressRValue(temporary); + auto borrowedAddr = + SGF.emitManagedStoreBorrow(loc, object.getValue(), temporary); + return ManagedValue::forBorrowedAddressRValue(borrowedAddr.getValue()); +} + +ManagedValue ManagedValue::formallyMaterialize(SILGenFunction &SGF, + SILLocation loc) const { + auto temporary = SGF.emitTemporaryAllocation(loc, getType()); + bool hadCleanup = hasCleanup(); + auto &lowering = SGF.getTypeLowering(getType()); + + if (hadCleanup) { + SGF.B.emitStoreValueOperation(loc, forward(SGF), temporary, + StoreOwnershipQualifier::Init); + + return ManagedValue::forOwnedAddressRValue( + temporary, SGF.enterDestroyCleanup(temporary)); + } + if (lowering.isAddressOnly()) { + assert(!SGF.silConv.useLoweredAddresses()); + auto copy = SGF.B.createCopyValue(loc, getValue()); + SGF.B.emitStoreValueOperation(loc, copy, temporary, + StoreOwnershipQualifier::Init); + return ManagedValue::forOwnedAddressRValue( + temporary, SGF.enterDestroyCleanup(temporary)); + } + auto object = SGF.emitFormalEvaluationManagedBeginBorrow(loc, getValue()); + return SGF.emitFormalEvaluationManagedStoreBorrow(loc, object.getValue(), + temporary); } void ManagedValue::print(raw_ostream &os) const { diff --git a/lib/SILGen/ManagedValue.h b/lib/SILGen/ManagedValue.h index 9be116087b1..0d124a942d8 100644 --- a/lib/SILGen/ManagedValue.h +++ b/lib/SILGen/ManagedValue.h @@ -320,6 +320,8 @@ public: /// exact same level of cleanup it had before. ManagedValue materialize(SILGenFunction &SGF, SILLocation loc) const; + ManagedValue formallyMaterialize(SILGenFunction &SGF, SILLocation loc) const; + /// Disable the cleanup for this value. void forwardCleanup(SILGenFunction &SGF) const; diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index 2a786911c49..40a10304b9b 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -5722,7 +5722,11 @@ ArgumentSource AccessorBaseArgPreparer::prepareAccessorObjectBaseArg() { assert(!selfParam.isIndirectMutating() && "passing unmaterialized r-value as inout argument"); - base = base.materialize(SGF, loc); + base = base.formallyMaterialize(SGF, loc); + auto shouldTake = IsTake_t(base.hasCleanup()); + base = SGF.emitFormalAccessLoad(loc, base.forward(SGF), + SGF.getTypeLowering(baseLoweredType), + SGFContext(), shouldTake); } return ArgumentSource(loc, RValue(SGF, loc, baseFormalType, base)); diff --git a/lib/SILGen/SILGenBridging.cpp b/lib/SILGen/SILGenBridging.cpp index 7523df3ef80..ba1ce028514 100644 --- a/lib/SILGen/SILGenBridging.cpp +++ b/lib/SILGen/SILGenBridging.cpp @@ -154,8 +154,8 @@ emitBridgeNativeToObjectiveC(SILGenFunction &SGF, if (witnessConv.isSILIndirect(witnessConv.getParameters()[0]) && !swiftValue.getType().isAddress()) { auto tmp = SGF.emitTemporaryAllocation(loc, swiftValue.getType()); - SGF.B.createStoreBorrowOrTrivial(loc, swiftValue.borrow(SGF, loc), tmp); - swiftValue = ManagedValue::forUnmanaged(tmp); + swiftValue = SGF.emitManagedStoreBorrow( + loc, swiftValue.borrow(SGF, loc).getValue(), tmp); } // Call the witness. diff --git a/lib/SILGen/SILGenBuilder.cpp b/lib/SILGen/SILGenBuilder.cpp index 4de678a0c3e..c7efd8cebe3 100644 --- a/lib/SILGen/SILGenBuilder.cpp +++ b/lib/SILGen/SILGenBuilder.cpp @@ -721,21 +721,23 @@ createValueMetatype(SILLocation loc, SILType metatype, return ManagedValue::forUnmanaged(v); } -void SILGenBuilder::createStoreBorrow(SILLocation loc, ManagedValue value, - SILValue address) { +ManagedValue SILGenBuilder::createStoreBorrow(SILLocation loc, + ManagedValue value, + SILValue address) { assert(value.getOwnershipKind() == OwnershipKind::Guaranteed); - createStoreBorrow(loc, value.getValue(), address); + auto *sbi = createStoreBorrow(loc, value.getValue(), address); + return ManagedValue(sbi, CleanupHandle::invalid()); } -void SILGenBuilder::createStoreBorrowOrTrivial(SILLocation loc, - ManagedValue value, - SILValue address) { +ManagedValue SILGenBuilder::createStoreBorrowOrTrivial(SILLocation loc, + ManagedValue value, + SILValue address) { if (value.getOwnershipKind() == OwnershipKind::None) { createStore(loc, value, address, StoreOwnershipQualifier::Trivial); - return; + return ManagedValue(address, CleanupHandle::invalid()); } - createStoreBorrow(loc, value, address); + return createStoreBorrow(loc, value, address); } ManagedValue SILGenBuilder::createBridgeObjectToRef(SILLocation loc, diff --git a/lib/SILGen/SILGenBuilder.h b/lib/SILGen/SILGenBuilder.h index 5c18dc73b76..bdde2ada064 100644 --- a/lib/SILGen/SILGenBuilder.h +++ b/lib/SILGen/SILGenBuilder.h @@ -190,12 +190,13 @@ public: ManagedValue createFormalAccessLoadBorrow(SILLocation loc, ManagedValue base); using SILBuilder::createStoreBorrow; - void createStoreBorrow(SILLocation loc, ManagedValue value, SILValue address); + ManagedValue createStoreBorrow(SILLocation loc, ManagedValue value, + SILValue address); /// Create a store_borrow if we have a non-trivial value and a store [trivial] /// otherwise. - void createStoreBorrowOrTrivial(SILLocation loc, ManagedValue value, - SILValue address); + ManagedValue createStoreBorrowOrTrivial(SILLocation loc, ManagedValue value, + SILValue address); /// Prepares a buffer to receive the result of an expression, either using the /// 'emit into' initialization buffer if available, or allocating a temporary diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index 6584ff2ad93..f204f328a45 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -129,12 +129,13 @@ ManagedValue SILGenFunction::emitManagedStoreBorrow( assert(lowering.getLoweredType().getObjectType() == v->getType()); if (lowering.isTrivial() || v->getOwnershipKind() == OwnershipKind::None) { lowering.emitStore(B, loc, v, addr, StoreOwnershipQualifier::Trivial); - return ManagedValue::forUnmanaged(v); + return ManagedValue::forTrivialAddressRValue(addr); } assert((!lowering.isAddressOnly() || !silConv.useLoweredAddresses()) && "cannot retain an unloadable type"); auto *sbi = B.createStoreBorrow(loc, v, addr); - return emitManagedBorrowedRValueWithCleanup(sbi->getSrc(), sbi, lowering); + Cleanups.pushCleanup(sbi); + return ManagedValue(sbi, CleanupHandle::invalid()); } ManagedValue SILGenFunction::emitManagedBeginBorrow(SILLocation loc, @@ -243,6 +244,18 @@ ManagedValue SILGenFunction::emitFormalEvaluationManagedBeginBorrow( lowering); } +ManagedValue SILGenFunction::emitFormalEvaluationManagedStoreBorrow( + SILLocation loc, SILValue v, SILValue addr) { + auto &lowering = getTypeLowering(v->getType()); + if (lowering.isTrivial() || v->getOwnershipKind() == OwnershipKind::None) { + lowering.emitStore(B, loc, v, addr, StoreOwnershipQualifier::Trivial); + return ManagedValue::forTrivialAddressRValue(addr); + } + auto *sbi = B.createStoreBorrow(loc, v, addr); + return emitFormalEvaluationManagedBorrowedRValueWithCleanup(loc, v, sbi, + lowering); +} + ManagedValue SILGenFunction::emitFormalEvaluationManagedBorrowedRValueWithCleanup( SILLocation loc, SILValue original, SILValue borrowed) { @@ -260,10 +273,6 @@ SILGenFunction::emitFormalEvaluationManagedBorrowedRValueWithCleanup( if (lowering.isTrivial()) return ManagedValue::forUnmanaged(borrowed); - if (!borrowed->getType().isObject()) { - return ManagedValue(borrowed, CleanupHandle::invalid()); - } - assert(isInFormalEvaluationScope() && "Must be in formal evaluation scope"); auto &cleanup = Cleanups.pushCleanup(); CleanupHandle handle = Cleanups.getTopCleanup(); @@ -329,10 +338,7 @@ ManagedValue SILGenFunction::emitManagedBorrowedRValueWithCleanup( original->getOwnershipKind() == OwnershipKind::None) return ManagedValue::forUnmanaged(borrowed); - if (borrowed->getType().isObject()) { - Cleanups.pushCleanup(borrowed); - } - + Cleanups.pushCleanup(borrowed); return ManagedValue(borrowed, CleanupHandle::invalid()); } diff --git a/lib/SILGen/SILGenFunction.h b/lib/SILGen/SILGenFunction.h index c2aff0f73e4..f192cf553f6 100644 --- a/lib/SILGen/SILGenFunction.h +++ b/lib/SILGen/SILGenFunction.h @@ -1544,6 +1544,10 @@ public: emitFormalEvaluationManagedBeginBorrow(SILLocation loc, SILValue v, const TypeLowering &lowering); + ManagedValue emitFormalEvaluationManagedStoreBorrow(SILLocation loc, + SILValue v, + SILValue addr); + ManagedValue emitManagedRValueWithCleanup(SILValue v); ManagedValue emitManagedRValueWithCleanup(SILValue v, const TypeLowering &lowering); diff --git a/test/SIL/OwnershipVerifier/false_positive_leaks.sil b/test/SIL/OwnershipVerifier/false_positive_leaks.sil index 7f6ec934538..3a51ba37f7b 100644 --- a/test/SIL/OwnershipVerifier/false_positive_leaks.sil +++ b/test/SIL/OwnershipVerifier/false_positive_leaks.sil @@ -26,9 +26,10 @@ sil [ossa] @leak_loop_test : $@convention(thin) (@owned Builtin.NativeObject) -> bb0(%0 : @owned $Builtin.NativeObject): %1 = alloc_stack $Builtin.NativeObject %2 = begin_borrow %0 : $Builtin.NativeObject - store_borrow %2 to %1 : $*Builtin.NativeObject + %sbi = store_borrow %2 to %1 : $*Builtin.NativeObject %3 = function_ref @in_guaranteed_user : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () - apply %3(%1) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () + apply %3(%sbi) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () + end_borrow %sbi : $*Builtin.NativeObject end_borrow %2 : $Builtin.NativeObject dealloc_stack %1 : $*Builtin.NativeObject br bb1 diff --git a/test/SIL/OwnershipVerifier/interior_pointer.sil b/test/SIL/OwnershipVerifier/interior_pointer.sil index 341af147dec..6121b4a960b 100644 --- a/test/SIL/OwnershipVerifier/interior_pointer.sil +++ b/test/SIL/OwnershipVerifier/interior_pointer.sil @@ -119,8 +119,7 @@ bb0(%0 : @owned $Box, %1 : $*Int): // CHECK-NEXT: Found outside of lifetime use?! // CHECK-NEXT: Value: %1 = begin_borrow %0 : $Builtin.NativeObject // users: %4, %3 // CHECK-NEXT: Consuming User: end_borrow %1 : $Builtin.NativeObject // id: %4 -// CHECK-NEXT: Non Consuming User: %7 = apply %6(%3) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () -// CHECK-NEXT: Block: bb0 +// CHECK-NEXT: Non Consuming User: end_borrow %3 : $*Builtin.NativeObject sil [ossa] @store_borrow_result_used_outside_of_borrow_lifetime : $@convention(thin) (@owned Builtin.NativeObject) -> () { bb0(%0 : @owned $Builtin.NativeObject): %0a = begin_borrow %0 : $Builtin.NativeObject @@ -130,6 +129,7 @@ bb0(%0 : @owned $Builtin.NativeObject): destroy_value %0 : $Builtin.NativeObject %func = function_ref @use_builtinnativeobject_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () apply %func(%result) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () + end_borrow %result : $*Builtin.NativeObject dealloc_stack %1 : $*Builtin.NativeObject %9999 = tuple() return %9999 : $() diff --git a/test/SIL/OwnershipVerifier/use_verifier.sil b/test/SIL/OwnershipVerifier/use_verifier.sil index 705b02dcc92..a8e0f83aabf 100644 --- a/test/SIL/OwnershipVerifier/use_verifier.sil +++ b/test/SIL/OwnershipVerifier/use_verifier.sil @@ -127,7 +127,8 @@ bb0(%0 : @guaranteed $Builtin.NativeObject): sil [ossa] @store_borrow_result : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () { bb0(%0 : @guaranteed $Builtin.NativeObject): %1 = alloc_stack $Builtin.NativeObject - store_borrow %0 to %1 : $*Builtin.NativeObject + %sb = store_borrow %0 to %1 : $*Builtin.NativeObject + end_borrow %sb : $*Builtin.NativeObject dealloc_stack %1 : $*Builtin.NativeObject %9999 = tuple() return %9999 : $() diff --git a/test/SIL/Parser/borrow.sil b/test/SIL/Parser/borrow.sil index 9f5eddac272..fbce300ea74 100644 --- a/test/SIL/Parser/borrow.sil +++ b/test/SIL/Parser/borrow.sil @@ -10,8 +10,8 @@ import Builtin // CHECK: [[BORROWED_ARG2:%.*]] = begin_borrow [[ARG2]] // CHECK: end_borrow [[BORROWED_ARG2]] // CHECK: [[MEM:%.*]] = alloc_stack $Builtin.NativeObject -// CHECK: store_borrow [[ARG2]] to [[MEM]] : $*Builtin.NativeObject -// CHECK: end_borrow [[MEM]] : $*Builtin.NativeObject +// CHECK: [[SB:%.*]] = store_borrow [[ARG2]] to [[MEM]] : $*Builtin.NativeObject +// CHECK: end_borrow [[SB]] : $*Builtin.NativeObject // CHECK: } // end sil function 'borrow_test' sil [ossa] @borrow_test : $@convention(thin) (@in Builtin.NativeObject, @guaranteed Builtin.NativeObject) -> () { bb0(%0 : $*Builtin.NativeObject, %1 : @guaranteed $Builtin.NativeObject): @@ -19,8 +19,8 @@ bb0(%0 : $*Builtin.NativeObject, %1 : @guaranteed $Builtin.NativeObject): end_borrow %2 : $Builtin.NativeObject %3 = alloc_stack $Builtin.NativeObject - store_borrow %1 to %3 : $*Builtin.NativeObject - end_borrow %3 : $*Builtin.NativeObject + %sb = store_borrow %1 to %3 : $*Builtin.NativeObject + end_borrow %sb : $*Builtin.NativeObject dealloc_stack %3 : $*Builtin.NativeObject destroy_addr %0 : $*Builtin.NativeObject diff --git a/test/SIL/Serialization/borrow.sil b/test/SIL/Serialization/borrow.sil index 0485712b540..917a6aa9c3e 100644 --- a/test/SIL/Serialization/borrow.sil +++ b/test/SIL/Serialization/borrow.sil @@ -56,8 +56,8 @@ bb0(%0 : $*Builtin.NativeObject, %1 : @guaranteed $Builtin.NativeObject): end_borrow %2 : $Builtin.NativeObject %3 = alloc_stack $Builtin.NativeObject - store_borrow %1 to %3 : $*Builtin.NativeObject - end_borrow %3 : $*Builtin.NativeObject + %sb = store_borrow %1 to %3 : $*Builtin.NativeObject + end_borrow %sb : $*Builtin.NativeObject dealloc_stack %3 : $*Builtin.NativeObject destroy_addr %0 : $*Builtin.NativeObject %4 = tuple() diff --git a/test/SIL/memory_lifetime.sil b/test/SIL/memory_lifetime.sil index e59fccc7f7d..d4c105a194e 100644 --- a/test/SIL/memory_lifetime.sil +++ b/test/SIL/memory_lifetime.sil @@ -506,7 +506,8 @@ bb0(%0 : $*T): sil [ossa] @test_store_borrow : $@convention(thin) (@guaranteed T) -> () { bb0(%0 : @guaranteed $T): %s = alloc_stack $T - store_borrow %0 to %s : $*T + %sb = store_borrow %0 to %s : $*T + end_borrow %sb : $*T dealloc_stack %s : $*T %res = tuple () return %res : $() diff --git a/test/SIL/memory_lifetime_failures.sil b/test/SIL/memory_lifetime_failures.sil index f04d4446d60..ce868ce49c9 100644 --- a/test/SIL/memory_lifetime_failures.sil +++ b/test/SIL/memory_lifetime_failures.sil @@ -271,11 +271,12 @@ bb0(%0 : $*T): return %res : $() } -// CHECK: SIL memory lifetime failure in @test_store_borrow_destroy: memory is not initialized, but should be +// CHECK: SIL memory lifetime failure in @test_store_borrow_destroy: store-borrow location cannot be written sil [ossa] @test_store_borrow_destroy : $@convention(thin) (@guaranteed T) -> () { bb0(%0 : @guaranteed $T): %s = alloc_stack $T - store_borrow %0 to %s : $*T + %sb = store_borrow %0 to %s : $*T + end_borrow %sb : $*T destroy_addr %s : $*T dealloc_stack %s : $*T %res = tuple () @@ -284,13 +285,14 @@ bb0(%0 : @guaranteed $T): sil [ossa] @func_with_inout_param : $@convention(thin) (@inout T) -> () -// CHECK: SIL memory lifetime failure in @test_store_borrow_inout: store-borrow location cannot be written +// T-CHECK: SIL memory lifetime failure in @test_store_borrow_inout: store-borrow location cannot be written sil [ossa] @test_store_borrow_inout : $@convention(thin) (@guaranteed T) -> () { bb0(%0 : @guaranteed $T): %s = alloc_stack $T - store_borrow %0 to %s : $*T + %sb = store_borrow %0 to %s : $*T %f = function_ref @func_with_inout_param : $@convention(thin) (@inout T) -> () - %a = apply %f(%s) : $@convention(thin) (@inout T) -> () + %a = apply %f(%sb) : $@convention(thin) (@inout T) -> () + end_borrow %sb : $*T dealloc_stack %s : $*T %res = tuple () return %res : $() @@ -300,7 +302,8 @@ bb0(%0 : @guaranteed $T): sil [ossa] @test_store_borrow_store : $@convention(thin) (@guaranteed T, @owned T) -> () { bb0(%0 : @guaranteed $T, %1 : @owned $T): %s = alloc_stack $T - store_borrow %0 to %s : $*T + %sb = store_borrow %0 to %s : $*T + end_borrow %sb : $*T store %1 to [assign] %s : $*T dealloc_stack %s : $*T %res = tuple () @@ -311,7 +314,8 @@ bb0(%0 : @guaranteed $T, %1 : @owned $T): sil [ossa] @test_store_borrow_load : $@convention(thin) (@guaranteed T) -> @owned T { bb0(%0 : @guaranteed $T): %s = alloc_stack $T - store_borrow %0 to %s : $*T + %sb = store_borrow %0 to %s : $*T + end_borrow %sb : $*T %res = load [take] %s : $*T dealloc_stack %s : $*T return %res : $T @@ -321,7 +325,8 @@ bb0(%0 : @guaranteed $T): sil [ossa] @test_store_borrow_copy_src : $@convention(thin) (@guaranteed T) -> @out T { bb0(%0 : $*T, %1 : @guaranteed $T): %s = alloc_stack $T - store_borrow %1 to %s : $*T + %sb = store_borrow %1 to %s : $*T + end_borrow %sb : $*T copy_addr [take] %s to [initialization] %0 : $*T dealloc_stack %s : $*T %res = tuple () @@ -332,7 +337,8 @@ bb0(%0 : $*T, %1 : @guaranteed $T): sil [ossa] @test_store_borrow_copy_dst : $@convention(thin) (@in_guaranteed T, @guaranteed T) -> () { bb0(%0 : $*T, %1 : @guaranteed $T): %s = alloc_stack $T - store_borrow %1 to %s : $*T + %sb = store_borrow %1 to %s : $*T + end_borrow %sb : $*T copy_addr %0 to %s : $*T dealloc_stack %s : $*T %res = tuple () @@ -343,7 +349,8 @@ bb0(%0 : $*T, %1 : @guaranteed $T): sil [ossa] @test_store_borrow_init_enum : $@convention(thin) (@guaranteed Optional) -> () { bb0(%0 : @guaranteed $Optional): %s = alloc_stack $Optional - store_borrow %0 to %s : $*Optional + %sb = store_borrow %0 to %s : $*Optional + end_borrow %sb : $*Optional %ie = init_enum_data_addr %s : $*Optional, #Optional.some!enumelt dealloc_stack %s : $*Optional %res = tuple () @@ -354,8 +361,9 @@ bb0(%0 : @guaranteed $Optional): sil [ossa] @test_store_borrow_take_enum : $@convention(thin) (@guaranteed Optional) -> () { bb0(%0 : @guaranteed $Optional): %s = alloc_stack $Optional - store_borrow %0 to %s : $*Optional + %sb = store_borrow %0 to %s : $*Optional %ue = unchecked_take_enum_data_addr %s : $*Optional, #Optional.some!enumelt + end_borrow %sb : $*Optional dealloc_stack %s : $*Optional %res = tuple () return %res : $() @@ -369,7 +377,8 @@ bb0(%0 : @guaranteed $T): store %copy to [init] %stk : $*T %ld = load [take] %stk : $*T destroy_value %ld : $T - store_borrow %0 to %stk : $*T + %sb = store_borrow %0 to %stk : $*T + end_borrow %sb : $*T dealloc_stack %stk : $*T %8 = tuple () return %8 : $() @@ -385,7 +394,8 @@ bb0(%0 : @guaranteed $T): destroy_value %ld : $T br bb1 bb1: - store_borrow %0 to %stk : $*T + %sb = store_borrow %0 to %stk : $*T + end_borrow %sb : $*T dealloc_stack %stk : $*T %8 = tuple () return %8 : $() diff --git a/test/SILGen/class_bound_protocols.swift b/test/SILGen/class_bound_protocols.swift index 5e13d532fbc..d342d8bd9d1 100644 --- a/test/SILGen/class_bound_protocols.swift +++ b/test/SILGen/class_bound_protocols.swift @@ -189,10 +189,11 @@ func takesInheritsMutatingMethod(x: inout InheritsMutatingMethod, // ** pass to an in_guaranteed method. PredictableMemOpts is able to handle this // ** type of temporary codegen successfully. // CHECK-NEXT: [[TEMPORARY_2:%.*]] = alloc_stack $@opened("{{.*}}", InheritsMutatingMethod) Self - // CHECK-NEXT: store_borrow [[X_PAYLOAD_RELOADED:%.*]] to [[TEMPORARY_2]] + // CHECK-NEXT: [[SB:%.*]] = store_borrow [[X_PAYLOAD_RELOADED:%.*]] to [[TEMPORARY_2]] // // CHECK-NEXT: [[METHOD:%.*]] = witness_method $@opened("{{.*}}", InheritsMutatingMethod) Self, #HasMutatingMethod.mutatingCounter!getter : (Self) -> () -> Value, [[X_PAYLOAD]] : $@opened("{{.*}}", InheritsMutatingMethod) Self : $@convention(witness_method: HasMutatingMethod) <τ_0_0 where τ_0_0 : HasMutatingMethod> (@in_guaranteed τ_0_0) -> Value - // CHECK-NEXT: [[RESULT_VALUE:%.*]] = apply [[METHOD]]<@opened("{{.*}}", InheritsMutatingMethod) Self>([[TEMPORARY_2]]) : $@convention(witness_method: HasMutatingMethod) <τ_0_0 where τ_0_0 : HasMutatingMethod> (@in_guaranteed τ_0_0) -> Value + // CHECK-NEXT: [[RESULT_VALUE:%.*]] = apply [[METHOD]]<@opened("{{.*}}", InheritsMutatingMethod) Self>([[SB]]) : $@convention(witness_method: HasMutatingMethod) <τ_0_0 where τ_0_0 : HasMutatingMethod> (@in_guaranteed τ_0_0) -> Value + // CHECK-NEXT: end_borrow [[SB]] // CHECK-NEXT: dealloc_stack [[TEMPORARY_2]] // CHECK-NEXT: end_borrow // CHECK-NEXT: destroy_addr diff --git a/test/SILGen/copy_operator.swift b/test/SILGen/copy_operator.swift index 77260e1aeeb..2fff7423f4d 100644 --- a/test/SILGen/copy_operator.swift +++ b/test/SILGen/copy_operator.swift @@ -24,10 +24,11 @@ class Klass {} // CHECK-NEXT: debug_value // CHECK-NEXT: [[RESULT_ADDR:%.*]] = alloc_stack $Klass // CHECK-NEXT: [[INPUT_ADDR:%.*]] = alloc_stack $Klass -// CHECK-NEXT: store_borrow [[ARG]] to [[INPUT_ADDR]] +// CHECK-NEXT: [[SB:%.*]] = store_borrow [[ARG]] to [[INPUT_ADDR]] // CHECK-NEXT: // function_ref _copy(_:) // CHECK-NEXT: [[COPY:%.*]] = function_ref @$ss5_copyyxxlF : -// CHECK-NEXT: [[APPLY_RESULT:%.*]] = apply [[COPY]]([[RESULT_ADDR]], [[INPUT_ADDR]]) +// CHECK-NEXT: [[APPLY_RESULT:%.*]] = apply [[COPY]]([[RESULT_ADDR]], [[SB]]) +// CHECK-NEXT: end_borrow // CHECK-NEXT: dealloc_stack [[INPUT_ADDR]] // CHECK-NEXT: [[RELOADED_VALUE:%.*]] = load [take] [[RESULT_ADDR]] // CHECK-NEXT: dealloc_stack [[RESULT_ADDR]] @@ -65,10 +66,11 @@ public func useCopy(_ k: Klass) -> Klass { // CHECK-NEXT: debug_value // CHECK-NEXT: [[RESULT_ADDR:%.*]] = alloc_stack $T // CHECK-NEXT: [[INPUT_ADDR:%.*]] = alloc_stack $T -// CHECK-NEXT: store_borrow [[ARG]] to [[INPUT_ADDR]] +// CHECK-NEXT: [[SB:%.*]] = store_borrow [[ARG]] to [[INPUT_ADDR]] // CHECK-NEXT: // function_ref _copy(_:) // CHECK-NEXT: [[COPY:%.*]] = function_ref @$ss5_copyyxxlF : -// CHECK-NEXT: [[APPLY_RESULT:%.*]] = apply [[COPY]]([[RESULT_ADDR]], [[INPUT_ADDR]]) +// CHECK-NEXT: [[APPLY_RESULT:%.*]] = apply [[COPY]]([[RESULT_ADDR]], [[SB]]) +// CHECK-NEXT: end_borrow // CHECK-NEXT: dealloc_stack [[INPUT_ADDR]] // CHECK-NEXT: [[RELOADED_VALUE:%.*]] = load [take] [[RESULT_ADDR]] // CHECK-NEXT: dealloc_stack [[RESULT_ADDR]] diff --git a/test/SILGen/lexical_lifetime.swift b/test/SILGen/lexical_lifetime.swift index 812c42e2e38..94543f6abef 100644 --- a/test/SILGen/lexical_lifetime.swift +++ b/test/SILGen/lexical_lifetime.swift @@ -91,9 +91,9 @@ func lexical_borrow_let_class_in_enum() { // CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [lexical] [[INSTANCE]] // CHECK: debug_value [[LIFETIME]] // CHECK: [[ADDR:%[^,]+]] = alloc_stack $C -// CHECK: store_borrow [[LIFETIME]] to [[ADDR]] +// CHECK: [[SB:%.*]] = store_borrow [[LIFETIME]] to [[ADDR]] // CHECK: [[USE_GENERIC:%[^,]+]] = function_ref @use_generic -// CHECK: [[REGISTER_6:%[^,]+]] = apply [[USE_GENERIC]]([[ADDR]]) +// CHECK: [[REGISTER_6:%[^,]+]] = apply [[USE_GENERIC]]([[SB]]) // CHECK: dealloc_stack [[ADDR]] // CHECK: end_borrow [[LIFETIME]] // CHECK: [[RETVAL:%[^,]+]] = tuple () diff --git a/test/SILGen/objc_bridging_any.swift b/test/SILGen/objc_bridging_any.swift index 609db861364..e44a5b4373f 100644 --- a/test/SILGen/objc_bridging_any.swift +++ b/test/SILGen/objc_bridging_any.swift @@ -151,8 +151,8 @@ func passingToId(receiver: NSIdLover, // CHECK: [[BRIDGE_OPTIONAL:%.*]] = function_ref @$sSq19_bridgeToObjectiveCyXlyF // CHECK: [[TMP:%.*]] = alloc_stack $Optional // CHECK: [[BORROWED_OPT_STRING_COPY:%.*]] = begin_borrow [[OPT_STRING_COPY]] - // CHECK: store_borrow [[BORROWED_OPT_STRING_COPY]] to [[TMP]] - // CHECK: [[ANYOBJECT:%.*]] = apply [[BRIDGE_OPTIONAL]]([[TMP]]) + // CHECK: [[SB1:%.*]] = store_borrow [[BORROWED_OPT_STRING_COPY]] to [[TMP]] + // CHECK: [[ANYOBJECT:%.*]] = apply [[BRIDGE_OPTIONAL]]([[SB1]]) // CHECK: end_borrow [[BORROWED_OPT_STRING_COPY]] // CHECK: [[METHOD:%.*]] = objc_method [[SELF]] : $NSIdLover, // CHECK: apply [[METHOD]]([[ANYOBJECT]], [[SELF]]) @@ -162,8 +162,8 @@ func passingToId(receiver: NSIdLover, // CHECK: [[BRIDGE_OPTIONAL:%.*]] = function_ref @$sSq19_bridgeToObjectiveCyXlyF // CHECK: [[TMP:%.*]] = alloc_stack $Optional // CHECK: [[BORROWED_OPT_NSSTRING_COPY:%.*]] = begin_borrow [[OPT_NSSTRING_COPY]] - // CHECK: store_borrow [[BORROWED_OPT_NSSTRING_COPY]] to [[TMP]] - // CHECK: [[ANYOBJECT:%.*]] = apply [[BRIDGE_OPTIONAL]]([[TMP]]) + // CHECK: [[SB2:%.*]] = store_borrow [[BORROWED_OPT_NSSTRING_COPY]] to [[TMP]] + // CHECK: [[ANYOBJECT:%.*]] = apply [[BRIDGE_OPTIONAL]]([[SB2]]) // CHECK: end_borrow [[BORROWED_OPT_NSSTRING_COPY]] // CHECK: [[METHOD:%.*]] = objc_method [[SELF]] : $NSIdLover, // CHECK: apply [[METHOD]]([[ANYOBJECT]], [[SELF]]) @@ -668,7 +668,8 @@ class AnyHashableClass : NSObject { // CHECK: [[FN:%.*]] = function_ref @$sIeg_ytIegr_TR // CHECK: partial_apply [callee_guaranteed] [[FN]] // CHECK: [[SELF:%.*]] = alloc_stack $Optional<@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>> -// CHECK: apply [[BRIDGE]]<() -> ()>([[SELF]]) +// CHECK: [[SB:%.*]] = store_borrow {{.*}} to [[SELF]] +// CHECK: apply [[BRIDGE]]<() -> ()>([[SB]]) func bridgeOptionalFunctionToAnyObject(fn: (() -> ())?) -> AnyObject { return fn as AnyObject } diff --git a/test/SILGen/objc_bridging_peephole.swift b/test/SILGen/objc_bridging_peephole.swift index 5da6d358d43..a5d933373e1 100644 --- a/test/SILGen/objc_bridging_peephole.swift +++ b/test/SILGen/objc_bridging_peephole.swift @@ -118,8 +118,8 @@ func testForcedMethodResult(dummy: DummyClass) { // CHECK: [[BRIDGE:%.*]] = function_ref @$sSq19_bridgeToObjectiveCyXlyF // CHECK-NEXT: [[TEMP:%.*]] = alloc_stack $Optional // CHECK-NEXT: [[BORROW:%.*]] = begin_borrow [[OPTSTRING]] - // CHECK-NEXT: store_borrow [[BORROW]] to [[TEMP]] : $*Optional - // CHECK-NEXT: [[ANYOBJECT:%.*]] = apply [[BRIDGE]]([[TEMP]]) + // CHECK-NEXT: [[SB:%.*]] = store_borrow [[BORROW]] to [[TEMP]] : $*Optional + // CHECK-NEXT: [[ANYOBJECT:%.*]] = apply [[BRIDGE]]([[SB]]) // CHECK: [[USE:%.*]] = function_ref @$s22objc_bridging_peephole12useAnyObjectyyyXlF // CHECK: apply [[USE]]([[ANYOBJECT]]) useAnyObject(dummy.fetchNullproneString() as AnyObject) @@ -227,8 +227,8 @@ func testForcedPropertyValue(dummy: DummyClass) { // CHECK: [[BRIDGE:%.*]] = function_ref @$sSq19_bridgeToObjectiveCyXlyF // CHECK-NEXT: [[TEMP:%.*]] = alloc_stack $Optional // CHECK-NEXT: [[BORROW:%.*]] = begin_borrow [[OPTSTRING]] - // CHECK-NEXT: store_borrow [[BORROW]] to [[TEMP]] : $*Optional - // CHECK-NEXT: [[ANYOBJECT:%.*]] = apply [[BRIDGE]]([[TEMP]]) + // CHECK-NEXT: [[SB:%.*]] = store_borrow [[BORROW]] to [[TEMP]] : $*Optional + // CHECK-NEXT: [[ANYOBJECT:%.*]] = apply [[BRIDGE]]([[SB]]) // CHECK: dealloc_stack [[TEMP]] // CHECK: [[USE:%.*]] = function_ref @$s22objc_bridging_peephole12useAnyObjectyyyXlF // CHECK-NEXT: apply [[USE]]([[ANYOBJECT]]) diff --git a/test/SILGen/partial_apply_protocol_class_refinement_method.swift b/test/SILGen/partial_apply_protocol_class_refinement_method.swift index 2201676a7e6..fea78c1cff3 100644 --- a/test/SILGen/partial_apply_protocol_class_refinement_method.swift +++ b/test/SILGen/partial_apply_protocol_class_refinement_method.swift @@ -9,8 +9,9 @@ protocol Q: class, P {} func partialApply(_ q: Q) -> () -> () { // CHECK: [[OPENED:%.*]] = open_existential_ref [[ARG]] // CHECK: [[TMP:%.*]] = alloc_stack - // CHECK: store_borrow [[OPENED]] to [[TMP:%.*]] : - // CHECK: apply {{%.*}}<{{.*}}>([[TMP]]) + // CHECK: [[SB:%.*]] = store_borrow [[OPENED]] to [[TMP:%.*]] : + // CHECK: apply {{%.*}}<{{.*}}>([[SB]]) + // CHECK: end_borrow // CHECK-NEXT: dealloc_stack [[TMP]] return q.foo } diff --git a/test/SILGen/protocol_extensions.swift b/test/SILGen/protocol_extensions.swift index 670b41bc4aa..eb18b54b392 100644 --- a/test/SILGen/protocol_extensions.swift +++ b/test/SILGen/protocol_extensions.swift @@ -103,9 +103,10 @@ func testD(_ m: MetaHolder, dd: D.Type, d: D) { // CHECK: [[D2L:%[0-9]+]] = begin_borrow [lexical] [[D2]] // CHECK: [[RESULT:%.*]] = project_box [[D2L]] // CHECK: [[MATERIALIZED_BORROWED_D:%[0-9]+]] = alloc_stack $D - // CHECK: store_borrow [[D]] to [[MATERIALIZED_BORROWED_D]] + // CHECK: [[SB:%.*]] = store_borrow [[D]] to [[MATERIALIZED_BORROWED_D]] // CHECK: [[FN:%[0-9]+]] = function_ref @$s19protocol_extensions2P1PAAE11returnsSelf{{[_0-9a-zA-Z]*}}F - // CHECK: apply [[FN]]([[RESULT]], [[MATERIALIZED_BORROWED_D]]) : $@convention(method) <τ_0_0 where τ_0_0 : P1> (@in_guaranteed τ_0_0) -> @out τ_0_0 + // CHECK: apply [[FN]]([[RESULT]], [[SB]]) : $@convention(method) <τ_0_0 where τ_0_0 : P1> (@in_guaranteed τ_0_0) -> @out τ_0_0 + // CHECK: end_borrow // CHECK-NEXT: dealloc_stack [[MATERIALIZED_BORROWED_D]] var d2: D = d.returnsSelf() diff --git a/test/SILGen/subclass_existentials.swift b/test/SILGen/subclass_existentials.swift index 02c66300fa6..3d39fdb7f30 100644 --- a/test/SILGen/subclass_existentials.swift +++ b/test/SILGen/subclass_existentials.swift @@ -129,12 +129,13 @@ func methodCalls( // CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[ARG0]] : $Base & P to $@opened("{{.*}}", Base & P) Self // CHECK: [[SELF_BOX:%.*]] = alloc_stack $@opened("{{.*}}", Base & P) Self - // CHECK: store_borrow [[PAYLOAD]] to [[SELF_BOX]] : $*@opened("{{.*}}", Base & P) Self + // CHECK: [[SB:%.*]] = store_borrow [[PAYLOAD]] to [[SELF_BOX]] : $*@opened("{{.*}}", Base & P) Self // CHECK: [[METHOD:%.*]] = witness_method $@opened("{{.*}}", Base & P) Self, #P.protocolSelfReturn : (Self) -> () -> Self, [[PAYLOAD]] : $@opened("{{.*}}", Base & P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0 // CHECK: [[RESULT_BOX:%.*]] = alloc_box // CHECK: [[RESULT_LIFETIME:%[^,]+]] = begin_borrow [lexical] [[RESULT_BOX]] // CHECK: [[RESULT_BUF:%.*]] = project_box [[RESULT_LIFETIME]] - // CHECK: apply [[METHOD]]<@opened("{{.*}}", Base & P) Self>([[RESULT_BUF]], [[SELF_BOX]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0 + // CHECK: apply [[METHOD]]<@opened("{{.*}}", Base & P) Self>([[RESULT_BUF]], [[SB]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0 + // end_borrow [[SB]] // CHECK: dealloc_stack [[SELF_BOX]] : $*@opened("{{.*}}", Base & P) Self // CHECK: [[RESULT_REF:%.*]] = load [take] [[RESULT_BUF]] : $*@opened("{{.*}}", Base & P) Self // CHECK: [[RESULT:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}", Base & P) Self : $@opened("{{.*}}", Base & P) Self, $Base & P diff --git a/test/SILGen/switch_var.swift b/test/SILGen/switch_var.swift index 2256841ac6e..7de48efd061 100644 --- a/test/SILGen/switch_var.swift +++ b/test/SILGen/switch_var.swift @@ -472,8 +472,8 @@ func test_let() { // CHECK: [[VAL_COPY_3:%.*]] = copy_value [[BORROWED_VAL_3]] // CHECK: [[BORROWED_VAL_COPY_3:%.*]] = begin_borrow [lexical] [[VAL_COPY_3]] // CHECK: function_ref @$s10switch_var4barsSSyF - // CHECK: store_borrow [[BORROWED_VAL_COPY_3]] to [[IN_ARG:%.*]] : - // CHECK: apply {{%.*}}({{.*}}, [[IN_ARG]]) + // CHECK: [[SB:%.*]] = store_borrow [[BORROWED_VAL_COPY_3]] to [[IN_ARG:%.*]] : + // CHECK: apply {{%.*}}({{.*}}, [[SB]]) // CHECK: cond_br {{%.*}}, [[YES_CASE3:bb[0-9]+]], [[NO_CASE3:bb[0-9]+]] // ExprPatterns implicitly contain a 'let' binding. case bars(): @@ -548,8 +548,8 @@ func test_mixed_let_var() { // CHECK: [[BORROWED_VAL:%.*]] = begin_borrow [[VAL]] // CHECK: [[VAL_COPY:%.*]] = copy_value [[BORROWED_VAL]] // CHECK: [[BORROWED_VAL_COPY:%.*]] = begin_borrow [lexical] [[VAL_COPY]] - // CHECK: store_borrow [[BORROWED_VAL_COPY]] to [[TMP_VAL_COPY_ADDR:%.*]] : - // CHECK: apply {{.*}}({{.*}}, [[TMP_VAL_COPY_ADDR]]) + // CHECK: [[SB:%.*]] = store_borrow [[BORROWED_VAL_COPY]] to [[TMP_VAL_COPY_ADDR:%.*]] : + // CHECK: apply {{.*}}({{.*}}, [[SB]]) // CHECK: cond_br {{.*}}, [[CASE3:bb[0-9]+]], [[NOCASE3:bb[0-9]+]] case bars(): // CHECK: [[CASE3]]: diff --git a/test/SILOptimizer/OSLogMandatoryOptTest.sil b/test/SILOptimizer/OSLogMandatoryOptTest.sil index 1b7215cd050..adcd8d1df7b 100644 --- a/test/SILOptimizer/OSLogMandatoryOptTest.sil +++ b/test/SILOptimizer/OSLogMandatoryOptTest.sil @@ -89,9 +89,10 @@ bb0: %9 = struct_extract %8 : $OSLogMessageStub, #OSLogMessageStub.interpolation %10 = struct_extract %9 : $OSLogInterpolationStub, #OSLogInterpolationStub.formatString %11 = alloc_stack $String - store_borrow %10 to %11 : $*String + %12 = store_borrow %10 to %11 : $*String %13 = function_ref @useFormatStringIndirect : $@convention(thin) (@in_guaranteed String) -> () - %14 = apply %13(%11) : $@convention(thin) (@in_guaranteed String) -> () + %14 = apply %13(%12) : $@convention(thin) (@in_guaranteed String) -> () + end_borrow %12 : $*String end_borrow %8 : $OSLogMessageStub destroy_value %7 : $OSLogMessageStub dealloc_stack %11 : $*String diff --git a/test/SILOptimizer/OSLogMandatoryOptTest.swift b/test/SILOptimizer/OSLogMandatoryOptTest.swift index 3503f3bf943..2642a99a77e 100644 --- a/test/SILOptimizer/OSLogMandatoryOptTest.swift +++ b/test/SILOptimizer/OSLogMandatoryOptTest.swift @@ -45,8 +45,8 @@ func testSimpleInterpolation() { // the array which is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // We need to wade through some borrows and copy values here. // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] @@ -92,8 +92,8 @@ func testInterpolationWithFormatOptions() { // the array which is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] @@ -140,8 +140,8 @@ func testInterpolationWithFormatOptionsAndPrivacy() { // the array which is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] @@ -194,8 +194,9 @@ func testInterpolationWithMultipleArguments() { // the array which is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] + // CHECK-DAG: [[ARGSARRAYADDR]] = alloc_stack $Array<(inout UnsafeMutablePointer, inout Optional>, inout Optional>) -> ()> // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] @@ -244,8 +245,8 @@ func testLogMessageWithoutData() { // Check whether argument array is folded. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to {{.*}} // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[ARGSARRAY:%[0-9]+]] @@ -317,8 +318,8 @@ func testMessageWithTooManyArguments() { // Check whether argument array is folded. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] @@ -402,8 +403,8 @@ func testDynamicStringArguments() { // the array which is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] @@ -455,8 +456,8 @@ func testNSObjectInterpolation() { // the array which is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] @@ -503,8 +504,8 @@ func testDoubleInterpolation() { // not checked here, but is checked by a different test suite. // CHECK-DAG: [[FOREACH:%[0-9]+]] = function_ref @$sSTsE7forEachyyy7ElementQzKXEKF - // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[ARGSARRAYADDR:%[0-9]+]]) - // CHECK-DAG: store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR]] + // CHECK-DAG: try_apply [[FOREACH]], inout Optional>, inout Optional>) -> ()>>({{%.*}}, [[SB:%[0-9]+]]) + // CHECK-DAG: [[SB]] = store_borrow [[ARGSARRAY2:%[0-9]+]] to [[ARGSARRAYADDR:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY2]] = begin_borrow [[ARGSARRAY3:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY3]] = copy_value [[ARGSARRAY4:%[0-9]+]] // CHECK-DAG: [[ARGSARRAY4]] = begin_borrow [[FINARR:%[0-9]+]] diff --git a/test/SILOptimizer/dead_code_elimination_ossa.sil b/test/SILOptimizer/dead_code_elimination_ossa.sil index 4c3662b53e6..dd5b9a5e1ce 100644 --- a/test/SILOptimizer/dead_code_elimination_ossa.sil +++ b/test/SILOptimizer/dead_code_elimination_ossa.sil @@ -353,9 +353,10 @@ bb0(%0 : @guaranteed $S): debug_value %0 : $S, let, name "self", argno 1 %2 = alloc_stack $S %3 = store_borrow %0 to %2 : $*S - %4 = load_borrow %2 : $*S + %4 = load_borrow %3 : $*S fix_lifetime %4 : $S end_borrow %4 : $S + end_borrow %3 : $*S dealloc_stack %2 : $*S %8 = tuple () return %8 : $() diff --git a/test/SILOptimizer/existential_transform_extras_ossa.sil b/test/SILOptimizer/existential_transform_extras_ossa.sil index 0df506afed6..51b1ab9a24f 100644 --- a/test/SILOptimizer/existential_transform_extras_ossa.sil +++ b/test/SILOptimizer/existential_transform_extras_ossa.sil @@ -295,7 +295,8 @@ bb0(%0 : @guaranteed $Klass3 & P): %3 = alloc_stack $@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self %4 = store_borrow %2 to %3 : $*@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self %5 = witness_method $@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self, #P.foo : (Self) -> () -> Int32, %2 : $@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int32 - %6 = apply %5<@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self>(%3) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int32 + %6 = apply %5<@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self>(%4) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int32 + end_borrow %4 : $*@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self dealloc_stack %3 : $*@opened("77949BFA-77BC-11EB-BC0E-F2189810406F", Klass3 & P) Self return %6 : $Int32 } diff --git a/test/SILOptimizer/for_each_loop_unroll_test.sil b/test/SILOptimizer/for_each_loop_unroll_test.sil index 313789f6702..2580aa9faf0 100644 --- a/test/SILOptimizer/for_each_loop_unroll_test.sil +++ b/test/SILOptimizer/for_each_loop_unroll_test.sil @@ -33,9 +33,10 @@ bb0: %26 = thin_to_thick_function %25 : $@convention(thin) @noescape (@in_guaranteed Builtin.Int64) -> @error Error to $@noescape @callee_guaranteed (@in_guaranteed Builtin.Int64) -> @error Error // A stub for Sequence.forEach(_:) %30 = function_ref @forEach : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error - try_apply %30<[Builtin.Int64]>(%26, %22) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 + try_apply %30<[Builtin.Int64]>(%26, %23) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 bb1(%32 : $()): + end_borrow %23 : $*Array dealloc_stack %22 : $*Array end_borrow %21 : $Array destroy_value %3 : $Array @@ -95,9 +96,10 @@ bb0(%0: @owned $@callee_guaranteed @substituted () -> @out A for , %1: %26 = thin_to_thick_function %25 : $@convention(thin) @noescape (@in_guaranteed @callee_guaranteed @substituted () -> @out A for ) -> @error Error to $@noescape @callee_guaranteed (@in_guaranteed @callee_guaranteed @substituted () -> @out A for ) -> @error Error // A stub for Sequence.forEach(_:) %30 = function_ref @forEach : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error - try_apply %30<[() -> Int]>(%26, %22) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 + try_apply %30<[() -> Int]>(%26, %23) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 bb1(%32 : $()): + end_borrow %23 : $*Array<() -> Int> dealloc_stack %22 : $*Array<() -> Int> end_borrow %21 : $Array<() -> Int> destroy_value %5 : $Array<() -> Int> @@ -163,14 +165,16 @@ bb0: %26 = thin_to_thick_function %25 : $@convention(thin) @noescape (@in_guaranteed Builtin.Int64) -> @error Error to $@noescape @callee_guaranteed (@in_guaranteed Builtin.Int64) -> @error Error // A stub for Sequence.forEach(_:) %30 = function_ref @forEach : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error - try_apply %30<[Builtin.Int64]>(%26, %22) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 + try_apply %30<[Builtin.Int64]>(%26, %23) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2 bb1(%32 : $()): + end_borrow %23 : $*Array // An indirect fixLifetime use dealloc_stack %22 : $*Array %33 = alloc_stack $Array %34 = store_borrow %21 to %33 : $*Array - fix_lifetime %33 : $*Array + fix_lifetime %34 : $*Array + end_borrow %34 : $*Array dealloc_stack %33 : $*Array end_borrow %21 : $Array destroy_value %3 : $Array @@ -207,9 +211,10 @@ bb2(%arg2 : $Builtin.Int64): %26 = thin_to_thick_function %25 : $@convention(thin) @noescape (@in_guaranteed Builtin.Int64) -> @error Error to $@noescape @callee_guaranteed (@in_guaranteed Builtin.Int64) -> @error Error // A stub for Sequence.forEach(_:) %30 = function_ref @forEach : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error - try_apply %30<[Builtin.Int64]>(%26, %22) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb3, error bb4 + try_apply %30<[Builtin.Int64]>(%26, %23) : $@convention(method) <τ_0_0 where τ_0_0 : Sequence> (@noescape @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @error Error, @in_guaranteed τ_0_0) -> @error Error, normal bb3, error bb4 bb3(%32 : $()): + end_borrow %23 : $*Array dealloc_stack %22 : $*Array end_borrow %21 : $Array destroy_value %13 : $Array diff --git a/test/SILOptimizer/mandatory_inlining_ossa_to_non_ossa.sil b/test/SILOptimizer/mandatory_inlining_ossa_to_non_ossa.sil index 4711909b0b6..0d38e6d96b0 100644 --- a/test/SILOptimizer/mandatory_inlining_ossa_to_non_ossa.sil +++ b/test/SILOptimizer/mandatory_inlining_ossa_to_non_ossa.sil @@ -28,10 +28,11 @@ sil [ossa] [transparent] @load_store_borrow_ossa_callee : $@convention(thin) (@o bb0(%0 : @owned $Builtin.NativeObject): %1 = begin_borrow %0 : $Builtin.NativeObject %2 = alloc_stack $Builtin.NativeObject - store_borrow %1 to %2 : $*Builtin.NativeObject - end_borrow %1 : $Builtin.NativeObject + %sb = store_borrow %1 to %2 : $*Builtin.NativeObject %f = function_ref @in_guaranteed_user : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () - apply %f(%2) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () + apply %f(%sb) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () + end_borrow %sb : $*Builtin.NativeObject + end_borrow %1 : $Builtin.NativeObject dealloc_stack %2 : $*Builtin.NativeObject %3 = alloc_stack $Builtin.NativeObject diff --git a/test/SILOptimizer/mem2reg_borrows.sil b/test/SILOptimizer/mem2reg_borrows.sil index 39f2648a952..35310a76abe 100644 --- a/test/SILOptimizer/mem2reg_borrows.sil +++ b/test/SILOptimizer/mem2reg_borrows.sil @@ -103,12 +103,13 @@ bb0(%0 : @owned $Klass): sil [ossa] @test_with_structs_and_borrows1 : $@convention(thin) (@guaranteed WrapperStruct) -> () { bb0(%0 : @guaranteed $WrapperStruct): %stk = alloc_stack $WrapperStruct - store_borrow %0 to %stk : $*WrapperStruct - %ele = struct_element_addr %stk : $*WrapperStruct, #WrapperStruct.val + %sb = store_borrow %0 to %stk : $*WrapperStruct + %ele = struct_element_addr %sb : $*WrapperStruct, #WrapperStruct.val %ld = load_borrow %ele : $*Klass %f = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () apply %f(%ld) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %ld : $Klass + end_borrow %sb : $*WrapperStruct dealloc_stack %stk : $*WrapperStruct %r = tuple () return %r : $() @@ -119,7 +120,8 @@ bb0(%0 : @guaranteed $WrapperStruct): sil [ossa] @store_only_allocas : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %1 = alloc_stack $Klass - store_borrow %0 to %1 : $*Klass + %2 = store_borrow %0 to %1 : $*Klass + end_borrow %2 : $*Klass dealloc_stack %1 : $*Klass %6 = tuple () return %6 : $() @@ -131,7 +133,8 @@ bb0(%0 : @guaranteed $Klass): sil [ossa] @store_only_lexicalallocas : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %1 = alloc_stack [lexical] $Klass - store_borrow %0 to %1 : $*Klass + %2 = store_borrow %0 to %1 : $*Klass + end_borrow %2 : $*Klass dealloc_stack %1 : $*Klass %6 = tuple () return %6 : $() @@ -143,11 +146,12 @@ bb0(%0 : @guaranteed $Klass): sil [ossa] @test1 : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %1 = alloc_stack $Klass - store_borrow %0 to %1 : $*Klass - %2 = load_borrow %1 : $*Klass + %sb = store_borrow %0 to %1 : $*Klass + %2 = load_borrow %sb : $*Klass %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %2 : $Klass + end_borrow %sb : $*Klass dealloc_stack %1 : $*Klass %6 = tuple () return %6 : $() @@ -159,11 +163,12 @@ bb0(%0 : @guaranteed $Klass): sil [ossa] @test1_lexical : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %1 = alloc_stack [lexical] $Klass - store_borrow %0 to %1 : $*Klass - %2 = load_borrow %1 : $*Klass + %sb = store_borrow %0 to %1 : $*Klass + %2 = load_borrow %sb : $*Klass %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %2 : $Klass + end_borrow %sb : $*Klass dealloc_stack %1 : $*Klass %6 = tuple () return %6 : $() @@ -175,15 +180,16 @@ bb0(%0 : @guaranteed $Klass): sil [ossa] @test2 : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %1 = alloc_stack $Klass - store_borrow %0 to %1 : $*Klass - %2 = load_borrow %1 : $*Klass + %sb = store_borrow %0 to %1 : $*Klass + %2 = load_borrow %sb : $*Klass %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %2 : $Klass - %5 = load_borrow %1 : $*Klass + %5 = load_borrow %sb : $*Klass %6 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %7 = apply %3(%5) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %5 : $Klass + end_borrow %sb : $*Klass dealloc_stack %1 : $*Klass %8 = tuple () return %8 : $() @@ -195,15 +201,17 @@ bb0(%0 : @guaranteed $Klass): sil [ossa] @test3 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass): %2 = alloc_stack $Klass - store_borrow %0 to %2 : $*Klass - %3 = load_borrow %2 : $*Klass + %sb1 = store_borrow %0 to %2 : $*Klass + %3 = load_borrow %sb1 : $*Klass %4 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %5 = apply %4(%3) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %3 : $Klass - store_borrow %1 to %2 : $*Klass - %6 = load_borrow %2 : $*Klass + end_borrow %sb1 : $*Klass + %sb2 = store_borrow %1 to %2 : $*Klass + %6 = load_borrow %sb2 : $*Klass %7 = apply %4(%6) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %6 : $Klass + end_borrow %sb2 : $*Klass dealloc_stack %2 : $*Klass %9 = tuple () return %9 : $() @@ -215,14 +223,15 @@ bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass): sil [ossa] @test4 : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %1 = alloc_stack $Klass - store_borrow %0 to %1 : $*Klass - %2 = load_borrow %1 : $*Klass + %sb = store_borrow %0 to %1 : $*Klass + %2 = load_borrow %sb: $*Klass %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %2 : $Klass - %5 = load [copy] %1 : $*Klass + %5 = load [copy] %sb : $*Klass %6 = function_ref @use_owned : $@convention(thin) (@owned Klass) -> () %7 = apply %6(%5) : $@convention(thin) (@owned Klass) -> () + end_borrow %sb : $*Klass dealloc_stack %1 : $*Klass %8 = tuple () return %8 : $() @@ -235,135 +244,47 @@ sil [ossa] @test6 : $@convention(thin) (@owned Klass) -> () { bb0(%0 : @owned $Klass): %1 = alloc_stack $Klass %b = begin_borrow %0 : $Klass - store_borrow %b to %1 : $*Klass - end_borrow %b : $Klass - %2 = load_borrow %1 : $*Klass + %sb = store_borrow %b to %1 : $*Klass + %2 = load_borrow %sb : $*Klass %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %2 : $Klass + end_borrow %sb : $*Klass + end_borrow %b : $Klass destroy_value %0 : $Klass dealloc_stack %1 : $*Klass %6 = tuple () return %6 : $() } -// Following tests are not optimized because multi block alloc with store_borrows is not handled in mem2reg -sil [ossa] @test_control_flow1 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () { -bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass): - %stk = alloc_stack $Klass - cond_br undef, bb1, bb2 - -bb1: - store_borrow %0 to %stk : $*Klass - br bb3 - -bb2: - store_borrow %1 to %stk : $*Klass - br bb3 - -bb3: - %2 = load_borrow %stk : $*Klass - %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () - %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () - end_borrow %2 : $Klass - dealloc_stack %stk : $*Klass - %8 = tuple () - return %8 : $() -} - -sil [ossa] @test_control_flow2 : $@convention(thin) (@owned Klass, @owned Klass) -> () { -bb0(%0 : @owned $Klass, %1 : @owned $Klass): - %stk = alloc_stack $Klass - cond_br undef, bb1, bb2 - -bb1: - %b1 = begin_borrow %0 : $Klass - store_borrow %b1 to %stk : $*Klass - end_borrow %b1 : $Klass - br bb3 - -bb2: - %b2 = begin_borrow %1 : $Klass - store_borrow %b2 to %stk : $*Klass - end_borrow %b2 : $Klass - br bb3 - -bb3: - %2 = load_borrow %stk : $*Klass - %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () - %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () - end_borrow %2 : $Klass - destroy_value %0 : $Klass - destroy_value %1 : $Klass - dealloc_stack %stk : $*Klass - %8 = tuple () - return %8 : $() -} - -sil [ossa] @test_control_flow3 : $@convention(thin) (@owned Klass, @owned Klass) -> () { -bb0(%0 : @owned $Klass, %1 : @owned $Klass): - %stk = alloc_stack $Klass - cond_br undef, bb1, bb2 - -bb1: - %b1 = begin_borrow %0 : $Klass - store_borrow %b1 to %stk : $*Klass - end_borrow %b1 : $Klass - br bb3 - -bb2: - %b2 = begin_borrow %1 : $Klass - store_borrow %b2 to %stk : $*Klass - end_borrow %b2 : $Klass - br bb3 - -bb3: - cond_br undef, bb4, bb5 - -bb4: - %2 = load_borrow %stk : $*Klass - %3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> () - %4 = apply %3(%2) : $@convention(thin) (@guaranteed Klass) -> () - end_borrow %2 : $Klass - br bb6 - -bb5: - br bb6 - -bb6: - destroy_value %0 : $Klass - destroy_value %1 : $Klass - dealloc_stack %stk : $*Klass - %8 = tuple () - return %8 : $() -} - -sil [ossa] @test_control_flow4 : $@convention(thin) (@guaranteed Klass) -> () { +sil [ossa] @test_control_flow1 : $@convention(thin) (@guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass): %stk = alloc_stack $Klass - store_borrow %0 to %stk : $*Klass + %sb = store_borrow %0 to %stk : $*Klass cond_br undef, bb1, bb2 bb1: - %ld1 = load_borrow %stk : $*Klass + %ld1 = load_borrow %sb : $*Klass fix_lifetime %ld1 : $Klass end_borrow %ld1 : $Klass + end_borrow %sb : $*Klass dealloc_stack %stk : $*Klass %r = tuple () return %r : $() bb2: - %ld2 = load_borrow %stk : $*Klass + %ld2 = load_borrow %sb : $*Klass fix_lifetime %ld2 : $Klass end_borrow %ld2 : $Klass + end_borrow %sb : $*Klass dealloc_stack %stk : $*Klass unreachable } -// CHECK-LABEL: sil [ossa] @test_control_flow5 : +// CHECK-LABEL: sil [ossa] @test_control_flow2 : // CHECK-NOT: alloc_stack -// CHECK-LABEL: } // end sil function 'test_control_flow5' -sil [ossa] @test_control_flow5 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () { +// CHECK-LABEL: } // end sil function 'test_control_flow2' +sil [ossa] @test_control_flow2 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass): %stk = alloc_stack $Klass cond_br undef, bb1, bb2 @@ -389,10 +310,10 @@ bb3: return %8 : $() } -// CHECK-LABEL: sil [ossa] @test_control_flow6 : +// CHECK-LABEL: sil [ossa] @test_control_flow3 : // CHECK-NOT: alloc_stack -// CHECK-LABEL: } // end sil function 'test_control_flow6' -sil [ossa] @test_control_flow6 : $@convention(thin) () -> () { +// CHECK-LABEL: } // end sil function 'test_control_flow3' +sil [ossa] @test_control_flow3 : $@convention(thin) () -> () { bb0: %4 = alloc_stack [lexical] $Klass %f = function_ref @get_owned : $@convention(thin) () -> @owned Klass @@ -417,10 +338,10 @@ bb3: return %r : $() } -// CHECK-LABEL: sil [ossa] @test_control_flow7 : +// CHECK-LABEL: sil [ossa] @test_control_flow4 : // CHECK-NOT: alloc_stack -// CHECK-LABEL: } // end sil function 'test_control_flow7' -sil [ossa] @test_control_flow7 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () { +// CHECK-LABEL: } // end sil function 'test_control_flow4' +sil [ossa] @test_control_flow4 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () { bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass): %stk = alloc_stack [lexical] $Klass cond_br undef, bb1, bb2 diff --git a/test/SILOptimizer/move_only_type_eliminator.sil b/test/SILOptimizer/move_only_type_eliminator.sil index fb8109384f2..f2f601535a3 100644 --- a/test/SILOptimizer/move_only_type_eliminator.sil +++ b/test/SILOptimizer/move_only_type_eliminator.sil @@ -165,19 +165,20 @@ bb0(%0 : $Trivial): %alloc = alloc_stack $@moveOnly Trivial %1 = copyable_to_moveonlywrapper [owned] %0 : $Trivial %1a = begin_borrow %1 : $@moveOnly Trivial - store_borrow %1a to %alloc : $*@moveOnly Trivial - %2 = load [copy] %alloc : $*@moveOnly Trivial + %sb = store_borrow %1a to %alloc : $*@moveOnly Trivial + %2 = load [copy] %sb : $*@moveOnly Trivial %2a = begin_borrow %2 : $@moveOnly Trivial %3 = moveonlywrapper_to_copyable [guaranteed] %2a : $@moveOnly Trivial apply %f(%3) : $@convention(thin) (Trivial) -> () end_borrow %2a : $@moveOnly Trivial destroy_value %2 : $@moveOnly Trivial - %4 = load_borrow %alloc : $*@moveOnly Trivial + %4 = load_borrow %sb : $*@moveOnly Trivial %5 = moveonlywrapper_to_copyable [guaranteed] %4 : $@moveOnly Trivial apply %f(%5) : $@convention(thin) (Trivial) -> () end_borrow %4 : $@moveOnly Trivial + end_borrow %sb : $*@moveOnly Trivial end_borrow %1a : $@moveOnly Trivial destroy_value %1 : $@moveOnly Trivial dealloc_stack %alloc : $*@moveOnly Trivial @@ -418,18 +419,19 @@ bb0(%0 : @guaranteed $Klass): %1aa = copy_value %0 : $Klass %1 = copyable_to_moveonlywrapper [owned] %1aa : $Klass %1a = begin_borrow %1 : $@moveOnly Klass - store_borrow %1a to %alloc : $*@moveOnly Klass - %2 = load [copy] %alloc : $*@moveOnly Klass + %sb = store_borrow %1a to %alloc : $*@moveOnly Klass + %2 = load [copy] %sb : $*@moveOnly Klass %2a = begin_borrow %2 : $@moveOnly Klass %3 = moveonlywrapper_to_copyable [guaranteed] %2a : $@moveOnly Klass apply %f(%3) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %2a : $@moveOnly Klass destroy_value %2 : $@moveOnly Klass - %4 = load_borrow %alloc : $*@moveOnly Klass + %4 = load_borrow %sb : $*@moveOnly Klass %5 = moveonlywrapper_to_copyable [guaranteed] %4 : $@moveOnly Klass apply %f(%5) : $@convention(thin) (@guaranteed Klass) -> () end_borrow %4 : $@moveOnly Klass + end_borrow %sb : $*@moveOnly Klass end_borrow %1a : $@moveOnly Klass destroy_value %1 : $@moveOnly Klass diff --git a/test/SILOptimizer/ownership_model_eliminator.sil b/test/SILOptimizer/ownership_model_eliminator.sil index ff3a59668cd..ed8150350bf 100644 --- a/test/SILOptimizer/ownership_model_eliminator.sil +++ b/test/SILOptimizer/ownership_model_eliminator.sil @@ -112,7 +112,8 @@ bb0(%0 : @owned $Builtin.NativeObject): end_borrow %1 : $Builtin.NativeObject %2 = alloc_stack $Builtin.NativeObject %3 = begin_borrow %0 : $Builtin.NativeObject - store_borrow %3 to %2 : $*Builtin.NativeObject + %4 = store_borrow %3 to %2 : $*Builtin.NativeObject + end_borrow %4 : $*Builtin.NativeObject end_borrow %3 : $Builtin.NativeObject dealloc_stack %2 : $*Builtin.NativeObject destroy_value %0 : $Builtin.NativeObject @@ -375,7 +376,8 @@ bb0(%0 : @guaranteed $Builtin.NativeObject): %result = store_borrow %0 to %1 : $*Builtin.NativeObject %f = function_ref @use_native_object_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () apply %f(%result) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () + end_borrow %result : $*Builtin.NativeObject dealloc_stack %1 : $*Builtin.NativeObject %9999 = tuple() return %9999 : $() -} \ No newline at end of file +} diff --git a/test/SILOptimizer/specialize_ossa.sil b/test/SILOptimizer/specialize_ossa.sil index 613c7aa859e..7a3b9dd004b 100644 --- a/test/SILOptimizer/specialize_ossa.sil +++ b/test/SILOptimizer/specialize_ossa.sil @@ -977,8 +977,8 @@ bb3: dealloc_stack %0a : $*Builtin.Int32 %0b = alloc_stack $Builtin.NativeObject - store_borrow %1 to %0b : $*Builtin.NativeObject - try_apply %f(%0b) : $@convention(thin) (@in_guaranteed T) -> @error Error, normal bb4, error bb5 + %sb1 = store_borrow %1 to %0b : $*Builtin.NativeObject + try_apply %f(%sb1) : $@convention(thin) (@in_guaranteed T) -> @error Error, normal bb4, error bb5 bb4(%result2 : $()): br bb6 @@ -988,13 +988,14 @@ bb5(%e2 : @owned $Error): br bb6 bb6: + end_borrow %sb1 : $*Builtin.NativeObject dealloc_stack %0b : $*Builtin.NativeObject %0c = alloc_stack $Builtin.NativeObject - store_borrow %1 to %0c : $*Builtin.NativeObject + %sb2 = store_borrow %1 to %0c : $*Builtin.NativeObject %outParam = alloc_stack $Builtin.NativeObject %f2 = function_ref @generic_try_apply_callee_out_param : $@convention(thin) (@in_guaranteed T) -> (@out T, @error Error) - try_apply %f2(%outParam, %0c) : $@convention(thin) (@in_guaranteed T) -> (@out T, @error Error), normal bb7, error bb8 + try_apply %f2(%outParam, %sb2) : $@convention(thin) (@in_guaranteed T) -> (@out T, @error Error), normal bb7, error bb8 bb7(%result3 : $()): destroy_addr %outParam : $*Builtin.NativeObject @@ -1005,6 +1006,7 @@ bb8(%error4 : @owned $Error): br bb9 bb9: + end_borrow %sb2 : $*Builtin.NativeObject dealloc_stack %outParam : $*Builtin.NativeObject dealloc_stack %0c : $*Builtin.NativeObject %9999 = tuple() @@ -1030,13 +1032,15 @@ bb2(%e : @owned $Error): bb3: dealloc_stack %0a : $*Builtin.Int32 %0b = alloc_stack $Builtin.NativeObject - store_borrow %1 to %0b : $*Builtin.NativeObject - try_apply %f(%0b) : $@convention(thin) (@in_guaranteed T) -> @error Error, normal bb4, error bb5 + %sb = store_borrow %1 to %0b : $*Builtin.NativeObject + try_apply %f(%sb) : $@convention(thin) (@in_guaranteed T) -> @error Error, normal bb4, error bb5 bb4(%result2 : $()): + end_borrow %sb : $*Builtin.NativeObject br bb6 bb5(%e2 : @owned $Error): + end_borrow %sb : $*Builtin.NativeObject dealloc_stack %0b : $*Builtin.NativeObject br bbError(%e2 : $Error) @@ -1084,8 +1088,8 @@ sil [ossa] @test_try_apply_loadable : $@convention(thin) (@inout Klass, @guarant bb0(%0 : $*Klass, %1 : @guaranteed $Klass): %f = function_ref @generic_try_apply_callee_loadable_1 : $@convention(thin) (@inout T, @in_guaranteed T) -> @error Error %1b = alloc_stack $Klass - store_borrow %1 to %1b : $*Klass - try_apply %f(%0, %1b) : $@convention(thin) (@inout T, @in_guaranteed T) -> @error Error, normal bb4, error bb5 + %sb = store_borrow %1 to %1b : $*Klass + try_apply %f(%0, %sb) : $@convention(thin) (@inout T, @in_guaranteed T) -> @error Error, normal bb4, error bb5 bb4(%result2 : $()): br bb6 @@ -1095,6 +1099,7 @@ bb5(%e2 : @owned $Error): br bb6 bb6: + end_borrow %sb : $*Klass dealloc_stack %1b : $*Klass %9999 = tuple() return %9999 : $()