Skip to content

Commit 9f6407a

Browse files
committed
[IRGen] Skip metadata heapification on flag.
If the -enable-pack-metadata-stack-promotion[=true] flag is passed, skip eager heapification.
1 parent 6e34b18 commit 9f6407a

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

lib/IRGen/GenPack.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,12 @@ irgen::emitTypeMetadataPackRef(IRGenFunction &IGF, CanPackType packType,
512512
metadata = IGF.Builder.CreatePointerCast(
513513
metadata, IGF.IGM.TypeMetadataPtrTy->getPointerTo());
514514

515-
metadata = IGF.Builder.CreateCall(
516-
IGF.IGM.getAllocateMetadataPackFunctionPointer(), {metadata, shape});
515+
if (!IGF.canStackPromotePackMetadata()) {
516+
metadata = IGF.Builder.CreateCall(
517+
IGF.IGM.getAllocateMetadataPackFunctionPointer(), {metadata, shape});
517518

518-
cleanupTypeMetadataPack(IGF, pack, shape);
519+
cleanupTypeMetadataPack(IGF, pack, shape);
520+
}
519521

520522
auto response = MetadataResponse::forComplete(metadata);
521523
IGF.setScopedLocalTypeMetadata(packType, response);
@@ -674,10 +676,12 @@ llvm::Value *irgen::emitWitnessTablePackRef(IRGenFunction &IGF,
674676
result = IGF.Builder.CreatePointerCast(
675677
result, IGF.IGM.WitnessTablePtrTy->getPointerTo());
676678

677-
result = IGF.Builder.CreateCall(
678-
IGF.IGM.getAllocateWitnessTablePackFunctionPointer(), {result, shape});
679+
if (!IGF.canStackPromotePackMetadata()) {
680+
result = IGF.Builder.CreateCall(
681+
IGF.IGM.getAllocateWitnessTablePackFunctionPointer(), {result, shape});
679682

680-
cleanupWitnessTablePack(IGF, pack, shape);
683+
cleanupWitnessTablePack(IGF, pack, shape);
684+
}
681685

682686
IGF.setScopedLocalTypeData(packType, localDataKind, result);
683687

lib/IRGen/IRGenFunction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ OptimizationMode IRGenFunction::getEffectiveOptimizationMode() const {
7676
return IGM.getOptions().OptMode;
7777
}
7878

79+
bool IRGenFunction::canStackPromotePackMetadata() const {
80+
return IGM.getSILModule().getOptions().EnablePackMetadataStackPromotion &&
81+
!packMetadataStackPromotionDisabled;
82+
}
83+
7984
ModuleDecl *IRGenFunction::getSwiftModule() const {
8085
return IGM.getSwiftModule();
8186
}

lib/IRGen/IRGenFunction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ class IRGenFunction {
201201
llvm::Value *AsyncCoroutineCurrentResume = nullptr;
202202
llvm::Value *AsyncCoroutineCurrentContinuationContext = nullptr;
203203

204+
// Whether pack metadata stack promotion is disabled for this function in
205+
// particular.
206+
bool packMetadataStackPromotionDisabled = false;
207+
204208
Address asyncContextLocation;
205209

206210
/// The unique block that calls @llvm.coro.end.
@@ -229,6 +233,10 @@ class IRGenFunction {
229233
return getEffectiveOptimizationMode() == OptimizationMode::ForSize;
230234
}
231235

236+
/// Whether metadata/wtable packs allocated on the stack must be eagerly
237+
/// heapified.
238+
bool canStackPromotePackMetadata() const;
239+
232240
void setupAsync(unsigned asyncContextIndex);
233241
bool isAsync() const { return asyncContextLocation.isValid(); }
234242

0 commit comments

Comments
 (0)