mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Type annotations for instruction operands are omitted, e.g. ``` %3 = struct $S(%1, %2) ``` Operand types are redundant anyway and were only used for sanity checking in the SIL parser. But: operand types _are_ printed if the definition of the operand value was not printed yet. This happens: * if the block with the definition appears after the block where the operand's instruction is located * if a block or instruction is printed in isolation, e.g. in a debugger The old behavior can be restored with `-Xllvm -sil-print-types`. This option is added to many existing test files which check for operand types in their check-lines.
138 lines
4.3 KiB
Plaintext
138 lines
4.3 KiB
Plaintext
// RUN: %target-sil-opt -sil-print-types -sil-combine %s | %FileCheck %s
|
|
|
|
// Tests for when the mandatory combiner is running with optimizations
|
|
// enabled. Only put tests here for functionality that only occurs when the
|
|
// Mandatory Combiner runs in between the diagnostics/perf pipeline at -O,
|
|
// -Osize.
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
|
|
// Trivial declarations
|
|
|
|
struct MyInt {
|
|
var value: Builtin.Int64
|
|
}
|
|
|
|
// Generic declarations
|
|
|
|
protocol Addable {
|
|
static var an: Self { get }
|
|
}
|
|
|
|
// Class declarations
|
|
|
|
class Klass {
|
|
init()
|
|
deinit
|
|
}
|
|
|
|
// Existential declarations
|
|
|
|
protocol Proto {
|
|
static var an: Proto { get }
|
|
}
|
|
|
|
// Trivial support
|
|
|
|
sil @first_of_three_ints : $@convention(thin) (MyInt, MyInt, MyInt) -> MyInt
|
|
|
|
sil @constant_zero : $@convention(thin) () -> MyInt
|
|
|
|
sil @identity_int : $@convention(thin) (MyInt) -> MyInt
|
|
|
|
// Generic support
|
|
|
|
sil @first_of_three_addables : $@convention(thin) <A where A : Addable> (@in_guaranteed A, @guaranteed <τ_0_0 where τ_0_0 : Addable> { var τ_0_0 } <A>, @guaranteed <τ_0_0 where τ_0_0 : Addable> { var τ_0_0 } <A>) -> @
|
|
out A
|
|
|
|
// Class support
|
|
|
|
sil [exact_self_class] @klass_alloc_init : $@convention(method) (@thick Klass.Type) -> @owned Klass
|
|
|
|
// Klass.init()
|
|
sil @klass_init : $@convention(method) (@owned Klass) -> @owned Klass
|
|
// Klass.deinit
|
|
sil @klass_deinit : $@convention(method) (@guaranteed Klass) -> @owned Builtin.NativeObject
|
|
|
|
// Klass.__deallocating_deinit
|
|
sil @klass_dealloc_deinit : $@convention(method) (@owned Klass) -> ()
|
|
|
|
sil_vtable Klass {
|
|
#Klass.init!allocator: (Klass.Type) -> () -> Klass : @klass_alloc_init
|
|
#Klass.deinit!deallocator: @klass_dealloc_deinit
|
|
}
|
|
|
|
sil @first_of_three_klasses : $@convention(thin) (@guaranteed Klass, @guaranteed Klass, @guaranteed Klass) -> @owned Klass
|
|
|
|
// Existential support
|
|
|
|
sil @first_of_three_protos : $@convention(thin) (@in_guaranteed Proto, @guaranteed { var Proto }, @guaranteed { var Proto }) -> @out Proto
|
|
|
|
sil @get_proto : $@convention(thin) () -> @out Proto
|
|
|
|
// Mixed support
|
|
|
|
sil @proto_from_proto_and_myint : $@convention(thin) (@in_guaranteed Proto, MyInt) -> @out Proto
|
|
|
|
sil @myint_from_myint_and_proto : $@convention(thin) (MyInt, @guaranteed { var Proto }) -> MyInt
|
|
|
|
sil @myint_from_proto_and_myint : $@convention(thin) (@guaranteed { var Proto }, MyInt) -> MyInt
|
|
|
|
// Optional support
|
|
enum FakeOptional<T> {
|
|
case none
|
|
case some(T)
|
|
}
|
|
|
|
///////////
|
|
// Tests //
|
|
///////////
|
|
|
|
|
|
// CHECK-LABEL: sil [ossa] @eliminate_simple_arc_traffic : $@convention(thin) (@guaranteed Klass) -> () {
|
|
// CHECK-NOT: copy_value
|
|
// CHECK-NOT: destroy_value
|
|
// CHECK-NOT: enum
|
|
// CHECK-NOT: end_borrow
|
|
// CHECK: } // end sil function 'eliminate_simple_arc_traffic'
|
|
sil [ossa] @eliminate_simple_arc_traffic : $@convention(thin) (@guaranteed Klass) -> () {
|
|
bb0(%0 : @guaranteed $Klass):
|
|
%1 = copy_value %0 : $Klass
|
|
destroy_value %1 : $Klass
|
|
%2 = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
|
|
end_borrow %2 : $FakeOptional<Klass>
|
|
%9999 = tuple()
|
|
return %9999 : $()
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Test removal of redundant borrow scopes for owned-to-guaranteed
|
|
// coroutine arguments.
|
|
class C {
|
|
@_hasStorage var float: Builtin.Int64 { get set }
|
|
init(_ float: Builtin.Int64)
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @testCoroutineBorrow : $@convention(thin) (@owned C, Builtin.Int64) -> () {
|
|
// CHECK-LABEL: bb0(%0 : @owned $C, %1 : $Builtin.Int64):
|
|
// CHECK-NOT: borrow
|
|
// CHECK: class_method %0 : $C, #C.float!modify : (C) -> () -> (), $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
|
|
// CHECK: begin_apply %{{.*}}(%0) : $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
|
|
// CHECK-NOT: borrow
|
|
// CHECK: destroy_value %0 : $C
|
|
// CHECK-LABEL: } // end sil function 'testCoroutineBorrow'
|
|
sil hidden [ossa] @testCoroutineBorrow : $@convention(thin) (@owned C, Builtin.Int64) -> () {
|
|
bb0(%0 : @owned $C, %1 : $Builtin.Int64):
|
|
%14 = begin_borrow %0 : $C
|
|
%15 = class_method %14 : $C, #C.float!modify : (C) -> () -> (), $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
|
|
(%16, %17) = begin_apply %15(%14) : $@yield_once @convention(method) (@guaranteed C) -> @yields @inout Builtin.Int64
|
|
store %1 to [trivial] %16 : $*Builtin.Int64
|
|
end_apply %17 as $()
|
|
end_borrow %14 : $C
|
|
destroy_value %0 : $C
|
|
%23 = tuple ()
|
|
return %23 : $()
|
|
}
|