42#include "llvm/Analysis/CFGPrinter.h"
43#include "llvm/IR/LegacyPassManager.h"
44#include "llvm/IR/PassManager.h"
45#include "llvm/IR/Verifier.h"
46#include "llvm/Passes/PassBuilder.h"
47#include "llvm/Passes/PassPlugin.h"
48#include "llvm/Support/CommandLine.h"
49#include "llvm/Support/TargetSelect.h"
50#include "llvm/Transforms/IPO.h"
52namespace cl = llvm::cl;
54using llvm::FunctionPassManager;
55using llvm::OptimizationLevel;
56using llvm::PassBuilder;
57using llvm::PassInstrumentationCallbacks;
60 "Configure the polly loop optimizer");
65 cl::desc(
"Enable the polly optimizer (with -O1, -O2 or -O3)"),
69 "polly-only-scop-detection",
70 cl::desc(
"Only run scop detection, but no other optimizations"),
78 "polly-position", cl::desc(
"Where to run polly in the pass pipeline"),
79 cl::values(clEnumValN(
POSITION_EARLY,
"early",
"Before everything"),
81 "Right before the vectorizer")),
84static cl::opt<OptimizerChoice>
85 Optimizer(
"polly-optimizer", cl::desc(
"Select the scheduling optimizer"),
88 "The isl scheduling optimizer")),
93 "polly-code-generation", cl::desc(
"How much code-generation to perform"),
94 cl::values(clEnumValN(
CODEGEN_FULL,
"full",
"AST and IR generation"),
95 clEnumValN(
CODEGEN_AST,
"ast",
"Only AST generation"),
102 "polly-vectorizer", cl::desc(
"Select the vectorization strategy"),
107 "Strip-mine outer loops for the loop-vectorizer to trigger")),
113 cl::desc(
"Import the polyhedral description of the detected Scops"),
118 cl::desc(
"Fully expand the memory accesses of the detected Scops"),
123 cl::desc(
"Export the polyhedral description of the detected Scops"),
127 cl::desc(
"Run the dead code elimination"),
132 cl::desc(
"Highlight the code regions that will be optimized in a "
133 "(CFG BBs and LLVM-IR instructions)"),
138 cl::desc(
"Highlight the code regions that will be optimized in "
143 PollyPrinter(
"polly-dot", cl::desc(
"Enable the Polly DOT printer in -O3"),
144 cl::Hidden, cl::value_desc(
"Run the Polly DOT printer at -O3"),
149 cl::desc(
"Enable the Polly DOT printer in -O3 (no BB content)"), cl::Hidden,
150 cl::value_desc(
"Run the Polly DOT printer at -O3 (no BB content"),
155 cl::desc(
"Show the Polly CFG right after code generation"),
160 cl::desc(
"Enable operand tree forwarding"), cl::Hidden,
165 cl::desc(
"Dump module before Polly transformations into a file "
166 "suffixed with \"-before\""),
170 "polly-dump-before-file",
171 cl::desc(
"Dump module before Polly transformations to the given file"),
176 cl::desc(
"Dump module after Polly transformations into a file "
177 "suffixed with \"-after\""),
181 "polly-dump-after-file",
182 cl::desc(
"Dump module after Polly transformations to the given file"),
187 cl::desc(
"Eliminate scalar loop carried dependences"),
192 cl::desc(
"Simplify SCoP after optimizations"),
196 "polly-enable-prune-unprofitable",
197 cl::desc(
"Bail out on unprofitable SCoPs before rescheduling"), cl::Hidden,
207struct StaticInitializer {
208 StaticInitializer() {
209 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
213static StaticInitializer InitializeEverything;
303 OptimizationLevel Level,
377 PM.addPass(PB.buildFunctionSimplificationPipeline(
378 Level, llvm::ThinOrFullLTOPhase::None));
381 PM.addPass(llvm::CFGPrinterPass());
385 llvm::OptimizationLevel Level) {
394 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
401 FPM = FunctionPassManager();
405 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
414 llvm::OptimizationLevel Level) {
423 llvm::report_fatal_error(
424 "Option -polly-dump-before-file at -polly-position=late "
425 "not supported with NPM",
433 llvm::report_fatal_error(
434 "Option -polly-dump-after-file at -polly-position=late "
435 "not supported with NPM",
441 PassInstrumentationCallbacks *PIC) {
443#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
444 Proxy.getManager().registerPass([PIC] { \
446 return CREATE_PASS; \
448#include "PollyPasses.def"
456 PassInstrumentationCallbacks *PIC) {
458#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
459 FAM.registerPass([] { return CREATE_PASS; });
461#include "PollyPasses.def"
468 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
469 if (llvm::parseAnalysisUtilityPasses<OwningScopAnalysisManagerFunctionProxy>(
470 "polly-scop-analyses", Name, FPM))
473#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
474 if (llvm::parseAnalysisUtilityPasses< \
475 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
479#define FUNCTION_PASS(NAME, CREATE_PASS) \
480 if (Name == NAME) { \
481 FPM.addPass(CREATE_PASS); \
485#include "PollyPasses.def"
490 PassInstrumentationCallbacks *PIC) {
491#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
492 if (llvm::parseAnalysisUtilityPasses< \
493 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
497#define SCOP_PASS(NAME, CREATE_PASS) \
498 if (Name == NAME) { \
499 SPM.addPass(CREATE_PASS); \
503#include "PollyPasses.def"
509 PassInstrumentationCallbacks *PIC,
510 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
513 if (!Pipeline.empty()) {
515 for (
const auto &E : Pipeline)
524#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
525 if (Name == "require<" NAME ">") \
527 if (Name == "invalidate<" NAME ">") \
530#define SCOP_PASS(NAME, CREATE_PASS) \
534#include "PollyPasses.def"
541 PassInstrumentationCallbacks *PIC,
542 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
543 std::vector<PassBuilder::PipelineElement> FullPipeline;
544 StringRef FirstName = Pipeline.front().Name;
549 FunctionPassManager FPM;
552 for (
auto &Element : Pipeline) {
553 auto &Name = Element.Name;
554 auto &InnerPipeline = Element.InnerPipeline;
555 if (!InnerPipeline.empty())
562 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
594 PassInstrumentationCallbacks *PIC = PB.getPassInstrumentationCallbacks();
595 PB.registerAnalysisRegistrationCallback([PIC](FunctionAnalysisManager &FAM) {
599 PB.registerPipelineParsingCallback(
600 [PIC](StringRef Name, FunctionPassManager &FPM,
601 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
604 PB.registerParseTopLevelPipelineCallback(
605 [PIC](llvm::ModulePassManager &MPM,
606 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
622 return {LLVM_PLUGIN_API_VERSION,
"Polly", LLVM_VERSION_STRING,
llvm::cl::OptionCategory PollyCategory
llvm::PassPluginLibraryInfo getPollyPluginInfo()
AnalysisManagerT & getManager()
void initializePolyhedralInfoPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeScopDetectionWrapperPassPass(llvm::PassRegistry &)
void initializeScopInfoPrinterLegacyRegionPassPass(llvm::PassRegistry &)
void initializeDependenceInfoWrapperPassPass(llvm::PassRegistry &)
void initializeScopInfoRegionPassPass(PassRegistry &)
void initializeScopInfoPrinterLegacyFunctionPassPass(PassRegistry &)
void initializeDependenceInfoPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeCodeGenerationPass(llvm::PassRegistry &)
void initializeIslAstInfoPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeMaximalStaticExpanderWrapperPassPass(llvm::PassRegistry &)
void initializeScopInlinerPass(llvm::PassRegistry &)
void initializeSimplifyWrapperPassPass(llvm::PassRegistry &)
void initializeScopDetectionPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeJSONImporterPass(llvm::PassRegistry &)
void initializePollyCanonicalizePass(llvm::PassRegistry &)
void initializeIslAstInfoWrapperPassPass(llvm::PassRegistry &)
void initializePruneUnprofitableWrapperPassPass(llvm::PassRegistry &)
void initializeFlattenSchedulePrinterLegacyPassPass(llvm::PassRegistry &)
void initializeForwardOpTreeWrapperPassPass(PassRegistry &)
void initializeJSONExporterPass(llvm::PassRegistry &)
void initializePolyhedralInfoPass(llvm::PassRegistry &)
void initializeDependenceInfoPass(llvm::PassRegistry &)
void initializeIslScheduleOptimizerWrapperPassPass(llvm::PassRegistry &)
void initializeDumpModuleWrapperPassPass(llvm::PassRegistry &)
void initializeDependenceInfoPrinterLegacyFunctionPassPass(llvm::PassRegistry &)
void initializeSimplifyPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeScopInfoWrapperPassPass(PassRegistry &)
void initializeCodePreparationPass(llvm::PassRegistry &)
void initializeFlattenSchedulePass(llvm::PassRegistry &)
void initializeIslScheduleOptimizerPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeDeLICMPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeDeLICMWrapperPassPass(llvm::PassRegistry &)
void initializeJSONImporterPrinterLegacyPassPass(llvm::PassRegistry &)
void initializeForwardOpTreePrinterLegacyPassPass(PassRegistry &)
void initializeDeadCodeElimWrapperPassPass(llvm::PassRegistry &)
static cl::opt< bool > ExportJScop("polly-export", cl::desc("Export the polyhedral description of the detected Scops"), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< bool > FullyIndexedStaticExpansion("polly-enable-mse", cl::desc("Fully expand the memory accesses of the detected Scops"), cl::Hidden, cl::cat(PollyCategory))
@ POSITION_BEFORE_VECTORIZER
static bool parseTopLevelPipeline(llvm::ModulePassManager &MPM, PassInstrumentationCallbacks *PIC, ArrayRef< PassBuilder::PipelineElement > Pipeline)
static cl::list< std::string > DumpBeforeFile("polly-dump-before-file", cl::desc("Dump module before Polly transformations to the given file"), cl::cat(PollyCategory))
static bool shouldEnablePollyForDiagnostic()
FunctionToScopPassAdaptor< ScopPassT > createFunctionToScopPassAdaptor(ScopPassT Pass)
static cl::opt< VectorizerChoice, true > Vectorizer("polly-vectorizer", cl::desc("Select the vectorization strategy"), cl::values(clEnumValN(VECTORIZER_NONE, "none", "No Vectorization"), clEnumValN(VECTORIZER_STRIPMINE, "stripmine", "Strip-mine outer loops for the loop-vectorizer to trigger")), cl::location(PollyVectorizerChoice), cl::init(VECTORIZER_NONE), cl::cat(PollyCategory))
static cl::opt< bool > PollyOnlyViewer("polly-show-only", cl::desc("Highlight the code regions that will be optimized in " "a (CFG only BBs)"), cl::init(false), cl::cat(PollyCategory))
static void buildLatePollyPipeline(FunctionPassManager &PM, llvm::OptimizationLevel Level)
static cl::opt< bool > EnableSimplify("polly-enable-simplify", cl::desc("Simplify SCoP after optimizations"), cl::init(true), cl::cat(PollyCategory))
PassManager< Scop, ScopAnalysisManager, ScopStandardAnalysisResults &, SPMUpdater & > ScopPassManager
static cl::opt< OptimizerChoice > Optimizer("polly-optimizer", cl::desc("Select the scheduling optimizer"), cl::values(clEnumValN(OPTIMIZER_NONE, "none", "No optimizer"), clEnumValN(OPTIMIZER_ISL, "isl", "The isl scheduling optimizer")), cl::Hidden, cl::init(OPTIMIZER_ISL), cl::cat(PollyCategory))
void registerPollyPasses(llvm::PassBuilder &PB)
static cl::opt< bool > PollyViewer("polly-show", cl::desc("Highlight the code regions that will be optimized in a " "(CFG BBs and LLVM-IR instructions)"), cl::cat(PollyCategory))
static cl::opt< bool > PollyPrinter("polly-dot", cl::desc("Enable the Polly DOT printer in -O3"), cl::Hidden, cl::value_desc("Run the Polly DOT printer at -O3"), cl::init(false), cl::cat(PollyCategory))
static cl::opt< bool > PollyEnabled("polly", cl::desc("Enable the polly optimizer (with -O1, -O2 or -O3)"), cl::cat(PollyCategory))
VectorizerChoice PollyVectorizerChoice
static cl::opt< bool > DumpBefore("polly-dump-before", cl::desc("Dump module before Polly transformations into a file " "suffixed with \"-before\""), cl::init(false), cl::cat(PollyCategory))
void initializePollyPasses(llvm::PassRegistry &Registry)
static cl::opt< bool > EnableForwardOpTree("polly-enable-optree", cl::desc("Enable operand tree forwarding"), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::opt< bool > DumpAfter("polly-dump-after", cl::desc("Dump module after Polly transformations into a file " "suffixed with \"-after\""), cl::init(false), cl::cat(PollyCategory))
static bool parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM, ArrayRef< PassBuilder::PipelineElement > Pipeline)
static cl::opt< bool > PollyDetectOnly("polly-only-scop-detection", cl::desc("Only run scop detection, but no other optimizations"), cl::cat(PollyCategory))
static cl::opt< bool > CFGPrinter("polly-view-cfg", cl::desc("Show the Polly CFG right after code generation"), cl::Hidden, cl::init(false), cl::cat(PollyCategory))
static bool isScopPassName(StringRef Name)
static void registerFunctionAnalyses(FunctionAnalysisManager &FAM, PassInstrumentationCallbacks *PIC)
static cl::opt< bool > DeadCodeElim("polly-run-dce", cl::desc("Run the dead code elimination"), cl::Hidden, cl::cat(PollyCategory))
static void buildCommonPollyPipeline(FunctionPassManager &PM, OptimizationLevel Level, bool EnableForOpt)
Register Polly passes such that they form a polyhedral optimizer.
static cl::opt< bool > EnablePruneUnprofitable("polly-enable-prune-unprofitable", cl::desc("Bail out on unprofitable SCoPs before rescheduling"), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::opt< bool > EnableDeLICM("polly-enable-delicm", cl::desc("Eliminate scalar loop carried dependences"), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static OwningScopAnalysisManagerFunctionProxy createScopAnalyses(FunctionAnalysisManager &FAM, PassInstrumentationCallbacks *PIC)
static bool parseScopPipeline(StringRef Name, FunctionPassManager &FPM, PassInstrumentationCallbacks *PIC, ArrayRef< PassBuilder::PipelineElement > Pipeline)
static cl::opt< bool > ImportJScop("polly-import", cl::desc("Import the polyhedral description of the detected Scops"), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< bool > PollyOnlyPrinter("polly-dot-only", 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), cl::cat(PollyCategory))
llvm::FunctionPassManager buildCanonicalicationPassesForNPM(llvm::ModulePassManager &MPM, llvm::OptimizationLevel Level)
AnalysisManager< Scop, ScopStandardAnalysisResults & > ScopAnalysisManager
static cl::opt< PassPositionChoice > PassPosition("polly-position", cl::desc("Where to run polly in the pass pipeline"), cl::values(clEnumValN(POSITION_EARLY, "early", "Before everything"), clEnumValN(POSITION_BEFORE_VECTORIZER, "before-vectorizer", "Right before the vectorizer")), cl::Hidden, cl::init(POSITION_BEFORE_VECTORIZER), cl::cat(PollyCategory))
static cl::list< std::string > DumpAfterFile("polly-dump-after-file", cl::desc("Dump module after Polly transformations to the given file"), cl::cat(PollyCategory))
static bool shouldEnablePollyForOptimization()
OwningInnerAnalysisManagerProxy< ScopAnalysisManager, Function > OwningScopAnalysisManagerFunctionProxy
static void buildEarlyPollyPipeline(llvm::ModulePassManager &MPM, llvm::OptimizationLevel Level)
OuterAnalysisManagerProxy< FunctionAnalysisManager, Scop, ScopStandardAnalysisResults & > FunctionAnalysisManagerScopProxy
static cl::opt< CodeGenChoice > CodeGeneration("polly-code-generation", cl::desc("How much code-generation to perform"), cl::values(clEnumValN(CODEGEN_FULL, "full", "AST and IR generation"), clEnumValN(CODEGEN_AST, "ast", "Only AST generation"), clEnumValN(CODEGEN_NONE, "none", "No code generation")), cl::Hidden, cl::init(CODEGEN_FULL), cl::cat(PollyCategory))
static bool parseScopPass(StringRef Name, ScopPassManager &SPM, PassInstrumentationCallbacks *PIC)
A pass that isolates a function into a new Module and writes it into a file.
A pass that prints the module into a file.
This pass exports a scop to a jscop file.
This pass imports a scop from a jscop file.