File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -135,15 +135,14 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
135
135
<< PrevF << " \n " );
136
136
if (!PrevF)
137
137
continue ;
138
+ assert (PrevF->isExternalDeclaration () &&
139
+ " Prespecialized function should be an external declaration" );
138
140
NewF = PrevF;
139
141
}
140
142
141
143
if (!NewF)
142
144
continue ;
143
145
144
- assert (NewF->isExternalDeclaration () &&
145
- " Prespecialized function should be an external declaration" );
146
-
147
146
// An existing specialization was found.
148
147
DEBUG (llvm::dbgs () << " Found a specialization of " << ReferencedF->getName ()
149
148
<< " : " << NewF->getName () << " \n " );
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend -emit-ir %s -module-name main | FileCheck %s
2
+
3
+ sil_stage canonical
4
+
5
+ struct Box<T> {
6
+ @inline(never)
7
+ static func foo() {}
8
+ }
9
+
10
+ // Reference a function in a way that will be specialized.
11
+ sil @test : $@convention(thin) () -> () {
12
+ bb0:
13
+ // function_ref static Box.foo() -> ()
14
+ %0 = function_ref @_TZFV4main3Box3foofT_T_ : $@convention(thin) <τ_0_0> (@thin Box<τ_0_0>.Type) -> () // user: %2
15
+ %1 = metatype $@thin Box<()>.Type // user: %2
16
+ %2 = apply %0<()>(%1) : $@convention(thin) <τ_0_0> (@thin Box<τ_0_0>.Type) -> ()
17
+ %3 = tuple () // user: %4
18
+ return %3 : $() // id: %4
19
+ }
20
+
21
+ // This is the unspecialized form.
22
+ sil hidden @_TZFV4main3Box3foofT_T_ : $@convention(thin) <T> (@thin Box<T>.Type) -> () {
23
+ bb0(%0 : $@thin Box<T>.Type):
24
+ %1 = tuple ()
25
+ return %1 : $()
26
+ }
27
+
28
+ // generic specialization <()> of static main.Box.foo () -> ()
29
+ // This specialization is one that would be matched by the prespecialization
30
+ // pass.
31
+ sil shared @_TTSg5T____TZFV4main3Box3foofT_T_ : $@convention(thin) (@thin Box<()>.Type) -> () {
32
+ bb0(%0 : $@thin Box<()>.Type):
33
+ %1 = tuple ()
34
+ return %1 : $()
35
+ }
36
+
37
+ // CHECK-DAG: define linkonce_odr hidden void @_TTSg5T____TZFV4main3Box3foofT_T_() {{.*}}{
38
+ // CHECK-DAG: call void @_TTSg5T____TZFV4main3Box3foofT_T_()
You can’t perform that action at this time.
0 commit comments