aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
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);