Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1015,6 +1019,18 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
else if (action == BackendActionTy::Backend_EmitLL)
mpm.addPass(llvm::PrintModulePass(os));

// 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);
}
Expand Down
10 changes: 10 additions & 0 deletions flang/test/Driver/print-pipeline-passes.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
! Test that -print-pipeline-passes works in flang

! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s

! Don't try to check all passes, just a few to make sure that something is
! actually printed.
! CHECK: always-inline
! CHECK-SAME: annotation-remarks

end program
Loading