[clang] a8c678c - [Remarks][Driver][NFC] Make shouldEmitRemarks more available in the Driver

Francis Visoiu Mistrih via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 18 14:32:45 PST 2019


Author: Francis Visoiu Mistrih
Date: 2019-12-18T14:31:41-08:00
New Revision: a8c678cb9a90c4f82505f573e9b9fa23fec93a64

URL: https://github.com/llvm/llvm-project/commit/a8c678cb9a90c4f82505f573e9b9fa23fec93a64
DIFF: https://github.com/llvm/llvm-project/commit/a8c678cb9a90c4f82505f573e9b9fa23fec93a64.diff

LOG: [Remarks][Driver][NFC] Make shouldEmitRemarks more available in the Driver

Move the function to Driver.h so that it can be re-used in other places.

Added: 
    

Modified: 
    clang/include/clang/Driver/Driver.h
    clang/lib/Driver/Driver.cpp
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h
index 64f1eb8cb5d7..d667fcb1efef 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -620,6 +620,9 @@ class Driver {
 /// And False otherwise.
 bool isOptimizationLevelFast(const llvm::opt::ArgList &Args);
 
+/// \return True if the argument combination will end up generating remarks.
+bool willEmitRemarks(const llvm::opt::ArgList &Args);
+
 } // end namespace driver
 } // end namespace clang
 

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f2b234315512..35e7998bf22f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5060,3 +5060,26 @@ Driver::getIncludeExcludeOptionFlagMasks(bool IsClCompatMode) const {
 bool clang::driver::isOptimizationLevelFast(const ArgList &Args) {
   return Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group, false);
 }
+
+bool clang::driver::willEmitRemarks(const ArgList &Args) {
+  // -fsave-optimization-record enables it.
+  if (Args.hasFlag(options::OPT_fsave_optimization_record,
+                   options::OPT_fno_save_optimization_record, false))
+    return true;
+
+  // -fsave-optimization-record=<format> enables it as well.
+  if (Args.hasFlag(options::OPT_fsave_optimization_record_EQ,
+                   options::OPT_fno_save_optimization_record, false))
+    return true;
+
+  // -foptimization-record-file alone enables it too.
+  if (Args.hasFlag(options::OPT_foptimization_record_file_EQ,
+                   options::OPT_fno_save_optimization_record, false))
+    return true;
+
+  // -foptimization-record-passes alone enables it too.
+  if (Args.hasFlag(options::OPT_foptimization_record_passes_EQ,
+                   options::OPT_fno_save_optimization_record, false))
+    return true;
+  return false;
+}

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 5bf0efcf0503..9840acafd6ea 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1415,29 +1415,6 @@ static bool isNoCommonDefault(const llvm::Triple &Triple) {
   }
 }
 
-static bool shouldEmitRemarks(const ArgList &Args) {
-  // -fsave-optimization-record enables it.
-  if (Args.hasFlag(options::OPT_fsave_optimization_record,
-                   options::OPT_fno_save_optimization_record, false))
-    return true;
-
-  // -fsave-optimization-record=<format> enables it as well.
-  if (Args.hasFlag(options::OPT_fsave_optimization_record_EQ,
-                   options::OPT_fno_save_optimization_record, false))
-    return true;
-
-  // -foptimization-record-file alone enables it too.
-  if (Args.hasFlag(options::OPT_foptimization_record_file_EQ,
-                   options::OPT_fno_save_optimization_record, false))
-    return true;
-
-  // -foptimization-record-passes alone enables it too.
-  if (Args.hasFlag(options::OPT_foptimization_record_passes_EQ,
-                   options::OPT_fno_save_optimization_record, false))
-    return true;
-  return false;
-}
-
 static bool hasMultipleInvocations(const llvm::Triple &Triple,
                                    const ArgList &Args) {
   // Supported only on Darwin where we invoke the compiler multiple times
@@ -3718,7 +3695,7 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
   TC.adjustDebugInfoKind(DebugInfoKind, Args);
 
   // When emitting remarks, we need at least debug lines in the output.
-  if (shouldEmitRemarks(Args) &&
+  if (willEmitRemarks(Args) &&
       DebugInfoKind <= codegenoptions::DebugDirectivesOnly)
     DebugInfoKind = codegenoptions::DebugLineTablesOnly;
 
@@ -5546,7 +5523,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-fapple-pragma-pack");
 
   // Remarks can be enabled with any of the `-f.*optimization-record.*` flags.
-  if (shouldEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple))
+  if (willEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple))
     renderRemarksOptions(Args, CmdArgs, Triple, Input, JA);
 
   bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,


        


More information about the cfe-commits mailing list