forked from OSchip/llvm-project
Introduce -polly-canonicalize pass
This ModulePass schedules the set of Polly canonicalization passes. It is a debugging tool that can be used to preoptimize .ll files for Polly processing. llvm-svn: 198376
This commit is contained in:
parent
3d216a579c
commit
a9376ff571
|
@ -0,0 +1,30 @@
|
|||
//===--- Canonicalization.h - The set of canonicalization passes------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef POLLY_CANONICALIZATION_H
|
||||
#define POLLY_CANONICALIZATION_H
|
||||
|
||||
#include "llvm/PassManager.h"
|
||||
|
||||
namespace polly {
|
||||
|
||||
/// @brief Schedule a set of canonicalization passes to prepare for Polly
|
||||
///
|
||||
/// The set of optimization passes was partially taken/copied from the
|
||||
/// set of default optimization passes in LLVM. It is used to bring the code
|
||||
/// into a canonical form that simplifies the analysis and optimization passes
|
||||
/// of Polly. The set of optimization passes scheduled here is probably not yet
|
||||
/// optimal. TODO: Optimize the set of canonicalization passes.
|
||||
void registerCanonicalicationPasses(llvm::PassManagerBase &PM,
|
||||
bool SCEVCodegen = false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -45,6 +45,7 @@ llvm::Pass *createJSONImporterPass();
|
|||
#ifdef PLUTO_FOUND
|
||||
llvm::Pass *createPlutoOptimizerPass();
|
||||
#endif
|
||||
llvm::Pass *createPollyCanonicalizePass();
|
||||
llvm::Pass *createScopDetectionPass();
|
||||
llvm::Pass *createScopInfoPass();
|
||||
llvm::Pass *createIslAstInfoPass();
|
||||
|
@ -100,6 +101,7 @@ struct PollyForcePassLinking {
|
|||
#ifdef PLUTO_FOUND
|
||||
createPlutoOptimizerPass();
|
||||
#endif
|
||||
createPollyCanonicalizePass();
|
||||
createIslAstInfoPass();
|
||||
createIslCodeGenerationPass();
|
||||
createIslScheduleOptimizerPass();
|
||||
|
@ -134,6 +136,7 @@ void initializeIslScheduleOptimizerPass(llvm::PassRegistry &);
|
|||
#ifdef PLUTO_FOUND
|
||||
void initializePlutoOptimizerPass(llvm::PassRegistry &);
|
||||
#endif
|
||||
void initializePollyCanonicalizePass(llvm::PassRegistry &);
|
||||
#ifdef SCOPLIB_FOUND
|
||||
void initializePoccPass(llvm::PassRegistry &);
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@ set(LLVM_USED_LIBS
|
|||
)
|
||||
|
||||
add_polly_loadable_module(LLVMPolly
|
||||
Canonicalization.cpp
|
||||
CodePreparation.cpp
|
||||
DeadCodeElimination.cpp
|
||||
IndependentBlocks.cpp
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
//===---- Canonicalization.cpp - Run canonicalization passes ======-------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Run the set of default canonicalization passes.
|
||||
//
|
||||
// This pass is mainly used for debugging.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "polly/LinkAllPasses.h"
|
||||
#include "polly/Canonicalization.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace polly;
|
||||
|
||||
void polly::registerCanonicalicationPasses(llvm::PassManagerBase &PM,
|
||||
bool SCEVCodegen) {
|
||||
PM.add(llvm::createPromoteMemoryToRegisterPass());
|
||||
PM.add(llvm::createPromoteMemoryToRegisterPass());
|
||||
PM.add(llvm::createInstructionCombiningPass());
|
||||
PM.add(llvm::createCFGSimplificationPass());
|
||||
PM.add(llvm::createTailCallEliminationPass());
|
||||
PM.add(llvm::createCFGSimplificationPass());
|
||||
PM.add(llvm::createReassociatePass());
|
||||
PM.add(llvm::createLoopRotatePass());
|
||||
PM.add(llvm::createInstructionCombiningPass());
|
||||
|
||||
if (!SCEVCodegen)
|
||||
PM.add(polly::createIndVarSimplifyPass());
|
||||
|
||||
PM.add(polly::createCodePreparationPass());
|
||||
}
|
||||
|
||||
namespace {
|
||||
class PollyCanonicalize : public ModulePass {
|
||||
PollyCanonicalize(const PollyCanonicalize &) LLVM_DELETED_FUNCTION;
|
||||
const PollyCanonicalize &
|
||||
operator=(const PollyCanonicalize &) LLVM_DELETED_FUNCTION;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
explicit PollyCanonicalize() : ModulePass(ID) {}
|
||||
~PollyCanonicalize();
|
||||
|
||||
/// @name FunctionPass interface.
|
||||
//@{
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
||||
virtual void releaseMemory();
|
||||
virtual bool runOnModule(Module &M);
|
||||
virtual void print(raw_ostream &OS, const Module *) const;
|
||||
//@}
|
||||
};
|
||||
}
|
||||
|
||||
PollyCanonicalize::~PollyCanonicalize() {}
|
||||
|
||||
void PollyCanonicalize::getAnalysisUsage(AnalysisUsage &AU) const {}
|
||||
|
||||
void PollyCanonicalize::releaseMemory() {}
|
||||
|
||||
bool PollyCanonicalize::runOnModule(Module &M) {
|
||||
PassManager PM;
|
||||
registerCanonicalicationPasses(PM);
|
||||
PM.run(M);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PollyCanonicalize::print(raw_ostream &OS, const Module *) const {}
|
||||
|
||||
char PollyCanonicalize::ID = 0;
|
||||
|
||||
Pass *polly::createPollyCanonicalizePass() { return new PollyCanonicalize(); }
|
||||
|
||||
INITIALIZE_PASS_BEGIN(PollyCanonicalize, "polly-canonicalize",
|
||||
"Polly - Run canonicalization passes", false, false)
|
||||
INITIALIZE_PASS_END(PollyCanonicalize, "polly-canonicalize",
|
||||
"Polly - Run canonicalization passes", false, false)
|
|
@ -20,6 +20,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "polly/RegisterPasses.h"
|
||||
#include "polly/Canonicalization.h"
|
||||
#include "polly/CodeGen/BlockGenerators.h"
|
||||
#include "polly/CodeGen/Cloog.h"
|
||||
#include "polly/CodeGen/CodeGeneration.h"
|
||||
|
@ -172,6 +173,7 @@ static void initializePollyPasses(PassRegistry &Registry) {
|
|||
initializePoccPass(Registry);
|
||||
#endif
|
||||
initializePollyIndVarSimplifyPass(Registry);
|
||||
initializePollyCanonicalizePass(Registry);
|
||||
initializeScopDetectionPass(Registry);
|
||||
initializeScopInfoPass(Registry);
|
||||
initializeTempScopInfoPass(Registry);
|
||||
|
@ -191,29 +193,6 @@ public:
|
|||
};
|
||||
static StaticInitializer InitializeEverything;
|
||||
|
||||
/// @brief Schedule a set of canonicalization passes to prepare for Polly
|
||||
///
|
||||
/// The set of optimization passes was partially taken/copied from the
|
||||
/// set of default optimization passes in LLVM. It is used to bring the code
|
||||
/// into a canonical form that simplifies the analysis and optimization passes
|
||||
/// of Polly. The set of optimization passes scheduled here is probably not yet
|
||||
/// optimal. TODO: Optimize the set of canonicalization passes.
|
||||
static void registerCanonicalicationPasses(llvm::PassManagerBase &PM) {
|
||||
PM.add(llvm::createPromoteMemoryToRegisterPass());
|
||||
PM.add(llvm::createInstructionCombiningPass());
|
||||
PM.add(llvm::createCFGSimplificationPass());
|
||||
PM.add(llvm::createTailCallEliminationPass());
|
||||
PM.add(llvm::createCFGSimplificationPass());
|
||||
PM.add(llvm::createReassociatePass());
|
||||
PM.add(llvm::createLoopRotatePass());
|
||||
PM.add(llvm::createInstructionCombiningPass());
|
||||
|
||||
if (!SCEVCodegen)
|
||||
PM.add(polly::createIndVarSimplifyPass());
|
||||
|
||||
PM.add(polly::createCodePreparationPass());
|
||||
}
|
||||
|
||||
/// @brief Register Polly passes such that they form a polyhedral optimizer.
|
||||
///
|
||||
/// The individual Polly passes are registered in the pass manager such that
|
||||
|
@ -245,7 +224,7 @@ static void registerCanonicalicationPasses(llvm::PassManagerBase &PM) {
|
|||
/// code generator. For the moment, the CLooG code generator is enabled by
|
||||
/// default.
|
||||
static void registerPollyPasses(llvm::PassManagerBase &PM) {
|
||||
registerCanonicalicationPasses(PM);
|
||||
registerCanonicalicationPasses(PM, SCEVCodegen);
|
||||
|
||||
PM.add(polly::createScopInfoPass());
|
||||
|
||||
|
|
|
@ -54,11 +54,9 @@ alias opt="opt -load ${PATH_TO_POLLY_LIB}/LLVMPolly.so"</pre>
|
|||
<li><h4>Prepare the LLVM-IR for Polly</h4>
|
||||
|
||||
Polly is only able to work with code that matches a canonical form. To translate
|
||||
the LLVM-IR into this form we use a set of canonicalication passes. For this
|
||||
example only three passes are necessary. To get good coverage on more
|
||||
complicated input files often more canonicalization passes are needed. pollycc
|
||||
contains a list of passes that have shown to be beneficial.
|
||||
<pre class="code">opt -S -mem2reg -loop-simplify -polly-indvars matmul.s > matmul.preopt.ll</pre></li>
|
||||
the LLVM-IR into this form we use a set of canonicalication passes. They are
|
||||
scheduled by using '-polly-canonicalize'.
|
||||
<pre class="code">opt -S -polly-canonicalize matmul.s > matmul.preopt.ll</pre></li>
|
||||
|
||||
<li><h4>Show the SCoPs detected by Polly (optional)</h4>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ export PATH_TO_POLLY_LIB="~/polly/build/lib/"
|
|||
alias opt="opt -load ${PATH_TO_POLLY_LIB}/LLVMPolly.so"
|
||||
|
||||
echo "--> 3. Prepare the LLVM-IR for Polly"
|
||||
opt -S -mem2reg -loop-simplify -polly-indvars matmul.s > matmul.preopt.ll
|
||||
opt -S -polly-canonicalize matmul.s > matmul.preopt.ll
|
||||
|
||||
echo "--> 4. Show the SCoPs detected by Polly"
|
||||
opt -basicaa -polly-cloog -analyze -q matmul.preopt.ll
|
||||
|
|
Loading…
Reference in New Issue