@@ -1176,11 +1176,6 @@ static bool isLazilyEmittedFunction(SILFunction &f, SILModule &m) {
1176
1176
1177
1177
// Eagerly emit global variables that are externally visible.
1178
1178
static bool isLazilyEmittedGlobalVariable (SILGlobalVariable &v, SILModule &m) {
1179
- // FIXME: Eagerly emit statically-initialized objects due to an issue I
1180
- // have yet to debug.
1181
- if (v.isInitializedObject ())
1182
- return false ;
1183
-
1184
1179
if (v.isPossiblyUsedExternally ()) {
1185
1180
// Under the embedded linkage model, if it has a non-unique definition,
1186
1181
// treat it lazily.
@@ -2780,7 +2775,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
2780
2775
2781
2776
if (var->isInitializedObject ()) {
2782
2777
assert (ti.isFixedSize (expansion));
2783
- StructLayout *Layout = StaticObjectLayouts[var].get ();
2778
+ StructLayout *Layout = StaticObjectLayouts[var].layout . get ();
2784
2779
if (!Layout) {
2785
2780
// Create the layout (includes the llvm type) for the statically
2786
2781
// initialized object and store it for later.
@@ -2791,7 +2786,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
2791
2786
}
2792
2787
Layout = getClassLayoutWithTailElems (*this ,
2793
2788
var->getLoweredType (), TailTypes);
2794
- StaticObjectLayouts[var] = std::unique_ptr<StructLayout>(Layout);
2789
+ StaticObjectLayouts[var] = { std::unique_ptr<StructLayout>(Layout), nullptr } ;
2795
2790
}
2796
2791
storageType = Layout->getType ();
2797
2792
fixedSize = Layout->getSize ();
@@ -2907,7 +2902,7 @@ llvm::Constant *IRGenModule::getGlobalInitValue(SILGlobalVariable *var,
2907
2902
llvm::Type *storageType,
2908
2903
Alignment alignment) {
2909
2904
if (var->isInitializedObject ()) {
2910
- StructLayout *layout = StaticObjectLayouts[var].get ();
2905
+ StructLayout *layout = StaticObjectLayouts[var].layout . get ();
2911
2906
ObjectInst *oi = cast<ObjectInst>(var->getStaticInitializerValue ());
2912
2907
llvm::Constant *initVal = emitConstantObject (*this , oi, layout);
2913
2908
if (!canMakeStaticObjectReadOnly (var->getLoweredType ())) {
@@ -2917,13 +2912,18 @@ llvm::Constant *IRGenModule::getGlobalInitValue(SILGlobalVariable *var,
2917
2912
// swift_once_t token[fixedAlignment / sizeof(swift_once_t)];
2918
2913
// HeapObject object;
2919
2914
// };
2920
- std::string typeName = storageType->getStructName ().str () + ' c' ;
2921
- assert (alignment >= getPointerAlignment ());
2922
- unsigned numTokens = alignment.getValue () /
2923
- getPointerAlignment ().getValue ();
2924
- auto *containerTy = llvm::StructType::create (getLLVMContext (),
2925
- {llvm::ArrayType::get (OnceTy, numTokens), initVal->getType ()},
2926
- typeName);
2915
+ llvm::StructType *containerTy = StaticObjectLayouts[var].containerTy ;
2916
+ if (!containerTy) {
2917
+ std::string typeName = storageType->getStructName ().str () + ' c' ;
2918
+ assert (alignment >= getPointerAlignment ());
2919
+ unsigned numTokens = alignment.getValue () /
2920
+ getPointerAlignment ().getValue ();
2921
+ containerTy = llvm::StructType::create (getLLVMContext (),
2922
+ {llvm::ArrayType::get (OnceTy, numTokens), initVal->getType ()},
2923
+ typeName);
2924
+ StaticObjectLayouts[var].containerTy = containerTy;
2925
+ }
2926
+
2927
2927
auto *zero = llvm::ConstantAggregateZero::get (containerTy->getElementType (0 ));
2928
2928
initVal = llvm::ConstantStruct::get (containerTy, {zero , initVal});
2929
2929
}
0 commit comments