[PATCH] D129586: [LinkerWrapper] Support remarks files for device LTO

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 12 13:01:15 PDT 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield.
Herald added subscribers: wenlei, inglorion.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds the necessary changes to parse the `-plugin-opt`
arguments that provide the paths for things like
`-fsave-optmization-record`, allowing these options to be used for
device LTO as well. We still require some form of PGO to fully utilize
these however.

Depends on D129581 <https://reviews.llvm.org/D129581>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129586

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===================================================================
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -112,6 +112,24 @@
 def opt_level : Joined<["--", "-"], "plugin-opt=O">, Flags<[HelpHidden, PluginOnlyOption]>,
   HelpText<"Optimization level for LTO">;
 
+def jobs : Joined<["--", "-"], "plugin-opt=jobs=">, Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Number of jobs for ThinLTO">;
+
+def remarks_filename : Joined<["--", "-"], "plugin-opt=opt-remarks-filename=">,
+  Flags<[HelpHidden, PluginOnlyOption]>, HelpText<"YAML output file for optimization remarks">;
+def remarks_passes : Joined<["--", "-"], "plugin-opt=opt-remarks-passes=">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Regex for the passes that need to be serialized to the output file">;
+def remarks_with_hotness : Flag<["--", "-"], "plugin-opt=opt-remarks-with-hotness">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Regex for the passes that need to be serialized to the output file">;
+def remarks_hotness_threshold : Joined<["--", "-"], "plugin-opt=opt-remarks-hotness-threshold">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Minimum profile count to trigger an optimization">;
+def remarks_format : Joined<["--", "-"], "plugin-opt=opt-remarks-format=">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"The format used for serializing remarks (default: YAML)">;
+
 // Sink all the other options here so we can ignore them if needed.
 def plugin_opt : Separate<["--", "-"], "plugin-opt">, Flags<[HelpHidden, PluginOnlyOption]>,
   HelpText<"Options passed to the linker plugin">;
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===================================================================
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Remarks/HotnessThresholdParser.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
@@ -783,8 +784,9 @@
   lto::Config Conf;
   lto::ThinBackend Backend;
   // TODO: Handle index-only thin-LTO
-  Backend =
-      lto::createInProcessThinBackend(llvm::heavyweight_hardware_concurrency());
+  StringRef Jobs = Args.getLastArgValue(OPT_jobs, "0");
+  Backend = lto::createInProcessThinBackend(
+      llvm::heavyweight_hardware_concurrency(Jobs));
 
   Conf.CPU = Arch.str();
   Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
@@ -820,7 +822,18 @@
   Conf.PostOptModuleHook = Hook;
   Conf.CGFileType = Triple.isNVPTX() ? CGFT_AssemblyFile : CGFT_ObjectFile;
 
-  // TODO: Handle remark files
+  Conf.RemarksFilename = (Args.getLastArgValue(OPT_remarks_filename) + "-" +
+                          Triple.getTriple() + "-" + Arch)
+                             .str();
+  Conf.RemarksPasses = Args.getLastArgValue(OPT_remarks_passes).str();
+  Conf.RemarksWithHotness = Args.hasArg(OPT_remarks_with_hotness);
+  Conf.RemarksFormat = Args.getLastArgValue(OPT_remarks_format).str();
+  auto Threshold = remarks::parseHotnessThresholdOption(
+      Args.getLastArgValue(OPT_remarks_hotness_threshold, "-1"));
+  if (!Threshold)
+    reportError(Threshold.takeError());
+  Conf.RemarksHotnessThreshold = *Threshold;
+
   Conf.HasWholeProgramVisibility = Args.hasArg(OPT_whole_program);
 
   return std::make_unique<lto::LTO>(std::move(Conf), Backend);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129586.444053.patch
Type: text/x-patch
Size: 3661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220712/fd37657d/attachment.bin>


More information about the cfe-commits mailing list