[lld] 4f9c61e - [lld] add context-sensitive PGO options for COFF.

Pengfei Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 24 23:41:40 PDT 2021


Author: Yolanda Chen
Date: 2021-03-24T23:40:09-07:00
New Revision: 4f9c61ef7229037f43d6502f5157050aeadb4605

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

LOG: [lld] add context-sensitive PGO options for COFF.

Add lld CSPGO (Contex-Sensitive PGO) options for COFF target.

Reference the ELF options from https://reviews.llvm.org/D56675

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D98763

Added: 
    

Modified: 
    lld/COFF/Config.h
    lld/COFF/Driver.cpp
    lld/COFF/LTO.cpp
    lld/COFF/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index ba1a5793ed5b..bde7b5b473d9 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -215,6 +215,12 @@ struct Configuration {
   // Used for /lto-obj-path:
   llvm::StringRef ltoObjPath;
 
+  // Used for /lto-cs-profile-generate:
+  bool ltoCSProfileGenerate = false;
+
+  // Used for /lto-cs-profile-path
+  llvm::StringRef ltoCSProfileFile;
+
   // Used for /call-graph-ordering-file:
   llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>,
                   uint64_t>

diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 9c13d4a078ec..c5c8d5c0cf90 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1712,6 +1712,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   config->thinLTOObjectSuffixReplace =
       getOldNewOptions(args, OPT_thinlto_object_suffix_replace);
   config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);
+  config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate);
+  config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file);
   // Handle miscellaneous boolean flags.
   config->allowBind = args.hasFlag(OPT_allowbind, OPT_allowbind_no, true);
   config->allowIsolation =

diff  --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 2fa3536db873..a47f66ec7cf0 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -84,6 +84,8 @@ static lto::Config createConfig() {
   c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty();
   c.UseNewPM = config->ltoNewPassManager;
   c.DebugPassManager = config->ltoDebugPassManager;
+  c.CSIRProfile = std::string(config->ltoCSProfileFile);
+  c.RunCSIRInstr = config->ltoCSProfileGenerate;
 
   if (config->saveTemps)
     checkError(c.addSaveTemps(std::string(config->outputFile) + ".",

diff  --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index 73c3380df17c..33d560902f78 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -239,6 +239,10 @@ def thinlto_prefix_replace: P<
 def lto_obj_path : P<
     "lto-obj-path",
     "output native object for merged LTO unit to this path">;
+def lto_cs_profile_generate: F<"lto-cs-profile-generate">,
+    HelpText<"Perform context sensitive PGO instrumentation">;
+def lto_cs_profile_file : P<"lto-cs-profile-file",
+    "Context sensitive profile file path">;
 def dash_dash_version : Flag<["--"], "version">,
   HelpText<"Display the version number and exit">;
 def threads


        


More information about the llvm-commits mailing list