Skip to content

Commit f7fc125

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

File tree

1 file changed

+2
-53
lines changed

1 file changed

+2
-53
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ class DeadFunctionAndGlobalElimination {
154154
return AliveFunctionsAndTables.count(F) != 0;
155155
}
156156

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

186-
AliveFunctionsAndTables.insert(WT);
187181
for (const SILWitnessTable::Entry &entry : WT->getEntries()) {
188182
switch (entry.getKind()) {
189183
case SILWitnessTable::Method: {
@@ -201,27 +195,13 @@ class DeadFunctionAndGlobalElimination {
201195
}
202196
} break;
203197

204-
case SILWitnessTable::AssociatedConformance: {
205-
ProtocolConformanceRef CRef =
206-
entry.getAssociatedConformanceWitness().Witness;
207-
if (CRef.isConcrete())
208-
ensureAliveConformance(CRef.getConcrete());
209-
break;
210-
}
198+
case SILWitnessTable::AssociatedConformance:
211199
case SILWitnessTable::BaseProtocol:
212-
ensureAliveConformance(entry.getBaseProtocolWitness().Witness);
213-
break;
214-
215200
case SILWitnessTable::Invalid:
216201
case SILWitnessTable::AssociatedType:
217202
break;
218203
}
219204
}
220-
221-
for (const auto &conf : WT->getConditionalConformances()) {
222-
if (conf.isConcrete())
223-
ensureAliveConformance(conf.getConcrete());
224-
}
225205
}
226206

227207
/// Marks the \p global and all functions, which are referenced from its
@@ -279,14 +259,6 @@ class DeadFunctionAndGlobalElimination {
279259
makeAlive(global);
280260
}
281261

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-
290262
/// Returns true if the implementation of method \p FD in class \p ImplCl
291263
/// may be called when the type of the class_method's operand is \p MethodCl.
292264
/// Both, \p MethodCl and \p ImplCl, may by null if not known or if it's a
@@ -338,13 +310,7 @@ class DeadFunctionAndGlobalElimination {
338310
return;
339311
mi->methodIsCalled = true;
340312
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-
}
313+
makeAlive(FImpl.F);
348314
}
349315
}
350316

@@ -613,11 +579,6 @@ class DeadFunctionAndGlobalElimination {
613579
MethodInfo *mi = getMethodInfo(fd, /*isWitnessTable*/ true);
614580
ensureAliveProtocolMethod(mi);
615581
}
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);
621582
}
622583

623584
// Check default witness methods.
@@ -763,18 +724,6 @@ class DeadFunctionAndGlobalElimination {
763724
}
764725
}
765726

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

0 commit comments

Comments
 (0)