Skip to content

Commit

Permalink
[polly][NFC] removes using-directives to fix modules build
Browse files Browse the repository at this point in the history
When compiling with Clang modules enabled, polly's use of using-directives
caused the global object `Target` in RegisterPasses.cpp to clash with
`llvm::Target`. By eliminating the using-directives, we're able to get
polly to play nicely with a modules build.

Differential Revision: https://reviews.llvm.org/D119809
  • Loading branch information
cjdb committed Feb 15, 2022
1 parent f6ded53 commit e51e7e7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 50 deletions.
18 changes: 9 additions & 9 deletions polly/lib/Support/PollyPasses.def
Expand Up @@ -9,14 +9,14 @@ FUNCTION_ANALYSIS("polly-function-scops", ScopInfoAnalysis())
#define FUNCTION_PASS(NAME, CREATE_PASS)
#endif
FUNCTION_PASS("polly-prepare", CodePreparationPass())
FUNCTION_PASS("print<polly-detect>", ScopAnalysisPrinterPass(errs()))
FUNCTION_PASS("print<polly-function-scops>", ScopInfoPrinterPass(errs()))
FUNCTION_PASS("print<polly-detect>", ScopAnalysisPrinterPass(llvm::errs()))
FUNCTION_PASS("print<polly-function-scops>", ScopInfoPrinterPass(llvm::errs()))
#undef FUNCTION_PASS

#ifndef SCOP_ANALYSIS
#define SCOP_ANALYSIS(NAME, CREATE_PASS)
#endif
SCOP_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
SCOP_ANALYSIS("pass-instrumentation", llvm::PassInstrumentationAnalysis(PIC))
SCOP_ANALYSIS("polly-ast", IslAstAnalysis())
SCOP_ANALYSIS("polly-dependences", DependenceAnalysis())
#undef SCOP_ANALYSIS
Expand All @@ -26,17 +26,17 @@ SCOP_ANALYSIS("polly-dependences", DependenceAnalysis())
#endif
SCOP_PASS("polly-export-jscop", JSONExportPass())
SCOP_PASS("polly-import-jscop", JSONImportPass())
SCOP_PASS("print<polly-ast>", IslAstPrinterPass(outs()))
SCOP_PASS("print<polly-dependences>", DependenceInfoPrinterPass(outs()))
SCOP_PASS("print<polly-ast>", IslAstPrinterPass(llvm::outs()))
SCOP_PASS("print<polly-dependences>", DependenceInfoPrinterPass(llvm::outs()))
SCOP_PASS("polly-codegen", CodeGenerationPass())
SCOP_PASS("polly-simplify", SimplifyPass())
SCOP_PASS("print<polly-simplify>", SimplifyPrinterPass(outs()))
SCOP_PASS("print<polly-simplify>", SimplifyPrinterPass(llvm::outs()))
SCOP_PASS("polly-optree", ForwardOpTreePass())
SCOP_PASS("print<polly-optree>", ForwardOpTreePrinterPass(outs()))
SCOP_PASS("print<polly-optree>", ForwardOpTreePrinterPass(llvm::outs()))
SCOP_PASS("polly-delicm", DeLICMPass())
SCOP_PASS("print<polly-delicm>", DeLICMPrinterPass(outs()))
SCOP_PASS("print<polly-delicm>", DeLICMPrinterPass(llvm::outs()))
SCOP_PASS("polly-prune-unprofitable", PruneUnprofitablePass())
SCOP_PASS("polly-opt-isl", IslScheduleOptimizerPass())
SCOP_PASS("print<polly-opt-isl>", IslScheduleOptimizerPrinterPass(outs()))
SCOP_PASS("print<polly-opt-isl>", IslScheduleOptimizerPrinterPass(llvm::outs()))
SCOP_PASS("polly-dce", DeadCodeElimPass())
#undef SCOP_PASS
96 changes: 55 additions & 41 deletions polly/lib/Support/RegisterPasses.cpp
Expand Up @@ -40,6 +40,7 @@
#include "polly/Support/DumpModulePass.h"
#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/PassPlugin.h"
Expand All @@ -48,12 +49,17 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"

using namespace llvm;
using namespace polly;
namespace cl = llvm::cl;

using llvm::FunctionPassManager;
using llvm::OptimizationLevel;
using llvm::PassBuilder;
using llvm::PassInstrumentationCallbacks;

cl::OptionCategory PollyCategory("Polly Options",
"Configure the polly loop optimizer");

namespace polly {
static cl::opt<bool>
PollyEnabled("polly",
cl::desc("Enable the polly optimizer (with -O1, -O2 or -O3)"),
Expand Down Expand Up @@ -112,17 +118,17 @@ static cl::opt<TargetChoice>
),
cl::init(TARGET_CPU), cl::ZeroOrMore, cl::cat(PollyCategory));

