File: opaque_values_opt.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (71 lines) | stat: -rw-r--r-- 3,269 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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)
}