Skip to content

Commit 85760d5

Browse files
committed
SIL: Add a PartialApplySimplification pass.
This will turn `partial_apply` instructions into explicit box construction and extraction code sequences. To begin with, recognize when a private function is only used in partial applications and directly modify the function to be usable as a closure invocation function. This simplifies the lowering in IRGen and avoids generating a "partial application forwarder" thunk.
1 parent f66d9bd commit 85760d5

File tree

5 files changed

+672
-0
lines changed

5 files changed

+672
-0
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ PASS(MoveFunctionCanonicalization, "sil-move-function-canon",
446446
"function checking.")
447447
PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
448448
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
449+
PASS(PartialApplySimplification, "partial-apply-simplification",
450+
"Transform partial_apply instructions into explicit closure box constructions")
449451
PASS(PruneVTables, "prune-vtables",
450452
"Mark class methods that do not require vtable dispatch")
451453
PASS_RANGE(AllPasses, AADumper, PruneVTables)

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,16 @@ SILPassPipelinePlan::getIRGenPreparePassPipeline(const SILOptions &Options) {
825825
SILPassPipelinePlan P(Options);
826826
P.startPipeline("IRGen Preparation");
827827
// Insert SIL passes to run during IRGen.
828+
/*
829+
// Simplify partial_apply instructions by expanding box construction into
830+
// component operations.
831+
P.addPartialApplySimplification();
832+
*/
828833
// Hoist generic alloc_stack instructions to the entry block to enable better
829834
// llvm-ir generation for dynamic alloca instructions.
830835
P.addAllocStackHoisting();
836+
// Change large loadable types to be passed indirectly across function
837+
// boundaries as required by the ABI.
831838
P.addLoadableByAddress();
832839

833840
return P;

lib/SILOptimizer/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ target_sources(swiftSILOptimizer PRIVATE
2525
Outliner.cpp
2626
ObjectOutliner.cpp
2727
AssemblyVisionRemarkGenerator.cpp
28+
PartialApplySimplification.cpp
2829
PerformanceInliner.cpp
2930
PhiArgumentOptimizations.cpp
3031
PruneVTables.cpp

0 commit comments

Comments
 (0)