Add a check (can be disabled via a flag) that the pipeline we generate is actually parsable.
Can be disabled because we don't expect to handle every pass in -print-pipeline-passes.
Fixes #58280.
Reviewed By: ChuanqiXu
Differential Revision: https://reviews.llvm.org/D135703
CoroConditionalWrapper(ModulePassManager &&);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
static bool isRequired() { return true; }
+ void printPipeline(raw_ostream &OS,
+ function_ref<StringRef(StringRef)> MapClassName2PassName);
private:
ModulePassManager PM;
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
#include "llvm/Transforms/Coroutines/CoroCleanup.h"
+#include "llvm/Transforms/Coroutines/CoroConditionalWrapper.h"
#include "llvm/Transforms/Coroutines/CoroEarly.h"
#include "llvm/Transforms/Coroutines/CoroElide.h"
#include "llvm/Transforms/Coroutines/CoroSplit.h"
return true;
if (Name == "function" || Name == "function<eager-inv>")
return true;
+ if (Name == "coro-cond")
+ return true;
// Explicitly handle custom-parsed pass names.
if (parseRepeatPassName(Name))
MPM.addPass(std::move(NestedMPM));
return Error::success();
}
+ if (Name == "coro-cond") {
+ ModulePassManager NestedMPM;
+ if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
+ return Err;
+ MPM.addPass(CoroConditionalWrapper(std::move(NestedMPM)));
+ return Error::success();
+ }
if (Name == "cgscc") {
CGSCCPassManager CGPM;
if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
return PM.run(M, AM);
}
+
+void CoroConditionalWrapper::printPipeline(
+ raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
+ OS << "coro-cond";
+ OS << "(";
+ PM.printPipeline(OS, MapClassName2PassName);
+ OS << ")";
+}
; CHECK-2: repeat<5>(function(mem2reg)),invalidate<all>
;; Test that we get ClassName printed when there is no ClassName to pass-name mapping (as is the case for the BitcodeWriterPass).
-; RUN: opt -o /dev/null -disable-verify -print-pipeline-passes -passes='function(mem2reg)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-3
+; RUN: opt -o /dev/null -disable-verify -print-pipeline-passes -passes='function(mem2reg)' < %s -disable-pipeline-verification | FileCheck %s --match-full-lines --check-prefixes=CHECK-3
; CHECK-3: function(mem2reg),BitcodeWriterPass
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(loop-mssa(indvars))' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-4
;; Test that LICM & LNICM with options.
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(loop-mssa(licm<allowspeculation>,licm<no-allowspeculation>,lnicm<allowspeculation>,lnicm<no-allowspeculation>))' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-25
; CHECK-25: function(loop-mssa(licm<allowspeculation>,licm<no-allowspeculation>,lnicm<allowspeculation>,lnicm<no-allowspeculation>))
+
+;; Test coro-cond.
+; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='coro-cond(no-op-module)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-26
+; CHECK-26: coro-cond(no-op-module)
+
+;; Test that -print-pipeline-passes is parsable (implicitly done with -print-pipeline-passes) for various default pipelines.
+; RUN: opt -disable-output -passes='default<O0>' < %s
+; RUN: opt -disable-output -passes='default<O1>' < %s
+; RUN: opt -disable-output -passes='default<O2>' < %s
+; RUN: opt -disable-output -passes='default<O3>' < %s
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
"pipelines"),
cl::Hidden);
+static cl::opt<bool> DisablePipelineVerification(
+ "disable-pipeline-verification",
+ cl::desc("Only has an effect when specified with -print-pipeline-passes. "
+ "Disables verifying that the textual pipeline generated by "
+ "-print-pipeline-passes can be used to create a pipeline."),
+ cl::Hidden);
+
// Individual pipeline tuning options.
extern cl::opt<bool> DisableLoopUnrolling;
// Print a textual, '-passes=' compatible, representation of pipeline if
// requested.
if (PrintPipelinePasses) {
- MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
+ std::string Pipeline;
+ raw_string_ostream SOS(Pipeline);
+ MPM.printPipeline(SOS, [&PIC](StringRef ClassName) {
auto PassName = PIC.getPassNameForClassName(ClassName);
return PassName.empty() ? ClassName : PassName;
});
+ outs() << Pipeline;
outs() << "\n";
+
+ if (!DisablePipelineVerification) {
+ // Check that we can parse the returned pipeline string as an actual
+ // pipeline.
+ ModulePassManager TempPM;
+ if (auto Err = PB.parsePassPipeline(TempPM, Pipeline)) {
+ errs() << "Could not parse dumped pass pipeline: "
+ << toString(std::move(Err)) << "\n";
+ return false;
+ }
+ }
+
return true;
}