Skip to content

Commit 098759f

Browse files
committed
CopyPropagation for SILValues with ownership.
This is a simple "utility" pass that canonicalizes SSA SILValues with respect to copies and destroys. It is a self-contained, provably complete pass that eliminates spurious copy_value instructions from scalar SSA SILValues. It fundamentally depends on ownership SIL, but otherwise can be run efficiently after any other pass. It separates the pure problem of handling scalar SSA values from the more important and complex problems: - Promoting variables to SSA form (PredictableMemOps and Mem2Reg partially do this). - Optimizing copies within "SIL borrow" scopes (another mandatory pass will be introduced to do this). - Composing and decomposing aggregates (SROA handles some of this). - Coalescing phis (A BlockArgumentOptimizer will be introduced as part of AddressLowering). - Removing unnecessary retain/release when nothing within its scope may release the same object (ARC Code Motion does some of this). Note that removing SSA copies was more obviously necessary before the migration to +0 argument convention.
1 parent e3f3e93 commit 098759f

File tree

4 files changed

+1116
-0
lines changed

4 files changed

+1116
-0
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ PASS(ConditionForwarding, "condition-forwarding",
108108
"Conditional Branch Forwarding to Fold SIL switch_enum")
109109
PASS(CopyForwarding, "copy-forwarding",
110110
"Copy Forwarding to Remove Redundant Copies")
111+
PASS(CopyPropagation, "copy-propagation",
112+
"Copy propagation to Remove Redundant SSA Copies")
111113
PASS(EpilogueARCMatcherDumper, "sil-epilogue-arc-dumper",
112114
"Print Epilogue retains of Returned Values and Argument releases")
113115
PASS(EpilogueRetainReleaseMatcherDumper, "sil-epilogue-retain-release-dumper",

lib/SILOptimizer/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ silopt_register_sources(
99
CSE.cpp
1010
ConditionForwarding.cpp
1111
CopyForwarding.cpp
12+
CopyPropagation.cpp
1213
DeadCodeElimination.cpp
1314
DeadObjectElimination.cpp
1415
DeadStoreElimination.cpp

0 commit comments

Comments
 (0)