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:
Erik Eckstein
2022-06-21 14:36:53 +02:00
parent 8b20c88914
commit 24d077e78b
13 changed files with 213 additions and 36 deletions

View File

@@ -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;