[llvm] r363573 - [Remarks] Extend -fsave-optimization-record to specify the format

Francis Visoiu Mistrih via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 09:06:00 PDT 2019


Author: thegameg
Date: Mon Jun 17 09:06:00 2019
New Revision: 363573

URL: http://llvm.org/viewvc/llvm-project?rev=363573&view=rev
Log:
[Remarks] Extend -fsave-optimization-record to specify the format

Use -fsave-optimization-record=<format> to specify a different format
than the default, which is YAML.

For now, only YAML is supported.

Modified:
    llvm/trunk/include/llvm/IR/RemarkStreamer.h
    llvm/trunk/include/llvm/LTO/Config.h
    llvm/trunk/include/llvm/LTO/LTO.h
    llvm/trunk/lib/IR/RemarkStreamer.cpp
    llvm/trunk/lib/LTO/LTO.cpp
    llvm/trunk/lib/LTO/LTOBackend.cpp
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
    llvm/trunk/test/ThinLTO/X86/diagnostic-handler-remarks.ll
    llvm/trunk/test/tools/gold/X86/opt-remarks.ll
    llvm/trunk/tools/gold/gold-plugin.cpp
    llvm/trunk/tools/llc/llc.cpp
    llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/include/llvm/IR/RemarkStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/RemarkStreamer.h?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/RemarkStreamer.h (original)
+++ llvm/trunk/include/llvm/IR/RemarkStreamer.h Mon Jun 17 09:06:00 2019
@@ -85,10 +85,20 @@ struct RemarkSetupPatternError : RemarkS
   using RemarkSetupErrorInfo<RemarkSetupPatternError>::RemarkSetupErrorInfo;
 };
 
+struct RemarkSetupFormatError : RemarkSetupErrorInfo<RemarkSetupFormatError> {
+  static char ID;
+  using RemarkSetupErrorInfo<RemarkSetupFormatError>::RemarkSetupErrorInfo;
+};
+
+enum class RemarksSerializerFormat { Unknown, YAML };
+
+Expected<RemarksSerializerFormat> parseSerializerFormat(StringRef Format);
+
 /// Setup optimization remarks.
 Expected<std::unique_ptr<ToolOutputFile>>
 setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
-                         StringRef RemarksPasses, bool RemarksWithHotness,
+                         StringRef RemarksPasses, StringRef RemarksFormat,
+                         bool RemarksWithHotness,
                          unsigned RemarksHotnessThreshold = 0);
 
 } // end namespace llvm

Modified: llvm/trunk/include/llvm/LTO/Config.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/Config.h?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/Config.h (original)
+++ llvm/trunk/include/llvm/LTO/Config.h Mon Jun 17 09:06:00 2019
@@ -108,6 +108,9 @@ struct Config {
   /// Whether to emit optimization remarks with hotness informations.
   bool RemarksWithHotness = false;
 
+  /// The format used for serializing remarks (default: YAML).
+  std::string RemarksFormat = "";
+
   /// Whether to emit the pass manager debuggging informations.
   bool DebugPassManager = false;
 

Modified: llvm/trunk/include/llvm/LTO/LTO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTO.h (original)
+++ llvm/trunk/include/llvm/LTO/LTO.h Mon Jun 17 09:06:00 2019
@@ -20,6 +20,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/ModuleSummaryIndex.h"
+#include "llvm/IR/RemarkStreamer.h"
 #include "llvm/LTO/Config.h"
 #include "llvm/Linker/IRMover.h"
 #include "llvm/Object/IRSymtab.h"
@@ -85,8 +86,8 @@ std::string getThinLTOOutputFile(const s
 /// Setup optimization remarks.
 Expected<std::unique_ptr<ToolOutputFile>>
 setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
-                         StringRef RemarksPasses, bool RemarksWithHotness,
-                         int Count = -1);
+                         StringRef RemarksPasses, StringRef RemarksFormat,
+                         bool RemarksWithHotness, int Count = -1);
 
 /// Setups the output file for saving statistics.
 Expected<std::unique_ptr<ToolOutputFile>>

