Skip to content

Commit 5d3c1cc

Browse files
committed
[flang] Add support for -f[no-]verbose-asm
This flag provides extra commentary in the assembly output. It is in CodeGenOptions to match what is done in clang, even though the backend treats it as a target option.
1 parent 63635c1 commit 5d3c1cc

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,7 @@ defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
34673467
PosFlag<SetTrue>>;
34683468
def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group<f_Group>;
34693469
def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group<f_Group>,
3470-
Visibility<[ClangOption, CC1Option]>,
3470+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
34713471
MarshallingInfoNegativeFlag<CodeGenOpts<"AsmVerbose">>;
34723472
def fno_working_directory : Flag<["-"], "fno-working-directory">, Group<f_Group>;
34733473
def fobjc_arc : Flag<["-"], "fobjc-arc">, Group<f_Group>,
@@ -4142,7 +4142,8 @@ defm use_init_array : BoolFOption<"use-init-array",
41424142
PosFlag<SetTrue>>;
41434143
def fno_var_tracking : Flag<["-"], "fno-var-tracking">, Group<clang_ignored_f_Group>;
41444144
def fverbose_asm : Flag<["-"], "fverbose-asm">, Group<f_Group>,
4145-
HelpText<"Generate verbose assembly output">;
4145+
HelpText<"Generate verbose assembly output">,
4146+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
41464147
def dA : Flag<["-"], "dA">, Alias<fverbose_asm>;
41474148
defm visibility_from_dllstorageclass : BoolFOption<"visibility-from-dllstorageclass",
41484149
LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
172172
options::OPT_finit_global_zero,
173173
options::OPT_fno_init_global_zero, options::OPT_ftime_report,
174174
options::OPT_ftime_report_EQ, options::OPT_funroll_loops,
175-
options::OPT_fno_unroll_loops});
175+
options::OPT_fno_unroll_loops, options::OPT_fverbose_asm,
176+
options::OPT_fno_verbose_asm});
176177
}
177178

178179
void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {

flang/include/flang/Frontend/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, llvm::codeg
4242
ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use
4343
ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 2, llvm::FramePointerKind::None) ///< Enable the usage of frame pointers
4444

45+
CODEGENOPT(AsmVerbose, 1, 0)
46+
4547
#undef CODEGENOPT
4648
#undef ENUM_CODEGENOPT

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
254254
clang::driver::options::OPT_fno_unroll_loops,
255255
(opts.OptimizationLevel > 1));
256256

257+
if (args.hasFlag(clang::driver::options::OPT_fverbose_asm,
258+
clang::driver::options::OPT_fno_verbose_asm, false))
259+
opts.AsmVerbose = 1;
260+
257261
opts.AliasAnalysis = opts.OptimizationLevel > 0;
258262

259263
// -mframe-pointer=none/non-leaf/all option.

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ void CodeGenAction::executeAction() {
12841284
// given on the command-line).
12851285
llvm::TargetMachine &targetMachine = ci.getTargetMachine();
12861286

1287+
targetMachine.Options.MCOptions.AsmVerbose = codeGenOpts.AsmVerbose;
1288+
12871289
const llvm::Triple &theTriple = targetMachine.getTargetTriple();
12881290

12891291
if (llvmModule->getTargetTriple() != theTriple) {

flang/test/Driver/verbose-asm.f90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! RUN: %flang -### -S -o - -fverbose-asm %s 2>&1 | FileCheck %s --check-prefix=FORWARDING
2+
! FORWARDING: -fverbose-asm
3+
4+
! RUN: %flang -S -o - -fverbose-asm %s | FileCheck %s --check-prefix=VERBOSE
5+
! RUN: %flang_fc1 -S -o - -fverbose-asm %s | FileCheck %s --check-prefix=VERBOSE
6+
7+
! RUN: %flang -S -o - %s | FileCheck %s --check-prefix=QUIET
8+
! RUN: %flang_fc1 -S -o - %s | FileCheck %s --check-prefix=QUIET
9+
! RUN: %flang -S -o - -fverbose-asm -fno-verbose-asm %s | FileCheck %s --check-prefix=QUIET
10+
! RUN: %flang_fc1 -S -o - -fverbose-asm -fno-verbose-asm %s | FileCheck %s --check-prefix=QUIET
11+
12+
! VERBOSE: // -- Begin function _QQmain
13+
! QUIET-NOT: // -- Begin function _QQmain
14+
program test
15+
16+
end program

0 commit comments

Comments
 (0)