[clang] [flang] [flang][Driver] Add support for -mllvm -print-pipeline-passes (PR #106141)
Tarun Prabhu via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 08:10:29 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/3] [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/3] 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
>From 81d4f14e7c06173d2893db172bc99b31d6fdaa4a Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Thu, 29 Aug 2024 09:10:15 -0600
Subject: [PATCH 3/3] Add comment as a reminder that -mllvm
-print-pipeline-passes should eventually be replaced with a proper compiler
driver option
---
clang/lib/CodeGen/BackendUtil.cpp | 2 ++
flang/lib/Frontend/FrontendActions.cpp | 2 ++
2 files changed, 4 insertions(+)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 026f16484c0949..564efa3181d188 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -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) {
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 012649b2ba16bd..0bdd4be10ccca3 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1019,6 +1019,8 @@ 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.
More information about the cfe-commits
mailing list