File: inline_devirtualize_specialize.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 (102 lines) | stat: -rw-r--r-- 3,170 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
// RUN: %target-sil-opt -enable-sil-verify-all %s -devirtualizer -generic-specializer -inline -dce | %FileCheck %s

sil_stage canonical

import Builtin

protocol P {
  func foo() -> Builtin.Int1
}

struct S : P {
  func foo() -> Builtin.Int1
}

private class C : P {
  func foo() -> Builtin.Int1
}

// CHECK-LABEL: struct_target
sil [always_inline] @struct_target : $@convention(method) (S) -> Builtin.Int1 {
// CHECK: bb0
bb0(%0 : $S):
  %2 = integer_literal $Builtin.Int1, 0
  return %2 : $Builtin.Int1
}

// CHECK-LABEL: struct_witness
sil [always_inline] [thunk] @struct_witness : $@convention(witness_method: P) (@in_guaranteed S) -> Builtin.Int1 {
// CHECK: bb0
bb0(%0 : $*S):
  // CHECK-NOT: load
  %1 = load %0 : $*S
  // CHECK-NOT: function_ref
  %2 = function_ref @struct_target : $@convention(method) (S) -> Builtin.Int1
  // CHECK-NOT: apply
  %3 = apply %2(%1) : $@convention(method) (S) -> Builtin.Int1
  // CHECK: [[ZERO:%.*]] = integer_literal $Builtin.Int1, 0
  // CHECK: return [[ZERO]]
  return %3 : $Builtin.Int1
}

// CHECK-LABEL: struct_caller
sil shared @struct_caller : $@convention(thin) (@in S) -> Builtin.Int1 {
// CHECK: bb0
bb0(%0 : $*S):
  // CHECK-NOT: witness_method
  %2 = witness_method $S, #P.foo : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Builtin.Int1
  // CHECK-NOT: apply
  %3 = apply %2<S>(%0) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Builtin.Int1
  // CHECK: [[ZERO:%.*]] = integer_literal $Builtin.Int1, 0
  // CHECK: return [[ZERO]]
  destroy_addr %0 : $*S
  return %3 : $Builtin.Int1
}

// CHECK-LABEL: class_target
sil [always_inline] @class_target : $@convention(method) (@guaranteed C) -> Builtin.Int1 {
bb0(%0 : $C):
  %1 = integer_literal $Builtin.Int1, -1
  return %1 : $Builtin.Int1
}

// CHECK-LABEL: class_witness
sil [always_inline] [thunk] @class_witness : $@convention(witness_method: P) (@in_guaranteed C) -> Builtin.Int1 {
// CHECK: bb0
bb0(%0 : $*C):
  // CHECK-NOT: load
  %1 = load %0 : $*C
  // CHECK-NOT: class_method
  %3 = class_method %1 : $C, #C.foo : (C) -> () -> Builtin.Int1, $@convention(method) (@guaranteed C) -> Builtin.Int1
  // CHECK-NOT: apply
  %4 = apply %3(%1) : $@convention(method) (@guaranteed C) -> Builtin.Int1
  // CHECK: [[ONE:%.*]] = integer_literal $Builtin.Int1, -1
  // CHECK: return [[ONE]]
  return %4 : $Builtin.Int1
}

// CHECK-LABEL: class_caller
sil shared @class_caller : $@convention(thin) (@in C) -> Builtin.Int1 {
// CHECK: bb0
bb0(%0 : $*C):
  // CHECK-NOT: witness_method
  %1 = witness_method $C, #P.foo : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Builtin.Int1
  // CHECK-NOT: apply
  %2 = apply %1<C>(%0) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Builtin.Int1
  destroy_addr %0 : $*C
  // CHECK: [[ONE:%.*]] = integer_literal $Builtin.Int1, -1
  // CHECK: return [[ONE]]
  return %2 : $Builtin.Int1
}

sil_vtable C {
  #C.foo: @class_target
}

sil_witness_table C: P module main {
  method #P.foo: @class_witness
}

sil_witness_table S: P module main {
  method #P.foo: @struct_witness
}