diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 026f16484c094..564efa3181d18 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1095,6 +1095,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1)); } + // FIXME: This should eventually be replaced by a first-class driver option. + // This should be done for both clang and flang simultaneously. // Print a textual, '-passes=' compatible, representation of pipeline if // requested. if (PrintPipelinePasses) { diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp index 5c86bd947ce73..0bdd4be10ccca 100644 --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -79,6 +79,10 @@ #include "flang/Tools/CLOptions.inc" +namespace llvm { +extern cl::opt PrintPipelinePasses; +} // namespace llvm + using namespace Fortran::frontend; // Declare plugin extension function declarations. @@ -1015,6 +1019,20 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) { else if (action == BackendActionTy::Backend_EmitLL) mpm.addPass(llvm::PrintModulePass(os)); + // FIXME: This should eventually be replaced by a first-class driver option. + // This should be done for both flang and clang simultaneously. + // Print a textual, '-passes=' compatible, representation of pipeline if + // requested. In this case, don't run the passes. This mimics the behavior of + // clang. + if (llvm::PrintPipelinePasses) { + mpm.printPipeline(llvm::outs(), [&pic](llvm::StringRef className) { + auto passName = pic.getPassNameForClassName(className); + return passName.empty() ? className : passName; + }); + llvm::outs() << "\n"; + return; + } + // Run the passes. mpm.run(*llvmModule, mam); } diff --git a/flang/test/Driver/print-pipeline-passes.f90 b/flang/test/Driver/print-pipeline-passes.f90 new file mode 100644 index 0000000000000..72c213802508e --- /dev/null +++ b/flang/test/Driver/print-pipeline-passes.f90 @@ -0,0 +1,7 @@ +! RUN: %flang_fc1 -mllvm -print-pipeline-passes -emit-llvm-bc -o /dev/null -O0 %s 2>&1 | FileCheck %s + +! Just check a few passes to ensure that something reasonable is being printed. +! CHECK: always-inline +! CHECK-SAME: annotation-remarks + +end program