11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#define DEBUG_TYPE " sil-dead-function-elimination"
14
+ #include " swift/AST/PackConformance.h"
14
15
#include " swift/AST/ProtocolConformance.h"
15
16
#include " swift/Basic/Assertions.h"
16
17
#include " swift/SIL/InstructionUtils.h"
@@ -154,11 +155,6 @@ class DeadFunctionAndGlobalElimination {
154
155
return AliveFunctionsAndTables.count (F) != 0 ;
155
156
}
156
157
157
- // / Returns true if a witness table is marked as alive.
158
- bool isAlive (SILWitnessTable *WT) {
159
- return AliveFunctionsAndTables.count (WT) != 0 ;
160
- }
161
-
162
158
// / Returns true if a global variable is marked as alive.
163
159
bool isAlive (SILGlobalVariable *global) {
164
160
return AliveFunctionsAndTables.count (global) != 0 ;
@@ -183,7 +179,6 @@ class DeadFunctionAndGlobalElimination {
183
179
LLVM_DEBUG (llvm::dbgs () << " scan witness table " << WT->getName ()
184
180
<< ' \n ' );
185
181
186
- AliveFunctionsAndTables.insert (WT);
187
182
for (const SILWitnessTable::Entry &entry : WT->getEntries ()) {
188
183
switch (entry.getKind ()) {
189
184
case SILWitnessTable::Method: {
@@ -201,27 +196,13 @@ class DeadFunctionAndGlobalElimination {
201
196
}
202
197
} break ;
203
198
204
- case SILWitnessTable::AssociatedConformance: {
205
- ProtocolConformanceRef CRef =
206
- entry.getAssociatedConformanceWitness ().Witness ;
207
- if (CRef.isConcrete ())
208
- ensureAliveConformance (CRef.getConcrete ());
209
- break ;
210
- }
199
+ case SILWitnessTable::AssociatedConformance:
211
200
case SILWitnessTable::BaseProtocol:
212
- ensureAliveConformance (entry.getBaseProtocolWitness ().Witness );
213
- break ;
214
-
215
201
case SILWitnessTable::Invalid:
216
202
case SILWitnessTable::AssociatedType:
217
203
break ;
218
204
}
219
205
}
220
-
221
- for (const auto &conf : WT->getConditionalConformances ()) {
222
- if (conf.isConcrete ())
223
- ensureAliveConformance (conf.getConcrete ());
224
- }
225
206
}
226
207
227
208
// / Marks the \p global and all functions, which are referenced from its
@@ -279,14 +260,6 @@ class DeadFunctionAndGlobalElimination {
279
260
makeAlive (global);
280
261
}
281
262
282
- // / Marks a witness table as alive if it is not alive yet.
283
- void ensureAliveConformance (const ProtocolConformance *C) {
284
- SILWitnessTable *WT = Module->lookUpWitnessTable (C);
285
- if (!WT || isAlive (WT))
286
- return ;
287
- makeAlive (WT);
288
- }
289
-
290
263
// / Returns true if the implementation of method \p FD in class \p ImplCl
291
264
// / may be called when the type of the class_method's operand is \p MethodCl.
292
265
// / Both, \p MethodCl and \p ImplCl, may by null if not known or if it's a
@@ -338,13 +311,7 @@ class DeadFunctionAndGlobalElimination {
338
311
return ;
339
312
mi->methodIsCalled = true ;
340
313
for (FuncImpl &FImpl : mi->implementingFunctions ) {
341
- if (auto Conf = FImpl.Impl .dyn_cast <ProtocolConformance *>()) {
342
- SILWitnessTable *WT = Module->lookUpWitnessTable (Conf);
343
- if (!WT || isAlive (WT))
344
- makeAlive (FImpl.F );
345
- } else {
346
- makeAlive (FImpl.F );
347
- }
314
+ makeAlive (FImpl.F );
348
315
}
349
316
}
350
317
@@ -613,11 +580,6 @@ class DeadFunctionAndGlobalElimination {
613
580
MethodInfo *mi = getMethodInfo (fd, /* isWitnessTable*/ true );
614
581
ensureAliveProtocolMethod (mi);
615
582
}
616
-
617
- // We don't do dead witness table elimination right now. So we assume
618
- // that all witness tables are alive. Dead witness table elimination is
619
- // done in IRGen by lazily emitting witness tables.
620
- makeAlive (&WT);
621
583
}
622
584
623
585
// Check default witness methods.
@@ -763,18 +725,6 @@ class DeadFunctionAndGlobalElimination {
763
725
}
764
726
}
765
727
766
- // Next step: delete dead witness tables.
767
- SILModule::WitnessTableListType &WTables = Module->getWitnessTableList ();
768
- for (auto Iter = WTables.begin (), End = WTables.end (); Iter != End;) {
769
- SILWitnessTable *Wt = &*Iter;
770
- Iter++;
771
- if (!isAlive (Wt)) {
772
- LLVM_DEBUG (llvm::dbgs () << " erase dead witness table "
773
- << Wt->getName () << ' \n ' );
774
- Module->deleteWitnessTable (Wt);
775
- }
776
- }
777
-
778
728
// Last step: delete all dead functions.
779
729
for (SILFunction *deadFunc : DeadFunctions) {
780
730
LLVM_DEBUG (llvm::dbgs () << " erase dead function " << deadFunc->getName ()
0 commit comments