VectorizerChoice polly::PollyVectorizerChoice;
static cl::opt<polly::VectorizerChoice, true> Vectorizer(
VectorizerChoice PollyVectorizerChoice;

static cl::opt<VectorizerChoice, true> Vectorizer(
"polly-vectorizer", cl::desc("Select the vectorization strategy"),
cl::values(
clEnumValN(polly::VECTORIZER_NONE, "none", "No Vectorization"),
clEnumValN(polly::VECTORIZER_POLLY, "polly",
"Polly internal vectorizer"),
clEnumValN(VECTORIZER_NONE, "none", "No Vectorization"),
clEnumValN(VECTORIZER_POLLY, "polly", "Polly internal vectorizer"),
clEnumValN(
polly::VECTORIZER_STRIPMINE, "stripmine",
VECTORIZER_STRIPMINE, "stripmine",
"Strip-mine outer loops for the loop-vectorizer to trigger")),
cl::location(PollyVectorizerChoice), cl::init(polly::VECTORIZER_NONE),
cl::location(PollyVectorizerChoice), cl::init(VECTORIZER_NONE),
cl::ZeroOrMore, cl::cat(PollyCategory));

static cl::opt<bool> ImportJScop(
Expand Down Expand Up @@ -237,8 +243,7 @@ class StaticInitializer {
static StaticInitializer InitializeEverything;
} // end of anonymous namespace.

namespace polly {
void initializePollyPasses(PassRegistry &Registry) {
void initializePollyPasses(llvm::PassRegistry &Registry) {
initializeCodeGenerationPass(Registry);

#ifdef GPU_CODEGEN
Expand Down Expand Up @@ -395,7 +400,7 @@ static void registerPollyPasses(llvm::legacy::PassManagerBase &PM,
// FIXME: This dummy ModulePass keeps some programs from miscompiling,
// probably some not correctly preserved analyses. It acts as a barrier to
// force all analysis results to be recomputed.
PM.add(createBarrierNoopPass());
PM.add(llvm::createBarrierNoopPass());

if (DumpAfter)
PM.add(polly::createDumpModuleWrapperPass("-after", true));
Expand Down Expand Up @@ -491,15 +496,18 @@ static void buildCommonPollyPipeline(FunctionPassManager &PM,
}

if (PollyViewer)
report_fatal_error("Option -polly-show not supported with NPM", false);
llvm::report_fatal_error("Option -polly-show not supported with NPM",
false);
if (PollyOnlyViewer)
report_fatal_error("Option -polly-show-only not supported with NPM", false);
llvm::report_fatal_error("Option -polly-show-only not supported with NPM",
false);
if (PollyPrinter)
report_fatal_error("Option -polly-dot not supported with NPM", false);
llvm::report_fatal_error("Option -polly-dot not supported with NPM", false);
if (PollyOnlyPrinter)
report_fatal_error("Option -polly-dot-only not supported with NPM", false);
llvm::report_fatal_error("Option -polly-dot-only not supported with NPM",
false);
if (EnablePolyhedralInfo)
report_fatal_error(
llvm::report_fatal_error(
"Option -polly-enable-polyhedralinfo not supported with NPM", false);

if (EnableSimplify)
Expand All @@ -518,8 +526,8 @@ static void buildCommonPollyPipeline(FunctionPassManager &PM,
SPM.addPass(DeadCodeElimPass());

if (FullyIndexedStaticExpansion)
report_fatal_error("Option -polly-enable-mse not supported with NPM",
false);
llvm::report_fatal_error("Option -polly-enable-mse not supported with NPM",
false);

if (EnablePruneUnprofitable)
SPM.addPass(PruneUnprofitablePass());
Expand All @@ -535,7 +543,8 @@ static void buildCommonPollyPipeline(FunctionPassManager &PM,
}

if (ExportJScop)
report_fatal_error("Option -polly-export not supported with NPM", false);
llvm::report_fatal_error("Option -polly-export not supported with NPM",
false);

if (!EnableForOpt)
return;
Expand All @@ -544,8 +553,9 @@ static void buildCommonPollyPipeline(FunctionPassManager &PM,
switch (CodeGeneration) {
case CODEGEN_AST:
SPM.addPass(
RequireAnalysisPass<IslAstAnalysis, Scop, ScopAnalysisManager,
ScopStandardAnalysisResults &, SPMUpdater &>());
llvm::RequireAnalysisPass<IslAstAnalysis, Scop, ScopAnalysisManager,
ScopStandardAnalysisResults &,
SPMUpdater &>());
break;
case CODEGEN_FULL:
SPM.addPass(CodeGenerationPass());
Expand All @@ -556,25 +566,26 @@ static void buildCommonPollyPipeline(FunctionPassManager &PM,
}
#ifdef GPU_CODEGEN
else
report_fatal_error("Option -polly-target=gpu not supported for NPM", false);
llvm::report_fatal_error("Option -polly-target=gpu not supported for NPM",
false);
#endif

#ifdef GPU_CODEGEN
if (Target == TARGET_HYBRID)
report_fatal_error("Option -polly-target=hybrid not supported for NPM",
false);
llvm::report_fatal_error(
"Option -polly-target=hybrid not supported for NPM", false);
#endif

PM.addPass(createFunctionToScopPassAdaptor(std::move(SPM)));
PM.addPass(PB.buildFunctionSimplificationPipeline(
Level, ThinOrFullLTOPhase::None)); // Cleanup
Level, llvm::ThinOrFullLTOPhase::None)); // Cleanup

if (CFGPrinter)
PM.addPass(llvm::CFGPrinterPass());
}

static void buildEarlyPollyPipeline(ModulePassManager &MPM,
OptimizationLevel Level) {
static void buildEarlyPollyPipeline(llvm::ModulePassManager &MPM,
llvm::OptimizationLevel Level) {
bool EnableForOpt =
shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
Expand Down Expand Up @@ -603,7 +614,7 @@ static void buildEarlyPollyPipeline(ModulePassManager &MPM,
}

static void buildLatePollyPipeline(FunctionPassManager &PM,
OptimizationLevel Level) {
llvm::OptimizationLevel Level) {
bool EnableForOpt =
shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed();
if (!shouldEnablePollyForDiagnostic() && !EnableForOpt)
Expand All @@ -612,18 +623,20 @@ static void buildLatePollyPipeline(FunctionPassManager &PM,
if (DumpBefore)
PM.addPass(DumpFunctionPass("-before"));
if (!DumpBeforeFile.empty())
report_fatal_error("Option -polly-dump-before-file at -polly-position=late "
"not supported with NPM",
false);
llvm::report_fatal_error(
"Option -polly-dump-before-file at -polly-position=late "
"not supported with NPM",
false);

buildCommonPollyPipeline(PM, Level, EnableForOpt);

if (DumpAfter)
PM.addPass(DumpFunctionPass("-after"));
if (!DumpAfterFile.empty())
report_fatal_error("Option -polly-dump-after-file at -polly-position=late "
"not supported with NPM",
false);
llvm::report_fatal_error(
"Option -polly-dump-after-file at -polly-position=late "
"not supported with NPM",
false);
}

/// Register Polly to be available as an optimizer
Expand Down Expand Up @@ -705,12 +718,12 @@ static void registerFunctionAnalyses(FunctionAnalysisManager &FAM,
static bool
parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
ArrayRef<PassBuilder::PipelineElement> Pipeline) {
if (parseAnalysisUtilityPasses<OwningScopAnalysisManagerFunctionProxy>(
if (llvm::parseAnalysisUtilityPasses<OwningScopAnalysisManagerFunctionProxy>(
"polly-scop-analyses", Name, FPM))
return true;

#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
if (parseAnalysisUtilityPasses< \
if (llvm::parseAnalysisUtilityPasses< \
std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
FPM)) \
return true;
Expand All @@ -728,7 +741,7 @@ parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
static bool parseScopPass(StringRef Name, ScopPassManager &SPM,
PassInstrumentationCallbacks *PIC) {
#define SCOP_ANALYSIS(NAME, CREATE_PASS) \
if (parseAnalysisUtilityPasses< \
if (llvm::parseAnalysisUtilityPasses< \
std::remove_reference<decltype(CREATE_PASS)>::type>(NAME, Name, \
SPM)) \
return true;
Expand Down Expand Up @@ -776,7 +789,8 @@ static bool isScopPassName(StringRef Name) {
}

static bool
parseTopLevelPipeline(ModulePassManager &MPM, PassInstrumentationCallbacks *PIC,
parseTopLevelPipeline(llvm::ModulePassManager &MPM,
PassInstrumentationCallbacks *PIC,
ArrayRef<PassBuilder::PipelineElement> Pipeline) {
std::vector<PassBuilder::PipelineElement> FullPipeline;
StringRef FirstName = Pipeline.front().Name;
Expand Down Expand Up @@ -814,7 +828,7 @@ void registerPollyPasses(PassBuilder &PB) {
return parseScopPipeline(Name, FPM, PIC, Pipeline);
});
PB.registerParseTopLevelPipelineCallback(
[PIC](ModulePassManager &MPM,
[PIC](llvm::ModulePassManager &MPM,
ArrayRef<PassBuilder::PipelineElement> Pipeline) -> bool {
return parseTopLevelPipeline(MPM, PIC, Pipeline);
});
Expand All @@ -824,7 +838,7 @@ void registerPollyPasses(PassBuilder &PB) {
PB.registerPipelineStartEPCallback(buildEarlyPollyPipeline);
break;
case POSITION_AFTER_LOOPOPT:
report_fatal_error(
llvm::report_fatal_error(
"Option -polly-position=after-loopopt not supported with NPM", false);
break;
case POSITION_BEFORE_VECTORIZER:
Expand Down

0 comments on commit e51e7e7

Please sign in to comment.