mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Optimizer: support static initialization of global arrays
The buffer of global arrays could already be statically initialized. The missing piece was the array itself, which is basically a reference to the array buffer. For example: ``` var a = [1, 2, 3] ``` ends up in two statically initialized globals: 1. the array buffer, which contains the elements 2. the variable `a` which is a single reference (= pointer) of the array buffer This optimization removes the need for lazy initialization of such variables. rdar://127757554
This commit is contained in:
@@ -355,6 +355,9 @@ Explosion irgen::emitConstantValue(IRGenModule &IGM, SILValue operand,
|
||||
} else if (auto *CFI = dyn_cast<ConvertFunctionInst>(operand)) {
|
||||
return emitConstantValue(IGM, CFI->getOperand(), flatten);
|
||||
|
||||
} else if (auto *URCI = dyn_cast<UncheckedRefCastInst>(operand)) {
|
||||
return emitConstantValue(IGM, URCI->getOperand(), flatten);
|
||||
|
||||
} else if (auto *T2TFI = dyn_cast<ThinToThickFunctionInst>(operand)) {
|
||||
SILType type = operand->getType();
|
||||
auto *sTy = cast<llvm::StructType>(IGM.getTypeInfo(type).getStorageType());
|
||||
@@ -405,6 +408,14 @@ Explosion irgen::emitConstantValue(IRGenModule &IGM, SILValue operand,
|
||||
return llvm::ConstantPointerNull::get(IGM.OpaquePtrTy);
|
||||
}
|
||||
|
||||
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti, NotForDefinition);
|
||||
return addr.getAddress();
|
||||
} else if (auto *gVal = dyn_cast<GlobalValueInst>(operand)) {
|
||||
assert(IGM.canMakeStaticObjectReadOnly(gVal->getType()));
|
||||
SILGlobalVariable *var = gVal->getReferencedGlobal();
|
||||
auto &ti = IGM.getTypeInfo(var->getLoweredType());
|
||||
auto expansion = IGM.getResilienceExpansionForLayout(var);
|
||||
assert(ti.isFixedSize(expansion));
|
||||
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti, NotForDefinition);
|
||||
return addr.getAddress();
|
||||
} else if (auto *atp = dyn_cast<AddressToPointerInst>(operand)) {
|
||||
|
||||
Reference in New Issue
Block a user