Modified: llvm/trunk/lib/IR/RemarkStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/RemarkStreamer.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/lib/IR/RemarkStreamer.cpp (original)
+++ llvm/trunk/lib/IR/RemarkStreamer.cpp Mon Jun 17 09:06:00 2019
@@ -109,10 +109,37 @@ void RemarkStreamer::emit(const Diagnost
 
 char RemarkSetupFileError::ID = 0;
 char RemarkSetupPatternError::ID = 0;
+char RemarkSetupFormatError::ID = 0;
+
+static std::unique_ptr<remarks::Serializer>
+formatToSerializer(RemarksSerializerFormat RemarksFormat, raw_ostream &OS) {
+  switch (RemarksFormat) {
+  default:
+    llvm_unreachable("Unknown remark serializer format.");
+    return nullptr;
+  case RemarksSerializerFormat::YAML:
+    return llvm::make_unique<remarks::YAMLSerializer>(OS);
+  };
+}
+
+Expected<RemarksSerializerFormat>
+llvm::parseSerializerFormat(StringRef StrFormat) {
+  auto Format = StringSwitch<RemarksSerializerFormat>(StrFormat)
+                    .Cases("", "yaml", RemarksSerializerFormat::YAML)
+                    .Default(RemarksSerializerFormat::Unknown);
+
+  if (Format == RemarksSerializerFormat::Unknown)
+    return createStringError(std::make_error_code(std::errc::invalid_argument),
+                             "Unknown remark serializer format: '%s'",
+                             StrFormat.data());
+
+  return Format;
+}
 
 Expected<std::unique_ptr<ToolOutputFile>>
 llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
-                               StringRef RemarksPasses, bool RemarksWithHotness,
+                               StringRef RemarksPasses, StringRef RemarksFormat,
+                               bool RemarksWithHotness,
                                unsigned RemarksHotnessThreshold) {
   if (RemarksWithHotness)
     Context.setDiagnosticsHotnessRequested(true);
@@ -131,9 +158,13 @@ llvm::setupOptimizationRemarks(LLVMConte
   if (EC)
     return make_error<RemarkSetupFileError>(errorCodeToError(EC));
 
+  Expected<RemarksSerializerFormat> Format =
+      parseSerializerFormat(RemarksFormat);
+  if (Error E = Format.takeError())
+    return make_error<RemarkSetupFormatError>(std::move(E));
+
   Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
-      RemarksFilename,
-      llvm::make_unique<remarks::YAMLSerializer>(RemarksFile->os())));
+      RemarksFilename, formatToSerializer(*Format, RemarksFile->os())));
 
   if (!RemarksPasses.empty())
     if (Error E = Context.getRemarkStreamer()->setFilter(RemarksPasses))

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Mon Jun 17 09:06:00 2019
@@ -1339,14 +1339,14 @@ Error LTO::runThinLTO(AddStreamFn AddStr
 
 Expected<std::unique_ptr<ToolOutputFile>>
 lto::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
-                              StringRef RemarksPasses, bool RemarksWithHotness,
-                              int Count) {
+                              StringRef RemarksPasses, StringRef RemarksFormat,
+                              bool RemarksWithHotness, int Count) {
   std::string Filename = RemarksFilename;
   if (!Filename.empty() && Count != -1)
     Filename += ".thin." + llvm::utostr(Count) + ".yaml";
 
   auto ResultOrErr = llvm::setupOptimizationRemarks(
-      Context, Filename, RemarksPasses, RemarksWithHotness);
+      Context, Filename, RemarksPasses, RemarksFormat, RemarksWithHotness);
   if (Error E = ResultOrErr.takeError())
     return std::move(E);
 

Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Mon Jun 17 09:06:00 2019
@@ -431,9 +431,9 @@ Error lto::backend(Config &C, AddStreamF
   std::unique_ptr<TargetMachine> TM = createTargetMachine(C, *TOrErr, *Mod);
 
   // Setup optimization remarks.
-  auto DiagFileOrErr =
-      lto::setupOptimizationRemarks(Mod->getContext(), C.RemarksFilename,
-                                    C.RemarksPasses, C.RemarksWithHotness);
+  auto DiagFileOrErr = lto::setupOptimizationRemarks(
+      Mod->getContext(), C.RemarksFilename, C.RemarksPasses, C.RemarksFormat,
+      C.RemarksWithHotness);
   if (!DiagFileOrErr)
     return DiagFileOrErr.takeError();
   auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
@@ -488,7 +488,7 @@ Error lto::thinBackend(Config &Conf, uns
   // Setup optimization remarks.
   auto DiagFileOrErr = lto::setupOptimizationRemarks(
       Mod.getContext(), Conf.RemarksFilename, Conf.RemarksPasses,
-      Conf.RemarksWithHotness, Task);
+      Conf.RemarksFormat, Conf.RemarksWithHotness, Task);
   if (!DiagFileOrErr)
     return DiagFileOrErr.takeError();
   auto DiagnosticOutputFile = std::move(*DiagFileOrErr);

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Mon Jun 17 09:06:00 2019
@@ -97,6 +97,11 @@ cl::opt<std::string>
                            "names match the given regular expression"),
                   cl::value_desc("regex"));
 
