@@ -104,6 +104,9 @@ class SILGlobalOpt {
104
104
bool run ();
105
105
106
106
protected:
107
+ // / Checks if a given global variable is assigned only once.
108
+ bool isAssignedOnlyOnceInInitializer (SILGlobalVariable *SILG);
109
+
107
110
// / If this is a call to a global initializer, map it.
108
111
void collectGlobalInitCall (ApplyInst *AI);
109
112
@@ -595,15 +598,18 @@ static SILFunction *genGetterFromInit(SILOptFunctionBuilder &FunctionBuilder,
595
598
return GetterF;
596
599
}
597
600
598
- // / Checks if a given global variable is assigned only once.
599
- static bool isAssignedOnlyOnceInInitializer (SILGlobalVariable *SILG) {
601
+ bool SILGlobalOpt::isAssignedOnlyOnceInInitializer (SILGlobalVariable *SILG) {
600
602
if (SILG->isLet ())
601
603
return true ;
602
- // TODO: If we can prove that a given global variable
603
- // is assigned only once, during initialization, then
604
- // we can treat it as if it is a let.
605
- // If this global is internal or private, it should be
606
- return false ;
604
+
605
+ // If we should skip this, it is probably because there are multiple stores.
606
+ // Return false if there are multiple stores or no stores.
607
+ if (GlobalVarSkipProcessing.count (SILG) || !GlobalVarStore.count (SILG))
608
+ return false ;
609
+
610
+ // Otherwise, return true if this can't be used externally (false, otherwise).
611
+ return !isPossiblyUsedExternally (SILG->getLinkage (),
612
+ SILG->getModule ().isWholeModule ());
607
613
}
608
614
609
615
// / Replace load sequence which may contain
0 commit comments