-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Conversation
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.
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-clang-driver Author: Tom Eccles (tblah) ChangesThis 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. Full diff: https://github.com/llvm/llvm-project/pull/130788.diff 6 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index e69cd6b833c3a..ac6392f92f311 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -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,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index d4fea633d0edf..09b77b4aab03d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -172,7 +172,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_finit_global_zero,
options::OPT_fno_init_global_zero, options::OPT_ftime_report,
options::OPT_ftime_report_EQ, options::OPT_funroll_loops,
- options::OPT_fno_unroll_loops});
+ options::OPT_fno_unroll_loops, options::OPT_fverbose_asm,
+ options::OPT_fno_verbose_asm});
}
void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..d2ff06d5fe08a 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -42,5 +42,7 @@ ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, llvm::codeg
ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use
ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 2, llvm::FramePointerKind::None) ///< Enable the usage of frame pointers
+CODEGENOPT(AsmVerbose, 1, 0)
+
#undef CODEGENOPT
#undef ENUM_CODEGENOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 8b07a50824899..5451006960e8b 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -254,6 +254,10 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
clang::driver::options::OPT_fno_unroll_loops,
(opts.OptimizationLevel > 1));
+ if (args.hasFlag(clang::driver::options::OPT_fverbose_asm,
+ clang::driver::options::OPT_fno_verbose_asm, false))
+ opts.AsmVerbose = 1;
+
opts.AliasAnalysis = opts.OptimizationLevel > 0;
// -mframe-pointer=none/non-leaf/all option.
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 94de376aaf7d6..0ef2708bb42fb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1284,6 +1284,8 @@ void CodeGenAction::executeAction() {
// given on the command-line).
llvm::TargetMachine &targetMachine = ci.getTargetMachine();
+ targetMachine.Options.MCOptions.AsmVerbose = codeGenOpts.AsmVerbose;
+
const llvm::Triple &theTriple = targetMachine.getTargetTriple();
if (llvmModule->getTargetTriple() != theTriple) {
diff --git a/flang/test/Driver/verbose-asm.f90 b/flang/test/Driver/verbose-asm.f90
new file mode 100644
index 0000000000000..20e930d22bf0a
--- /dev/null
+++ b/flang/test/Driver/verbose-asm.f90
@@ -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
|
I tested it, working as expected for me. Very nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to maintain an equivalence with clang by keeping this in CodeGenOptions
when it really ought to be a TargetOption
? It looks like almost all of the handling of this option takes place in flang
, so we probably shouldn't be bound to idiosyncracies in clang
if we can help it.
It might make the option declaration messier unless conditional marshalling is possible (I don't know if it is or not).
I don't have a very strong opinion on this. If others are ok with leaving this in CodeGenOptions
, I'm happy to go along with it. What do you think?
No problem. I have moved it to target options in 6f6f867 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the changes, Tom! LGTM.
This flag provides extra commentary in the assembly output.
This flag provides extra commentary in the assembly output.