| // RUN: %target-sil-opt -enable-sil-ownership -ownership-model-eliminator %s | %FileCheck %s |
| |
| sil_stage canonical |
| |
| import Builtin |
| |
| sil @use_native_object : $@convention(thin) (@owned Builtin.NativeObject) -> () |
| sil @use_int32 : $@convention(thin) (Builtin.Int32) -> () |
| |
| // CHECK-LABEL: sil @load : $@convention(thin) (@in Builtin.NativeObject, @in Builtin.Int32) -> () { |
| // CHECK: bb0([[ARG1:%[0-9]+]] : $*Builtin.NativeObject, [[ARG2:%[0-9]+]] : $*Builtin.Int32): |
| // CHECK: [[LOAD2:%[0-9]+]] = load [[ARG1]] : $*Builtin.NativeObject |
| // CHECK: apply {{%[0-9]+}}([[LOAD2]]) |
| // CHECK: [[LOAD3:%[0-9]+]] = load [[ARG1]] : $*Builtin.NativeObject |
| // CHECK: retain_value [[LOAD3]] |
| // CHECK: apply {{%[0-9]+}}([[LOAD3]]) |
| // CHECK: [[LOAD4:%[0-9]+]] = load [[ARG2]] : $*Builtin.Int32 |
| // CHECK: apply {{%[0-9]+}}([[LOAD4]]) |
| sil @load : $@convention(thin) (@in Builtin.NativeObject, @in Builtin.Int32) -> () { |
| bb0(%0 : $*Builtin.NativeObject, %1 : $*Builtin.Int32): |
| %use_native_object_func = function_ref @use_native_object : $@convention(thin) (@owned Builtin.NativeObject) -> () |
| %use_int32_func = function_ref @use_int32 : $@convention(thin) (Builtin.Int32) -> () |
| |
| %3 = load [take] %0 : $*Builtin.NativeObject |
| apply %use_native_object_func(%3) : $@convention(thin) (@owned Builtin.NativeObject) -> () |
| |
| %4 = load [copy] %0 : $*Builtin.NativeObject |
| apply %use_native_object_func(%4) : $@convention(thin) (@owned Builtin.NativeObject) -> () |
| |
| %5 = load [trivial] %1 : $*Builtin.Int32 |
| apply %use_int32_func(%5) : $@convention(thin) (Builtin.Int32) -> () |
| |
| %9999 = tuple() |
| return %9999 : $() |
| } |
| |
| // CHECK-LABEL: sil @store : $@convention(thin) (@in Builtin.NativeObject, Builtin.NativeObject, @in Builtin.Int32, Builtin.Int32) -> () |
| // CHECK: bb0([[ARG1:%[0-9]+]] : $*Builtin.NativeObject, [[ARG2:%[0-9]+]] : $Builtin.NativeObject, [[ARG3:%[0-9]+]] : $*Builtin.Int32, [[ARG4:%[0-9]+]] : $Builtin.Int32): |
| // CHECK: store [[ARG2]] to [[ARG1]] : $*Builtin.NativeObject |
| // CHECK: [[OLDVAL:%[0-9]+]] = load [[ARG1]] : $*Builtin.NativeObject |
| // CHECK: store [[ARG2]] to [[ARG1]] : $*Builtin.NativeObject |
| // CHECK: release_value [[OLDVAL]] |
| // CHECK: store [[ARG4]] to [[ARG3]] : $*Builtin.Int32 |
| sil @store : $@convention(thin) (@in Builtin.NativeObject, Builtin.NativeObject, @in Builtin.Int32, Builtin.Int32) -> () { |
| bb0(%0 : $*Builtin.NativeObject, %1 : $Builtin.NativeObject, %2 : $*Builtin.Int32, %3 : $Builtin.Int32): |
| store %1 to [init] %0 : $*Builtin.NativeObject |
| store %1 to [assign] %0 : $*Builtin.NativeObject |
| store %3 to [trivial] %2 : $*Builtin.Int32 |
| %9999 = tuple() |
| return %9999 : $() |
| } |
| |
| // CHECK-LABEL: sil @borrow : $@convention(thin) (@in Builtin.NativeObject) -> () { |
| // CHECK: bb0([[ARG:%[0-9]+]] : $*Builtin.NativeObject): |
| // CHECK: [[BORROWED_VALUE:%[0-9]+]] = load [[ARG]] : $*Builtin.NativeObject |
| // CHECK: unchecked_ref_cast [[BORROWED_VALUE]] |
| // CHECK-NOT: end_borrow |
| sil @borrow : $@convention(thin) (@in Builtin.NativeObject) -> () { |
| bb0(%0 : $*Builtin.NativeObject): |
| %1 = load_borrow %0 : $*Builtin.NativeObject |
| %2 = unchecked_ref_cast %1 : $Builtin.NativeObject to $Builtin.NativeObject |
| end_borrow %1 from %0 : $Builtin.NativeObject, $*Builtin.NativeObject |
| %3 = tuple() |
| return %3 : $() |
| } |
| |
| // CHECK-LABEL: sil @copy_value_destroy_value : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { |
| // CHECK: bb0([[ARG1:%.*]] : $Builtin.NativeObject): |
| // CHECK: retain_value [[ARG1]] |
| // CHECK: release_value [[ARG1]] |
| // CHECK: return [[ARG1]] |
| sil @copy_value_destroy_value : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { |
| bb0(%0 : $Builtin.NativeObject): |
| %1 = copy_value %0 : $Builtin.NativeObject |
| destroy_value %0 : $Builtin.NativeObject |
| return %1 : $Builtin.NativeObject |
| } |