File: devirtualize.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 (156 lines) | stat: -rw-r--r-- 5,482 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// RUN: %target-sil-opt -enable-sil-verify-all %/s -devirtualizer -dce -save-optimization-record-path=%t.yaml | %FileCheck %s
// RUN: %FileCheck -check-prefix=YAML -input-file=%t.yaml %s

sil_stage canonical

import Builtin
import Swift

class Bar {
  init()
  func foo()
}

sil_global @x : $Bar


//CHECK: function_with_cm
//CHECK: function_ref @_TFC4main3Bar3foofS0_FT_T_
//CHECK-NEXT: apply
//CHECK-NOT: class_method
//CHECK: return

// YAML:      --- !Passed
// YAML-NEXT: Pass:            sil-devirtualizer
// YAML-NEXT: Name:            sil.ClassMethodDevirtualized
// YAML-NEXT: DebugLoc:
// YAML:        File:            {{.*}}/devirtualize.sil
// YAML:        Line:            47
// YAML:        Column:          8
// YAML-NEXT: Function:        function_with_cm
// YAML-NEXT: Args:
// YAML-NEXT:   - String:          'Devirtualized call to class method '
// YAML-NEXT:   - Method:          '"main.Bar.foo(_:)"'
// YAML-NEXT:     DebugLoc:
// YAML:            File:            {{.*}}/devirtualize.sil
// YAML:            Line:            53
// YAML:            Column:          6
// YAML-NEXT: ...

sil @function_with_cm : $@convention(thin) () -> () {
bb0:
  %0 = global_addr @x : $*Bar                     // users: %2, %3
  %1 = alloc_ref $Bar                             // user: %2
  store %1 to %0 : $*Bar                          // id: %2
  %3 = load %0 : $*Bar                            // users: %6, %5, %4
  %5 = class_method %1 : $Bar, #Bar.foo : (Bar) -> () -> (), $@convention(method) (@guaranteed Bar) -> () // user: %6
  %6 = apply %5(%1) : $@convention(method) (@guaranteed Bar) -> ()
  release_value %1 : $Bar
  %7 = tuple ()                                   // user: %8
  return %7 : $()                                 // id: %8
}

sil @_TFC4main3Bar3foofS0_FT_T_ : $@convention(method) (@guaranteed Bar) -> ()

sil_vtable Bar {
  #Bar.foo: @_TFC4main3Bar3foofS0_FT_T_
}

private class Node {
  @_hasStorage var index: Int { get set }
  init(index: Int)
   deinit
}

// CHECK-LABEL: sil private @class_method_apply
sil private @class_method_apply : $@convention(method) (@guaranteed Node) -> Int {
bb0(%0 : $Node):
  // CHECK: strong_retain %0
  strong_retain %0 : $Node
  // CHECK-NOT: class_method %0
  // CHECK: [[FUNC:%.*]] = function_ref @transparent_target
  %3 = class_method %0 : $Node, #Node.index!getter : (Node) -> () -> Int, $@convention(method) (@guaranteed Node) -> Int
  // CHECK: [[RESULT:%.*]] = apply [[FUNC]](%0)
  %4 = apply %3(%0) : $@convention(method) (@guaranteed Node) -> Int
  // CHECK: strong_release %0
  strong_release %0 : $Node
  // return [[RESULT]]
  return %4 : $Int
}

// YAML-NEXT: --- !Passed
// YAML-NEXT: Pass:            sil-devirtualizer
// YAML-NEXT: Name:            sil.ClassMethodDevirtualized
// YAML-NEXT: DebugLoc:
// YAML:        File:            {{.*}}/devirtualize.sil
// YAML:        Line:            74
// YAML:        Column:          8
// YAML-NEXT: Function:        class_method_apply
// YAML-NEXT: Args:
// YAML-NEXT:   - String:          'Devirtualized call to class method '
// YAML-NEXT:   - Method:          '"transparent_target"'
// YAML-NEXT:     DebugLoc:
// YAML:            File:            {{.*}}/devirtualize.sil
// YAML:            Line:            100
// YAML:            Column:          39
// YAML-NEXT: ...


// CHECK-LABEL: sil private [transparent] [noinline] @transparent_target
sil private [transparent] [noinline] @transparent_target : $@convention(method) (@guaranteed Node) -> Int {
bb0(%0 : $Node):
  %2 = ref_element_addr %0 : $Node, #Node.index
  %3 = load %2 : $*Int
  // CHECK: return
  return %3 : $Int
}

sil_vtable Node {
  #Node.index!getter: @transparent_target
}

private class B {
  class func foo() -> Int
}

private class C : B { }

sil @_TZFC4metaP33_7026FC13D35FB9700BACF693F51A99011B3foofMS0_FT_Si : $@convention(method) (@thick B.Type) -> Int

// CHECK-LABEL: sil private [noinline] @_TF4metaP33_7026FC13D35FB9700BACF693F51A99016callerFMCS_P33_7026FC13D35FB9700BACF693F51A99011CT_
sil private [noinline] @_TF4metaP33_7026FC13D35FB9700BACF693F51A99016callerFMCS_P33_7026FC13D35FB9700BACF693F51A99011CT_ : $@convention(method) (@thick C.Type) -> () {
bb0(%0 : $@thick C.Type):
  %2 = upcast %0 : $@thick C.Type to $@thick B.Type
  // CHECK-NOT: class_method
  // CHECK: function_ref @_TZFC4metaP33_7026FC13D35FB9700BACF693F51A99011B3foofMS0_FT_Si
  %3 = class_method %2 : $@thick B.Type, #B.foo : (B.Type) -> () -> Int, $@convention(method) (@thick B.Type) -> Int
  %4 = apply %3(%2) : $@convention(method) (@thick B.Type) -> Int
  %5 = tuple ()
  // CHECK: return
  return %5 : $()
}

// YAML-NEXT: --- !Passed
// YAML-NEXT: Pass:            sil-devirtualizer
// YAML-NEXT: Name:            sil.ClassMethodDevirtualized
// YAML-NEXT: DebugLoc:
// YAML:        File:            {{.*}}/devirtualize.sil
// YAML:        Line:            127
// YAML:        Column:          8
// YAML-NEXT: Function:        'caller(_:)'
// YAML-NEXT: Args:
// YAML-NEXT:   - String:          'Devirtualized call to class method '
// YAML-NEXT:   - Method:          '"static meta.B.foo(_:)"'
// YAML-NEXT:     DebugLoc:
// YAML:            File:            {{.*}}/devirtualize.sil
// YAML:            Line:            118
// YAML:            Column:          6
// YAML-NEXT: ...

sil_vtable B {
  #B.foo: @_TZFC4metaP33_7026FC13D35FB9700BACF693F51A99011B3foofMS0_FT_Si
}

sil_vtable C {
  #B.foo: @_TZFC4metaP33_7026FC13D35FB9700BACF693F51A99011B3foofMS0_FT_Si [inherited]
}