Files
swift-mirror/test/SIL/Parser/borrow.sil
Meghana Gupta 1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00

70 lines
2.3 KiB
Plaintext

// RUN: %target-sil-opt %s | %target-sil-opt | %FileCheck %s
sil_stage canonical
import Builtin
// We do not verify here, but just make sure that all of the combinations parse and print correctly.
// CHECK-LABEL: sil [ossa] @borrow_test : $@convention(thin) (@in Builtin.NativeObject, @guaranteed Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG1:%[0-9]+]] : $*Builtin.NativeObject, [[ARG2:%[0-9]+]] : @guaranteed $Builtin.NativeObject):
// CHECK: [[BORROWED_ARG2:%.*]] = begin_borrow [[ARG2]]
// CHECK: end_borrow [[BORROWED_ARG2]]
// CHECK: [[MEM:%.*]] = alloc_stack $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):
%2 = begin_borrow %1 : $Builtin.NativeObject
end_borrow %2 : $Builtin.NativeObject
%3 = alloc_stack $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()
return %4 : $()
}
class C {}
// CHECK-LABEL: sil [ossa] @foo
// CHECK: begin_borrow {{%[^,]+}}
// CHECK: begin_borrow [lexical] {{%[^,]+}}
// CHECK-LABEL: } // end sil function 'foo'
sil [ossa] @foo : $@convention(thin) () -> () {
%instance = alloc_ref $C
%guaranteed_c2 = begin_borrow %instance : $C
end_borrow %guaranteed_c2 : $C
%guaranteed_c = begin_borrow [lexical] %instance : $C
end_borrow %guaranteed_c : $C
destroy_value %instance : $C
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [ossa] @reborrowTest : $@convention(thin) (@owned C) -> () {
// CHECK: bb3([[ARG:%.*]] : @reborrow @guaranteed $C):
// CHECK: } // end sil function 'reborrowTest'
sil [ossa] @reborrowTest : $@convention(thin) (@owned C) -> () {
bb0(%0 : @owned $C):
cond_br undef, bb1, bb2
bb1:
%b1 = begin_borrow %0 : $C
br bb3(%b1 : $C)
bb2:
%b2 = begin_borrow %0 : $C
br bb3(%b2 : $C)
bb3(%r : @reborrow @guaranteed $C):
end_borrow %r : $C
destroy_value %0 : $C
%9999 = tuple()
return %9999 : $()
}