[flang-commits] [flang] [flang][Driver] Add support for -mllvm -print-pipeline-passes (PR #106141)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Tue Aug 27 04:24:27 PDT 2024
https://github.com/tarunprabhu updated https://github.com/llvm/llvm-project/pull/106141
>From 9b83df995dc5c1d95db63a6ad32ba612b8a52290 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Mon, 26 Aug 2024 14:51:29 -0600
Subject: [PATCH 1/2] [flang][Driver] Add support for -mllvm
-print-pipeline-passes
The behavior deliberately mimics that of clang.
---
flang/lib/Frontend/FrontendActions.cpp | 16 ++++++++++++++++
flang/test/Driver/print-pipeline-passes.f90 | 10 ++++++++++
2 files changed, 26 insertions(+)
create mode 100644 flang/test/Driver/print-pipeline-passes.f90
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
>From a8d69e724d52e9e04faba7bf128883c22d5e1614 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Tue, 27 Aug 2024 05:24:15 -0600
Subject: [PATCH 2/2] Remove unnecessary target triple from test invocation.
---
flang/test/Driver/print-pipeline-passes.f90 | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/flang/test/Driver/print-pipeline-passes.f90 b/flang/test/Driver/print-pipeline-passes.f90
index 4b413cbc07b691..72c213802508e5 100644
--- a/flang/test/Driver/print-pipeline-passes.f90
+++ b/flang/test/Driver/print-pipeline-passes.f90
@@ -1,9 +1,6 @@
-! Test that -print-pipeline-passes works in flang
+! RUN: %flang_fc1 -mllvm -print-pipeline-passes -emit-llvm-bc -o /dev/null -O0 %s 2>&1 | FileCheck %s
-! 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.
+! Just check a few passes to ensure that something reasonable is being printed.
! CHECK: always-inline
! CHECK-SAME: annotation-remarks
More information about the flang-commits
mailing list