Skip to content

Commit 0625b16

Browse files
committed
SILOptimizer: Remove witness table marking from DeadFunctionElimination
This logic was unconditionally disabled and incorrect.
1 parent cbd10b7 commit 0625b16

File tree

1 file changed

+3
-53
lines changed

1 file changed

+3
-53
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#define DEBUG_TYPE "sil-dead-function-elimination"
14+
#include "swift/AST/PackConformance.h"
1415
#include "swift/AST/ProtocolConformance.h"
1516
#include "swift/Basic/Assertions.h"
1617
#include "swift/SIL/InstructionUtils.h"
@@ -154,11 +155,6 @@ class DeadFunctionAndGlobalElimination {
154155
return AliveFunctionsAndTables.count(F) != 0;
155156
}
156157

157-
/// Returns true if a witness table is marked as alive.
158-
bool isAlive(SILWitnessTable *WT) {
159-
return AliveFunctionsAndTables.count(WT) != 0;
160-
}
161-
162158
/// Returns true if a global variable is marked as alive.
163159
bool isAlive(SILGlobalVariable *global) {
164160
return AliveFunctionsAndTables.count(global) != 0;
@@ -183,7 +179,6 @@ class DeadFunctionAndGlobalElimination {
183179
LLVM_DEBUG(llvm::dbgs() << " scan witness table " << WT->getName()
184180
<< '\n');
185181

186-
AliveFunctionsAndTables.insert(WT);
187182
for (const SILWitnessTable::Entry &entry : WT->getEntries()) {
188183
switch (entry.getKind()) {
189184
case SILWitnessTable::Method: {
@@ -201,27 +196,13 @@ class DeadFunctionAndGlobalElimination {
201196
}
202197
} break;
203198

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:
211200
case SILWitnessTable::BaseProtocol:
212-
ensureAliveConformance(entry.getBaseProtocolWitness().Witness);
213-
break;
214-
215201
case SILWitnessTable::Invalid:
216202
case SILWitnessTable::AssociatedType:
217203
break;
218204
}
219205
}
220-
221-
for (const auto &conf : WT->getConditionalConformances()) {
222-
if (conf.isConcrete())
223-
ensureAliveConformance(conf.getConcrete());
224-
}
225206
}
226207

227208
/// Marks the \p global and all functions, which are referenced from its
@@ -279,14 +260,6 @@ class DeadFunctionAndGlobalElimination {
279260
makeAlive(global);
280261
}
281262

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-
290263
/// Returns true if the implementation of method \p FD in class \p ImplCl
291264
/// may be called when the type of the class_method's operand is \p MethodCl.
292265
/// Both, \p MethodCl and \p ImplCl, may by null if not known or if it's a
@@ -338,13 +311,7 @@ class DeadFunctionAndGlobalElimination {
338311
return;
339312
mi->methodIsCalled = true;
340313
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);
348315
}
349316
}
350317

@@ -613,11 +580,6 @@ class DeadFunctionAndGlobalElimination {
613580
MethodInfo *mi = getMethodInfo(fd, /*isWitnessTable*/ true);
614581
ensureAliveProtocolMethod(mi);
615582
}
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);
621583
}
622584

623585
// Check default witness methods.
@@ -763,18 +725,6 @@ class DeadFunctionAndGlobalElimination {
763725
}
764726
}
765727

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-
778728
// Last step: delete all dead functions.
779729
for (SILFunction *deadFunc : DeadFunctions) {
780730
LLVM_DEBUG(llvm::dbgs() << " erase dead function " << deadFunc->getName()

0 commit comments

Comments
 (0)