2011-08-24 06:35:38 +08:00
|
|
|
//===------ RegisterPasses.cpp - Add the Polly Passes to default passes --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Add the Polly passes to the optimization passes executed at -O3.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/InitializePasses.h"
|
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/PassRegistry.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
2011-10-08 08:30:44 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-08-24 06:35:38 +08:00
|
|
|
|
|
|
|
#include "polly/LinkAllPasses.h"
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
#include "polly/Cloog.h"
|
|
|
|
#include "polly/Dependences.h"
|
|
|
|
#include "polly/ScopDetection.h"
|
|
|
|
#include "polly/ScopInfo.h"
|
|
|
|
#include "polly/TempScopInfo.h"
|
|
|
|
|
2011-11-23 03:40:19 +08:00
|
|
|
#include <string>
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-11-18 03:10:48 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
PollyEnabled("polly", cl::desc("Enable the default passes of Polly in -O3"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2011-10-24 04:59:32 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
DisableScheduler("polly-no-optimizer",
|
|
|
|
cl::desc("Disable Polly Scheduling Optimizer"), cl::Hidden,
|
|
|
|
cl::init(false));
|
2011-10-24 04:59:11 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
DisableCodegen("polly-no-codegen",
|
|
|
|
cl::desc("Disable Polly Code Generation"), cl::Hidden,
|
|
|
|
cl::init(false));
|
2011-11-23 03:40:19 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
Optimizer("polly-optimizer",
|
|
|
|
cl::desc("Select the scheduling optimizer. "
|
|
|
|
"Either isl (default) or pocc."),
|
|
|
|
cl::Hidden, cl::init("isl"));
|
2011-10-24 04:59:35 +08:00
|
|
|
static cl::opt<bool>
|
2011-11-15 19:38:36 +08:00
|
|
|
ImportJScop("polly-run-import-jscop",
|
|
|
|
cl::desc("Export the JScop description of the detected Scops"),
|
|
|
|
cl::Hidden, cl::init(false));
|
|
|
|
static cl::opt<bool>
|
|
|
|
ExportJScop("polly-run-export-jscop",
|
|
|
|
cl::desc("Export the JScop description of the detected Scops"),
|
|
|
|
cl::Hidden, cl::init(false));
|
|
|
|
static cl::opt<bool>
|
2011-10-24 04:59:14 +08:00
|
|
|
PollyViewer("polly-show",
|
2011-10-08 08:30:44 +08:00
|
|
|
cl::desc("Enable the Polly DOT viewer in -O3"), cl::Hidden,
|
|
|
|
cl::value_desc("Run the Polly DOT viewer at -O3"),
|
|
|
|
cl::init(false));
|
|
|
|
static cl::opt<bool>
|
2011-10-24 04:59:14 +08:00
|
|
|
PollyOnlyViewer("polly-show-only",
|
2011-10-08 08:30:44 +08:00
|
|
|
cl::desc("Enable the Polly DOT viewer in -O3 (no BB content)"),
|
|
|
|
cl::Hidden,
|
|
|
|
cl::value_desc("Run the Polly DOT viewer at -O3 (no BB content"),
|
|
|
|
cl::init(false));
|
|
|
|
static cl::opt<bool>
|
2011-10-24 04:59:14 +08:00
|
|
|
PollyPrinter("polly-dot",
|
2011-10-08 08:30:44 +08:00
|
|
|
cl::desc("Enable the Polly DOT printer in -O3"), cl::Hidden,
|
|
|
|
cl::value_desc("Run the Polly DOT printer at -O3"),
|
|
|
|
cl::init(false));
|
|
|
|
static cl::opt<bool>
|
2011-10-24 04:59:14 +08:00
|
|
|
PollyOnlyPrinter("polly-dot-only",
|
2011-10-08 08:30:44 +08:00
|
|
|
cl::desc("Enable the Polly DOT printer in -O3 (no BB content)"),
|
|
|
|
cl::Hidden,
|
|
|
|
cl::value_desc("Run the Polly DOT printer at -O3 (no BB content"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
void initializePollyPasses(PassRegistry &Registry) {
|
|
|
|
initializeCloogInfoPass(Registry);
|
|
|
|
initializeCodeGenerationPass(Registry);
|
|
|
|
initializeCodePreparationPass(Registry);
|
|
|
|
initializeDependencesPass(Registry);
|
|
|
|
initializeIndependentBlocksPass(Registry);
|
2011-11-15 19:38:36 +08:00
|
|
|
initializeJSONExporterPass(Registry);
|
|
|
|
initializeJSONImporterPass(Registry);
|
2011-10-08 08:30:40 +08:00
|
|
|
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;
|
|
|
|
|
2011-08-24 06:35:38 +08:00
|
|
|
static void registerPollyPasses(const llvm::PassManagerBuilder &Builder,
|
|
|
|
llvm::PassManagerBase &PM) {
|
2011-11-18 03:10:48 +08:00
|
|
|
if (PollyOnlyPrinter || PollyPrinter || PollyOnlyViewer || PollyViewer ||
|
|
|
|
ExportJScop || ImportJScop)
|
|
|
|
PollyEnabled = true;
|
|
|
|
|
|
|
|
if (!PollyEnabled) {
|
|
|
|
if (DisableCodegen)
|
|
|
|
errs() << "The option -polly-no-codegen has no effect. "
|
|
|
|
"Polly was not enabled\n";
|
|
|
|
|
|
|
|
if (DisableScheduler)
|
|
|
|
errs() << "The option -polly-no-optimizer has no effect. "
|
|
|
|
"Polly was not enabled\n";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2011-11-17 20:56:06 +08:00
|
|
|
|
2011-08-24 06:35:38 +08:00
|
|
|
// Polly is only enabled at -O3
|
2011-11-18 03:10:48 +08:00
|
|
|
if (Builder.OptLevel != 3) {
|
|
|
|
errs() << "Polly should only be run with -O3. Disabling Polly.\n";
|
2011-08-24 06:35:38 +08:00
|
|
|
return;
|
2011-11-18 03:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RunScheduler = !DisableScheduler;
|
|
|
|
bool RunCodegen = !DisableCodegen;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-24 06:35:38 +08:00
|
|
|
|
|
|
|
// A standard set of optimization passes partially taken/copied from the
|
2011-08-24 15:33:05 +08:00
|
|
|
// 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
|
|
|
|
// most probably not yet optimal. TODO: Investigate optimal set of passes.
|
2011-08-24 06:35:38 +08:00
|
|
|
PM.add(llvm::createPromoteMemoryToRegisterPass());
|
|
|
|
PM.add(llvm::createInstructionCombiningPass()); // Clean up after IPCP & DAE
|
|
|
|
PM.add(llvm::createCFGSimplificationPass()); // Clean up after IPCP & DAE
|
|
|
|
PM.add(llvm::createTailCallEliminationPass()); // Eliminate tail calls
|
|
|
|
PM.add(llvm::createCFGSimplificationPass()); // Merge & remove BBs
|
|
|
|
PM.add(llvm::createReassociatePass()); // Reassociate expressions
|
|
|
|
PM.add(llvm::createLoopRotatePass()); // Rotate Loop
|
|
|
|
PM.add(llvm::createInstructionCombiningPass());
|
|
|
|
PM.add(llvm::createIndVarSimplifyPass()); // Canonicalize indvars
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
PM.add(polly::createCodePreparationPass());
|
2011-08-24 06:35:38 +08:00
|
|
|
PM.add(polly::createRegionSimplifyPass());
|
2011-11-10 20:45:07 +08:00
|
|
|
// FIXME: The next two passes should not be necessary here. They are currently
|
|
|
|
// because of two problems:
|
|
|
|
//
|
|
|
|
// 1. The RegionSimplifyPass destroys the canonical form of induction
|
|
|
|
// variables,as it produces PHI nodes with incorrectly ordered
|
|
|
|
// operands. To fix this we run IndVarSimplify.
|
|
|
|
//
|
|
|
|
// 2. IndVarSimplify does not preserve the region information and
|
|
|
|
// the regioninfo pass does currently not recover simple regions.
|
|
|
|
// As a result we need to run the RegionSimplify pass again to
|
|
|
|
// recover them
|
2011-08-24 06:35:38 +08:00
|
|
|
PM.add(llvm::createIndVarSimplifyPass());
|
2011-11-10 20:45:07 +08:00
|
|
|
PM.add(polly::createRegionSimplifyPass());
|
2011-10-08 08:30:44 +08:00
|
|
|
|
|
|
|
if (PollyViewer)
|
|
|
|
PM.add(polly::createDOTViewerPass());
|
|
|
|
if (PollyOnlyViewer)
|
|
|
|
PM.add(polly::createDOTOnlyViewerPass());
|
|
|
|
if (PollyPrinter)
|
|
|
|
PM.add(polly::createDOTPrinterPass());
|
|
|
|
if (PollyOnlyPrinter)
|
|
|
|
PM.add(polly::createDOTOnlyPrinterPass());
|
|
|
|
|
2011-11-15 19:38:36 +08:00
|
|
|
if (ImportJScop)
|
|
|
|
PM.add(polly::createJSONImporterPass());
|
|
|
|
|
2011-11-17 20:56:06 +08:00
|
|
|
if (RunScheduler) {
|
2011-11-23 03:40:19 +08:00
|
|
|
if (Optimizer == "pocc") {
|
2011-10-24 04:59:35 +08:00
|
|
|
#ifdef SCOPLIB_FOUND
|
|
|
|
PM.add(polly::createPoccPass());
|
|
|
|
#else
|
|
|
|
errs() << "Polly is compiled without scoplib support. As scoplib is "
|
2011-11-23 03:40:19 +08:00
|
|
|
"required to run PoCC, PoCC is also not available. Falling "
|
|
|
|
"back to the isl optimizer.\n";
|
2011-10-24 04:59:35 +08:00
|
|
|
PM.add(polly::createIslScheduleOptimizerPass());
|
|
|
|
#endif
|
2011-11-23 03:40:19 +08:00
|
|
|
} else if (Optimizer == "isl") {
|
|
|
|
PM.add(polly::createIslScheduleOptimizerPass());
|
2011-11-17 20:56:06 +08:00
|
|
|
} else {
|
2011-11-23 03:40:19 +08:00
|
|
|
errs() << "Invalid optimizer. Only 'isl' and 'pocc' allowed. "
|
|
|
|
"Falling back to 'isl'.\n";
|
2011-11-17 20:56:06 +08:00
|
|
|
PM.add(polly::createIslScheduleOptimizerPass());
|
2011-10-24 04:59:35 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-24 04:59:11 +08:00
|
|
|
|
2011-11-15 19:38:36 +08:00
|
|
|
if (ExportJScop)
|
|
|
|
PM.add(polly::createJSONExporterPass());
|
|
|
|
|
2011-11-17 20:56:06 +08:00
|
|
|
if (RunCodegen)
|
2011-10-24 04:59:11 +08:00
|
|
|
PM.add(polly::createCodeGenerationPass());
|
2011-08-24 06:35:38 +08:00
|
|
|
}
|
|
|
|
|
2011-08-24 15:33:05 +08:00
|
|
|
// Execute Polly together with a set of preparing passes.
|
|
|
|
//
|
|
|
|
// 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.
|
2011-10-08 08:30:40 +08:00
|
|
|
|
2011-08-24 06:35:38 +08:00
|
|
|
static llvm::RegisterStandardPasses
|
|
|
|
PassRegister(llvm::PassManagerBuilder::EP_EarlyAsPossible,
|
|
|
|
registerPollyPasses);
|