Skip to content

Commit df15ca1

Browse files
committed
[PassManager] Process the function in a bottom-up order.
This commit changes the order in which we process the functions in the module from module order to bottom-up order. Right now this change should not make any noticeable difference, but soon we'll be able to make the inliner a function pass and improve the caching of our inter-procedural analysis like side-effects analysis.
1 parent 44fdbd8 commit df15ca1

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lib/SILPasses/PassManager/PassManager.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/SILPasses/Transforms.h"
2020
#include "llvm/ADT/Statistic.h"
2121
#include "llvm/ADT/StringSwitch.h"
22+
#include "swift/SILAnalysis/FunctionOrder.h"
2223
#include "llvm/Support/CommandLine.h"
2324
#include "llvm/Support/Debug.h"
2425
#include "llvm/Support/TimeValue.h"
@@ -160,21 +161,25 @@ SILPassManager::SILPassManager(SILModule *M, llvm::StringRef Stage) :
160161
bool SILPassManager::runFunctionPasses(PassList FuncTransforms) {
161162
const SILOptions &Options = getOptions();
162163

163-
for (auto &F : *Mod) {
164-
if (F.empty())
164+
BasicCalleeAnalysis *BCA = getAnalysis<BasicCalleeAnalysis>();
165+
BottomUpFunctionOrder BottomUpOrder(*Mod, BCA);
166+
auto BottomUpFunctions = BottomUpOrder.getFunctions();
167+
168+
for (auto *F : BottomUpFunctions) {
169+
if (F->empty())
165170
continue;
166171

167172
// Don't optimize functions that are marked with the opt.never attribute.
168-
if (!F.shouldOptimize())
173+
if (!F->shouldOptimize())
169174
continue;
170175

171-
CompletedPasses &completedPasses = CompletedPassesMap[&F];
176+
CompletedPasses &completedPasses = CompletedPassesMap[F];
172177

173178
for (auto SFT : FuncTransforms) {
174179
PrettyStackTraceSILFunctionTransform X(SFT);
175180
SFT->injectPassManager(this);
176-
SFT->injectFunction(&F);
177-
181+
SFT->injectFunction(F);
182+
178183
// If nothing changed since the last run of this pass, we can skip this
179184
// pass.
180185
if (completedPasses.test((size_t)SFT->getPassKind()))
@@ -188,13 +193,13 @@ bool SILPassManager::runFunctionPasses(PassList FuncTransforms) {
188193
if (SILPrintPassName)
189194
llvm::dbgs() << "#" << NumPassesRun << " Stage: " << StageName
190195
<< " Pass: " << SFT->getName()
191-
<< ", Function: " << F.getName() << "\n";
196+
<< ", Function: " << F->getName() << "\n";
192197

193-
if (doPrintBefore(SFT, &F)) {
198+
if (doPrintBefore(SFT, F)) {
194199
llvm::dbgs() << "*** SIL function before " << StageName << " "
195200
<< SFT->getName() << " (" << NumOptimizationIterations
196201
<< ") ***\n";
197-
F.dump(Options.EmitVerboseSIL);
202+
F->dump(Options.EmitVerboseSIL);
198203
}
199204

200205
llvm::sys::TimeValue StartTime = llvm::sys::TimeValue::now();
@@ -205,17 +210,17 @@ bool SILPassManager::runFunctionPasses(PassList FuncTransforms) {
205210
if (SILPrintPassTime) {
206211
auto Delta = llvm::sys::TimeValue::now().nanoseconds() -
207212
StartTime.nanoseconds();
208-
llvm::dbgs() << Delta << " (" << SFT->getName() << "," << F.getName()
213+
llvm::dbgs() << Delta << " (" << SFT->getName() << "," << F->getName()
209214
<< ")\n";
210215
}
211216

212217
// If this pass invalidated anything, print and verify.
213-
if (doPrintAfter(SFT, &F,
218+
if (doPrintAfter(SFT, F,
214219
currentPassHasInvalidated && SILPrintAll)) {
215220
llvm::dbgs() << "*** SIL function after " << StageName << " "
216221
<< SFT->getName() << " (" << NumOptimizationIterations
217222
<< ") ***\n";
218-
F.dump(Options.EmitVerboseSIL);
223+
F->dump(Options.EmitVerboseSIL);
219224
}
220225

221226
// Remember if this pass didn't change anything.
@@ -224,8 +229,8 @@ bool SILPassManager::runFunctionPasses(PassList FuncTransforms) {
224229

225230
if (Options.VerifyAll &&
226231
(currentPassHasInvalidated || SILVerifyWithoutInvalidation)) {
227-
F.verify();
228-
verifyAnalyses(&F);
232+
F->verify();
233+
verifyAnalyses(F);
229234
}
230235

231236
++NumPassesRun;

0 commit comments

Comments
 (0)