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

This flag provides extra commentary in the assembly output.
This commit is contained in:
Tom Eccles 2025-03-13 15:22:13 +00:00 committed by GitHub
parent 143bf95d41
commit 01aca42363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 2 deletions

View File

@ -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>,
@ -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,

View File

@ -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,

View File

@ -50,6 +50,9 @@ public:
/// Extended Altivec ABI on AIX
bool EnableAIXExtendedAltivecABI;
/// Print verbose assembly
bool asmVerbose = false;
};
} // end namespace Fortran::frontend

View File

@ -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) {

View File

@ -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();
@ -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) {

View File

@ -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