[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
GitOrigin-RevId: 4f9c61ef7229037f43d6502f5157050aeadb4605
diff --git a/COFF/Config.h b/COFF/Config.h
index ba1a579..bde7b5b 100644
--- a/COFF/Config.h
+++ b/COFF/Config.h
@@ -215,6 +215,12 @@
// 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/COFF/Driver.cpp b/COFF/Driver.cpp
index 9c13d4a..c5c8d5c 100644
--- a/COFF/Driver.cpp
+++ b/COFF/Driver.cpp
@@ -1712,6 +1712,8 @@
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/COFF/LTO.cpp b/COFF/LTO.cpp
index 2fa3536..a47f66e 100644
--- a/COFF/LTO.cpp
+++ b/COFF/LTO.cpp
@@ -84,6 +84,8 @@
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/COFF/Options.td b/COFF/Options.td
index 73c3380..33d5609 100644
--- a/COFF/Options.td
+++ b/COFF/Options.td
@@ -239,6 +239,10 @@
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