Skip to content

Commit 4cd82bf

Browse files
committed
Minor cleanup of static initializer emission.
1 parent e17df96 commit 4cd82bf

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ void IRGenModuleDispatcher::emitGlobalTopLevel() {
807807
// Emit static initializers.
808808
for (auto Iter : *this) {
809809
IRGenModule *IGM = Iter.second;
810-
IGM->emitSILStaticInitializer();
810+
IGM->emitSILStaticInitializers();
811811
}
812812

813813
// Emit witness tables.

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ private: \
757757
void emitCoverageMapping();
758758
void emitSILFunction(SILFunction *f);
759759
void emitSILWitnessTable(SILWitnessTable *wt);
760-
void emitSILStaticInitializer();
760+
void emitSILStaticInitializers();
761761
llvm::Constant *emitFixedTypeLayout(CanType t, const FixedTypeInfo &ti);
762762

763763
void emitNestedTypeDecls(DeclRange members);

lib/IRGen/IRGenSIL.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4813,40 +4813,34 @@ static llvm::Constant *getConstantValue(IRGenModule &IGM, llvm::StructType *STy,
48134813
return llvm::ConstantStruct::get(STy, Elts);
48144814
}
48154815

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())
48214820
continue;
48224821

4823-
auto *gvar = Module.getGlobalVariable(v.getName(),
4824-
/*allowInternal*/true);
4822+
auto *IRGlobal =
4823+
Module.getGlobalVariable(Global.getName(), true /* = AllowLocal */);
48254824

48264825
// A check for multi-threaded compilation: Is this the llvm module where the
48274826
// global is defined and not only referenced (or not referenced at all).
4828-
if (!gvar || !gvar->hasInitializer())
4827+
if (!IRGlobal || !IRGlobal->hasInitializer())
48294828
continue;
48304829

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();
48334832

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;
48474838
}
48484839

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));
48504844
}
48514845
}
48524846

0 commit comments

Comments
 (0)