Skip to content

Commit 91bba4d

Browse files
author
Joe Shajrawi
authored
Do not emit shadow copied for inout parameters (#5218)
radar rdar://problem/28434323 SILGen has no reason to insert shadow copies for inout parameters any more. They cannot be captured. We still emit these copies. Sometimes deshadowing removes them, but sometimes it does not. In this PR we just avoid emitting the copies and remove the deshadowing pass. This PR chery-picked some of @dduan work and built on top of it.
1 parent 6584406 commit 91bba4d

24 files changed

+95
-736
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ PASS(HighLevelLICM, "high-level-licm",
133133
"High Level Loop invariant code motion")
134134
PASS(IVInfoPrinter, "iv-info-printer",
135135
"Display induction variable information")
136-
PASS(InOutDeshadowing, "inout-deshadow",
137-
"Remove inout argument shadow variables")
138136
PASS(InstCount, "inst-count",
139137
"Count all instructions in the module using llvm Statistics")
140138
PASS(JumpThreadSimplifyCFG, "simplify-cfg",

lib/SIL/TypeLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture) {
121121
if (var->isLet() && !getTypeLowering(var->getType()).isAddressOnly())
122122
return CaptureKind::Constant;
123123

124+
if (var->getType()->is<InOutType>()) {
125+
return CaptureKind::StorageAddress;
126+
}
127+
124128
// If we're capturing into a non-escaping closure, we can generally just
125129
// capture the address of the value as no-escape.
126130
return capture.isNoEscape() ?

lib/SILGen/SILGenProlog.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,18 @@ struct ArgumentInitHelper {
262262
gen.B.createDebugValueAddr(loc, address, {vd->isLet(), ArgNo});
263263
return;
264264
}
265-
266-
// Allocate the local variable for the inout.
267-
auto initVar = gen.emitLocalVariableWithCleanup(vd, false, ArgNo);
268-
269-
// Initialize with the value from the inout with an "autogenerated"
270-
// copyaddr.
271-
loc.markAutoGenerated();
272-
gen.B.createCopyAddr(loc, address, initVar->getAddress(),
273-
IsNotTake, IsInitialization);
274-
initVar->finishInitialization(gen);
275-
276-
// Set up a cleanup to write back to the inout.
277-
gen.Cleanups.pushCleanup<CleanupWriteBackToInOut>(vd, address);
265+
assert(argrv.getType().isAddress() && "expected inout to be address");
278266
} else {
279267
assert(vd->isLet() && "expected parameter to be immutable!");
280268
// If the variable is immutable, we can bind the value as is.
281269
// Leave the cleanup on the argument, if any, in place to consume the
282270
// argument if we're responsible for it.
283-
gen.VarLocs[vd] = SILGenFunction::VarLoc::get(argrv.getValue());
284-
if (argrv.getType().isAddress())
285-
gen.B.createDebugValueAddr(loc, argrv.getValue(), {vd->isLet(), ArgNo});
286-
else
287-
gen.B.createDebugValue(loc, argrv.getValue(), {vd->isLet(), ArgNo});
288271
}
272+
gen.VarLocs[vd] = SILGenFunction::VarLoc::get(argrv.getValue());
273+
if (argrv.getType().isAddress())
274+
gen.B.createDebugValueAddr(loc, argrv.getValue(), {vd->isLet(), ArgNo});
275+
else
276+
gen.B.createDebugValue(loc, argrv.getValue(), {vd->isLet(), ArgNo});
289277
}
290278

291279
void emitParam(ParamDecl *PD) {

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ set(MANDATORY_SOURCES
66
Mandatory/DiagnoseUnreachable.cpp
77
Mandatory/PredictableMemOpt.cpp
88
Mandatory/ConstantPropagation.cpp
9-
Mandatory/InOutDeshadowing.cpp
109
PARENT_SCOPE)

lib/SILOptimizer/Mandatory/InOutDeshadowing.cpp

Lines changed: 0 additions & 321 deletions
This file was deleted.

lib/SILOptimizer/PassManager/Passes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ bool swift::runSILDiagnosticPasses(SILModule &Module) {
8989
// Otherwise run the rest of diagnostics.
9090
PM.addCapturePromotion();
9191
PM.addAllocBoxToStack();
92-
PM.addInOutDeshadowing();
9392
PM.addNoReturnFolding();
9493
PM.addDefiniteInitialization();
9594

0 commit comments

Comments
 (0)