Skip to content

Commit 6a853fa

Browse files
committed
IRGen: Co-locate metadata instatiation/completions/accessor functions in a special section
For spatial locality on startup. rdar://101593202
1 parent 958832d commit 6a853fa

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,7 @@ static llvm::Function *emitObjCMetadataUpdateFunction(IRGenModule &IGM,
25112511
llvm::Function *f =
25122512
IGM.getAddrOfObjCMetadataUpdateFunction(D, ForDefinition);
25132513
f->setAttributes(IGM.constructInitialAttributes());
2514+
IGM.setColocateMetadataSection(f);
25142515

25152516
IRGenFunction IGF(IGM, f);
25162517
if (IGM.DebugInfo)

lib/IRGen/GenDecl.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,7 @@ void IRGenerator::emitEagerClassInitialization() {
19741974
IGM->DebugInfo->emitArtificialFunction(RegisterIGF, RegisterIGF.CurFn);
19751975
RegisterFn->setAttributes(IGM->constructInitialAttributes());
19761976
RegisterFn->setCallingConv(IGM->DefaultCC);
1977+
IGM->setColocateMetadataSection(RegisterFn);
19771978

19781979
for (ClassDecl *CD : ClassesForEagerInitialization) {
19791980
auto Ty = CD->getDeclaredType()->getCanonicalType();
@@ -2017,6 +2018,7 @@ void IRGenerator::emitObjCActorsNeedingSuperclassSwizzle() {
20172018
IGM->DebugInfo->emitArtificialFunction(RegisterIGF, RegisterIGF.CurFn);
20182019
RegisterFn->setAttributes(IGM->constructInitialAttributes());
20192020
RegisterFn->setCallingConv(IGM->DefaultCC);
2021+
IGM->setColocateMetadataSection(RegisterFn);
20202022

20212023
// Look up the SwiftNativeNSObject class.
20222024
auto swiftNativeNSObjectName =
@@ -5853,3 +5855,24 @@ IRGenModule::getOrCreateHelperFunction(StringRef fnName, llvm::Type *resultTy,
58535855

58545856
return fn;
58555857
}
5858+
5859+
void IRGenModule::setColocateMetadataSection(llvm::Function *f) {
5860+
switch (TargetInfo.OutputObjectFormat) {
5861+
case llvm::Triple::MachO:
5862+
f->setSection("__TEXT, __swift_colocat, regular");
5863+
break;
5864+
case llvm::Triple::DXContainer:
5865+
case llvm::Triple::GOFF:
5866+
case llvm::Triple::SPIRV:
5867+
case llvm::Triple::UnknownObjectFormat:
5868+
break;
5869+
case llvm::Triple::Wasm:
5870+
case llvm::Triple::ELF:
5871+
f->setSection("swift_colocate_functions");
5872+
break;
5873+
case llvm::Triple::XCOFF:
5874+
case llvm::Triple::COFF:
5875+
f->setSection(".sw5colo$B");
5876+
break;
5877+
}
5878+
}

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static void emitMetadataCompletionFunction(IRGenModule &IGM,
206206
f->setAttributes(IGM.constructInitialAttributes());
207207
f->setDoesNotThrow();
208208
IGM.setHasNoFramePointer(f);
209+
IGM.setColocateMetadataSection(f);
209210

210211
IRGenFunction IGF(IGM, f);
211212

@@ -2969,6 +2970,7 @@ namespace {
29692970
f->setAttributes(IGM.constructInitialAttributes());
29702971
f->setDoesNotThrow();
29712972
IGM.setHasNoFramePointer(f);
2973+
IGM.setColocateMetadataSection(f);
29722974

29732975
IRGenFunction IGF(IGM, f);
29742976

lib/IRGen/IRGenModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,8 @@ private: \
15751575
void appendLLVMUsedConditionalEntry(llvm::GlobalVariable *var,
15761576
const ProtocolConformance *conformance);
15771577

1578+
void setColocateMetadataSection(llvm::Function *f);
1579+
15781580
llvm::Constant *
15791581
getAddrOfTypeMetadata(CanType concreteType,
15801582
TypeMetadataCanonicality canonicality =

lib/IRGen/MetadataRequest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,7 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM, llvm::Function *accessor,
20522052
accessor->addFnAttr(llvm::Attribute::NoInline);
20532053
// Accessor functions don't need frame pointers.
20542054
IGM.setHasNoFramePointer(accessor);
2055+
IGM.setColocateMetadataSection(accessor);
20552056

20562057
// This function is logically 'readnone': the caller does not need
20572058
// to reason about any side effects or stores it might perform.
@@ -2404,6 +2405,7 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction(
24042405
generateThunkFn,
24052406
/*noinline*/ true));
24062407
}
2408+
IGM.setColocateMetadataSection(thunkFn);
24072409

24082410
// Call out to the helper.
24092411
auto arg0 = numArguments >= 1
@@ -2674,6 +2676,8 @@ irgen::getGenericTypeMetadataAccessFunction(IRGenModule &IGM,
26742676
llvm::Function *accessor =
26752677
IGM.getAddrOfGenericTypeMetadataAccessFunction(
26762678
nominal, genericArgs.Types, shouldDefine);
2679+
if (shouldDefine)
2680+
IGM.setColocateMetadataSection(accessor);
26772681

26782682
// If we're not supposed to define the accessor, or if we already
26792683
// have defined it, just return the pointer.
@@ -2917,6 +2921,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,
29172921
IGM.setHasNoFramePointer(subIGF.CurFn);
29182922
if (IGM.DebugInfo)
29192923
IGM.DebugInfo->emitArtificialFunction(subIGF, subIGF.CurFn);
2924+
IGM.setColocateMetadataSection(subIGF.CurFn);
29202925

29212926
auto params = subIGF.collectParameters();
29222927
auto cache = params.claimNext();

0 commit comments

Comments
 (0)