+cl::opt<std::string> RemarksFormat(
+    "lto-pass-remarks-format",
+    cl::desc("The format used for serializing remarks (default: YAML)"),
+    cl::value_desc("format"), cl::init("yaml"));
+
 cl::opt<std::string> LTOStatsFile(
     "lto-stats-file",
     cl::desc("Save statistics to the specified file"),
@@ -517,8 +522,9 @@ bool LTOCodeGenerator::optimize(bool Dis
   if (!this->determineTarget())
     return false;
 
-  auto DiagFileOrErr = lto::setupOptimizationRemarks(
-      Context, RemarksFilename, RemarksPasses, RemarksWithHotness);
+  auto DiagFileOrErr =
+      lto::setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
+                                    RemarksFormat, RemarksWithHotness);
   if (!DiagFileOrErr) {
     errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
     report_fatal_error("Can't get an output file for the remarks");

Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Mon Jun 17 09:06:00 2019
@@ -73,6 +73,7 @@ extern cl::opt<bool> LTODiscardValueName
 extern cl::opt<std::string> RemarksFilename;
 extern cl::opt<std::string> RemarksPasses;
 extern cl::opt<bool> RemarksWithHotness;
+extern cl::opt<std::string> RemarksFormat;
 }
 
 namespace {
@@ -1020,7 +1021,7 @@ void ThinLTOCodeGenerator::run() {
         Context.setDiscardValueNames(LTODiscardValueNames);
         Context.enableDebugTypeODRUniquing();
         auto DiagFileOrErr = lto::setupOptimizationRemarks(
-            Context, RemarksFilename, RemarksPasses,
+            Context, RemarksFilename, RemarksPasses, RemarksFormat,
             RemarksWithHotness, count);
         if (!DiagFileOrErr) {
           errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";

Modified: llvm/trunk/test/ThinLTO/X86/diagnostic-handler-remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/diagnostic-handler-remarks.ll?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/diagnostic-handler-remarks.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/diagnostic-handler-remarks.ll Mon Jun 17 09:06:00 2019
@@ -6,6 +6,7 @@
 ; RUN: llvm-lto -thinlto-action=run \
 ; RUN:          -lto-pass-remarks-output=%t.yaml \
 ; RUN:          -lto-pass-remarks-filter=inline \
+; RUN:          -lto-pass-remarks-format=yaml \
 ; RUN:          -exported-symbol _func2 \
 ; RUN:          -exported-symbol _main %t1.bc %t2.bc 2>&1 | \
 ; RUN:     FileCheck %s -allow-empty

Modified: llvm/trunk/test/tools/gold/X86/opt-remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/opt-remarks.ll?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/opt-remarks.ll (original)
+++ llvm/trunk/test/tools/gold/X86/opt-remarks.ll Mon Jun 17 09:06:00 2019
@@ -3,10 +3,12 @@
 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \
 ; RUN:	  -plugin-opt=save-temps \
 ; RUN:    -plugin-opt=opt-remarks-passes=inline \
+; RUN:    -plugin-opt=opt-remarks-format=yaml \
 ; RUN:    -plugin-opt=opt-remarks-filename=%t.yaml %t.o -o %t2.o 2>&1
 ; RUN: llvm-dis %t2.o.0.4.opt.bc -o - | FileCheck %s
 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \
 ; RUN:    -plugin-opt=opt-remarks-passes=inline \
+; RUN:    -plugin-opt=opt-remarks-format=yaml \
 ; RUN:    -plugin-opt=opt-remarks-with-hotness \
 ; RUN:	  -plugin-opt=opt-remarks-filename=%t.hot.yaml %t.o -o %t2.o 2>&1
 ; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Mon Jun 17 09:06:00 2019
@@ -209,6 +209,7 @@ namespace options {
   static std::string RemarksFilename;
   static std::string RemarksPasses;
   static bool RemarksWithHotness = false;
+  static std::string RemarksFormat;
 
   // Context sensitive PGO options.
   static std::string cs_profile_path;
@@ -290,6 +291,8 @@ namespace options {
       RemarksPasses = opt.substr(strlen("opt-remarks-passes="));
     } else if (opt == "opt-remarks-with-hotness") {
       RemarksWithHotness = true;
+    } else if (opt.startswith("opt-remarks-format=")) {
+      RemarksFormat = opt.substr(strlen("opt-remarks-format="));
     } else if (opt.startswith("stats-file=")) {
       stats_file = opt.substr(strlen("stats-file="));
     } else {
@@ -913,6 +916,7 @@ static std::unique_ptr<LTO> createLTO(In
   Conf.RemarksFilename = options::RemarksFilename;
   Conf.RemarksPasses = options::RemarksPasses;
   Conf.RemarksWithHotness = options::RemarksWithHotness;
+  Conf.RemarksFormat = options::RemarksFormat;
 
   // Use new pass manager if set in driver
   Conf.UseNewPM = options::new_pass_manager;

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Mon Jun 17 09:06:00 2019
@@ -155,6 +155,11 @@ static cl::opt<std::string>
                            "names match the given regular expression"),
                   cl::value_desc("regex"));
 
+static cl::opt<std::string> RemarksFormat(
+    "pass-remarks-format",
+    cl::desc("The format used for serializing remarks (default: YAML)"),
+    cl::value_desc("format"), cl::init("yaml"));
+
 namespace {
 static ManagedStatic<std::vector<std::string>> RunPassNames;
 
@@ -329,7 +334,8 @@ int main(int argc, char **argv) {
 
   Expected<std::unique_ptr<ToolOutputFile>> RemarksFileOrErr =
       setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
-                               RemarksWithHotness, RemarksHotnessThreshold);
+                               RemarksFormat, RemarksWithHotness,
+                               RemarksHotnessThreshold);
   if (Error E = RemarksFileOrErr.takeError()) {
     WithColor::error(errs(), argv[0]) << toString(std::move(E)) << '\n';
     return 1;

Modified: llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp (original)
+++ llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp Mon Jun 17 09:06:00 2019
@@ -107,6 +107,11 @@ static cl::opt<std::string>
                            "names match the given regular expression"),
                   cl::value_desc("regex"));
 
+static cl::opt<std::string> RemarksFormat(
+    "pass-remarks-format",
+    cl::desc("The format used for serializing remarks (default: YAML)"),
+    cl::value_desc("format"), cl::init("yaml"));
+
 static cl::opt<std::string>
     SamplePGOFile("lto-sample-profile-file",
                   cl::desc("Specify a SamplePGO profile file"));
@@ -229,6 +234,7 @@ static int run(int argc, char **argv) {
   Conf.RemarksFilename = RemarksFilename;
   Conf.RemarksPasses = RemarksPasses;
   Conf.RemarksWithHotness = RemarksWithHotness;
+  Conf.RemarksFormat = RemarksFormat;
 
   Conf.SampleProfile = SamplePGOFile;
   Conf.CSIRProfile = CSPGOFile;

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=363573&r1=363572&r2=363573&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Mon Jun 17 09:06:00 2019
@@ -273,6 +273,11 @@ static cl::opt<std::string>
                            "names match the given regular expression"),
                   cl::value_desc("regex"));
 
+static cl::opt<std::string> RemarksFormat(
+    "pass-remarks-format",
+    cl::desc("The format used for serializing remarks (default: YAML)"),
+    cl::value_desc("format"), cl::init("yaml"));
+
 cl::opt<PGOKind>
     PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
                 cl::desc("The kind of profile guided optimization"),
@@ -552,7 +557,8 @@ int main(int argc, char **argv) {
 
   Expected<std::unique_ptr<ToolOutputFile>> RemarksFileOrErr =
       setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
-                               RemarksWithHotness, RemarksHotnessThreshold);
+                               RemarksFormat, RemarksWithHotness,
+                               RemarksHotnessThreshold);
   if (Error E = RemarksFileOrErr.takeError()) {
     errs() << toString(std::move(E)) << '\n';
     return 1;




More information about the llvm-commits mailing list