| // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -global-opt | %FileCheck %s |
| |
| import Builtin |
| import Swift |
| |
| // Check that token0 gets eliminated as it is not used after removing the once call. |
| // CHECK-NOT: sil_global private @globalinit_token0 : $Builtin.Word |
| sil_global private @globalinit_token0 : $Builtin.Word |
| |
| // CHECK: sil_global @_Tv2ch1xSi : $Int32, @globalinit_func0 : $@convention(thin) () -> () |
| sil_global @_Tv2ch1xSi : $Int32 |
| |
| // CHECK-LABEL: sil private @globalinit_func0 : $@convention(thin) () -> () { |
| sil private @globalinit_func0 : $@convention(thin) () -> () { |
| bb0: |
| %0 = global_addr @_Tv2ch1xSi : $*Int32 |
| %1 = integer_literal $Builtin.Int32, 2 |
| %2 = struct $Int32 (%1 : $Builtin.Int32) |
| store %2 to %0 : $*Int32 |
| %4 = tuple () |
| return %4 : $() |
| } |
| |
| // CHECK-LABEL: sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer { |
| // CHECK-NEXT: bb0: |
| // CHECK-NOT: global_addr @globalinit_token0 |
| // CHECK-NEXT: address_to_pointer |
| // CHECK: function_ref @globalinit_func0 : $@convention(thin) () -> () |
| // CHECK-NEXT: global_addr @_Tv2ch1xSi : $*Int32 |
| // CHECK-NEXT: address_to_pointer |
| // CHECK-NEXT: return |
| sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer { |
| bb0: |
| %1 = global_addr @globalinit_token0 : $*Builtin.Word |
| %2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer |
| %3 = function_ref @globalinit_func0 : $@convention(thin) () -> () |
| %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $() |
| %6 = global_addr @_Tv2ch1xSi : $*Int32 |
| %7 = address_to_pointer %6 : $*Int32 to $Builtin.RawPointer |
| return %7 : $Builtin.RawPointer |
| } |
| |
| // CHECK-LABEL: sil @_TF2ch1fFT_Si : $@convention(thin) () -> Int32 { |
| sil @_TF2ch1fFT_Si : $@convention(thin) () -> Int32 { |
| bb0: |
| %0 = function_ref @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer |
| %1 = apply %0() : $@convention(thin) () -> Builtin.RawPointer |
| %2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*Int32 |
| %3 = load %2 : $*Int32 |
| return %3 : $Int32 |
| } |