[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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
7
flang/test/Driver/print-pipeline-passes.f90
Normal file
7
flang/test/Driver/print-pipeline-passes.f90
Normal 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
|
||||
Reference in New Issue
Block a user