43#include "llvm/Analysis/CFGPrinter.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"
52#include "llvm/Transforms/IPO/PassManagerBuilder.h"
54namespace cl = llvm::cl;
56using llvm::FunctionPassManager;
57using llvm::OptimizationLevel;
58using llvm::PassBuilder;
59using llvm::PassInstrumentationCallbacks;
62 "Configure the polly loop optimizer");
67 cl::desc(
"Enable the polly optimizer (with -O1, -O2 or -O3)"),
71 "polly-only-scop-detection",
72 cl::desc(
"Only run scop detection, but no other optimizations"),
80 "polly-position", cl::desc(
"Where to run polly in the pass pipeline"),
81 cl::values(clEnumValN(
POSITION_EARLY,
"early",
"Before everything"),
83 "Right before the vectorizer")),
86static cl::opt<OptimizerChoice>
87 Optimizer(
"polly-optimizer", cl::desc(
"Select the scheduling optimizer"),
90 "The isl scheduling optimizer")),
95 "polly-code-generation", cl::desc(
"How much code-generation to perform"),
96 cl::values(clEnumValN(
CODEGEN_FULL,
"full",
"AST and IR generation"),
97 clEnumValN(
CODEGEN_AST,
"ast",
"Only AST generation"),
104 "polly-vectorizer", cl::desc(
"Select the vectorization strategy"),
110 "Strip-mine outer loops for the loop-vectorizer to trigger")),
116 cl::desc(
"Import the polyhedral description of the detected Scops"),
121 cl::desc(
"Fully expand the memory accesses of the detected Scops"),
126 cl::desc(
"Export the polyhedral description of the detected Scops"),
130 cl::desc(
"Run the dead code elimination"),
135 cl::desc(
"Highlight the code regions that will be optimized in a "
136 "(CFG BBs and LLVM-IR instructions)"),
141 cl::desc(
"Highlight the code regions that will be optimized in "
146 PollyPrinter(
"polly-dot", cl::desc(
"Enable the Polly DOT printer in -O3"),
147 cl::Hidden, cl::value_desc(
"Run the Polly DOT printer at -O3"),
152 cl::desc(
"Enable the Polly DOT printer in -O3 (no BB content)"), cl::Hidden,
153 cl::value_desc(
"Run the Polly DOT printer at -O3 (no BB content"),
158 cl::desc(
"Show the Polly CFG right after code generation"),
163 cl::desc(
"Enable operand tree forwarding"), cl::Hidden,
168 cl::desc(
"Dump module before Polly transformations into a file "
169 "suffixed with \"-before\""),
173 "polly-dump-before-file",
174 cl::desc(
"Dump module before Polly transformations to the given file"),
179 cl::desc(
"Dump module after Polly transformations into a file "
180 "suffixed with \"-after\""),
184 "polly-dump-after-file",
185 cl::desc(
"Dump module after Polly transformations to the given file"),
190 cl::desc(
"Eliminate scalar loop carried dependences"),
195 cl::desc(
"Simplify SCoP after optimizations"),
199 "polly-enable-prune-unprofitable",
200 cl::desc(
"Bail out on unprofitable SCoPs before rescheduling"), cl::Hidden,
210struct StaticInitializer {
211 StaticInitializer() {
212 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
216static StaticInitializer InitializeEverything;
220 initializeCodeGenerationPass(Registry);
223 initializePPCGCodeGenerationPass(Registry);
224 initializeManagedMemoryRewritePassPass(Registry);
225 LLVMInitializeNVPTXTarget();
226 LLVMInitializeNVPTXTargetInfo();
227 LLVMInitializeNVPTXTargetMC();
228 LLVMInitializeNVPTXAsmPrinter();
230 initializeCodePreparationPass(Registry);
231 initializeDeadCodeElimWrapperPassPass(Registry);
232 initializeDependenceInfoPass(Registry);
233 initializeDependenceInfoPrinterLegacyPassPass(Registry);
234 initializeDependenceInfoWrapperPassPass(Registry);
235 initializeDependenceInfoPrinterLegacyFunctionPassPass(Registry);
236 initializeJSONExporterPass(Registry);
237 initializeJSONImporterPass(Registry);
238 initializeJSONImporterPrinterLegacyPassPass(Registry);
239 initializeMaximalStaticExpanderWrapperPassPass(Registry);
240 initializeIslAstInfoWrapperPassPass(Registry);
241 initializeIslAstInfoPrinterLegacyPassPass(Registry);
242 initializeIslScheduleOptimizerWrapperPassPass(Registry);
243 initializeIslScheduleOptimizerPrinterLegacyPassPass(Registry);
244 initializePollyCanonicalizePass(Registry);
245 initializePolyhedralInfoPass(Registry);
246 initializePolyhedralInfoPrinterLegacyPassPass(Registry);
247 initializeScopDetectionWrapperPassPass(Registry);
248 initializeScopDetectionPrinterLegacyPassPass(Registry);
249 initializeScopInlinerPass(Registry);
250 initializeScopInfoRegionPassPass(Registry);
251 initializeScopInfoPrinterLegacyRegionPassPass(Registry);
252 initializeScopInfoWrapperPassPass(Registry);
253 initializeScopInfoPrinterLegacyFunctionPassPass(Registry);
254 initializeCodegenCleanupPass(Registry);
255 initializeFlattenSchedulePass(Registry);
256 initializeFlattenSchedulePrinterLegacyPassPass(Registry);
257 initializeForwardOpTreeWrapperPassPass(Registry);
258 initializeForwardOpTreePrinterLegacyPassPass(Registry);
259 initializeDeLICMWrapperPassPass(Registry);
260 initializeDeLICMPrinterLegacyPassPass(Registry);
261 initializeSimplifyWrapperPassPass(Registry);
262 initializeSimplifyPrinterLegacyPassPass(Registry);
263 initializeDumpModuleWrapperPassPass(Registry);
264 initializePruneUnprofitableWrapperPassPass(Registry);
315 OptimizationLevel Level,
389 PM.addPass(PB.buildFunctionSimplificationPipeline(
390 Level, llvm::ThinOrFullLTOPhase::None));
393 PM.addPass(llvm::CFGPrinterPass());
397 llvm::OptimizationLevel Level) {
406 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
413 FPM = FunctionPassManager();
417 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
426 llvm::OptimizationLevel Level) {
435 llvm::report_fatal_error(
436 "Option -polly-dump-before-file at -polly-position=late "
437 "not supported with NPM",
445 llvm::report_fatal_error(
446 "Option -polly-dump-after-file at -polly-position=late "
447 "not supported with NPM",
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"
480 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
481 if (llvm::parseAnalysisUtilityPasses<OwningScopAnalysisManagerFunctionProxy>(
482 "polly-scop-analyses", Name, FPM))
485#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
486 if (llvm::parseAnalysisUtilityPasses< \
487 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
491#define FUNCTION_PASS(NAME, CREATE_PASS) \
492 if (Name == NAME) { \
493 FPM.addPass(CREATE_PASS); \
497#include "PollyPasses.def"
502 PassInstrumentationCallbacks *PIC) {
503#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
504 if (llvm::parseAnalysisUtilityPasses< \
505 std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
509#define SCOP_PASS(NAME, CREATE_PASS) \
510 if (Name == NAME) { \
511 SPM.addPass(CREATE_PASS); \
515#include "PollyPasses.def"
521 PassInstrumentationCallbacks *PIC,
522 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
525 if (!Pipeline.empty()) {
527 for (
const auto &E : Pipeline)
536#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
537 if (Name == "require<" NAME ">") \
539 if (Name == "invalidate<" NAME ">") \
542#define SCOP_PASS(NAME, CREATE_PASS) \
546#include "PollyPasses.def"
553 PassInstrumentationCallbacks *PIC,
554 ArrayRef<PassBuilder::PipelineElement> Pipeline) {
555 std::vector<PassBuilder::PipelineElement> FullPipeline;
556 StringRef FirstName = Pipeline.front().Name;
561 FunctionPassManager FPM;
564 for (
auto &Element : Pipeline) {
565 auto &Name = Element.Name;
566 auto &InnerPipeline = Element.InnerPipeline;
567 if (!InnerPipeline.empty())
574 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
606 PassInstrumentationCallbacks *PIC = PB.getPassInstrumentationCallbacks();
607 PB.registerAnalysisRegistrationCallback([PIC](FunctionAnalysisManager &FAM) {
611 PB.registerPipelineParsingCallback(
612 [PIC](StringRef Name, FunctionPassManager &FPM,
613 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
616 PB.registerParseTopLevelPipelineCallback(
617 [PIC](llvm::ModulePassManager &MPM,
618 ArrayRef<PassBuilder::PipelineElement> Pipeline) ->
bool {
634 return {LLVM_PLUGIN_API_VERSION,
"Polly", LLVM_VERSION_STRING,
llvm::cl::OptionCategory PollyCategory
llvm::PassPluginLibraryInfo getPollyPluginInfo()
AnalysisManagerT & getManager()
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< 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 cl::opt< VectorizerChoice, true > Vectorizer("polly-vectorizer", cl::desc("Select the vectorization strategy"), cl::values(clEnumValN(VECTORIZER_NONE, "none", "No Vectorization"), clEnumValN(VECTORIZER_POLLY, "polly", "Polly internal vectorizer"), 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 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.