From f04ccadf35441b2e13b3ab30edeef251818fa9c7 Mon Sep 17 00:00:00 2001 From: Victor Kingi Date: Thu, 27 Jul 2023 21:57:54 +0000 Subject: [Flang] Add support for fsave-optimization-record Add support for generating and saving the optimization record. Optimization record lists the optimizations performed by LLVM. This patch enables the flag in Flang. Clang handles this functionality using the BackendConsumer which Flang doesn't have, hence, was implemented in CodeGenAction::executeAction FlangOption added to all variants of fsave-optimization-record in clang/include/clang/Driver/Options.td . Clang handles it the same way. opt_record_file, opt_record_passes and opt_record_format flags in Options.td were moved out of the group [CC1Option, NoDriverOption] to allow flang -fc1 support. The renderRemarksOptions and willEmitRemarks functions in clang/lib/Driver/ToolChains/Flang.cpp follow same syntax as clang. In flang/lib/Frontend/CompilerInvocation.cpp we update the field OptRecordFile with the provided optimization file value. Clang doesn't do this as it processes the Options.td, mapping the OptRecordFile earlier on. Reviewed By: awarzynski, tblah Differential Revision: https://reviews.llvm.org/D155452 --- flang/lib/Frontend/CompilerInvocation.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index b1f0d27..90b93b2 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -163,13 +163,12 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, opts.DebugPassManager = 1; if (args.hasFlag(clang::driver::options::OPT_fstack_arrays, - clang::driver::options::OPT_fno_stack_arrays, false)) { + clang::driver::options::OPT_fno_stack_arrays, false)) opts.StackArrays = 1; - } + if (args.hasFlag(clang::driver::options::OPT_floop_versioning, - clang::driver::options::OPT_fno_loop_versioning, false)) { + clang::driver::options::OPT_fno_loop_versioning, false)) opts.LoopVersioning = 1; - } for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ)) opts.LLVMPassPlugins.push_back(a->getValue()); @@ -190,6 +189,19 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, opts.PrepareForThinLTO = true; } + // -f[no-]save-optimization-record[=] + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_opt_record_file)) + opts.OptRecordFile = a->getValue(); + + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_opt_record_format)) + opts.OptRecordFormat = a->getValue(); + + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_opt_record_passes)) + opts.OptRecordPasses = a->getValue(); + if (auto *a = args.getLastArg(clang::driver::options::OPT_save_temps_EQ)) opts.SaveTempsDir = a->getValue(); -- cgit v1.1