@@ -63,10 +63,14 @@ class CrossModuleSerializationSetup {
63
63
64
64
bool canSerialize (SILInstruction *inst, bool lookIntoThunks);
65
65
66
+ bool canSerialize (SILGlobalVariable *global);
67
+
66
68
bool canSerialize (SILType type);
67
69
68
70
void setUpForSerialization (SILFunction *F);
69
71
72
+ void setUpForSerialization (SILGlobalVariable *global);
73
+
70
74
void prepareInstructionForSerialization (SILInstruction *inst);
71
75
72
76
void handleReferencedFunction (SILFunction *F);
@@ -241,9 +245,6 @@ static void makeFunctionUsableFromInline(SILFunction *F) {
241
245
// / referenced function onto the worklist.
242
246
void CrossModuleSerializationSetup::
243
247
prepareInstructionForSerialization (SILInstruction *inst) {
244
- // Make all types of the instruction usable from inline.
245
- InstructionVisitor::visitInst (inst, *this );
246
-
247
248
// Put callees onto the worklist if they should be serialized as well.
248
249
if (auto *FRI = dyn_cast<FunctionRefBaseInst>(inst)) {
249
250
SILFunction *callee = FRI->getReferencedFunctionOrNull ();
@@ -252,8 +253,11 @@ prepareInstructionForSerialization(SILInstruction *inst) {
252
253
return ;
253
254
}
254
255
if (auto *GAI = dyn_cast<GlobalAddrInst>(inst)) {
255
- GAI->getReferencedGlobal ()->setSerialized (IsSerialized);
256
- GAI->getReferencedGlobal ()->setLinkage (SILLinkage::Public);
256
+ SILGlobalVariable *gl = GAI->getReferencedGlobal ();
257
+ if (canSerialize (gl)) {
258
+ setUpForSerialization (gl);
259
+ }
260
+ gl->setLinkage (SILLinkage::Public);
257
261
return ;
258
262
}
259
263
if (auto *MI = dyn_cast<MethodInst>(inst)) {
@@ -353,6 +357,15 @@ bool CrossModuleSerializationSetup::canSerialize(SILInstruction *inst,
353
357
return true ;
354
358
}
355
359
360
+ bool CrossModuleSerializationSetup::canSerialize (SILGlobalVariable *global) {
361
+ for (const SILInstruction &initInst : *global) {
362
+ if (!canSerialize (const_cast <SILInstruction *>(&initInst),
363
+ /* lookIntoThunks*/ true ))
364
+ return false ;
365
+ }
366
+ return true ;
367
+ }
368
+
356
369
bool CrossModuleSerializationSetup::canSerialize (SILType type) {
357
370
auto iter = typesChecked.find (type);
358
371
if (iter != typesChecked.end ())
@@ -421,6 +434,9 @@ void CrossModuleSerializationSetup::setUpForSerialization(SILFunction *F) {
421
434
// for serialization.
422
435
for (SILBasicBlock &block : *F) {
423
436
for (SILInstruction &inst : block) {
437
+ // Make all types of the instruction usable from inline.
438
+ InstructionVisitor::visitInst (&inst, *this );
439
+
424
440
prepareInstructionForSerialization (&inst);
425
441
}
426
442
}
@@ -439,6 +455,14 @@ void CrossModuleSerializationSetup::setUpForSerialization(SILFunction *F) {
439
455
}
440
456
}
441
457
458
+ void CrossModuleSerializationSetup::
459
+ setUpForSerialization (SILGlobalVariable *global) {
460
+ for (const SILInstruction &initInst : *global) {
461
+ prepareInstructionForSerialization (const_cast <SILInstruction *>(&initInst));
462
+ }
463
+ global->setSerialized (IsSerialized);
464
+ }
465
+
442
466
// / Select functions in the module which should be serialized.
443
467
void CrossModuleSerializationSetup::scanModule () {
444
468
0 commit comments