diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -519,8 +519,7 @@ } const char *PluginOptPrefix = IsOSAIX ? "-bplugin_opt:" : "-plugin-opt="; - const char *mcpuOptPrefix = IsOSAIX ? "-mcpu=" : "mcpu="; - const char *OptLevelPrefix = IsOSAIX ? "-O" : "O"; + const char *ExtraDash = IsOSAIX ? "-" : ""; // Note, this solution is far from perfect, better to encode it into IR // metadata, but this may not be worth it, since it looks like aranges is on @@ -537,7 +536,7 @@ std::string CPU = getCPUName(D, Args, ToolChain.getTriple()); if (!CPU.empty()) CmdArgs.push_back( - Args.MakeArgString(Twine(PluginOptPrefix) + mcpuOptPrefix + CPU)); + Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "mcpu=" + CPU)); if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { // The optimization level matches @@ -556,7 +555,7 @@ OOpt = "0"; if (!OOpt.empty()) CmdArgs.push_back( - Args.MakeArgString(Twine(PluginOptPrefix) + OptLevelPrefix + OOpt)); + Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "O" + OOpt)); } if (Args.hasArg(options::OPT_gsplit_dwarf)) @@ -650,24 +649,25 @@ auto *ProfileUseArg = getLastProfileUseArg(Args); if (CSPGOGenerateArg) { - CmdArgs.push_back( - Args.MakeArgString(Twine(PluginOptPrefix) + "cs-profile-generate")); + CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + + "cs-profile-generate")); if (CSPGOGenerateArg->getOption().matches( options::OPT_fcs_profile_generate_EQ)) { SmallString<128> Path(CSPGOGenerateArg->getValue()); llvm::sys::path::append(Path, "default_%m.profraw"); - CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + + CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "cs-profile-path=" + Path)); } else - CmdArgs.push_back(Args.MakeArgString( - Twine(PluginOptPrefix) + "cs-profile-path=default_%m.profraw")); + CmdArgs.push_back( + Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + + "cs-profile-path=default_%m.profraw")); } else if (ProfileUseArg) { SmallString<128> Path( ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue()); if (Path.empty() || llvm::sys::fs::is_directory(Path)) llvm::sys::path::append(Path, "default.profdata"); - CmdArgs.push_back( - Args.MakeArgString(Twine(PluginOptPrefix) + "cs-profile-path=" + Path)); + CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + + "cs-profile-path=" + Path)); } // This controls whether or not we perform JustMyCode instrumentation. diff --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c --- a/clang/test/Driver/lto-aix.c +++ b/clang/test/Driver/lto-aix.c @@ -67,3 +67,9 @@ // // STRICT: "-bplugin_opt:-strict-dwarf=true" // NOSTRICT-NOT: "-bplugin_opt:-strict-dwarf=true" +// +// Test cspgo options +// RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld \ +// RUN: -fcs-profile-generate 2>&1 | FileCheck -check-prefix=CSPGO %s +// +// CSPGO: "-bplugin_opt:-cs-profile-generate" "-bplugin_opt:-cs-profile-path=default_%m.profraw" diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -118,7 +118,15 @@ "lto-aix-system-assembler", cl::desc("Path to a system assembler, picked up on AIX only"), cl::value_desc("path")); -} + +cl::opt + LTORunCSIRInstr("cs-profile-generate", + cl::desc("Perform context sensitive PGO instrumentation")); + +cl::opt + LTOCSIRProfile("cs-profile-path", + cl::desc("Context sensitive profile file path")); +} // namespace llvm LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context) : Context(Context), MergedModule(new Module("ld-temp.o", Context)), @@ -131,6 +139,9 @@ Config.PreCodeGenPassesHook = [](legacy::PassManager &PM) { PM.add(createObjCARCContractPass()); }; + + Config.RunCSIRInstr = LTORunCSIRInstr; + Config.CSIRProfile = LTOCSIRProfile; } LTOCodeGenerator::~LTOCodeGenerator() = default;