Skip to content

[flang] Add support for -f[no-]verbose-asm #130788

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

Merged
merged 4 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3467,7 +3467,7 @@ defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
PosFlag<SetTrue>>;
def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group<f_Group>;
def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
MarshallingInfoNegativeFlag<CodeGenOpts<"AsmVerbose">>;
def fno_working_directory : Flag<["-"], "fno-working-directory">, Group<f_Group>;
def fobjc_arc : Flag<["-"], "fobjc-arc">, Group<f_Group>,
Expand Down Expand Up @@ -4142,7 +4142,8 @@ defm use_init_array : BoolFOption<"use-init-array",
PosFlag<SetTrue>>;
def fno_var_tracking : Flag<["-"], "fno-var-tracking">, Group<clang_ignored_f_Group>;
def fverbose_asm : Flag<["-"], "fverbose-asm">, Group<f_Group>,
HelpText<"Generate verbose assembly output">;
HelpText<"Generate verbose assembly output">,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
def dA : Flag<["-"], "dA">, Alias<fverbose_asm>;
defm visibility_from_dllstorageclass : BoolFOption<"visibility-from-dllstorageclass",
LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ void Flang::addTargetOptions(const ArgList &Args,
else
CmdArgs.push_back(A->getValue());
}

Args.addAllArgs(CmdArgs,
{options::OPT_fverbose_asm, options::OPT_fno_verbose_asm});
}

void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
Expand Down
3 changes: 3 additions & 0 deletions flang/include/flang/Frontend/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class TargetOptions {

/// Extended Altivec ABI on AIX
bool EnableAIXExtendedAltivecABI;

/// Print verbose assembly
bool asmVerbose = false;
};

} // end namespace Fortran::frontend
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
opts.EnableAIXExtendedAltivecABI = false;
}
}

opts.asmVerbose =
args.hasFlag(clang::driver::options::OPT_fverbose_asm,
clang::driver::options::OPT_fno_verbose_asm, false);
}
// Tweak the frontend configuration based on the frontend action
static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
Expand Down
3 changes: 3 additions & 0 deletions flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ void CodeGenAction::executeAction() {

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

targetMachine.Options.MCOptions.AsmVerbose = targetOpts.asmVerbose;

const llvm::Triple &theTriple = targetMachine.getTargetTriple();

if (llvmModule->getTargetTriple() != theTriple) {
Expand Down
16 changes: 16 additions & 0 deletions flang/test/Driver/verbose-asm.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! RUN: %flang -### -S -o - -fverbose-asm %s 2>&1 | FileCheck %s --check-prefix=FORWARDING
! FORWARDING: -fverbose-asm

! RUN: %flang -S -o - -fverbose-asm %s | FileCheck %s --check-prefix=VERBOSE
! RUN: %flang_fc1 -S -o - -fverbose-asm %s | FileCheck %s --check-prefix=VERBOSE

! RUN: %flang -S -o - %s | FileCheck %s --check-prefix=QUIET
! RUN: %flang_fc1 -S -o - %s | FileCheck %s --check-prefix=QUIET
! RUN: %flang -S -o - -fverbose-asm -fno-verbose-asm %s | FileCheck %s --check-prefix=QUIET
! RUN: %flang_fc1 -S -o - -fverbose-asm -fno-verbose-asm %s | FileCheck %s --check-prefix=QUIET

! VERBOSE: -- Begin function _QQmain
! QUIET-NOT: -- Begin function _QQmain
program test

end program