Skip to content

Commit 9b211d4

Browse files
committed
[loop-arc] Prepare to remove opaque ARC pairing interfaces.
The ARC optimizer has been using opaque interface boundaries in between the pairing analysis and the actual optimization pass. This was necessary in order to not expose details from ARC pairing when the ARC pairing computation was split in between SILAnalysis and SILPasses. Now that is gone, I can remove this interface and simplify the layering. The other reason to do this is that the non-loop and loop ARC optimizers are going to start to differ a bit more since the loop optimizer is going to use a LoopVisitor.
1 parent 2faaa34 commit 9b211d4

File tree

1 file changed

+85
-11
lines changed

1 file changed

+85
-11
lines changed

lib/SILPasses/ARC/ARCSequenceOpts.cpp

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ void CodeMotionOrDeleteCallback::processMatchingSet(ARCMatchingSet &MatchSet) {
156156
}
157157

158158
//===----------------------------------------------------------------------===//
159-
// Top Level Driver
159+
// Non Loop Optimizer
160160
//===----------------------------------------------------------------------===//
161161

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) {
166167
// GlobalARCOpts seems to be taking up a lot of compile time when running on
167168
// globalinit_func. Since that is not *that* interesting from an ARC
168169
// 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,
177178
// Construct our context once. A context contains the RPOT as well as maps
178179
// that contain state for each BB in F. This is a major place where the
179180
// 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);
182251

183252
// If Ctx is null, we failed to initialize and can not do anything so just
184253
// return false.
@@ -222,6 +291,10 @@ static bool processFunction(SILFunction &F, bool FreezePostDomRelease,
222291
return Changed;
223292
}
224293

294+
//===----------------------------------------------------------------------===//
295+
// Top Level Driver
296+
//===----------------------------------------------------------------------===//
297+
225298
namespace {
226299
class ARCSequenceOpts : public SILFunctionTransform {
227300
/// The entry point to the transformation.
@@ -237,8 +310,8 @@ class ARCSequenceOpts : public SILFunctionTransform {
237310
auto *POTA = getAnalysis<PostOrderAnalysis>();
238311
auto *RCFI = getAnalysis<RCIdentityAnalysis>()->get(F);
239312

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);
242315
invalidateAnalysis(SILAnalysis::InvalidationKind::CallsAndInstructions);
243316
}
244317
return;
@@ -264,14 +337,15 @@ class ARCSequenceOpts : public SILFunctionTransform {
264337
auto *RCFI = getAnalysis<RCIdentityAnalysis>()->get(F);
265338
auto *LRFI = getAnalysis<LoopRegionAnalysis>()->get(F);
266339

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);
269342
invalidateAnalysis(SILAnalysis::InvalidationKind::CallsAndInstructions);
270343
}
271344
}
272345

273346
StringRef getName() override { return "ARC Sequence Opts"; }
274347
};
348+
275349
} // end anonymous namespace
276350

277351

0 commit comments

Comments
 (0)