Skip to content

Commit 6f5931e

Browse files
RichBarton-Armbryanpkc
authored andcommitted
[driver] Add -emit-flang-llvm option
-emit-flang-llvm instructs flang to stop after flang2 and dump the LLVM IR. Can be useful for debugging and also would be a useful option for testing flang output more accurately. Signed-off-by: Richard Barton <[email protected]>
1 parent c368999 commit 6f5931e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,10 @@ def d_Joined : Joined<["-"], "d">, Group<d_Group>;
15451545
def emit_ast : Flag<["-"], "emit-ast">,
15461546
Visibility<[ClangOption, CLOption, DXCOption]>,
15471547
HelpText<"Emit Clang AST files for source inputs">;
1548+
#ifdef ENABLE_CLASSIC_FLANG
1549+
def emit_flang_llvm : Flag<["-"], "emit-flang-llvm">,
1550+
HelpText<"Emit Flang LLVM files for source inputs">;
1551+
#endif
15481552
def emit_llvm : Flag<["-"], "emit-llvm">,
15491553
Visibility<[ClangOption, CC1Option, FC1Option, FlangOption]>,
15501554
Group<Action_Group>,

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
423423
(PhaseArg = DAL.getLastArg(options::OPT_print_supported_cpus)) ||
424424
(PhaseArg = DAL.getLastArg(options::OPT_print_enabled_extensions)) ||
425425
(PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
426+
#ifdef ENABLE_CLASSIC_FLANG
427+
(PhaseArg = DAL.getLastArg(options::OPT_emit_flang_llvm)) ||
428+
#endif
426429
(PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
427430
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
428431
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||

clang/lib/Driver/ToolChains/ClassicFlang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
8787
llvm::sys::path::replace_extension(Stem, "");
8888
}
8989

90+
#ifdef ENABLE_CLASSIC_FLANG
91+
if (Args.hasArg(options::OPT_emit_flang_llvm)) {
92+
// -emit-flang-llvm only supports asm output so claim -S to prevent warning
93+
Args.ClaimAllArgs(options::OPT_S);
94+
}
95+
#endif
96+
9097
// Add input file name to the compilation line
9198
UpperCmdArgs.push_back(Input.getBaseInput());
9299

0 commit comments

Comments
 (0)