29
29
30
30
using namespace swift ;
31
31
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.
36
35
//
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." ));
52
41
53
42
namespace {
54
43
55
44
struct AccessMarkerElimination {
56
45
SILModule *Mod;
57
46
SILFunction *F;
58
- bool isFullElimination;
59
47
60
48
bool removedAny = false ;
61
49
62
- AccessMarkerElimination (SILFunction *F, bool isFullElimination )
63
- : Mod(&F->getModule ()), F(F), isFullElimination(isFullElimination) {}
50
+ AccessMarkerElimination (SILFunction *F)
51
+ : Mod(&F->getModule ()), F(F) {}
64
52
65
53
SILBasicBlock::iterator eraseInst (SILInstruction *inst) {
66
54
DEBUG (llvm::dbgs () << " Erasing access marker: " << *inst);
@@ -70,7 +58,6 @@ struct AccessMarkerElimination {
70
58
71
59
void replaceBeginAccessUsers (BeginAccessInst *beginAccess);
72
60
73
- // Precondition: !EnableAccessMarkers || isFullElimination
74
61
bool shouldPreserveAccess (SILAccessEnforcement enforcement);
75
62
76
63
// Check if the instruction is a marker that should be eliminated. If so,
@@ -100,26 +87,18 @@ void AccessMarkerElimination::replaceBeginAccessUsers(
100
87
}
101
88
}
102
89
103
- // Precondition: !EnableAccessMarkers || isFullElimination
104
90
bool AccessMarkerElimination::shouldPreserveAccess (
105
91
SILAccessEnforcement enforcement) {
106
- if (isFullElimination )
92
+ if (!EnableOptimizedAccessMarkers )
107
93
return false ;
108
94
109
95
switch (enforcement) {
110
- case SILAccessEnforcement::Unknown:
111
- return false ;
112
96
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 ;
121
97
case SILAccessEnforcement::Unsafe:
122
98
return false ;
99
+ case SILAccessEnforcement::Unknown:
100
+ case SILAccessEnforcement::Dynamic:
101
+ return Mod->getOptions ().EnforceExclusivityDynamic ;
123
102
}
124
103
}
125
104
@@ -162,10 +141,6 @@ bool AccessMarkerElimination::checkAndEliminateMarker(SILInstruction *inst) {
162
141
// Top-level per-function entry-point.
163
142
// Return `true` if any markers were removed.
164
143
bool AccessMarkerElimination::stripMarkers () {
165
- // FIXME: When dynamic markers are fully supported, just skip this pass:
166
- // if (EnableAccessMarkers && !isFullElimination)
167
- // return false;
168
-
169
144
// Iterating in reverse eliminates more begin_access users before they
170
145
// need to be replaced.
171
146
for (auto &BB : reversed (*F)) {
@@ -186,19 +161,16 @@ bool AccessMarkerElimination::stripMarkers() {
186
161
static void prepareSILFunctionForOptimization (ModuleDecl *, SILFunction *F) {
187
162
DEBUG (llvm::dbgs () << " Stripping all markers in: " << F->getName () << " \n " );
188
163
189
- AccessMarkerElimination (F, /* isFullElimination= */ true ).stripMarkers ();
164
+ AccessMarkerElimination (F).stripMarkers ();
190
165
}
191
166
192
167
namespace {
193
168
194
169
struct AccessMarkerEliminationPass : SILModuleTransform {
195
- virtual bool isFullElimination () = 0;
196
-
197
170
void run () override {
198
171
auto &M = *getModule ();
199
172
for (auto &F : M) {
200
- bool removedAny = AccessMarkerElimination (&F, isFullElimination ())
201
- .stripMarkers ();
173
+ bool removedAny = AccessMarkerElimination (&F).stripMarkers ();
202
174
203
175
// Only invalidate analyses if we removed some markers.
204
176
if (removedAny) {
@@ -208,26 +180,14 @@ struct AccessMarkerEliminationPass : SILModuleTransform {
208
180
209
181
// Markers from all current SIL functions are stripped. Register a
210
182
// callback to strip an subsequently loaded functions on-the-fly.
211
- if (isFullElimination () )
183
+ if (!EnableOptimizedAccessMarkers )
212
184
M.registerDeserializationCallback (prepareSILFunctionForOptimization);
213
185
}
214
186
}
215
187
};
216
188
217
- struct InactiveAccessMarkerElimination : AccessMarkerEliminationPass {
218
- virtual bool isFullElimination () { return false ; }
219
- };
220
-
221
- struct FullAccessMarkerElimination : AccessMarkerEliminationPass {
222
- virtual bool isFullElimination () { return true ; }
223
- };
224
-
225
189
} // end anonymous namespace
226
190
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 ();
233
193
}
0 commit comments