Files
swift-mirror/test/SILOptimizer/opaque_values_opt.sil
Andrew Trick b90007a98c Update and reimplement AddressLowering pass (for SIL opaque values).
Merge the AddressLowering pass from its old development branch and update
it so we can begin incrementally enabling it under a flag.

This has been reimplemented for simplicity. There's no point in
looking at the old code.
2022-03-09 17:18:15 -08:00

72 lines
3.2 KiB
Plaintext

// RUN: %target-sil-opt -O -enable-sil-opaque-values -emit-sorted-sil %s | %FileCheck %s
//
// These tests assume that opaque values are lowered in the
// optimization pipeline. They are currently only lowered in raw sil.
//
// REQUIRES: enable_opaque_values
import Builtin
sil_stage canonical
public typealias Int = Builtin.Int64
// CHECK: sil shared [noinline] @$s20f010_genericIdentityBi64__Tg5 : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
// CHECK: bb0(%0 : $Builtin.Int64):
// CHECK: return %0 : $Builtin.Int64
// CHECK: } // end sil function '$s20f010_genericIdentityBi64__Tg5'
sil hidden [noinline] [ossa] @f010_genericIdentity : $@convention(thin) <T> (@in T) -> @out T {
bb0(%0 : @owned $T):
return %0 : $T
}
sil [ossa] @f015_callGeneric : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
bb0(%0 : $Builtin.Int64):
%2 = function_ref @f010_genericIdentity : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
%3 = apply %2<Builtin.Int64>(%0) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0
return %3 : $Builtin.Int64
}
// Test returning an opaque tuple of tuples.
// FIXME: Early copy optimization should eliminate one copy_value+destroy pair,
// and forward %0 into all tuple positions.
// ---
// CHECK-LABEL: sil hidden [noinline] @f020_multiResult : $@convention(thin) <T> (@in T) -> (@out T, @out T, @out T) {
// CHECK: bb0(%0 : $T):
// CHECK: %1 = copy_value %0 : $T
// CHECK: %2 = copy_value %0 : $T
// CHECK: %3 = copy_value %0 : $T
// CHECK: destroy_value %0 : $T
// CHECK: %5 = tuple (%1 : $T, %2 : $T, %3 : $T)
// CHECK: return %5 : $(T, T, T)
// CHECK-LABEL: } // end sil function 'f020_multiResult'
sil hidden [noinline] [ossa] @f020_multiResult : $@convention(thin) <T> (@in T) -> (@out T, @out T, @out T) {
bb0(%0 : @owned $T):
%2 = copy_value %0 : $T
%3 = copy_value %0 : $T
%4 = copy_value %0 : $T
destroy_value %0 : $T
%6 = tuple (%2 : $T, %3 : $T, %4 : $T)
return %6 : $(T, T, T)
}
// Test returning an opaque tuple of tuples as a concrete tuple.
// The multiResult call is specialized, but the SIL result convention does not change.
// ---
// CHECK-LABEL: sil @f030_callMultiResult : $@convention(thin) (Builtin.Int64) -> (Builtin.Int64, Builtin.Int64, Builtin.Int64) {
// CHECK: bb0(%0 : $Builtin.Int64):
// CHECK: %1 = function_ref @$s16f020_multiResultBi64__Tg5 : $@convention(thin) (Builtin.Int64) -> (Builtin.Int64, @out Builtin.Int64, @out Builtin.Int64)
// CHECK: %2 = apply %1(%0) : $@convention(thin) (Builtin.Int64) -> (Builtin.Int64, @out Builtin.Int64, @out Builtin.Int64)
// CHECK: return %2 : $(Builtin.Int64, Builtin.Int64, Builtin.Int64)
// CHECK-LABEL: } // end sil function 'f030_callMultiResult'
sil [ossa] @f030_callMultiResult : $@convention(thin) (Int) -> (Int, Int, Int) {
bb0(%0 : $Int):
%1 = function_ref @f020_multiResult : $@convention(thin) <τ_0_0> (@in τ_0_0) -> (@out τ_0_0, @out τ_0_0, @out τ_0_0)
%2 = apply %1<Int>(%0) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> (@out τ_0_0, @out τ_0_0, @out τ_0_0)
%3 = tuple_extract %2 : $(Int, Int, Int), 0
%4 = tuple_extract %2 : $(Int, Int, Int), 1
%5 = tuple_extract %2 : $(Int, Int, Int), 2
%6 = tuple (%3 : $Int, %4 : $Int, %5 : $Int)
return %6 : $(Int, Int, Int)
}