blob: 98b7d9b76aaaad9b3ee8281bc72b31ac1a18ba2c [file] [log] [blame]
Chandler Carruth7caea412013-11-09 12:26:54 +00001//===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
Devang Patel6e5a1132006-11-07 21:31:57 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Devang Patel6e5a1132006-11-07 21:31:57 +00006//
7//===----------------------------------------------------------------------===//
8//
Chandler Carruth7caea412013-11-09 12:26:54 +00009// This file implements the legacy LLVM Pass Manager infrastructure.
Devang Patel6e5a1132006-11-07 21:31:57 +000010//
11//===----------------------------------------------------------------------===//
12
Chandler Carruth7caea412013-11-09 12:26:54 +000013#include "llvm/IR/LegacyPassManager.h"
Florian Hahna4ffa3a2018-05-24 21:33:17 +000014#include "llvm/ADT/MapVector.h"
James Henderson852f6fd2017-05-16 09:43:21 +000015#include "llvm/ADT/Statistic.h"
Jessica Paquettee49374d2018-05-18 17:26:39 +000016#include "llvm/IR/DiagnosticInfo.h"
Pavel Labathec534e62016-10-25 16:20:07 +000017#include "llvm/IR/IRPrintingPasses.h"
18#include "llvm/IR/LLVMContext.h"
Chandler Carruth7caea412013-11-09 12:26:54 +000019#include "llvm/IR/LegacyPassManagers.h"
Chandler Carruth1b69ed82014-03-04 12:32:42 +000020#include "llvm/IR/LegacyPassNameParser.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000021#include "llvm/IR/Module.h"
Fedor Sergeev43083112018-08-28 21:06:51 +000022#include "llvm/IR/PassTimingInfo.h"
Pavel Labathec534e62016-10-25 16:20:07 +000023#include "llvm/Support/Chrono.h"
Devang Patelf1567a52006-12-13 20:03:48 +000024#include "llvm/Support/CommandLine.h"
David Greene994e1bb2010-01-05 01:30:02 +000025#include "llvm/Support/Debug.h"
Peter Collingbourne7f00d0a2016-11-09 17:49:19 +000026#include "llvm/Support/Error.h"
Torok Edwin6dd27302009-07-08 18:01:40 +000027#include "llvm/Support/ErrorHandling.h"
Devang Patelb8817b92006-12-14 00:59:42 +000028#include "llvm/Support/ManagedStatic.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000029#include "llvm/Support/Mutex.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000030#include "llvm/Support/Timer.h"
31#include "llvm/Support/raw_ostream.h"
Jeff Cohenb622c112007-03-05 00:00:42 +000032#include <algorithm>
Weiming Zhao0f1762c2016-01-06 22:55:03 +000033#include <unordered_set>
Dan Gohman8c43e412007-10-03 19:04:09 +000034using namespace llvm;
Chandler Carruth7caea412013-11-09 12:26:54 +000035using namespace llvm::legacy;
Devang Patelffca9102006-12-15 19:39:30 +000036
Devang Patele7599552007-01-12 18:52:44 +000037// See PassManagers.h for Pass Manager infrastructure overview.
Devang Patel6fea2852006-12-07 18:23:30 +000038
Devang Patelf1567a52006-12-13 20:03:48 +000039//===----------------------------------------------------------------------===//
40// Pass debugging information. Often it is useful to find out what pass is
41// running when a crash occurs in a utility. When this library is compiled with
42// debugging on, a command line option (--debug-pass) is enabled that causes the
43// pass name to be printed before it executes.
44//
45
Chandler Carruth7caea412013-11-09 12:26:54 +000046namespace {
Devang Patel03fb5872006-12-13 21:13:31 +000047// Different debug levels that can be enabled...
48enum PassDebugLevel {
Dmitri Gribenko3238fb72013-05-05 00:40:33 +000049 Disabled, Arguments, Structure, Executions, Details
Devang Patel03fb5872006-12-13 21:13:31 +000050};
Chandler Carruth7caea412013-11-09 12:26:54 +000051}
Devang Patel03fb5872006-12-13 21:13:31 +000052
Andrew Trickb5e1e6c2013-09-19 06:02:43 +000053static cl::opt<enum PassDebugLevel>
54PassDebugging("debug-pass", cl::Hidden,
Devang Patelf1567a52006-12-13 20:03:48 +000055 cl::desc("Print PassManager debugging information"),
56 cl::values(
Andrew Trickb5e1e6c2013-09-19 06:02:43 +000057 clEnumVal(Disabled , "disable debug output"),
58 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
59 clEnumVal(Structure , "print pass structure before run()"),
60 clEnumVal(Executions, "print pass name before it is executed"),
Mehdi Amini732afdd2016-10-08 19:41:06 +000061 clEnumVal(Details , "print pass details when it is executed")));
David Greene9b063df2010-04-02 23:17:14 +000062
Chandler Carruth7caea412013-11-09 12:26:54 +000063namespace {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +000064typedef llvm::cl::list<const llvm::PassInfo *, bool, PassNameParser>
65PassOptionList;
Chandler Carruth7caea412013-11-09 12:26:54 +000066}
Andrew Trickb5e1e6c2013-09-19 06:02:43 +000067
68// Print IR out before/after specified passes.
69static PassOptionList
70PrintBefore("print-before",
71 llvm::cl::desc("Print IR before specified passes"),
72 cl::Hidden);
73
74static PassOptionList
75PrintAfter("print-after",
76 llvm::cl::desc("Print IR after specified passes"),
77 cl::Hidden);
78
Zachary Turner8065f0b2017-12-01 00:53:10 +000079static cl::opt<bool> PrintBeforeAll("print-before-all",
80 llvm::cl::desc("Print IR before each pass"),
81 cl::init(false), cl::Hidden);
82static cl::opt<bool> PrintAfterAll("print-after-all",
83 llvm::cl::desc("Print IR after each pass"),
84 cl::init(false), cl::Hidden);
Andrew Trickb5e1e6c2013-09-19 06:02:43 +000085
Fedor Sergeev94dca7c2017-12-01 17:42:46 +000086static cl::opt<bool>
87 PrintModuleScope("print-module-scope",
88 cl::desc("When printing IR for print-[before|after]{-all} "
89 "always print a module IR"),
Craig Topperf5730c32018-04-01 21:54:26 +000090 cl::init(false), cl::Hidden);
Fedor Sergeev94dca7c2017-12-01 17:42:46 +000091
Weiming Zhao0f1762c2016-01-06 22:55:03 +000092static cl::list<std::string>
93 PrintFuncsList("filter-print-funcs", cl::value_desc("function names"),
94 cl::desc("Only print IR for functions whose name "
95 "match this for all print-[before|after][-all] "
96 "options"),
Zachary Turner8065f0b2017-12-01 00:53:10 +000097 cl::CommaSeparated, cl::Hidden);
Weiming Zhao0f1762c2016-01-06 22:55:03 +000098
Andrew Trickb5e1e6c2013-09-19 06:02:43 +000099/// This is a helper to determine whether to print IR before or
100/// after a pass.
101
Fedor Sergeev662e5682018-09-24 16:08:15 +0000102bool llvm::shouldPrintBeforePass() {
103 return PrintBeforeAll || !PrintBefore.empty();
104}
105
106bool llvm::shouldPrintAfterPass() {
107 return PrintAfterAll || !PrintAfter.empty();
108}
109
110static bool ShouldPrintBeforeOrAfterPass(StringRef PassID,
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000111 PassOptionList &PassesToPrint) {
Chris Bieneman664294c2015-04-29 21:45:22 +0000112 for (auto *PassInf : PassesToPrint) {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000113 if (PassInf)
Fedor Sergeev662e5682018-09-24 16:08:15 +0000114 if (PassInf->getPassArgument() == PassID) {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000115 return true;
116 }
David Greene9b063df2010-04-02 23:17:14 +0000117 }
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000118 return false;
119}
Dan Gohmande6188a2010-08-12 23:50:08 +0000120
Fedor Sergeev662e5682018-09-24 16:08:15 +0000121bool llvm::shouldPrintBeforePass(StringRef PassID) {
122 return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PassID, PrintBefore);
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000123}
David Greene9b063df2010-04-02 23:17:14 +0000124
Fedor Sergeev662e5682018-09-24 16:08:15 +0000125bool llvm::shouldPrintAfterPass(StringRef PassID) {
126 return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PassID, PrintAfter);
David Greene9b063df2010-04-02 23:17:14 +0000127}
128
Fedor Sergeev94dca7c2017-12-01 17:42:46 +0000129bool llvm::forcePrintModuleIR() { return PrintModuleScope; }
130
Weiming Zhao0f1762c2016-01-06 22:55:03 +0000131bool llvm::isFunctionInPrintList(StringRef FunctionName) {
132 static std::unordered_set<std::string> PrintFuncNames(PrintFuncsList.begin(),
133 PrintFuncsList.end());
134 return PrintFuncNames.empty() || PrintFuncNames.count(FunctionName);
135}
Chris Lattnerd4d966f2009-09-15 05:03:04 +0000136/// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
137/// or higher is specified.
138bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000139 return PassDebugging >= Executions;
Chris Lattnerd4d966f2009-09-15 05:03:04 +0000140}
141
Jessica Paquettea0aa5b32018-09-06 21:19:54 +0000142unsigned PMDataManager::initSizeRemarkInfo(
143 Module &M, StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount) {
Jessica Paquettee49374d2018-05-18 17:26:39 +0000144 // Only calculate getInstructionCount if the size-info remark is requested.
Jessica Paquettea0aa5b32018-09-06 21:19:54 +0000145 unsigned InstrCount = 0;
146
147 // Collect instruction counts for every function. We'll use this to emit
148 // per-function size remarks later.
149 for (Function &F : M) {
150 unsigned FCount = F.getInstructionCount();
151
152 // Insert a record into FunctionToInstrCount keeping track of the current
153 // size of the function as the first member of a pair. Set the second
154 // member to 0; if the function is deleted by the pass, then when we get
155 // here, we'll be able to let the user know that F no longer contributes to
156 // the module.
157 FunctionToInstrCount[F.getName().str()] =
158 std::pair<unsigned, unsigned>(FCount, 0);
159 InstrCount += FCount;
160 }
161 return InstrCount;
Jessica Paquettee49374d2018-05-18 17:26:39 +0000162}
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000163
Jessica Paquettea0aa5b32018-09-06 21:19:54 +0000164void PMDataManager::emitInstrCountChangedRemark(
165 Pass *P, Module &M, int64_t Delta, unsigned CountBefore,
166 StringMap<std::pair<unsigned, unsigned>> &FunctionToInstrCount,
167 Function *F) {
Jessica Paquette397c05d2018-08-31 20:51:54 +0000168 // If it's a pass manager, don't emit a remark. (This hinges on the assumption
169 // that the only passes that return non-null with getAsPMDataManager are pass
170 // managers.) The reason we have to do this is to avoid emitting remarks for
171 // CGSCC passes.
172 if (P->getAsPMDataManager())
173 return;
174
Jessica Paquette31d2e5e2018-09-04 21:03:43 +0000175 // Set to true if this isn't a module pass or CGSCC pass.
176 bool CouldOnlyImpactOneFunction = (F != nullptr);
177
Jessica Paquettea0aa5b32018-09-06 21:19:54 +0000178 // Helper lambda that updates the changes to the size of some function.
179 auto UpdateFunctionChanges =
180 [&FunctionToInstrCount](Function &MaybeChangedFn) {
181 // Update the total module count.
182 unsigned FnSize = MaybeChangedFn.getInstructionCount();
183 auto It = FunctionToInstrCount.find(MaybeChangedFn.getName());
184
185 // If we created a new function, then we need to add it to the map and
186 // say that it changed from 0 instructions to FnSize.
187 if (It == FunctionToInstrCount.end()) {
188 FunctionToInstrCount[MaybeChangedFn.getName()] =
189 std::pair<unsigned, unsigned>(0, FnSize);
190 return;
191 }
192 // Insert the new function size into the second member of the pair. This
193 // tells us whether or not this function changed in size.
194 It->second.second = FnSize;
195 };
196
197 // We need to initially update all of the function sizes.
198 // If no function was passed in, then we're either a module pass or an
199 // CGSCC pass.
200 if (!CouldOnlyImpactOneFunction)
201 std::for_each(M.begin(), M.end(), UpdateFunctionChanges);
202 else
203 UpdateFunctionChanges(*F);
204
Jessica Paquette71e97782018-08-31 20:54:37 +0000205 // Do we have a function we can use to emit a remark?
Jessica Paquette31d2e5e2018-09-04 21:03:43 +0000206 if (!CouldOnlyImpactOneFunction) {
Jessica Paquette71e97782018-08-31 20:54:37 +0000207 // We need a function containing at least one basic block in order to output
208 // remarks. Since it's possible that the first function in the module
209 // doesn't actually contain a basic block, we have to go and find one that's
210 // suitable for emitting remarks.
211 auto It = std::find_if(M.begin(), M.end(),
212 [](const Function &Fn) { return !Fn.empty(); });
Jessica Paquettee49374d2018-05-18 17:26:39 +0000213
Jessica Paquette71e97782018-08-31 20:54:37 +0000214 // Didn't find a function. Quit.
215 if (It == M.end())
216 return;
Jessica Paquettee49374d2018-05-18 17:26:39 +0000217
Jessica Paquette71e97782018-08-31 20:54:37 +0000218 // We found a function containing at least one basic block.
219 F = &*It;
220 }
Jessica Paquette9a23c552018-08-31 20:20:57 +0000221 int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
Jessica Paquettee49374d2018-05-18 17:26:39 +0000222 BasicBlock &BB = *F->begin();
223 OptimizationRemarkAnalysis R("size-info", "IRSizeChange",
224 DiagnosticLocation(), &BB);
225 // FIXME: Move ore namespace to DiagnosticInfo so that we can use it. This
226 // would let us use NV instead of DiagnosticInfoOptimizationBase::Argument.
227 R << DiagnosticInfoOptimizationBase::Argument("Pass", P->getPassName())
228 << ": IR instruction count changed from "
229 << DiagnosticInfoOptimizationBase::Argument("IRInstrsBefore", CountBefore)
230 << " to "
231 << DiagnosticInfoOptimizationBase::Argument("IRInstrsAfter", CountAfter)
232 << "; Delta: "
233 << DiagnosticInfoOptimizationBase::Argument("DeltaInstrCount", Delta);
234 F->getContext().diagnose(R); // Not using ORE for layering reasons.
Jessica Paquettea0aa5b32018-09-06 21:19:54 +0000235
236 // Emit per-function size change remarks separately.
237 std::string PassName = P->getPassName().str();
238
239 // Helper lambda that emits a remark when the size of a function has changed.
240 auto EmitFunctionSizeChangedRemark = [&FunctionToInstrCount, &F, &BB,
241 &PassName](const std::string &Fname) {
242 unsigned FnCountBefore, FnCountAfter;
243 std::pair<unsigned, unsigned> &Change = FunctionToInstrCount[Fname];
244 std::tie(FnCountBefore, FnCountAfter) = Change;
245 int64_t FnDelta = static_cast<int64_t>(FnCountAfter) -
246 static_cast<int64_t>(FnCountBefore);
247
248 if (FnDelta == 0)
249 return;
250
251 // FIXME: We shouldn't use BB for the location here. Unfortunately, because
252 // the function that we're looking at could have been deleted, we can't use
253 // it for the source location. We *want* remarks when a function is deleted
254 // though, so we're kind of stuck here as is. (This remark, along with the
255 // whole-module size change remarks really ought not to have source
256 // locations at all.)
257 OptimizationRemarkAnalysis FR("size-info", "FunctionIRSizeChange",
258 DiagnosticLocation(), &BB);
259 FR << DiagnosticInfoOptimizationBase::Argument("Pass", PassName)
260 << ": Function: "
261 << DiagnosticInfoOptimizationBase::Argument("Function", Fname)
262 << ": IR instruction count changed from "
263 << DiagnosticInfoOptimizationBase::Argument("IRInstrsBefore",
264 FnCountBefore)
265 << " to "
266 << DiagnosticInfoOptimizationBase::Argument("IRInstrsAfter",
267 FnCountAfter)
268 << "; Delta: "
269 << DiagnosticInfoOptimizationBase::Argument("DeltaInstrCount", FnDelta);
270 F->getContext().diagnose(FR);
271
272 // Update the function size.
273 Change.first = FnCountAfter;
274 };
275
276 // Are we looking at more than one function? If so, emit remarks for all of
277 // the functions in the module. Otherwise, only emit one remark.
278 if (!CouldOnlyImpactOneFunction)
279 std::for_each(FunctionToInstrCount.keys().begin(),
280 FunctionToInstrCount.keys().end(),
281 EmitFunctionSizeChangedRemark);
282 else
283 EmitFunctionSizeChangedRemark(F->getName().str());
Jessica Paquettee49374d2018-05-18 17:26:39 +0000284}
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000285
Chris Lattner4c1e9542009-03-06 06:45:05 +0000286void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
Craig Topperc6207612014-04-09 06:08:46 +0000287 if (!V && !M)
Chris Lattner4c1e9542009-03-06 06:45:05 +0000288 OS << "Releasing pass '";
289 else
290 OS << "Running pass '";
Dan Gohmande6188a2010-08-12 23:50:08 +0000291
Chris Lattner4c1e9542009-03-06 06:45:05 +0000292 OS << P->getPassName() << "'";
Dan Gohmande6188a2010-08-12 23:50:08 +0000293
Chris Lattner4c1e9542009-03-06 06:45:05 +0000294 if (M) {
295 OS << " on module '" << M->getModuleIdentifier() << "'.\n";
296 return;
297 }
Craig Topperc6207612014-04-09 06:08:46 +0000298 if (!V) {
Chris Lattner4c1e9542009-03-06 06:45:05 +0000299 OS << '\n';
300 return;
301 }
302
Dan Gohman79fc0e92009-03-10 18:47:59 +0000303 OS << " on ";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000304 if (isa<Function>(V))
Dan Gohman79fc0e92009-03-10 18:47:59 +0000305 OS << "function";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000306 else if (isa<BasicBlock>(V))
Dan Gohman79fc0e92009-03-10 18:47:59 +0000307 OS << "basic block";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000308 else
Dan Gohman79fc0e92009-03-10 18:47:59 +0000309 OS << "value";
310
311 OS << " '";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000312 V->printAsOperand(OS, /*PrintTy=*/false, M);
Dan Gohman79fc0e92009-03-10 18:47:59 +0000313 OS << "'\n";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000314}
315
316
Devang Patelffca9102006-12-15 19:39:30 +0000317namespace {
Devang Patelf33f3eb2006-12-07 19:21:29 +0000318//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000319// BBPassManager
Devang Patel10c2ca62006-12-12 22:47:13 +0000320//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000321/// BBPassManager manages BasicBlockPass. It batches all the
Devang Patelca58e352006-11-08 10:05:38 +0000322/// pass together and sequence them to process one basic block before
323/// processing next basic block.
Nick Lewycky02d5f772009-10-25 06:33:48 +0000324class BBPassManager : public PMDataManager, public FunctionPass {
Devang Patelca58e352006-11-08 10:05:38 +0000325
326public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000327 static char ID;
Andrew Trick08966212011-08-29 17:07:00 +0000328 explicit BBPassManager()
329 : PMDataManager(), FunctionPass(ID) {}
Devang Patelca58e352006-11-08 10:05:38 +0000330
Devang Patelca58e352006-11-08 10:05:38 +0000331 /// Execute all of the passes scheduled for execution. Keep track of
332 /// whether any of the passes modifies the function, and if so, return true.
Craig Topperf398d7c2014-03-05 06:35:38 +0000333 bool runOnFunction(Function &F) override;
Devang Patelca58e352006-11-08 10:05:38 +0000334
Devang Patelf9d96b92006-12-07 19:57:52 +0000335 /// Pass Manager itself does not invalidate any analysis info.
Craig Topperf398d7c2014-03-05 06:35:38 +0000336 void getAnalysisUsage(AnalysisUsage &Info) const override {
Devang Patelf9d96b92006-12-07 19:57:52 +0000337 Info.setPreservesAll();
338 }
339
Craig Topperf398d7c2014-03-05 06:35:38 +0000340 bool doInitialization(Module &M) override;
Devang Patel475c4532006-12-08 00:59:05 +0000341 bool doInitialization(Function &F);
Craig Topperf398d7c2014-03-05 06:35:38 +0000342 bool doFinalization(Module &M) override;
Devang Patel475c4532006-12-08 00:59:05 +0000343 bool doFinalization(Function &F);
344
Craig Topperf398d7c2014-03-05 06:35:38 +0000345 PMDataManager *getAsPMDataManager() override { return this; }
346 Pass *getAsPass() override { return this; }
Chris Lattner2fa26e52010-01-22 05:24:46 +0000347
Mehdi Amini117296c2016-10-01 02:56:57 +0000348 StringRef getPassName() const override { return "BasicBlock Pass Manager"; }
Devang Patele3858e62007-02-01 22:08:25 +0000349
Devang Pateleda56172006-12-12 23:34:33 +0000350 // Print passes managed by this manager
Craig Topperf398d7c2014-03-05 06:35:38 +0000351 void dumpPassStructure(unsigned Offset) override {
Eric Christophera13839f2014-02-26 23:27:16 +0000352 dbgs().indent(Offset*2) << "BasicBlockPass Manager\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000353 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
354 BasicBlockPass *BP = getContainedPass(Index);
Dan Gohmanf71c5212010-08-19 01:29:07 +0000355 BP->dumpPassStructure(Offset + 1);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000356 dumpLastUses(BP, Offset+1);
Devang Pateleda56172006-12-12 23:34:33 +0000357 }
358 }
Devang Patelabfbe3b2006-12-16 00:56:26 +0000359
360 BasicBlockPass *getContainedPass(unsigned N) {
Evan Cheng66dbd3f2012-11-13 02:56:38 +0000361 assert(N < PassVector.size() && "Pass number out of range!");
Devang Patelabfbe3b2006-12-16 00:56:26 +0000362 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
363 return BP;
364 }
Devang Patel3b3f8992007-01-11 01:10:25 +0000365
Craig Topperf398d7c2014-03-05 06:35:38 +0000366 PassManagerType getPassManagerType() const override {
Dan Gohmande6188a2010-08-12 23:50:08 +0000367 return PMT_BasicBlockPassManager;
Devang Patel3b3f8992007-01-11 01:10:25 +0000368 }
Devang Patelca58e352006-11-08 10:05:38 +0000369};
370
Devang Patel8c78a0b2007-05-03 01:11:54 +0000371char BBPassManager::ID = 0;
Chandler Carruth7caea412013-11-09 12:26:54 +0000372} // End anonymous namespace
Devang Patel67d6a5e2006-12-19 19:46:59 +0000373
Devang Patele7599552007-01-12 18:52:44 +0000374namespace llvm {
Chandler Carruth7caea412013-11-09 12:26:54 +0000375namespace legacy {
Devang Patel10c2ca62006-12-12 22:47:13 +0000376//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000377// FunctionPassManagerImpl
Devang Patel10c2ca62006-12-12 22:47:13 +0000378//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000379/// FunctionPassManagerImpl manages FPPassManagers
380class FunctionPassManagerImpl : public Pass,
Devang Patelad98d232007-01-11 22:15:30 +0000381 public PMDataManager,
382 public PMTopLevelManager {
David Blaikiea379b1812011-12-20 02:50:00 +0000383 virtual void anchor();
Torok Edwin24c78352009-06-29 18:49:09 +0000384private:
385 bool wasRun;
Devang Patel67d6a5e2006-12-19 19:46:59 +0000386public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000387 static char ID;
Andrew Trick08966212011-08-29 17:07:00 +0000388 explicit FunctionPassManagerImpl() :
389 Pass(PT_PassManager, ID), PMDataManager(),
390 PMTopLevelManager(new FPPassManager()), wasRun(false) {}
Devang Patel67d6a5e2006-12-19 19:46:59 +0000391
Matthias Braun0880c602014-12-12 01:27:01 +0000392 /// \copydoc FunctionPassManager::add()
Devang Patel67d6a5e2006-12-19 19:46:59 +0000393 void add(Pass *P) {
394 schedulePass(P);
395 }
Dan Gohmande6188a2010-08-12 23:50:08 +0000396
397 /// createPrinterPass - Get a function printer pass.
Craig Topperf398d7c2014-03-05 06:35:38 +0000398 Pass *createPrinterPass(raw_ostream &O,
399 const std::string &Banner) const override {
Chandler Carruth9d805132014-01-12 11:30:46 +0000400 return createPrintFunctionPass(O, Banner);
David Greene9b063df2010-04-02 23:17:14 +0000401 }
402
Torok Edwin24c78352009-06-29 18:49:09 +0000403 // Prepare for running an on the fly pass, freeing memory if needed
404 // from a previous run.
405 void releaseMemoryOnTheFly();
406
Devang Patel67d6a5e2006-12-19 19:46:59 +0000407 /// run - Execute all of the passes scheduled for execution. Keep track of
408 /// whether any of the passes modifies the module, and if so, return true.
409 bool run(Function &F);
410
411 /// doInitialization - Run all of the initializers for the function passes.
412 ///
Craig Topperf398d7c2014-03-05 06:35:38 +0000413 bool doInitialization(Module &M) override;
Dan Gohmande6188a2010-08-12 23:50:08 +0000414
Dan Gohmane6656eb2007-07-30 14:51:13 +0000415 /// doFinalization - Run all of the finalizers for the function passes.
Devang Patel67d6a5e2006-12-19 19:46:59 +0000416 ///
Craig Topperf398d7c2014-03-05 06:35:38 +0000417 bool doFinalization(Module &M) override;
Devang Patel67d6a5e2006-12-19 19:46:59 +0000418
Dan Gohmande6188a2010-08-12 23:50:08 +0000419
Craig Topperf398d7c2014-03-05 06:35:38 +0000420 PMDataManager *getAsPMDataManager() override { return this; }
421 Pass *getAsPass() override { return this; }
422 PassManagerType getTopLevelPassManagerType() override {
Andrew Trickcbc845f2012-02-01 07:16:20 +0000423 return PMT_FunctionPassManager;
424 }
Chris Lattner2fa26e52010-01-22 05:24:46 +0000425
Devang Patel67d6a5e2006-12-19 19:46:59 +0000426 /// Pass Manager itself does not invalidate any analysis info.
Craig Topperf398d7c2014-03-05 06:35:38 +0000427 void getAnalysisUsage(AnalysisUsage &Info) const override {
Devang Patel67d6a5e2006-12-19 19:46:59 +0000428 Info.setPreservesAll();
429 }
430
Devang Patel67d6a5e2006-12-19 19:46:59 +0000431 FPPassManager *getContainedManager(unsigned N) {
Chris Lattner60987362009-03-06 05:53:14 +0000432 assert(N < PassManagers.size() && "Pass number out of range!");
Devang Patel67d6a5e2006-12-19 19:46:59 +0000433 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
434 return FP;
435 }
Devang Patel67d6a5e2006-12-19 19:46:59 +0000436};
437
David Blaikiea379b1812011-12-20 02:50:00 +0000438void FunctionPassManagerImpl::anchor() {}
439
Devang Patel8c78a0b2007-05-03 01:11:54 +0000440char FunctionPassManagerImpl::ID = 0;
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000441} // End of legacy namespace
442} // End of llvm namespace
Dan Gohmande6188a2010-08-12 23:50:08 +0000443
Chandler Carruth7caea412013-11-09 12:26:54 +0000444namespace {
Devang Patel67d6a5e2006-12-19 19:46:59 +0000445//===----------------------------------------------------------------------===//
446// MPPassManager
447//
448/// MPPassManager manages ModulePasses and function pass managers.
Dan Gohmandfdf2c02008-03-11 16:18:48 +0000449/// It batches all Module passes and function pass managers together and
450/// sequences them to process one module.
Devang Patel67d6a5e2006-12-19 19:46:59 +0000451class MPPassManager : public Pass, public PMDataManager {
Devang Patelca58e352006-11-08 10:05:38 +0000452public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000453 static char ID;
Andrew Trick08966212011-08-29 17:07:00 +0000454 explicit MPPassManager() :
455 Pass(PT_PassManager, ID), PMDataManager() { }
Devang Patel2ff44922007-04-16 20:39:59 +0000456
457 // Delete on the fly managers.
Alexander Kornienkof817c1c2015-04-11 02:11:45 +0000458 ~MPPassManager() override {
Yaron Keren4849aa32015-06-05 17:48:47 +0000459 for (auto &OnTheFlyManager : OnTheFlyManagers) {
460 FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
Devang Patel2ff44922007-04-16 20:39:59 +0000461 delete FPP;
462 }
463 }
464
Dan Gohmande6188a2010-08-12 23:50:08 +0000465 /// createPrinterPass - Get a module printer pass.
Craig Topperf398d7c2014-03-05 06:35:38 +0000466 Pass *createPrinterPass(raw_ostream &O,
467 const std::string &Banner) const override {
Chandler Carruth9d805132014-01-12 11:30:46 +0000468 return createPrintModulePass(O, Banner);
David Greene9b063df2010-04-02 23:17:14 +0000469 }
470
Devang Patelca58e352006-11-08 10:05:38 +0000471 /// run - Execute all of the passes scheduled for execution. Keep track of
472 /// whether any of the passes modifies the module, and if so, return true.
473 bool runOnModule(Module &M);
Devang Patelebba9702006-11-13 22:40:09 +0000474
Pedro Artigase4348b02012-12-03 21:56:57 +0000475 using llvm::Pass::doInitialization;
476 using llvm::Pass::doFinalization;
477
Devang Patelf9d96b92006-12-07 19:57:52 +0000478 /// Pass Manager itself does not invalidate any analysis info.
Craig Topperf398d7c2014-03-05 06:35:38 +0000479 void getAnalysisUsage(AnalysisUsage &Info) const override {
Devang Patelf9d96b92006-12-07 19:57:52 +0000480 Info.setPreservesAll();
481 }
482
Devang Patele64d3052007-04-16 20:12:57 +0000483 /// Add RequiredPass into list of lower level passes required by pass P.
484 /// RequiredPass is run on the fly by Pass Manager when P requests it
485 /// through getAnalysis interface.
Craig Topperf398d7c2014-03-05 06:35:38 +0000486 void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
Devang Patele64d3052007-04-16 20:12:57 +0000487
Dan Gohmande6188a2010-08-12 23:50:08 +0000488 /// Return function pass corresponding to PassInfo PI, that is
Devang Patel69e9f6d2007-04-16 20:27:05 +0000489 /// required by module pass MP. Instantiate analysis pass, by using
490 /// its runOnFunction() for function F.
Craig Topperf398d7c2014-03-05 06:35:38 +0000491 Pass* getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F) override;
Devang Patel69e9f6d2007-04-16 20:27:05 +0000492
Mehdi Amini117296c2016-10-01 02:56:57 +0000493 StringRef getPassName() const override { return "Module Pass Manager"; }
Devang Patele3858e62007-02-01 22:08:25 +0000494
Craig Topperf398d7c2014-03-05 06:35:38 +0000495 PMDataManager *getAsPMDataManager() override { return this; }
496 Pass *getAsPass() override { return this; }
Chris Lattner2fa26e52010-01-22 05:24:46 +0000497
Devang Pateleda56172006-12-12 23:34:33 +0000498 // Print passes managed by this manager
Craig Topperf398d7c2014-03-05 06:35:38 +0000499 void dumpPassStructure(unsigned Offset) override {
Eric Christophera13839f2014-02-26 23:27:16 +0000500 dbgs().indent(Offset*2) << "ModulePass Manager\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000501 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
502 ModulePass *MP = getContainedPass(Index);
Dan Gohmanf71c5212010-08-19 01:29:07 +0000503 MP->dumpPassStructure(Offset + 1);
Florian Hahna4ffa3a2018-05-24 21:33:17 +0000504 MapVector<Pass *, FunctionPassManagerImpl *>::const_iterator I =
505 OnTheFlyManagers.find(MP);
Dan Gohman83ff1842009-07-01 23:12:33 +0000506 if (I != OnTheFlyManagers.end())
507 I->second->dumpPassStructure(Offset + 2);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000508 dumpLastUses(MP, Offset+1);
Devang Pateleda56172006-12-12 23:34:33 +0000509 }
510 }
511
Devang Patelabfbe3b2006-12-16 00:56:26 +0000512 ModulePass *getContainedPass(unsigned N) {
Evan Cheng66dbd3f2012-11-13 02:56:38 +0000513 assert(N < PassVector.size() && "Pass number out of range!");
Chris Lattner60987362009-03-06 05:53:14 +0000514 return static_cast<ModulePass *>(PassVector[N]);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000515 }
516
Craig Topperf398d7c2014-03-05 06:35:38 +0000517 PassManagerType getPassManagerType() const override {
Dan Gohmande6188a2010-08-12 23:50:08 +0000518 return PMT_ModulePassManager;
Devang Patel28349ab2007-02-27 15:00:39 +0000519 }
Devang Patel69e9f6d2007-04-16 20:27:05 +0000520
521 private:
522 /// Collection of on the fly FPPassManagers. These managers manage
523 /// function passes that are required by module passes.
Florian Hahna4ffa3a2018-05-24 21:33:17 +0000524 MapVector<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
Devang Patelca58e352006-11-08 10:05:38 +0000525};
526
Devang Patel8c78a0b2007-05-03 01:11:54 +0000527char MPPassManager::ID = 0;
Chandler Carruth7caea412013-11-09 12:26:54 +0000528} // End anonymous namespace
529
530namespace llvm {
531namespace legacy {
Devang Patel10c2ca62006-12-12 22:47:13 +0000532//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000533// PassManagerImpl
Devang Patel10c2ca62006-12-12 22:47:13 +0000534//
Devang Patel09f162c2007-05-01 21:15:47 +0000535
Devang Patel67d6a5e2006-12-19 19:46:59 +0000536/// PassManagerImpl manages MPPassManagers
537class PassManagerImpl : public Pass,
Devang Patelad98d232007-01-11 22:15:30 +0000538 public PMDataManager,
539 public PMTopLevelManager {
David Blaikiea379b1812011-12-20 02:50:00 +0000540 virtual void anchor();
Devang Patel376fefa2006-11-08 10:29:57 +0000541
542public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000543 static char ID;
Andrew Trick08966212011-08-29 17:07:00 +0000544 explicit PassManagerImpl() :
545 Pass(PT_PassManager, ID), PMDataManager(),
546 PMTopLevelManager(new MPPassManager()) {}
Devang Patel4c36e6b2006-12-07 23:24:58 +0000547
Matthias Braun0880c602014-12-12 01:27:01 +0000548 /// \copydoc PassManager::add()
Devang Patel31217af2006-12-07 21:32:57 +0000549 void add(Pass *P) {
Devang Pateldf6c9ae2006-12-08 22:34:02 +0000550 schedulePass(P);
Devang Patel31217af2006-12-07 21:32:57 +0000551 }
Dan Gohmande6188a2010-08-12 23:50:08 +0000552
553 /// createPrinterPass - Get a module printer pass.
Craig Topperf398d7c2014-03-05 06:35:38 +0000554 Pass *createPrinterPass(raw_ostream &O,
555 const std::string &Banner) const override {
Chandler Carruth9d805132014-01-12 11:30:46 +0000556 return createPrintModulePass(O, Banner);
David Greene9b063df2010-04-02 23:17:14 +0000557 }
558
Devang Patel376fefa2006-11-08 10:29:57 +0000559 /// run - Execute all of the passes scheduled for execution. Keep track of
560 /// whether any of the passes modifies the module, and if so, return true.
561 bool run(Module &M);
562
Pedro Artigase4348b02012-12-03 21:56:57 +0000563 using llvm::Pass::doInitialization;
564 using llvm::Pass::doFinalization;
565
Devang Patelf9d96b92006-12-07 19:57:52 +0000566 /// Pass Manager itself does not invalidate any analysis info.
Craig Topperf398d7c2014-03-05 06:35:38 +0000567 void getAnalysisUsage(AnalysisUsage &Info) const override {
Devang Patelf9d96b92006-12-07 19:57:52 +0000568 Info.setPreservesAll();
569 }
570
Craig Topperf398d7c2014-03-05 06:35:38 +0000571 PMDataManager *getAsPMDataManager() override { return this; }
572 Pass *getAsPass() override { return this; }
573 PassManagerType getTopLevelPassManagerType() override {
Andrew Trickcbc845f2012-02-01 07:16:20 +0000574 return PMT_ModulePassManager;
575 }
Chris Lattner2fa26e52010-01-22 05:24:46 +0000576
Devang Patel67d6a5e2006-12-19 19:46:59 +0000577 MPPassManager *getContainedManager(unsigned N) {
Chris Lattner60987362009-03-06 05:53:14 +0000578 assert(N < PassManagers.size() && "Pass number out of range!");
Devang Patel67d6a5e2006-12-19 19:46:59 +0000579 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
580 return MP;
581 }
Devang Patel376fefa2006-11-08 10:29:57 +0000582};
583
David Blaikiea379b1812011-12-20 02:50:00 +0000584void PassManagerImpl::anchor() {}
585
Devang Patel8c78a0b2007-05-03 01:11:54 +0000586char PassManagerImpl::ID = 0;
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000587} // End of legacy namespace
588} // End of llvm namespace
Devang Patel1c3633e2007-01-29 23:10:37 +0000589
Devang Patela1514cb2006-12-07 19:39:39 +0000590//===----------------------------------------------------------------------===//
Devang Patelafb1f3622006-12-12 22:35:25 +0000591// PMTopLevelManager implementation
592
Devang Patel4268fc02007-01-16 02:00:38 +0000593/// Initialize top level manager. Create first pass manager.
Dan Gohmane85c6192010-08-16 21:38:42 +0000594PMTopLevelManager::PMTopLevelManager(PMDataManager *PMDM) {
595 PMDM->setTopLevelManager(this);
596 addPassManager(PMDM);
597 activeStack.push(PMDM);
Devang Patel4268fc02007-01-16 02:00:38 +0000598}
599
Devang Patelafb1f3622006-12-12 22:35:25 +0000600/// Set pass P as the last user of the given analysis passes.
Dan Gohmanc8da21b2010-10-12 00:12:29 +0000601void
Bill Wendlingea857e12012-05-14 07:53:40 +0000602PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) {
Tobias Grosserf07426b2011-01-20 21:03:22 +0000603 unsigned PDepth = 0;
604 if (P->getResolver())
605 PDepth = P->getResolver()->getPMDataManager().getDepth();
606
Yaron Keren4849aa32015-06-05 17:48:47 +0000607 for (Pass *AP : AnalysisPasses) {
Devang Patelafb1f3622006-12-12 22:35:25 +0000608 LastUser[AP] = P;
Dan Gohmande6188a2010-08-12 23:50:08 +0000609
Devang Patel01919d22007-03-08 19:05:01 +0000610 if (P == AP)
611 continue;
612
Tobias Grosserf07426b2011-01-20 21:03:22 +0000613 // Update the last users of passes that are required transitive by AP.
614 AnalysisUsage *AnUsage = findAnalysisUsage(AP);
615 const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet();
616 SmallVector<Pass *, 12> LastUses;
617 SmallVector<Pass *, 12> LastPMUses;
Yaron Keren83009952016-04-28 14:49:44 +0000618 for (AnalysisID ID : IDs) {
619 Pass *AnalysisPass = findAnalysisPass(ID);
Tobias Grosserf07426b2011-01-20 21:03:22 +0000620 assert(AnalysisPass && "Expected analysis pass to exist.");
621 AnalysisResolver *AR = AnalysisPass->getResolver();
622 assert(AR && "Expected analysis resolver to exist.");
623 unsigned APDepth = AR->getPMDataManager().getDepth();
624
625 if (PDepth == APDepth)
626 LastUses.push_back(AnalysisPass);
627 else if (PDepth > APDepth)
628 LastPMUses.push_back(AnalysisPass);
629 }
630
631 setLastUser(LastUses, P);
632
633 // If this pass has a corresponding pass manager, push higher level
634 // analysis to this pass manager.
635 if (P->getResolver())
636 setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass());
637
638
Devang Patelafb1f3622006-12-12 22:35:25 +0000639 // If AP is the last user of other passes then make P last user of
640 // such passes.
Yaron Kerenbd873192016-10-02 19:21:41 +0000641 for (auto LU : LastUser) {
642 if (LU.second == AP)
Devang Patelc68a0b62008-08-12 00:26:16 +0000643 // DenseMap iterator is not invalidated here because
Tobias Grosserf07426b2011-01-20 21:03:22 +0000644 // this is just updating existing entries.
Yaron Kerenbd873192016-10-02 19:21:41 +0000645 LastUser[LU.first] = P;
Devang Patelafb1f3622006-12-12 22:35:25 +0000646 }
647 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000648}
649
650/// Collect passes whose last user is P
Dan Gohman7224bce2010-10-12 00:11:18 +0000651void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses,
Devang Patelc68a0b62008-08-12 00:26:16 +0000652 Pass *P) {
Dan Gohmande6188a2010-08-12 23:50:08 +0000653 DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
Devang Patelc68a0b62008-08-12 00:26:16 +0000654 InversedLastUser.find(P);
655 if (DMI == InversedLastUser.end())
656 return;
657
658 SmallPtrSet<Pass *, 8> &LU = DMI->second;
Craig Topper46276792014-08-24 23:23:06 +0000659 for (Pass *LUP : LU) {
660 LastUses.push_back(LUP);
Devang Patelc68a0b62008-08-12 00:26:16 +0000661 }
662
Devang Patelafb1f3622006-12-12 22:35:25 +0000663}
664
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000665AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
Craig Topperc6207612014-04-09 06:08:46 +0000666 AnalysisUsage *AnUsage = nullptr;
Philip Reamese8aeaeb2015-12-04 20:05:04 +0000667 auto DMI = AnUsageMap.find(P);
Dan Gohmande6188a2010-08-12 23:50:08 +0000668 if (DMI != AnUsageMap.end())
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000669 AnUsage = DMI->second;
670 else {
Philip Reamese8aeaeb2015-12-04 20:05:04 +0000671 // Look up the analysis usage from the pass instance (different instances
672 // of the same pass can produce different results), but unique the
673 // resulting object to reduce memory usage. This helps to greatly reduce
674 // memory usage when we have many instances of only a few pass types
675 // (e.g. instcombine, simplifycfg, etc...) which tend to share a fixed set
676 // of dependencies.
677 AnalysisUsage AU;
678 P->getAnalysisUsage(AU);
Bjorn Petterssonaa025802018-07-03 12:39:52 +0000679
Philip Reamese8aeaeb2015-12-04 20:05:04 +0000680 AUFoldingSetNode* Node = nullptr;
681 FoldingSetNodeID ID;
682 AUFoldingSetNode::Profile(ID, AU);
683 void *IP = nullptr;
684 if (auto *N = UniqueAnalysisUsages.FindNodeOrInsertPos(ID, IP))
685 Node = N;
686 else {
Philip Reames000f77d2015-12-04 23:48:19 +0000687 Node = new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
Philip Reamese8aeaeb2015-12-04 20:05:04 +0000688 UniqueAnalysisUsages.InsertNode(Node, IP);
689 }
690 assert(Node && "cached analysis usage must be non null");
691
692 AnUsageMap[P] = &Node->AU;
Mandeep Singh Grang5e1697e2017-06-06 05:08:36 +0000693 AnUsage = &Node->AU;
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000694 }
695 return AnUsage;
696}
697
Devang Patelafb1f3622006-12-12 22:35:25 +0000698/// Schedule pass P for execution. Make sure that passes required by
699/// P are run before P is run. Update analysis info maintained by
700/// the manager. Remove dead passes. This is a recursive function.
701void PMTopLevelManager::schedulePass(Pass *P) {
702
Devang Patel3312f752007-01-16 21:43:18 +0000703 // TODO : Allocate function manager for this pass, other wise required set
704 // may be inserted into previous function manager
Devang Patelafb1f3622006-12-12 22:35:25 +0000705
Devang Pateld74ede72007-03-06 01:06:16 +0000706 // Give pass a chance to prepare the stage.
707 P->preparePassManager(activeStack);
708
Devang Patel864970e2008-03-18 00:39:19 +0000709 // If P is an analysis pass and it is available then do not
710 // generate the analysis again. Stale analysis info should not be
711 // available at this point.
Chandler Carruth5b0d3e32015-01-28 09:47:21 +0000712 const PassInfo *PI = findAnalysisPassInfo(P->getPassID());
Owen Andersona7aed182010-08-06 18:33:48 +0000713 if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
Craig Topper4ee28412018-08-20 20:57:30 +0000714 // Remove any cached AnalysisUsage information.
715 AnUsageMap.erase(P);
Nuno Lopes0460bb22008-11-04 23:03:58 +0000716 delete P;
Devang Patelaf75ab82008-03-19 00:48:41 +0000717 return;
Nuno Lopes0460bb22008-11-04 23:03:58 +0000718 }
Devang Patel864970e2008-03-18 00:39:19 +0000719
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000720 AnalysisUsage *AnUsage = findAnalysisUsage(P);
721
Devang Patelfdee7032008-08-14 23:07:48 +0000722 bool checkAnalysis = true;
723 while (checkAnalysis) {
724 checkAnalysis = false;
Dan Gohmande6188a2010-08-12 23:50:08 +0000725
Devang Patelfdee7032008-08-14 23:07:48 +0000726 const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
Florian Hahn03c3a1a2017-07-13 10:52:00 +0000727 for (const AnalysisID ID : RequiredSet) {
Dan Gohmande6188a2010-08-12 23:50:08 +0000728
Florian Hahn03c3a1a2017-07-13 10:52:00 +0000729 Pass *AnalysisPass = findAnalysisPass(ID);
Devang Patelfdee7032008-08-14 23:07:48 +0000730 if (!AnalysisPass) {
Florian Hahn03c3a1a2017-07-13 10:52:00 +0000731 const PassInfo *PI = findAnalysisPassInfo(ID);
Victor Oliveiraaa9ccee2012-07-18 19:59:29 +0000732
Craig Topperc6207612014-04-09 06:08:46 +0000733 if (!PI) {
Victor Oliveiraaa9ccee2012-07-18 19:59:29 +0000734 // Pass P is not in the global PassRegistry
735 dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
736 dbgs() << "Verify if there is a pass dependency cycle." << "\n";
737 dbgs() << "Required Passes:" << "\n";
Florian Hahn03c3a1a2017-07-13 10:52:00 +0000738 for (const AnalysisID ID2 : RequiredSet) {
739 if (ID == ID2)
740 break;
741 Pass *AnalysisPass2 = findAnalysisPass(ID2);
Victor Oliveiraaa9ccee2012-07-18 19:59:29 +0000742 if (AnalysisPass2) {
743 dbgs() << "\t" << AnalysisPass2->getPassName() << "\n";
Craig Topper821d6af2013-02-06 06:50:38 +0000744 } else {
Victor Oliveiraaa9ccee2012-07-18 19:59:29 +0000745 dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
746 dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
747 dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n";
748 }
749 }
750 }
751
Andrew Trick6bbaf132011-06-03 00:48:58 +0000752 assert(PI && "Expected required passes to be initialized");
Owen Andersona7aed182010-08-06 18:33:48 +0000753 AnalysisPass = PI->createPass();
Devang Patelfdee7032008-08-14 23:07:48 +0000754 if (P->getPotentialPassManagerType () ==
755 AnalysisPass->getPotentialPassManagerType())
756 // Schedule analysis pass that is managed by the same pass manager.
757 schedulePass(AnalysisPass);
758 else if (P->getPotentialPassManagerType () >
759 AnalysisPass->getPotentialPassManagerType()) {
760 // Schedule analysis pass that is managed by a new manager.
761 schedulePass(AnalysisPass);
Dan Gohman6304db32010-08-16 22:57:28 +0000762 // Recheck analysis passes to ensure that required analyses that
Devang Patelfdee7032008-08-14 23:07:48 +0000763 // are already checked are still available.
764 checkAnalysis = true;
Craig Topper821d6af2013-02-06 06:50:38 +0000765 } else
Chad Rosierc83fa9e2015-03-20 15:45:14 +0000766 // Do not schedule this analysis. Lower level analysis
Devang Patelfdee7032008-08-14 23:07:48 +0000767 // passes are run on the fly.
768 delete AnalysisPass;
769 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000770 }
771 }
772
773 // Now all required passes are available.
Andrew Trickcbc845f2012-02-01 07:16:20 +0000774 if (ImmutablePass *IP = P->getAsImmutablePass()) {
775 // P is a immutable pass and it will be managed by this
776 // top level manager. Set up analysis resolver to connect them.
777 PMDataManager *DM = getAsPMDataManager();
778 AnalysisResolver *AR = new AnalysisResolver(*DM);
779 P->setResolver(AR);
780 DM->initializeAnalysisImpl(P);
781 addImmutablePass(IP);
782 DM->recordAvailableAnalysis(IP);
783 return;
784 }
785
Fedor Sergeev662e5682018-09-24 16:08:15 +0000786 if (PI && !PI->isAnalysis() && shouldPrintBeforePass(PI->getPassArgument())) {
Andrew Trickcbc845f2012-02-01 07:16:20 +0000787 Pass *PP = P->createPrinterPass(
Mehdi Amini117296c2016-10-01 02:56:57 +0000788 dbgs(), ("*** IR Dump Before " + P->getPassName() + " ***").str());
Andrew Trickcbc845f2012-02-01 07:16:20 +0000789 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
790 }
791
792 // Add the requested pass to the best available pass manager.
793 P->assignPassManager(activeStack, getTopLevelPassManagerType());
794
Fedor Sergeev662e5682018-09-24 16:08:15 +0000795 if (PI && !PI->isAnalysis() && shouldPrintAfterPass(PI->getPassArgument())) {
Andrew Trickcbc845f2012-02-01 07:16:20 +0000796 Pass *PP = P->createPrinterPass(
Mehdi Amini117296c2016-10-01 02:56:57 +0000797 dbgs(), ("*** IR Dump After " + P->getPassName() + " ***").str());
Andrew Trickcbc845f2012-02-01 07:16:20 +0000798 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
799 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000800}
801
802/// Find the pass that implements Analysis AID. Search immutable
803/// passes and all pass managers. If desired pass is not found
804/// then return NULL.
805Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
Chandler Carruthb1e3a9a2015-09-10 02:31:42 +0000806 // For immutable passes we have a direct mapping from ID to pass, so check
807 // that first.
808 if (Pass *P = ImmutablePassMap.lookup(AID))
809 return P;
Devang Patelafb1f3622006-12-12 22:35:25 +0000810
Devang Patelcd6ba152006-12-12 22:50:05 +0000811 // Check pass managers
Yaron Keren4849aa32015-06-05 17:48:47 +0000812 for (PMDataManager *PassManager : PassManagers)
813 if (Pass *P = PassManager->findAnalysisPass(AID, false))
Dan Gohman844dd0a2010-10-11 23:19:01 +0000814 return P;
Devang Patelcd6ba152006-12-12 22:50:05 +0000815
816 // Check other pass managers
Yaron Keren4849aa32015-06-05 17:48:47 +0000817 for (PMDataManager *IndirectPassManager : IndirectPassManagers)
818 if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
Dan Gohman844dd0a2010-10-11 23:19:01 +0000819 return P;
Devang Patelcd6ba152006-12-12 22:50:05 +0000820
Craig Topperc6207612014-04-09 06:08:46 +0000821 return nullptr;
Devang Patelafb1f3622006-12-12 22:35:25 +0000822}
823
Chandler Carruth5b0d3e32015-01-28 09:47:21 +0000824const PassInfo *PMTopLevelManager::findAnalysisPassInfo(AnalysisID AID) const {
825 const PassInfo *&PI = AnalysisPassInfos[AID];
826 if (!PI)
827 PI = PassRegistry::getPassRegistry()->getPassInfo(AID);
828 else
829 assert(PI == PassRegistry::getPassRegistry()->getPassInfo(AID) &&
830 "The pass info pointer changed for an analysis ID!");
831
832 return PI;
833}
834
Chandler Carruthb1e3a9a2015-09-10 02:31:42 +0000835void PMTopLevelManager::addImmutablePass(ImmutablePass *P) {
836 P->initializePass();
837 ImmutablePasses.push_back(P);
838
839 // Add this pass to the map from its analysis ID. We clobber any prior runs
840 // of the pass in the map so that the last one added is the one found when
841 // doing lookups.
842 AnalysisID AID = P->getPassID();
843 ImmutablePassMap[AID] = P;
844
845 // Also add any interfaces implemented by the immutable pass to the map for
846 // fast lookup.
847 const PassInfo *PassInf = findAnalysisPassInfo(AID);
848 assert(PassInf && "Expected all immutable passes to be initialized");
Chandler Carruth87275182015-09-10 04:22:36 +0000849 for (const PassInfo *ImmPI : PassInf->getInterfacesImplemented())
Chandler Carruthb1e3a9a2015-09-10 02:31:42 +0000850 ImmutablePassMap[ImmPI->getTypeInfo()] = P;
851}
852
Devang Pateleda56172006-12-12 23:34:33 +0000853// Print passes managed by this top level manager.
Devang Patel991aeba2006-12-15 20:13:01 +0000854void PMTopLevelManager::dumpPasses() const {
Devang Pateleda56172006-12-12 23:34:33 +0000855
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000856 if (PassDebugging < Structure)
Devang Patel67d6a5e2006-12-19 19:46:59 +0000857 return;
858
Devang Pateleda56172006-12-12 23:34:33 +0000859 // Print out the immutable passes
860 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
Dan Gohmanf71c5212010-08-19 01:29:07 +0000861 ImmutablePasses[i]->dumpPassStructure(0);
Devang Pateleda56172006-12-12 23:34:33 +0000862 }
Dan Gohmande6188a2010-08-12 23:50:08 +0000863
Dan Gohmanf71c5212010-08-19 01:29:07 +0000864 // Every class that derives from PMDataManager also derives from Pass
865 // (sometimes indirectly), but there's no inheritance relationship
866 // between PMDataManager and Pass, so we have to getAsPass to get
867 // from a PMDataManager* to a Pass*.
Yaron Keren4849aa32015-06-05 17:48:47 +0000868 for (PMDataManager *Manager : PassManagers)
869 Manager->getAsPass()->dumpPassStructure(1);
Devang Pateleda56172006-12-12 23:34:33 +0000870}
871
Devang Patel991aeba2006-12-15 20:13:01 +0000872void PMTopLevelManager::dumpArguments() const {
Devang Patelcfd70c42006-12-13 22:10:00 +0000873
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000874 if (PassDebugging < Arguments)
Devang Patelcfd70c42006-12-13 22:10:00 +0000875 return;
876
David Greene994e1bb2010-01-05 01:30:02 +0000877 dbgs() << "Pass Arguments: ";
Yaron Keren83009952016-04-28 14:49:44 +0000878 for (ImmutablePass *P : ImmutablePasses)
879 if (const PassInfo *PI = findAnalysisPassInfo(P->getPassID())) {
Andrew Trick6bbaf132011-06-03 00:48:58 +0000880 assert(PI && "Expected all immutable passes to be initialized");
Dan Gohmanf51d06bb2010-11-11 16:32:17 +0000881 if (!PI->isAnalysisGroup())
882 dbgs() << " -" << PI->getPassArgument();
Andrew Trick6bbaf132011-06-03 00:48:58 +0000883 }
Yaron Keren83009952016-04-28 14:49:44 +0000884 for (PMDataManager *PM : PassManagers)
885 PM->dumpPassArguments();
David Greene994e1bb2010-01-05 01:30:02 +0000886 dbgs() << "\n";
Devang Patelcfd70c42006-12-13 22:10:00 +0000887}
888
Devang Patele3068402006-12-21 00:16:50 +0000889void PMTopLevelManager::initializeAllAnalysisInfo() {
Yaron Keren83009952016-04-28 14:49:44 +0000890 for (PMDataManager *PM : PassManagers)
891 PM->initializeAnalysisInfo();
Dan Gohmande6188a2010-08-12 23:50:08 +0000892
Devang Patele3068402006-12-21 00:16:50 +0000893 // Initailize other pass managers
Yaron Keren83009952016-04-28 14:49:44 +0000894 for (PMDataManager *IPM : IndirectPassManagers)
895 IPM->initializeAnalysisInfo();
Devang Patelc68a0b62008-08-12 00:26:16 +0000896
Yaron Kerenbd873192016-10-02 19:21:41 +0000897 for (auto LU : LastUser) {
898 SmallPtrSet<Pass *, 8> &L = InversedLastUser[LU.second];
899 L.insert(LU.first);
Devang Patelc68a0b62008-08-12 00:26:16 +0000900 }
Devang Patele3068402006-12-21 00:16:50 +0000901}
902
Devang Patele7599552007-01-12 18:52:44 +0000903/// Destructor
904PMTopLevelManager::~PMTopLevelManager() {
Yaron Keren83009952016-04-28 14:49:44 +0000905 for (PMDataManager *PM : PassManagers)
906 delete PM;
Dan Gohmande6188a2010-08-12 23:50:08 +0000907
Yaron Keren83009952016-04-28 14:49:44 +0000908 for (ImmutablePass *P : ImmutablePasses)
909 delete P;
Devang Patele7599552007-01-12 18:52:44 +0000910}
911
Devang Patelafb1f3622006-12-12 22:35:25 +0000912//===----------------------------------------------------------------------===//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000913// PMDataManager implementation
Devang Patelf68a3492006-11-07 22:35:17 +0000914
Devang Patel643676c2006-11-11 01:10:19 +0000915/// Augement AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000916void PMDataManager::recordAvailableAnalysis(Pass *P) {
Owen Andersona7aed182010-08-06 18:33:48 +0000917 AnalysisID PI = P->getPassID();
Dan Gohmande6188a2010-08-12 23:50:08 +0000918
Chris Lattner60987362009-03-06 05:53:14 +0000919 AvailableAnalysis[PI] = P;
Dan Gohmande6188a2010-08-12 23:50:08 +0000920
Dan Gohmanb83d1b62010-08-12 23:46:28 +0000921 assert(!AvailableAnalysis.empty());
Devang Patel643676c2006-11-11 01:10:19 +0000922
Dan Gohmande6188a2010-08-12 23:50:08 +0000923 // This pass is the current implementation of all of the interfaces it
924 // implements as well.
Chandler Carruth5b0d3e32015-01-28 09:47:21 +0000925 const PassInfo *PInf = TPM->findAnalysisPassInfo(PI);
Craig Topperc6207612014-04-09 06:08:46 +0000926 if (!PInf) return;
Owen Andersona7aed182010-08-06 18:33:48 +0000927 const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
Owen Anderson3183ef12010-07-20 16:55:05 +0000928 for (unsigned i = 0, e = II.size(); i != e; ++i)
Owen Andersona7aed182010-08-06 18:33:48 +0000929 AvailableAnalysis[II[i]->getTypeInfo()] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000930}
931
Devang Patel9d9fc902007-03-06 17:52:53 +0000932// Return true if P preserves high level analysis used by other
933// passes managed by this manager
934bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000935 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000936 if (AnUsage->getPreservesAll())
Devang Patel9d9fc902007-03-06 17:52:53 +0000937 return true;
Dan Gohmande6188a2010-08-12 23:50:08 +0000938
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000939 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
Yaron Kerenbd873192016-10-02 19:21:41 +0000940 for (Pass *P1 : HigherLevelAnalysis) {
Craig Topperc6207612014-04-09 06:08:46 +0000941 if (P1->getAsImmutablePass() == nullptr &&
David Majnemer0d955d02016-08-11 22:21:41 +0000942 !is_contained(PreservedSet, P1->getPassID()))
Devang Patel01919d22007-03-08 19:05:01 +0000943 return false;
Devang Patel9d9fc902007-03-06 17:52:53 +0000944 }
Dan Gohmande6188a2010-08-12 23:50:08 +0000945
Devang Patel9d9fc902007-03-06 17:52:53 +0000946 return true;
947}
948
Chris Lattner02eb94c2008-08-07 07:34:50 +0000949/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
Devang Patela273d1c2007-07-19 18:02:32 +0000950void PMDataManager::verifyPreservedAnalysis(Pass *P) {
Chris Lattner02eb94c2008-08-07 07:34:50 +0000951 // Don't do this unless assertions are enabled.
952#ifdef NDEBUG
953 return;
954#endif
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000955 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
956 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
Devang Patelf68a3492006-11-07 22:35:17 +0000957
Devang Patelef432532007-07-19 05:36:09 +0000958 // Verify preserved analysis
Yaron Kerenbd873192016-10-02 19:21:41 +0000959 for (AnalysisID AID : PreservedSet) {
Dan Gohman4dbb3012009-09-28 00:27:48 +0000960 if (Pass *AP = findAnalysisPass(AID, true)) {
Chris Lattner707431c2010-03-30 04:03:22 +0000961 TimeRegion PassTimer(getPassTimer(AP));
Devang Patela273d1c2007-07-19 18:02:32 +0000962 AP->verifyAnalysis();
Dan Gohman4dbb3012009-09-28 00:27:48 +0000963 }
Devang Patel9dbe4d12008-07-01 17:44:24 +0000964 }
965}
966
Devang Patel67c79a42008-07-01 19:50:56 +0000967/// Remove Analysis not preserved by Pass P
Devang Patela273d1c2007-07-19 18:02:32 +0000968void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000969 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
970 if (AnUsage->getPreservesAll())
Devang Patel2e169c32006-12-07 20:03:49 +0000971 return;
972
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000973 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
Michael Ilsemanc33b6ac2013-02-26 01:31:59 +0000974 for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
Devang Patelbe6bd55e2006-12-12 23:07:44 +0000975 E = AvailableAnalysis.end(); I != E; ) {
Michael Ilsemanc33b6ac2013-02-26 01:31:59 +0000976 DenseMap<AnalysisID, Pass*>::iterator Info = I++;
Craig Topperc6207612014-04-09 06:08:46 +0000977 if (Info->second->getAsImmutablePass() == nullptr &&
David Majnemer0d955d02016-08-11 22:21:41 +0000978 !is_contained(PreservedSet, Info->first)) {
Devang Patel349170f2006-11-11 01:24:55 +0000979 // Remove this analysis
Andrew Trickb5e1e6c2013-09-19 06:02:43 +0000980 if (PassDebugging >= Details) {
Devang Patelbb4720c2008-06-03 01:02:16 +0000981 Pass *S = Info->second;
David Greene994e1bb2010-01-05 01:30:02 +0000982 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
983 dbgs() << S->getPassName() << "'\n";
Devang Patelbb4720c2008-06-03 01:02:16 +0000984 }
Dan Gohman193e4c02008-11-06 21:57:17 +0000985 AvailableAnalysis.erase(Info);
Devang Patelbb4720c2008-06-03 01:02:16 +0000986 }
Devang Patel349170f2006-11-11 01:24:55 +0000987 }
Dan Gohmande6188a2010-08-12 23:50:08 +0000988
Devang Patel42dd1e92007-03-06 01:55:46 +0000989 // Check inherited analysis also. If P is not preserving analysis
990 // provided by parent manager then remove it here.
991 for (unsigned Index = 0; Index < PMT_Last; ++Index) {
992
993 if (!InheritedAnalysis[Index])
994 continue;
995
Michael Ilsemanc33b6ac2013-02-26 01:31:59 +0000996 for (DenseMap<AnalysisID, Pass*>::iterator
Devang Patel42dd1e92007-03-06 01:55:46 +0000997 I = InheritedAnalysis[Index]->begin(),
998 E = InheritedAnalysis[Index]->end(); I != E; ) {
Michael Ilsemanc33b6ac2013-02-26 01:31:59 +0000999 DenseMap<AnalysisID, Pass *>::iterator Info = I++;
Craig Topperc6207612014-04-09 06:08:46 +00001000 if (Info->second->getAsImmutablePass() == nullptr &&
David Majnemer0d955d02016-08-11 22:21:41 +00001001 !is_contained(PreservedSet, Info->first)) {
Devang Patel42dd1e92007-03-06 01:55:46 +00001002 // Remove this analysis
Andrew Trickb5e1e6c2013-09-19 06:02:43 +00001003 if (PassDebugging >= Details) {
Andreas Neustifter46651412009-12-04 06:58:24 +00001004 Pass *S = Info->second;
David Greene994e1bb2010-01-05 01:30:02 +00001005 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
1006 dbgs() << S->getPassName() << "'\n";
Andreas Neustifter46651412009-12-04 06:58:24 +00001007 }
Devang Patel01919d22007-03-08 19:05:01 +00001008 InheritedAnalysis[Index]->erase(Info);
Andreas Neustifter46651412009-12-04 06:58:24 +00001009 }
Devang Patel42dd1e92007-03-06 01:55:46 +00001010 }
1011 }
Devang Patelf68a3492006-11-07 22:35:17 +00001012}
1013
Devang Patelca189262006-11-14 03:05:08 +00001014/// Remove analysis passes that are not used any longer
Daniel Dunbarad36e8a2009-11-06 10:58:06 +00001015void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
Devang Patel003a5592007-03-05 20:01:30 +00001016 enum PassDebuggingString DBG_STR) {
Devang Patel17ad0962006-12-08 00:37:52 +00001017
Devang Patel8adae862007-07-20 18:04:54 +00001018 SmallVector<Pass *, 12> DeadPasses;
Devang Patel69e9f6d2007-04-16 20:27:05 +00001019
Devang Patel2ff44922007-04-16 20:39:59 +00001020 // If this is a on the fly manager then it does not have TPM.
Devang Patel69e9f6d2007-04-16 20:27:05 +00001021 if (!TPM)
1022 return;
1023
Devang Patel17ad0962006-12-08 00:37:52 +00001024 TPM->collectLastUses(DeadPasses, P);
1025
Andrew Trickb5e1e6c2013-09-19 06:02:43 +00001026 if (PassDebugging >= Details && !DeadPasses.empty()) {
David Greene994e1bb2010-01-05 01:30:02 +00001027 dbgs() << " -*- '" << P->getPassName();
1028 dbgs() << "' is the last user of following pass instances.";
1029 dbgs() << " Free these instances\n";
Evan Cheng93af6ce2008-06-04 09:13:31 +00001030 }
1031
Yaron Kerenbd873192016-10-02 19:21:41 +00001032 for (Pass *P : DeadPasses)
1033 freePass(P, Msg, DBG_STR);
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001034}
Devang Patel200d3052006-12-13 23:50:44 +00001035
Daniel Dunbarad36e8a2009-11-06 10:58:06 +00001036void PMDataManager::freePass(Pass *P, StringRef Msg,
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001037 enum PassDebuggingString DBG_STR) {
1038 dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
Devang Patel200d3052006-12-13 23:50:44 +00001039
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001040 {
1041 // If the pass crashes releasing memory, remember this.
1042 PassManagerPrettyStackEntry X(P);
Chris Lattner707431c2010-03-30 04:03:22 +00001043 TimeRegion PassTimer(getPassTimer(P));
1044
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001045 P->releaseMemory();
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001046 }
1047
Owen Andersona7aed182010-08-06 18:33:48 +00001048 AnalysisID PI = P->getPassID();
Chandler Carruth5b0d3e32015-01-28 09:47:21 +00001049 if (const PassInfo *PInf = TPM->findAnalysisPassInfo(PI)) {
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001050 // Remove the pass itself (if it is not already removed).
1051 AvailableAnalysis.erase(PI);
1052
1053 // Remove all interfaces this pass implements, for which it is also
1054 // listed as the available implementation.
Owen Andersona7aed182010-08-06 18:33:48 +00001055 const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
Owen Anderson3183ef12010-07-20 16:55:05 +00001056 for (unsigned i = 0, e = II.size(); i != e; ++i) {
Michael Ilsemanc33b6ac2013-02-26 01:31:59 +00001057 DenseMap<AnalysisID, Pass*>::iterator Pos =
Owen Andersona7aed182010-08-06 18:33:48 +00001058 AvailableAnalysis.find(II[i]->getTypeInfo());
Dan Gohman5e8ba5d2009-09-27 23:38:27 +00001059 if (Pos != AvailableAnalysis.end() && Pos->second == P)
Devang Patelc3e3ca92008-10-06 20:36:36 +00001060 AvailableAnalysis.erase(Pos);
Devang Patelc3e3ca92008-10-06 20:36:36 +00001061 }
Devang Patel17ad0962006-12-08 00:37:52 +00001062 }
Devang Patelca189262006-11-14 03:05:08 +00001063}
1064
Dan Gohmande6188a2010-08-12 23:50:08 +00001065/// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +00001066/// AvailableAnalysis appropriately if ProcessAnalysis is true.
Chris Lattner60987362009-03-06 05:53:14 +00001067void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
Devang Pateld440cd92006-12-08 23:53:00 +00001068 // This manager is going to manage pass P. Set up analysis resolver
1069 // to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +00001070 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Pateld440cd92006-12-08 23:53:00 +00001071 P->setResolver(AR);
1072
Devang Patelec2b9a72007-03-05 22:57:49 +00001073 // If a FunctionPass F is the last user of ModulePass info M
1074 // then the F's manager, not F, records itself as a last user of M.
Devang Patel8adae862007-07-20 18:04:54 +00001075 SmallVector<Pass *, 12> TransferLastUses;
Devang Patelec2b9a72007-03-05 22:57:49 +00001076
Chris Lattner60987362009-03-06 05:53:14 +00001077 if (!ProcessAnalysis) {
1078 // Add pass
1079 PassVector.push_back(P);
1080 return;
Devang Patel90b05e02006-11-11 02:04:19 +00001081 }
Devang Patel8cad70d2006-11-11 01:51:02 +00001082
Chris Lattner60987362009-03-06 05:53:14 +00001083 // At the moment, this pass is the last user of all required passes.
1084 SmallVector<Pass *, 12> LastUses;
Chandler Carruth44a13852015-08-19 03:02:12 +00001085 SmallVector<Pass *, 8> UsedPasses;
Chris Lattner60987362009-03-06 05:53:14 +00001086 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
1087
1088 unsigned PDepth = this->getDepth();
1089
Chandler Carruth44a13852015-08-19 03:02:12 +00001090 collectRequiredAndUsedAnalyses(UsedPasses, ReqAnalysisNotAvailable, P);
1091 for (Pass *PUsed : UsedPasses) {
Chris Lattner60987362009-03-06 05:53:14 +00001092 unsigned RDepth = 0;
1093
Chandler Carruth44a13852015-08-19 03:02:12 +00001094 assert(PUsed->getResolver() && "Analysis Resolver is not set");
1095 PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
Chris Lattner60987362009-03-06 05:53:14 +00001096 RDepth = DM.getDepth();
1097
1098 if (PDepth == RDepth)
Chandler Carruth44a13852015-08-19 03:02:12 +00001099 LastUses.push_back(PUsed);
Chris Lattner60987362009-03-06 05:53:14 +00001100 else if (PDepth > RDepth) {
1101 // Let the parent claim responsibility of last use
Chandler Carruth44a13852015-08-19 03:02:12 +00001102 TransferLastUses.push_back(PUsed);
Chris Lattner60987362009-03-06 05:53:14 +00001103 // Keep track of higher level analysis used by this manager.
Chandler Carruth44a13852015-08-19 03:02:12 +00001104 HigherLevelAnalysis.push_back(PUsed);
Dan Gohmande6188a2010-08-12 23:50:08 +00001105 } else
Chandler Carruth44a13852015-08-19 03:02:12 +00001106 llvm_unreachable("Unable to accommodate Used Pass");
Chris Lattner60987362009-03-06 05:53:14 +00001107 }
1108
1109 // Set P as P's last user until someone starts using P.
1110 // However, if P is a Pass Manager then it does not need
1111 // to record its last user.
Craig Topperc6207612014-04-09 06:08:46 +00001112 if (!P->getAsPMDataManager())
Chris Lattner60987362009-03-06 05:53:14 +00001113 LastUses.push_back(P);
1114 TPM->setLastUser(LastUses, P);
1115
1116 if (!TransferLastUses.empty()) {
Chris Lattner2fa26e52010-01-22 05:24:46 +00001117 Pass *My_PM = getAsPass();
Chris Lattner60987362009-03-06 05:53:14 +00001118 TPM->setLastUser(TransferLastUses, My_PM);
1119 TransferLastUses.clear();
1120 }
1121
Dan Gohman6304db32010-08-16 22:57:28 +00001122 // Now, take care of required analyses that are not available.
Chandler Carruth2f02ea42015-08-18 18:41:53 +00001123 for (AnalysisID ID : ReqAnalysisNotAvailable) {
1124 const PassInfo *PI = TPM->findAnalysisPassInfo(ID);
Owen Andersona7aed182010-08-06 18:33:48 +00001125 Pass *AnalysisPass = PI->createPass();
Chris Lattner60987362009-03-06 05:53:14 +00001126 this->addLowerLevelRequiredPass(P, AnalysisPass);
1127 }
1128
1129 // Take a note of analysis required and made available by this pass.
1130 // Remove the analysis not preserved by this pass
1131 removeNotPreservedAnalysis(P);
1132 recordAvailableAnalysis(P);
1133
Devang Patel8cad70d2006-11-11 01:51:02 +00001134 // Add pass
1135 PassVector.push_back(P);
Devang Patel8cad70d2006-11-11 01:51:02 +00001136}
1137
Devang Patele64d3052007-04-16 20:12:57 +00001138
Chandler Carruth44a13852015-08-19 03:02:12 +00001139/// Populate UP with analysis pass that are used or required by
Devang Patele64d3052007-04-16 20:12:57 +00001140/// pass P and are available. Populate RP_NotAvail with analysis
1141/// pass that are required by pass P but are not available.
Chandler Carruth44a13852015-08-19 03:02:12 +00001142void PMDataManager::collectRequiredAndUsedAnalyses(
1143 SmallVectorImpl<Pass *> &UP, SmallVectorImpl<AnalysisID> &RP_NotAvail,
1144 Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +00001145 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
Chandler Carruth44a13852015-08-19 03:02:12 +00001146
1147 for (const auto &UsedID : AnUsage->getUsedSet())
1148 if (Pass *AnalysisPass = findAnalysisPass(UsedID, true))
1149 UP.push_back(AnalysisPass);
1150
Chandler Carruth2f02ea42015-08-18 18:41:53 +00001151 for (const auto &RequiredID : AnUsage->getRequiredSet())
1152 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
Chandler Carruth44a13852015-08-19 03:02:12 +00001153 UP.push_back(AnalysisPass);
Devang Patele64d3052007-04-16 20:12:57 +00001154 else
Chandler Carruth2f02ea42015-08-18 18:41:53 +00001155 RP_NotAvail.push_back(RequiredID);
Devang Patelf58183d2006-12-12 23:09:32 +00001156
Chandler Carruth2f02ea42015-08-18 18:41:53 +00001157 for (const auto &RequiredID : AnUsage->getRequiredTransitiveSet())
1158 if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
Chandler Carruth44a13852015-08-19 03:02:12 +00001159 UP.push_back(AnalysisPass);
Devang Patele64d3052007-04-16 20:12:57 +00001160 else
Chandler Carruth2f02ea42015-08-18 18:41:53 +00001161 RP_NotAvail.push_back(RequiredID);
Devang Patel1d6267c2006-12-07 23:05:44 +00001162}
1163
Devang Patel07f4f582006-11-14 21:49:36 +00001164// All Required analyses should be available to the pass as it runs! Here
1165// we fill in the AnalysisImpls member of the pass so that it can
1166// successfully use the getAnalysis() method to retrieve the
1167// implementations it needs.
1168//
Devang Pateldbe4a1e2006-12-07 18:36:24 +00001169void PMDataManager::initializeAnalysisImpl(Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +00001170 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
1171
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001172 for (const AnalysisID ID : AnUsage->getRequiredSet()) {
1173 Pass *Impl = findAnalysisPass(ID, true);
Craig Topperc6207612014-04-09 06:08:46 +00001174 if (!Impl)
Devang Patel56a5c622007-04-16 20:44:16 +00001175 // This may be analysis pass that is initialized on the fly.
1176 // If that is not the case then it will raise an assert when it is used.
1177 continue;
Devang Patelb66334b2007-01-05 22:47:07 +00001178 AnalysisResolver *AR = P->getResolver();
Chris Lattner60987362009-03-06 05:53:14 +00001179 assert(AR && "Analysis Resolver is not set");
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001180 AR->addAnalysisImplsPair(ID, Impl);
Devang Patel07f4f582006-11-14 21:49:36 +00001181 }
1182}
1183
Devang Patel640c5bb2006-12-08 22:30:11 +00001184/// Find the pass that implements Analysis AID. If desired pass is not found
1185/// then return NULL.
1186Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
1187
1188 // Check if AvailableAnalysis map has one entry.
Michael Ilsemanc33b6ac2013-02-26 01:31:59 +00001189 DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
Devang Patel640c5bb2006-12-08 22:30:11 +00001190
1191 if (I != AvailableAnalysis.end())
1192 return I->second;
1193
1194 // Search Parents through TopLevelManager
1195 if (SearchParent)
1196 return TPM->findAnalysisPass(AID);
Dan Gohmande6188a2010-08-12 23:50:08 +00001197
Craig Topperc6207612014-04-09 06:08:46 +00001198 return nullptr;
Devang Patel640c5bb2006-12-08 22:30:11 +00001199}
1200
Devang Patel991aeba2006-12-15 20:13:01 +00001201// Print list of passes that are last used by P.
1202void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
1203
Devang Patel8adae862007-07-20 18:04:54 +00001204 SmallVector<Pass *, 12> LUses;
Devang Patel2ff44922007-04-16 20:39:59 +00001205
1206 // If this is a on the fly manager then it does not have TPM.
1207 if (!TPM)
1208 return;
1209
Devang Patel991aeba2006-12-15 20:13:01 +00001210 TPM->collectLastUses(LUses, P);
Dan Gohmande6188a2010-08-12 23:50:08 +00001211
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001212 for (Pass *P : LUses) {
Eric Christophera13839f2014-02-26 23:27:16 +00001213 dbgs() << "--" << std::string(Offset*2, ' ');
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001214 P->dumpPassStructure(0);
Devang Patel991aeba2006-12-15 20:13:01 +00001215 }
1216}
1217
1218void PMDataManager::dumpPassArguments() const {
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001219 for (Pass *P : PassVector) {
1220 if (PMDataManager *PMD = P->getAsPMDataManager())
Devang Patel991aeba2006-12-15 20:13:01 +00001221 PMD->dumpPassArguments();
1222 else
Owen Andersona7aed182010-08-06 18:33:48 +00001223 if (const PassInfo *PI =
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001224 TPM->findAnalysisPassInfo(P->getPassID()))
Devang Patel991aeba2006-12-15 20:13:01 +00001225 if (!PI->isAnalysisGroup())
David Greene994e1bb2010-01-05 01:30:02 +00001226 dbgs() << " -" << PI->getPassArgument();
Devang Patel991aeba2006-12-15 20:13:01 +00001227 }
1228}
1229
Chris Lattnerdd6304f2007-08-10 06:17:04 +00001230void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
1231 enum PassDebuggingString S2,
Daniel Dunbarad36e8a2009-11-06 10:58:06 +00001232 StringRef Msg) {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +00001233 if (PassDebugging < Executions)
Devang Patel991aeba2006-12-15 20:13:01 +00001234 return;
Pavel Labathec534e62016-10-25 16:20:07 +00001235 dbgs() << "[" << std::chrono::system_clock::now() << "] " << (void *)this
Chandler Carruth20c56932014-04-27 23:59:25 +00001236 << std::string(getDepth() * 2 + 1, ' ');
Devang Patel003a5592007-03-05 20:01:30 +00001237 switch (S1) {
1238 case EXECUTION_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001239 dbgs() << "Executing Pass '" << P->getPassName();
Devang Patel003a5592007-03-05 20:01:30 +00001240 break;
1241 case MODIFICATION_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001242 dbgs() << "Made Modification '" << P->getPassName();
Devang Patel003a5592007-03-05 20:01:30 +00001243 break;
1244 case FREEING_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001245 dbgs() << " Freeing Pass '" << P->getPassName();
Devang Patel003a5592007-03-05 20:01:30 +00001246 break;
1247 default:
1248 break;
1249 }
1250 switch (S2) {
1251 case ON_BASICBLOCK_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001252 dbgs() << "' on BasicBlock '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001253 break;
1254 case ON_FUNCTION_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001255 dbgs() << "' on Function '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001256 break;
1257 case ON_MODULE_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001258 dbgs() << "' on Module '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001259 break;
Tobias Grosser23c83412010-10-20 01:54:44 +00001260 case ON_REGION_MSG:
1261 dbgs() << "' on Region '" << Msg << "'...\n";
1262 break;
Devang Patel003a5592007-03-05 20:01:30 +00001263 case ON_LOOP_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001264 dbgs() << "' on Loop '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001265 break;
1266 case ON_CG_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001267 dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001268 break;
1269 default:
1270 break;
1271 }
Devang Patel991aeba2006-12-15 20:13:01 +00001272}
1273
Chris Lattner4c1e9542009-03-06 06:45:05 +00001274void PMDataManager::dumpRequiredSet(const Pass *P) const {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +00001275 if (PassDebugging < Details)
Chris Lattner4c493d92008-08-08 15:14:09 +00001276 return;
Dan Gohmande6188a2010-08-12 23:50:08 +00001277
Chris Lattner4c493d92008-08-08 15:14:09 +00001278 AnalysisUsage analysisUsage;
1279 P->getAnalysisUsage(analysisUsage);
1280 dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
1281}
1282
Chris Lattner4c1e9542009-03-06 06:45:05 +00001283void PMDataManager::dumpPreservedSet(const Pass *P) const {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +00001284 if (PassDebugging < Details)
Chris Lattner4c493d92008-08-08 15:14:09 +00001285 return;
Dan Gohmande6188a2010-08-12 23:50:08 +00001286
Chris Lattner4c493d92008-08-08 15:14:09 +00001287 AnalysisUsage analysisUsage;
1288 P->getAnalysisUsage(analysisUsage);
1289 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
1290}
1291
Chandler Carruth44a13852015-08-19 03:02:12 +00001292void PMDataManager::dumpUsedSet(const Pass *P) const {
1293 if (PassDebugging < Details)
1294 return;
1295
1296 AnalysisUsage analysisUsage;
1297 P->getAnalysisUsage(analysisUsage);
1298 dumpAnalysisUsage("Used", P, analysisUsage.getUsedSet());
1299}
1300
Daniel Dunbarad36e8a2009-11-06 10:58:06 +00001301void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
Chris Lattner4c1e9542009-03-06 06:45:05 +00001302 const AnalysisUsage::VectorType &Set) const {
Andrew Trickb5e1e6c2013-09-19 06:02:43 +00001303 assert(PassDebugging >= Details);
Chris Lattner4c493d92008-08-08 15:14:09 +00001304 if (Set.empty())
1305 return;
Roman Divackyad06cee2012-09-05 22:26:57 +00001306 dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
Chris Lattner4c1e9542009-03-06 06:45:05 +00001307 for (unsigned i = 0; i != Set.size(); ++i) {
David Greene994e1bb2010-01-05 01:30:02 +00001308 if (i) dbgs() << ',';
Chandler Carruth5b0d3e32015-01-28 09:47:21 +00001309 const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]);
Andrew Trick6bbaf132011-06-03 00:48:58 +00001310 if (!PInf) {
1311 // Some preserved passes, such as AliasAnalysis, may not be initialized by
1312 // all drivers.
1313 dbgs() << " Uninitialized Pass";
1314 continue;
1315 }
Owen Andersona7aed182010-08-06 18:33:48 +00001316 dbgs() << ' ' << PInf->getPassName();
Chris Lattner4c1e9542009-03-06 06:45:05 +00001317 }
David Greene994e1bb2010-01-05 01:30:02 +00001318 dbgs() << '\n';
Devang Patel991aeba2006-12-15 20:13:01 +00001319}
Devang Patel9bdf7d42006-12-08 23:28:54 +00001320
Devang Patel004937b2007-07-27 20:06:09 +00001321/// Add RequiredPass into list of lower level passes required by pass P.
1322/// RequiredPass is run on the fly by Pass Manager when P requests it
1323/// through getAnalysis interface.
1324/// This should be handled by specific pass manager.
1325void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1326 if (TPM) {
1327 TPM->dumpArguments();
1328 TPM->dumpPasses();
1329 }
Devang Patel8df7cc12008-02-02 01:43:30 +00001330
Dan Gohmande6188a2010-08-12 23:50:08 +00001331 // Module Level pass may required Function Level analysis info
1332 // (e.g. dominator info). Pass manager uses on the fly function pass manager
1333 // to provide this on demand. In that case, in Pass manager terminology,
Devang Patel8df7cc12008-02-02 01:43:30 +00001334 // module level pass is requiring lower level analysis info managed by
1335 // lower level pass manager.
1336
1337 // When Pass manager is not able to order required analysis info, Pass manager
Dan Gohmande6188a2010-08-12 23:50:08 +00001338 // checks whether any lower level manager will be able to provide this
Devang Patel8df7cc12008-02-02 01:43:30 +00001339 // analysis info on demand or not.
Devang Patelab85d6b2008-06-03 01:20:02 +00001340#ifndef NDEBUG
David Greene994e1bb2010-01-05 01:30:02 +00001341 dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
1342 dbgs() << "' required by '" << P->getPassName() << "'\n";
Devang Patelab85d6b2008-06-03 01:20:02 +00001343#endif
Torok Edwinfbcc6632009-07-14 16:55:14 +00001344 llvm_unreachable("Unable to schedule pass");
Devang Patel004937b2007-07-27 20:06:09 +00001345}
1346
Owen Andersona7aed182010-08-06 18:33:48 +00001347Pass *PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F) {
Craig Topperc514b542012-02-05 22:14:15 +00001348 llvm_unreachable("Unable to find on the fly pass");
Dan Gohmanffdee302010-06-21 18:46:45 +00001349}
1350
Devang Patele7599552007-01-12 18:52:44 +00001351// Destructor
1352PMDataManager::~PMDataManager() {
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001353 for (Pass *P : PassVector)
1354 delete P;
Devang Patele7599552007-01-12 18:52:44 +00001355}
1356
Devang Patel9bdf7d42006-12-08 23:28:54 +00001357//===----------------------------------------------------------------------===//
1358// NOTE: Is this the right place to define this method ?
Duncan Sands5a913d62009-01-28 13:14:17 +00001359// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
1360Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
Devang Patel9bdf7d42006-12-08 23:28:54 +00001361 return PM.findAnalysisPass(ID, dir);
1362}
1363
Dan Gohmande6188a2010-08-12 23:50:08 +00001364Pass *AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI,
Devang Patel92942812007-04-16 20:56:24 +00001365 Function &F) {
1366 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1367}
1368
Devang Patela1514cb2006-12-07 19:39:39 +00001369//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001370// BBPassManager implementation
Devang Patel6e5a1132006-11-07 21:31:57 +00001371
Dan Gohmande6188a2010-08-12 23:50:08 +00001372/// Execute all of the passes scheduled for execution by invoking
1373/// runOnBasicBlock method. Keep track of whether any of the passes modifies
Devang Patel6e5a1132006-11-07 21:31:57 +00001374/// the function, and if so, return true.
Chris Lattner4c1e9542009-03-06 06:45:05 +00001375bool BBPassManager::runOnFunction(Function &F) {
Reid Spencer5301e7c2007-01-30 20:08:39 +00001376 if (F.isDeclaration())
Devang Patel745a6962006-12-12 23:15:28 +00001377 return false;
1378
Devang Patele9585592006-12-08 01:38:28 +00001379 bool Changed = doInitialization(F);
Jessica Paquettee49374d2018-05-18 17:26:39 +00001380 Module &M = *F.getParent();
Devang Patel050ec722006-11-14 01:23:29 +00001381
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001382 unsigned InstrCount, BBSize = 0;
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001383 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
Xin Tong023e25a2018-07-22 05:27:41 +00001384 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001385 if (EmitICRemark)
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001386 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001387
1388 for (BasicBlock &BB : F) {
1389 // Collect the initial size of the basic block.
1390 if (EmitICRemark)
1391 BBSize = BB.size();
Devang Patelabfbe3b2006-12-16 00:56:26 +00001392 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1393 BasicBlockPass *BP = getContainedPass(Index);
Dan Gohman74b189f2010-03-01 17:34:28 +00001394 bool LocalChanged = false;
Devang Patelf6d1d212006-12-14 00:25:06 +00001395
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001396 dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, BB.getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001397 dumpRequiredSet(BP);
Devang Patelf6d1d212006-12-14 00:25:06 +00001398
Devang Patelabfbe3b2006-12-16 00:56:26 +00001399 initializeAnalysisImpl(BP);
Devang Patel93a197c2006-12-14 00:08:04 +00001400
Chris Lattner4c1e9542009-03-06 06:45:05 +00001401 {
1402 // If the pass crashes, remember this.
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001403 PassManagerPrettyStackEntry X(BP, BB);
Chris Lattner707431c2010-03-30 04:03:22 +00001404 TimeRegion PassTimer(getPassTimer(BP));
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001405 LocalChanged |= BP->runOnBasicBlock(BB);
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001406 if (EmitICRemark) {
1407 unsigned NewSize = BB.size();
1408 // Update the size of the basic block, emit a remark, and update the
1409 // size of the module.
1410 if (NewSize != BBSize) {
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001411 int64_t Delta =
1412 static_cast<int64_t>(NewSize) - static_cast<int64_t>(BBSize);
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001413 emitInstrCountChangedRemark(BP, M, Delta, InstrCount,
1414 FunctionToInstrCount, &F);
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001415 InstrCount = static_cast<int64_t>(InstrCount) + Delta;
1416 BBSize = NewSize;
1417 }
1418 }
Chris Lattner4c1e9542009-03-06 06:45:05 +00001419 }
Devang Patel93a197c2006-12-14 00:08:04 +00001420
Dan Gohman74b189f2010-03-01 17:34:28 +00001421 Changed |= LocalChanged;
Dan Gohmande6188a2010-08-12 23:50:08 +00001422 if (LocalChanged)
Dan Gohman929391a2008-01-29 12:09:55 +00001423 dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001424 BB.getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001425 dumpPreservedSet(BP);
Chandler Carruth44a13852015-08-19 03:02:12 +00001426 dumpUsedSet(BP);
Devang Patel93a197c2006-12-14 00:08:04 +00001427
Devang Patela273d1c2007-07-19 18:02:32 +00001428 verifyPreservedAnalysis(BP);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001429 removeNotPreservedAnalysis(BP);
1430 recordAvailableAnalysis(BP);
Florian Hahn03c3a1a2017-07-13 10:52:00 +00001431 removeDeadPasses(BP, BB.getName(), ON_BASICBLOCK_MSG);
Devang Patel6e5a1132006-11-07 21:31:57 +00001432 }
Jessica Paquette9eda13e2018-08-31 20:20:53 +00001433 }
Chris Lattnerde2aa652007-08-10 06:22:25 +00001434
Bill Wendling6ce6d262009-12-25 13:50:18 +00001435 return doFinalization(F) || Changed;
Devang Patel6e5a1132006-11-07 21:31:57 +00001436}
1437
Devang Patel475c4532006-12-08 00:59:05 +00001438// Implement doInitialization and doFinalization
Duncan Sands51495602009-02-13 09:42:34 +00001439bool BBPassManager::doInitialization(Module &M) {
Devang Patel475c4532006-12-08 00:59:05 +00001440 bool Changed = false;
1441
Chris Lattner4c1e9542009-03-06 06:45:05 +00001442 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1443 Changed |= getContainedPass(Index)->doInitialization(M);
Devang Patel475c4532006-12-08 00:59:05 +00001444
1445 return Changed;
1446}
1447
Duncan Sands51495602009-02-13 09:42:34 +00001448bool BBPassManager::doFinalization(Module &M) {
Devang Patel475c4532006-12-08 00:59:05 +00001449 bool Changed = false;
1450
Pedro Artigas41b98842012-12-05 17:12:22 +00001451 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
Chris Lattner4c1e9542009-03-06 06:45:05 +00001452 Changed |= getContainedPass(Index)->doFinalization(M);
Devang Patel475c4532006-12-08 00:59:05 +00001453
1454 return Changed;
1455}
1456
Duncan Sands51495602009-02-13 09:42:34 +00001457bool BBPassManager::doInitialization(Function &F) {
Devang Patel475c4532006-12-08 00:59:05 +00001458 bool Changed = false;
1459
Devang Patelabfbe3b2006-12-16 00:56:26 +00001460 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1461 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +00001462 Changed |= BP->doInitialization(F);
1463 }
1464
1465 return Changed;
1466}
1467
Duncan Sands51495602009-02-13 09:42:34 +00001468bool BBPassManager::doFinalization(Function &F) {
Devang Patel475c4532006-12-08 00:59:05 +00001469 bool Changed = false;
1470
Devang Patelabfbe3b2006-12-16 00:56:26 +00001471 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1472 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +00001473 Changed |= BP->doFinalization(F);
1474 }
1475
1476 return Changed;
1477}
1478
1479
Devang Patela1514cb2006-12-07 19:39:39 +00001480//===----------------------------------------------------------------------===//
Devang Patelb67904d2006-12-13 02:36:01 +00001481// FunctionPassManager implementation
Devang Patela1514cb2006-12-07 19:39:39 +00001482
Devang Patel4e12f862006-11-08 10:44:40 +00001483/// Create new Function pass manager
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00001484FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
Andrew Trick08966212011-08-29 17:07:00 +00001485 FPM = new FunctionPassManagerImpl();
Devang Patel9c6290c2006-12-12 22:02:16 +00001486 // FPM is the top level manager.
1487 FPM->setTopLevelManager(FPM);
Devang Patel1036b652006-12-12 23:27:37 +00001488
Dan Gohman565df952008-03-13 02:08:36 +00001489 AnalysisResolver *AR = new AnalysisResolver(*FPM);
Devang Patel1036b652006-12-12 23:27:37 +00001490 FPM->setResolver(AR);
Devang Patel1f653682006-12-08 18:57:16 +00001491}
1492
Devang Patelb67904d2006-12-13 02:36:01 +00001493FunctionPassManager::~FunctionPassManager() {
Devang Patelab97cf42006-12-13 00:09:23 +00001494 delete FPM;
1495}
1496
Dan Gohmande6188a2010-08-12 23:50:08 +00001497void FunctionPassManager::add(Pass *P) {
Andrew Trickcbc845f2012-02-01 07:16:20 +00001498 FPM->add(P);
Devang Patel4e12f862006-11-08 10:44:40 +00001499}
1500
Devang Patel9f3083e2006-11-15 19:39:54 +00001501/// run - Execute all of the passes scheduled for execution. Keep
1502/// track of whether any of the passes modifies the function, and if
1503/// so, return true.
1504///
Devang Patelb67904d2006-12-13 02:36:01 +00001505bool FunctionPassManager::run(Function &F) {
Peter Collingbourne7f00d0a2016-11-09 17:49:19 +00001506 handleAllErrors(F.materialize(), [&](ErrorInfoBase &EIB) {
1507 report_fatal_error("Error reading bitcode file: " + EIB.message());
1508 });
Devang Patel272908d2006-12-08 22:57:48 +00001509 return FPM->run(F);
Devang Patel9f3083e2006-11-15 19:39:54 +00001510}
1511
1512
Devang Patelff631ae2006-11-15 01:27:05 +00001513/// doInitialization - Run all of the initializers for the function passes.
1514///
Devang Patelb67904d2006-12-13 02:36:01 +00001515bool FunctionPassManager::doInitialization() {
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00001516 return FPM->doInitialization(*M);
Devang Patelff631ae2006-11-15 01:27:05 +00001517}
1518
Dan Gohmane6656eb2007-07-30 14:51:13 +00001519/// doFinalization - Run all of the finalizers for the function passes.
Devang Patelff631ae2006-11-15 01:27:05 +00001520///
Devang Patelb67904d2006-12-13 02:36:01 +00001521bool FunctionPassManager::doFinalization() {
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00001522 return FPM->doFinalization(*M);
Devang Patelff631ae2006-11-15 01:27:05 +00001523}
1524
Devang Patela1514cb2006-12-07 19:39:39 +00001525//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001526// FunctionPassManagerImpl implementation
1527//
Duncan Sands51495602009-02-13 09:42:34 +00001528bool FunctionPassManagerImpl::doInitialization(Module &M) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001529 bool Changed = false;
1530
Dan Gohman05ebc8f2009-11-23 16:24:18 +00001531 dumpArguments();
1532 dumpPasses();
1533
Yaron Keren4849aa32015-06-05 17:48:47 +00001534 for (ImmutablePass *ImPass : getImmutablePasses())
1535 Changed |= ImPass->doInitialization(M);
Pedro Artigas41b98842012-12-05 17:12:22 +00001536
Chris Lattner4c1e9542009-03-06 06:45:05 +00001537 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1538 Changed |= getContainedManager(Index)->doInitialization(M);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001539
1540 return Changed;
1541}
1542
Duncan Sands51495602009-02-13 09:42:34 +00001543bool FunctionPassManagerImpl::doFinalization(Module &M) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001544 bool Changed = false;
1545
Pedro Artigas41b98842012-12-05 17:12:22 +00001546 for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
Chris Lattner4c1e9542009-03-06 06:45:05 +00001547 Changed |= getContainedManager(Index)->doFinalization(M);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001548
Yaron Keren4849aa32015-06-05 17:48:47 +00001549 for (ImmutablePass *ImPass : getImmutablePasses())
1550 Changed |= ImPass->doFinalization(M);
Pedro Artigas41b98842012-12-05 17:12:22 +00001551
Devang Patel67d6a5e2006-12-19 19:46:59 +00001552 return Changed;
1553}
1554
Devang Patelec9c58f2009-04-01 22:34:41 +00001555/// cleanup - After running all passes, clean up pass manager cache.
1556void FPPassManager::cleanup() {
1557 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1558 FunctionPass *FP = getContainedPass(Index);
1559 AnalysisResolver *AR = FP->getResolver();
1560 assert(AR && "Analysis Resolver is not set");
1561 AR->clearAnalysisImpls();
1562 }
1563}
1564
Torok Edwin24c78352009-06-29 18:49:09 +00001565void FunctionPassManagerImpl::releaseMemoryOnTheFly() {
1566 if (!wasRun)
1567 return;
1568 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1569 FPPassManager *FPPM = getContainedManager(Index);
1570 for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
1571 FPPM->getContainedPass(Index)->releaseMemory();
1572 }
1573 }
Torok Edwin896556e2009-06-29 21:05:10 +00001574 wasRun = false;
Torok Edwin24c78352009-06-29 18:49:09 +00001575}
1576
Devang Patel67d6a5e2006-12-19 19:46:59 +00001577// Execute all the passes managed by this top level manager.
1578// Return true if any function is modified by a pass.
1579bool FunctionPassManagerImpl::run(Function &F) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001580 bool Changed = false;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001581
Devang Patele3068402006-12-21 00:16:50 +00001582 initializeAllAnalysisInfo();
Juergen Ributzka34390c72014-05-16 02:33:15 +00001583 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
Serge Pavloved5eb932017-01-15 10:23:18 +00001584 Changed |= getContainedManager(Index)->runOnFunction(F);
Juergen Ributzka34390c72014-05-16 02:33:15 +00001585 F.getContext().yield();
1586 }
Devang Patelec9c58f2009-04-01 22:34:41 +00001587
1588 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1589 getContainedManager(Index)->cleanup();
1590
Torok Edwin24c78352009-06-29 18:49:09 +00001591 wasRun = true;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001592 return Changed;
1593}
1594
1595//===----------------------------------------------------------------------===//
1596// FPPassManager implementation
Devang Patel0c2012f2006-11-07 21:49:50 +00001597
Devang Patel8c78a0b2007-05-03 01:11:54 +00001598char FPPassManager::ID = 0;
Devang Patele7599552007-01-12 18:52:44 +00001599/// Print passes managed by this manager
1600void FPPassManager::dumpPassStructure(unsigned Offset) {
Benjamin Kramercc863b22011-10-16 16:30:34 +00001601 dbgs().indent(Offset*2) << "FunctionPass Manager\n";
Devang Patele7599552007-01-12 18:52:44 +00001602 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1603 FunctionPass *FP = getContainedPass(Index);
Dan Gohmanf71c5212010-08-19 01:29:07 +00001604 FP->dumpPassStructure(Offset + 1);
Devang Patele7599552007-01-12 18:52:44 +00001605 dumpLastUses(FP, Offset+1);
1606 }
1607}
1608
1609
Dan Gohmande6188a2010-08-12 23:50:08 +00001610/// Execute all of the passes scheduled for execution by invoking
1611/// runOnFunction method. Keep track of whether any of the passes modifies
Devang Patel0c2012f2006-11-07 21:49:50 +00001612/// the function, and if so, return true.
Devang Patel67d6a5e2006-12-19 19:46:59 +00001613bool FPPassManager::runOnFunction(Function &F) {
Chris Lattner60987362009-03-06 05:53:14 +00001614 if (F.isDeclaration())
1615 return false;
Devang Patel9f3083e2006-11-15 19:39:54 +00001616
1617 bool Changed = false;
Jessica Paquettee49374d2018-05-18 17:26:39 +00001618 Module &M = *F.getParent();
Devang Patelcbbf2912008-03-20 01:09:53 +00001619 // Collect inherited analysis from Module level pass manager.
1620 populateInheritedAnalysis(TPM->activeStack);
Devang Patel745a6962006-12-12 23:15:28 +00001621
Jessica Paquettef2a202c2018-08-31 20:19:41 +00001622 unsigned InstrCount, FunctionSize = 0;
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001623 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
Xin Tong023e25a2018-07-22 05:27:41 +00001624 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
Jessica Paquettef2a202c2018-08-31 20:19:41 +00001625 // Collect the initial size of the module.
1626 if (EmitICRemark) {
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001627 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
Jessica Paquettef2a202c2018-08-31 20:19:41 +00001628 FunctionSize = F.getInstructionCount();
1629 }
1630
Devang Patelabfbe3b2006-12-16 00:56:26 +00001631 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1632 FunctionPass *FP = getContainedPass(Index);
Dan Gohman74b189f2010-03-01 17:34:28 +00001633 bool LocalChanged = false;
Devang Patelabfbe3b2006-12-16 00:56:26 +00001634
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001635 dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001636 dumpRequiredSet(FP);
Devang Patel93a197c2006-12-14 00:08:04 +00001637
Devang Patelabfbe3b2006-12-16 00:56:26 +00001638 initializeAnalysisImpl(FP);
Eric Christopher3c0d5162012-03-23 03:54:05 +00001639
Chris Lattner4c1e9542009-03-06 06:45:05 +00001640 {
1641 PassManagerPrettyStackEntry X(FP, F);
Chris Lattner707431c2010-03-30 04:03:22 +00001642 TimeRegion PassTimer(getPassTimer(FP));
Dan Gohman74b189f2010-03-01 17:34:28 +00001643 LocalChanged |= FP->runOnFunction(F);
Jessica Paquettef2a202c2018-08-31 20:19:41 +00001644 if (EmitICRemark) {
1645 unsigned NewSize = F.getInstructionCount();
1646
1647 // Update the size of the function, emit a remark, and update the size
1648 // of the module.
1649 if (NewSize != FunctionSize) {
Jessica Paquettef2a202c2018-08-31 20:19:41 +00001650 int64_t Delta = static_cast<int64_t>(NewSize) -
1651 static_cast<int64_t>(FunctionSize);
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001652 emitInstrCountChangedRemark(FP, M, Delta, InstrCount,
1653 FunctionToInstrCount, &F);
Jessica Paquettef2a202c2018-08-31 20:19:41 +00001654 InstrCount = static_cast<int64_t>(InstrCount) + Delta;
1655 FunctionSize = NewSize;
1656 }
1657 }
Chris Lattner4c1e9542009-03-06 06:45:05 +00001658 }
Devang Patel93a197c2006-12-14 00:08:04 +00001659
Dan Gohman74b189f2010-03-01 17:34:28 +00001660 Changed |= LocalChanged;
1661 if (LocalChanged)
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001662 dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001663 dumpPreservedSet(FP);
Chandler Carruth44a13852015-08-19 03:02:12 +00001664 dumpUsedSet(FP);
Devang Patel93a197c2006-12-14 00:08:04 +00001665
Devang Patela273d1c2007-07-19 18:02:32 +00001666 verifyPreservedAnalysis(FP);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001667 removeNotPreservedAnalysis(FP);
1668 recordAvailableAnalysis(FP);
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001669 removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
Devang Patel9f3083e2006-11-15 19:39:54 +00001670 }
1671 return Changed;
1672}
1673
Devang Patel67d6a5e2006-12-19 19:46:59 +00001674bool FPPassManager::runOnModule(Module &M) {
Pedro Artigasd6b092b2012-11-29 17:47:05 +00001675 bool Changed = false;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001676
Serge Pavloved5eb932017-01-15 10:23:18 +00001677 for (Function &F : M)
Yaron Keren3b1e24b2015-06-05 14:15:07 +00001678 Changed |= runOnFunction(F);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001679
Pedro Artigasd6b092b2012-11-29 17:47:05 +00001680 return Changed;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001681}
1682
Duncan Sands51495602009-02-13 09:42:34 +00001683bool FPPassManager::doInitialization(Module &M) {
Devang Patelff631ae2006-11-15 01:27:05 +00001684 bool Changed = false;
1685
Chris Lattner4c1e9542009-03-06 06:45:05 +00001686 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1687 Changed |= getContainedPass(Index)->doInitialization(M);
Andrew Trickdc073ad2013-09-18 23:31:10 +00001688
Devang Patelff631ae2006-11-15 01:27:05 +00001689 return Changed;
1690}
1691
Duncan Sands51495602009-02-13 09:42:34 +00001692bool FPPassManager::doFinalization(Module &M) {
Devang Patelff631ae2006-11-15 01:27:05 +00001693 bool Changed = false;
Pedro Artigas41b98842012-12-05 17:12:22 +00001694
1695 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
Chris Lattner4c1e9542009-03-06 06:45:05 +00001696 Changed |= getContainedPass(Index)->doFinalization(M);
Andrew Trickdc073ad2013-09-18 23:31:10 +00001697
Devang Patelff631ae2006-11-15 01:27:05 +00001698 return Changed;
1699}
1700
Devang Patela1514cb2006-12-07 19:39:39 +00001701//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001702// MPPassManager implementation
Devang Patel05e1a972006-11-07 22:03:15 +00001703
Dan Gohmande6188a2010-08-12 23:50:08 +00001704/// Execute all of the passes scheduled for execution by invoking
1705/// runOnModule method. Keep track of whether any of the passes modifies
Devang Patel05e1a972006-11-07 22:03:15 +00001706/// the module, and if so, return true.
1707bool
Devang Patel67d6a5e2006-12-19 19:46:59 +00001708MPPassManager::runOnModule(Module &M) {
Devang Patel05e1a972006-11-07 22:03:15 +00001709 bool Changed = false;
Devang Patel050ec722006-11-14 01:23:29 +00001710
Torok Edwin24c78352009-06-29 18:49:09 +00001711 // Initialize on-the-fly passes
Yaron Keren3b1e24b2015-06-05 14:15:07 +00001712 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1713 FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
Torok Edwin24c78352009-06-29 18:49:09 +00001714 Changed |= FPP->doInitialization(M);
1715 }
1716
Pedro Artigasd6b092b2012-11-29 17:47:05 +00001717 // Initialize module passes
1718 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1719 Changed |= getContainedPass(Index)->doInitialization(M);
1720
Jessica Paquette454d1032018-08-31 20:20:55 +00001721 unsigned InstrCount, ModuleCount = 0;
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001722 StringMap<std::pair<unsigned, unsigned>> FunctionToInstrCount;
Xin Tong023e25a2018-07-22 05:27:41 +00001723 bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
Jessica Paquette454d1032018-08-31 20:20:55 +00001724 // Collect the initial size of the module.
1725 if (EmitICRemark) {
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001726 InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount);
Jessica Paquette454d1032018-08-31 20:20:55 +00001727 ModuleCount = InstrCount;
1728 }
1729
Devang Patelabfbe3b2006-12-16 00:56:26 +00001730 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1731 ModulePass *MP = getContainedPass(Index);
Dan Gohman74b189f2010-03-01 17:34:28 +00001732 bool LocalChanged = false;
Devang Patelabfbe3b2006-12-16 00:56:26 +00001733
Benjamin Kramerdfcc2852009-12-08 13:07:38 +00001734 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
Chris Lattner4c493d92008-08-08 15:14:09 +00001735 dumpRequiredSet(MP);
Devang Patel93a197c2006-12-14 00:08:04 +00001736
Devang Patelabfbe3b2006-12-16 00:56:26 +00001737 initializeAnalysisImpl(MP);
Devang Patelb8817b92006-12-14 00:59:42 +00001738
Chris Lattner4c1e9542009-03-06 06:45:05 +00001739 {
1740 PassManagerPrettyStackEntry X(MP, M);
Chris Lattner707431c2010-03-30 04:03:22 +00001741 TimeRegion PassTimer(getPassTimer(MP));
1742
Dan Gohman74b189f2010-03-01 17:34:28 +00001743 LocalChanged |= MP->runOnModule(M);
Jessica Paquette454d1032018-08-31 20:20:55 +00001744 if (EmitICRemark) {
1745 // Update the size of the module.
Jessica Paquette454d1032018-08-31 20:20:55 +00001746 ModuleCount = M.getInstructionCount();
1747 if (ModuleCount != InstrCount) {
Jessica Paquette9a23c552018-08-31 20:20:57 +00001748 int64_t Delta = static_cast<int64_t>(ModuleCount) -
1749 static_cast<int64_t>(InstrCount);
Jessica Paquettea0aa5b32018-09-06 21:19:54 +00001750 emitInstrCountChangedRemark(MP, M, Delta, InstrCount,
1751 FunctionToInstrCount);
Jessica Paquettea69696d2018-08-31 22:43:41 +00001752 InstrCount = ModuleCount;
Jessica Paquette454d1032018-08-31 20:20:55 +00001753 }
1754 }
Chris Lattner4c1e9542009-03-06 06:45:05 +00001755 }
Devang Patel93a197c2006-12-14 00:08:04 +00001756
Dan Gohman74b189f2010-03-01 17:34:28 +00001757 Changed |= LocalChanged;
1758 if (LocalChanged)
Dan Gohman929391a2008-01-29 12:09:55 +00001759 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
Benjamin Kramerdfcc2852009-12-08 13:07:38 +00001760 M.getModuleIdentifier());
Chris Lattner4c493d92008-08-08 15:14:09 +00001761 dumpPreservedSet(MP);
Chandler Carruth44a13852015-08-19 03:02:12 +00001762 dumpUsedSet(MP);
Dan Gohmande6188a2010-08-12 23:50:08 +00001763
Devang Patela273d1c2007-07-19 18:02:32 +00001764 verifyPreservedAnalysis(MP);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001765 removeNotPreservedAnalysis(MP);
1766 recordAvailableAnalysis(MP);
Benjamin Kramerdfcc2852009-12-08 13:07:38 +00001767 removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
Devang Patel05e1a972006-11-07 22:03:15 +00001768 }
Torok Edwin24c78352009-06-29 18:49:09 +00001769
Pedro Artigasd6b092b2012-11-29 17:47:05 +00001770 // Finalize module passes
Pedro Artigas41b98842012-12-05 17:12:22 +00001771 for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
Pedro Artigasd6b092b2012-11-29 17:47:05 +00001772 Changed |= getContainedPass(Index)->doFinalization(M);
1773
Torok Edwin24c78352009-06-29 18:49:09 +00001774 // Finalize on-the-fly passes
Yaron Keren3b1e24b2015-06-05 14:15:07 +00001775 for (auto &OnTheFlyManager : OnTheFlyManagers) {
1776 FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
Torok Edwin24c78352009-06-29 18:49:09 +00001777 // We don't know when is the last time an on-the-fly pass is run,
1778 // so we need to releaseMemory / finalize here
1779 FPP->releaseMemoryOnTheFly();
1780 Changed |= FPP->doFinalization(M);
1781 }
Andrew Trickdc073ad2013-09-18 23:31:10 +00001782
Devang Patel05e1a972006-11-07 22:03:15 +00001783 return Changed;
1784}
1785
Devang Patele64d3052007-04-16 20:12:57 +00001786/// Add RequiredPass into list of lower level passes required by pass P.
1787/// RequiredPass is run on the fly by Pass Manager when P requests it
1788/// through getAnalysis interface.
1789void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
Chris Lattner60987362009-03-06 05:53:14 +00001790 assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
1791 "Unable to handle Pass that requires lower level Analysis pass");
Dan Gohmande6188a2010-08-12 23:50:08 +00001792 assert((P->getPotentialPassManagerType() <
Chris Lattner60987362009-03-06 05:53:14 +00001793 RequiredPass->getPotentialPassManagerType()) &&
1794 "Unable to handle Pass that requires lower level Analysis pass");
Andrew Trick02066f22014-04-08 03:40:34 +00001795 if (!RequiredPass)
1796 return;
Devang Patele64d3052007-04-16 20:12:57 +00001797
Devang Patel68f72b12007-04-26 17:50:19 +00001798 FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
Devang Patel69e9f6d2007-04-16 20:27:05 +00001799 if (!FPP) {
Andrew Trick08966212011-08-29 17:07:00 +00001800 FPP = new FunctionPassManagerImpl();
Devang Patel68f72b12007-04-26 17:50:19 +00001801 // FPP is the top level manager.
1802 FPP->setTopLevelManager(FPP);
1803
Devang Patel69e9f6d2007-04-16 20:27:05 +00001804 OnTheFlyManagers[P] = FPP;
1805 }
Chandler Carruth5b0d3e32015-01-28 09:47:21 +00001806 const PassInfo *RequiredPassPI =
1807 TPM->findAnalysisPassInfo(RequiredPass->getPassID());
Devang Patel69e9f6d2007-04-16 20:27:05 +00001808
Craig Topperc6207612014-04-09 06:08:46 +00001809 Pass *FoundPass = nullptr;
Andrew Trick02066f22014-04-08 03:40:34 +00001810 if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
1811 FoundPass =
1812 ((PMTopLevelManager*)FPP)->findAnalysisPass(RequiredPass->getPassID());
Devang Patel6eb3a6b2011-09-13 21:13:29 +00001813 }
Andrew Trick02066f22014-04-08 03:40:34 +00001814 if (!FoundPass) {
1815 FoundPass = RequiredPass;
1816 // This should be guaranteed to add RequiredPass to the passmanager given
Sylvestre Ledru469de192014-08-11 18:04:46 +00001817 // that we checked for an available analysis above.
Andrew Trick02066f22014-04-08 03:40:34 +00001818 FPP->add(RequiredPass);
1819 }
1820 // Register P as the last user of FoundPass or RequiredPass.
1821 SmallVector<Pass *, 1> LU;
1822 LU.push_back(FoundPass);
1823 FPP->setLastUser(LU, P);
Devang Patele64d3052007-04-16 20:12:57 +00001824}
Devang Patel69e9f6d2007-04-16 20:27:05 +00001825
Dan Gohmande6188a2010-08-12 23:50:08 +00001826/// Return function pass corresponding to PassInfo PI, that is
Devang Patel69e9f6d2007-04-16 20:27:05 +00001827/// required by module pass MP. Instantiate analysis pass, by using
1828/// its runOnFunction() for function F.
Owen Andersona7aed182010-08-06 18:33:48 +00001829Pass* MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F){
Devang Patel68f72b12007-04-26 17:50:19 +00001830 FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
Chris Lattner60987362009-03-06 05:53:14 +00001831 assert(FPP && "Unable to find on the fly pass");
Dan Gohmande6188a2010-08-12 23:50:08 +00001832
Torok Edwin24c78352009-06-29 18:49:09 +00001833 FPP->releaseMemoryOnTheFly();
Devang Patel68f72b12007-04-26 17:50:19 +00001834 FPP->run(F);
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001835 return ((PMTopLevelManager*)FPP)->findAnalysisPass(PI);
Devang Patel69e9f6d2007-04-16 20:27:05 +00001836}
1837
1838
Devang Patela1514cb2006-12-07 19:39:39 +00001839//===----------------------------------------------------------------------===//
1840// PassManagerImpl implementation
Owen Anderson1aa27512012-11-15 00:14:15 +00001841
Devang Patelab97cf42006-12-13 00:09:23 +00001842//
Devang Patelc290c8a2006-11-07 22:23:34 +00001843/// run - Execute all of the passes scheduled for execution. Keep track of
1844/// whether any of the passes modifies the module, and if so, return true.
Devang Patel67d6a5e2006-12-19 19:46:59 +00001845bool PassManagerImpl::run(Module &M) {
Devang Patelc290c8a2006-11-07 22:23:34 +00001846 bool Changed = false;
Devang Patelb8817b92006-12-14 00:59:42 +00001847
Devang Patelcfd70c42006-12-13 22:10:00 +00001848 dumpArguments();
Devang Patel67d6a5e2006-12-19 19:46:59 +00001849 dumpPasses();
Devang Patelf1567a52006-12-13 20:03:48 +00001850
Yaron Keren3b1e24b2015-06-05 14:15:07 +00001851 for (ImmutablePass *ImPass : getImmutablePasses())
1852 Changed |= ImPass->doInitialization(M);
Pedro Artigas41b98842012-12-05 17:12:22 +00001853
Devang Patele3068402006-12-21 00:16:50 +00001854 initializeAllAnalysisInfo();
Juergen Ributzka34390c72014-05-16 02:33:15 +00001855 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
Serge Pavloved5eb932017-01-15 10:23:18 +00001856 Changed |= getContainedManager(Index)->runOnModule(M);
Juergen Ributzka34390c72014-05-16 02:33:15 +00001857 M.getContext().yield();
1858 }
Pedro Artigas41b98842012-12-05 17:12:22 +00001859
Yaron Keren3b1e24b2015-06-05 14:15:07 +00001860 for (ImmutablePass *ImPass : getImmutablePasses())
1861 Changed |= ImPass->doFinalization(M);
Pedro Artigas41b98842012-12-05 17:12:22 +00001862
Devang Patelc290c8a2006-11-07 22:23:34 +00001863 return Changed;
1864}
Devang Patel376fefa2006-11-08 10:29:57 +00001865
Devang Patela1514cb2006-12-07 19:39:39 +00001866//===----------------------------------------------------------------------===//
1867// PassManager implementation
1868
Devang Patel376fefa2006-11-08 10:29:57 +00001869/// Create new pass manager
Devang Patelb67904d2006-12-13 02:36:01 +00001870PassManager::PassManager() {
Andrew Trick08966212011-08-29 17:07:00 +00001871 PM = new PassManagerImpl();
Devang Patel9c6290c2006-12-12 22:02:16 +00001872 // PM is the top level manager
1873 PM->setTopLevelManager(PM);
Devang Patel376fefa2006-11-08 10:29:57 +00001874}
1875
Devang Patelb67904d2006-12-13 02:36:01 +00001876PassManager::~PassManager() {
Devang Patelab97cf42006-12-13 00:09:23 +00001877 delete PM;
1878}
1879
Chris Lattner60987362009-03-06 05:53:14 +00001880void PassManager::add(Pass *P) {
Andrew Trickcbc845f2012-02-01 07:16:20 +00001881 PM->add(P);
Devang Patel376fefa2006-11-08 10:29:57 +00001882}
1883
1884/// run - Execute all of the passes scheduled for execution. Keep track of
1885/// whether any of the passes modifies the module, and if so, return true.
Chris Lattner60987362009-03-06 05:53:14 +00001886bool PassManager::run(Module &M) {
Devang Patel376fefa2006-11-08 10:29:57 +00001887 return PM->run(M);
1888}
1889
Devang Patelb8817b92006-12-14 00:59:42 +00001890//===----------------------------------------------------------------------===//
Devang Patel1c56a632007-01-08 19:29:38 +00001891// PMStack implementation
1892//
Devang Patelad98d232007-01-11 22:15:30 +00001893
Devang Patel1c56a632007-01-08 19:29:38 +00001894// Pop Pass Manager from the stack and clear its analysis info.
1895void PMStack::pop() {
1896
1897 PMDataManager *Top = this->top();
1898 Top->initializeAnalysisInfo();
1899
1900 S.pop_back();
1901}
1902
1903// Push PM on the stack and set its top level manager.
Dan Gohman11eecd62008-03-13 01:21:31 +00001904void PMStack::push(PMDataManager *PM) {
Chris Lattner60987362009-03-06 05:53:14 +00001905 assert(PM && "Unable to push. Pass Manager expected");
Andrew Trick08966212011-08-29 17:07:00 +00001906 assert(PM->getDepth()==0 && "Pass Manager depth set too early");
Devang Patel1c56a632007-01-08 19:29:38 +00001907
Chris Lattner60987362009-03-06 05:53:14 +00001908 if (!this->empty()) {
Andrew Trick08966212011-08-29 17:07:00 +00001909 assert(PM->getPassManagerType() > this->top()->getPassManagerType()
1910 && "pushing bad pass manager to PMStack");
Chris Lattner60987362009-03-06 05:53:14 +00001911 PMTopLevelManager *TPM = this->top()->getTopLevelManager();
Devang Patel1c56a632007-01-08 19:29:38 +00001912
Chris Lattner60987362009-03-06 05:53:14 +00001913 assert(TPM && "Unable to find top level manager");
Devang Patel15701b52007-01-11 00:19:00 +00001914 TPM->addIndirectPassManager(PM);
1915 PM->setTopLevelManager(TPM);
Andrew Trick08966212011-08-29 17:07:00 +00001916 PM->setDepth(this->top()->getDepth()+1);
Craig Topper821d6af2013-02-06 06:50:38 +00001917 } else {
Benjamin Kramer6bb5b3c2011-08-29 18:14:15 +00001918 assert((PM->getPassManagerType() == PMT_ModulePassManager
1919 || PM->getPassManagerType() == PMT_FunctionPassManager)
Andrew Trick08966212011-08-29 17:07:00 +00001920 && "pushing bad pass manager to PMStack");
1921 PM->setDepth(1);
Devang Patel15701b52007-01-11 00:19:00 +00001922 }
1923
Devang Patel15701b52007-01-11 00:19:00 +00001924 S.push_back(PM);
1925}
1926
1927// Dump content of the pass manager stack.
Yaron Kereneb2a2542016-01-29 20:50:44 +00001928LLVM_DUMP_METHOD void PMStack::dump() const {
Yaron Keren4849aa32015-06-05 17:48:47 +00001929 for (PMDataManager *Manager : S)
1930 dbgs() << Manager->getAsPass()->getPassName() << ' ';
Chris Lattner60987362009-03-06 05:53:14 +00001931
Devang Patel15701b52007-01-11 00:19:00 +00001932 if (!S.empty())
Benjamin Kramer4dd515c2011-08-29 18:14:17 +00001933 dbgs() << '\n';
Devang Patel1c56a632007-01-08 19:29:38 +00001934}
1935
Devang Patel1c56a632007-01-08 19:29:38 +00001936/// Find appropriate Module Pass Manager in the PM Stack and
Dan Gohmande6188a2010-08-12 23:50:08 +00001937/// add self into that manager.
1938void ModulePass::assignPassManager(PMStack &PMS,
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001939 PassManagerType PreferredType) {
Devang Patel1c56a632007-01-08 19:29:38 +00001940 // Find Module Pass Manager
Dan Gohmande6188a2010-08-12 23:50:08 +00001941 while (!PMS.empty()) {
Devang Patel23f8aa92007-01-17 21:19:23 +00001942 PassManagerType TopPMType = PMS.top()->getPassManagerType();
1943 if (TopPMType == PreferredType)
1944 break; // We found desired pass manager
1945 else if (TopPMType > PMT_ModulePassManager)
Devang Patel1c56a632007-01-08 19:29:38 +00001946 PMS.pop(); // Pop children pass managers
Devang Patelac99eca2007-01-11 19:59:06 +00001947 else
1948 break;
Devang Patel1c56a632007-01-08 19:29:38 +00001949 }
Devang Patel18ff6362008-09-09 21:38:40 +00001950 assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
Devang Patel23f8aa92007-01-17 21:19:23 +00001951 PMS.top()->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001952}
1953
Devang Patel3312f752007-01-16 21:43:18 +00001954/// Find appropriate Function Pass Manager or Call Graph Pass Manager
Dan Gohmande6188a2010-08-12 23:50:08 +00001955/// in the PM Stack and add self into that manager.
Devang Pateldffca632007-01-17 20:30:17 +00001956void FunctionPass::assignPassManager(PMStack &PMS,
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001957 PassManagerType PreferredType) {
Devang Patel1c56a632007-01-08 19:29:38 +00001958
Andrew Trickcbc845f2012-02-01 07:16:20 +00001959 // Find Function Pass Manager
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001960 while (!PMS.empty()) {
Devang Patelac99eca2007-01-11 19:59:06 +00001961 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1962 PMS.pop();
Devang Patel1c56a632007-01-08 19:29:38 +00001963 else
Dan Gohmande6188a2010-08-12 23:50:08 +00001964 break;
Devang Patel3312f752007-01-16 21:43:18 +00001965 }
Devang Patel3312f752007-01-16 21:43:18 +00001966
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001967 // Create new Function Pass Manager if needed.
1968 FPPassManager *FPP;
1969 if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
1970 FPP = (FPPassManager *)PMS.top();
1971 } else {
Devang Patel3312f752007-01-16 21:43:18 +00001972 assert(!PMS.empty() && "Unable to create Function Pass Manager");
1973 PMDataManager *PMD = PMS.top();
1974
1975 // [1] Create new Function Pass Manager
Andrew Trick08966212011-08-29 17:07:00 +00001976 FPP = new FPPassManager();
Devang Patelcbbf2912008-03-20 01:09:53 +00001977 FPP->populateInheritedAnalysis(PMS);
Devang Patel3312f752007-01-16 21:43:18 +00001978
1979 // [2] Set up new manager's top level manager
1980 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1981 TPM->addIndirectPassManager(FPP);
1982
1983 // [3] Assign manager to manage this new manager. This may create
1984 // and push new managers into PMS
Devang Patela3286902008-09-09 17:56:50 +00001985 FPP->assignPassManager(PMS, PMD->getPassManagerType());
Devang Patel3312f752007-01-16 21:43:18 +00001986
1987 // [4] Push new manager into PMS
1988 PMS.push(FPP);
Devang Patel1c56a632007-01-08 19:29:38 +00001989 }
1990
Devang Patel3312f752007-01-16 21:43:18 +00001991 // Assign FPP as the manager of this pass.
1992 FPP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001993}
1994
Devang Patel3312f752007-01-16 21:43:18 +00001995/// Find appropriate Basic Pass Manager or Call Graph Pass Manager
Dan Gohmande6188a2010-08-12 23:50:08 +00001996/// in the PM Stack and add self into that manager.
Devang Pateldffca632007-01-17 20:30:17 +00001997void BasicBlockPass::assignPassManager(PMStack &PMS,
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001998 PassManagerType PreferredType) {
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001999 BBPassManager *BBP;
Devang Patel1c56a632007-01-08 19:29:38 +00002000
Devang Patel15701b52007-01-11 00:19:00 +00002001 // Basic Pass Manager is a leaf pass manager. It does not handle
2002 // any other pass manager.
Dan Gohmande6188a2010-08-12 23:50:08 +00002003 if (!PMS.empty() &&
Chris Lattner9efd4fc2010-01-22 05:37:10 +00002004 PMS.top()->getPassManagerType() == PMT_BasicBlockPassManager) {
2005 BBP = (BBPassManager *)PMS.top();
2006 } else {
2007 // If leaf manager is not Basic Block Pass manager then create new
2008 // basic Block Pass manager.
Devang Patel3312f752007-01-16 21:43:18 +00002009 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
2010 PMDataManager *PMD = PMS.top();
2011
2012 // [1] Create new Basic Block Manager
Andrew Trick08966212011-08-29 17:07:00 +00002013 BBP = new BBPassManager();
Devang Patel3312f752007-01-16 21:43:18 +00002014
2015 // [2] Set up new manager's top level manager
2016 // Basic Block Pass Manager does not live by itself
2017 PMTopLevelManager *TPM = PMD->getTopLevelManager();
2018 TPM->addIndirectPassManager(BBP);
2019
Devang Patel15701b52007-01-11 00:19:00 +00002020 // [3] Assign manager to manage this new manager. This may create
2021 // and push new managers into PMS
David Greene103d4b42010-05-10 20:24:27 +00002022 BBP->assignPassManager(PMS, PreferredType);
Devang Patel15701b52007-01-11 00:19:00 +00002023
Devang Patel3312f752007-01-16 21:43:18 +00002024 // [4] Push new manager into PMS
2025 PMS.push(BBP);
2026 }
Devang Patel1c56a632007-01-08 19:29:38 +00002027
Devang Patel3312f752007-01-16 21:43:18 +00002028 // Assign BBP as the manager of this pass.
2029 BBP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00002030}
2031
Dan Gohmand3a20c92008-03-11 16:41:42 +00002032PassManagerBase::~PassManagerBase() {}