File: mandatory_combiner_opt.sil

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (137 lines) | stat: -rw-r--r-- 4,408 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// RUN: %target-sil-opt -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 : $()
}