Initialize the passes early and properly.

llvm-svn: 141455
This commit is contained in:
Tobias Grosser 2011-10-08 00:30:40 +00:00
parent 6ddf7f443e
commit 73600b8edd
18 changed files with 201 additions and 92 deletions

View File

@ -61,4 +61,9 @@ namespace polly {
virtual void releaseMemory();
};
}
namespace llvm {
class PassRegistry;
void initializeCloogInfoPass(llvm::PassRegistry&);
}
#endif /* POLLY_CLOOG_H */

View File

@ -108,4 +108,9 @@ namespace polly {
};
} // End polly namespace.
namespace llvm {
class PassRegistry;
void initializeDependencesPass(llvm::PassRegistry&);
}
#endif

View File

@ -21,6 +21,7 @@
namespace llvm {
class Pass;
class PassInfo;
class PassRegistry;
class RegionPass;
}
@ -31,7 +32,7 @@ namespace polly {
Pass *createCloogExporterPass();
Pass *createCloogInfoPass();
Pass *createCodeGenerationPass();
Pass *createCodePreperationPass();
Pass *createCodePreparationPass();
Pass *createDependencesPass();
Pass *createDOTOnlyPrinterPass();
Pass *createDOTOnlyViewerPass();
@ -43,7 +44,7 @@ namespace polly {
Pass *createRegionSimplifyPass();
Pass *createScopDetectionPass();
Pass *createScopInfoPass();
Pass *createScheduleOptimizerPass();
Pass *createIslScheduleOptimizerPass();
Pass *createTempScopInfoPass();
#ifdef OPENSCOP_FOUND
@ -58,7 +59,7 @@ namespace polly {
#endif
extern char &IndependentBlocksID;
extern char &CodePreperationID;
extern char &CodePreparationID;
}
using namespace polly;
@ -77,7 +78,7 @@ namespace {
createCloogExporterPass();
createCloogInfoPass();
createCodeGenerationPass();
createCodePreperationPass();
createCodePreparationPass();
createDependencesPass();
createDOTOnlyPrinterPass();
createDOTOnlyViewerPass();
@ -89,7 +90,7 @@ namespace {
createRegionSimplifyPass();
createScopDetectionPass();
createScopInfoPass();
createScheduleOptimizerPass();
createIslScheduleOptimizerPass();
createTempScopInfoPass();
#ifdef OPENSCOP_FOUND
@ -106,4 +107,16 @@ namespace {
} PollyForcePassLinking; // Force link by creating a global definition.
}
namespace llvm {
class PassRegistry;
void initializeCodeGenerationPass(llvm::PassRegistry&);
void initializeCodePreparationPass(llvm::PassRegistry&);
void initializeIndependentBlocksPass(llvm::PassRegistry&);
void initializeIslScheduleOptimizerPass(llvm::PassRegistry&);
#ifdef SCOPLIB_FOUND
void initializePoccPass(llvm::PassRegistry&);
#endif
void initializeRegionSimplifyPass(llvm::PassRegistry&);
}
#endif

View File

@ -273,4 +273,9 @@ public:
} //end namespace polly
namespace llvm {
class PassRegistry;
void initializeScopDetectionPass(llvm::PassRegistry&);
}
#endif

View File

@ -29,13 +29,13 @@
using namespace llvm;
namespace llvm {
class SCEV;
class ScalarEvolution;
class SCEVAddRecExpr;
class Loop;
class LoopInfo;
class Type;
class PHINode;
class ScalarEvolution;
class SCEV;
class SCEVAddRecExpr;
class Type;
}
struct isl_map;
@ -596,4 +596,9 @@ public:
} //end namespace polly
namespace llvm {
class PassRegistry;
void initializeScopInfoPass(llvm::PassRegistry&);
}
#endif

View File

@ -386,5 +386,9 @@ public:
} // end namespace polly
namespace llvm {
class PassRegistry;
void initializeTempScopInfoPass(llvm::PassRegistry&);
}
#endif

View File

