[flang-commits] [flang] [flang][Driver] Add support for -mllvm -print-pipeline-passes (PR #106141)
via flang-commits
flang-commits at lists.llvm.org
Mon Aug 26 14:03:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
Author: Tarun Prabhu (tarunprabhu)
<details>
<summary>Changes</summary>
The behavior deliberately mimics that of clang.
---
Full diff: https://github.com/llvm/llvm-project/pull/106141.diff
2 Files Affected:
- (modified) flang/lib/Frontend/FrontendActions.cpp (+16)
- (added) flang/test/Driver/print-pipeline-passes.f90 (+10)
``````````diff
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 5c86bd947ce73f..012649b2ba16bd 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<bool> PrintPipelinePasses;
+} // namespace llvm
+
using namespace Fortran::frontend;
// Declare plugin extension function declarations.
@@ -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);
}
diff --git a/flang/test/Driver/print-pipeline-passes.f90 b/flang/test/Driver/print-pipeline-passes.f90
new file mode 100644
index 00000000000000..4b413cbc07b691
--- /dev/null
+++ b/flang/test/Driver/print-pipeline-passes.f90
@@ -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
``````````
</details>
https://github.com/llvm/llvm-project/pull/106141
More information about the flang-commits
mailing list