@@ -248,6 +248,12 @@ bool CrossModuleOptimization::canSerializeInstruction(SILInstruction *inst,
248248 if (!callee)
249249 return false ;
250250
251+ // In conservative mode we don't want to turn non-public functions into
252+ // public functions, because that can increase code size. E.g. if the
253+ // function is completely inlined afterwards.
254+ if (conservative && !hasPublicVisibility (callee->getLinkage ()))
255+ return false ;
256+
251257 // Recursivly walk down the call graph.
252258 if (canSerializeFunction (callee, canSerializeFlags, maxDepth - 1 ))
253259 return true ;
@@ -260,12 +266,12 @@ bool CrossModuleOptimization::canSerializeInstruction(SILInstruction *inst,
260266 if (!canUseFromInline (callee))
261267 return false ;
262268
263- // In conservative mode we don't want to turn non-public functions into
264- // public functions, because that can increase code size. E.g. if the
265- // function is completely inlined afterwards.
266- if (conservative && callee->getLinkage () != SILLinkage::Public)
269+ return true ;
270+ }
271+ if (auto *GAI = dyn_cast<GlobalAddrInst>(inst)) {
272+ SILGlobalVariable *global = GAI->getReferencedGlobal ();
273+ if (conservative && !hasPublicVisibility (global->getLinkage ()))
267274 return false ;
268-
269275 return true ;
270276 }
271277 if (auto *KPI = dyn_cast<KeyPathInst>(inst)) {
@@ -457,7 +463,7 @@ void CrossModuleOptimization::serializeInstruction(SILInstruction *inst,
457463 if (canSerializeGlobal (global)) {
458464 serializeGlobal (global);
459465 }
460- if (global->getLinkage () != SILLinkage::Public ) {
466+ if (! hasPublicVisibility ( global->getLinkage ()) ) {
461467 global->setLinkage (SILLinkage::Public);
462468 M.addPublicCMOSymbol (global->getName ());
463469 }
0 commit comments