qiongsiwu1 created this revision. qiongsiwu1 added reviewers: w2yehia, MaskRay. qiongsiwu1 added projects: clang, LLVM. Herald added subscribers: ormris, StephenFan, wenlei, steven_wu, hiraditya, inglorion. Herald added a project: All. qiongsiwu1 requested review of this revision. Herald added subscribers: llvm-commits, cfe-commits.
This patch enables context sensitive PGO (CSPGO) for LTO on AIX. Two parts are involved: 1. Frontend logic is added so libLTO can understand the CSPGO related options. 2. Two options are added to the backend so that the LTOCodeGenerator can understand the CSPGO related options and make use of them. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138854 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/lto-aix.c llvm/lib/LTO/LTOCodeGenerator.cpp
Index: llvm/lib/LTO/LTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/LTOCodeGenerator.cpp +++ llvm/lib/LTO/LTOCodeGenerator.cpp @@ -118,7 +118,16 @@ "lto-aix-system-assembler", cl::desc("Path to a system assembler, picked up on AIX only"), cl::value_desc("path")); -} + +cl::opt<bool> + LTORunCSIRInstr("cs-profile-generate", + cl::desc("Perform context sensitive PGO instrumentation"), + cl::init(false)); + +cl::opt<std::string> + 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 +140,9 @@ Config.PreCodeGenPassesHook = [](legacy::PassManager &PM) { PM.add(createObjCARCContractPass()); }; + + Config.RunCSIRInstr = LTORunCSIRInstr; + Config.CSIRProfile = LTOCSIRProfile; } LTOCodeGenerator::~LTOCodeGenerator() = default; Index: clang/test/Driver/lto-aix.c =================================================================== --- clang/test/Driver/lto-aix.c +++ 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" Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits