aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorVictor Kingi <victor.kingi@arm.com>2023-08-17 11:19:12 +0000
committerVictor Kingi <victor.kingi@arm.com>2023-08-23 10:19:56 +0000
commit91989c67483c37bbcee4404eea789e39dd3470d9 (patch)
tree53197f74e551a28f2cede3926f5fb6aa61de8bda /flang/lib/Frontend/CompilerInvocation.cpp
parent8d24b7322ee55eb780fc8115bfa8af07b6ee66b7 (diff)
downloadllvm-91989c67483c37bbcee4404eea789e39dd3470d9.zip
llvm-91989c67483c37bbcee4404eea789e39dd3470d9.tar.gz
llvm-91989c67483c37bbcee4404eea789e39dd3470d9.tar.bz2
[Flang][Driver] Implement OPT_R_Joined options
Add a BackendRemarkConsumer class, responsible for handling diagnostics received from LLVM. The diagnostics being information on middle and backend passes used or not used. Clang by default has all remarks ignored but manually sets the severity of `R_Group` to visible(`clang::diag::clang::Severity::Remark`). This patch does the same for Flang. Depends on D157410. That patch adds the R family of options to `FlangOption` and `FC1Option` in `clang/include/clang/Driver/Options.td` Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D158174
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ecafa4e..f2a7ffd 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -153,6 +153,38 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
return true;
}
+// Generate an OptRemark object containing info on if the -Rgroup
+// specified is enabled or not.
+static CodeGenOptions::OptRemark
+parseOptimizationRemark(llvm::opt::ArgList &args,
+ llvm::StringRef remarkOptName) {
+ assert((remarkOptName == "pass" || remarkOptName == "pass-missed" ||
+ remarkOptName == "pass-analysis") &&
+ "Unknown group name provided.");
+ CodeGenOptions::OptRemark result;
+
+ for (llvm::opt::Arg *a : args) {
+ if (a->getOption().matches(clang::driver::options::OPT_R_Joined)) {
+ llvm::StringRef value = a->getValue();
+
+ if (value == remarkOptName) {
+ result.Kind = CodeGenOptions::RemarkKind::RK_Enabled;
+ // Enable everything
+ result.Pattern = ".*";
+ result.Regex = std::make_shared<llvm::Regex>(result.Pattern);
+
+ } else if (value.split('-') ==
+ std::make_pair(llvm::StringRef("no"), remarkOptName)) {
+ result.Kind = CodeGenOptions::RemarkKind::RK_Disabled;
+ // Disable everything
+ result.Pattern = "";
+ result.Regex = nullptr;
+ }
+ }
+ }
+ return result;
+}
+
static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
@@ -194,14 +226,30 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
args.getLastArg(clang::driver::options::OPT_opt_record_file))
opts.OptRecordFile = a->getValue();
+ // Optimization file format. Defaults to yaml
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_opt_record_format))
opts.OptRecordFormat = a->getValue();
+ // Specifies, using a regex, which successful optimization passes(middle and
+ // backend), to include in the final optimization record file generated. If
+ // not provided -fsave-optimization-record will include all passes.
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_opt_record_passes))
opts.OptRecordPasses = a->getValue();
+ // Create OptRemark that allows printing of all successful optimization
+ // passes applied.
+ opts.OptimizationRemark = parseOptimizationRemark(args, "pass");
+
+ // Create OptRemark that allows all missed optimization passes to be printed.
+ opts.OptimizationRemarkMissed = parseOptimizationRemark(args, "pass-missed");
+
+ // Create OptRemark that allows all optimization decisions made by LLVM
+ // to be printed.
+ opts.OptimizationRemarkAnalysis =
+ parseOptimizationRemark(args, "pass-analysis");
+
if (auto *a = args.getLastArg(clang::driver::options::OPT_save_temps_EQ))
opts.SaveTempsDir = a->getValue();
@@ -959,6 +1007,12 @@ bool CompilerInvocation::createFromArgs(
res.loweringOpts.setNoPPCNativeVecElemOrder(true);
}
+ // Preserve all the remark options requested, i.e. -Rpass, -Rpass-missed or
+ // -Rpass-analysis. This will be used later when processing and outputting the
+ // remarks generated by LLVM in ExecuteCompilerInvocation.cpp.
+ for (auto *a : args.filtered(clang::driver::options::OPT_R_Group))
+ res.getDiagnosticOpts().Remarks.push_back(a->getValue());
+
success &= parseFrontendArgs(res.getFrontendOpts(), args, diags);
parseTargetArgs(res.getTargetOpts(), args);
parsePreprocessorArgs(res.getPreprocessorOpts(), args);