@@ -156,13 +156,14 @@ void CodeMotionOrDeleteCallback::processMatchingSet(ARCMatchingSet &MatchSet) {
156
156
}
157
157
158
158
// ===----------------------------------------------------------------------===//
159
- // Top Level Driver
159
+ // Non Loop Optimizer
160
160
// ===----------------------------------------------------------------------===//
161
161
162
- static bool processFunction (SILFunction &F, bool FreezePostDomRelease,
163
- AliasAnalysis *AA, PostOrderAnalysis *POTA,
164
- LoopRegionFunctionInfo *LRFI, SILLoopInfo *LI,
165
- RCIdentityFunctionInfo *RCIA) {
162
+ static bool processFunctionWithoutLoopSupport (SILFunction &F,
163
+ bool FreezePostDomRelease,
164
+ AliasAnalysis *AA,
165
+ PostOrderAnalysis *POTA,
166
+ RCIdentityFunctionInfo *RCIA) {
166
167
// GlobalARCOpts seems to be taking up a lot of compile time when running on
167
168
// globalinit_func. Since that is not *that* interesting from an ARC
168
169
// perspective (i.e. no ref count operations in a loop), disable it on such
@@ -177,8 +178,76 @@ static bool processFunction(SILFunction &F, bool FreezePostDomRelease,
177
178
// Construct our context once. A context contains the RPOT as well as maps
178
179
// that contain state for each BB in F. This is a major place where the
179
180
// optimizer allocates memory in one large chunk.
180
- auto *Ctx = createARCMatchingSetComputationContext (F, AA, POTA, LRFI, LI,
181
- RCIA, EnableLoopARC);
181
+ auto *Ctx = createARCMatchingSetComputationContext (F, AA, POTA, nullptr ,
182
+ nullptr , RCIA, false );
183
+
184
+ // If Ctx is null, we failed to initialize and can not do anything so just
185
+ // return false.
186
+ if (!Ctx) {
187
+ DEBUG (llvm::dbgs () << " Failed to initialize matching set computation "
188
+ " context! Bailing!\n " );
189
+ return false ;
190
+ }
191
+
192
+ CodeMotionOrDeleteCallback Callback;
193
+ // Until we do not remove any instructions or have nested increments,
194
+ // decrements...
195
+ while (true ) {
196
+ // Compute matching sets of increments, decrements, and their insertion
197
+ // points.
198
+ //
199
+ // We need to blot pointers we remove after processing an individual pointer
200
+ // so we don't process pairs after we have paired them up. Thus we pass in a
201
+ // lambda that performs the work for us.
202
+ bool ShouldRunAgain =
203
+ computeARCMatchingSet (Ctx, FreezePostDomRelease, Callback);
204
+
205
+ Changed |= Callback.madeChange ();
206
+
207
+ // If we did not remove any instructions or have any nested increments, do
208
+ // not perform another iteration.
209
+ if (!ShouldRunAgain)
210
+ break ;
211
+
212
+ // Otherwise, perform another iteration.
213
+ DEBUG (llvm::dbgs () << " \n <<< Made a Change! Reprocessing Function! >>>\n " );
214
+ }
215
+
216
+ // Now that we have finished our computation, destroy the matching set
217
+ // computation context.
218
+ destroyARCMatchingSetComputationContext (Ctx);
219
+
220
+ DEBUG (llvm::dbgs () << " \n " );
221
+
222
+ // Return true if we moved or deleted any instructions.
223
+ return Changed;
224
+ }
225
+
226
+ // ===----------------------------------------------------------------------===//
227
+ // Loop Optimizer
228
+ // ===----------------------------------------------------------------------===//
229
+
230
+ static bool
231
+ processFunctionWithLoopSupport (SILFunction &F, bool FreezePostDomRelease,
232
+ AliasAnalysis *AA, PostOrderAnalysis *POTA,
233
+ LoopRegionFunctionInfo *LRFI, SILLoopInfo *LI,
234
+ RCIdentityFunctionInfo *RCIA) {
235
+ // GlobalARCOpts seems to be taking up a lot of compile time when running on
236
+ // globalinit_func. Since that is not *that* interesting from an ARC
237
+ // perspective (i.e. no ref count operations in a loop), disable it on such
238
+ // functions temporarily in order to unblock others. This should be removed.
239
+ if (F.getName ().startswith (" globalinit_" ))
240
+ return false ;
241
+
242
+ DEBUG (llvm::dbgs () << " ***** Processing " << F.getName () << " *****\n " );
243
+
244
+ bool Changed = false ;
245
+
246
+ // Construct our context once. A context contains the RPOT as well as maps
247
+ // that contain state for each BB in F. This is a major place where the
248
+ // optimizer allocates memory in one large chunk.
249
+ auto *Ctx =
250
+ createARCMatchingSetComputationContext (F, AA, POTA, LRFI, LI, RCIA, true );
182
251
183
252
// If Ctx is null, we failed to initialize and can not do anything so just
184
253
// return false.
@@ -222,6 +291,10 @@ static bool processFunction(SILFunction &F, bool FreezePostDomRelease,
222
291
return Changed;
223
292
}
224
293
294
+ // ===----------------------------------------------------------------------===//
295
+ // Top Level Driver
296
+ // ===----------------------------------------------------------------------===//
297
+
225
298
namespace {
226
299
class ARCSequenceOpts : public SILFunctionTransform {
227
300
// / The entry point to the transformation.
@@ -237,8 +310,8 @@ class ARCSequenceOpts : public SILFunctionTransform {
237
310
auto *POTA = getAnalysis<PostOrderAnalysis>();
238
311
auto *RCFI = getAnalysis<RCIdentityAnalysis>()->get (F);
239
312
240
- if (processFunction (*F, false , AA, POTA, nullptr , nullptr , RCFI)) {
241
- processFunction (*F, true , AA, POTA, nullptr , nullptr , RCFI);
313
+ if (processFunctionWithoutLoopSupport (*F, false , AA, POTA, RCFI)) {
314
+ processFunctionWithoutLoopSupport (*F, true , AA, POTA, RCFI);
242
315
invalidateAnalysis (SILAnalysis::InvalidationKind::CallsAndInstructions);
243
316
}
244
317
return ;
@@ -264,14 +337,15 @@ class ARCSequenceOpts : public SILFunctionTransform {
264
337
auto *RCFI = getAnalysis<RCIdentityAnalysis>()->get (F);
265
338
auto *LRFI = getAnalysis<LoopRegionAnalysis>()->get (F);
266
339
267
- if (processFunction (*F, false , AA, POTA, LRFI, LI, RCFI)) {
268
- processFunction (*F, true , AA, POTA, LRFI, LI, RCFI);
340
+ if (processFunctionWithLoopSupport (*F, false , AA, POTA, LRFI, LI, RCFI)) {
341
+ processFunctionWithLoopSupport (*F, true , AA, POTA, LRFI, LI, RCFI);
269
342
invalidateAnalysis (SILAnalysis::InvalidationKind::CallsAndInstructions);
270
343
}
271
344
}
272
345
273
346
StringRef getName () override { return " ARC Sequence Opts" ; }
274
347
};
348
+
275
349
} // end anonymous namespace
276
350
277
351
0 commit comments