Skip to content

Commit a1441ca

Browse files
tarunprabhuTarun Prabhu
and
Tarun Prabhu
authored
[flang][Driver] Add support for -mllvm -print-pipeline-passes
The behavior deliberately mimics that of clang. Ideally, -print-pipeline-passes should be a first-class driver option. Notes to this effect have been added in the appropriate places in both flang and clang. --------- Co-authored-by: Tarun Prabhu <tarun.prabhu@gmail.com>
1 parent cc943a6 commit a1441ca

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10951095
TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
10961096
}
10971097

1098+
// FIXME: This should eventually be replaced by a first-class driver option.
1099+
// This should be done for both clang and flang simultaneously.
10981100
// Print a textual, '-passes=' compatible, representation of pipeline if
10991101
// requested.
11001102
if (PrintPipelinePasses) {

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979

8080
#include "flang/Tools/CLOptions.inc"
8181

82+
namespace llvm {
83+
extern cl::opt<bool> PrintPipelinePasses;
84+
} // namespace llvm
85+
8286
using namespace Fortran::frontend;
8387

8488
// Declare plugin extension function declarations.
@@ -1016,6 +1020,20 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
10161020
else if (action == BackendActionTy::Backend_EmitLL)
10171021
mpm.addPass(llvm::PrintModulePass(os));
10181022

1023+
// FIXME: This should eventually be replaced by a first-class driver option.
1024+
// This should be done for both flang and clang simultaneously.
1025+
// Print a textual, '-passes=' compatible, representation of pipeline if
1026+
// requested. In this case, don't run the passes. This mimics the behavior of
1027+
// clang.
1028+
if (llvm::PrintPipelinePasses) {
1029+
mpm.printPipeline(llvm::outs(), [&pic](llvm::StringRef className) {
1030+
auto passName = pic.getPassNameForClassName(className);
1031+
return passName.empty() ? className : passName;
1032+
});
1033+
llvm::outs() << "\n";
1034+
return;
1035+
}
1036+
10191037
// Run the passes.
10201038
mpm.run(*llvmModule, mam);
10211039
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! RUN: %flang_fc1 -mllvm -print-pipeline-passes -emit-llvm-bc -o /dev/null -O0 %s 2>&1 | FileCheck %s
2+
3+
! Just check a few passes to ensure that something reasonable is being printed.
4+
! CHECK: always-inline
5+
! CHECK-SAME: annotation-remarks
6+
7+
end program

0 commit comments

Comments
 (0)