mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
IRGen: re-enable generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.
But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.
rdar://94185998
This reverts the revert commit df353ff3c0.
Also, I added a frontend option to disable this optimization: `-disable-readonly-static-objects`
This commit is contained in:
@@ -1785,6 +1785,19 @@ bool IRGenModule::shouldPrespecializeGenericMetadata() {
|
||||
canPrespecializeTarget;
|
||||
}
|
||||
|
||||
bool IRGenModule::canMakeStaticObjectsReadOnly() {
|
||||
if (getOptions().DisableReadonlyStaticObjects)
|
||||
return false;
|
||||
|
||||
// TODO: Support constant static arrays on other platforms, too.
|
||||
// See also the comment in GlobalObjects.cpp.
|
||||
if (!Triple.isOSDarwin())
|
||||
return false;
|
||||
|
||||
return getAvailabilityContext().isContainedIn(
|
||||
Context.getImmortalRefCountSymbolsAvailability());
|
||||
}
|
||||
|
||||
void IRGenerator::addGenModule(SourceFile *SF, IRGenModule *IGM) {
|
||||
assert(GenModules.count(SF) == 0);
|
||||
GenModules[SF] = IGM;
|
||||
|
||||
Reference in New Issue
Block a user