2013-11-09 12:26:54 +00:00
|
|
|
//===- LegacyPassManager.cpp - LLVM Pass Infrastructure Implementation ----===//
|
2006-11-07 21:31:57 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-11-07 21:31:57 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2013-11-09 12:26:54 +00:00
|
|
|
// This file implements the legacy LLVM Pass Manager infrastructure.
|
2006-11-07 21:31:57 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
2014-05-16 02:33:15 +00:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2014-01-12 11:10:32 +00:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2013-11-09 12:26:54 +00:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
|
|
#include "llvm/IR/LegacyPassManagers.h"
|
2014-03-04 12:32:42 +00:00
|
|
|
#include "llvm/IR/LegacyPassNameParser.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2006-12-13 20:03:48 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2010-01-05 01:30:02 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 18:01:40 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2006-12-14 00:59:42 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/Mutex.h"
|
2014-04-27 23:59:25 +00:00
|
|
|
#include "llvm/Support/TimeValue.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/Timer.h"
|
2009-03-06 06:45:05 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-03-05 00:00:42 +00:00
|
|
|
#include <algorithm>
|
2006-11-14 01:59:59 +00:00
|
|
|
#include <map>
|
2016-01-06 22:55:03 +00:00
|
|
|
#include <unordered_set>
|
2007-10-03 19:04:09 +00:00
|
|
|
using namespace llvm;
|
2013-11-09 12:26:54 +00:00
|
|
|
using namespace llvm::legacy;
|
2006-12-15 19:39:30 +00:00
|
|
|
|
2007-01-12 18:52:44 +00:00
|
|
|
// See PassManagers.h for Pass Manager infrastructure overview.
|
2006-12-07 18:23:30 +00:00
|
|
|
|
2006-12-13 20:03:48 +00: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 12:26:54 +00:00
|
|
|
namespace {
|
2006-12-13 21:13:31 +00:00
|
|
|
// Different debug levels that can be enabled...
|
|
|
|
enum PassDebugLevel {
|
2013-05-05 00:40:33 +00:00
|
|
|
Disabled, Arguments, Structure, Executions, Details
|
2006-12-13 21:13:31 +00:00
|
|
|
};
|
2013-11-09 12:26:54 +00:00
|
|
|
}
|
2006-12-13 21:13:31 +00:00
|
|
|
|
2013-09-19 06:02:43 +00:00
|
|
|
static cl::opt<enum PassDebugLevel>
|
|
|
|
PassDebugging("debug-pass", cl::Hidden,
|
2006-12-13 20:03:48 +00:00
|
|
|
cl::desc("Print PassManager debugging information"),
|
|
|
|
cl::values(
|
2013-09-19 06:02:43 +00: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 12:26:54 +00:00
|
|
|
namespace {
|
2013-09-19 06:02:43 +00:00
|
|
|
typedef llvm::cl::list<const llvm::PassInfo *, bool, PassNameParser>
|
|
|
|
PassOptionList;
|
2013-11-09 12:26:54 +00:00
|
|
|
}
|
2013-09-19 06:02:43 +00: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));
|
|
|
|
|
2016-01-06 22:55:03 +00:00
|
|
|
static cl::list<std::string>
|
|
|
|
PrintFuncsList("filter-print-funcs", cl::value_desc("function names"),
|
|
|
|
cl::desc("Only print IR for functions whose name "
|
|
|
|
"match this for all print-[before|after][-all] "
|
|
|
|
"options"),
|
|
|
|
cl::CommaSeparated);
|
|
|
|
|
2013-09-19 06:02:43 +00:00
|
|
|
/// This is a helper to determine whether to print IR before or
|
|
|
|
/// after a pass.
|
|
|
|
|
|
|
|
static bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
|
|
|
|
PassOptionList &PassesToPrint) {
|
2015-04-29 21:45:22 +00:00
|
|
|
for (auto *PassInf : PassesToPrint) {
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassInf)
|
|
|
|
if (PassInf->getPassArgument() == PI->getPassArgument()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-18 23:31:16 +00:00
|
|
|
}
|
2013-09-19 06:02:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-04-02 23:17:14 +00:00
|
|
|
|
2013-09-19 06:02:43 +00: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-18 23:31:16 +00:00
|
|
|
|
2013-09-19 06:02:43 +00: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-02 23:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 22:55:03 +00:00
|
|
|
bool llvm::isFunctionInPrintList(StringRef FunctionName) {
|
|
|
|
static std::unordered_set<std::string> PrintFuncNames(PrintFuncsList.begin(),
|
|
|
|
PrintFuncsList.end());
|
|
|
|
return PrintFuncNames.empty() || PrintFuncNames.count(FunctionName);
|
|
|
|
}
|
2009-09-15 05:03:04 +00:00
|
|
|
/// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
|
|
|
|
/// or higher is specified.
|
|
|
|
bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
|
2013-09-19 06:02:43 +00:00
|
|
|
return PassDebugging >= Executions;
|
2009-09-15 05:03:04 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 06:02:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!V && !M)
|
2009-03-06 06:45:05 +00:00
|
|
|
OS << "Releasing pass '";
|
|
|
|
else
|
|
|
|
OS << "Running pass '";
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
OS << P->getPassName() << "'";
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
if (M) {
|
|
|
|
OS << " on module '" << M->getModuleIdentifier() << "'.\n";
|
|
|
|
return;
|
|
|
|
}
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!V) {
|
2009-03-06 06:45:05 +00:00
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-10 18:47:59 +00:00
|
|
|
OS << " on ";
|
2009-03-06 06:45:05 +00:00
|
|
|
if (isa<Function>(V))
|
2009-03-10 18:47:59 +00:00
|
|
|
OS << "function";
|
2009-03-06 06:45:05 +00:00
|
|
|
else if (isa<BasicBlock>(V))
|
2009-03-10 18:47:59 +00:00
|
|
|
OS << "basic block";
|
2009-03-06 06:45:05 +00:00
|
|
|
else
|
2009-03-10 18:47:59 +00:00
|
|
|
OS << "value";
|
|
|
|
|
|
|
|
OS << " '";
|
2014-01-09 02:29:41 +00:00
|
|
|
V->printAsOperand(OS, /*PrintTy=*/false, M);
|
2009-03-10 18:47:59 +00:00
|
|
|
OS << "'\n";
|
2009-03-06 06:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-15 19:39:30 +00:00
|
|
|
namespace {
|
2006-12-12 22:47:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-19 19:46:59 +00:00
|
|
|
// BBPassManager
|
2006-12-12 22:47:13 +00:00
|
|
|
//
|
2006-12-19 19:46:59 +00:00
|
|
|
/// BBPassManager manages BasicBlockPass. It batches all the
|
2006-11-08 10:05:38 +00:00
|
|
|
/// pass together and sequence them to process one basic block before
|
|
|
|
/// processing next basic block.
|
2009-10-25 06:33:48 +00:00
|
|
|
class BBPassManager : public PMDataManager, public FunctionPass {
|
2006-11-08 10:05:38 +00:00
|
|
|
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2011-08-29 17:07:00 +00:00
|
|
|
explicit BBPassManager()
|
|
|
|
: PMDataManager(), FunctionPass(ID) {}
|
2006-11-08 10:05:38 +00: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.
|
2014-03-05 06:35:38 +00:00
|
|
|
bool runOnFunction(Function &F) override;
|
2006-11-08 10:05:38 +00:00
|
|
|
|
2006-12-07 19:57:52 +00:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
2014-03-05 06:35:38 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const override {
|
2006-12-07 19:57:52 +00:00
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
bool doInitialization(Module &M) override;
|
2006-12-08 00:59:05 +00:00
|
|
|
bool doInitialization(Function &F);
|
2014-03-05 06:35:38 +00:00
|
|
|
bool doFinalization(Module &M) override;
|
2006-12-08 00:59:05 +00:00
|
|
|
bool doFinalization(Function &F);
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PMDataManager *getAsPMDataManager() override { return this; }
|
|
|
|
Pass *getAsPass() override { return this; }
|
2010-01-22 05:24:46 +00:00
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
const char *getPassName() const override {
|
2008-03-13 01:58:48 +00:00
|
|
|
return "BasicBlock Pass Manager";
|
2007-02-01 22:08:25 +00:00
|
|
|
}
|
|
|
|
|
2006-12-12 23:34:33 +00:00
|
|
|
// Print passes managed by this manager
|
2014-03-05 06:35:38 +00:00
|
|
|
void dumpPassStructure(unsigned Offset) override {
|
2014-02-26 23:27:16 +00:00
|
|
|
dbgs().indent(Offset*2) << "BasicBlockPass Manager\n";
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2010-08-19 01:29:07 +00:00
|
|
|
BP->dumpPassStructure(Offset + 1);
|
2006-12-16 00:56:26 +00:00
|
|
|
dumpLastUses(BP, Offset+1);
|
2006-12-12 23:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-16 00:56:26 +00:00
|
|
|
|
|
|
|
BasicBlockPass *getContainedPass(unsigned N) {
|
2012-11-13 02:56:38 +00:00
|
|
|
assert(N < PassVector.size() && "Pass number out of range!");
|
2006-12-16 00:56:26 +00:00
|
|
|
BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
|
|
|
|
return BP;
|
|
|
|
}
|
2007-01-11 01:10:25 +00:00
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PassManagerType getPassManagerType() const override {
|
2010-08-12 23:50:08 +00:00
|
|
|
return PMT_BasicBlockPassManager;
|
2007-01-11 01:10:25 +00:00
|
|
|
}
|
2006-11-08 10:05:38 +00:00
|
|
|
};
|
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char BBPassManager::ID = 0;
|
2013-11-09 12:26:54 +00:00
|
|
|
} // End anonymous namespace
|
2006-12-16 00:56:26 +00:00
|
|
|
|
2007-01-12 18:52:44 +00:00
|
|
|
namespace llvm {
|
2013-11-09 12:26:54 +00:00
|
|
|
namespace legacy {
|
2006-12-19 19:46:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FunctionPassManagerImpl
|
|
|
|
//
|
|
|
|
/// FunctionPassManagerImpl manages FPPassManagers
|
|
|
|
class FunctionPassManagerImpl : public Pass,
|
2007-01-11 22:15:30 +00:00
|
|
|
public PMDataManager,
|
|
|
|
public PMTopLevelManager {
|
2011-12-20 02:50:00 +00:00
|
|
|
virtual void anchor();
|
2009-06-29 18:49:09 +00:00
|
|
|
private:
|
|
|
|
bool wasRun;
|
2006-12-19 19:46:59 +00:00
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2011-08-29 17:07:00 +00:00
|
|
|
explicit FunctionPassManagerImpl() :
|
|
|
|
Pass(PT_PassManager, ID), PMDataManager(),
|
|
|
|
PMTopLevelManager(new FPPassManager()), wasRun(false) {}
|
2006-12-19 19:46:59 +00:00
|
|
|
|
2014-12-12 01:27:01 +00:00
|
|
|
/// \copydoc FunctionPassManager::add()
|
2006-12-19 19:46:59 +00:00
|
|
|
void add(Pass *P) {
|
|
|
|
schedulePass(P);
|
|
|
|
}
|
2010-08-12 23:50:08 +00:00
|
|
|
|
|
|
|
/// createPrinterPass - Get a function printer pass.
|
2014-03-05 06:35:38 +00:00
|
|
|
Pass *createPrinterPass(raw_ostream &O,
|
|
|
|
const std::string &Banner) const override {
|
2014-01-12 11:30:46 +00:00
|
|
|
return createPrintFunctionPass(O, Banner);
|
2010-04-02 23:17:14 +00:00
|
|
|
}
|
|
|
|
|
2009-06-29 18:49:09 +00:00
|
|
|
// Prepare for running an on the fly pass, freeing memory if needed
|
|
|
|
// from a previous run.
|
|
|
|
void releaseMemoryOnTheFly();
|
|
|
|
|
2006-12-19 19:46:59 +00: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.
|
|
|
|
///
|
2014-03-05 06:35:38 +00:00
|
|
|
bool doInitialization(Module &M) override;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2007-07-30 14:51:13 +00:00
|
|
|
/// doFinalization - Run all of the finalizers for the function passes.
|
2006-12-19 19:46:59 +00:00
|
|
|
///
|
2014-03-05 06:35:38 +00:00
|
|
|
bool doFinalization(Module &M) override;
|
2006-12-19 19:46:59 +00:00
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PMDataManager *getAsPMDataManager() override { return this; }
|
|
|
|
Pass *getAsPass() override { return this; }
|
|
|
|
PassManagerType getTopLevelPassManagerType() override {
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00:00
|
|
|
return PMT_FunctionPassManager;
|
|
|
|
}
|
2010-01-22 05:24:46 +00:00
|
|
|
|
2006-12-19 19:46:59 +00:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
2014-03-05 06:35:38 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const override {
|
2006-12-19 19:46:59 +00:00
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
FPPassManager *getContainedManager(unsigned N) {
|
2009-03-06 05:53:14 +00:00
|
|
|
assert(N < PassManagers.size() && "Pass number out of range!");
|
2006-12-19 19:46:59 +00:00
|
|
|
FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
|
|
|
|
return FP;
|
|
|
|
}
|
2006-11-08 10:05:38 +00:00
|
|
|
};
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void FunctionPassManagerImpl::anchor() {}
|
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char FunctionPassManagerImpl::ID = 0;
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End of legacy namespace
|
|
|
|
} // End of llvm namespace
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2013-11-09 12:26:54 +00:00
|
|
|
namespace {
|
2006-12-12 22:47:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-19 19:46:59 +00:00
|
|
|
// MPPassManager
|
2006-12-12 22:47:13 +00:00
|
|
|
//
|
2006-12-19 19:46:59 +00:00
|
|
|
/// MPPassManager manages ModulePasses and function pass managers.
|
2008-03-11 16:18:48 +00:00
|
|
|
/// It batches all Module passes and function pass managers together and
|
|
|
|
/// sequences them to process one module.
|
2006-12-19 19:46:59 +00:00
|
|
|
class MPPassManager : public Pass, public PMDataManager {
|
2006-11-08 10:05:38 +00:00
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2011-08-29 17:07:00 +00:00
|
|
|
explicit MPPassManager() :
|
|
|
|
Pass(PT_PassManager, ID), PMDataManager() { }
|
2007-04-16 20:39:59 +00:00
|
|
|
|
|
|
|
// Delete on the fly managers.
|
2015-04-11 02:11:45 +00:00
|
|
|
~MPPassManager() override {
|
2015-06-05 17:48:47 +00:00
|
|
|
for (auto &OnTheFlyManager : OnTheFlyManagers) {
|
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
2007-04-16 20:39:59 +00:00
|
|
|
delete FPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// createPrinterPass - Get a module printer pass.
|
2014-03-05 06:35:38 +00:00
|
|
|
Pass *createPrinterPass(raw_ostream &O,
|
|
|
|
const std::string &Banner) const override {
|
2014-01-12 11:30:46 +00:00
|
|
|
return createPrintModulePass(O, Banner);
|
2010-04-02 23:17:14 +00:00
|
|
|
}
|
|
|
|
|
2006-11-08 10:05:38 +00: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-13 22:40:09 +00:00
|
|
|
|
2012-12-03 21:56:57 +00:00
|
|
|
using llvm::Pass::doInitialization;
|
|
|
|
using llvm::Pass::doFinalization;
|
|
|
|
|
2006-12-07 19:57:52 +00:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
2014-03-05 06:35:38 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const override {
|
2006-12-07 19:57:52 +00:00
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2007-04-16 20:12:57 +00: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.
|
2014-03-05 06:35:38 +00:00
|
|
|
void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) override;
|
2007-04-16 20:12:57 +00:00
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// Return function pass corresponding to PassInfo PI, that is
|
2007-04-16 20:27:05 +00:00
|
|
|
/// required by module pass MP. Instantiate analysis pass, by using
|
|
|
|
/// its runOnFunction() for function F.
|
2014-03-05 06:35:38 +00:00
|
|
|
Pass* getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F) override;
|
2007-04-16 20:27:05 +00:00
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
const char *getPassName() const override {
|
2007-02-01 22:08:25 +00:00
|
|
|
return "Module Pass Manager";
|
|
|
|
}
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PMDataManager *getAsPMDataManager() override { return this; }
|
|
|
|
Pass *getAsPass() override { return this; }
|
2010-01-22 05:24:46 +00:00
|
|
|
|
2006-12-12 23:34:33 +00:00
|
|
|
// Print passes managed by this manager
|
2014-03-05 06:35:38 +00:00
|
|
|
void dumpPassStructure(unsigned Offset) override {
|
2014-02-26 23:27:16 +00:00
|
|
|
dbgs().indent(Offset*2) << "ModulePass Manager\n";
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
ModulePass *MP = getContainedPass(Index);
|
2010-08-19 01:29:07 +00:00
|
|
|
MP->dumpPassStructure(Offset + 1);
|
2009-07-01 23:12:33 +00:00
|
|
|
std::map<Pass *, FunctionPassManagerImpl *>::const_iterator I =
|
|
|
|
OnTheFlyManagers.find(MP);
|
|
|
|
if (I != OnTheFlyManagers.end())
|
|
|
|
I->second->dumpPassStructure(Offset + 2);
|
2006-12-16 00:56:26 +00:00
|
|
|
dumpLastUses(MP, Offset+1);
|
2006-12-12 23:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
ModulePass *getContainedPass(unsigned N) {
|
2012-11-13 02:56:38 +00:00
|
|
|
assert(N < PassVector.size() && "Pass number out of range!");
|
2009-03-06 05:53:14 +00:00
|
|
|
return static_cast<ModulePass *>(PassVector[N]);
|
2006-12-16 00:56:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PassManagerType getPassManagerType() const override {
|
2010-08-12 23:50:08 +00:00
|
|
|
return PMT_ModulePassManager;
|
2007-02-27 15:00:39 +00:00
|
|
|
}
|
2007-04-16 20:27:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Collection of on the fly FPPassManagers. These managers manage
|
|
|
|
/// function passes that are required by module passes.
|
2007-04-26 17:50:19 +00:00
|
|
|
std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
|
2006-11-08 10:05:38 +00:00
|
|
|
};
|
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char MPPassManager::ID = 0;
|
2013-11-09 12:26:54 +00:00
|
|
|
} // End anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace legacy {
|
2006-12-12 22:47:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-19 19:46:59 +00:00
|
|
|
// PassManagerImpl
|
2006-12-12 22:47:13 +00:00
|
|
|
//
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2006-12-19 19:46:59 +00:00
|
|
|
/// PassManagerImpl manages MPPassManagers
|
|
|
|
class PassManagerImpl : public Pass,
|
2007-01-11 22:15:30 +00:00
|
|
|
public PMDataManager,
|
|
|
|
public PMTopLevelManager {
|
2011-12-20 02:50:00 +00:00
|
|
|
virtual void anchor();
|
2006-11-08 10:29:57 +00:00
|
|
|
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2011-08-29 17:07:00 +00:00
|
|
|
explicit PassManagerImpl() :
|
|
|
|
Pass(PT_PassManager, ID), PMDataManager(),
|
|
|
|
PMTopLevelManager(new MPPassManager()) {}
|
2006-12-07 23:24:58 +00:00
|
|
|
|
2014-12-12 01:27:01 +00:00
|
|
|
/// \copydoc PassManager::add()
|
2006-12-07 21:32:57 +00:00
|
|
|
void add(Pass *P) {
|
2006-12-08 22:34:02 +00:00
|
|
|
schedulePass(P);
|
2006-12-07 21:32:57 +00:00
|
|
|
}
|
2010-08-12 23:50:08 +00:00
|
|
|
|
|
|
|
/// createPrinterPass - Get a module printer pass.
|
2014-03-05 06:35:38 +00:00
|
|
|
Pass *createPrinterPass(raw_ostream &O,
|
|
|
|
const std::string &Banner) const override {
|
2014-01-12 11:30:46 +00:00
|
|
|
return createPrintModulePass(O, Banner);
|
2010-04-02 23:17:14 +00:00
|
|
|
}
|
|
|
|
|
2006-11-08 10:29:57 +00: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-03 21:56:57 +00:00
|
|
|
using llvm::Pass::doInitialization;
|
|
|
|
using llvm::Pass::doFinalization;
|
|
|
|
|
2006-12-07 19:57:52 +00:00
|
|
|
/// Pass Manager itself does not invalidate any analysis info.
|
2014-03-05 06:35:38 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &Info) const override {
|
2006-12-07 19:57:52 +00:00
|
|
|
Info.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PMDataManager *getAsPMDataManager() override { return this; }
|
|
|
|
Pass *getAsPass() override { return this; }
|
|
|
|
PassManagerType getTopLevelPassManagerType() override {
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00:00
|
|
|
return PMT_ModulePassManager;
|
|
|
|
}
|
2010-01-22 05:24:46 +00:00
|
|
|
|
2006-12-19 19:46:59 +00:00
|
|
|
MPPassManager *getContainedManager(unsigned N) {
|
2009-03-06 05:53:14 +00:00
|
|
|
assert(N < PassManagers.size() && "Pass number out of range!");
|
2006-12-19 19:46:59 +00:00
|
|
|
MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
|
|
|
|
return MP;
|
|
|
|
}
|
2006-11-08 10:29:57 +00:00
|
|
|
};
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void PassManagerImpl::anchor() {}
|
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char PassManagerImpl::ID = 0;
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End of legacy namespace
|
|
|
|
} // End of llvm namespace
|
2006-12-14 00:59:42 +00:00
|
|
|
|
2007-01-29 23:10:37 +00:00
|
|
|
namespace {
|
2007-01-29 20:06:26 +00:00
|
|
|
|
2007-01-29 23:10:37 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-03-06 06:45:05 +00: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-17 21:28:54 +00:00
|
|
|
|
2009-06-18 20:51:00 +00:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > TimingInfoMutex;
|
2009-06-17 21:28:54 +00:00
|
|
|
|
2009-10-25 06:33:48 +00:00
|
|
|
class TimingInfo {
|
2012-12-03 17:31:11 +00:00
|
|
|
DenseMap<Pass*, Timer*> TimingData;
|
2007-01-29 23:10:37 +00:00
|
|
|
TimerGroup TG;
|
|
|
|
public:
|
|
|
|
// Use 'create' member to get this.
|
|
|
|
TimingInfo() : TG("... Pass execution timing report ...") {}
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2007-01-29 23:10:37 +00:00
|
|
|
// TimingDtor - Print out information about timing information
|
|
|
|
~TimingInfo() {
|
2010-03-30 04:03:22 +00:00
|
|
|
// Delete all of the timers, which accumulate their info into the
|
|
|
|
// TimerGroup.
|
2015-06-05 17:48:47 +00:00
|
|
|
for (auto &I : TimingData)
|
|
|
|
delete I.second;
|
2007-01-29 23:10:37 +00:00
|
|
|
// TimerGroup is deleted next, printing the report.
|
|
|
|
}
|
|
|
|
|
|
|
|
// createTheTimeInfo - This method either initializes the TheTimeInfo pointer
|
2013-12-05 05:44:44 +00:00
|
|
|
// to a non-null value (if the -time-passes option is enabled) or it leaves it
|
2007-01-29 23:10:37 +00:00
|
|
|
// null. It may be called multiple times.
|
|
|
|
static void createTheTimeInfo();
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
/// getPassTimer - Return the timer for the specified pass if it exists.
|
|
|
|
Timer *getPassTimer(Pass *P) {
|
2010-08-12 23:50:08 +00:00
|
|
|
if (P->getAsPMDataManager())
|
2014-04-09 06:08:46 +00:00
|
|
|
return nullptr;
|
2007-01-29 23:10:37 +00:00
|
|
|
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
|
2012-12-03 17:31:11 +00:00
|
|
|
Timer *&T = TimingData[P];
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!T)
|
2010-03-30 04:03:22 +00:00
|
|
|
T = new Timer(P->getPassName(), TG);
|
2010-03-30 03:57:00 +00:00
|
|
|
return T;
|
2007-01-29 23:10:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End of anon namespace
|
2006-11-08 10:05:38 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
static TimingInfo *TheTimeInfo;
|
|
|
|
|
2006-12-12 22:35:25 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PMTopLevelManager implementation
|
|
|
|
|
2007-01-16 02:00:38 +00:00
|
|
|
/// Initialize top level manager. Create first pass manager.
|
2010-08-16 21:38:42 +00:00
|
|
|
PMTopLevelManager::PMTopLevelManager(PMDataManager *PMDM) {
|
|
|
|
PMDM->setTopLevelManager(this);
|
|
|
|
addPassManager(PMDM);
|
|
|
|
activeStack.push(PMDM);
|
2007-01-16 02:00:38 +00:00
|
|
|
}
|
|
|
|
|
2006-12-12 22:35:25 +00:00
|
|
|
/// Set pass P as the last user of the given analysis passes.
|
2010-10-12 00:12:29 +00:00
|
|
|
void
|
2012-05-14 07:53:40 +00:00
|
|
|
PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) {
|
2011-01-20 21:03:22 +00:00
|
|
|
unsigned PDepth = 0;
|
|
|
|
if (P->getResolver())
|
|
|
|
PDepth = P->getResolver()->getPMDataManager().getDepth();
|
|
|
|
|
2015-06-05 17:48:47 +00:00
|
|
|
for (Pass *AP : AnalysisPasses) {
|
2006-12-12 22:35:25 +00:00
|
|
|
LastUser[AP] = P;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2007-03-08 19:05:01 +00:00
|
|
|
if (P == AP)
|
|
|
|
continue;
|
|
|
|
|
2011-01-20 21:03:22 +00: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;
|
2016-04-28 14:49:44 +00:00
|
|
|
for (AnalysisID ID : IDs) {
|
|
|
|
Pass *AnalysisPass = findAnalysisPass(ID);
|
2011-01-20 21:03:22 +00:00
|
|
|
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-12 22:35:25 +00:00
|
|
|
// If AP is the last user of other passes then make P last user of
|
|
|
|
// such passes.
|
2008-08-12 00:26:16 +00:00
|
|
|
for (DenseMap<Pass *, Pass *>::iterator LUI = LastUser.begin(),
|
2006-12-12 22:35:25 +00:00
|
|
|
LUE = LastUser.end(); LUI != LUE; ++LUI) {
|
|
|
|
if (LUI->second == AP)
|
2008-08-12 00:26:16 +00:00
|
|
|
// DenseMap iterator is not invalidated here because
|
2011-01-20 21:03:22 +00:00
|
|
|
// this is just updating existing entries.
|
2006-12-12 22:35:25 +00:00
|
|
|
LastUser[LUI->first] = P;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Collect passes whose last user is P
|
2010-10-12 00:11:18 +00:00
|
|
|
void PMTopLevelManager::collectLastUses(SmallVectorImpl<Pass *> &LastUses,
|
2008-08-12 00:26:16 +00:00
|
|
|
Pass *P) {
|
2010-08-12 23:50:08 +00:00
|
|
|
DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
|
2008-08-12 00:26:16 +00:00
|
|
|
InversedLastUser.find(P);
|
|
|
|
if (DMI == InversedLastUser.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
SmallPtrSet<Pass *, 8> &LU = DMI->second;
|
2014-08-24 23:23:06 +00:00
|
|
|
for (Pass *LUP : LU) {
|
|
|
|
LastUses.push_back(LUP);
|
2008-08-12 00:26:16 +00:00
|
|
|
}
|
|
|
|
|
2006-12-12 22:35:25 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
|
2014-04-09 06:08:46 +00:00
|
|
|
AnalysisUsage *AnUsage = nullptr;
|
2015-12-04 20:05:04 +00:00
|
|
|
auto DMI = AnUsageMap.find(P);
|
2010-08-12 23:50:08 +00:00
|
|
|
if (DMI != AnUsageMap.end())
|
2008-08-11 21:13:39 +00:00
|
|
|
AnUsage = DMI->second;
|
|
|
|
else {
|
2015-12-04 20:05:04 +00:00
|
|
|
// Look up the analysis usage from the pass instance (different instances
|
|
|
|
// of the same pass can produce different results), but unique the
|
|
|
|
// resulting object to reduce memory usage. This helps to greatly reduce
|
|
|
|
// memory usage when we have many instances of only a few pass types
|
|
|
|
// (e.g. instcombine, simplifycfg, etc...) which tend to share a fixed set
|
|
|
|
// of dependencies.
|
|
|
|
AnalysisUsage AU;
|
|
|
|
P->getAnalysisUsage(AU);
|
|
|
|
|
|
|
|
AUFoldingSetNode* Node = nullptr;
|
|
|
|
FoldingSetNodeID ID;
|
|
|
|
AUFoldingSetNode::Profile(ID, AU);
|
|
|
|
void *IP = nullptr;
|
|
|
|
if (auto *N = UniqueAnalysisUsages.FindNodeOrInsertPos(ID, IP))
|
|
|
|
Node = N;
|
|
|
|
else {
|
2015-12-04 23:48:19 +00:00
|
|
|
Node = new (AUFoldingSetNodeAllocator.Allocate()) AUFoldingSetNode(AU);
|
2015-12-04 20:05:04 +00:00
|
|
|
UniqueAnalysisUsages.InsertNode(Node, IP);
|
|
|
|
}
|
|
|
|
assert(Node && "cached analysis usage must be non null");
|
|
|
|
|
|
|
|
AnUsageMap[P] = &Node->AU;
|
|
|
|
AnUsage = &Node->AU;;
|
2008-08-11 21:13:39 +00:00
|
|
|
}
|
|
|
|
return AnUsage;
|
|
|
|
}
|
|
|
|
|
2006-12-12 22:35:25 +00: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-16 21:43:18 +00:00
|
|
|
// TODO : Allocate function manager for this pass, other wise required set
|
|
|
|
// may be inserted into previous function manager
|
2006-12-12 22:35:25 +00:00
|
|
|
|
2007-03-06 01:06:16 +00:00
|
|
|
// Give pass a chance to prepare the stage.
|
|
|
|
P->preparePassManager(activeStack);
|
|
|
|
|
2008-03-18 00:39:19 +00: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.
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
const PassInfo *PI = findAnalysisPassInfo(P->getPassID());
|
2010-08-06 18:33:48 +00:00
|
|
|
if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
|
2008-11-04 23:03:58 +00:00
|
|
|
delete P;
|
2008-03-19 00:48:41 +00:00
|
|
|
return;
|
2008-11-04 23:03:58 +00:00
|
|
|
}
|
2008-03-18 00:39:19 +00:00
|
|
|
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *AnUsage = findAnalysisUsage(P);
|
|
|
|
|
2008-08-14 23:07:48 +00:00
|
|
|
bool checkAnalysis = true;
|
|
|
|
while (checkAnalysis) {
|
|
|
|
checkAnalysis = false;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2008-08-14 23:07:48 +00:00
|
|
|
const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
|
|
|
|
for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
|
|
|
|
E = RequiredSet.end(); I != E; ++I) {
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2008-08-14 23:07:48 +00:00
|
|
|
Pass *AnalysisPass = findAnalysisPass(*I);
|
|
|
|
if (!AnalysisPass) {
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
const PassInfo *PI = findAnalysisPassInfo(*I);
|
2012-07-18 19:59:29 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!PI) {
|
2012-07-18 19:59:29 +00:00
|
|
|
// 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 06:50:38 +00:00
|
|
|
} else {
|
2012-07-18 19:59:29 +00: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 00:48:58 +00:00
|
|
|
assert(PI && "Expected required passes to be initialized");
|
2010-08-06 18:33:48 +00:00
|
|
|
AnalysisPass = PI->createPass();
|
2008-08-14 23:07:48 +00: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-16 22:57:28 +00:00
|
|
|
// Recheck analysis passes to ensure that required analyses that
|
2008-08-14 23:07:48 +00:00
|
|
|
// are already checked are still available.
|
|
|
|
checkAnalysis = true;
|
2013-02-06 06:50:38 +00:00
|
|
|
} else
|
2015-03-20 15:45:14 +00:00
|
|
|
// Do not schedule this analysis. Lower level analysis
|
2008-08-14 23:07:48 +00:00
|
|
|
// passes are run on the fly.
|
|
|
|
delete AnalysisPass;
|
|
|
|
}
|
2006-12-12 22:35:25 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00: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 06:02:43 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00: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 06:02:43 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00:00
|
|
|
Pass *PP = P->createPrinterPass(
|
|
|
|
dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
|
|
|
|
PP->assignPassManager(activeStack, getTopLevelPassManagerType());
|
|
|
|
}
|
2006-12-12 22:35:25 +00: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) {
|
2015-09-10 02:31:42 +00:00
|
|
|
// For immutable passes we have a direct mapping from ID to pass, so check
|
|
|
|
// that first.
|
|
|
|
if (Pass *P = ImmutablePassMap.lookup(AID))
|
|
|
|
return P;
|
2006-12-12 22:35:25 +00:00
|
|
|
|
2006-12-12 22:50:05 +00:00
|
|
|
// Check pass managers
|
2015-06-05 17:48:47 +00:00
|
|
|
for (PMDataManager *PassManager : PassManagers)
|
|
|
|
if (Pass *P = PassManager->findAnalysisPass(AID, false))
|
2010-10-11 23:19:01 +00:00
|
|
|
return P;
|
2006-12-12 22:50:05 +00:00
|
|
|
|
|
|
|
// Check other pass managers
|
2015-06-05 17:48:47 +00:00
|
|
|
for (PMDataManager *IndirectPassManager : IndirectPassManagers)
|
|
|
|
if (Pass *P = IndirectPassManager->findAnalysisPass(AID, false))
|
2010-10-11 23:19:01 +00:00
|
|
|
return P;
|
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
return nullptr;
|
2006-12-12 22:35:25 +00:00
|
|
|
}
|
|
|
|
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
const PassInfo *PMTopLevelManager::findAnalysisPassInfo(AnalysisID AID) const {
|
|
|
|
const PassInfo *&PI = AnalysisPassInfos[AID];
|
|
|
|
if (!PI)
|
|
|
|
PI = PassRegistry::getPassRegistry()->getPassInfo(AID);
|
|
|
|
else
|
|
|
|
assert(PI == PassRegistry::getPassRegistry()->getPassInfo(AID) &&
|
|
|
|
"The pass info pointer changed for an analysis ID!");
|
|
|
|
|
|
|
|
return PI;
|
|
|
|
}
|
|
|
|
|
2015-09-10 02:31:42 +00:00
|
|
|
void PMTopLevelManager::addImmutablePass(ImmutablePass *P) {
|
|
|
|
P->initializePass();
|
|
|
|
ImmutablePasses.push_back(P);
|
|
|
|
|
|
|
|
// Add this pass to the map from its analysis ID. We clobber any prior runs
|
|
|
|
// of the pass in the map so that the last one added is the one found when
|
|
|
|
// doing lookups.
|
|
|
|
AnalysisID AID = P->getPassID();
|
|
|
|
ImmutablePassMap[AID] = P;
|
|
|
|
|
|
|
|
// Also add any interfaces implemented by the immutable pass to the map for
|
|
|
|
// fast lookup.
|
|
|
|
const PassInfo *PassInf = findAnalysisPassInfo(AID);
|
|
|
|
assert(PassInf && "Expected all immutable passes to be initialized");
|
2015-09-10 04:22:36 +00:00
|
|
|
for (const PassInfo *ImmPI : PassInf->getInterfacesImplemented())
|
2015-09-10 02:31:42 +00:00
|
|
|
ImmutablePassMap[ImmPI->getTypeInfo()] = P;
|
|
|
|
}
|
|
|
|
|
2006-12-12 23:34:33 +00:00
|
|
|
// Print passes managed by this top level manager.
|
2006-12-15 20:13:01 +00:00
|
|
|
void PMTopLevelManager::dumpPasses() const {
|
2006-12-12 23:34:33 +00:00
|
|
|
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging < Structure)
|
2006-12-19 19:46:59 +00:00
|
|
|
return;
|
|
|
|
|
2006-12-12 23:34:33 +00:00
|
|
|
// Print out the immutable passes
|
|
|
|
for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
|
2010-08-19 01:29:07 +00:00
|
|
|
ImmutablePasses[i]->dumpPassStructure(0);
|
2006-12-12 23:34:33 +00:00
|
|
|
}
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2010-08-19 01:29:07 +00: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*.
|
2015-06-05 17:48:47 +00:00
|
|
|
for (PMDataManager *Manager : PassManagers)
|
|
|
|
Manager->getAsPass()->dumpPassStructure(1);
|
2006-12-12 23:34:33 +00:00
|
|
|
}
|
|
|
|
|
2006-12-15 20:13:01 +00:00
|
|
|
void PMTopLevelManager::dumpArguments() const {
|
2006-12-13 22:10:00 +00:00
|
|
|
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging < Arguments)
|
2006-12-13 22:10:00 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "Pass Arguments: ";
|
2016-04-28 14:49:44 +00:00
|
|
|
for (ImmutablePass *P : ImmutablePasses)
|
|
|
|
if (const PassInfo *PI = findAnalysisPassInfo(P->getPassID())) {
|
2011-06-03 00:48:58 +00:00
|
|
|
assert(PI && "Expected all immutable passes to be initialized");
|
2010-11-11 16:32:17 +00:00
|
|
|
if (!PI->isAnalysisGroup())
|
|
|
|
dbgs() << " -" << PI->getPassArgument();
|
2011-06-03 00:48:58 +00:00
|
|
|
}
|
2016-04-28 14:49:44 +00:00
|
|
|
for (PMDataManager *PM : PassManagers)
|
|
|
|
PM->dumpPassArguments();
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "\n";
|
2006-12-13 22:10:00 +00:00
|
|
|
}
|
|
|
|
|
2006-12-21 00:16:50 +00:00
|
|
|
void PMTopLevelManager::initializeAllAnalysisInfo() {
|
2016-04-28 14:49:44 +00:00
|
|
|
for (PMDataManager *PM : PassManagers)
|
|
|
|
PM->initializeAnalysisInfo();
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2006-12-21 00:16:50 +00:00
|
|
|
// Initailize other pass managers
|
2016-04-28 14:49:44 +00:00
|
|
|
for (PMDataManager *IPM : IndirectPassManagers)
|
|
|
|
IPM->initializeAnalysisInfo();
|
2008-08-12 00:26:16 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
for (DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
|
2008-08-12 00:26:16 +00:00
|
|
|
DME = LastUser.end(); DMI != DME; ++DMI) {
|
2015-10-05 18:53:30 +00:00
|
|
|
SmallPtrSet<Pass *, 8> &L = InversedLastUser[DMI->second];
|
|
|
|
L.insert(DMI->first);
|
2008-08-12 00:26:16 +00:00
|
|
|
}
|
2006-12-21 00:16:50 +00:00
|
|
|
}
|
|
|
|
|
2007-01-12 18:52:44 +00:00
|
|
|
/// Destructor
|
|
|
|
PMTopLevelManager::~PMTopLevelManager() {
|
2016-04-28 14:49:44 +00:00
|
|
|
for (PMDataManager *PM : PassManagers)
|
|
|
|
delete PM;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2016-04-28 14:49:44 +00:00
|
|
|
for (ImmutablePass *P : ImmutablePasses)
|
|
|
|
delete P;
|
2007-01-12 18:52:44 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-07 18:36:24 +00:00
|
|
|
// PMDataManager implementation
|
2006-11-07 22:35:17 +00:00
|
|
|
|
2006-11-11 01:10:19 +00:00
|
|
|
/// Augement AvailableAnalysis by adding analysis made available by pass P.
|
2006-12-07 19:33:53 +00:00
|
|
|
void PMDataManager::recordAvailableAnalysis(Pass *P) {
|
2010-08-06 18:33:48 +00:00
|
|
|
AnalysisID PI = P->getPassID();
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
AvailableAnalysis[PI] = P;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2010-08-12 23:46:28 +00:00
|
|
|
assert(!AvailableAnalysis.empty());
|
2006-11-11 01:10:19 +00:00
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
// This pass is the current implementation of all of the interfaces it
|
|
|
|
// implements as well.
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
const PassInfo *PInf = TPM->findAnalysisPassInfo(PI);
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!PInf) return;
|
2010-08-06 18:33:48 +00:00
|
|
|
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
|
2010-07-20 16:55:05 +00:00
|
|
|
for (unsigned i = 0, e = II.size(); i != e; ++i)
|
2010-08-06 18:33:48 +00:00
|
|
|
AvailableAnalysis[II[i]->getTypeInfo()] = P;
|
2006-11-11 01:10:19 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 17:52:53 +00:00
|
|
|
// Return true if P preserves high level analysis used by other
|
|
|
|
// passes managed by this manager
|
|
|
|
bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
if (AnUsage->getPreservesAll())
|
2007-03-06 17:52:53 +00:00
|
|
|
return true;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2008-08-11 21:13:39 +00:00
|
|
|
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
|
2010-10-12 00:15:27 +00:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = HigherLevelAnalysis.begin(),
|
2007-03-06 17:52:53 +00:00
|
|
|
E = HigherLevelAnalysis.end(); I != E; ++I) {
|
|
|
|
Pass *P1 = *I;
|
2014-04-09 06:08:46 +00:00
|
|
|
if (P1->getAsImmutablePass() == nullptr &&
|
2016-08-11 22:21:41 +00:00
|
|
|
!is_contained(PreservedSet, P1->getPassID()))
|
2007-03-08 19:05:01 +00:00
|
|
|
return false;
|
2007-03-06 17:52:53 +00:00
|
|
|
}
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2007-03-06 17:52:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-07 07:34:50 +00:00
|
|
|
/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
|
2007-07-19 18:02:32 +00:00
|
|
|
void PMDataManager::verifyPreservedAnalysis(Pass *P) {
|
2008-08-07 07:34:50 +00:00
|
|
|
// Don't do this unless assertions are enabled.
|
|
|
|
#ifdef NDEBUG
|
|
|
|
return;
|
|
|
|
#endif
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
|
2006-11-11 01:24:55 +00:00
|
|
|
|
2007-07-19 05:36:09 +00:00
|
|
|
// Verify preserved analysis
|
2008-08-08 05:33:04 +00:00
|
|
|
for (AnalysisUsage::VectorType::const_iterator I = PreservedSet.begin(),
|
2007-07-19 18:02:32 +00:00
|
|
|
E = PreservedSet.end(); I != E; ++I) {
|
|
|
|
AnalysisID AID = *I;
|
2009-09-28 00:27:48 +00:00
|
|
|
if (Pass *AP = findAnalysisPass(AID, true)) {
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRegion PassTimer(getPassTimer(AP));
|
2009-09-28 00:27:48 +00:00
|
|
|
AP->verifyAnalysis();
|
|
|
|
}
|
2008-07-01 17:44:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 19:50:56 +00:00
|
|
|
/// Remove Analysis not preserved by Pass P
|
2007-07-19 18:02:32 +00:00
|
|
|
void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
if (AnUsage->getPreservesAll())
|
2006-12-07 20:03:49 +00:00
|
|
|
return;
|
|
|
|
|
2008-08-11 21:13:39 +00:00
|
|
|
const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
|
2013-02-26 01:31:59 +00:00
|
|
|
for (DenseMap<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
|
2006-12-12 23:07:44 +00:00
|
|
|
E = AvailableAnalysis.end(); I != E; ) {
|
2013-02-26 01:31:59 +00:00
|
|
|
DenseMap<AnalysisID, Pass*>::iterator Info = I++;
|
2014-04-09 06:08:46 +00:00
|
|
|
if (Info->second->getAsImmutablePass() == nullptr &&
|
2016-08-11 22:21:41 +00:00
|
|
|
!is_contained(PreservedSet, Info->first)) {
|
2006-11-11 01:24:55 +00:00
|
|
|
// Remove this analysis
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging >= Details) {
|
2008-06-03 01:02:16 +00:00
|
|
|
Pass *S = Info->second;
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
|
|
|
|
dbgs() << S->getPassName() << "'\n";
|
2008-06-03 01:02:16 +00:00
|
|
|
}
|
2008-11-06 21:57:17 +00:00
|
|
|
AvailableAnalysis.erase(Info);
|
2008-06-03 01:02:16 +00:00
|
|
|
}
|
2006-11-11 01:24:55 +00:00
|
|
|
}
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2007-03-06 01:55:46 +00: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 01:31:59 +00:00
|
|
|
for (DenseMap<AnalysisID, Pass*>::iterator
|
2007-03-06 01:55:46 +00:00
|
|
|
I = InheritedAnalysis[Index]->begin(),
|
|
|
|
E = InheritedAnalysis[Index]->end(); I != E; ) {
|
2013-02-26 01:31:59 +00:00
|
|
|
DenseMap<AnalysisID, Pass *>::iterator Info = I++;
|
2014-04-09 06:08:46 +00:00
|
|
|
if (Info->second->getAsImmutablePass() == nullptr &&
|
2016-08-11 22:21:41 +00:00
|
|
|
!is_contained(PreservedSet, Info->first)) {
|
2007-03-06 01:55:46 +00:00
|
|
|
// Remove this analysis
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging >= Details) {
|
2009-12-04 06:58:24 +00:00
|
|
|
Pass *S = Info->second;
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
|
|
|
|
dbgs() << S->getPassName() << "'\n";
|
2009-12-04 06:58:24 +00:00
|
|
|
}
|
2007-03-08 19:05:01 +00:00
|
|
|
InheritedAnalysis[Index]->erase(Info);
|
2009-12-04 06:58:24 +00:00
|
|
|
}
|
2007-03-06 01:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-07 22:35:17 +00:00
|
|
|
}
|
|
|
|
|
2006-11-14 03:05:08 +00:00
|
|
|
/// Remove analysis passes that are not used any longer
|
2009-11-06 10:58:06 +00:00
|
|
|
void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
|
2007-03-05 20:01:30 +00:00
|
|
|
enum PassDebuggingString DBG_STR) {
|
2006-12-08 00:37:52 +00:00
|
|
|
|
2007-07-20 18:04:54 +00:00
|
|
|
SmallVector<Pass *, 12> DeadPasses;
|
2007-04-16 20:27:05 +00:00
|
|
|
|
2007-04-16 20:39:59 +00:00
|
|
|
// If this is a on the fly manager then it does not have TPM.
|
2007-04-16 20:27:05 +00:00
|
|
|
if (!TPM)
|
|
|
|
return;
|
|
|
|
|
2006-12-08 00:37:52 +00:00
|
|
|
TPM->collectLastUses(DeadPasses, P);
|
|
|
|
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging >= Details && !DeadPasses.empty()) {
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << " -*- '" << P->getPassName();
|
|
|
|
dbgs() << "' is the last user of following pass instances.";
|
|
|
|
dbgs() << " Free these instances\n";
|
2008-06-04 09:13:31 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 00:15:27 +00:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = DeadPasses.begin(),
|
2009-09-27 23:38:27 +00:00
|
|
|
E = DeadPasses.end(); I != E; ++I)
|
|
|
|
freePass(*I, Msg, DBG_STR);
|
|
|
|
}
|
2006-12-13 23:50:44 +00:00
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void PMDataManager::freePass(Pass *P, StringRef Msg,
|
2009-09-27 23:38:27 +00:00
|
|
|
enum PassDebuggingString DBG_STR) {
|
|
|
|
dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
|
2006-12-13 23:50:44 +00:00
|
|
|
|
2009-09-27 23:38:27 +00:00
|
|
|
{
|
|
|
|
// If the pass crashes releasing memory, remember this.
|
|
|
|
PassManagerPrettyStackEntry X(P);
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRegion PassTimer(getPassTimer(P));
|
|
|
|
|
2009-09-27 23:38:27 +00:00
|
|
|
P->releaseMemory();
|
|
|
|
}
|
2008-10-06 20:36:36 +00:00
|
|
|
|
2010-08-06 18:33:48 +00:00
|
|
|
AnalysisID PI = P->getPassID();
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
if (const PassInfo *PInf = TPM->findAnalysisPassInfo(PI)) {
|
2009-09-27 23:38:27 +00:00
|
|
|
// Remove the pass itself (if it is not already removed).
|
|
|
|
AvailableAnalysis.erase(PI);
|
2008-10-06 20:36:36 +00:00
|
|
|
|
2009-09-27 23:38:27 +00:00
|
|
|
// Remove all interfaces this pass implements, for which it is also
|
|
|
|
// listed as the available implementation.
|
2010-08-06 18:33:48 +00:00
|
|
|
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
|
2010-07-20 16:55:05 +00:00
|
|
|
for (unsigned i = 0, e = II.size(); i != e; ++i) {
|
2013-02-26 01:31:59 +00:00
|
|
|
DenseMap<AnalysisID, Pass*>::iterator Pos =
|
2010-08-06 18:33:48 +00:00
|
|
|
AvailableAnalysis.find(II[i]->getTypeInfo());
|
2009-09-27 23:38:27 +00:00
|
|
|
if (Pos != AvailableAnalysis.end() && Pos->second == P)
|
|
|
|
AvailableAnalysis.erase(Pos);
|
2008-10-06 20:36:36 +00:00
|
|
|
}
|
2006-12-08 00:37:52 +00:00
|
|
|
}
|
2006-11-14 03:05:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// Add pass P into the PassVector. Update
|
2006-11-11 02:04:19 +00:00
|
|
|
/// AvailableAnalysis appropriately if ProcessAnalysis is true.
|
2009-03-06 05:53:14 +00:00
|
|
|
void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
|
2006-12-08 23:53:00 +00:00
|
|
|
// This manager is going to manage pass P. Set up analysis resolver
|
|
|
|
// to connect them.
|
2007-01-05 22:47:07 +00:00
|
|
|
AnalysisResolver *AR = new AnalysisResolver(*this);
|
2006-12-08 23:53:00 +00:00
|
|
|
P->setResolver(AR);
|
|
|
|
|
2007-03-05 22:57:49 +00: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-20 18:04:54 +00:00
|
|
|
SmallVector<Pass *, 12> TransferLastUses;
|
2007-03-05 22:57:49 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
if (!ProcessAnalysis) {
|
|
|
|
// Add pass
|
|
|
|
PassVector.push_back(P);
|
|
|
|
return;
|
|
|
|
}
|
2007-04-16 20:12:57 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
// At the moment, this pass is the last user of all required passes.
|
|
|
|
SmallVector<Pass *, 12> LastUses;
|
2015-08-19 03:02:12 +00:00
|
|
|
SmallVector<Pass *, 8> UsedPasses;
|
2009-03-06 05:53:14 +00:00
|
|
|
SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
|
2007-03-05 22:57:49 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
unsigned PDepth = this->getDepth();
|
|
|
|
|
2015-08-19 03:02:12 +00:00
|
|
|
collectRequiredAndUsedAnalyses(UsedPasses, ReqAnalysisNotAvailable, P);
|
|
|
|
for (Pass *PUsed : UsedPasses) {
|
2009-03-06 05:53:14 +00:00
|
|
|
unsigned RDepth = 0;
|
|
|
|
|
2015-08-19 03:02:12 +00:00
|
|
|
assert(PUsed->getResolver() && "Analysis Resolver is not set");
|
|
|
|
PMDataManager &DM = PUsed->getResolver()->getPMDataManager();
|
2009-03-06 05:53:14 +00:00
|
|
|
RDepth = DM.getDepth();
|
|
|
|
|
|
|
|
if (PDepth == RDepth)
|
2015-08-19 03:02:12 +00:00
|
|
|
LastUses.push_back(PUsed);
|
2009-03-06 05:53:14 +00:00
|
|
|
else if (PDepth > RDepth) {
|
|
|
|
// Let the parent claim responsibility of last use
|
2015-08-19 03:02:12 +00:00
|
|
|
TransferLastUses.push_back(PUsed);
|
2009-03-06 05:53:14 +00:00
|
|
|
// Keep track of higher level analysis used by this manager.
|
2015-08-19 03:02:12 +00:00
|
|
|
HigherLevelAnalysis.push_back(PUsed);
|
2010-08-12 23:50:08 +00:00
|
|
|
} else
|
2015-08-19 03:02:12 +00:00
|
|
|
llvm_unreachable("Unable to accommodate Used Pass");
|
2009-03-06 05:53:14 +00: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.
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!P->getAsPMDataManager())
|
2009-03-06 05:53:14 +00:00
|
|
|
LastUses.push_back(P);
|
|
|
|
TPM->setLastUser(LastUses, P);
|
|
|
|
|
|
|
|
if (!TransferLastUses.empty()) {
|
2010-01-22 05:24:46 +00:00
|
|
|
Pass *My_PM = getAsPass();
|
2009-03-06 05:53:14 +00:00
|
|
|
TPM->setLastUser(TransferLastUses, My_PM);
|
|
|
|
TransferLastUses.clear();
|
|
|
|
}
|
2007-04-16 20:27:05 +00:00
|
|
|
|
2010-08-16 22:57:28 +00:00
|
|
|
// Now, take care of required analyses that are not available.
|
2015-08-18 18:41:53 +00:00
|
|
|
for (AnalysisID ID : ReqAnalysisNotAvailable) {
|
|
|
|
const PassInfo *PI = TPM->findAnalysisPassInfo(ID);
|
2010-08-06 18:33:48 +00:00
|
|
|
Pass *AnalysisPass = PI->createPass();
|
2009-03-06 05:53:14 +00:00
|
|
|
this->addLowerLevelRequiredPass(P, AnalysisPass);
|
2006-11-11 02:04:19 +00:00
|
|
|
}
|
2006-11-11 01:51:02 +00:00
|
|
|
|
2009-03-06 05:53:14 +00: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 01:51:02 +00:00
|
|
|
// Add pass
|
|
|
|
PassVector.push_back(P);
|
|
|
|
}
|
|
|
|
|
2007-04-16 20:12:57 +00:00
|
|
|
|
2015-08-19 03:02:12 +00:00
|
|
|
/// Populate UP with analysis pass that are used or required by
|
2007-04-16 20:12:57 +00:00
|
|
|
/// pass P and are available. Populate RP_NotAvail with analysis
|
|
|
|
/// pass that are required by pass P but are not available.
|
2015-08-19 03:02:12 +00:00
|
|
|
void PMDataManager::collectRequiredAndUsedAnalyses(
|
|
|
|
SmallVectorImpl<Pass *> &UP, SmallVectorImpl<AnalysisID> &RP_NotAvail,
|
|
|
|
Pass *P) {
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
2015-08-19 03:02:12 +00:00
|
|
|
|
|
|
|
for (const auto &UsedID : AnUsage->getUsedSet())
|
|
|
|
if (Pass *AnalysisPass = findAnalysisPass(UsedID, true))
|
|
|
|
UP.push_back(AnalysisPass);
|
|
|
|
|
2015-08-18 18:41:53 +00:00
|
|
|
for (const auto &RequiredID : AnUsage->getRequiredSet())
|
|
|
|
if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
|
2015-08-19 03:02:12 +00:00
|
|
|
UP.push_back(AnalysisPass);
|
2007-04-16 20:12:57 +00:00
|
|
|
else
|
2015-08-18 18:41:53 +00:00
|
|
|
RP_NotAvail.push_back(RequiredID);
|
2006-12-12 23:09:32 +00:00
|
|
|
|
2015-08-18 18:41:53 +00:00
|
|
|
for (const auto &RequiredID : AnUsage->getRequiredTransitiveSet())
|
|
|
|
if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
|
2015-08-19 03:02:12 +00:00
|
|
|
UP.push_back(AnalysisPass);
|
2007-04-16 20:12:57 +00:00
|
|
|
else
|
2015-08-18 18:41:53 +00:00
|
|
|
RP_NotAvail.push_back(RequiredID);
|
2006-12-07 23:05:44 +00:00
|
|
|
}
|
|
|
|
|
2006-11-14 21:49:36 +00: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-07 18:36:24 +00:00
|
|
|
void PMDataManager::initializeAnalysisImpl(Pass *P) {
|
2008-08-11 21:13:39 +00:00
|
|
|
AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
|
|
|
|
|
2008-08-08 05:33:04 +00:00
|
|
|
for (AnalysisUsage::VectorType::const_iterator
|
2008-08-11 21:13:39 +00:00
|
|
|
I = AnUsage->getRequiredSet().begin(),
|
|
|
|
E = AnUsage->getRequiredSet().end(); I != E; ++I) {
|
2006-12-08 22:30:11 +00:00
|
|
|
Pass *Impl = findAnalysisPass(*I, true);
|
2014-04-09 06:08:46 +00:00
|
|
|
if (!Impl)
|
2007-04-16 20:44:16 +00: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-05 22:47:07 +00:00
|
|
|
AnalysisResolver *AR = P->getResolver();
|
2009-03-06 05:53:14 +00:00
|
|
|
assert(AR && "Analysis Resolver is not set");
|
2006-12-09 01:11:34 +00:00
|
|
|
AR->addAnalysisImplsPair(*I, Impl);
|
2006-11-14 21:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-08 22:30:11 +00: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 01:31:59 +00:00
|
|
|
DenseMap<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
|
2006-12-08 22:30:11 +00:00
|
|
|
|
|
|
|
if (I != AvailableAnalysis.end())
|
|
|
|
return I->second;
|
|
|
|
|
|
|
|
// Search Parents through TopLevelManager
|
|
|
|
if (SearchParent)
|
|
|
|
return TPM->findAnalysisPass(AID);
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
return nullptr;
|
2006-12-08 22:30:11 +00:00
|
|
|
}
|
|
|
|
|
2006-12-15 20:13:01 +00:00
|
|
|
// Print list of passes that are last used by P.
|
|
|
|
void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
|
|
|
|
|
2007-07-20 18:04:54 +00:00
|
|
|
SmallVector<Pass *, 12> LUses;
|
2007-04-16 20:39:59 +00:00
|
|
|
|
|
|
|
// If this is a on the fly manager then it does not have TPM.
|
|
|
|
if (!TPM)
|
|
|
|
return;
|
|
|
|
|
2006-12-15 20:13:01 +00:00
|
|
|
TPM->collectLastUses(LUses, P);
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2010-10-12 00:11:18 +00:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = LUses.begin(),
|
2006-12-15 20:13:01 +00:00
|
|
|
E = LUses.end(); I != E; ++I) {
|
2014-02-26 23:27:16 +00:00
|
|
|
dbgs() << "--" << std::string(Offset*2, ' ');
|
2010-08-19 01:29:07 +00:00
|
|
|
(*I)->dumpPassStructure(0);
|
2006-12-15 20:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PMDataManager::dumpPassArguments() const {
|
2010-10-12 00:11:18 +00:00
|
|
|
for (SmallVectorImpl<Pass *>::const_iterator I = PassVector.begin(),
|
2006-12-15 20:13:01 +00:00
|
|
|
E = PassVector.end(); I != E; ++I) {
|
2010-01-22 05:24:46 +00:00
|
|
|
if (PMDataManager *PMD = (*I)->getAsPMDataManager())
|
2006-12-15 20:13:01 +00:00
|
|
|
PMD->dumpPassArguments();
|
|
|
|
else
|
2010-08-06 18:33:48 +00:00
|
|
|
if (const PassInfo *PI =
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
TPM->findAnalysisPassInfo((*I)->getPassID()))
|
2006-12-15 20:13:01 +00:00
|
|
|
if (!PI->isAnalysisGroup())
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << " -" << PI->getPassArgument();
|
2006-12-15 20:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-10 06:17:04 +00:00
|
|
|
void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
|
|
|
|
enum PassDebuggingString S2,
|
2009-11-06 10:58:06 +00:00
|
|
|
StringRef Msg) {
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging < Executions)
|
2006-12-15 20:13:01 +00:00
|
|
|
return;
|
2014-04-27 23:59:25 +00:00
|
|
|
dbgs() << "[" << sys::TimeValue::now().str() << "] " << (void *)this
|
|
|
|
<< std::string(getDepth() * 2 + 1, ' ');
|
2007-03-05 20:01:30 +00:00
|
|
|
switch (S1) {
|
|
|
|
case EXECUTION_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "Executing Pass '" << P->getPassName();
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
case MODIFICATION_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "Made Modification '" << P->getPassName();
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
case FREEING_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << " Freeing Pass '" << P->getPassName();
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (S2) {
|
|
|
|
case ON_BASICBLOCK_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "' on BasicBlock '" << Msg << "'...\n";
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
case ON_FUNCTION_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "' on Function '" << Msg << "'...\n";
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
case ON_MODULE_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "' on Module '" << Msg << "'...\n";
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
2010-10-20 01:54:44 +00:00
|
|
|
case ON_REGION_MSG:
|
|
|
|
dbgs() << "' on Region '" << Msg << "'...\n";
|
|
|
|
break;
|
2007-03-05 20:01:30 +00:00
|
|
|
case ON_LOOP_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "' on Loop '" << Msg << "'...\n";
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
case ON_CG_MSG:
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
|
2007-03-05 20:01:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-12-15 20:13:01 +00:00
|
|
|
}
|
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
void PMDataManager::dumpRequiredSet(const Pass *P) const {
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging < Details)
|
2008-08-08 15:14:09 +00:00
|
|
|
return;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2008-08-08 15:14:09 +00:00
|
|
|
AnalysisUsage analysisUsage;
|
|
|
|
P->getAnalysisUsage(analysisUsage);
|
|
|
|
dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
|
|
|
|
}
|
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
void PMDataManager::dumpPreservedSet(const Pass *P) const {
|
2013-09-19 06:02:43 +00:00
|
|
|
if (PassDebugging < Details)
|
2008-08-08 15:14:09 +00:00
|
|
|
return;
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2008-08-08 15:14:09 +00:00
|
|
|
AnalysisUsage analysisUsage;
|
|
|
|
P->getAnalysisUsage(analysisUsage);
|
|
|
|
dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
|
|
|
|
}
|
|
|
|
|
2015-08-19 03:02:12 +00:00
|
|
|
void PMDataManager::dumpUsedSet(const Pass *P) const {
|
|
|
|
if (PassDebugging < Details)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AnalysisUsage analysisUsage;
|
|
|
|
P->getAnalysisUsage(analysisUsage);
|
|
|
|
dumpAnalysisUsage("Used", P, analysisUsage.getUsedSet());
|
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
|
2009-03-06 06:45:05 +00:00
|
|
|
const AnalysisUsage::VectorType &Set) const {
|
2013-09-19 06:02:43 +00:00
|
|
|
assert(PassDebugging >= Details);
|
2008-08-08 15:14:09 +00:00
|
|
|
if (Set.empty())
|
|
|
|
return;
|
2012-09-05 22:26:57 +00:00
|
|
|
dbgs() << (const void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
|
2009-03-06 06:45:05 +00:00
|
|
|
for (unsigned i = 0; i != Set.size(); ++i) {
|
2010-01-05 01:30:02 +00:00
|
|
|
if (i) dbgs() << ',';
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
const PassInfo *PInf = TPM->findAnalysisPassInfo(Set[i]);
|
2011-06-03 00:48:58 +00:00
|
|
|
if (!PInf) {
|
|
|
|
// Some preserved passes, such as AliasAnalysis, may not be initialized by
|
|
|
|
// all drivers.
|
|
|
|
dbgs() << " Uninitialized Pass";
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-06 18:33:48 +00:00
|
|
|
dbgs() << ' ' << PInf->getPassName();
|
2009-03-06 06:45:05 +00:00
|
|
|
}
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << '\n';
|
2006-12-15 20:13:01 +00:00
|
|
|
}
|
2006-12-08 23:28:54 +00:00
|
|
|
|
2007-07-27 20:06:09 +00: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 01:43:30 +00:00
|
|
|
|
2010-08-12 23:50:08 +00: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 01:43:30 +00: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-12 23:50:08 +00:00
|
|
|
// checks whether any lower level manager will be able to provide this
|
2008-02-02 01:43:30 +00:00
|
|
|
// analysis info on demand or not.
|
2008-06-03 01:20:02 +00:00
|
|
|
#ifndef NDEBUG
|
2010-01-05 01:30:02 +00:00
|
|
|
dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
|
|
|
|
dbgs() << "' required by '" << P->getPassName() << "'\n";
|
2008-06-03 01:20:02 +00:00
|
|
|
#endif
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unable to schedule pass");
|
2007-07-27 20:06:09 +00:00
|
|
|
}
|
|
|
|
|
2010-08-06 18:33:48 +00:00
|
|
|
Pass *PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F) {
|
2012-02-05 22:14:15 +00:00
|
|
|
llvm_unreachable("Unable to find on the fly pass");
|
2010-06-21 18:46:45 +00:00
|
|
|
}
|
|
|
|
|
2007-01-12 18:52:44 +00:00
|
|
|
// Destructor
|
|
|
|
PMDataManager::~PMDataManager() {
|
2010-10-12 00:11:18 +00:00
|
|
|
for (SmallVectorImpl<Pass *>::iterator I = PassVector.begin(),
|
2007-01-12 18:52:44 +00:00
|
|
|
E = PassVector.end(); I != E; ++I)
|
|
|
|
delete *I;
|
|
|
|
}
|
|
|
|
|
2006-12-08 23:28:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NOTE: Is this the right place to define this method ?
|
2009-01-28 13:14:17 +00:00
|
|
|
// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
|
|
|
|
Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
|
2006-12-08 23:28:54 +00:00
|
|
|
return PM.findAnalysisPass(ID, dir);
|
|
|
|
}
|
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
Pass *AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI,
|
2007-04-16 20:56:24 +00:00
|
|
|
Function &F) {
|
|
|
|
return PM.getOnTheFlyPass(P, AnalysisPI, F);
|
|
|
|
}
|
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-19 19:46:59 +00:00
|
|
|
// BBPassManager implementation
|
2006-11-07 21:31:57 +00:00
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// Execute all of the passes scheduled for execution by invoking
|
|
|
|
/// runOnBasicBlock method. Keep track of whether any of the passes modifies
|
2006-11-07 21:31:57 +00:00
|
|
|
/// the function, and if so, return true.
|
2009-03-06 06:45:05 +00:00
|
|
|
bool BBPassManager::runOnFunction(Function &F) {
|
2007-01-30 20:08:39 +00:00
|
|
|
if (F.isDeclaration())
|
2006-12-12 23:15:28 +00:00
|
|
|
return false;
|
|
|
|
|
2006-12-08 01:38:28 +00:00
|
|
|
bool Changed = doInitialization(F);
|
2006-11-14 01:23:29 +00:00
|
|
|
|
2006-11-07 21:31:57 +00:00
|
|
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2010-03-01 17:34:28 +00:00
|
|
|
bool LocalChanged = false;
|
2006-12-14 00:25:06 +00:00
|
|
|
|
2009-07-26 07:49:05 +00:00
|
|
|
dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getName());
|
2008-08-08 15:14:09 +00:00
|
|
|
dumpRequiredSet(BP);
|
2006-12-14 00:25:06 +00:00
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
initializeAnalysisImpl(BP);
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
{
|
|
|
|
// If the pass crashes, remember this.
|
|
|
|
PassManagerPrettyStackEntry X(BP, *I);
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRegion PassTimer(getPassTimer(BP));
|
|
|
|
|
2010-03-01 17:34:28 +00:00
|
|
|
LocalChanged |= BP->runOnBasicBlock(*I);
|
2009-03-06 06:45:05 +00:00
|
|
|
}
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2010-03-01 17:34:28 +00:00
|
|
|
Changed |= LocalChanged;
|
2010-08-12 23:50:08 +00:00
|
|
|
if (LocalChanged)
|
2008-01-29 12:09:55 +00:00
|
|
|
dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
|
2009-07-26 07:49:05 +00:00
|
|
|
I->getName());
|
2008-08-08 15:14:09 +00:00
|
|
|
dumpPreservedSet(BP);
|
2015-08-19 03:02:12 +00:00
|
|
|
dumpUsedSet(BP);
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2007-07-19 18:02:32 +00:00
|
|
|
verifyPreservedAnalysis(BP);
|
2006-12-16 00:56:26 +00:00
|
|
|
removeNotPreservedAnalysis(BP);
|
|
|
|
recordAvailableAnalysis(BP);
|
2009-07-26 07:49:05 +00:00
|
|
|
removeDeadPasses(BP, I->getName(), ON_BASICBLOCK_MSG);
|
2006-11-07 21:31:57 +00:00
|
|
|
}
|
2007-08-10 06:22:25 +00:00
|
|
|
|
2009-12-25 13:50:18 +00:00
|
|
|
return doFinalization(F) || Changed;
|
2006-11-07 21:31:57 +00:00
|
|
|
}
|
|
|
|
|
2006-12-08 00:59:05 +00:00
|
|
|
// Implement doInitialization and doFinalization
|
2009-02-13 09:42:34 +00:00
|
|
|
bool BBPassManager::doInitialization(Module &M) {
|
2006-12-08 00:59:05 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
|
|
|
|
Changed |= getContainedPass(Index)->doInitialization(M);
|
2006-12-08 00:59:05 +00:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 09:42:34 +00:00
|
|
|
bool BBPassManager::doFinalization(Module &M) {
|
2006-12-08 00:59:05 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2012-12-05 17:12:22 +00:00
|
|
|
for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
|
2009-03-06 06:45:05 +00:00
|
|
|
Changed |= getContainedPass(Index)->doFinalization(M);
|
2006-12-08 00:59:05 +00:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 09:42:34 +00:00
|
|
|
bool BBPassManager::doInitialization(Function &F) {
|
2006-12-08 00:59:05 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2006-12-08 00:59:05 +00:00
|
|
|
Changed |= BP->doInitialization(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 09:42:34 +00:00
|
|
|
bool BBPassManager::doFinalization(Function &F) {
|
2006-12-08 00:59:05 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
BasicBlockPass *BP = getContainedPass(Index);
|
2006-12-08 00:59:05 +00:00
|
|
|
Changed |= BP->doFinalization(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-13 02:36:01 +00:00
|
|
|
// FunctionPassManager implementation
|
2006-12-07 19:39:39 +00:00
|
|
|
|
2006-11-08 10:44:40 +00:00
|
|
|
/// Create new Function pass manager
|
2010-01-27 20:34:15 +00:00
|
|
|
FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
|
2011-08-29 17:07:00 +00:00
|
|
|
FPM = new FunctionPassManagerImpl();
|
2006-12-12 22:02:16 +00:00
|
|
|
// FPM is the top level manager.
|
|
|
|
FPM->setTopLevelManager(FPM);
|
2006-12-12 23:27:37 +00:00
|
|
|
|
2008-03-13 02:08:36 +00:00
|
|
|
AnalysisResolver *AR = new AnalysisResolver(*FPM);
|
2006-12-12 23:27:37 +00:00
|
|
|
FPM->setResolver(AR);
|
2006-12-08 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 02:36:01 +00:00
|
|
|
FunctionPassManager::~FunctionPassManager() {
|
2006-12-13 00:09:23 +00:00
|
|
|
delete FPM;
|
|
|
|
}
|
|
|
|
|
2010-08-12 23:50:08 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00:00
|
|
|
FPM->add(P);
|
2006-11-08 10:44:40 +00:00
|
|
|
}
|
|
|
|
|
2006-11-15 19:39:54 +00: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 02:36:01 +00:00
|
|
|
bool FunctionPassManager::run(Function &F) {
|
2014-11-01 16:46:18 +00:00
|
|
|
if (std::error_code EC = F.materialize())
|
|
|
|
report_fatal_error("Error reading bitcode file: " + EC.message());
|
2006-12-08 22:57:48 +00:00
|
|
|
return FPM->run(F);
|
2006-11-15 19:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-15 01:27:05 +00:00
|
|
|
/// doInitialization - Run all of the initializers for the function passes.
|
|
|
|
///
|
2006-12-13 02:36:01 +00:00
|
|
|
bool FunctionPassManager::doInitialization() {
|
2010-01-27 20:34:15 +00:00
|
|
|
return FPM->doInitialization(*M);
|
2006-11-15 01:27:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-30 14:51:13 +00:00
|
|
|
/// doFinalization - Run all of the finalizers for the function passes.
|
2006-11-15 01:27:05 +00:00
|
|
|
///
|
2006-12-13 02:36:01 +00:00
|
|
|
bool FunctionPassManager::doFinalization() {
|
2010-01-27 20:34:15 +00:00
|
|
|
return FPM->doFinalization(*M);
|
2006-11-15 01:27:05 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-19 19:46:59 +00:00
|
|
|
// FunctionPassManagerImpl implementation
|
|
|
|
//
|
2009-02-13 09:42:34 +00:00
|
|
|
bool FunctionPassManagerImpl::doInitialization(Module &M) {
|
2006-12-19 19:46:59 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2009-11-23 16:24:18 +00:00
|
|
|
dumpArguments();
|
|
|
|
dumpPasses();
|
|
|
|
|
2015-06-05 17:48:47 +00:00
|
|
|
for (ImmutablePass *ImPass : getImmutablePasses())
|
|
|
|
Changed |= ImPass->doInitialization(M);
|
2012-12-05 17:12:22 +00:00
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
|
|
|
Changed |= getContainedManager(Index)->doInitialization(M);
|
2006-12-19 19:46:59 +00:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 09:42:34 +00:00
|
|
|
bool FunctionPassManagerImpl::doFinalization(Module &M) {
|
2006-12-19 19:46:59 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2012-12-05 17:12:22 +00:00
|
|
|
for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
|
2009-03-06 06:45:05 +00:00
|
|
|
Changed |= getContainedManager(Index)->doFinalization(M);
|
2006-12-19 19:46:59 +00:00
|
|
|
|
2015-06-05 17:48:47 +00:00
|
|
|
for (ImmutablePass *ImPass : getImmutablePasses())
|
|
|
|
Changed |= ImPass->doFinalization(M);
|
2012-12-05 17:12:22 +00:00
|
|
|
|
2006-12-19 19:46:59 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-04-01 22:34:41 +00: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-29 18:49:09 +00: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-29 21:05:10 +00:00
|
|
|
wasRun = false;
|
2009-06-29 18:49:09 +00:00
|
|
|
}
|
|
|
|
|
2006-12-19 19:46:59 +00: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 00:16:50 +00:00
|
|
|
initializeAllAnalysisInfo();
|
2014-05-16 02:33:15 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
2009-03-06 06:45:05 +00:00
|
|
|
Changed |= getContainedManager(Index)->runOnFunction(F);
|
2014-05-16 02:33:15 +00:00
|
|
|
F.getContext().yield();
|
|
|
|
}
|
2009-04-01 22:34:41 +00:00
|
|
|
|
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
|
|
|
getContainedManager(Index)->cleanup();
|
|
|
|
|
2009-06-29 18:49:09 +00:00
|
|
|
wasRun = true;
|
2006-12-19 19:46:59 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPPassManager implementation
|
2006-11-07 21:49:50 +00:00
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char FPPassManager::ID = 0;
|
2007-01-12 18:52:44 +00:00
|
|
|
/// Print passes managed by this manager
|
|
|
|
void FPPassManager::dumpPassStructure(unsigned Offset) {
|
2011-10-16 16:30:34 +00:00
|
|
|
dbgs().indent(Offset*2) << "FunctionPass Manager\n";
|
2007-01-12 18:52:44 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
FunctionPass *FP = getContainedPass(Index);
|
2010-08-19 01:29:07 +00:00
|
|
|
FP->dumpPassStructure(Offset + 1);
|
2007-01-12 18:52:44 +00:00
|
|
|
dumpLastUses(FP, Offset+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// Execute all of the passes scheduled for execution by invoking
|
|
|
|
/// runOnFunction method. Keep track of whether any of the passes modifies
|
2006-11-07 21:49:50 +00:00
|
|
|
/// the function, and if so, return true.
|
2006-12-19 19:46:59 +00:00
|
|
|
bool FPPassManager::runOnFunction(Function &F) {
|
2009-03-06 05:53:14 +00:00
|
|
|
if (F.isDeclaration())
|
|
|
|
return false;
|
2006-11-15 19:39:54 +00:00
|
|
|
|
|
|
|
bool Changed = false;
|
2006-12-12 23:15:28 +00:00
|
|
|
|
2008-03-20 01:09:53 +00:00
|
|
|
// Collect inherited analysis from Module level pass manager.
|
|
|
|
populateInheritedAnalysis(TPM->activeStack);
|
2006-12-12 23:15:28 +00:00
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
FunctionPass *FP = getContainedPass(Index);
|
2010-03-01 17:34:28 +00:00
|
|
|
bool LocalChanged = false;
|
2006-12-16 00:56:26 +00:00
|
|
|
|
2009-07-26 07:49:05 +00:00
|
|
|
dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
|
2008-08-08 15:14:09 +00:00
|
|
|
dumpRequiredSet(FP);
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
initializeAnalysisImpl(FP);
|
2012-03-23 03:54:05 +00:00
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
{
|
|
|
|
PassManagerPrettyStackEntry X(FP, F);
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRegion PassTimer(getPassTimer(FP));
|
2009-03-06 06:45:05 +00:00
|
|
|
|
2010-03-01 17:34:28 +00:00
|
|
|
LocalChanged |= FP->runOnFunction(F);
|
2009-03-06 06:45:05 +00:00
|
|
|
}
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2010-03-01 17:34:28 +00:00
|
|
|
Changed |= LocalChanged;
|
|
|
|
if (LocalChanged)
|
2009-07-26 07:49:05 +00:00
|
|
|
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
|
2008-08-08 15:14:09 +00:00
|
|
|
dumpPreservedSet(FP);
|
2015-08-19 03:02:12 +00:00
|
|
|
dumpUsedSet(FP);
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2007-07-19 18:02:32 +00:00
|
|
|
verifyPreservedAnalysis(FP);
|
2006-12-16 00:56:26 +00:00
|
|
|
removeNotPreservedAnalysis(FP);
|
|
|
|
recordAvailableAnalysis(FP);
|
2009-07-26 07:49:05 +00:00
|
|
|
removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
|
2006-11-15 19:39:54 +00:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2006-12-19 19:46:59 +00:00
|
|
|
bool FPPassManager::runOnModule(Module &M) {
|
2012-11-29 17:47:05 +00:00
|
|
|
bool Changed = false;
|
2006-12-19 19:46:59 +00:00
|
|
|
|
2015-06-05 14:15:07 +00:00
|
|
|
for (Function &F : M)
|
|
|
|
Changed |= runOnFunction(F);
|
2006-12-19 19:46:59 +00:00
|
|
|
|
2012-11-29 17:47:05 +00:00
|
|
|
return Changed;
|
2006-12-19 19:46:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-13 09:42:34 +00:00
|
|
|
bool FPPassManager::doInitialization(Module &M) {
|
2006-11-15 01:27:05 +00:00
|
|
|
bool Changed = false;
|
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
|
|
|
|
Changed |= getContainedPass(Index)->doInitialization(M);
|
2013-09-18 23:31:10 +00:00
|
|
|
|
2006-11-15 01:27:05 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2009-02-13 09:42:34 +00:00
|
|
|
bool FPPassManager::doFinalization(Module &M) {
|
2006-11-15 01:27:05 +00:00
|
|
|
bool Changed = false;
|
2012-12-05 17:12:22 +00:00
|
|
|
|
|
|
|
for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
|
2009-03-06 06:45:05 +00:00
|
|
|
Changed |= getContainedPass(Index)->doFinalization(M);
|
2013-09-18 23:31:10 +00:00
|
|
|
|
2006-11-15 01:27:05 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-12-19 19:46:59 +00:00
|
|
|
// MPPassManager implementation
|
2006-11-07 22:03:15 +00:00
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// Execute all of the passes scheduled for execution by invoking
|
|
|
|
/// runOnModule method. Keep track of whether any of the passes modifies
|
2006-11-07 22:03:15 +00:00
|
|
|
/// the module, and if so, return true.
|
|
|
|
bool
|
2006-12-19 19:46:59 +00:00
|
|
|
MPPassManager::runOnModule(Module &M) {
|
2006-11-07 22:03:15 +00:00
|
|
|
bool Changed = false;
|
2006-11-14 01:23:29 +00:00
|
|
|
|
2009-06-29 18:49:09 +00:00
|
|
|
// Initialize on-the-fly passes
|
2015-06-05 14:15:07 +00:00
|
|
|
for (auto &OnTheFlyManager : OnTheFlyManagers) {
|
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
2009-06-29 18:49:09 +00:00
|
|
|
Changed |= FPP->doInitialization(M);
|
|
|
|
}
|
|
|
|
|
2012-11-29 17:47:05 +00:00
|
|
|
// Initialize module passes
|
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
|
|
|
|
Changed |= getContainedPass(Index)->doInitialization(M);
|
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
|
|
|
ModulePass *MP = getContainedPass(Index);
|
2010-03-01 17:34:28 +00:00
|
|
|
bool LocalChanged = false;
|
2006-12-16 00:56:26 +00:00
|
|
|
|
2009-12-08 13:07:38 +00:00
|
|
|
dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
|
2008-08-08 15:14:09 +00:00
|
|
|
dumpRequiredSet(MP);
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2006-12-16 00:56:26 +00:00
|
|
|
initializeAnalysisImpl(MP);
|
2006-12-14 00:59:42 +00:00
|
|
|
|
2009-03-06 06:45:05 +00:00
|
|
|
{
|
|
|
|
PassManagerPrettyStackEntry X(MP, M);
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRegion PassTimer(getPassTimer(MP));
|
|
|
|
|
2010-03-01 17:34:28 +00:00
|
|
|
LocalChanged |= MP->runOnModule(M);
|
2009-03-06 06:45:05 +00:00
|
|
|
}
|
2006-12-14 00:08:04 +00:00
|
|
|
|
2010-03-01 17:34:28 +00:00
|
|
|
Changed |= LocalChanged;
|
|
|
|
if (LocalChanged)
|
2008-01-29 12:09:55 +00:00
|
|
|
dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
|
2009-12-08 13:07:38 +00:00
|
|
|
M.getModuleIdentifier());
|
2008-08-08 15:14:09 +00:00
|
|
|
dumpPreservedSet(MP);
|
2015-08-19 03:02:12 +00:00
|
|
|
dumpUsedSet(MP);
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2007-07-19 18:02:32 +00:00
|
|
|
verifyPreservedAnalysis(MP);
|
2006-12-16 00:56:26 +00:00
|
|
|
removeNotPreservedAnalysis(MP);
|
|
|
|
recordAvailableAnalysis(MP);
|
2009-12-08 13:07:38 +00:00
|
|
|
removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
|
2006-11-07 22:03:15 +00:00
|
|
|
}
|
2009-06-29 18:49:09 +00:00
|
|
|
|
2012-11-29 17:47:05 +00:00
|
|
|
// Finalize module passes
|
2012-12-05 17:12:22 +00:00
|
|
|
for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index)
|
2012-11-29 17:47:05 +00:00
|
|
|
Changed |= getContainedPass(Index)->doFinalization(M);
|
|
|
|
|
2009-06-29 18:49:09 +00:00
|
|
|
// Finalize on-the-fly passes
|
2015-06-05 14:15:07 +00:00
|
|
|
for (auto &OnTheFlyManager : OnTheFlyManagers) {
|
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
2009-06-29 18:49:09 +00:00
|
|
|
// 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-18 23:31:10 +00:00
|
|
|
|
2006-11-07 22:03:15 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2007-04-16 20:12:57 +00: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 05:53:14 +00:00
|
|
|
assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
|
|
|
|
"Unable to handle Pass that requires lower level Analysis pass");
|
2010-08-12 23:50:08 +00:00
|
|
|
assert((P->getPotentialPassManagerType() <
|
2009-03-06 05:53:14 +00:00
|
|
|
RequiredPass->getPotentialPassManagerType()) &&
|
|
|
|
"Unable to handle Pass that requires lower level Analysis pass");
|
2014-04-08 03:40:34 +00:00
|
|
|
if (!RequiredPass)
|
|
|
|
return;
|
2007-04-16 20:12:57 +00:00
|
|
|
|
2007-04-26 17:50:19 +00:00
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
|
2007-04-16 20:27:05 +00:00
|
|
|
if (!FPP) {
|
2011-08-29 17:07:00 +00:00
|
|
|
FPP = new FunctionPassManagerImpl();
|
2007-04-26 17:50:19 +00:00
|
|
|
// FPP is the top level manager.
|
|
|
|
FPP->setTopLevelManager(FPP);
|
|
|
|
|
2007-04-16 20:27:05 +00:00
|
|
|
OnTheFlyManagers[P] = FPP;
|
|
|
|
}
|
[LPM] A targeted but somewhat horrible fix to the legacy pass manager's
querying of the pass registry.
The pass manager relies on the static registry of PassInfo objects to
perform all manner of its functionality. I don't understand why it does
much of this. My very vague understanding is that this registry is
touched both during static initialization *and* while each pass is being
constructed. As a consequence it is hard to make accessing it not
require a acquiring some lock. This lock ends up in the hot path of
setting up, tearing down, and invaliditing analyses in the legacy pass
manager.
On most systems you can observe this as a non-trivial % of the time
spent in 'ninja check-llvm'. However, I haven't really seen it be more
than 1% in extreme cases of compiling more real-world software,
including LTO.
Unfortunately, some of the GPU JITs are seeing this taking essentially
all of their time because they have very small IR running through
a small pass pipeline very many times (at least, this is the vague
understanding I have of it).
This patch tries to minimize the cost of looking up PassInfo objects by
leveraging the fact that the objects themselves are immutable and they
are allocated separately on the heap and so don't have their address
change. It also requires a change I made the last time I tried to debug
this problem which removed the ability to de-register a pass from the
registry. This patch creates a single access path to these objects
inside the PMTopLevelManager which memoizes the result of querying the
registry. This is somewhat gross as I don't really know if
PMTopLevelManager is the *right* place to put it, and I dislike using
a mutable member to memoize things, but it seems to work.
For long-lived pass managers this should completely eliminate
the cost of acquiring locks to look into the pass registry once the
memoized cache is warm. For 'ninja check' I measured about 1.5%
reduction in CPU time and in total time on a machine with 32 hardware
threads. For normal compilation, I don't know how much this will help,
sadly. We will still pay the cost while we populate the memoized cache.
I don't think it will hurt though, and for LTO or compiles with many
small functions it should still be a win. However, for tight loops
around a pass manager with many passes and small modules, this will help
tremendously. On the AArch64 backend I saw nearly 50% reductions in time
to complete 2000 cycles of spinning up and tearing down the pipeline.
Measurements from Owen of an actual long-lived pass manager show more
along the lines of 10% improvements.
Differential Revision: http://reviews.llvm.org/D7213
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-28 09:47:21 +00:00
|
|
|
const PassInfo *RequiredPassPI =
|
|
|
|
TPM->findAnalysisPassInfo(RequiredPass->getPassID());
|
2007-04-16 20:27:05 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
Pass *FoundPass = nullptr;
|
2014-04-08 03:40:34 +00:00
|
|
|
if (RequiredPassPI && RequiredPassPI->isAnalysis()) {
|
|
|
|
FoundPass =
|
|
|
|
((PMTopLevelManager*)FPP)->findAnalysisPass(RequiredPass->getPassID());
|
|
|
|
}
|
|
|
|
if (!FoundPass) {
|
|
|
|
FoundPass = RequiredPass;
|
|
|
|
// This should be guaranteed to add RequiredPass to the passmanager given
|
2014-08-11 18:04:46 +00:00
|
|
|
// that we checked for an available analysis above.
|
2014-04-08 03:40:34 +00:00
|
|
|
FPP->add(RequiredPass);
|
2011-09-13 21:13:29 +00:00
|
|
|
}
|
2014-04-08 03:40:34 +00:00
|
|
|
// Register P as the last user of FoundPass or RequiredPass.
|
|
|
|
SmallVector<Pass *, 1> LU;
|
|
|
|
LU.push_back(FoundPass);
|
|
|
|
FPP->setLastUser(LU, P);
|
2007-04-16 20:12:57 +00:00
|
|
|
}
|
2007-04-16 20:27:05 +00:00
|
|
|
|
2010-08-12 23:50:08 +00:00
|
|
|
/// Return function pass corresponding to PassInfo PI, that is
|
2007-04-16 20:27:05 +00:00
|
|
|
/// required by module pass MP. Instantiate analysis pass, by using
|
|
|
|
/// its runOnFunction() for function F.
|
2010-08-06 18:33:48 +00:00
|
|
|
Pass* MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F){
|
2007-04-26 17:50:19 +00:00
|
|
|
FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
|
2009-03-06 05:53:14 +00:00
|
|
|
assert(FPP && "Unable to find on the fly pass");
|
2010-08-12 23:50:08 +00:00
|
|
|
|
2009-06-29 18:49:09 +00:00
|
|
|
FPP->releaseMemoryOnTheFly();
|
2007-04-26 17:50:19 +00:00
|
|
|
FPP->run(F);
|
2010-01-22 05:37:10 +00:00
|
|
|
return ((PMTopLevelManager*)FPP)->findAnalysisPass(PI);
|
2007-04-16 20:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManagerImpl implementation
|
2012-11-15 00:14:15 +00:00
|
|
|
|
2006-12-13 00:09:23 +00:00
|
|
|
//
|
2006-11-07 22:23:34 +00: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-19 19:46:59 +00:00
|
|
|
bool PassManagerImpl::run(Module &M) {
|
2006-11-07 22:23:34 +00:00
|
|
|
bool Changed = false;
|
2006-12-14 00:59:42 +00:00
|
|
|
TimingInfo::createTheTimeInfo();
|
|
|
|
|
2006-12-13 22:10:00 +00:00
|
|
|
dumpArguments();
|
2006-12-19 19:46:59 +00:00
|
|
|
dumpPasses();
|
2006-12-13 20:03:48 +00:00
|
|
|
|
2015-06-05 14:15:07 +00:00
|
|
|
for (ImmutablePass *ImPass : getImmutablePasses())
|
|
|
|
Changed |= ImPass->doInitialization(M);
|
2012-12-05 17:12:22 +00:00
|
|
|
|
2006-12-21 00:16:50 +00:00
|
|
|
initializeAllAnalysisInfo();
|
2014-05-16 02:33:15 +00:00
|
|
|
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
2009-03-06 06:45:05 +00:00
|
|
|
Changed |= getContainedManager(Index)->runOnModule(M);
|
2014-05-16 02:33:15 +00:00
|
|
|
M.getContext().yield();
|
|
|
|
}
|
2012-12-05 17:12:22 +00:00
|
|
|
|
2015-06-05 14:15:07 +00:00
|
|
|
for (ImmutablePass *ImPass : getImmutablePasses())
|
|
|
|
Changed |= ImPass->doFinalization(M);
|
2012-12-05 17:12:22 +00:00
|
|
|
|
2006-11-07 22:23:34 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
2006-11-08 10:29:57 +00:00
|
|
|
|
2006-12-07 19:39:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PassManager implementation
|
|
|
|
|
2006-11-08 10:29:57 +00:00
|
|
|
/// Create new pass manager
|
2006-12-13 02:36:01 +00:00
|
|
|
PassManager::PassManager() {
|
2011-08-29 17:07:00 +00:00
|
|
|
PM = new PassManagerImpl();
|
2006-12-12 22:02:16 +00:00
|
|
|
// PM is the top level manager
|
|
|
|
PM->setTopLevelManager(PM);
|
2006-11-08 10:29:57 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 02:36:01 +00:00
|
|
|
PassManager::~PassManager() {
|
2006-12-13 00:09:23 +00:00
|
|
|
delete PM;
|
|
|
|
}
|
|
|
|
|
2009-03-06 05:53:14 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00:00
|
|
|
PM->add(P);
|
2006-11-08 10:29:57 +00: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 05:53:14 +00:00
|
|
|
bool PassManager::run(Module &M) {
|
2006-11-08 10:29:57 +00:00
|
|
|
return PM->run(M);
|
|
|
|
}
|
|
|
|
|
2006-12-14 00:59:42 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2013-04-03 15:33:45 +00:00
|
|
|
// TimingInfo implementation
|
|
|
|
|
2013-09-19 06:02:43 +00: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 00:59:42 +00:00
|
|
|
// createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
|
2013-12-05 05:44:44 +00:00
|
|
|
// a non-null value (if the -time-passes option is enabled) or it leaves it
|
2006-12-14 00:59:42 +00:00
|
|
|
// null. It may be called multiple times.
|
|
|
|
void TimingInfo::createTheTimeInfo() {
|
|
|
|
if (!TimePassesIsEnabled || TheTimeInfo) return;
|
|
|
|
|
2012-09-27 10:14:43 +00:00
|
|
|
// Constructed the first time this is called, iff -time-passes is enabled.
|
2006-12-14 00:59:42 +00: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-29 23:10:37 +00:00
|
|
|
/// If TimingInfo is enabled then start pass timer.
|
2010-03-30 04:03:22 +00:00
|
|
|
Timer *llvm::getPassTimer(Pass *P) {
|
2010-08-12 23:50:08 +00:00
|
|
|
if (TheTimeInfo)
|
2010-03-30 04:03:22 +00:00
|
|
|
return TheTimeInfo->getPassTimer(P);
|
2014-04-09 06:08:46 +00:00
|
|
|
return nullptr;
|
2007-01-29 23:10:37 +00:00
|
|
|
}
|
|
|
|
|
2007-01-08 19:29:38 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PMStack implementation
|
|
|
|
//
|
2007-01-11 22:15:30 +00:00
|
|
|
|
2007-01-08 19:29:38 +00: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 01:21:31 +00:00
|
|
|
void PMStack::push(PMDataManager *PM) {
|
2009-03-06 05:53:14 +00:00
|
|
|
assert(PM && "Unable to push. Pass Manager expected");
|
2011-08-29 17:07:00 +00:00
|
|
|
assert(PM->getDepth()==0 && "Pass Manager depth set too early");
|
2007-01-08 19:29:38 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
if (!this->empty()) {
|
2011-08-29 17:07:00 +00:00
|
|
|
assert(PM->getPassManagerType() > this->top()->getPassManagerType()
|
|
|
|
&& "pushing bad pass manager to PMStack");
|
2009-03-06 05:53:14 +00:00
|
|
|
PMTopLevelManager *TPM = this->top()->getTopLevelManager();
|
2007-01-11 00:19:00 +00:00
|
|
|
|
2009-03-06 05:53:14 +00:00
|
|
|
assert(TPM && "Unable to find top level manager");
|
2007-01-11 00:19:00 +00:00
|
|
|
TPM->addIndirectPassManager(PM);
|
|
|
|
PM->setTopLevelManager(TPM);
|
2011-08-29 17:07:00 +00:00
|
|
|
PM->setDepth(this->top()->getDepth()+1);
|
2013-02-06 06:50:38 +00:00
|
|
|
} else {
|
2011-08-29 18:14:15 +00:00
|
|
|
assert((PM->getPassManagerType() == PMT_ModulePassManager
|
|
|
|
|| PM->getPassManagerType() == PMT_FunctionPassManager)
|
2011-08-29 17:07:00 +00:00
|
|
|
&& "pushing bad pass manager to PMStack");
|
|
|
|
PM->setDepth(1);
|
2007-01-11 00:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
S.push_back(PM);
|
|
|
|
}
|
2007-01-08 19:29:38 +00:00
|
|
|
|
2007-01-11 00:19:00 +00:00
|
|
|
// Dump content of the pass manager stack.
|
2016-01-29 20:50:44 +00:00
|
|
|
LLVM_DUMP_METHOD void PMStack::dump() const {
|
2015-06-05 17:48:47 +00:00
|
|
|
for (PMDataManager *Manager : S)
|
|
|
|
dbgs() << Manager->getAsPass()->getPassName() << ' ';
|
2009-03-06 05:53:14 +00:00
|
|
|
|
2007-01-11 00:19:00 +00:00
|
|
|
if (!S.empty())
|
2011-08-29 18:14:17 +00:00
|
|
|
dbgs() << '\n';
|
2007-01-08 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Find appropriate Module Pass Manager in the PM Stack and
|
2010-08-12 23:50:08 +00:00
|
|
|
/// add self into that manager.
|
|
|
|
void ModulePass::assignPassManager(PMStack &PMS,
|
2007-04-16 18:10:23 +00:00
|
|
|
PassManagerType PreferredType) {
|
2007-01-08 19:29:38 +00:00
|
|
|
// Find Module Pass Manager
|
2010-08-12 23:50:08 +00:00
|
|
|
while (!PMS.empty()) {
|
2007-01-17 21:19:23 +00:00
|
|
|
PassManagerType TopPMType = PMS.top()->getPassManagerType();
|
|
|
|
if (TopPMType == PreferredType)
|
|
|
|
break; // We found desired pass manager
|
|
|
|
else if (TopPMType > PMT_ModulePassManager)
|
2007-01-08 19:29:38 +00:00
|
|
|
PMS.pop(); // Pop children pass managers
|
2007-01-11 19:59:06 +00:00
|
|
|
else
|
|
|
|
break;
|
2007-01-08 19:29:38 +00:00
|
|
|
}
|
2008-09-09 21:38:40 +00:00
|
|
|
assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
|
2007-01-17 21:19:23 +00:00
|
|
|
PMS.top()->add(this);
|
2007-01-08 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
/// Find appropriate Function Pass Manager or Call Graph Pass Manager
|
2010-08-12 23:50:08 +00:00
|
|
|
/// in the PM Stack and add self into that manager.
|
2007-01-17 20:30:17 +00:00
|
|
|
void FunctionPass::assignPassManager(PMStack &PMS,
|
2007-04-16 18:10:23 +00:00
|
|
|
PassManagerType PreferredType) {
|
2007-01-08 19:29:38 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:16:20 +00:00
|
|
|
// Find Function Pass Manager
|
2010-01-22 05:37:10 +00:00
|
|
|
while (!PMS.empty()) {
|
2007-01-11 19:59:06 +00:00
|
|
|
if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
|
|
|
|
PMS.pop();
|
2007-01-08 19:29:38 +00:00
|
|
|
else
|
2010-08-12 23:50:08 +00:00
|
|
|
break;
|
2007-01-08 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 05:37:10 +00:00
|
|
|
// Create new Function Pass Manager if needed.
|
|
|
|
FPPassManager *FPP;
|
|
|
|
if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
|
|
|
|
FPP = (FPPassManager *)PMS.top();
|
|
|
|
} else {
|
2007-01-16 21:43:18 +00:00
|
|
|
assert(!PMS.empty() && "Unable to create Function Pass Manager");
|
|
|
|
PMDataManager *PMD = PMS.top();
|
2007-01-11 00:19:00 +00:00
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
// [1] Create new Function Pass Manager
|
2011-08-29 17:07:00 +00:00
|
|
|
FPP = new FPPassManager();
|
2008-03-20 01:09:53 +00:00
|
|
|
FPP->populateInheritedAnalysis(PMS);
|
2007-01-11 00:19:00 +00:00
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
// [2] Set up new manager's top level manager
|
|
|
|
PMTopLevelManager *TPM = PMD->getTopLevelManager();
|
|
|
|
TPM->addIndirectPassManager(FPP);
|
2007-01-11 00:19:00 +00:00
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
// [3] Assign manager to manage this new manager. This may create
|
|
|
|
// and push new managers into PMS
|
2008-09-09 17:56:50 +00:00
|
|
|
FPP->assignPassManager(PMS, PMD->getPassManagerType());
|
2007-01-16 21:43:18 +00:00
|
|
|
|
|
|
|
// [4] Push new manager into PMS
|
|
|
|
PMS.push(FPP);
|
|
|
|
}
|
2007-01-08 19:29:38 +00:00
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
// Assign FPP as the manager of this pass.
|
|
|
|
FPP->add(this);
|
2007-01-08 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
/// Find appropriate Basic Pass Manager or Call Graph Pass Manager
|
2010-08-12 23:50:08 +00:00
|
|
|
/// in the PM Stack and add self into that manager.
|
2007-01-17 20:30:17 +00:00
|
|
|
void BasicBlockPass::assignPassManager(PMStack &PMS,
|
2007-04-16 18:10:23 +00:00
|
|
|
PassManagerType PreferredType) {
|
2010-01-22 05:37:10 +00:00
|
|
|
BBPassManager *BBP;
|
2007-01-08 19:29:38 +00:00
|
|
|
|
2007-01-11 00:19:00 +00:00
|
|
|
// Basic Pass Manager is a leaf pass manager. It does not handle
|
|
|
|
// any other pass manager.
|
2010-08-12 23:50:08 +00:00
|
|
|
if (!PMS.empty() &&
|
2010-01-22 05:37:10 +00: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-16 21:43:18 +00:00
|
|
|
assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
|
|
|
|
PMDataManager *PMD = PMS.top();
|
|
|
|
|
|
|
|
// [1] Create new Basic Block Manager
|
2011-08-29 17:07:00 +00:00
|
|
|
BBP = new BBPassManager();
|
2007-01-16 21:43:18 +00: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 00:19:00 +00:00
|
|
|
|
|
|
|
// [3] Assign manager to manage this new manager. This may create
|
|
|
|
// and push new managers into PMS
|
2010-05-10 20:24:27 +00:00
|
|
|
BBP->assignPassManager(PMS, PreferredType);
|
2007-01-16 19:46:09 +00:00
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
// [4] Push new manager into PMS
|
|
|
|
PMS.push(BBP);
|
|
|
|
}
|
2007-01-08 19:29:38 +00:00
|
|
|
|
2007-01-16 21:43:18 +00:00
|
|
|
// Assign BBP as the manager of this pass.
|
|
|
|
BBP->add(this);
|
2007-01-08 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 16:41:42 +00:00
|
|
|
PassManagerBase::~PassManagerBase() {}
|