Skip to content

Commit db744c6

Browse files
authored
Merge pull request #10770 from atrick/exclusivity
2 parents 834a7d5 + d45f171 commit db744c6

File tree

4 files changed

+23
-66
lines changed

4 files changed

+23
-66
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ PASS(AccessEnforcementSelection, "access-enforcement-selection",
5858
"Access Enforcement Selection")
5959
PASS(AccessSummaryDumper, "access-summary-dump",
6060
"Dump Address Parameter Access Summary")
61-
PASS(InactiveAccessMarkerElimination, "inactive-access-marker-elim",
62-
"Inactive Access Marker Elimination.")
63-
PASS(FullAccessMarkerElimination, "full-access-marker-elim",
64-
"Full Access Marker Elimination.")
61+
PASS(AccessMarkerElimination, "access-marker-elim",
62+
"Access Marker Elimination.")
6563
PASS(AddressLowering, "address-lowering",
6664
"SIL Address Lowering")
6765
PASS(AllocBoxToStack, "allocbox-to-stack",

lib/SILOptimizer/Mandatory/AccessMarkerElimination.cpp

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,26 @@
2929

3030
using namespace swift;
3131

32-
// This option allows markers to remain in -Onone as a structural SIL property.
33-
// Regardless of this option, sufficient markers are always emitted to satisfy
34-
// the current enforcement level. This options simply allows markers to remain
35-
// for testing and validation.
32+
// This temporary option allows markers during optimization passes. Enabling
33+
// this flag causes this pass to preserve only dynamic checks when dynamic
34+
// checking is enabled. Otherwise, this pass removes all checks.
3635
//
37-
// This option only applies to InactiveAccessMarkerElimination. Any occurrence
38-
// of FullAccessMarkerElimination in the pass pipeline effectively overrides the
39-
// options and removes all markers.
40-
//
41-
// At -Onone, with EnableMarkers, no static markers are removed.
42-
// With !EnableMarkers:
43-
// Enforcement | Static | Dynamic
44-
// none | Remove after Diag | Remove ASAP
45-
// unchecked | Remain through IRGen | Remove ASAP
46-
// checked | Remain through IRGen | Remain through IRGen
47-
// dynamic-only| Remove after Diag | Remain through IRGen
48-
llvm::cl::opt<bool> EnableAccessMarkers(
49-
"sil-access-markers", llvm::cl::init(true),
50-
llvm::cl::desc("Enable memory access makers that aren't needed for "
51-
"diagnostics."));
36+
// This is currently unsupported because tail duplication results in
37+
// address-type block arguments.
38+
llvm::cl::opt<bool> EnableOptimizedAccessMarkers(
39+
"sil-optimized-access-markers", llvm::cl::init(false),
40+
llvm::cl::desc("Enable memory access markers during optimization passes."));
5241

5342
namespace {
5443

5544
struct AccessMarkerElimination {
5645
SILModule *Mod;
5746
SILFunction *F;
58-
bool isFullElimination;
5947

6048
bool removedAny = false;
6149

62-
AccessMarkerElimination(SILFunction *F, bool isFullElimination)
63-
: Mod(&F->getModule()), F(F), isFullElimination(isFullElimination) {}
50+
AccessMarkerElimination(SILFunction *F)
51+
: Mod(&F->getModule()), F(F) {}
6452

6553
SILBasicBlock::iterator eraseInst(SILInstruction *inst) {
6654
DEBUG(llvm::dbgs() << "Erasing access marker: " << *inst);
@@ -70,7 +58,6 @@ struct AccessMarkerElimination {
7058

7159
void replaceBeginAccessUsers(BeginAccessInst *beginAccess);
7260

73-
// Precondition: !EnableAccessMarkers || isFullElimination
7461
bool shouldPreserveAccess(SILAccessEnforcement enforcement);
7562

7663
// Check if the instruction is a marker that should be eliminated. If so,
@@ -100,26 +87,18 @@ void AccessMarkerElimination::replaceBeginAccessUsers(
10087
}
10188
}
10289

103-
// Precondition: !EnableAccessMarkers || isFullElimination
10490
bool AccessMarkerElimination::shouldPreserveAccess(
10591
SILAccessEnforcement enforcement) {
106-
if (isFullElimination)
92+
if (!EnableOptimizedAccessMarkers)
10793
return false;
10894

10995
switch (enforcement) {
110-
case SILAccessEnforcement::Unknown:
111-
return false;
11296
case SILAccessEnforcement::Static:
113-
// Even though static enforcement is already performed, this flag is
114-
// useful to control marker preservation for now.
115-
return EnableAccessMarkers || Mod->getOptions().EnforceExclusivityStatic;
116-
case SILAccessEnforcement::Dynamic:
117-
// FIXME: when dynamic markers are fully supported, don't strip:
118-
// return
119-
// EnableAccessMarkers || Mod->getOptions().EnforceExclusivityDynamic;
120-
return Mod->getOptions().EnforceExclusivityDynamic;
12197
case SILAccessEnforcement::Unsafe:
12298
return false;
99+
case SILAccessEnforcement::Unknown:
100+
case SILAccessEnforcement::Dynamic:
101+
return Mod->getOptions().EnforceExclusivityDynamic;
123102
}
124103
}
125104

@@ -162,10 +141,6 @@ bool AccessMarkerElimination::checkAndEliminateMarker(SILInstruction *inst) {
162141
// Top-level per-function entry-point.
163142
// Return `true` if any markers were removed.
164143
bool AccessMarkerElimination::stripMarkers() {
165-
// FIXME: When dynamic markers are fully supported, just skip this pass:
166-
// if (EnableAccessMarkers && !isFullElimination)
167-
// return false;
168-
169144
// Iterating in reverse eliminates more begin_access users before they
170145
// need to be replaced.
171146
for (auto &BB : reversed(*F)) {
@@ -186,19 +161,16 @@ bool AccessMarkerElimination::stripMarkers() {
186161
static void prepareSILFunctionForOptimization(ModuleDecl *, SILFunction *F) {
187162
DEBUG(llvm::dbgs() << "Stripping all markers in: " << F->getName() << "\n");
188163

189-
AccessMarkerElimination(F, /*isFullElimination=*/true).stripMarkers();
164+
AccessMarkerElimination(F).stripMarkers();
190165
}
191166

192167
namespace {
193168

194169
struct AccessMarkerEliminationPass : SILModuleTransform {
195-
virtual bool isFullElimination() = 0;
196-
197170
void run() override {
198171
auto &M = *getModule();
199172
for (auto &F : M) {
200-
bool removedAny = AccessMarkerElimination(&F, isFullElimination())
201-
.stripMarkers();
173+
bool removedAny = AccessMarkerElimination(&F).stripMarkers();
202174

203175
// Only invalidate analyses if we removed some markers.
204176
if (removedAny) {
@@ -208,26 +180,14 @@ struct AccessMarkerEliminationPass : SILModuleTransform {
208180

209181
// Markers from all current SIL functions are stripped. Register a
210182
// callback to strip an subsequently loaded functions on-the-fly.
211-
if (isFullElimination())
183+
if (!EnableOptimizedAccessMarkers)
212184
M.registerDeserializationCallback(prepareSILFunctionForOptimization);
213185
}
214186
}
215187
};
216188

217-
struct InactiveAccessMarkerElimination : AccessMarkerEliminationPass {
218-
virtual bool isFullElimination() { return false; }
219-
};
220-
221-
struct FullAccessMarkerElimination : AccessMarkerEliminationPass {
222-
virtual bool isFullElimination() { return true; }
223-
};
224-
225189
} // end anonymous namespace
226190

227-
SILTransform *swift::createInactiveAccessMarkerElimination() {
228-
return new InactiveAccessMarkerElimination();
229-
}
230-
231-
SILTransform *swift::createFullAccessMarkerElimination() {
232-
return new FullAccessMarkerElimination();
191+
SILTransform *swift::createAccessMarkerElimination() {
192+
return new AccessMarkerEliminationPass();
233193
}

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
8383
// Select access kind after capture promotion and before stack promotion.
8484
// This guarantees that stack-promotable boxes have [static] enforcement.
8585
P.addAccessEnforcementSelection();
86-
P.addInactiveAccessMarkerElimination();
8786

8887
P.addAllocBoxToStack();
8988
P.addNoReturnFolding();
@@ -454,7 +453,7 @@ SILPassPipelinePlan::getSILOptPreparePassPipeline(const SILOptions &Options) {
454453
}
455454

456455
P.startPipeline("SILOpt Prepare Passes");
457-
P.addFullAccessMarkerElimination();
456+
P.addAccessMarkerElimination();
458457

459458
return P;
460459
}

test/SILOptimizer/access_marker_elim.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enforce-exclusivity=checked -emit-sorted-sil -full-access-marker-elim %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enforce-exclusivity=checked -emit-sorted-sil -access-marker-elim %s | %FileCheck %s
22

33
sil_stage raw
44

0 commit comments

Comments
 (0)