[flang][Driver] Add support for -mllvm -print-pipeline-passes

The behavior deliberately mimics that of clang. Ideally, -print-pipeline-passes
should be a first-class driver option. Notes to this effect have been added in 
the appropriate places in both flang and clang.

---------

Co-authored-by: Tarun Prabhu <tarun.prabhu@gmail.com>
This commit is contained in:
Tarun Prabhu
2024-08-29 16:21:43 -06:00
committed by GitHub
parent cc943a67d1
commit a1441ca747
3 changed files with 27 additions and 0 deletions

View File

@@ -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) {

View File

@@ -79,6 +79,10 @@
#include "flang/Tools/CLOptions.inc"
namespace llvm {
extern cl::opt<bool> PrintPipelinePasses;
} // namespace llvm
using namespace Fortran::frontend;
// Declare plugin extension function declarations.
@@ -1016,6 +1020,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);
}

View File

@@ -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