@ -448,8 +448,11 @@ void Dependences::getAnalysisUsage(AnalysisUsage &AU) const {
char Dependences::ID = 0;
static RegisterPass<Dependences>
X("polly-dependences", "Polly - Calculate dependences for Scop");
INITIALIZE_PASS_BEGIN(Dependences, "polly-dependences",
"Polly - Calculate dependences", false, false)
INITIALIZE_PASS_DEPENDENCY(ScopInfo)
INITIALIZE_PASS_END(Dependences, "polly-dependences",
"Polly - Calculate dependences", false, false)
Pass* polly::createDependencesPass() {
return new Dependences();

View File

@ -650,8 +650,17 @@ void ScopDetection::releaseMemory() {
char ScopDetection::ID = 0;
static RegisterPass<ScopDetection>
X("polly-detect", "Polly - Detect Scops in functions");
INITIALIZE_PASS_BEGIN(ScopDetection, "polly-detect",
"Polly - Detect static control parts (SCoPs)", false,
false)
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
INITIALIZE_PASS_DEPENDENCY(RegionInfo)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
INITIALIZE_PASS_END(ScopDetection, "polly-detect",
"Polly - Detect static control parts (SCoPs)", false, false)
Pass *polly::createScopDetectionPass() {
return new ScopDetection();

View File

@ -1064,9 +1064,16 @@ bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
char ScopInfo::ID = 0;
static RegisterPass<ScopInfo>
X("polly-scops", "Polly - Create polyhedral description of Scops");
INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops",
"Polly - Create polyhedral description of Scops", false,
false)
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
INITIALIZE_PASS_DEPENDENCY(RegionInfo)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
INITIALIZE_PASS_DEPENDENCY(TempScopInfo)
INITIALIZE_PASS_END(ScopInfo, "polly-scops",
"Polly - Create polyhedral description of Scops", false,
false)
Pass *polly::createScopInfoPass() {
return new ScopInfo();

View File

@ -457,8 +457,19 @@ void TempScopInfo::clear() {
// TempScop information extraction pass implement
char TempScopInfo::ID = 0;
static RegisterPass<TempScopInfo>
X("polly-analyze-ir", "Polly - Analyse the LLVM-IR in the detected regions");
INITIALIZE_PASS_BEGIN(TempScopInfo, "polly-analyze-ir",
"Polly - Analyse the LLVM-IR in the detected regions",
false, false)
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
INITIALIZE_PASS_DEPENDENCY(RegionInfo)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
INITIALIZE_PASS_DEPENDENCY(TargetData)
INITIALIZE_PASS_END(TempScopInfo, "polly-analyze-ir",
"Polly - Analyse the LLVM-IR in the detected regions",
false, false)
Pass *polly::createTempScopInfoPass() {
return new TempScopInfo();

View File

@ -297,9 +297,11 @@ void CloogInfo::getAnalysisUsage(AnalysisUsage &AU) const {
}
char CloogInfo::ID = 0;
static RegisterPass<CloogInfo> B("polly-cloog",
"Execute Cloog code generation");
INITIALIZE_PASS_BEGIN(CloogInfo, "polly-cloog",
"Execute Cloog code generation", false, false)
INITIALIZE_PASS_DEPENDENCY(ScopInfo)
INITIALIZE_PASS_END(CloogInfo, "polly-cloog",
"Execute Cloog code generation", false, false)
Pass* polly::createCloogInfoPass() {
return new CloogInfo();

View File

@ -1567,8 +1567,8 @@ class CodeGeneration : public ScopPass {
AU.addRequired<CloogInfo>();
AU.addRequired<Dependences>();
AU.addRequired<DominatorTree>();
AU.addRequired<ScalarEvolution>();
AU.addRequired<RegionInfo>();
AU.addRequired<ScalarEvolution>();
AU.addRequired<ScopDetection>();
AU.addRequired<ScopInfo>();
AU.addRequired<TargetData>();
@ -1594,8 +1594,17 @@ class CodeGeneration : public ScopPass {
char CodeGeneration::ID = 1;
static RegisterPass<CodeGeneration>
Z("polly-codegen", "Polly - Create LLVM-IR from the polyhedral information");
INITIALIZE_PASS_BEGIN(CodeGeneration, "polly-codegen",
"Polly - Create LLVM-IR form SCoPs", false, false)
INITIALIZE_PASS_DEPENDENCY(CloogInfo)
INITIALIZE_PASS_DEPENDENCY(Dependences)
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
INITIALIZE_PASS_DEPENDENCY(RegionInfo)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
INITIALIZE_PASS_DEPENDENCY(ScopDetection)
INITIALIZE_PASS_DEPENDENCY(TargetData)
INITIALIZE_PASS_END(CodeGeneration, "polly-codegen",
"Polly - Create LLVM-IR form SCoPs", false, false)
Pass* polly::createCodeGenerationPass() {
return new CodeGeneration();

View File

@ -39,11 +39,11 @@ namespace {
/// @brief Scop Code Preparation - Perform some transforms to make scop detect
/// easier.
///
class CodePreperation : public FunctionPass {
class CodePreparation : public FunctionPass {
// DO NOT IMPLEMENT.
CodePreperation(const CodePreperation &);
CodePreparation(const CodePreparation &);
// DO NOT IMPLEMENT.
const CodePreperation &operator=(const CodePreperation &);
const CodePreparation &operator=(const CodePreparation &);
// LoopInfo to compute canonical induction variable.
LoopInfo *LI;
@ -56,8 +56,8 @@ class CodePreperation : public FunctionPass {
public:
static char ID;
explicit CodePreperation() : FunctionPass(ID) {}
~CodePreperation();
explicit CodePreparation() : FunctionPass(ID) {}
~CodePreparation();
/// @name FunctionPass interface.
//@{
@ -71,16 +71,16 @@ public:
}
//===----------------------------------------------------------------------===//
/// CodePreperation implement.
/// CodePreparation implement.
void CodePreperation::clear() {
void CodePreparation::clear() {
}
CodePreperation::~CodePreperation() {
CodePreparation::~CodePreparation() {
clear();
}
bool CodePreperation::eliminatePHINodes(Function &F) {
bool CodePreparation::eliminatePHINodes(Function &F) {
// The PHINodes that will be deleted.
std::vector<PHINode*> PNtoDel;
// The PHINodes that will be preserved.
@ -134,7 +134,7 @@ bool CodePreperation::eliminatePHINodes(Function &F) {
return true;
}
void CodePreperation::getAnalysisUsage(AnalysisUsage &AU) const {
void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfo>();
AU.addPreserved<LoopInfo>();
@ -143,7 +143,7 @@ void CodePreperation::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<DominanceFrontier>();
}
bool CodePreperation::runOnFunction(Function &F) {
bool CodePreparation::runOnFunction(Function &F) {
LI = &getAnalysis<LoopInfo>();
splitEntryBlockForAlloca(&F.getEntryBlock(), this);
@ -153,21 +153,22 @@ bool CodePreperation::runOnFunction(Function &F) {
return false;
}
void CodePreperation::releaseMemory() {
void CodePreparation::releaseMemory() {
clear();
}
void CodePreperation::print(raw_ostream &OS, const Module *) const {
void CodePreparation::print(raw_ostream &OS, const Module *) const {
}
char CodePreperation::ID = 0;
char CodePreparation::ID = 0;
char &polly::CodePreparationID = CodePreparation::ID;
RegisterPass<CodePreperation> X("polly-prepare",
"Polly - Prepare code for polly.",
false, true);
INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
"Polly - Prepare code for polly", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
"Polly - Prepare code for polly", false, false)
char &polly::CodePreperationID = CodePreperation::ID;
Pass *polly::createCodePreperationPass() {
return new CodePreperation();
Pass *polly::createCodePreparationPass() {
return new CodePreparation();
}

View File

@ -539,12 +539,17 @@ void IndependentBlocks::verifyScop(const Region *R) const {
}
char IndependentBlocks::ID = 0;
static RegisterPass<IndependentBlocks>
Z("polly-independent", "Polly - Create independent blocks");
char &polly::IndependentBlocksID = IndependentBlocks::ID;
INITIALIZE_PASS_BEGIN(IndependentBlocks, "polly-independent",
"Polly - Create independent blocks", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
INITIALIZE_PASS_DEPENDENCY(RegionInfo)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
INITIALIZE_PASS_DEPENDENCY(ScopDetection)
INITIALIZE_PASS_END(IndependentBlocks, "polly-independent",
"Polly - Create independent blocks", false, false)
Pass* polly::createIndependentBlocksPass() {
return new IndependentBlocks();
}

View File

@ -280,8 +280,12 @@ void Pocc::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<Dependences>();
}
static RegisterPass<Pocc> A("polly-optimize",
"Polly - Optimize the scop using pocc");
INITIALIZE_PASS_BEGIN(Pocc, "polly-optimize",
"Polly - Optimize the scop using pocc", false, false)
INITIALIZE_PASS_DEPENDENCY(Dependences)
INITIALIZE_PASS_DEPENDENCY(ScopInfo)
INITIALIZE_PASS_END(Pocc, "polly-optimize",
"Polly - Optimize the scop using pocc", false, false)
Pass* polly::createPoccPass() {
return new Pocc();

View File

@ -49,10 +49,15 @@ public:
};
}
static RegisterPass<RegionSimplify>
X("polly-region-simplify", "Transform refined regions into simple regions");
char RegionSimplify::ID = 0;
INITIALIZE_PASS_BEGIN(RegionSimplify, "polly-region-simplify",
"Transform refined regions into simple regions", false,
false)
INITIALIZE_PASS_DEPENDENCY(RegionInfo)
INITIALIZE_PASS_END(RegionSimplify, "polly-region-simplify",
"Transform refined regions into simple regions", false,
false)
namespace polly {
Pass *createRegionSimplifyPass() {
return new RegionSimplify();

View File

@ -19,25 +19,49 @@
#include "polly/LinkAllPasses.h"
#include "polly/Cloog.h"
#include "polly/Dependences.h"
#include "polly/ScopDetection.h"
#include "polly/ScopInfo.h"
#include "polly/TempScopInfo.h"
using namespace llvm;
void initializePollyPasses(PassRegistry &Registry) {
initializeCloogInfoPass(Registry);
initializeCodeGenerationPass(Registry);
initializeCodePreparationPass(Registry);
initializeDependencesPass(Registry);
initializeIndependentBlocksPass(Registry);
initializeIslScheduleOptimizerPass(Registry);
#ifdef SCOPLIB_FOUND
initializePoccPass(Registry);
#endif
initializeRegionSimplifyPass(Registry);
initializeScopDetectionPass(Registry);
initializeScopInfoPass(Registry);
initializeTempScopInfoPass(Registry);
}
// Statically register all Polly passes such that they are available after
// loading Polly.
class StaticInitializer {
public:
StaticInitializer() {
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializePollyPasses(Registry);
}
};
static StaticInitializer InitializeEverything;
static void registerPollyPasses(const llvm::PassManagerBuilder &Builder,
llvm::PassManagerBase &PM) {
// Polly is only enabled at -O3
if (Builder.OptLevel != 3)
return;
// We need to initialize the passes before we use them.
//
// This is not necessary for the opt tool, however clang crashes if passes
// are not initialized. (FIXME?)
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeDominatorTreePass(Registry);
initializePostDominatorTreePass(Registry);
initializeLoopInfoPass(Registry);
initializeScalarEvolutionPass(Registry);
initializeRegionInfoPass(Registry);
initializeDominanceFrontierPass(Registry);
initializeAliasAnalysisAnalysisGroup(Registry);
// A standard set of optimization passes partially taken/copied from the
// set of default optimization passes. It is used to bring the code into
// a canonical form that can than be analyzed by Polly. This set of passes is
@ -51,26 +75,15 @@ static void registerPollyPasses(const llvm::PassManagerBuilder &Builder,
PM.add(llvm::createLoopRotatePass()); // Rotate Loop
PM.add(llvm::createInstructionCombiningPass());
PM.add(llvm::createIndVarSimplifyPass()); // Canonicalize indvars
PM.add(llvm::createRegionInfoPass());
PM.add(polly::createCodePreperationPass());
PM.add(polly::createCodePreparationPass());
PM.add(polly::createRegionSimplifyPass());
// FIXME: Needed as RegionSimplifyPass destroys the canonical form of
// induction variables (It changes the order of the operands in the
// PHI nodes).
PM.add(llvm::createIndVarSimplifyPass());
PM.add(polly::createScopDetectionPass());
PM.add(polly::createIndependentBlocksPass());
// FIXME: We should not need to schedule passes like the TempScopInfoPass
// explicitally, as it is alread required by the ScopInfo pass.
// However, without this clang crashes because of unitialized passes.
PM.add(polly::createTempScopInfoPass());
PM.add(polly::createScopInfoPass());
PM.add(polly::createDependencesPass());
PM.add(polly::createScheduleOptimizerPass());
PM.add(polly::createCloogInfoPass());
PM.add(polly::createIslScheduleOptimizerPass());
PM.add(polly::createCodeGenerationPass());
}
@ -79,6 +92,7 @@ static void registerPollyPasses(const llvm::PassManagerBuilder &Builder,
// We run Polly that early to run before loop optimizer passes like LICM or
// the LoopIdomPass. Both transform the code in a way that Polly will recognize
// less scops.
static llvm::RegisterStandardPasses
PassRegister(llvm::PassManagerBuilder::EP_EarlyAsPossible,
registerPollyPasses);

View File

@ -45,11 +45,11 @@ Prevector("enable-schedule-prevector",
namespace {
class ScheduleOptimizer : public ScopPass {
class IslScheduleOptimizer : public ScopPass {
public:
static char ID;
explicit ScheduleOptimizer() : ScopPass(ID) {}
explicit IslScheduleOptimizer() : ScopPass(ID) {}
virtual bool runOnScop(Scop &S);
void printScop(llvm::raw_ostream &OS) const;
@ -58,7 +58,7 @@ namespace {
}
char ScheduleOptimizer::ID = 0;
char IslScheduleOptimizer::ID = 0;
static int getSingleMap(__isl_take isl_map *map, void *user) {
isl_map **singleMap = (isl_map **) user;
@ -341,7 +341,7 @@ static isl_union_map *tileSchedule(isl_schedule *schedule) {
return tiledSchedule;
}
bool ScheduleOptimizer::runOnScop(Scop &S) {
bool IslScheduleOptimizer::runOnScop(Scop &S) {
Dependences *D = &getAnalysis<Dependences>();
// Build input data.
@ -410,19 +410,21 @@ bool ScheduleOptimizer::runOnScop(Scop &S) {
return false;
}
void ScheduleOptimizer::printScop(raw_ostream &OS) const {
void IslScheduleOptimizer::printScop(raw_ostream &OS) const {
}
void ScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
ScopPass::getAnalysisUsage(AU);
AU.addRequired<Dependences>();
}
static RegisterPass<ScheduleOptimizer> A("polly-optimize-isl",
"Polly - Calculate optimized "
"schedules using the isl schedule "
"calculator");
INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-optimize-isl",
"Polly - Optimize schedule of SCoP", false, false)
INITIALIZE_PASS_DEPENDENCY(Dependences)
INITIALIZE_PASS_DEPENDENCY(ScopInfo)
INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-optimize-isl",
"Polly - Optimize schedule of SCoP", false, false)
Pass* polly::createScheduleOptimizerPass() {
return new ScheduleOptimizer();
Pass* polly::createIslScheduleOptimizerPass() {
return new IslScheduleOptimizer();
}