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/TargetSelect.h"
51#include "llvm/Transforms/IPO.h"
53namespace cl = llvm::cl;
55using llvm::FunctionPassManager;
56using llvm::OptimizationLevel;
57using llvm::PassBuilder;
58using llvm::PassInstrumentationCallbacks;
61 "Configure the polly loop optimizer");
66 cl::desc(
"Enable the polly optimizer (with -O1, -O2 or -O3)"),
70 "polly-only-scop-detection",
71 cl::desc(
"Only run scop detection, but no other optimizations"),
79 "polly-position", cl::desc(
"Where to run polly in the pass pipeline"),
80 cl::values(clEnumValN(
POSITION_EARLY,
"early",
"Before everything"),
82 "Right before the vectorizer")),
85static cl::opt<OptimizerChoice>
86 Optimizer(
"polly-optimizer", cl::desc(
"Select the scheduling optimizer"),
89 "The isl scheduling optimizer")),
94 "polly-code-generation", cl::desc(
"How much code-generation to perform"),
95 cl::values(clEnumValN(
CODEGEN_FULL,
"full",
"AST and IR generation"),
96 clEnumValN(
CODEGEN_AST,
"ast",
"Only AST generation"),
103 "polly-vectorizer", cl::desc(
"Select the vectorization strategy"),
108 "Strip-mine outer loops for the loop-vectorizer to trigger")),
114 cl::desc(
"Import the polyhedral description of the detected Scops"),
119 cl::desc(
"Fully expand the memory accesses of the detected Scops"),
124 cl::desc(
"Export the polyhedral description of the detected Scops"),
128 cl::desc(
"Run the dead code elimination"),
133 cl::desc(
"Highlight the code regions that will be optimized in a "
134 "(CFG BBs and LLVM-IR instructions)"),
139 cl::desc(
"Highlight the code regions that will be optimized in "
144 PollyPrinter(
"polly-dot", cl::desc(
"Enable the Polly DOT printer in -O3"),
145 cl::Hidden, cl::value_desc(
"Run the Polly DOT printer at -O3"),
150 cl::desc(
"Enable the Polly DOT printer in -O3 (no BB content)"), cl::Hidden,
151 cl::value_desc(
"Run the Polly DOT printer at -O3 (no BB content"),
156 cl::desc(
"Show the Polly CFG right after code generation"),
161 cl::desc(
"Enable operand tree forwarding"), cl::Hidden,
166 cl::desc(
"Dump module before Polly transformations into a file "
167 "suffixed with \"-before\""),
171 "polly-dump-before-file",
172 cl::desc(
"Dump module before Polly transformations to the given file"),
177 cl::desc(
"Dump module after Polly transformations into a file "
178 "suffixed with \"-after\""),
182 "polly-dump-after-file",
183 cl::desc(
"Dump module after Polly transformations to the given file"),
188 cl::desc(
"Eliminate scalar loop carried dependences"),
193 cl::desc(
"Simplify SCoP after optimizations"),
197 "polly-enable-prune-unprofitable",
198 cl::desc(
"Bail out on unprofitable SCoPs before rescheduling"), cl::Hidden,
208struct StaticInitializer {
209 StaticInitializer() {
210 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
214static StaticInitializer InitializeEverything;
304 OptimizationLevel Level,
378 PM.addPass(PB.buildFunctionSimplificationPipeline(
379 Level, llvm::ThinOrFullLTOPhase::None));
382 PM.addPass(llvm::CFGPrinterPass());
386 llvm::OptimizationLevel Level) {
395 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
402 FPM = FunctionPassManager();
406 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
415 llvm::OptimizationLevel Level) {
424 llvm::report_fatal_error(
425 "Option -polly-dump-before-file at -polly-position=late "
426 "not supported with NPM",
434 llvm::report_fatal_error(
435 "Option -polly-dump-after-file at -polly-position=late "
436 "not supported with NPM",
442 PassInstrumentationCallbacks *PIC) {
444#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
445 Proxy.getManager().registerPass([PIC] { \
447 return CREATE_PASS; \
449#include "PollyPasses.def"
457 PassInstrumentationCallbacks *PIC) {
459#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
460 FAM.registerPass([] { return CREATE_PASS; });
462#include "PollyPasses.def"
469 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
470 if (llvm::parseAnalysisUtilityPasses<OwningScopAnalysisManagerFunctionProxy>(
471 "polly-scop-analyses", Name, FPM))
474#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
475 if (llvm::parseAnalysisUtilityPasses< \
476 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
480#define FUNCTION_PASS(NAME, CREATE_PASS) \
481 if (Name == NAME) { \
482 FPM.addPass(CREATE_PASS); \
486#include "PollyPasses.def"
491 PassInstrumentationCallbacks *PIC) {
492#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
493 if (llvm::parseAnalysisUtilityPasses< \
494 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
498#define SCOP_PASS(NAME, CREATE_PASS) \
499 if (Name == NAME) { \
500 SPM.addPass(CREATE_PASS); \
504#include "PollyPasses.def"
510 PassInstrumentationCallbacks *PIC,
511 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
514 if (!Pipeline.empty()) {
516 for (
const auto &E : Pipeline)
525#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
526 if (Name == "require<" NAME ">") \
528 if (Name == "invalidate<" NAME ">") \
531#define SCOP_PASS(NAME, CREATE_PASS) \
535#include "PollyPasses.def"
542 PassInstrumentationCallbacks *PIC,
543 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
544 std::vector<PassBuilder::PipelineElement> FullPipeline;
545 StringRef FirstName = Pipeline.front().Name;
550 FunctionPassManager FPM;
553 for (
auto &Element : Pipeline) {
554 auto &Name = Element.Name;
555 auto &InnerPipeline = Element.InnerPipeline;
556 if (!InnerPipeline.empty())
563 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
595 PassInstrumentationCallbacks *PIC = PB.getPassInstrumentationCallbacks();
596 PB.registerAnalysisRegistrationCallback([PIC](FunctionAnalysisManager &FAM) {
600 PB.registerPipelineParsingCallback(
601 [PIC](StringRef Name, FunctionPassManager &FPM,
602 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
605 PB.registerParseTopLevelPipelineCallback(
606 [PIC](llvm::ModulePassManager &MPM,
607 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
623 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.