@@ -4813,40 +4813,34 @@ static llvm::Constant *getConstantValue(IRGenModule &IGM, llvm::StructType *STy,
4813
4813
return llvm::ConstantStruct::get (STy, Elts);
4814
4814
}
4815
4815
4816
- void IRGenModule::emitSILStaticInitializer () {
4817
- SmallVector<SILFunction*, 8 > StaticInitializers;
4818
- for (SILGlobalVariable &v : SILMod->getSILGlobals ()) {
4819
- auto *staticInit = v.getInitializer ();
4820
- if (!staticInit)
4816
+ void IRGenModule::emitSILStaticInitializers () {
4817
+ SmallVector<SILFunction *, 8 > StaticInitializers;
4818
+ for (SILGlobalVariable &Global : SILMod->getSILGlobals ()) {
4819
+ if (!Global.getInitializer ())
4821
4820
continue ;
4822
4821
4823
- auto *gvar = Module. getGlobalVariable (v. getName (),
4824
- /* allowInternal */ true );
4822
+ auto *IRGlobal =
4823
+ Module. getGlobalVariable (Global. getName (), true /* = AllowLocal */ );
4825
4824
4826
4825
// A check for multi-threaded compilation: Is this the llvm module where the
4827
4826
// global is defined and not only referenced (or not referenced at all).
4828
- if (!gvar || !gvar ->hasInitializer ())
4827
+ if (!IRGlobal || !IRGlobal ->hasInitializer ())
4829
4828
continue ;
4830
4829
4831
- if ( auto *STy = dyn_cast <llvm::StructType>(gvar ->getInitializer ()->getType ())) {
4832
- auto *InitValue = v .getValueOfStaticInitializer ();
4830
+ auto *STy = cast <llvm::StructType>(IRGlobal ->getInitializer ()->getType ());
4831
+ auto *InitValue = Global .getValueOfStaticInitializer ();
4833
4832
4834
- // Get the StructInst that we write to the SILGlobalVariable.
4835
- if (auto *SI = dyn_cast<StructInst>(InitValue)) {
4836
- gvar->setInitializer (getConstantValue (*this , STy, SI));
4837
- continue ;
4838
- }
4839
-
4840
- // Get the TupleInst that we write to the SILGlobalVariable.
4841
- if (auto *TI = dyn_cast<TupleInst>(InitValue)) {
4842
- gvar->setInitializer (getConstantValue (*this , STy, TI));
4843
- continue ;
4844
- }
4845
-
4846
- llvm_unreachable (" We only handle StructInst and TupleInst for now!" );
4833
+ // Set the IR global's initializer to the constant for this SIL
4834
+ // struct.
4835
+ if (auto *SI = dyn_cast<StructInst>(InitValue)) {
4836
+ IRGlobal->setInitializer (getConstantValue (*this , STy, SI));
4837
+ continue ;
4847
4838
}
4848
4839
4849
- llvm_unreachable (" We only handle StructType for now!" );
4840
+ // Set the IR global's initializer to the constant for this SIL
4841
+ // tuple.
4842
+ auto *TI = cast<TupleInst>(InitValue);
4843
+ IRGlobal->setInitializer (getConstantValue (*this , STy, TI));
4850
4844
}
4851
4845
}
4852
4846
0 commit comments