summaryrefslogtreecommitdiffstats
path: root/llvm/tools/opt
diff options
context:
space:
mode:
authorFedor Sergeev <fedor.sergeev@azul.com>2018-10-17 10:36:23 +0000
committerFedor Sergeev <fedor.sergeev@azul.com>2018-10-17 10:36:23 +0000
commitbd6b2138b94a47a9226ec1e69bf3be55a47fd1ef (patch)
treede58f3925965bf772e2becdad7ff066b456d90ed /llvm/tools/opt
parent8a08412533536cf433097817e9f155a4ce68252b (diff)
downloadbcm5719-llvm-bd6b2138b94a47a9226ec1e69bf3be55a47fd1ef.tar.gz
bcm5719-llvm-bd6b2138b94a47a9226ec1e69bf3be55a47fd1ef.zip
[NewPM] teach -passes= to emit meaningful error messages
All the PassBuilder::parse interfaces now return descriptive StringError instead of a plain bool. It allows to make -passes/aa-pipeline parsing errors context-specific and thus less confusing. TODO: ideally we should also make suggestions for misspelled pass names, but that requires some extensions to PassBuilder. Reviewed By: philip.pfaffe, chandlerc Differential Revision: https://reviews.llvm.org/D53246 llvm-svn: 344685
Diffstat (limited to 'llvm/tools/opt')
-rw-r--r--llvm/tools/opt/NewPMDriver.cpp90
1 files changed, 52 insertions, 38 deletions
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index e63547a79d0..e2f9a06523a 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -118,18 +118,20 @@ static cl::opt<bool> DebugInfoForProfiling(
/// @}}
template <typename PassManagerT>
-bool tryParsePipelineText(PassBuilder &PB, StringRef PipelineText) {
- if (PipelineText.empty())
+bool tryParsePipelineText(PassBuilder &PB,
+ const cl::opt<std::string> &PipelineOpt) {
+ if (PipelineOpt.empty())
return false;
// Verify the pipeline is parseable:
PassManagerT PM;
- if (PB.parsePassPipeline(PM, PipelineText))
- return true;
-
- errs() << "Could not parse pipeline '" << PipelineText
- << "'. I'm going to igore it.\n";
- return false;
+ if (auto Err = PB.parsePassPipeline(PM, PipelineOpt)) {
+ errs() << "Could not parse -" << PipelineOpt.ArgStr
+ << " pipeline: " << toString(std::move(Err))
+ << "... I'm going to ignore it.\n";
+ return false;
+ }
+ return true;
}
/// If one of the EPPipeline command line options was given, register callbacks
@@ -137,50 +139,61 @@ bool tryParsePipelineText(PassBuilder &PB, StringRef PipelineText) {
static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass,
bool DebugLogging) {
if (tryParsePipelineText<FunctionPassManager>(PB, PeepholeEPPipeline))
- PB.registerPeepholeEPCallback([&PB, VerifyEachPass, DebugLogging](
- FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
- PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass,
- DebugLogging);
- });
+ PB.registerPeepholeEPCallback(
+ [&PB, VerifyEachPass, DebugLogging](
+ FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
+ ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass,
+ DebugLogging));
+ });
if (tryParsePipelineText<LoopPassManager>(PB,
LateLoopOptimizationsEPPipeline))
PB.registerLateLoopOptimizationsEPCallback(
[&PB, VerifyEachPass, DebugLogging](
LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
- PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline,
- VerifyEachPass, DebugLogging);
+ ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline,
+ VerifyEachPass, DebugLogging));
});
if (tryParsePipelineText<LoopPassManager>(PB, LoopOptimizerEndEPPipeline))
- PB.registerLoopOptimizerEndEPCallback([&PB, VerifyEachPass, DebugLogging](
- LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
- PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline, VerifyEachPass,
- DebugLogging);
- });
+ PB.registerLoopOptimizerEndEPCallback(
+ [&PB, VerifyEachPass, DebugLogging](
+ LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
+ ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline,
+ VerifyEachPass, DebugLogging));
+ });
if (tryParsePipelineText<FunctionPassManager>(PB,
ScalarOptimizerLateEPPipeline))
PB.registerScalarOptimizerLateEPCallback(
[&PB, VerifyEachPass, DebugLogging](
FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
- PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline,
- VerifyEachPass, DebugLogging);
+ ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline,
+ VerifyEachPass, DebugLogging));
});
if (tryParsePipelineText<CGSCCPassManager>(PB, CGSCCOptimizerLateEPPipeline))
- PB.registerCGSCCOptimizerLateEPCallback([&PB, VerifyEachPass, DebugLogging](
- CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) {
- PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline, VerifyEachPass,
- DebugLogging);
- });
+ PB.registerCGSCCOptimizerLateEPCallback(
+ [&PB, VerifyEachPass, DebugLogging](
+ CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) {
+ ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline,
+ VerifyEachPass, DebugLogging));
+ });
if (tryParsePipelineText<FunctionPassManager>(PB, VectorizerStartEPPipeline))
- PB.registerVectorizerStartEPCallback([&PB, VerifyEachPass, DebugLogging](
- FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
- PB.parsePassPipeline(PM, VectorizerStartEPPipeline, VerifyEachPass,
- DebugLogging);
- });
+ PB.registerVectorizerStartEPCallback(
+ [&PB, VerifyEachPass, DebugLogging](
+ FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
+ ExitOnError Err("Unable to parse VectorizerStartEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline,
+ VerifyEachPass, DebugLogging));
+ });
if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline))
PB.registerPipelineStartEPCallback(
[&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) {
- PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass,
- DebugLogging);
+ ExitOnError Err("Unable to parse PipelineStartEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass,
+ DebugLogging));
});
}
@@ -258,8 +271,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
// Specially handle the alias analysis manager so that we can register
// a custom pipeline of AA passes with it.
AAManager AA;
- if (!PB.parseAAPipeline(AA, AAPipeline)) {
- errs() << Arg0 << ": unable to parse AA pipeline description.\n";
+ if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) {
+ errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
return false;
}
@@ -284,8 +297,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
if (EnableDebugify)
MPM.addPass(NewPMDebugifyPass());
- if (!PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
- errs() << Arg0 << ": unable to parse pass pipeline description.\n";
+ if (auto Err =
+ PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
+ errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
return false;
}
OpenPOWER on IntegriCloud