#include <llvm/IR/DiagnosticPrinter.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/raw_os_ostream.h>
+#include <llvm/Target/TargetMachine.h>
#include <map>
#include <string>
* SizeL - optimize for size
* Vectorize - whether to invoke the vectorizer (only used for legacy PM)
*/
-POCL_EXPORT void populateModulePM (void *Passes, void *Module, unsigned OptL,
- unsigned SizeL, bool Vectorize = true);
+POCL_EXPORT void populateModulePM (void *Passes,
+ void *Module,
+ unsigned OptL,
+ unsigned SizeL,
+ bool Vectorize = true,
+ llvm::TargetMachine *TM = nullptr);
extern std::string CurrentWgMethod;
// devices do not want to vectorize intra work-item at this
// stage.
Vectorize = ((CurrentWgMethod == "loopvec" || CurrentWgMethod == "cbs") &&
- (Dev->spmd == CL_FALSE));
+ (!Dev->spmd));
PTO.SLPVectorization = Vectorize;
PTO.LoopVectorization = Vectorize;
OptimizeLevel = OLevel;
#endif
pocl::registerFunctionAnalyses(PB);
-
// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PM.run(Bitcode, MAM);
#ifdef SEPARATE_OPTIMIZATION_FROM_POCL_PASSES
populateModulePM(nullptr, (void *)&Bitcode, OptimizeLevel, SizeLevel,
- Vectorize);
+ Vectorize, Machine.get());
#endif
}
// NOTE: if you add a new PoCL pass here,
// don't forget to register it in registerPassBuilderPasses
- if (Dev->spmd == CL_FALSE) {
+ if (!Dev->spmd) {
addPass(Passes, "simplifycfg");
addPass(Passes, "loop-simplify");
}
void populateModulePM(void *Passes, void *Module, unsigned OptL, unsigned SizeL,
- bool Vectorize) {
+ bool Vectorize, TargetMachine *TM) {
#if LLVM_MAJOR < MIN_LLVM_NEW_PASSMANAGER
PassManagerBuilder Builder;
Builder.OptLevel = OptL;
LegacyPasses->run(*Mod);
}
#else
+
+ PipelineTuningOptions PTO;
+
+ // Let the loopvec decide when to unroll.
+ PTO.LoopUnrolling = false;
+#if LLVM_MAJOR > 16
+ PTO.UnifiedLTO = false;
+#endif
+ PTO.SLPVectorization = Vectorize;
+ PTO.LoopVectorization = Vectorize;
+
+#ifdef DEBUG_NEW_PASS_MANAGER
+ PrintPassOptions PrintPassOpts;
+ PassInstrumentationCallbacks PIC;
+ llvm::LLVMContext Context; // for SI
+ std::unique_ptr<StandardInstrumentations> SI;
+ PrintPassOpts.Verbose = true;
+ PrintPassOpts.SkipAnalyses = false;
+ PrintPassOpts.Indent = true;
+ SI.reset(new StandardInstrumentations(Context,
+ true, // debug logging
+ false, // verify each
+ PrintPassOpts));
+ SI->registerCallbacks(PIC, &MAM);
+
+ PassBuilder PB(TM, PTO, std::nullopt, &PIC);
+#else
+ PassBuilder PB(TM, PTO);
+#endif
+
// Create the analysis managers.
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
- // Create the new pass manager builder.
- // Take a look at the PassBuilder constructor parameters for more
- // customization, e.g. specifying a TargetMachine or various debugging
- // options.
- PassBuilder PB;
-
// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);