2013-11-09 20:26:54 +08:00
|
|
|
//===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
|
2006-11-08 05:31:57 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-11-08 05:31:57 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2013-11-09 20:26:54 +08:00
|
|
|
// This file implements the legacy LLVM Pass Manager infrastructure.
|
2006-11-08 05:31:57 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
2014-01-12 19:10:32 +08:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2013-11-09 20:26:54 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
|
|
#include "llvm/IR/LegacyPassManagers.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2006-12-14 04:03:48 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2010-01-05 09:30:02 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 02:01:40 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2006-12-14 08:59:42 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/Mutex.h"
|
2010-04-03 07:17:14 +08:00
|
|
|
#include "llvm/Support/PassNameParser.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/Timer.h"
|
2009-03-06 14:45:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-03-05 08:00:42 +08:00
|
|
|
#include <algorithm>
|
2006-11-14 09:59:59 +08:00
|
|
|
#include <map>
|
2007-10-04 03:04:09 +08:00
|
|
|
using namespace llvm;
|
2013-11-09 20:26:54 +08:00
|
|
|
using namespace llvm::legacy;
|
2006-12-16 03:39:30 +08:00
|
|
|
|
2007-01-13 02:52:44 +08:00
|
|
|
// See PassManagers.h for Pass Manager infrastructure overview.
|
2006-12-08 02:23:30 +08:00
|
|
|
|
2006-12-14 04:03:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pass debugging information. Often it is useful to find out what pass is
|
|
|
|
// running when a crash occurs in a utility. When this library is compiled with
|
|
|
|
// debugging on, a command line option (--debug-pass) is enabled that causes the
|
|
|
|
// pass name to be printed before it executes.
|
|
|
|
//
|
|
|
|
|
2013-11-09 20:26:54 +08:00
|
|
|
namespace {
|
2006-12-14 05:13:31 +08:00
|
|
|
// Different debug levels that can be enabled...
|
|
|
|
enum PassDebugLevel {
|
2013-05-05 08:40:33 +08:00
|
|
|
Disabled, Arguments, Structure, Executions, Details
|
2006-12-14 05:13:31 +08:00
|
|
|
};
|
2013-11-09 20:26:54 +08:00
|
|
|
}
|
2006-12-14 05:13:31 +08:00
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
static cl::opt<enum PassDebugLevel>
|
|
|
|
PassDebugging("debug-pass", cl::Hidden,
|
2006-12-14 04:03:48 +08:00
|
|
|
cl::desc("Print PassManager debugging information"),
|
|
|
|
cl::values(
|
2013-09-19 14:02:43 +08:00
|
|
|
clEnumVal(Disabled , "disable debug output"),
|
|
|
|
clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
|
|
|
|
clEnumVal(Structure , "print pass structure before run()"),
|
|
|
|
clEnumVal(Executions, "print pass name before it is executed"),
|
|
|
|
clEnumVal(Details , "print pass details when it is executed"),
|
|
|
|
clEnumValEnd));
|
|
|
|
|
2013-11-09 20:26:54 +08:00
|
|
|
namespace {
|
2013-09-19 14:02:43 +08:00
|
|
|
typedef llvm::cl::list<const llvm::PassInfo *, bool, PassNameParser>
|
|
|
|
PassOptionList;
|
2013-11-09 20:26:54 +08:00
|
|
|
}
|
2013-09-19 14:02:43 +08:00
|
|
|
|
|
|
|
// Print IR out before/after specified passes.
|
|
|
|
static PassOptionList
|
|
|
|
PrintBefore("print-before",
|
|
|
|
llvm::cl::desc("Print IR before specified passes"),
|
|
|
|
cl::Hidden);
|
|
|
|
|
|
|
|
static PassOptionList
|
|
|
|
PrintAfter("print-after",
|
|
|
|
llvm::cl::desc("Print IR after specified passes"),
|
|
|
|
cl::Hidden);
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
PrintBeforeAll("print-before-all",
|
|
|
|
llvm::cl::desc("Print IR before each pass"),
|
|
|
|
cl::init(false));
|
|
|
|
static cl::opt<bool>
|
|
|
|
PrintAfterAll("print-after-all",
|
|
|
|
llvm::cl::desc("Print IR after each pass"),
|
|
|
|
cl::init(false));
|
|
|
|
|
|
|
|
/// This is a helper to determine whether to print IR before or
|
|
|
|
/// after a pass.
|
|
|
|
|
|
|
|
static bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
|
|
|
|
PassOptionList &PassesToPrint) {
|
|
|
|
for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) {
|
|
|
|
const llvm::PassInfo *PassInf = PassesToPrint[i];
|
|
|
|
if (PassInf)
|
|
|
|
if (PassInf->getPassArgument() == PI->getPassArgument()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-19 07:31:16 +08:00
|
|
|
}
|
2013-09-19 14:02:43 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-04-03 07:17:14 +08:00
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
/// This is a utility to check whether a pass should have IR dumped
|
|
|
|
/// before it.
|
|
|
|
static bool ShouldPrintBeforePass(const PassInfo *PI) {
|
|
|
|
return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore);
|
|
|
|
}
|
2013-09-19 07:31:16 +08:00
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
/// This is a utility to check whether a pass should have IR dumped
|
|
|
|
/// after it.
|
|
|
|
static bool ShouldPrintAfterPass(const PassInfo *PI) {
|
|
|
|
return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter);
|
2010-04-03 07:17:14 +08:00
|
|
|
}
|
|
|
|
|
2009-09-15 13:03:04 +08:00
|
|
|
/// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
|
|
|
|
/// or higher is specified.
|
|
|
|
bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
|
2013-09-19 14:02:43 +08:00
|
|
|
return PassDebugging >= Executions;
|
2009-09-15 13:03:04 +08:00
|
|
|
}
|
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
|
|
|
|
if (V == 0 && M == 0)
|
|
|
|
OS << "Releasing pass '";
|
|
|
|
else
|
|
|
|
OS << "Running pass '";
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
OS << P->getPassName() << "'";
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
if (M) {
|
|
|
|
OS << " on module '" << M->getModuleIdentifier() << "'.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (V == 0) {
|
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-11 02:47:59 +08:00
|
|
|
OS << " on ";
|
2009-03-06 14:45:05 +08:00
|
|
|
if (isa<Function>(V))
|
2009-03-11 02:47:59 +08:00
|
|
|
OS << "function";
|
2009-03-06 14:45:05 +08:00
|
|
|
else if (isa<BasicBlock>(V))
|
2009-03-11 02:47:59 +08:00
|
|
|
OS << "basic block";
|
2009-03-06 14:45:05 +08:00
|
|
|
else
|
2009-03-11 02:47:59 +08:00
|
|
|
OS << "value";
|
|
|
|
|
|
|
|
OS << " '";
|
2014-01-09 10:29:41 +08:00
|
|
|
V->printAsOperand(OS, /*PrintTy=*/false, M);
|
2009-03-11 02:47:59 +08:00
|
|
|
OS << "'\n";
|
2009-03-06 14:45:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-16 03:39:30 +08:00
|
|
|
namespace {
|
2006-12-13 06:47:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-20 03:46:59 +08:00
|
|
|
// BBPassManager
|
2006-12-13 06:47:13 +08:00
|
|
|
//
|
2006-12-20 03:46:59 +08:00
|
|
|
/// BBPassManager manages BasicBlockPass. It batches all the
|
2006-11-08 18:05:38 +08:00
|
|
|
/// pass together and sequence them to process one basic block before
|
|
|
|
/// processing next basic block.
|
2009-10-25 14:33:48 +08:00
|
|
|
class BBPassManager : public PMDataManager, public FunctionPass {
|
2006-11-08 18:05:38 +08:00
|
|
|
|
|
|
|
public:
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID;
|
2011-08-30 01:07:00 +08:00
|
|
|
explicit BBPassManager()
|
|
|
|
: PMDataManager(), FunctionPass(ID) {}
|
2006-11-08 18:05:38 +08:00
|
|
|
|
|
|
|
/// Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the function, and if so, return true.
|
|
|
|
bool runOnFunction(Function &F);
|
|
|
|
|
2006-12-08 03:57:52 +08:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const {
|
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2006-12-08 08:59:05 +08:00
|
|
|
bool doInitialization(Module &M);
|
|
|
|
bool doInitialization(Function &F);
|
|
|
|
bool doFinalization(Module &M);
|
|
|
|
bool doFinalization(Function &F);
|
|
|
|
|
2010-01-22 13:24:46 +08:00
|
|
|
virtual PMDataManager *getAsPMDataManager() { return this; }
|
|
|
|
virtual Pass *getAsPass() { return this; }
|
|
|
|
|
2007-02-02 06:08:25 +08:00
|
|
|
virtual const char *getPassName() const {
|
2008-03-13 09:58:48 +08:00
|
|
|
return "BasicBlock Pass Manager";
|
2007-02-02 06:08:25 +08:00
|
|
|
}
|
|
|
|
|
2006-12-13 07:34:33 +08:00
|
|
|
// Print passes managed by this manager
|
|
|
|
void dumpPassStructure(unsigned Offset) {
|
2011-08-30 02:14:17 +08:00
|
|
|
llvm::dbgs().indent(Offset*2) << "BasicBlockPass Manager\n";
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2010-08-19 09:29:07 +08:00
|
|
|
BP->dumpPassStructure(Offset + 1);
|
2006-12-16 08:56:26 +08:00
|
|
|
dumpLastUses(BP, Offset+1);
|
2006-12-13 07:34:33 +08:00
|
|
|
}
|
|
|
|
}
|
2006-12-16 08:56:26 +08:00
|
|
|
|
|
|
|
BasicBlockPass *getContainedPass(unsigned N) {
|
2012-11-13 10:56:38 +08:00
|
|
|
assert(N < PassVector.size() && "Pass number out of range!");
|
2006-12-16 08:56:26 +08:00
|
|
|
BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
|
|
|
|
return BP;
|
|
|
|
}
|
2007-01-11 09:10:25 +08:00
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
virtual PassManagerType getPassManagerType() const {
|
|
|
|
return PMT_BasicBlockPassManager;
|
2007-01-11 09:10:25 +08:00
|
|
|
}
|
2006-11-08 18:05:38 +08:00
|
|
|
};
|
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char BBPassManager::ID = 0;
|
2013-11-09 20:26:54 +08:00
|
|
|
} // End anonymous namespace
|
2006-12-16 08:56:26 +08:00
|
|
|
|
2007-01-13 02:52:44 +08:00
|
|
|
namespace llvm {
|
2013-11-09 20:26:54 +08:00
|
|
|
namespace legacy {
|
2006-12-20 03:46:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FunctionPassManagerImpl
|
|
|
|
//
|
|
|
|
/// FunctionPassManagerImpl manages FPPassManagers
|
|
|
|
class FunctionPassManagerImpl : public Pass,
|
2007-01-12 06:15:30 +08:00
|
|
|
public PMDataManager,
|
|
|
|
public PMTopLevelManager {
|
2011-12-20 10:50:00 +08:00
|
|
|
virtual void anchor();
|
2009-06-30 02:49:09 +08:00
|
|
|
private:
|
|
|
|
bool wasRun;
|
2006-12-20 03:46:59 +08:00
|
|
|
public:
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID;
|
2011-08-30 01:07:00 +08:00
|
|
|
explicit FunctionPassManagerImpl() :
|
|
|
|
Pass(PT_PassManager, ID), PMDataManager(),
|
|
|
|
PMTopLevelManager(new FPPassManager()), wasRun(false) {}
|
2006-12-20 03:46:59 +08:00
|
|
|
|
|
|
|
/// add - Add a pass to the queue of passes to run. This passes ownership of
|
|
|
|
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
|
|
|
|
/// will be destroyed as well, so there is no need to delete the pass. This
|
|
|
|
/// implies that all passes MUST be allocated with 'new'.
|
|
|
|
void add(Pass *P) {
|
|
|
|
schedulePass(P);
|
|
|
|
}
|
2010-08-13 07:50:08 +08:00
|
|
|
|
|
|
|
/// createPrinterPass - Get a function printer pass.
|
2010-04-03 07:17:14 +08:00
|
|
|
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
|
2014-01-12 19:30:46 +08:00
|
|
|
return createPrintFunctionPass(O, Banner);
|
2010-04-03 07:17:14 +08:00
|
|
|
}
|
|
|
|
|
2009-06-30 02:49:09 +08:00
|
|
|
// Prepare for running an on the fly pass, freeing memory if needed
|
|
|
|
// from a previous run.
|
|
|
|
void releaseMemoryOnTheFly();
|
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
|
|
|
bool run(Function &F);
|
|
|
|
|
|
|
|
/// doInitialization - Run all of the initializers for the function passes.
|
|
|
|
///
|
|
|
|
bool doInitialization(Module &M);
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2007-07-30 22:51:13 +08:00
|
|
|
/// doFinalization - Run all of the finalizers for the function passes.
|
2006-12-20 03:46:59 +08:00
|
|
|
///
|
|
|
|
bool doFinalization(Module &M);
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2010-01-22 13:24:46 +08:00
|
|
|
virtual PMDataManager *getAsPMDataManager() { return this; }
|
|
|
|
virtual Pass *getAsPass() { return this; }
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
virtual PassManagerType getTopLevelPassManagerType() {
|
|
|
|
return PMT_FunctionPassManager;
|
|
|
|
}
|
2010-01-22 13:24:46 +08:00
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const {
|
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
FPPassManager *getContainedManager(unsigned N) {
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(N < PassManagers.size() && "Pass number out of range!");
|
2006-12-20 03:46:59 +08:00
|
|
|
FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
|
|
|
|
return FP;
|
|
|
|
}
|
2006-11-08 18:05:38 +08:00
|
|
|
};
|
|
|
|
|
2011-12-20 10:50:00 +08:00
|
|
|
void FunctionPassManagerImpl::anchor() {}
|
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char FunctionPassManagerImpl::ID = 0;
|
2013-11-09 20:26:54 +08:00
|
|
|
} // End of legacy namespace
|
|
|
|
} // End of llvm namespace
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2013-11-09 20:26:54 +08:00
|
|
|
namespace {
|
2006-12-13 06:47:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-20 03:46:59 +08:00
|
|
|
// MPPassManager
|
2006-12-13 06:47:13 +08:00
|
|
|
//
|
2006-12-20 03:46:59 +08:00
|
|
|
/// MPPassManager manages ModulePasses and function pass managers.
|
2008-03-12 00:18:48 +08:00
|
|
|
/// It batches all Module passes and function pass managers together and
|
|
|
|
/// sequences them to process one module.
|
2006-12-20 03:46:59 +08:00
|
|
|
class MPPassManager : public Pass, public PMDataManager {
|
2006-11-08 18:05:38 +08:00
|
|
|
public:
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID;
|
2011-08-30 01:07:00 +08:00
|
|
|
explicit MPPassManager() :
|
|
|
|
Pass(PT_PassManager, ID), PMDataManager() { }
|
2007-04-17 04:39:59 +08:00
|
|
|
|
|
|
|
// Delete on the fly managers.
|
|
|
|
virtual ~MPPassManager() {
|
2010-08-13 07:50:08 +08:00
|
|
|
for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
|
2007-04-17 04:39:59 +08:00
|
|
|
I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
|
|
|
|
I != E; ++I) {
|
2007-04-27 01:50:19 +08:00
|
|
|
FunctionPassManagerImpl *FPP = I->second;
|
2007-04-17 04:39:59 +08:00
|
|
|
delete FPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// createPrinterPass - Get a module printer pass.
|
2010-04-03 07:17:14 +08:00
|
|
|
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
|
2014-01-12 19:30:46 +08:00
|
|
|
return createPrintModulePass(O, Banner);
|
2010-04-03 07:17:14 +08:00
|
|
|
}
|
|
|
|
|
2006-11-08 18:05:38 +08:00
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
|
|
|
bool runOnModule(Module &M);
|
2006-11-14 06:40:09 +08:00
|
|
|
|
2012-12-04 05:56:57 +08:00
|
|
|
using llvm::Pass::doInitialization;
|
|
|
|
using llvm::Pass::doFinalization;
|
|
|
|
|
2012-11-15 08:14:15 +08:00
|
|
|
/// doInitialization - Run all of the initializers for the module passes.
|
|
|
|
///
|
2012-11-16 00:51:49 +08:00
|
|
|
bool doInitialization();
|
2012-11-15 08:14:15 +08:00
|
|
|
|
|
|
|
/// doFinalization - Run all of the finalizers for the module passes.
|
|
|
|
///
|
2012-11-16 00:51:49 +08:00
|
|
|
bool doFinalization();
|
2012-11-15 08:14:15 +08:00
|
|
|
|
2006-12-08 03:57:52 +08:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const {
|
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2007-04-17 04:12:57 +08:00
|
|
|
/// Add RequiredPass into list of lower level passes required by pass P.
|
|
|
|
/// RequiredPass is run on the fly by Pass Manager when P requests it
|
|
|
|
/// through getAnalysis interface.
|
|
|
|
virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// Return function pass corresponding to PassInfo PI, that is
|
2007-04-17 04:27:05 +08:00
|
|
|
/// required by module pass MP. Instantiate analysis pass, by using
|
|
|
|
/// its runOnFunction() for function F.
|
2010-08-07 02:33:48 +08:00
|
|
|
virtual Pass* getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F);
|
2007-04-17 04:27:05 +08:00
|
|
|
|
2007-02-02 06:08:25 +08:00
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Module Pass Manager";
|
|
|
|
}
|
|
|
|
|
2010-01-22 13:24:46 +08:00
|
|
|
virtual PMDataManager *getAsPMDataManager() { return this; }
|
|
|
|
virtual Pass *getAsPass() { return this; }
|
|
|
|
|
2006-12-13 07:34:33 +08:00
|
|
|
// Print passes managed by this manager
|
|
|
|
void dumpPassStructure(unsigned Offset) {
|
2011-08-30 02:14:17 +08:00
|
|
|
llvm::dbgs().indent(Offset*2) << "ModulePass Manager\n";
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
ModulePass *MP = getContainedPass(Index);
|
2010-08-19 09:29:07 +08:00
|
|
|
MP->dumpPassStructure(Offset + 1);
|
2009-07-02 07:12:33 +08:00
|
|
|
std::map<Pass *, FunctionPassManagerImpl *>::const_iterator I =
|
|
|
|
OnTheFlyManagers.find(MP);
|
|
|
|
if (I != OnTheFlyManagers.end())
|
|
|
|
I->second->dumpPassStructure(Offset + 2);
|
2006-12-16 08:56:26 +08:00
|
|
|
dumpLastUses(MP, Offset+1);
|
2006-12-13 07:34:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
ModulePass *getContainedPass(unsigned N) {
|
2012-11-13 10:56:38 +08:00
|
|
|
assert(N < PassVector.size() && "Pass number out of range!");
|
2009-03-06 13:53:14 +08:00
|
|
|
return static_cast<ModulePass *>(PassVector[N]);
|
2006-12-16 08:56:26 +08:00
|
|
|
}
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
virtual PassManagerType getPassManagerType() const {
|
|
|
|
return PMT_ModulePassManager;
|
2007-02-27 23:00:39 +08:00
|
|
|
}
|
2007-04-17 04:27:05 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Collection of on the fly FPPassManagers. These managers manage
|
|
|
|
/// function passes that are required by module passes.
|
2007-04-27 01:50:19 +08:00
|
|
|
std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
|
2006-11-08 18:05:38 +08:00
|
|
|
};
|
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char MPPassManager::ID = 0;
|
2013-11-09 20:26:54 +08:00
|
|
|
} // End anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace legacy {
|
2006-12-13 06:47:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-20 03:46:59 +08:00
|
|
|
// PassManagerImpl
|
2006-12-13 06:47:13 +08:00
|
|
|
//
|
2007-05-02 05:15:47 +08:00
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
/// PassManagerImpl manages MPPassManagers
|
|
|
|
class PassManagerImpl : public Pass,
|
2007-01-12 06:15:30 +08:00
|
|
|
public PMDataManager,
|
|
|
|
public PMTopLevelManager {
|
2011-12-20 10:50:00 +08:00
|
|
|
virtual void anchor();
|
2006-11-08 18:29:57 +08:00
|
|
|
|
|
|
|
public:
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID;
|
2011-08-30 01:07:00 +08:00
|
|
|
explicit PassManagerImpl() :
|
|
|
|
Pass(PT_PassManager, ID), PMDataManager(),
|
|
|
|
PMTopLevelManager(new MPPassManager()) {}
|
2006-12-08 07:24:58 +08:00
|
|
|
|
2006-11-08 18:29:57 +08:00
|
|
|
/// add - Add a pass to the queue of passes to run. This passes ownership of
|
|
|
|
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
|
|
|
|
/// will be destroyed as well, so there is no need to delete the pass. This
|
|
|
|
/// implies that all passes MUST be allocated with 'new'.
|
2006-12-08 05:32:57 +08:00
|
|
|
void add(Pass *P) {
|
2006-12-09 06:34:02 +08:00
|
|
|
schedulePass(P);
|
2006-12-08 05:32:57 +08:00
|
|
|
}
|
2010-08-13 07:50:08 +08:00
|
|
|
|
|
|
|
/// createPrinterPass - Get a module printer pass.
|
2010-04-03 07:17:14 +08:00
|
|
|
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
|
2014-01-12 19:30:46 +08:00
|
|
|
return createPrintModulePass(O, Banner);
|
2010-04-03 07:17:14 +08:00
|
|
|
}
|
|
|
|
|
2006-11-08 18:29:57 +08:00
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
|
|
|
bool run(Module &M);
|
|
|
|
|
2012-12-04 05:56:57 +08:00
|
|
|
using llvm::Pass::doInitialization;
|
|
|
|
using llvm::Pass::doFinalization;
|
|
|
|
|
2012-11-15 08:14:15 +08:00
|
|
|
/// doInitialization - Run all of the initializers for the module passes.
|
|
|
|
///
|
2012-11-16 00:51:49 +08:00
|
|
|
bool doInitialization();
|
2012-11-15 08:14:15 +08:00
|
|
|
|
|
|
|
/// doFinalization - Run all of the finalizers for the module passes.
|
|
|
|
///
|
2012-11-16 00:51:49 +08:00
|
|
|
bool doFinalization();
|
2012-11-15 08:14:15 +08:00
|
|
|
|
2006-12-08 03:57:52 +08:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const {
|
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2010-01-22 13:24:46 +08:00
|
|
|
virtual PMDataManager *getAsPMDataManager() { return this; }
|
|
|
|
virtual Pass *getAsPass() { return this; }
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
virtual PassManagerType getTopLevelPassManagerType() {
|
|
|
|
return PMT_ModulePassManager;
|
|
|
|
}
|
2010-01-22 13:24:46 +08:00
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
MPPassManager *getContainedManager(unsigned N) {
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(N < PassManagers.size() && "Pass number out of range!");
|
2006-12-20 03:46:59 +08:00
|
|
|
MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
|
|
|
|
return MP;
|
|
|
|
}
|
2006-11-08 18:29:57 +08:00
|
|
|
};
|
|
|
|
|
2011-12-20 10:50:00 +08:00
|
|
|
void PassManagerImpl::anchor() {}
|
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char PassManagerImpl::ID = 0;
|
2013-11-09 20:26:54 +08:00
|
|
|
} // End of legacy namespace
|
2007-01-30 07:10:37 +08:00
|
|
|
} // End of llvm namespace
|
2006-12-14 08:59:42 +08:00
|
|
|
|
2007-01-30 07:10:37 +08:00
|
|
|
namespace {
|
2007-01-30 04:06:26 +08:00
|
|
|
|
2007-01-30 07:10:37 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-03-06 14:45:05 +08:00
|
|
|
/// TimingInfo Class - This class is used to calculate information about the
|
|
|
|
/// amount of time each pass takes to execute. This only happens when
|
|
|
|
/// -time-passes is enabled on the command line.
|
|
|
|
///
|
2009-06-18 05:28:54 +08:00
|
|
|
|
2009-06-19 04:51:00 +08:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > TimingInfoMutex;
|
2009-06-18 05:28:54 +08:00
|
|
|
|
2009-10-25 14:33:48 +08:00
|
|
|
class TimingInfo {
|
2012-12-04 01:31:11 +08:00
|
|
|
DenseMap<Pass*, Timer*> TimingData;
|
2007-01-30 07:10:37 +08:00
|
|
|
TimerGroup TG;
|
|
|
|
public:
|
|
|
|
// Use 'create' member to get this.
|
|
|
|
TimingInfo() : TG("... Pass execution timing report ...") {}
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2007-01-30 07:10:37 +08:00
|
|
|
// TimingDtor - Print out information about timing information
|
|
|
|
~TimingInfo() {
|
2010-03-30 12:03:22 +08:00
|
|
|
// Delete all of the timers, which accumulate their info into the
|
|
|
|
// TimerGroup.
|
2012-12-04 01:31:11 +08:00
|
|
|
for (DenseMap<Pass*, Timer*>::iterator I = TimingData.begin(),
|
2010-03-30 12:03:22 +08:00
|
|
|
E = TimingData.end(); I != E; ++I)
|
|
|
|
delete I->second;
|
2007-01-30 07:10:37 +08:00
|
|
|
// TimerGroup is deleted next, printing the report.
|
|
|
|
}
|
|
|
|
|
|
|
|
// createTheTimeInfo - This method either initializes the TheTimeInfo pointer
|
2013-12-05 13:44:44 +08:00
|
|
|
// to a non-null value (if the -time-passes option is enabled) or it leaves it
|
2007-01-30 07:10:37 +08:00
|
|
|
// null. It may be called multiple times.
|
|
|
|
static void createTheTimeInfo();
|
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
/// getPassTimer - Return the timer for the specified pass if it exists.
|
|
|
|
Timer *getPassTimer(Pass *P) {
|
2010-08-13 07:50:08 +08:00
|
|
|
if (P->getAsPMDataManager())
|
2009-09-28 08:07:05 +08:00
|
|
|
return 0;
|
2007-01-30 07:10:37 +08:00
|
|
|
|
2009-07-08 02:33:04 +08:00
|
|
|
sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
|
2012-12-04 01:31:11 +08:00
|
|
|
Timer *&T = TimingData[P];
|
2010-03-30 12:03:22 +08:00
|
|
|
if (T == 0)
|
|
|
|
T = new Timer(P->getPassName(), TG);
|
2010-03-30 11:57:00 +08:00
|
|
|
return T;
|
2007-01-30 07:10:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End of anon namespace
|
2006-11-08 18:05:38 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
static TimingInfo *TheTimeInfo;
|
|
|
|
|
2006-12-13 06:35:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PMTopLevelManager implementation
|
|
|
|
|
2007-01-16 10:00:38 +08:00
|
|
|
/// Initialize top level manager. Create first pass manager.
|
2010-08-17 05:38:42 +08:00
|
|
|
PMTopLevelManager::PMTopLevelManager(PMDataManager *PMDM) {
|
|
|
|
PMDM->setTopLevelManager(this);
|
|
|
|
addPassManager(PMDM);
|
|
|
|
activeStack.push(PMDM);
|
2007-01-16 10:00:38 +08:00
|
|
|
}
|
|
|
|
|
2006-12-13 06:35:25 +08:00
|
|
|
/// Set pass P as the last user of the given analysis passes.
|
2010-10-12 08:12:29 +08:00
|
|
|
void
|
2012-05-14 15:53:40 +08:00
|
|
|
PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) {
|
2011-01-21 05:03:22 +08:00
|
|
|
unsigned PDepth = 0;
|
|
|
|
if (P->getResolver())
|
|
|
|
PDepth = P->getResolver()->getPMDataManager().getDepth();
|
|
|
|
|
2010-10-12 08:12:29 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::const_iterator I = AnalysisPasses.begin(),
|
2006-12-13 06:35:25 +08:00
|
|
|
E = AnalysisPasses.end(); I != E; ++I) {
|
|
|
|
Pass *AP = *I;
|
|
|
|
LastUser[AP] = P;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2007-03-09 03:05:01 +08:00
|
|
|
if (P == AP)
|
|
|
|
continue;
|
|
|
|
|
2011-01-21 05:03:22 +08:00
|
|
|
// Update the last users of passes that are required transitive by AP.
|
|
|
|
AnalysisUsage *AnUsage = findAnalysisUsage(AP);
|
|
|
|
const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet();
|
|
|
|
SmallVector<Pass *, 12> LastUses;
|
|
|
|
SmallVector<Pass *, 12> LastPMUses;
|
|
|
|
for (AnalysisUsage::VectorType::const_iterator I = IDs.begin(),
|
|
|
|
E = IDs.end(); I != E; ++I) {
|
|
|
|
Pass *AnalysisPass = findAnalysisPass(*I);
|
|
|
|
assert(AnalysisPass && "Expected analysis pass to exist.");
|
|
|
|
AnalysisResolver *AR = AnalysisPass->getResolver();
|
|
|
|
assert(AR && "Expected analysis resolver to exist.");
|
|
|
|
unsigned APDepth = AR->getPMDataManager().getDepth();
|
|
|
|
|
|
|
|
if (PDepth == APDepth)
|
|
|
|
LastUses.push_back(AnalysisPass);
|
|
|
|
else if (PDepth > APDepth)
|
|
|
|
LastPMUses.push_back(AnalysisPass);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLastUser(LastUses, P);
|
|
|
|
|
|
|
|
// If this pass has a corresponding pass manager, push higher level
|
|
|
|
// analysis to this pass manager.
|
|
|
|
if (P->getResolver())
|
|
|
|
setLastUser(LastPMUses, P->getResolver()->getPMDataManager().getAsPass());
|
|
|
|
|
|
|
|
|
2006-12-13 06:35:25 +08:00
|
|
|
// If AP is the last user of other passes then make P last user of
|
|
|
|
// such passes.
|
2008-08-12 08:26:16 +08:00
|
|
|
for (DenseMap<Pass *, Pass *>::iterator LUI = LastUser.begin(),
|
2006-12-13 06:35:25 +08:00
|
|
|
LUE = LastUser.end(); LUI != LUE; ++LUI) {
|
|
|
|
if (LUI->second == AP)
|
2008-08-12 08:26:16 +08:00
|
|
|
// DenseMap iterator is not invalidated here because
|
2011-01-21 05:03:22 +08:00
|
|
|
// this is just updating existing entries.
|
2006-12-13 06:35:25 +08:00
|
|
|
LastUser[LUI->first] = P;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Collect passes whose last user is P
|
2010-10-12 08:11:18 +08:00
|
|
|
void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses,
|
2008-08-12 08:26:16 +08:00
|
|
|
Pass *P) {
|
2010-08-13 07:50:08 +08:00
|
|
|
DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
|
2008-08-12 08:26:16 +08:00
|
|
|
InversedLastUser.find(P);
|
|
|
|
if (DMI == InversedLastUser.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
SmallPtrSet<Pass *, 8> &LU = DMI->second;
|
|
|
|
for (SmallPtrSet<Pass *, 8>::iterator I = LU.begin(),
|
|
|
|
E = LU.end(); I != E; ++I) {
|
|
|
|
LastUses.push_back(*I);
|
|
|
|
}
|
|
|
|
|
2006-12-13 06:35:25 +08:00
|
|
|
}
|
|
|
|
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
|
|
|
|
AnalysisUsage *AnUsage = NULL;
|
|
|
|
DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.find(P);
|
2010-08-13 07:50:08 +08:00
|
|
|
if (DMI != AnUsageMap.end())
|
2008-08-12 05:13:39 +08:00
|
|
|
AnUsage = DMI->second;
|
|
|
|
else {
|
|
|
|
AnUsage = new AnalysisUsage();
|
|
|
|
P->getAnalysisUsage(*AnUsage);
|
|
|
|
AnUsageMap[P] = AnUsage;
|
|
|
|
}
|
|
|
|
return AnUsage;
|
|
|
|
}
|
|
|
|
|
2006-12-13 06:35:25 +08:00
|
|
|
/// Schedule pass P for execution. Make sure that passes required by
|
|
|
|
/// P are run before P is run. Update analysis info maintained by
|
|
|
|
/// the manager. Remove dead passes. This is a recursive function.
|
|
|
|
void PMTopLevelManager::schedulePass(Pass *P) {
|
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// TODO : Allocate function manager for this pass, other wise required set
|
|
|
|
// may be inserted into previous function manager
|
2006-12-13 06:35:25 +08:00
|
|
|
|
2007-03-06 09:06:16 +08:00
|
|
|
// Give pass a chance to prepare the stage.
|
|
|
|
P->preparePassManager(activeStack);
|
|
|
|
|
2008-03-18 08:39:19 +08:00
|
|
|
// If P is an analysis pass and it is available then do not
|
|
|
|
// generate the analysis again. Stale analysis info should not be
|
|
|
|
// available at this point.
|
2010-08-07 02:33:48 +08:00
|
|
|
const PassInfo *PI =
|
|
|
|
PassRegistry::getPassRegistry()->getPassInfo(P->getPassID());
|
|
|
|
if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
|
2008-11-05 07:03:58 +08:00
|
|
|
delete P;
|
2008-03-19 08:48:41 +08:00
|
|
|
return;
|
2008-11-05 07:03:58 +08:00
|
|
|
}
|
2008-03-18 08:39:19 +08:00
|
|
|
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *AnUsage = findAnalysisUsage(P);
|
|
|
|
|
2008-08-15 07:07:48 +08:00
|
|
|
bool checkAnalysis = true;
|
|
|
|
while (checkAnalysis) {
|
|
|
|
checkAnalysis = false;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2008-08-15 07:07:48 +08:00
|
|
|
const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
|
|
|
|
for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
|
|
|
|
E = RequiredSet.end(); I != E; ++I) {
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2008-08-15 07:07:48 +08:00
|
|
|
Pass *AnalysisPass = findAnalysisPass(*I);
|
|
|
|
if (!AnalysisPass) {
|
2010-08-07 02:33:48 +08:00
|
|
|
const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(*I);
|
2012-07-19 03:59:29 +08:00
|
|
|
|
|
|
|
if (PI == NULL) {
|
|
|
|
// Pass P is not in the global PassRegistry
|
|
|
|
dbgs() << "Pass '" << P->getPassName() << "' is not initialized." << "\n";
|
|
|
|
dbgs() << "Verify if there is a pass dependency cycle." << "\n";
|
|
|
|
dbgs() << "Required Passes:" << "\n";
|
|
|
|
for (AnalysisUsage::VectorType::const_iterator I2 = RequiredSet.begin(),
|
|
|
|
E = RequiredSet.end(); I2 != E && I2 != I; ++I2) {
|
|
|
|
Pass *AnalysisPass2 = findAnalysisPass(*I2);
|
|
|
|
if (AnalysisPass2) {
|
|
|
|
dbgs() << "\t" << AnalysisPass2->getPassName() << "\n";
|
2013-02-06 14:50:38 +08:00
|
|
|
} else {
|
2012-07-19 03:59:29 +08:00
|
|
|
dbgs() << "\t" << "Error: Required pass not found! Possible causes:" << "\n";
|
|
|
|
dbgs() << "\t\t" << "- Pass misconfiguration (e.g.: missing macros)" << "\n";
|
|
|
|
dbgs() << "\t\t" << "- Corruption of the global PassRegistry" << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-03 08:48:58 +08:00
|
|
|
assert(PI && "Expected required passes to be initialized");
|
2010-08-07 02:33:48 +08:00
|
|
|
AnalysisPass = PI->createPass();
|
2008-08-15 07:07:48 +08:00
|
|
|
if (P->getPotentialPassManagerType () ==
|
|
|
|
AnalysisPass->getPotentialPassManagerType())
|
|
|
|
// Schedule analysis pass that is managed by the same pass manager.
|
|
|
|
schedulePass(AnalysisPass);
|
|
|
|
else if (P->getPotentialPassManagerType () >
|
|
|
|
AnalysisPass->getPotentialPassManagerType()) {
|
|
|
|
// Schedule analysis pass that is managed by a new manager.
|
|
|
|
schedulePass(AnalysisPass);
|
2010-08-17 06:57:28 +08:00
|
|
|
// Recheck analysis passes to ensure that required analyses that
|
2008-08-15 07:07:48 +08:00
|
|
|
// are already checked are still available.
|
|
|
|
checkAnalysis = true;
|
2013-02-06 14:50:38 +08:00
|
|
|
} else
|
2010-08-13 07:50:08 +08:00
|
|
|
// Do not schedule this analysis. Lower level analsyis
|
2008-08-15 07:07:48 +08:00
|
|
|
// passes are run on the fly.
|
|
|
|
delete AnalysisPass;
|
|
|
|
}
|
2006-12-13 06:35:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now all required passes are available.
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
if (ImmutablePass *IP = P->getAsImmutablePass()) {
|
|
|
|
// P is a immutable pass and it will be managed by this
|
|
|
|
// top level manager. Set up analysis resolver to connect them.
|
|
|
|
PMDataManager *DM = getAsPMDataManager();
|
|
|
|
AnalysisResolver *AR = new AnalysisResolver(*DM);
|
|
|
|
P->setResolver(AR);
|
|
|
|
DM->initializeAnalysisImpl(P);
|
|
|
|
addImmutablePass(IP);
|
|
|
|
DM->recordAvailableAnalysis(IP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PI && !PI->isAnalysis() && ShouldPrintBeforePass(PI)) {
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
Pass *PP = P->createPrinterPass(
|
|
|
|
dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***");
|
|
|
|
PP->assignPassManager(activeStack, getTopLevelPassManagerType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the requested pass to the best available pass manager.
|
|
|
|
P->assignPassManager(activeStack, getTopLevelPassManagerType());
|
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PI && !PI->isAnalysis() && ShouldPrintAfterPass(PI)) {
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
Pass *PP = P->createPrinterPass(
|
|
|
|
dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
|
|
|
|
PP->assignPassManager(activeStack, getTopLevelPassManagerType());
|
|
|
|
}
|
2006-12-13 06:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Find the pass that implements Analysis AID. Search immutable
|
|
|
|
/// passes and all pass managers. If desired pass is not found
|
|
|
|
/// then return NULL.
|
|
|
|
Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
|
|
|
|
|
2006-12-13 06:50:05 +08:00
|
|
|
// Check pass managers
|
2010-10-12 08:11:18 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::iterator I = PassManagers.begin(),
|
2010-10-12 07:19:01 +08:00
|
|
|
E = PassManagers.end(); I != E; ++I)
|
|
|
|
if (Pass *P = (*I)->findAnalysisPass(AID, false))
|
|
|
|
return P;
|
2006-12-13 06:50:05 +08:00
|
|
|
|
|
|
|
// Check other pass managers
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::iterator
|
2009-03-06 13:53:14 +08:00
|
|
|
I = IndirectPassManagers.begin(),
|
2010-10-12 07:19:01 +08:00
|
|
|
E = IndirectPassManagers.end(); I != E; ++I)
|
|
|
|
if (Pass *P = (*I)->findAnalysisPass(AID, false))
|
|
|
|
return P;
|
|
|
|
|
|
|
|
// Check the immutable passes. Iterate in reverse order so that we find
|
|
|
|
// the most recently registered passes first.
|
2013-07-03 23:07:05 +08:00
|
|
|
for (SmallVectorImpl<ImmutablePass *>::reverse_iterator I =
|
2010-10-12 07:19:01 +08:00
|
|
|
ImmutablePasses.rbegin(), E = ImmutablePasses.rend(); I != E; ++I) {
|
2010-08-07 02:33:48 +08:00
|
|
|
AnalysisID PI = (*I)->getPassID();
|
2006-12-13 06:35:25 +08:00
|
|
|
if (PI == AID)
|
2010-10-12 07:19:01 +08:00
|
|
|
return *I;
|
2006-12-13 06:35:25 +08:00
|
|
|
|
|
|
|
// If Pass not found then check the interfaces implemented by Immutable Pass
|
2010-10-12 07:19:01 +08:00
|
|
|
const PassInfo *PassInf =
|
|
|
|
PassRegistry::getPassRegistry()->getPassInfo(PI);
|
2011-06-03 08:48:58 +08:00
|
|
|
assert(PassInf && "Expected all immutable passes to be initialized");
|
2010-10-12 07:19:01 +08:00
|
|
|
const std::vector<const PassInfo*> &ImmPI =
|
|
|
|
PassInf->getInterfacesImplemented();
|
|
|
|
for (std::vector<const PassInfo*>::const_iterator II = ImmPI.begin(),
|
|
|
|
EE = ImmPI.end(); II != EE; ++II) {
|
|
|
|
if ((*II)->getTypeInfo() == AID)
|
|
|
|
return *I;
|
2006-12-13 06:35:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 07:19:01 +08:00
|
|
|
return 0;
|
2006-12-13 06:35:25 +08:00
|
|
|
}
|
|
|
|
|
2006-12-13 07:34:33 +08:00
|
|
|
// Print passes managed by this top level manager.
|
2006-12-16 04:13:01 +08:00
|
|
|
void PMTopLevelManager::dumpPasses() const {
|
2006-12-13 07:34:33 +08:00
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging < Structure)
|
2006-12-20 03:46:59 +08:00
|
|
|
return;
|
|
|
|
|
2006-12-13 07:34:33 +08:00
|
|
|
// Print out the immutable passes
|
|
|
|
for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
|
2010-08-19 09:29:07 +08:00
|
|
|
ImmutablePasses[i]->dumpPassStructure(0);
|
2006-12-13 07:34:33 +08:00
|
|
|
}
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2010-08-19 09:29:07 +08:00
|
|
|
// Every class that derives from PMDataManager also derives from Pass
|
|
|
|
// (sometimes indirectly), but there's no inheritance relationship
|
|
|
|
// between PMDataManager and Pass, so we have to getAsPass to get
|
|
|
|
// from a PMDataManager* to a Pass*.
|
2013-07-03 23:07:05 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::const_iterator I =
|
|
|
|
PassManagers.begin(), E = PassManagers.end(); I != E; ++I)
|
2010-08-19 09:29:07 +08:00
|
|
|
(*I)->getAsPass()->dumpPassStructure(1);
|
2006-12-13 07:34:33 +08:00
|
|
|
}
|
|
|
|
|
2006-12-16 04:13:01 +08:00
|
|
|
void PMTopLevelManager::dumpArguments() const {
|
2006-12-14 06:10:00 +08:00
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging < Arguments)
|
2006-12-14 06:10:00 +08:00
|
|
|
return;
|
|
|
|
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "Pass Arguments: ";
|
2013-07-03 23:07:05 +08:00
|
|
|
for (SmallVectorImpl<ImmutablePass *>::const_iterator I =
|
2010-11-12 00:32:17 +08:00
|
|
|
ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
|
|
|
|
if (const PassInfo *PI =
|
2011-06-03 08:48:58 +08:00
|
|
|
PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID())) {
|
|
|
|
assert(PI && "Expected all immutable passes to be initialized");
|
2010-11-12 00:32:17 +08:00
|
|
|
if (!PI->isAnalysisGroup())
|
|
|
|
dbgs() << " -" << PI->getPassArgument();
|
2011-06-03 08:48:58 +08:00
|
|
|
}
|
2013-07-03 23:07:05 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::const_iterator I =
|
|
|
|
PassManagers.begin(), E = PassManagers.end(); I != E; ++I)
|
2009-03-06 14:45:05 +08:00
|
|
|
(*I)->dumpPassArguments();
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "\n";
|
2006-12-14 06:10:00 +08:00
|
|
|
}
|
|
|
|
|
2006-12-21 08:16:50 +08:00
|
|
|
void PMTopLevelManager::initializeAllAnalysisInfo() {
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::iterator I = PassManagers.begin(),
|
2009-03-06 14:45:05 +08:00
|
|
|
E = PassManagers.end(); I != E; ++I)
|
|
|
|
(*I)->initializeAnalysisInfo();
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2006-12-21 08:16:50 +08:00
|
|
|
// Initailize other pass managers
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::iterator
|
2010-08-13 07:50:08 +08:00
|
|
|
I = IndirectPassManagers.begin(), E = IndirectPassManagers.end();
|
|
|
|
I != E; ++I)
|
2006-12-21 08:16:50 +08:00
|
|
|
(*I)->initializeAnalysisInfo();
|
2008-08-12 08:26:16 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
for (DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
|
2008-08-12 08:26:16 +08:00
|
|
|
DME = LastUser.end(); DMI != DME; ++DMI) {
|
2010-08-13 07:50:08 +08:00
|
|
|
DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator InvDMI =
|
2008-08-12 08:26:16 +08:00
|
|
|
InversedLastUser.find(DMI->second);
|
|
|
|
if (InvDMI != InversedLastUser.end()) {
|
|
|
|
SmallPtrSet<Pass *, 8> &L = InvDMI->second;
|
|
|
|
L.insert(DMI->first);
|
|
|
|
} else {
|
|
|
|
SmallPtrSet<Pass *, 8> L; L.insert(DMI->first);
|
|
|
|
InversedLastUser[DMI->second] = L;
|
|
|
|
}
|
|
|
|
}
|
2006-12-21 08:16:50 +08:00
|
|
|
}
|
|
|
|
|
2007-01-13 02:52:44 +08:00
|
|
|
/// Destructor
|
|
|
|
PMTopLevelManager::~PMTopLevelManager() {
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<PMDataManager *>::iterator I = PassManagers.begin(),
|
2007-01-13 02:52:44 +08:00
|
|
|
E = PassManagers.end(); I != E; ++I)
|
|
|
|
delete *I;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<ImmutablePass *>::iterator
|
2007-01-13 02:52:44 +08:00
|
|
|
I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
|
|
|
|
delete *I;
|
2008-08-12 05:13:39 +08:00
|
|
|
|
|
|
|
for (DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.begin(),
|
2009-03-06 13:53:14 +08:00
|
|
|
DME = AnUsageMap.end(); DMI != DME; ++DMI)
|
|
|
|
delete DMI->second;
|
2007-01-13 02:52:44 +08:00
|
|
|
}
|
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-08 02:36:24 +08:00
|
|
|
// PMDataManager implementation
|
2006-11-08 06:35:17 +08:00
|
|
|
|
2006-11-11 09:10:19 +08:00
|
|
|
/// Augement AvailableAnalysis by adding analysis made available by pass P.
|
2006-12-08 03:33:53 +08:00
|
|
|
void PMDataManager::recordAvailableAnalysis(Pass *P) {
|
2010-08-07 02:33:48 +08:00
|
|
|
AnalysisID PI = P->getPassID();
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
AvailableAnalysis[PI] = P;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2010-08-13 07:46:28 +08:00
|
|
|
assert(!AvailableAnalysis.empty());
|
2006-11-11 09:10:19 +08:00
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
// This pass is the current implementation of all of the interfaces it
|
|
|
|
// implements as well.
|
2010-08-07 02:33:48 +08:00
|
|
|
const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI);
|
|
|
|
if (PInf == 0) return;
|
|
|
|
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
|
2010-07-21 00:55:05 +08:00
|
|
|
for (unsigned i = 0, e = II.size(); i != e; ++i)
|
2010-08-07 02:33:48 +08:00
|
|
|
AvailableAnalysis[II[i]->getTypeInfo()] = P;
|
2006-11-11 09:10:19 +08:00
|
|
|
}
|
|
|
|
|
2007-03-07 01:52:53 +08:00
|
|
|
// Return true if P preserves high level analysis used by other
|
|
|
|
// passes managed by this manager
|
|
|
|
bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
if (AnUsage->getPreservesAll())
|
2007-03-07 01:52:53 +08:00
|
|
|
return true;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2008-08-12 05:13:39 +08:00
|
|
|
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = HigherLevelAnalysis.begin(),
|
2007-03-07 01:52:53 +08:00
|
|
|
E = HigherLevelAnalysis.end(); I != E; ++I) {
|
|
|
|
Pass *P1 = *I;
|
2010-01-22 12:55:08 +08:00
|
|
|
if (P1->getAsImmutablePass() == 0 &&
|
2008-01-29 20:09:55 +08:00
|
|
|
std::find(PreservedSet.begin(), PreservedSet.end(),
|
2010-08-13 07:50:08 +08:00
|
|
|
P1->getPassID()) ==
|
2007-03-09 03:05:01 +08:00
|
|
|
PreservedSet.end())
|
|
|
|
return false;
|
2007-03-07 01:52:53 +08:00
|
|
|
}
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2007-03-07 01:52:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-07 15:34:50 +08:00
|
|
|
/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
|
2007-07-20 02:02:32 +08:00
|
|
|
void PMDataManager::verifyPreservedAnalysis(Pass *P) {
|
2008-08-07 15:34:50 +08:00
|
|
|
// Don't do this unless assertions are enabled.
|
|
|
|
#ifdef NDEBUG
|
|
|
|
return;
|
|
|
|
#endif
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
|
2006-11-11 09:24:55 +08:00
|
|
|
|
2007-07-19 13:36:09 +08:00
|
|
|
// Verify preserved analysis
|
2008-08-08 13:33:04 +08:00
|
|
|
for (AnalysisUsage::VectorType::const_iterator I = PreservedSet.begin(),
|
2007-07-20 02:02:32 +08:00
|
|
|
E = PreservedSet.end(); I != E; ++I) {
|
|
|
|
AnalysisID AID = *I;
|
2009-09-28 08:27:48 +08:00
|
|
|
if (Pass *AP = findAnalysisPass(AID, true)) {
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRegion PassTimer(getPassTimer(AP));
|
2009-09-28 08:27:48 +08:00
|
|
|
AP->verifyAnalysis();
|
|
|
|
}
|
2008-07-02 01:44:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-02 03:50:56 +08:00
|
|
|
/// Remove Analysis not preserved by Pass P
|
2007-07-20 02:02:32 +08:00
|
|
|
void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
if (AnUsage->getPreservesAll())
|
2006-12-08 04:03:49 +08:00
|
|
|
return;
|
|
|
|
|
2008-08-12 05:13:39 +08:00
|
|
|
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
|
2013-02-26 09:31:59 +08:00
|
|
|
for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
|
2006-12-13 07:07:44 +08:00
|
|
|
E = AvailableAnalysis.end(); I != E; ) {
|
2013-02-26 09:31:59 +08:00
|
|
|
DenseMap<AnalysisID, Pass*>::iterator Info = I++;
|
2010-01-22 12:55:08 +08:00
|
|
|
if (Info->second->getAsImmutablePass() == 0 &&
|
2010-08-13 07:50:08 +08:00
|
|
|
std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
|
2008-06-03 09:02:16 +08:00
|
|
|
PreservedSet.end()) {
|
2006-11-11 09:24:55 +08:00
|
|
|
// Remove this analysis
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging >= Details) {
|
2008-06-03 09:02:16 +08:00
|
|
|
Pass *S = Info->second;
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
|
|
|
|
dbgs() << S->getPassName() << "'\n";
|
2008-06-03 09:02:16 +08:00
|
|
|
}
|
2008-11-07 05:57:17 +08:00
|
|
|
AvailableAnalysis.erase(Info);
|
2008-06-03 09:02:16 +08:00
|
|
|
}
|
2006-11-11 09:24:55 +08:00
|
|
|
}
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2007-03-06 09:55:46 +08:00
|
|
|
// Check inherited analysis also. If P is not preserving analysis
|
|
|
|
// provided by parent manager then remove it here.
|
|
|
|
for (unsigned Index = 0; Index < PMT_Last; ++Index) {
|
|
|
|
|
|
|
|
if (!InheritedAnalysis[Index])
|
|
|
|
continue;
|
|
|
|
|
2013-02-26 09:31:59 +08:00
|
|
|
for (DenseMap<AnalysisID, Pass*>::iterator
|
2007-03-06 09:55:46 +08:00
|
|
|
I = InheritedAnalysis[Index]->begin(),
|
|
|
|
E = InheritedAnalysis[Index]->end(); I != E; ) {
|
2013-02-26 09:31:59 +08:00
|
|
|
DenseMap<AnalysisID, Pass *>::iterator Info = I++;
|
2010-01-22 12:55:08 +08:00
|
|
|
if (Info->second->getAsImmutablePass() == 0 &&
|
2010-08-13 07:50:08 +08:00
|
|
|
std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
|
2009-12-04 14:58:24 +08:00
|
|
|
PreservedSet.end()) {
|
2007-03-06 09:55:46 +08:00
|
|
|
// Remove this analysis
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging >= Details) {
|
2009-12-04 14:58:24 +08:00
|
|
|
Pass *S = Info->second;
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
|
|
|
|
dbgs() << S->getPassName() << "'\n";
|
2009-12-04 14:58:24 +08:00
|
|
|
}
|
2007-03-09 03:05:01 +08:00
|
|
|
InheritedAnalysis[Index]->erase(Info);
|
2009-12-04 14:58:24 +08:00
|
|
|
}
|
2007-03-06 09:55:46 +08:00
|
|
|
}
|
|
|
|
}
|
2006-11-08 06:35:17 +08:00
|
|
|
}
|
|
|
|
|
2006-11-14 11:05:08 +08:00
|
|
|
/// Remove analysis passes that are not used any longer
|
2009-11-06 18:58:06 +08:00
|
|
|
void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
|
2007-03-06 04:01:30 +08:00
|
|
|
enum PassDebuggingString DBG_STR) {
|
2006-12-08 08:37:52 +08:00
|
|
|
|
2007-07-21 02:04:54 +08:00
|
|
|
SmallVector<Pass *, 12> DeadPasses;
|
2007-04-17 04:27:05 +08:00
|
|
|
|
2007-04-17 04:39:59 +08:00
|
|
|
// If this is a on the fly manager then it does not have TPM.
|
2007-04-17 04:27:05 +08:00
|
|
|
if (!TPM)
|
|
|
|
return;
|
|
|
|
|
2006-12-08 08:37:52 +08:00
|
|
|
TPM->collectLastUses(DeadPasses, P);
|
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging >= Details && !DeadPasses.empty()) {
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << " -*- '" << P->getPassName();
|
|
|
|
dbgs() << "' is the last user of following pass instances.";
|
|
|
|
dbgs() << " Free these instances\n";
|
2008-06-04 17:13:31 +08:00
|
|
|
}
|
|
|
|
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = DeadPasses.begin(),
|
2009-09-28 07:38:27 +08:00
|
|
|
E = DeadPasses.end(); I != E; ++I)
|
|
|
|
freePass(*I, Msg, DBG_STR);
|
|
|
|
}
|
2006-12-14 07:50:44 +08:00
|
|
|
|
2009-11-06 18:58:06 +08:00
|
|
|
void PMDataManager::freePass(Pass *P, StringRef Msg,
|
2009-09-28 07:38:27 +08:00
|
|
|
enum PassDebuggingString DBG_STR) {
|
|
|
|
dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
|
2006-12-14 07:50:44 +08:00
|
|
|
|
2009-09-28 07:38:27 +08:00
|
|
|
{
|
|
|
|
// If the pass crashes releasing memory, remember this.
|
|
|
|
PassManagerPrettyStackEntry X(P);
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRegion PassTimer(getPassTimer(P));
|
|
|
|
|
2009-09-28 07:38:27 +08:00
|
|
|
P->releaseMemory();
|
|
|
|
}
|
2008-10-07 04:36:36 +08:00
|
|
|
|
2010-08-07 02:33:48 +08:00
|
|
|
AnalysisID PI = P->getPassID();
|
|
|
|
if (const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI)) {
|
2009-09-28 07:38:27 +08:00
|
|
|
// Remove the pass itself (if it is not already removed).
|
|
|
|
AvailableAnalysis.erase(PI);
|
2008-10-07 04:36:36 +08:00
|
|
|
|
2009-09-28 07:38:27 +08:00
|
|
|
// Remove all interfaces this pass implements, for which it is also
|
|
|
|
// listed as the available implementation.
|
2010-08-07 02:33:48 +08:00
|
|
|
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
|
2010-07-21 00:55:05 +08:00
|
|
|
for (unsigned i = 0, e = II.size(); i != e; ++i) {
|
2013-02-26 09:31:59 +08:00
|
|
|
DenseMap<AnalysisID, Pass*>::iterator Pos =
|
2010-08-07 02:33:48 +08:00
|
|
|
AvailableAnalysis.find(II[i]->getTypeInfo());
|
2009-09-28 07:38:27 +08:00
|
|
|
if (Pos != AvailableAnalysis.end() && Pos->second == P)
|
|
|
|
AvailableAnalysis.erase(Pos);
|
2008-10-07 04:36:36 +08:00
|
|
|
}
|
2006-12-08 08:37:52 +08:00
|
|
|
}
|
2006-11-14 11:05:08 +08:00
|
|
|
}
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// Add pass P into the PassVector. Update
|
2006-11-11 10:04:19 +08:00
|
|
|
/// AvailableAnalysis appropriately if ProcessAnalysis is true.
|
2009-03-06 13:53:14 +08:00
|
|
|
void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
|
2006-12-09 07:53:00 +08:00
|
|
|
// This manager is going to manage pass P. Set up analysis resolver
|
|
|
|
// to connect them.
|
2007-01-06 06:47:07 +08:00
|
|
|
AnalysisResolver *AR = new AnalysisResolver(*this);
|
2006-12-09 07:53:00 +08:00
|
|
|
P->setResolver(AR);
|
|
|
|
|
2007-03-06 06:57:49 +08:00
|
|
|
// If a FunctionPass F is the last user of ModulePass info M
|
|
|
|
// then the F's manager, not F, records itself as a last user of M.
|
2007-07-21 02:04:54 +08:00
|
|
|
SmallVector<Pass *, 12> TransferLastUses;
|
2007-03-06 06:57:49 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
if (!ProcessAnalysis) {
|
|
|
|
// Add pass
|
|
|
|
PassVector.push_back(P);
|
|
|
|
return;
|
|
|
|
}
|
2007-04-17 04:12:57 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
// At the moment, this pass is the last user of all required passes.
|
|
|
|
SmallVector<Pass *, 12> LastUses;
|
|
|
|
SmallVector<Pass *, 8> RequiredPasses;
|
|
|
|
SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
|
2007-03-06 06:57:49 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
unsigned PDepth = this->getDepth();
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
collectRequiredAnalysis(RequiredPasses,
|
2009-03-06 13:53:14 +08:00
|
|
|
ReqAnalysisNotAvailable, P);
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = RequiredPasses.begin(),
|
2009-03-06 13:53:14 +08:00
|
|
|
E = RequiredPasses.end(); I != E; ++I) {
|
|
|
|
Pass *PRequired = *I;
|
|
|
|
unsigned RDepth = 0;
|
|
|
|
|
|
|
|
assert(PRequired->getResolver() && "Analysis Resolver is not set");
|
|
|
|
PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
|
|
|
|
RDepth = DM.getDepth();
|
|
|
|
|
|
|
|
if (PDepth == RDepth)
|
|
|
|
LastUses.push_back(PRequired);
|
|
|
|
else if (PDepth > RDepth) {
|
|
|
|
// Let the parent claim responsibility of last use
|
|
|
|
TransferLastUses.push_back(PRequired);
|
|
|
|
// Keep track of higher level analysis used by this manager.
|
|
|
|
HigherLevelAnalysis.push_back(PRequired);
|
2010-08-13 07:50:08 +08:00
|
|
|
} else
|
2011-04-15 13:18:47 +08:00
|
|
|
llvm_unreachable("Unable to accommodate Required Pass");
|
2009-03-06 13:53:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set P as P's last user until someone starts using P.
|
|
|
|
// However, if P is a Pass Manager then it does not need
|
|
|
|
// to record its last user.
|
2010-01-22 13:24:46 +08:00
|
|
|
if (P->getAsPMDataManager() == 0)
|
2009-03-06 13:53:14 +08:00
|
|
|
LastUses.push_back(P);
|
|
|
|
TPM->setLastUser(LastUses, P);
|
|
|
|
|
|
|
|
if (!TransferLastUses.empty()) {
|
2010-01-22 13:24:46 +08:00
|
|
|
Pass *My_PM = getAsPass();
|
2009-03-06 13:53:14 +08:00
|
|
|
TPM->setLastUser(TransferLastUses, My_PM);
|
|
|
|
TransferLastUses.clear();
|
|
|
|
}
|
2007-04-17 04:27:05 +08:00
|
|
|
|
2010-08-17 06:57:28 +08:00
|
|
|
// Now, take care of required analyses that are not available.
|
2010-10-12 08:15:27 +08:00
|
|
|
for (SmallVectorImpl<AnalysisID>::iterator
|
2010-08-13 07:50:08 +08:00
|
|
|
I = ReqAnalysisNotAvailable.begin(),
|
2009-03-06 13:53:14 +08:00
|
|
|
E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
|
2010-08-07 02:33:48 +08:00
|
|
|
const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(*I);
|
|
|
|
Pass *AnalysisPass = PI->createPass();
|
2009-03-06 13:53:14 +08:00
|
|
|
this->addLowerLevelRequiredPass(P, AnalysisPass);
|
2006-11-11 10:04:19 +08:00
|
|
|
}
|
2006-11-11 09:51:02 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
// Take a note of analysis required and made available by this pass.
|
|
|
|
// Remove the analysis not preserved by this pass
|
|
|
|
removeNotPreservedAnalysis(P);
|
|
|
|
recordAvailableAnalysis(P);
|
|
|
|
|
2006-11-11 09:51:02 +08:00
|
|
|
// Add pass
|
|
|
|
PassVector.push_back(P);
|
|
|
|
}
|
|
|
|
|
2007-04-17 04:12:57 +08:00
|
|
|
|
|
|
|
/// Populate RP with analysis pass that are required by
|
|
|
|
/// pass P and are available. Populate RP_NotAvail with analysis
|
|
|
|
/// pass that are required by pass P but are not available.
|
2010-10-12 08:11:18 +08:00
|
|
|
void PMDataManager::collectRequiredAnalysis(SmallVectorImpl<Pass *> &RP,
|
|
|
|
SmallVectorImpl<AnalysisID> &RP_NotAvail,
|
2007-04-17 04:12:57 +08:00
|
|
|
Pass *P) {
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
|
2010-08-13 07:50:08 +08:00
|
|
|
for (AnalysisUsage::VectorType::const_iterator
|
2009-03-06 13:53:14 +08:00
|
|
|
I = RequiredSet.begin(), E = RequiredSet.end(); I != E; ++I) {
|
2007-04-17 04:12:57 +08:00
|
|
|
if (Pass *AnalysisPass = findAnalysisPass(*I, true))
|
2010-08-13 07:50:08 +08:00
|
|
|
RP.push_back(AnalysisPass);
|
2007-04-17 04:12:57 +08:00
|
|
|
else
|
2009-03-06 13:53:14 +08:00
|
|
|
RP_NotAvail.push_back(*I);
|
2006-12-08 07:05:44 +08:00
|
|
|
}
|
2006-12-13 07:09:32 +08:00
|
|
|
|
2008-08-12 05:13:39 +08:00
|
|
|
const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet();
|
2008-08-08 13:33:04 +08:00
|
|
|
for (AnalysisUsage::VectorType::const_iterator I = IDs.begin(),
|
2006-12-13 07:09:32 +08:00
|
|
|
E = IDs.end(); I != E; ++I) {
|
2007-04-17 04:12:57 +08:00
|
|
|
if (Pass *AnalysisPass = findAnalysisPass(*I, true))
|
2010-08-13 07:50:08 +08:00
|
|
|
RP.push_back(AnalysisPass);
|
2007-04-17 04:12:57 +08:00
|
|
|
else
|
2009-03-06 13:53:14 +08:00
|
|
|
RP_NotAvail.push_back(*I);
|
2006-12-13 07:09:32 +08:00
|
|
|
}
|
2006-12-08 07:05:44 +08:00
|
|
|
}
|
|
|
|
|
2006-11-15 05:49:36 +08:00
|
|
|
// All Required analyses should be available to the pass as it runs! Here
|
|
|
|
// we fill in the AnalysisImpls member of the pass so that it can
|
|
|
|
// successfully use the getAnalysis() method to retrieve the
|
|
|
|
// implementations it needs.
|
|
|
|
//
|
2006-12-08 02:36:24 +08:00
|
|
|
void PMDataManager::initializeAnalysisImpl(Pass *P) {
|
2008-08-12 05:13:39 +08:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
|
2008-08-08 13:33:04 +08:00
|
|
|
for (AnalysisUsage::VectorType::const_iterator
|
2008-08-12 05:13:39 +08:00
|
|
|
I = AnUsage->getRequiredSet().begin(),
|
|
|
|
E = AnUsage->getRequiredSet().end(); I != E; ++I) {
|
2006-12-09 06:30:11 +08:00
|
|
|
Pass *Impl = findAnalysisPass(*I, true);
|
2006-11-15 05:49:36 +08:00
|
|
|
if (Impl == 0)
|
2007-04-17 04:44:16 +08:00
|
|
|
// This may be analysis pass that is initialized on the fly.
|
|
|
|
// If that is not the case then it will raise an assert when it is used.
|
|
|
|
continue;
|
2007-01-06 06:47:07 +08:00
|
|
|
AnalysisResolver *AR = P->getResolver();
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(AR && "Analysis Resolver is not set");
|
2006-12-09 09:11:34 +08:00
|
|
|
AR->addAnalysisImplsPair(*I, Impl);
|
2006-11-15 05:49:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-09 06:30:11 +08:00
|
|
|
/// Find the pass that implements Analysis AID. If desired pass is not found
|
|
|
|
/// then return NULL.
|
|
|
|
Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
|
|
|
|
|
|
|
|
// Check if AvailableAnalysis map has one entry.
|
2013-02-26 09:31:59 +08:00
|
|
|
DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
|
2006-12-09 06:30:11 +08:00
|
|
|
|
|
|
|
if (I != AvailableAnalysis.end())
|
|
|
|
return I->second;
|
|
|
|
|
|
|
|
// Search Parents through TopLevelManager
|
|
|
|
if (SearchParent)
|
|
|
|
return TPM->findAnalysisPass(AID);
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2006-12-09 08:09:12 +08:00
|
|
|
return NULL;
|
2006-12-09 06:30:11 +08:00
|
|
|
}
|
|
|
|
|
2006-12-16 04:13:01 +08:00
|
|
|
// Print list of passes that are last used by P.
|
|
|
|
void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
|
|
|
|
|
2007-07-21 02:04:54 +08:00
|
|
|
SmallVector<Pass *, 12> LUses;
|
2007-04-17 04:39:59 +08:00
|
|
|
|
|
|
|
// If this is a on the fly manager then it does not have TPM.
|
|
|
|
if (!TPM)
|
|
|
|
return;
|
|
|
|
|
2006-12-16 04:13:01 +08:00
|
|
|
TPM->collectLastUses(LUses, P);
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2010-10-12 08:11:18 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = LUses.begin(),
|
2006-12-16 04:13:01 +08:00
|
|
|
E = LUses.end(); I != E; ++I) {
|
2010-01-05 09:30:02 +08:00
|
|
|
llvm::dbgs() << "--" << std::string(Offset*2, ' ');
|
2010-08-19 09:29:07 +08:00
|
|
|
(*I)->dumpPassStructure(0);
|
2006-12-16 04:13:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PMDataManager::dumpPassArguments() const {
|
2010-10-12 08:11:18 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::const_iterator I = PassVector.begin(),
|
2006-12-16 04:13:01 +08:00
|
|
|
E = PassVector.end(); I != E; ++I) {
|
2010-01-22 13:24:46 +08:00
|
|
|
if (PMDataManager *PMD = (*I)->getAsPMDataManager())
|
2006-12-16 04:13:01 +08:00
|
|
|
PMD->dumpPassArguments();
|
|
|
|
else
|
2010-08-07 02:33:48 +08:00
|
|
|
if (const PassInfo *PI =
|
|
|
|
PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID()))
|
2006-12-16 04:13:01 +08:00
|
|
|
if (!PI->isAnalysisGroup())
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << " -" << PI->getPassArgument();
|
2006-12-16 04:13:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-10 14:17:04 +08:00
|
|
|
void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
|
|
|
|
enum PassDebuggingString S2,
|
2009-11-06 18:58:06 +08:00
|
|
|
StringRef Msg) {
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging < Executions)
|
2006-12-16 04:13:01 +08:00
|
|
|
return;
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
|
2007-03-06 04:01:30 +08:00
|
|
|
switch (S1) {
|
|
|
|
case EXECUTION_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "Executing Pass '" << P->getPassName();
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
case MODIFICATION_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "Made Modification '" << P->getPassName();
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
case FREEING_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << " Freeing Pass '" << P->getPassName();
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (S2) {
|
|
|
|
case ON_BASICBLOCK_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "' on BasicBlock '" << Msg << "'...\n";
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
case ON_FUNCTION_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "' on Function '" << Msg << "'...\n";
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
case ON_MODULE_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "' on Module '" << Msg << "'...\n";
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
2010-10-20 09:54:44 +08:00
|
|
|
case ON_REGION_MSG:
|
|
|
|
dbgs() << "' on Region '" << Msg << "'...\n";
|
|
|
|
break;
|
2007-03-06 04:01:30 +08:00
|
|
|
case ON_LOOP_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "' on Loop '" << Msg << "'...\n";
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
case ON_CG_MSG:
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
|
2007-03-06 04:01:30 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-12-16 04:13:01 +08:00
|
|
|
}
|
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
void PMDataManager::dumpRequiredSet(const Pass *P) const {
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging < Details)
|
2008-08-08 23:14:09 +08:00
|
|
|
return;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2008-08-08 23:14:09 +08:00
|
|
|
AnalysisUsage analysisUsage;
|
|
|
|
P->getAnalysisUsage(analysisUsage);
|
|
|
|
dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
|
|
|
|
}
|
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
void PMDataManager::dumpPreservedSet(const Pass *P) const {
|
2013-09-19 14:02:43 +08:00
|
|
|
if (PassDebugging < Details)
|
2008-08-08 23:14:09 +08:00
|
|
|
return;
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2008-08-08 23:14:09 +08:00
|
|
|
AnalysisUsage analysisUsage;
|
|
|
|
P->getAnalysisUsage(analysisUsage);
|
|
|
|
dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
|
|
|
|
}
|
|
|
|
|
2009-11-06 18:58:06 +08:00
|
|
|
void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
|
2009-03-06 14:45:05 +08:00
|
|
|
const AnalysisUsage::VectorType &Set) const {
|
2013-09-19 14:02:43 +08:00
|
|
|
assert(PassDebugging >= Details);
|
2008-08-08 23:14:09 +08:00
|
|
|
if (Set.empty())
|
|
|
|
return;
|
2012-09-06 06:26:57 +08:00
|
|
|
dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
|
2009-03-06 14:45:05 +08:00
|
|
|
for (unsigned i = 0; i != Set.size(); ++i) {
|
2010-01-05 09:30:02 +08:00
|
|
|
if (i) dbgs() << ',';
|
2010-08-07 02:33:48 +08:00
|
|
|
const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(Set[i]);
|
2011-06-03 08:48:58 +08:00
|
|
|
if (!PInf) {
|
|
|
|
// Some preserved passes, such as AliasAnalysis, may not be initialized by
|
|
|
|
// all drivers.
|
|
|
|
dbgs() << " Uninitialized Pass";
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-07 02:33:48 +08:00
|
|
|
dbgs() << ' ' << PInf->getPassName();
|
2009-03-06 14:45:05 +08:00
|
|
|
}
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << '\n';
|
2006-12-16 04:13:01 +08:00
|
|
|
}
|
2006-12-09 07:28:54 +08:00
|
|
|
|
2007-07-28 04:06:09 +08:00
|
|
|
/// Add RequiredPass into list of lower level passes required by pass P.
|
|
|
|
/// RequiredPass is run on the fly by Pass Manager when P requests it
|
|
|
|
/// through getAnalysis interface.
|
|
|
|
/// This should be handled by specific pass manager.
|
|
|
|
void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
|
|
|
|
if (TPM) {
|
|
|
|
TPM->dumpArguments();
|
|
|
|
TPM->dumpPasses();
|
|
|
|
}
|
2008-02-02 09:43:30 +08:00
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
// Module Level pass may required Function Level analysis info
|
|
|
|
// (e.g. dominator info). Pass manager uses on the fly function pass manager
|
|
|
|
// to provide this on demand. In that case, in Pass manager terminology,
|
2008-02-02 09:43:30 +08:00
|
|
|
// module level pass is requiring lower level analysis info managed by
|
|
|
|
// lower level pass manager.
|
|
|
|
|
|
|
|
// When Pass manager is not able to order required analysis info, Pass manager
|
2010-08-13 07:50:08 +08:00
|
|
|
// checks whether any lower level manager will be able to provide this
|
2008-02-02 09:43:30 +08:00
|
|
|
// analysis info on demand or not.
|
2008-06-03 09:20:02 +08:00
|
|
|
#ifndef NDEBUG
|
2010-01-05 09:30:02 +08:00
|
|
|
dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
|
|
|
|
dbgs() << "' required by '" << P->getPassName() << "'\n";
|
2008-06-03 09:20:02 +08:00
|
|
|
#endif
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("Unable to schedule pass");
|
2007-07-28 04:06:09 +08:00
|
|
|
}
|
|
|
|
|
2010-08-07 02:33:48 +08:00
|
|
|
Pass *PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F) {
|
2012-02-06 06:14:15 +08:00
|
|
|
llvm_unreachable("Unable to find on the fly pass");
|
2010-06-22 02:46:45 +08:00
|
|
|
}
|
|
|
|
|
2007-01-13 02:52:44 +08:00
|
|
|
// Destructor
|
|
|
|
PMDataManager::~PMDataManager() {
|
2010-10-12 08:11:18 +08:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = PassVector.begin(),
|
2007-01-13 02:52:44 +08:00
|
|
|
E = PassVector.end(); I != E; ++I)
|
|
|
|
delete *I;
|
|
|
|
}
|
|
|
|
|
2006-12-09 07:28:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NOTE: Is this the right place to define this method ?
|
2009-01-28 21:14:17 +08:00
|
|
|
// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
|
|
|
|
Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
|
2006-12-09 07:28:54 +08:00
|
|
|
return PM.findAnalysisPass(ID, dir);
|
|
|
|
}
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
Pass *AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI,
|
2007-04-17 04:56:24 +08:00
|
|
|
Function &F) {
|
|
|
|
return PM.getOnTheFlyPass(P, AnalysisPI, F);
|
|
|
|
}
|
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-20 03:46:59 +08:00
|
|
|
// BBPassManager implementation
|
2006-11-08 05:31:57 +08:00
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// Execute all of the passes scheduled for execution by invoking
|
|
|
|
/// runOnBasicBlock method. Keep track of whether any of the passes modifies
|
2006-11-08 05:31:57 +08:00
|
|
|
/// the function, and if so, return true.
|
2009-03-06 14:45:05 +08:00
|
|
|
bool BBPassManager::runOnFunction(Function &F) {
|
2007-01-31 04:08:39 +08:00
|
|
|
if (F.isDeclaration())
|
2006-12-13 07:15:28 +08:00
|
|
|
return false;
|
|
|
|
|
2006-12-08 09:38:28 +08:00
|
|
|
bool Changed = doInitialization(F);
|
2006-11-14 09:23:29 +08:00
|
|
|
|
2006-11-08 05:31:57 +08:00
|
|
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2010-03-02 01:34:28 +08:00
|
|
|
bool LocalChanged = false;
|
2006-12-14 08:25:06 +08:00
|
|
|
|
2009-07-26 15:49:05 +08:00
|
|
|
dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getName());
|
2008-08-08 23:14:09 +08:00
|
|
|
dumpRequiredSet(BP);
|
2006-12-14 08:25:06 +08:00
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
initializeAnalysisImpl(BP);
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
{
|
|
|
|
// If the pass crashes, remember this.
|
|
|
|
PassManagerPrettyStackEntry X(BP, *I);
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRegion PassTimer(getPassTimer(BP));
|
|
|
|
|
2010-03-02 01:34:28 +08:00
|
|
|
LocalChanged |= BP->runOnBasicBlock(*I);
|
2009-03-06 14:45:05 +08:00
|
|
|
}
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2010-03-02 01:34:28 +08:00
|
|
|
Changed |= LocalChanged;
|
2010-08-13 07:50:08 +08:00
|
|
|
if (LocalChanged)
|
2008-01-29 20:09:55 +08:00
|
|
|
dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
|
2009-07-26 15:49:05 +08:00
|
|
|
I->getName());
|
2008-08-08 23:14:09 +08:00
|
|
|
dumpPreservedSet(BP);
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2007-07-20 02:02:32 +08:00
|
|
|
verifyPreservedAnalysis(BP);
|
2006-12-16 08:56:26 +08:00
|
|
|
removeNotPreservedAnalysis(BP);
|
|
|
|
recordAvailableAnalysis(BP);
|
2009-07-26 15:49:05 +08:00
|
|
|
removeDeadPasses(BP, I->getName(), ON_BASICBLOCK_MSG);
|
2006-11-08 05:31:57 +08:00
|
|
|
}
|
2007-08-10 14:22:25 +08:00
|
|
|
|
2009-12-25 21:50:18 +08:00
|
|
|
return doFinalization(F) || Changed;
|
2006-11-08 05:31:57 +08:00
|
|
|
}
|
|
|
|
|
2006-12-08 08:59:05 +08:00
|
|
|
// Implement doInitialization and doFinalization
|
2009-02-13 17:42:34 +08:00
|
|
|
bool BBPassManager::doInitialization(Module &M) {
|
2006-12-08 08:59:05 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
|
|
|
|
Changed |= getContainedPass(Index)->doInitialization(M);
|
2006-12-08 08:59:05 +08:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:42:34 +08:00
|
|
|
bool BBPassManager::doFinalization(Module &M) {
|
2006-12-08 08:59:05 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2012-12-06 01:12:22 +08:00
|
|
|
for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
|
2009-03-06 14:45:05 +08:00
|
|
|
Changed |= getContainedPass(Index)->doFinalization(M);
|
2006-12-08 08:59:05 +08:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:42:34 +08:00
|
|
|
bool BBPassManager::doInitialization(Function &F) {
|
2006-12-08 08:59:05 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2006-12-08 08:59:05 +08:00
|
|
|
Changed |= BP->doInitialization(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:42:34 +08:00
|
|
|
bool BBPassManager::doFinalization(Function &F) {
|
2006-12-08 08:59:05 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2006-12-08 08:59:05 +08:00
|
|
|
Changed |= BP->doFinalization(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-13 10:36:01 +08:00
|
|
|
// FunctionPassManager implementation
|
2006-12-08 03:39:39 +08:00
|
|
|
|
2006-11-08 18:44:40 +08:00
|
|
|
/// Create new Function pass manager
|
2010-01-28 04:34:15 +08:00
|
|
|
FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
|
2011-08-30 01:07:00 +08:00
|
|
|
FPM = new FunctionPassManagerImpl();
|
2006-12-13 06:02:16 +08:00
|
|
|
// FPM is the top level manager.
|
|
|
|
FPM->setTopLevelManager(FPM);
|
2006-12-13 07:27:37 +08:00
|
|
|
|
2008-03-13 10:08:36 +08:00
|
|
|
AnalysisResolver *AR = new AnalysisResolver(*FPM);
|
2006-12-13 07:27:37 +08:00
|
|
|
FPM->setResolver(AR);
|
2006-12-09 02:57:16 +08:00
|
|
|
}
|
|
|
|
|
2006-12-13 10:36:01 +08:00
|
|
|
FunctionPassManager::~FunctionPassManager() {
|
2006-12-13 08:09:23 +08:00
|
|
|
delete FPM;
|
|
|
|
}
|
|
|
|
|
2006-11-08 18:44:40 +08:00
|
|
|
/// add - Add a pass to the queue of passes to run. This passes
|
|
|
|
/// ownership of the Pass to the PassManager. When the
|
|
|
|
/// PassManager_X is destroyed, the pass will be destroyed as well, so
|
|
|
|
/// there is no need to delete the pass. (TODO delete passes.)
|
|
|
|
/// This implies that all passes MUST be allocated with 'new'.
|
2010-08-13 07:50:08 +08:00
|
|
|
void FunctionPassManager::add(Pass *P) {
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
FPM->add(P);
|
2006-11-08 18:44:40 +08:00
|
|
|
}
|
|
|
|
|
2006-11-16 03:39:54 +08:00
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep
|
|
|
|
/// track of whether any of the passes modifies the function, and if
|
|
|
|
/// so, return true.
|
|
|
|
///
|
2006-12-13 10:36:01 +08:00
|
|
|
bool FunctionPassManager::run(Function &F) {
|
2010-02-16 05:27:56 +08:00
|
|
|
if (F.isMaterializable()) {
|
|
|
|
std::string errstr;
|
2010-04-08 06:41:29 +08:00
|
|
|
if (F.Materialize(&errstr))
|
2010-04-08 18:44:28 +08:00
|
|
|
report_fatal_error("Error reading bitcode file: " + Twine(errstr));
|
2006-11-16 03:39:54 +08:00
|
|
|
}
|
2006-12-09 06:57:48 +08:00
|
|
|
return FPM->run(F);
|
2006-11-16 03:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-15 09:27:05 +08:00
|
|
|
/// doInitialization - Run all of the initializers for the function passes.
|
|
|
|
///
|
2006-12-13 10:36:01 +08:00
|
|
|
bool FunctionPassManager::doInitialization() {
|
2010-01-28 04:34:15 +08:00
|
|
|
return FPM->doInitialization(*M);
|
2006-11-15 09:27:05 +08:00
|
|
|
}
|
|
|
|
|
2007-07-30 22:51:13 +08:00
|
|
|
/// doFinalization - Run all of the finalizers for the function passes.
|
2006-11-15 09:27:05 +08:00
|
|
|
///
|
2006-12-13 10:36:01 +08:00
|
|
|
bool FunctionPassManager::doFinalization() {
|
2010-01-28 04:34:15 +08:00
|
|
|
return FPM->doFinalization(*M);
|
2006-11-15 09:27:05 +08:00
|
|
|
}
|
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-20 03:46:59 +08:00
|
|
|
// FunctionPassManagerImpl implementation
|
|
|
|
//
|
2009-02-13 17:42:34 +08:00
|
|
|
bool FunctionPassManagerImpl::doInitialization(Module &M) {
|
2006-12-20 03:46:59 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2009-11-24 00:24:18 +08:00
|
|
|
dumpArguments();
|
|
|
|
dumpPasses();
|
|
|
|
|
2012-12-06 01:12:22 +08:00
|
|
|
SmallVectorImpl<ImmutablePass *>& IPV = getImmutablePasses();
|
|
|
|
for (SmallVectorImpl<ImmutablePass *>::const_iterator I = IPV.begin(),
|
|
|
|
E = IPV.end(); I != E; ++I) {
|
|
|
|
Changed |= (*I)->doInitialization(M);
|
|
|
|
}
|
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
|
|
|
Changed |= getContainedManager(Index)->doInitialization(M);
|
2006-12-20 03:46:59 +08:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:42:34 +08:00
|
|
|
bool FunctionPassManagerImpl::doFinalization(Module &M) {
|
2006-12-20 03:46:59 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2012-12-06 01:12:22 +08:00
|
|
|
for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
|
2009-03-06 14:45:05 +08:00
|
|
|
Changed |= getContainedManager(Index)->doFinalization(M);
|
2006-12-20 03:46:59 +08:00
|
|
|
|
2012-12-06 01:12:22 +08:00
|
|
|
SmallVectorImpl<ImmutablePass *>& IPV = getImmutablePasses();
|
|
|
|
for (SmallVectorImpl<ImmutablePass *>::const_iterator I = IPV.begin(),
|
|
|
|
E = IPV.end(); I != E; ++I) {
|
|
|
|
Changed |= (*I)->doFinalization(M);
|
|
|
|
}
|
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-04-02 06:34:41 +08:00
|
|
|
/// cleanup - After running all passes, clean up pass manager cache.
|
|
|
|
void FPPassManager::cleanup() {
|
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
FunctionPass *FP = getContainedPass(Index);
|
|
|
|
AnalysisResolver *AR = FP->getResolver();
|
|
|
|
assert(AR && "Analysis Resolver is not set");
|
|
|
|
AR->clearAnalysisImpls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 02:49:09 +08:00
|
|
|
void FunctionPassManagerImpl::releaseMemoryOnTheFly() {
|
|
|
|
if (!wasRun)
|
|
|
|
return;
|
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
|
|
|
FPPassManager *FPPM = getContainedManager(Index);
|
|
|
|
for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
|
|
|
|
FPPM->getContainedPass(Index)->releaseMemory();
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 05:05:10 +08:00
|
|
|
wasRun = false;
|
2009-06-30 02:49:09 +08:00
|
|
|
}
|
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
// Execute all the passes managed by this top level manager.
|
|
|
|
// Return true if any function is modified by a pass.
|
|
|
|
bool FunctionPassManagerImpl::run(Function &F) {
|
|
|
|
bool Changed = false;
|
|
|
|
TimingInfo::createTheTimeInfo();
|
|
|
|
|
2006-12-21 08:16:50 +08:00
|
|
|
initializeAllAnalysisInfo();
|
2009-03-06 14:45:05 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
|
|
|
Changed |= getContainedManager(Index)->runOnFunction(F);
|
2009-04-02 06:34:41 +08:00
|
|
|
|
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
|
|
|
getContainedManager(Index)->cleanup();
|
|
|
|
|
2009-06-30 02:49:09 +08:00
|
|
|
wasRun = true;
|
2006-12-20 03:46:59 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPPassManager implementation
|
2006-11-08 05:49:50 +08:00
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char FPPassManager::ID = 0;
|
2007-01-13 02:52:44 +08:00
|
|
|
/// Print passes managed by this manager
|
|
|
|
void FPPassManager::dumpPassStructure(unsigned Offset) {
|
2011-10-17 00:30:34 +08:00
|
|
|
dbgs().indent(Offset*2) << "FunctionPass Manager\n";
|
2007-01-13 02:52:44 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
FunctionPass *FP = getContainedPass(Index);
|
2010-08-19 09:29:07 +08:00
|
|
|
FP->dumpPassStructure(Offset + 1);
|
2007-01-13 02:52:44 +08:00
|
|
|
dumpLastUses(FP, Offset+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// Execute all of the passes scheduled for execution by invoking
|
|
|
|
/// runOnFunction method. Keep track of whether any of the passes modifies
|
2006-11-08 05:49:50 +08:00
|
|
|
/// the function, and if so, return true.
|
2006-12-20 03:46:59 +08:00
|
|
|
bool FPPassManager::runOnFunction(Function &F) {
|
2009-03-06 13:53:14 +08:00
|
|
|
if (F.isDeclaration())
|
|
|
|
return false;
|
2006-11-16 03:39:54 +08:00
|
|
|
|
|
|
|
bool Changed = false;
|
2006-12-13 07:15:28 +08:00
|
|
|
|
2008-03-20 09:09:53 +08:00
|
|
|
// Collect inherited analysis from Module level pass manager.
|
|
|
|
populateInheritedAnalysis(TPM->activeStack);
|
2006-12-13 07:15:28 +08:00
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
FunctionPass *FP = getContainedPass(Index);
|
2010-03-02 01:34:28 +08:00
|
|
|
bool LocalChanged = false;
|
2006-12-16 08:56:26 +08:00
|
|
|
|
2009-07-26 15:49:05 +08:00
|
|
|
dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
|
2008-08-08 23:14:09 +08:00
|
|
|
dumpRequiredSet(FP);
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
initializeAnalysisImpl(FP);
|
2012-03-23 11:54:05 +08:00
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
{
|
|
|
|
PassManagerPrettyStackEntry X(FP, F);
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRegion PassTimer(getPassTimer(FP));
|
2009-03-06 14:45:05 +08:00
|
|
|
|
2010-03-02 01:34:28 +08:00
|
|
|
LocalChanged |= FP->runOnFunction(F);
|
2009-03-06 14:45:05 +08:00
|
|
|
}
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2010-03-02 01:34:28 +08:00
|
|
|
Changed |= LocalChanged;
|
|
|
|
if (LocalChanged)
|
2009-07-26 15:49:05 +08:00
|
|
|
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
|
2008-08-08 23:14:09 +08:00
|
|
|
dumpPreservedSet(FP);
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2007-07-20 02:02:32 +08:00
|
|
|
verifyPreservedAnalysis(FP);
|
2006-12-16 08:56:26 +08:00
|
|
|
removeNotPreservedAnalysis(FP);
|
|
|
|
recordAvailableAnalysis(FP);
|
2009-07-26 15:49:05 +08:00
|
|
|
removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
|
2006-11-16 03:39:54 +08:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2006-12-20 03:46:59 +08:00
|
|
|
bool FPPassManager::runOnModule(Module &M) {
|
2012-11-30 01:47:05 +08:00
|
|
|
bool Changed = false;
|
2006-12-20 03:46:59 +08:00
|
|
|
|
2010-05-12 04:30:00 +08:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
2011-08-09 07:01:10 +08:00
|
|
|
Changed |= runOnFunction(*I);
|
2006-12-20 03:46:59 +08:00
|
|
|
|
2012-11-30 01:47:05 +08:00
|
|
|
return Changed;
|
2006-12-20 03:46:59 +08:00
|
|
|
}
|
|
|
|
|
2009-02-13 17:42:34 +08:00
|
|
|
bool FPPassManager::doInitialization(Module &M) {
|
2006-11-15 09:27:05 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
|
|
|
|
Changed |= getContainedPass(Index)->doInitialization(M);
|
2013-09-19 07:31:10 +08:00
|
|
|
|
2006-11-15 09:27:05 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:42:34 +08:00
|
|
|
bool FPPassManager::doFinalization(Module &M) {
|
2006-11-15 09:27:05 +08:00
|
|
|
bool Changed = false;
|
2012-12-06 01:12:22 +08:00
|
|
|
|
|
|
|
for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
|
2009-03-06 14:45:05 +08:00
|
|
|
Changed |= getContainedPass(Index)->doFinalization(M);
|
2013-09-19 07:31:10 +08:00
|
|
|
|
2006-11-15 09:27:05 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-20 03:46:59 +08:00
|
|
|
// MPPassManager implementation
|
2006-11-08 06:03:15 +08:00
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// Execute all of the passes scheduled for execution by invoking
|
|
|
|
/// runOnModule method. Keep track of whether any of the passes modifies
|
2006-11-08 06:03:15 +08:00
|
|
|
/// the module, and if so, return true.
|
|
|
|
bool
|
2006-12-20 03:46:59 +08:00
|
|
|
MPPassManager::runOnModule(Module &M) {
|
2006-11-08 06:03:15 +08:00
|
|
|
bool Changed = false;
|
2006-11-14 09:23:29 +08:00
|
|
|
|
2009-06-30 02:49:09 +08:00
|
|
|
// Initialize on-the-fly passes
|
|
|
|
for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
|
|
|
|
I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
FunctionPassManagerImpl *FPP = I->second;
|
|
|
|
Changed |= FPP->doInitialization(M);
|
|
|
|
}
|
|
|
|
|
2012-11-30 01:47:05 +08:00
|
|
|
// Initialize module passes
|
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
|
|
|
|
Changed |= getContainedPass(Index)->doInitialization(M);
|
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
ModulePass *MP = getContainedPass(Index);
|
2010-03-02 01:34:28 +08:00
|
|
|
bool LocalChanged = false;
|
2006-12-16 08:56:26 +08:00
|
|
|
|
2009-12-08 21:07:38 +08:00
|
|
|
dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
|
2008-08-08 23:14:09 +08:00
|
|
|
dumpRequiredSet(MP);
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2006-12-16 08:56:26 +08:00
|
|
|
initializeAnalysisImpl(MP);
|
2006-12-14 08:59:42 +08:00
|
|
|
|
2009-03-06 14:45:05 +08:00
|
|
|
{
|
|
|
|
PassManagerPrettyStackEntry X(MP, M);
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRegion PassTimer(getPassTimer(MP));
|
|
|
|
|
2010-03-02 01:34:28 +08:00
|
|
|
LocalChanged |= MP->runOnModule(M);
|
2009-03-06 14:45:05 +08:00
|
|
|
}
|
2006-12-14 08:08:04 +08:00
|
|
|
|
2010-03-02 01:34:28 +08:00
|
|
|
Changed |= LocalChanged;
|
|
|
|
if (LocalChanged)
|
2008-01-29 20:09:55 +08:00
|
|
|
dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
|
2009-12-08 21:07:38 +08:00
|
|
|
M.getModuleIdentifier());
|
2008-08-08 23:14:09 +08:00
|
|
|
dumpPreservedSet(MP);
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2007-07-20 02:02:32 +08:00
|
|
|
verifyPreservedAnalysis(MP);
|
2006-12-16 08:56:26 +08:00
|
|
|
removeNotPreservedAnalysis(MP);
|
|
|
|
recordAvailableAnalysis(MP);
|
2009-12-08 21:07:38 +08:00
|
|
|
removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
|
2006-11-08 06:03:15 +08:00
|
|
|
}
|
2009-06-30 02:49:09 +08:00
|
|
|
|
2012-11-30 01:47:05 +08:00
|
|
|
// Finalize module passes
|
2012-12-06 01:12:22 +08:00
|
|
|
for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
|
2012-11-30 01:47:05 +08:00
|
|
|
Changed |= getContainedPass(Index)->doFinalization(M);
|
|
|
|
|
2009-06-30 02:49:09 +08:00
|
|
|
// Finalize on-the-fly passes
|
|
|
|
for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
|
|
|
|
I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
FunctionPassManagerImpl *FPP = I->second;
|
|
|
|
// We don't know when is the last time an on-the-fly pass is run,
|
|
|
|
// so we need to releaseMemory / finalize here
|
|
|
|
FPP->releaseMemoryOnTheFly();
|
|
|
|
Changed |= FPP->doFinalization(M);
|
|
|
|
}
|
2013-09-19 07:31:10 +08:00
|
|
|
|
2006-11-08 06:03:15 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2007-04-17 04:12:57 +08:00
|
|
|
/// Add RequiredPass into list of lower level passes required by pass P.
|
|
|
|
/// RequiredPass is run on the fly by Pass Manager when P requests it
|
|
|
|
/// through getAnalysis interface.
|
|
|
|
void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
|
|
|
|
"Unable to handle Pass that requires lower level Analysis pass");
|
2010-08-13 07:50:08 +08:00
|
|
|
assert((P->getPotentialPassManagerType() <
|
2009-03-06 13:53:14 +08:00
|
|
|
RequiredPass->getPotentialPassManagerType()) &&
|
|
|
|
"Unable to handle Pass that requires lower level Analysis pass");
|
2007-04-17 04:12:57 +08:00
|
|
|
|
2007-04-27 01:50:19 +08:00
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
|
2007-04-17 04:27:05 +08:00
|
|
|
if (!FPP) {
|
2011-08-30 01:07:00 +08:00
|
|
|
FPP = new FunctionPassManagerImpl();
|
2007-04-27 01:50:19 +08:00
|
|
|
// FPP is the top level manager.
|
|
|
|
FPP->setTopLevelManager(FPP);
|
|
|
|
|
2007-04-17 04:27:05 +08:00
|
|
|
OnTheFlyManagers[P] = FPP;
|
|
|
|
}
|
2007-04-27 01:50:19 +08:00
|
|
|
FPP->add(RequiredPass);
|
2007-04-17 04:27:05 +08:00
|
|
|
|
2007-04-27 01:50:19 +08:00
|
|
|
// Register P as the last user of RequiredPass.
|
2011-09-14 05:13:29 +08:00
|
|
|
if (RequiredPass) {
|
|
|
|
SmallVector<Pass *, 1> LU;
|
|
|
|
LU.push_back(RequiredPass);
|
|
|
|
FPP->setLastUser(LU, P);
|
|
|
|
}
|
2007-04-17 04:12:57 +08:00
|
|
|
}
|
2007-04-17 04:27:05 +08:00
|
|
|
|
2010-08-13 07:50:08 +08:00
|
|
|
/// Return function pass corresponding to PassInfo PI, that is
|
2007-04-17 04:27:05 +08:00
|
|
|
/// required by module pass MP. Instantiate analysis pass, by using
|
|
|
|
/// its runOnFunction() for function F.
|
2010-08-07 02:33:48 +08:00
|
|
|
Pass* MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F){
|
2007-04-27 01:50:19 +08:00
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(FPP && "Unable to find on the fly pass");
|
2010-08-13 07:50:08 +08:00
|
|
|
|
2009-06-30 02:49:09 +08:00
|
|
|
FPP->releaseMemoryOnTheFly();
|
2007-04-27 01:50:19 +08:00
|
|
|
FPP->run(F);
|
2010-01-22 13:37:10 +08:00
|
|
|
return ((PMTopLevelManager*)FPP)->findAnalysisPass(PI);
|
2007-04-17 04:27:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManagerImpl implementation
|
2012-11-15 08:14:15 +08:00
|
|
|
|
2006-12-13 08:09:23 +08:00
|
|
|
//
|
2006-11-08 06:23:34 +08:00
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
2006-12-20 03:46:59 +08:00
|
|
|
bool PassManagerImpl::run(Module &M) {
|
2006-11-08 06:23:34 +08:00
|
|
|
bool Changed = false;
|
2006-12-14 08:59:42 +08:00
|
|
|
TimingInfo::createTheTimeInfo();
|
|
|
|
|
2006-12-14 06:10:00 +08:00
|
|
|
dumpArguments();
|
2006-12-20 03:46:59 +08:00
|
|
|
dumpPasses();
|
2006-12-14 04:03:48 +08:00
|
|
|
|
2012-12-06 01:12:22 +08:00
|
|
|
SmallVectorImpl<ImmutablePass *>& IPV = getImmutablePasses();
|
|
|
|
for (SmallVectorImpl<ImmutablePass *>::const_iterator I = IPV.begin(),
|
|
|
|
E = IPV.end(); I != E; ++I) {
|
|
|
|
Changed |= (*I)->doInitialization(M);
|
|
|
|
}
|
|
|
|
|
2006-12-21 08:16:50 +08:00
|
|
|
initializeAllAnalysisInfo();
|
2009-03-06 14:45:05 +08:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
|
|
|
Changed |= getContainedManager(Index)->runOnModule(M);
|
2012-12-06 01:12:22 +08:00
|
|
|
|
|
|
|
for (SmallVectorImpl<ImmutablePass *>::const_iterator I = IPV.begin(),
|
|
|
|
E = IPV.end(); I != E; ++I) {
|
|
|
|
Changed |= (*I)->doFinalization(M);
|
|
|
|
}
|
|
|
|
|
2006-11-08 06:23:34 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
2006-11-08 18:29:57 +08:00
|
|
|
|
2006-12-08 03:39:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManager implementation
|
|
|
|
|
2006-11-08 18:29:57 +08:00
|
|
|
/// Create new pass manager
|
2006-12-13 10:36:01 +08:00
|
|
|
PassManager::PassManager() {
|
2011-08-30 01:07:00 +08:00
|
|
|
PM = new PassManagerImpl();
|
2006-12-13 06:02:16 +08:00
|
|
|
// PM is the top level manager
|
|
|
|
PM->setTopLevelManager(PM);
|
2006-11-08 18:29:57 +08:00
|
|
|
}
|
|
|
|
|
2006-12-13 10:36:01 +08:00
|
|
|
PassManager::~PassManager() {
|
2006-12-13 08:09:23 +08:00
|
|
|
delete PM;
|
|
|
|
}
|
|
|
|
|
2006-11-08 18:29:57 +08:00
|
|
|
/// add - Add a pass to the queue of passes to run. This passes ownership of
|
|
|
|
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
|
|
|
|
/// will be destroyed as well, so there is no need to delete the pass. This
|
|
|
|
/// implies that all passes MUST be allocated with 'new'.
|
2009-03-06 13:53:14 +08:00
|
|
|
void PassManager::add(Pass *P) {
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
PM->add(P);
|
2006-11-08 18:29:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// run - Execute all of the passes scheduled for execution. Keep track of
|
|
|
|
/// whether any of the passes modifies the module, and if so, return true.
|
2009-03-06 13:53:14 +08:00
|
|
|
bool PassManager::run(Module &M) {
|
2006-11-08 18:29:57 +08:00
|
|
|
return PM->run(M);
|
|
|
|
}
|
|
|
|
|
2006-12-14 08:59:42 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2013-04-03 23:33:45 +08:00
|
|
|
// TimingInfo implementation
|
|
|
|
|
2013-09-19 14:02:43 +08:00
|
|
|
bool llvm::TimePassesIsEnabled = false;
|
|
|
|
static cl::opt<bool,true>
|
|
|
|
EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
|
|
|
|
cl::desc("Time each pass, printing elapsed time for each on exit"));
|
|
|
|
|
2006-12-14 08:59:42 +08:00
|
|
|
// createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
|
2013-12-05 13:44:44 +08:00
|
|
|
// a non-null value (if the -time-passes option is enabled) or it leaves it
|
2006-12-14 08:59:42 +08:00
|
|
|
// null. It may be called multiple times.
|
|
|
|
void TimingInfo::createTheTimeInfo() {
|
|
|
|
if (!TimePassesIsEnabled || TheTimeInfo) return;
|
|
|
|
|
2012-09-27 18:14:43 +08:00
|
|
|
// Constructed the first time this is called, iff -time-passes is enabled.
|
2006-12-14 08:59:42 +08:00
|
|
|
// This guarantees that the object will be constructed before static globals,
|
|
|
|
// thus it will be destroyed before them.
|
|
|
|
static ManagedStatic<TimingInfo> TTI;
|
|
|
|
TheTimeInfo = &*TTI;
|
|
|
|
}
|
|
|
|
|
2007-01-30 07:10:37 +08:00
|
|
|
/// If TimingInfo is enabled then start pass timer.
|
2010-03-30 12:03:22 +08:00
|
|
|
Timer *llvm::getPassTimer(Pass *P) {
|
2010-08-13 07:50:08 +08:00
|
|
|
if (TheTimeInfo)
|
2010-03-30 12:03:22 +08:00
|
|
|
return TheTimeInfo->getPassTimer(P);
|
2009-09-28 08:07:05 +08:00
|
|
|
return 0;
|
2007-01-30 07:10:37 +08:00
|
|
|
}
|
|
|
|
|
2007-01-09 03:29:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PMStack implementation
|
|
|
|
//
|
2007-01-12 06:15:30 +08:00
|
|
|
|
2007-01-09 03:29:38 +08:00
|
|
|
// Pop Pass Manager from the stack and clear its analysis info.
|
|
|
|
void PMStack::pop() {
|
|
|
|
|
|
|
|
PMDataManager *Top = this->top();
|
|
|
|
Top->initializeAnalysisInfo();
|
|
|
|
|
|
|
|
S.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push PM on the stack and set its top level manager.
|
2008-03-13 09:21:31 +08:00
|
|
|
void PMStack::push(PMDataManager *PM) {
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(PM && "Unable to push. Pass Manager expected");
|
2011-08-30 01:07:00 +08:00
|
|
|
assert(PM->getDepth()==0 && "Pass Manager depth set too early");
|
2007-01-09 03:29:38 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
if (!this->empty()) {
|
2011-08-30 01:07:00 +08:00
|
|
|
assert(PM->getPassManagerType() > this->top()->getPassManagerType()
|
|
|
|
&& "pushing bad pass manager to PMStack");
|
2009-03-06 13:53:14 +08:00
|
|
|
PMTopLevelManager *TPM = this->top()->getTopLevelManager();
|
2007-01-11 08:19:00 +08:00
|
|
|
|
2009-03-06 13:53:14 +08:00
|
|
|
assert(TPM && "Unable to find top level manager");
|
2007-01-11 08:19:00 +08:00
|
|
|
TPM->addIndirectPassManager(PM);
|
|
|
|
PM->setTopLevelManager(TPM);
|
2011-08-30 01:07:00 +08:00
|
|
|
PM->setDepth(this->top()->getDepth()+1);
|
2013-02-06 14:50:38 +08:00
|
|
|
} else {
|
2011-08-30 02:14:15 +08:00
|
|
|
assert((PM->getPassManagerType() == PMT_ModulePassManager
|
|
|
|
|| PM->getPassManagerType() == PMT_FunctionPassManager)
|
2011-08-30 01:07:00 +08:00
|
|
|
&& "pushing bad pass manager to PMStack");
|
|
|
|
PM->setDepth(1);
|
2007-01-11 08:19:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
S.push_back(PM);
|
|
|
|
}
|
2007-01-09 03:29:38 +08:00
|
|
|
|
2007-01-11 08:19:00 +08:00
|
|
|
// Dump content of the pass manager stack.
|
2010-08-07 09:04:15 +08:00
|
|
|
void PMStack::dump() const {
|
|
|
|
for (std::vector<PMDataManager *>::const_iterator I = S.begin(),
|
2009-03-06 13:53:14 +08:00
|
|
|
E = S.end(); I != E; ++I)
|
2011-08-30 02:14:17 +08:00
|
|
|
dbgs() << (*I)->getAsPass()->getPassName() << ' ';
|
2009-03-06 13:53:14 +08:00
|
|
|
|
2007-01-11 08:19:00 +08:00
|
|
|
if (!S.empty())
|
2011-08-30 02:14:17 +08:00
|
|
|
dbgs() << '\n';
|
2007-01-09 03:29:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Find appropriate Module Pass Manager in the PM Stack and
|
2010-08-13 07:50:08 +08:00
|
|
|
/// add self into that manager.
|
|
|
|
void ModulePass::assignPassManager(PMStack &PMS,
|
2007-04-17 02:10:23 +08:00
|
|
|
PassManagerType PreferredType) {
|
2007-01-09 03:29:38 +08:00
|
|
|
// Find Module Pass Manager
|
2010-08-13 07:50:08 +08:00
|
|
|
while (!PMS.empty()) {
|
2007-01-18 05:19:23 +08:00
|
|
|
PassManagerType TopPMType = PMS.top()->getPassManagerType();
|
|
|
|
if (TopPMType == PreferredType)
|
|
|
|
break; // We found desired pass manager
|
|
|
|
else if (TopPMType > PMT_ModulePassManager)
|
2007-01-09 03:29:38 +08:00
|
|
|
PMS.pop(); // Pop children pass managers
|
2007-01-12 03:59:06 +08:00
|
|
|
else
|
|
|
|
break;
|
2007-01-09 03:29:38 +08:00
|
|
|
}
|
2008-09-10 05:38:40 +08:00
|
|
|
assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
|
2007-01-18 05:19:23 +08:00
|
|
|
PMS.top()->add(this);
|
2007-01-09 03:29:38 +08:00
|
|
|
}
|
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
/// Find appropriate Function Pass Manager or Call Graph Pass Manager
|
2010-08-13 07:50:08 +08:00
|
|
|
/// in the PM Stack and add self into that manager.
|
2007-01-18 04:30:17 +08:00
|
|
|
void FunctionPass::assignPassManager(PMStack &PMS,
|
2007-04-17 02:10:23 +08:00
|
|
|
PassManagerType PreferredType) {
|
2007-01-09 03:29:38 +08:00
|
|
|
|
Add pass printer passes in the right place.
The pass pointer should never be referenced after sending it to
schedulePass(), which may delete the pass. To fix this bug I had to
clean up the design leading to more goodness.
You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two.
The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed.
llvm-svn: 149480
2012-02-01 15:16:20 +08:00
|
|
|
// Find Function Pass Manager
|
2010-01-22 13:37:10 +08:00
|
|
|
while (!PMS.empty()) {
|
2007-01-12 03:59:06 +08:00
|
|
|
if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
|
|
|
|
PMS.pop();
|
2007-01-09 03:29:38 +08:00
|
|
|
else
|
2010-08-13 07:50:08 +08:00
|
|
|
break;
|
2007-01-09 03:29:38 +08:00
|
|
|
}
|
|
|
|
|
2010-01-22 13:37:10 +08:00
|
|
|
// Create new Function Pass Manager if needed.
|
|
|
|
FPPassManager *FPP;
|
|
|
|
if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
|
|
|
|
FPP = (FPPassManager *)PMS.top();
|
|
|
|
} else {
|
2007-01-17 05:43:18 +08:00
|
|
|
assert(!PMS.empty() && "Unable to create Function Pass Manager");
|
|
|
|
PMDataManager *PMD = PMS.top();
|
2007-01-11 08:19:00 +08:00
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// [1] Create new Function Pass Manager
|
2011-08-30 01:07:00 +08:00
|
|
|
FPP = new FPPassManager();
|
2008-03-20 09:09:53 +08:00
|
|
|
FPP->populateInheritedAnalysis(PMS);
|
2007-01-11 08:19:00 +08:00
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// [2] Set up new manager's top level manager
|
|
|
|
PMTopLevelManager *TPM = PMD->getTopLevelManager();
|
|
|
|
TPM->addIndirectPassManager(FPP);
|
2007-01-11 08:19:00 +08:00
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// [3] Assign manager to manage this new manager. This may create
|
|
|
|
// and push new managers into PMS
|
2008-09-10 01:56:50 +08:00
|
|
|
FPP->assignPassManager(PMS, PMD->getPassManagerType());
|
2007-01-17 05:43:18 +08:00
|
|
|
|
|
|
|
// [4] Push new manager into PMS
|
|
|
|
PMS.push(FPP);
|
|
|
|
}
|
2007-01-09 03:29:38 +08:00
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// Assign FPP as the manager of this pass.
|
|
|
|
FPP->add(this);
|
2007-01-09 03:29:38 +08:00
|
|
|
}
|
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
/// Find appropriate Basic Pass Manager or Call Graph Pass Manager
|
2010-08-13 07:50:08 +08:00
|
|
|
/// in the PM Stack and add self into that manager.
|
2007-01-18 04:30:17 +08:00
|
|
|
void BasicBlockPass::assignPassManager(PMStack &PMS,
|
2007-04-17 02:10:23 +08:00
|
|
|
PassManagerType PreferredType) {
|
2010-01-22 13:37:10 +08:00
|
|
|
BBPassManager *BBP;
|
2007-01-09 03:29:38 +08:00
|
|
|
|
2007-01-11 08:19:00 +08:00
|
|
|
// Basic Pass Manager is a leaf pass manager. It does not handle
|
|
|
|
// any other pass manager.
|
2010-08-13 07:50:08 +08:00
|
|
|
if (!PMS.empty() &&
|
2010-01-22 13:37:10 +08:00
|
|
|
PMS.top()->getPassManagerType() == PMT_BasicBlockPassManager) {
|
|
|
|
BBP = (BBPassManager *)PMS.top();
|
|
|
|
} else {
|
|
|
|
// If leaf manager is not Basic Block Pass manager then create new
|
|
|
|
// basic Block Pass manager.
|
2007-01-17 05:43:18 +08:00
|
|
|
assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
|
|
|
|
PMDataManager *PMD = PMS.top();
|
|
|
|
|
|
|
|
// [1] Create new Basic Block Manager
|
2011-08-30 01:07:00 +08:00
|
|
|
BBP = new BBPassManager();
|
2007-01-17 05:43:18 +08:00
|
|
|
|
|
|
|
// [2] Set up new manager's top level manager
|
|
|
|
// Basic Block Pass Manager does not live by itself
|
|
|
|
PMTopLevelManager *TPM = PMD->getTopLevelManager();
|
|
|
|
TPM->addIndirectPassManager(BBP);
|
2007-01-11 08:19:00 +08:00
|
|
|
|
|
|
|
// [3] Assign manager to manage this new manager. This may create
|
|
|
|
// and push new managers into PMS
|
2010-05-11 04:24:27 +08:00
|
|
|
BBP->assignPassManager(PMS, PreferredType);
|
2007-01-17 03:46:09 +08:00
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// [4] Push new manager into PMS
|
|
|
|
PMS.push(BBP);
|
|
|
|
}
|
2007-01-09 03:29:38 +08:00
|
|
|
|
2007-01-17 05:43:18 +08:00
|
|
|
// Assign BBP as the manager of this pass.
|
|
|
|
BBP->add(this);
|
2007-01-09 03:29:38 +08:00
|
|
|
}
|
|
|
|
|
2008-03-12 00:41:42 +08:00
|
|
|
PassManagerBase::~PassManagerBase() {}
|