Commits
Chris Lattner committed 5db1372c64f
rename couldReduceRefcount -> couldReduceStrongRefcount and teach it about some
new instructions that don't mutate the strong refcount. This allows us to
avoid retains and releases around weak and unowned pointer manipulations, for
example for this:
func unowned_local() -> C {
let c = C()
unowned let uc = c
return uc
}
before:
sil @_TF1w13unowned_localFT_CS_1C : $@thin () -> @owned C {
bb0:
// function_ref w.C.__allocating_init (w.C.Type)() -> w.C
%0 = function_ref @_TFC1w1CCfMS0_FT_S0_ : $@thin (@thick C.Type) -> @owned C // user: %2
%1 = metatype $@thick C.Type // user: %2
%2 = apply %0(%1) : $@thin (@thick C.Type) -> @owned C // users: %3, %5, %6, %9, %14
debug_value %2 : $C // let c // id: %3
%4 = alloc_box $@sil_unowned C // let uc // users: %8, %10, %13
strong_retain %2 : $C // id: %5
%6 = ref_to_unowned %2 : $C to $@sil_unowned C // users: %7, %8
unowned_retain %6 : $@sil_unowned C // id: %7
store %6 to %4#1 : $*@sil_unowned C // id: %8
strong_release %2 : $C // id: %9
%10 = load %4#1 : $*@sil_unowned C // users: %11, %12
strong_retain_unowned %10 : $@sil_unowned C // id: %11
%12 = unowned_to_ref %10 : $@sil_unowned C to $C // user: %15
strong_release %4#0 : $Builtin.NativeObject // id: %13
strong_release %2 : $C // id: %14
return %12 : $C // id: %15
}
after:
sil @_TF1w13unowned_localFT_CS_1C : $@thin () -> @owned C {
bb0:
// function_ref w.C.__allocating_init (w.C.Type)() -> w.C
%0 = function_ref @_TFC1w1CCfMS0_FT_S0_ : $@thin (@thick C.Type) -> @owned C // user: %2
%1 = metatype $@thick C.Type // user: %2
%2 = apply %0(%1) : $@thin (@thick C.Type) -> @owned C // users: %3, %5, %12
debug_value %2 : $C // let c // id: %3
%4 = alloc_box $@sil_unowned C // let uc // users: %7, %8, %11
%5 = ref_to_unowned %2 : $C to $@sil_unowned C // users: %6, %7
unowned_retain %5 : $@sil_unowned C // id: %6
store %5 to %4#1 : $*@sil_unowned C // id: %7
%8 = load %4#1 : $*@sil_unowned C // users: %9, %10
strong_retain_unowned %8 : $@sil_unowned C // id: %9
%10 = unowned_to_ref %8 : $@sil_unowned C to $C // user: %13
strong_release %4#0 : $Builtin.NativeObject // id: %11
strong_release %2 : $C // id: %12
return %10 : $C // id: %13
}
Swift SVN r17844