Skip to content

Commit 41a4cea

Browse files
committed
[Distributed] SILOpt: Make sure that ad-hoc function does not get eliminated as unused
1 parent 560e96f commit 41a4cea

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/SILOptimizer/Analysis/CallerAnalysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ CallerAnalysis::FunctionInfo::FunctionInfo(SILFunction *f)
3333
: callerStates(),
3434
// TODO: Make this more aggressive by considering
3535
// final/visibility/etc.
36-
mayHaveIndirectCallers(f->getDynamicallyReplacedFunction() ||
37-
canBeCalledIndirectly(f->getRepresentation())),
36+
mayHaveIndirectCallers(
37+
f->getDynamicallyReplacedFunction() ||
38+
f->getReferencedAdHocRequirementWitnessFunction() ||
39+
canBeCalledIndirectly(f->getRepresentation())),
3840
mayHaveExternalCallers(f->isPossiblyUsedExternally() ||
3941
f->isAvailableExternally()) {}
4042

lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ bool FunctionSignatureTransform::run(bool hasCaller) {
646646
hasCaller |= FSOOptimizeIfNotCalled;
647647

648648
if (!hasCaller && (F->getDynamicallyReplacedFunction() ||
649+
F->getReferencedAdHocRequirementWitnessFunction() ||
649650
canBeCalledIndirectly(F->getRepresentation()))) {
650651
LLVM_DEBUG(llvm::dbgs() << " function has no caller -> abort\n");
651652
return false;

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class DeadFunctionAndGlobalElimination {
101101
if (F->isDynamicallyReplaceable())
102102
return true;
103103

104+
if (F->getReferencedAdHocRequirementWitnessFunction())
105+
return true;
106+
104107
// Don't remove pre-specialized functions. We need to preserver the
105108
// pre-specialization specifications from other modules.
106109
if (F->hasPrespecialization())
@@ -325,6 +328,9 @@ class DeadFunctionAndGlobalElimination {
325328

326329
LLVM_DEBUG(llvm::dbgs() << " scan function " << F->getName() << '\n');
327330

331+
if (auto *adHocWitness = F->getReferencedAdHocRequirementWitnessFunction())
332+
ensureAlive(adHocWitness);
333+
328334
// First scan all instructions of the function.
329335
for (SILBasicBlock &BB : *F) {
330336
for (SILInstruction &I : BB) {

0 commit comments

Comments
 (0)