mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Instead, put the archetype->instrution map into SIlModule. SILOpenedArchetypesTracker tried to maintain and reconstruct the mapping locally, e.g. during a use of SILBuilder. Having a "global" map in SILModule makes the whole logic _much_ simpler. I'm wondering why we didn't do this in the first place. This requires that opened archetypes must be unique in a module - which makes sense. This was the case anyway, except for keypath accessors (which I fixed in the previous commit) and in some sil test files.
203 lines
10 KiB
Plaintext
203 lines
10 KiB
Plaintext
// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -sil-combine-disable-alloc-stack-opts | %FileCheck %s
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
class Klass {}
|
|
|
|
sil @returnInt : $@convention(thin) () -> Builtin.Int32
|
|
sil @use_anyobject : $@convention(thin) (@guaranteed AnyObject) -> ()
|
|
sil @use_nativeobject : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
|
|
|
|
// CHECK-LABEL: sil @optimize_convert_escape_to_noescape :
|
|
// CHECK: [[FN:%.*]] = function_ref @returnInt
|
|
// CHECK: apply [[FN]]()
|
|
// CHECK: } // end sil function 'optimize_convert_escape_to_noescape'
|
|
sil @optimize_convert_escape_to_noescape : $@convention(thin) () -> Builtin.Int32 {
|
|
bb0:
|
|
%0 = function_ref @returnInt : $@convention(thin) () -> Builtin.Int32
|
|
%1 = thin_to_thick_function %0 : $@convention(thin) () -> Builtin.Int32 to $@callee_guaranteed () -> Builtin.Int32
|
|
%2 = convert_escape_to_noescape %1 : $@callee_guaranteed () -> Builtin.Int32 to $@noescape @callee_guaranteed () -> Builtin.Int32
|
|
%4 = apply %2() : $@noescape @callee_guaranteed () -> Builtin.Int32
|
|
return %4 : $Builtin.Int32
|
|
}
|
|
|
|
// We have an extra thin_to_thick_function here since we do not yet have the
|
|
// optimization for eliminating it enabled in OSSA yet.
|
|
//
|
|
// CHECK-LABEL: sil [ossa] @optimize_convert_escape_to_noescape_ossa :
|
|
// CHECK: [[FN:%.*]] = function_ref @returnInt
|
|
// CHECK: apply [[FN]]()
|
|
// CHECK: } // end sil function 'optimize_convert_escape_to_noescape_ossa'
|
|
sil [ossa] @optimize_convert_escape_to_noescape_ossa : $@convention(thin) () -> Builtin.Int32 {
|
|
bb0:
|
|
%0 = function_ref @returnInt : $@convention(thin) () -> Builtin.Int32
|
|
%1 = thin_to_thick_function %0 : $@convention(thin) () -> Builtin.Int32 to $@callee_guaranteed () -> Builtin.Int32
|
|
%2 = convert_escape_to_noescape %1 : $@callee_guaranteed () -> Builtin.Int32 to $@noescape @callee_guaranteed () -> Builtin.Int32
|
|
%4 = apply %2() : $@noescape @callee_guaranteed () -> Builtin.Int32
|
|
return %4 : $Builtin.Int32
|
|
}
|
|
|
|
//////////////////////////////
|
|
// ref_to_raw_pointer tests //
|
|
//////////////////////////////
|
|
|
|
// RefToRawPointer pointer consumption.
|
|
//
|
|
// (ref_to_raw_pointer (unchecked_ref_cast x))
|
|
// -> (ref_to_raw_pointer x)
|
|
//
|
|
// CHECK-LABEL: sil @ref_to_raw_pointer_unchecked_ref_cast_composition : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer
|
|
// CHECK: bb0
|
|
// CHECK-NEXT: ref_to_raw_pointer
|
|
// CHECK-NEXT: return
|
|
// CHECK: } // end sil function 'ref_to_raw_pointer_unchecked_ref_cast_composition'
|
|
sil @ref_to_raw_pointer_unchecked_ref_cast_composition : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer {
|
|
bb0(%0 : $Klass):
|
|
%1 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject
|
|
%2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer
|
|
return %2 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_guaranteed : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer
|
|
// CHECK: bb0
|
|
// CHECK-NEXT: ref_to_raw_pointer
|
|
// CHECK-NEXT: return
|
|
// CHECK: } // end sil function 'ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_guaranteed'
|
|
sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_guaranteed : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer {
|
|
bb0(%0 : @guaranteed $Klass):
|
|
%1 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject
|
|
%2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer
|
|
return %2 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_owned : $@convention(thin) (@owned Klass) -> Builtin.RawPointer
|
|
// CHECK: bb0([[ARG:%.*]] : @owned
|
|
// CHECK-NEXT: [[RESULT:%.*]] = ref_to_raw_pointer [[ARG]]
|
|
// CHECK-NEXT: [[CAST:%.*]] = unchecked_ref_cast [[ARG]]
|
|
// CHECK-NEXT: destroy_value [[CAST]]
|
|
// CHECK-NEXT: return [[RESULT]]
|
|
// CHECK: } // end sil function 'ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_owned'
|
|
sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_owned : $@convention(thin) (@owned Klass) -> Builtin.RawPointer {
|
|
bb0(%0 : @owned $Klass):
|
|
%1 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject
|
|
%2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer
|
|
destroy_value %1 : $Builtin.NativeObject
|
|
return %2 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: sil @collapse_existential_pack_unpack_ref_to_raw_pointer :
|
|
// CHECK: bb0([[Ref:%.*]] : $Klass):
|
|
// CHECK-NOT: init_existential_ref
|
|
// CHECK-NOT: open_existential_ref
|
|
// CHECK: ref_to_raw_pointer [[Ref]]
|
|
// CHECK: } // end sil function 'collapse_existential_pack_unpack_ref_to_raw_pointer'
|
|
sil @collapse_existential_pack_unpack_ref_to_raw_pointer : $@convention(thin) (@guaranteed Klass) -> () {
|
|
bb0(%0 : $Klass):
|
|
%1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject
|
|
%2 = open_existential_ref %1 : $AnyObject to $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject
|
|
%3 = ref_to_raw_pointer %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject to $Builtin.RawPointer
|
|
%4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Builtin.Word
|
|
%5 = integer_literal $Builtin.Word, 5
|
|
store %5 to %4: $*Builtin.Word
|
|
%6 = tuple ()
|
|
return %6 : $()
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_guaranteed :
|
|
// CHECK: bb0([[Ref:%.*]] : @guaranteed $Klass):
|
|
// CHECK-NOT: init_existential_ref
|
|
// CHECK-NOT: open_existential_ref
|
|
// CHECK: ref_to_raw_pointer [[Ref]]
|
|
// CHECK: } // end sil function 'collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_guaranteed'
|
|
sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_guaranteed : $@convention(thin) (@guaranteed Klass) -> () {
|
|
bb0(%0 : @guaranteed $Klass):
|
|
%1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject
|
|
%2 = open_existential_ref %1 : $AnyObject to $@opened("3CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject
|
|
%3 = ref_to_raw_pointer %2 : $@opened("3CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject to $Builtin.RawPointer
|
|
%4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Builtin.Word
|
|
%5 = integer_literal $Builtin.Word, 5
|
|
store %5 to [trivial] %4: $*Builtin.Word
|
|
%6 = tuple ()
|
|
return %6 : $()
|
|
}
|
|
|
|
// We need to hoist the ref_to_raw_pointer above the init_existential_ref since
|
|
// that is where %0 is live.
|
|
//
|
|
// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_owned :
|
|
// CHECK: bb0([[ARG:%.*]] : @owned $Klass):
|
|
// CHECK-NOT: init_existential_ref
|
|
// CHECK-NOT: open_existential_ref
|
|
// CHECK: [[PTR:%.*]] = ref_to_raw_pointer [[ARG]]
|
|
// CHECK: [[FORWARDED_ARG:%.*]] = init_existential_ref [[ARG]]
|
|
// CHECK: destroy_value [[FORWARDED_ARG]]
|
|
// CHECK: } // end sil function 'collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_owned'
|
|
sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_owned : $@convention(thin) (@owned Klass) -> () {
|
|
bb0(%0 : @owned $Klass):
|
|
%1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject
|
|
%f = function_ref @use_anyobject : $@convention(thin) (@guaranteed AnyObject) -> ()
|
|
apply %f(%1) : $@convention(thin) (@guaranteed AnyObject) -> ()
|
|
%2 = open_existential_ref %1 : $AnyObject to $@opened("4CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject
|
|
%3 = ref_to_raw_pointer %2 : $@opened("4CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject to $Builtin.RawPointer
|
|
%4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Builtin.Word
|
|
%5 = integer_literal $Builtin.Word, 5
|
|
store %5 to [trivial] %4: $*Builtin.Word
|
|
destroy_value %2 : $@opened("4CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject
|
|
%6 = tuple ()
|
|
return %6 : $()
|
|
}
|
|
|
|
|
|
// (ref_to_raw_pointer (unchecked_ref_cast x)) -> (unchecked_trivial_bit_cast x)
|
|
//
|
|
// CHECK-LABEL: sil @collapse_to_unchecked_trivial_bit_cast :
|
|
// CHECK: bb0([[Ref:%.*]] : $Optional<Klass>):
|
|
// CHECK: unchecked_trivial_bit_cast [[Ref]]
|
|
// CHECK-NOT: unchecked_ref_cast
|
|
// CHECK-NOT: ref_to_raw_pointer
|
|
// CHECK: } // end sil function 'collapse_to_unchecked_trivial_bit_cast'
|
|
sil @collapse_to_unchecked_trivial_bit_cast : $@convention(thin) (Optional<Klass>) -> (Builtin.RawPointer) {
|
|
bb0(%0 : $Optional<Klass>):
|
|
%1 = unchecked_ref_cast %0 : $Optional<Klass> to $Builtin.NativeObject
|
|
%2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer
|
|
return %2 : $Builtin.RawPointer
|
|
}
|
|
|
|
// CHECK-LABEL: sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_guaranteed :
|
|
// CHECK: bb0([[Ref:%.*]] : @guaranteed $Optional<Klass>):
|
|
// CHECK: unchecked_trivial_bit_cast [[Ref]]
|
|
// CHECK-NOT: unchecked_ref_cast
|
|
// CHECK-NOT: ref_to_raw_pointer
|
|
// CHECK: } // end sil function 'collapse_to_unchecked_trivial_bit_cast_ossa_guaranteed'
|
|
sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_guaranteed : $@convention(thin) (@guaranteed Optional<Klass>) -> (Builtin.RawPointer) {
|
|
bb0(%0 : @guaranteed $Optional<Klass>):
|
|
%1 = unchecked_ref_cast %0 : $Optional<Klass> to $Builtin.NativeObject
|
|
%2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer
|
|
return %2 : $Builtin.RawPointer
|
|
}
|
|
|
|
// We need to make sure that we hoist unchecked_trivial_bit_cast above
|
|
// unchecked_ref_cast since we are not eliminating it here due to an additional
|
|
// user.
|
|
//
|
|
// CHECK-LABEL: sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_owned :
|
|
// CHECK: bb0([[ARG:%.*]] : @owned $Optional<Klass>):
|
|
// CHECK: [[RESULT:%.*]] = unchecked_trivial_bit_cast [[ARG]]
|
|
// CHECK: [[FORWARDED_ARG:%.*]] = unchecked_ref_cast [[ARG]]
|
|
// CHECK: destroy_value [[FORWARDED_ARG]]
|
|
// CHECK: return [[RESULT]]
|
|
// CHECK: } // end sil function 'collapse_to_unchecked_trivial_bit_cast_ossa_owned'
|
|
sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_owned : $@convention(thin) (@owned Optional<Klass>) -> (Builtin.RawPointer) {
|
|
bb0(%0 : @owned $Optional<Klass>):
|
|
%1 = unchecked_ref_cast %0 : $Optional<Klass> to $Builtin.NativeObject
|
|
%f = function_ref @use_nativeobject : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
|
|
apply %f(%1) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
|
|
%2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer
|
|
destroy_value %1 : $Builtin.NativeObject
|
|
return %2 : $Builtin.RawPointer
|
|
}
|
|
|