203 changes: 147 additions & 56 deletions llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion llvm/tools/gold/gold-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ namespace options {
static std::string OptRemarksFilename;
static bool OptRemarksWithHotness = false;

// Context sensitive PGO options.
static std::string cs_profile_path;
static bool cs_pgo_gen = false;

static void process_plugin_option(const char *opt_)
{
if (opt_ == nullptr)
Expand Down Expand Up @@ -268,7 +272,11 @@ namespace options {
} else if (opt == "disable-verify") {
DisableVerify = true;
} else if (opt.startswith("sample-profile=")) {
sample_profile= opt.substr(strlen("sample-profile="));
sample_profile = opt.substr(strlen("sample-profile="));
} else if (opt == "cs-profile-generate") {
cs_pgo_gen = true;
} else if (opt.startswith("cs-profile-path=")) {
cs_profile_path = opt.substr(strlen("cs-profile-path="));
} else if (opt == "new-pass-manager") {
new_pass_manager = true;
} else if (opt == "debug-pass-manager") {
Expand Down Expand Up @@ -892,6 +900,10 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
if (!options::sample_profile.empty())
Conf.SampleProfile = options::sample_profile;

if (!options::cs_profile_path.empty())
Conf.CSIRProfile = options::cs_profile_path;
Conf.RunCSIRInstr = options::cs_pgo_gen;

Conf.DwoDir = options::dwo_dir;

// Set up optimization remarks handling.
Expand Down
11 changes: 11 additions & 0 deletions llvm/tools/llvm-lto2/llvm-lto2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ static cl::opt<std::string>
SamplePGOFile("lto-sample-profile-file",
cl::desc("Specify a SamplePGO profile file"));

static cl::opt<std::string>
CSPGOFile("lto-cspgo-profile-file",
cl::desc("Specify a context sensitive PGO profile file"));

static cl::opt<bool>
RunCSIRInstr("lto-cspgo-gen",
cl::desc("Run PGO context sensitive IR instrumentation"),
cl::init(false), cl::Hidden);

static cl::opt<bool>
UseNewPM("use-new-pm",
cl::desc("Run LTO passes using the new pass manager"),
Expand Down Expand Up @@ -214,6 +223,8 @@ static int run(int argc, char **argv) {
Conf.RemarksWithHotness = OptRemarksWithHotness;

Conf.SampleProfile = SamplePGOFile;
Conf.CSIRProfile = CSPGOFile;
Conf.RunCSIRInstr = RunCSIRInstr;

// Run a custom pipeline, if asked for.
Conf.OptPipeline = OptPipeline;
Expand Down