42#include "llvm/Analysis/CFGPrinter.h"
43#include "llvm/Config/llvm-config.h"
44#include "llvm/IR/LegacyPassManager.h"
45#include "llvm/IR/PassManager.h"
46#include "llvm/IR/Verifier.h"
47#include "llvm/Passes/PassBuilder.h"
48#include "llvm/Passes/PassPlugin.h"
49#include "llvm/Support/CommandLine.h"
50#include "llvm/Support/Error.h"
51#include "llvm/Support/TargetSelect.h"
52#include "llvm/Transforms/IPO.h"
55namespace cl = llvm::cl;
58using llvm::FunctionPassManager;
59using llvm::OptimizationLevel;
60using llvm::PassBuilder;
61using llvm::PassInstrumentationCallbacks;
64 "Configure the polly loop optimizer");
69 cl::desc(
"Enable the polly optimizer (with -O1, -O2 or -O3)"),
73 "polly-only-scop-detection",
74 cl::desc(
"Only run scop detection, but no other optimizations"),
82 "polly-position", cl::desc(
"Where to run polly in the pass pipeline"),
83 cl::values(clEnumValN(
POSITION_EARLY,
"early",
"Before everything"),
85 "Right before the vectorizer")),
88static cl::opt<OptimizerChoice>
89 Optimizer(
"polly-optimizer", cl::desc(
"Select the scheduling optimizer"),
92 "The isl scheduling optimizer")),
97 "polly-code-generation", cl::desc(
"How much code-generation to perform"),
98 cl::values(clEnumValN(
CODEGEN_FULL,
"full",
"AST and IR generation"),
99 clEnumValN(
CODEGEN_AST,
"ast",
"Only AST generation"),
100 clEnumValN(
CODEGEN_NONE,
"none",
"No code generation")),
106 "polly-vectorizer", cl::desc(
"Select the vectorization strategy"),
111 "Strip-mine outer loops for the loop-vectorizer to trigger")),
117 cl::desc(
"Import the polyhedral description of the detected Scops"),
122 cl::desc(
"Fully expand the memory accesses of the detected Scops"),
127 cl::desc(
"Export the polyhedral description of the detected Scops"),
131 cl::desc(
"Run the dead code elimination"),
136 cl::desc(
"Highlight the code regions that will be optimized in a "
137 "(CFG BBs and LLVM-IR instructions)"),
142 cl::desc(
"Highlight the code regions that will be optimized in "
147 PollyPrinter(
"polly-dot", cl::desc(
"Enable the Polly DOT printer in -O3"),
148 cl::Hidden, cl::value_desc(
"Run the Polly DOT printer at -O3"),
153 cl::desc(
"Enable the Polly DOT printer in -O3 (no BB content)"), cl::Hidden,
154 cl::value_desc(
"Run the Polly DOT printer at -O3 (no BB content"),
159 cl::desc(
"Show the Polly CFG right after code generation"),
164 cl::desc(
"Enable operand tree forwarding"), cl::Hidden,
169 cl::desc(
"Dump module before Polly transformations into a file "
170 "suffixed with \"-before\""),
174 "polly-dump-before-file",
175 cl::desc(
"Dump module before Polly transformations to the given file"),
180 cl::desc(
"Dump module after Polly transformations into a file "
181 "suffixed with \"-after\""),
185 "polly-dump-after-file",
186 cl::desc(
"Dump module after Polly transformations to the given file"),
191 cl::desc(
"Eliminate scalar loop carried dependences"),
196 cl::desc(
"Simplify SCoP after optimizations"),
200 "polly-enable-prune-unprofitable",
201 cl::desc(
"Bail out on unprofitable SCoPs before rescheduling"), cl::Hidden,
211struct StaticInitializer {
212 StaticInitializer() {
213 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
217static StaticInitializer InitializeEverything;
305 OptimizationLevel Level,
379 PM.addPass(PB.buildFunctionSimplificationPipeline(
380 Level, llvm::ThinOrFullLTOPhase::None));
383 PM.addPass(llvm::CFGPrinterPass());
387 llvm::OptimizationLevel Level) {
396 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
403 FPM = FunctionPassManager();
407 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
416 llvm::OptimizationLevel Level) {
425 llvm::report_fatal_error(
426 "Option -polly-dump-before-file at -polly-position=late "
427 "not supported with NPM",
435 llvm::report_fatal_error(
436 "Option -polly-dump-after-file at -polly-position=late "
437 "not supported with NPM",
443 return make_error<StringError>(
444 formatv(
"'{0}' passed to pass that does not take any options", Params)
446 inconvertibleErrorCode());
448 return std::monostate{};
453 PassInstrumentationCallbacks *PIC) {
455#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
456 Proxy.getManager().registerPass([PIC] { \
458 return CREATE_PASS; \
460#include "PollyPasses.def"
468 PassInstrumentationCallbacks *PIC) {
470#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
471 FAM.registerPass([] { return CREATE_PASS; });
473#include "PollyPasses.def"
478static llvm::Expected<bool>
480 PassInstrumentationCallbacks *PIC,
481 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
482#define CGSCC_PASS(NAME, CREATE_PASS, PARSER) \
483 if (PassBuilder::checkParametrizedPassName(Name, NAME)) { \
484 auto Params = PassBuilder::parsePassParameters(PARSER, Name, NAME); \
486 return Params.takeError(); \
487 CGPM.addPass(CREATE_PASS); \
490#include "PollyPasses.def"
497 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
498 if (llvm::parseAnalysisUtilityPasses<OwningScopAnalysisManagerFunctionProxy>(
499 "polly-scop-analyses", Name, FPM))
502#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
503 if (llvm::parseAnalysisUtilityPasses< \
504 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
508#define FUNCTION_PASS(NAME, CREATE_PASS) \
509 if (Name == NAME) { \
510 FPM.addPass(CREATE_PASS); \
514#include "PollyPasses.def"
519 PassInstrumentationCallbacks *PIC) {
520#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
521 if (llvm::parseAnalysisUtilityPasses< \
522 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
526#define SCOP_PASS(NAME, CREATE_PASS) \
527 if (Name == NAME) { \
528 SPM.addPass(CREATE_PASS); \
532#include "PollyPasses.def"
538 PassInstrumentationCallbacks *PIC,
539 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
542 if (!Pipeline.empty()) {
544 for (
const auto &E : Pipeline)
553#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
554 if (Name == "require<" NAME ">") \
556 if (Name == "invalidate<" NAME ">") \
559#define SCOP_PASS(NAME, CREATE_PASS) \
563#include "PollyPasses.def"
570 PassInstrumentationCallbacks *PIC,
571 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
572 StringRef FirstName = Pipeline.front().Name;
577 FunctionPassManager FPM;
580 for (
auto &Element : Pipeline) {
581 auto &Name = Element.Name;
582 auto &InnerPipeline = Element.InnerPipeline;
583 if (!InnerPipeline.empty())
590 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
622 PassInstrumentationCallbacks *PIC = PB.getPassInstrumentationCallbacks();
623 PB.registerAnalysisRegistrationCallback([PIC](FunctionAnalysisManager &FAM) {
627 PB.registerPipelineParsingCallback(
628 [PIC](StringRef Name, FunctionPassManager &FPM,
629 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
632 PB.registerPipelineParsingCallback(
633 [PIC](StringRef Name, CGSCCPassManager &CGPM,
634 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
635 ExitOnError Err(
"Unable to parse Polly call graph pass: ");
638 PB.registerParseTopLevelPipelineCallback(
639 [PIC](llvm::ModulePassManager &MPM,
640 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
656 return {LLVM_PLUGIN_API_VERSION,
"Polly", LLVM_VERSION_STRING,
llvm::cl::OptionCategory PollyCategory
llvm::PassPluginLibraryInfo getPollyPluginInfo()
AnalysisManagerT & getManager()
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 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 initializeScopInlinerWrapperPassPass(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))
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 llvm::Expected< bool > parseCGPipeline(StringRef Name, llvm::CGSCCPassManager &CGPM, PassInstrumentationCallbacks *PIC, ArrayRef< PassBuilder::PipelineElement > Pipeline)
PassManager< Scop, ScopAnalysisManager, ScopStandardAnalysisResults &, SPMUpdater & > ScopPassManager
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))
OuterAnalysisManagerProxy< FunctionAnalysisManager, Scop, ScopStandardAnalysisResults & > FunctionAnalysisManagerScopProxy
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)
OwningInnerAnalysisManagerProxy< ScopAnalysisManager, Function > OwningScopAnalysisManagerFunctionProxy
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()
static llvm::Expected< std::monostate > parseNoOptions(StringRef Params)
AnalysisManager< Scop, ScopStandardAnalysisResults & > ScopAnalysisManager
static void buildEarlyPollyPipeline(llvm::ModulePassManager &MPM, llvm::OptimizationLevel Level)
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.