Skip to content

Commit 01aca42

Browse files
authored
[flang] Add support for -f[no-]verbose-asm (#130788)
This flag provides extra commentary in the assembly output.
1 parent 143bf95 commit 01aca42

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ void Flang::addTargetOptions(const ArgList &Args,
514514
else
515515
CmdArgs.push_back(A->getValue());
516516
}
517+
518+
Args.addAllArgs(CmdArgs,
519+
{options::OPT_fverbose_asm, options::OPT_fno_verbose_asm});
517520
}
518521

519522
void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,

flang/include/flang/Frontend/TargetOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class TargetOptions {
5050

5151
/// Extended Altivec ABI on AIX
5252
bool EnableAIXExtendedAltivecABI;
53+
54+
/// Print verbose assembly
55+
bool asmVerbose = false;
5356
};
5457

5558
} // end namespace Fortran::frontend

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
476476
opts.EnableAIXExtendedAltivecABI = false;
477477
}
478478
}
479+
480+
opts.asmVerbose =
481+
args.hasFlag(clang::driver::options::OPT_fverbose_asm,
482+
clang::driver::options::OPT_fno_verbose_asm, false);
479483
}
480484
// Tweak the frontend configuration based on the frontend action
481485
static void setUpFrontendBasedOnAction(FrontendOptions &opts) {

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ void CodeGenAction::executeAction() {
12201220

12211221
clang::DiagnosticsEngine &diags = ci.getDiagnostics();
12221222
const CodeGenOptions &codeGenOpts = ci.getInvocation().getCodeGenOpts();
1223+
const TargetOptions &targetOpts = ci.getInvocation().getTargetOpts();
12231224
Fortran::lower::LoweringOptions &loweringOpts =
12241225
ci.getInvocation().getLoweringOpts();
12251226
mlir::DefaultTimingManager &timingMgr = ci.getTimingManager();
@@ -1284,6 +1285,8 @@ void CodeGenAction::executeAction() {
12841285
// given on the command-line).
12851286
llvm::TargetMachine &targetMachine = ci.getTargetMachine();
12861287

1288+
targetMachine.Options.MCOptions.AsmVerbose = targetOpts.asmVerbose;
1289+
12871290
const llvm::Triple &theTriple = targetMachine.getTargetTriple();
12881291

12891292
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)