-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[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
[flang][Driver] Add support for -mllvm -print-pipeline-passes #106141
Conversation
The behavior deliberately mimics that of clang.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-flang-driver Author: Tarun Prabhu (tarunprabhu) ChangesThe behavior deliberately mimics that of clang. Full diff: https://github.com/llvm/llvm-project/pull/106141.diff 2 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. All builds and passes on my setup.
How is this different to |
In essence,
The output format is also very different. This prints a list of all the passes in a format that is compatible with Since |
Thanks for the summary!
This is something that I struggle with. It is basically making this one flag (which is meant as LLVM's internal option) a very very special flower. We should avoid that. This was already raised when that flag was introduced in Clang: Here's one follow-up question - could you compare the output from I'm 100% supportive of improving the end-user and developer's experience, but I want to make sure that there's no other, more canonical way to achieve the same. Right now it feels that indeed there is :) |
Output of
Output of `-mllvm -print-pipeline-passes
The outputs above are for -O0 on a simple 3-line hello world program. It gets more interesting when optimizations are enabled and the input is non-trivial.
In the second case, the output can be passed as is to the
My only concern with changing the behavior that is that we would have two frontends that are part of the same project with different behavior. It looks like they stopped compilation in If tangling this with an "internal" LLVM command line option is objectionable (and I agree that it feels messy) we could make this a separate, first class option in [EDIT: fix formatting] |
For me at least, these two different use cases justify two different flags. It would be useful to have something to pass straight to
I agree that whatever we do should match clang (or clang should be adapted to match us).
In my opinion, support for This LGTM, but don't merge without agreement from Andrzej |
Thanks for getting back to me.
+1
Well, not quite :) Using
+1
Why not? :) Similar concerns were raised when this flag was introduced in Clang, so I imagine that a sounder approach would be welcome. Also, while keeping Flang consistent with Clang should be a very high priority, it's OK to diverge when there's good justification. Also, even more importantly, if there's scope to improve things in Flang, please don't shy away from bringing similar improvements to Clang. To unblock you, I propose the following:
Alternatively, go with 2. straight away :) |
…ventually be replaced with a proper compiler driver option
I have added a comment to both Thanks for the review and suggestions, Andrzej. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving with the caveat that we should avoid leveraging LLVM options like this and that long-term this should be refactored as a dedicated, first-class driver option. This can be implemented in a seperate PR.
Thank you for the discussion and for addressing my comment @tarunprabhu 🙏🏻 LGTM
The behavior deliberately mimics that of clang.