[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG85af42df5dbb: [lld] add context-sensitive PGO options for MachO (authored by ellis). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151589/new/ https://reviews.llvm.org/D151589 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/cspgo-lto.c lld/MachO/Config.h lld/MachO/Driver.cpp lld/MachO/LTO.cpp lld/MachO/Options.td lld/test/MachO/cspgo-gen.ll lld/test/MachO/cspgo-use.ll lld/test/lit.cfg.py Index: lld/test/lit.cfg.py === --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -45,6 +45,7 @@ "llvm-objdump", "llvm-otool", "llvm-pdbutil", +"llvm-profdata", "llvm-dwarfdump", "llvm-readelf", "llvm-readobj", Index: lld/test/MachO/cspgo-use.ll === --- /dev/null +++ lld/test/MachO/cspgo-use.ll @@ -0,0 +1,18 @@ +; REQUIRES: x86 + +; Create an empty profile +; RUN: echo > %t.proftext +; RUN: llvm-profdata merge %t.proftext -o %t.profdata + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: Running pass: PGOInstrumentationUse + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +define void @foo() { +entry: + ret void +} Index: lld/test/MachO/cspgo-gen.ll === --- /dev/null +++ lld/test/MachO/cspgo-gen.ll @@ -0,0 +1,16 @@ +; REQUIRES: x86 + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: PGOInstrumentationGen + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +@__llvm_profile_runtime = global i32 0, align 4 + +define void @foo() { +entry: + ret void +} Index: lld/MachO/Options.td === --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -126,6 +126,10 @@ Group; def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">, HelpText<"Debug new pass manager">, Group; +def cs_profile_generate: Flag<["--"], "cs-profile-generate">, +HelpText<"Perform context senstive PGO instrumentation">, Group; +def cs_profile_path: Joined<["--"], "cs-profile-path=">, +HelpText<"Context sensitive profile file path">, Group; // This is a complete Options.td compiled from Apple's ld(1) manpage // dated 2018-03-07 and cross checked with ld64 source code in repo Index: lld/MachO/LTO.cpp === --- lld/MachO/LTO.cpp +++ lld/MachO/LTO.cpp @@ -69,6 +69,8 @@ c.TimeTraceEnabled = config->timeTraceEnabled; c.TimeTraceGranularity = config->timeTraceGranularity; c.DebugPassManager = config->ltoDebugPassManager; + c.CSIRProfile = std::string(config->csProfilePath); + c.RunCSIRInstr = config->csProfileGenerate; c.OptLevel = config->ltoo; c.CGOptLevel = config->ltoCgo; if (config->saveTemps) Index: lld/MachO/Driver.cpp === --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -1637,6 +1637,8 @@ config->ignoreAutoLinkOptions.insert(arg->getValue()); config->strictAutoLink = args.hasArg(OPT_strict_auto_link); config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager); + config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); + config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( Index: lld/MachO/Config.h === --- lld/MachO/Config.h +++ lld/MachO/Config.h @@ -206,6 +206,8 @@ std::vector sectionAlignments; std::vector segmentProtections; bool ltoDebugPassManager = false; + bool csProfileGenerate = false; + llvm::StringRef csProfilePath; bool callGraphProfileSort = false; llvm::StringRef printSymbolOrder; Index: clang/test/Driver/cspgo-lto.c === --- clang/test/Driver/cspgo-lto.c +++ clang/test/Driver/cspgo-lto.c @@ -4,3 +4,17 @@ // RUN: -fprofile-use 2>&1 | FileCheck %s // CHECK: -plugin-opt=cs-profile-path=default.profdata + +// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld
[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
ellis updated this revision to Diff 527205. ellis added a comment. Fix paths in clang test to support windows Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151589/new/ https://reviews.llvm.org/D151589 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/cspgo-lto.c lld/MachO/Config.h lld/MachO/Driver.cpp lld/MachO/LTO.cpp lld/MachO/Options.td lld/test/MachO/cspgo-gen.ll lld/test/MachO/cspgo-use.ll lld/test/lit.cfg.py Index: lld/test/lit.cfg.py === --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -45,6 +45,7 @@ "llvm-objdump", "llvm-otool", "llvm-pdbutil", +"llvm-profdata", "llvm-dwarfdump", "llvm-readelf", "llvm-readobj", Index: lld/test/MachO/cspgo-use.ll === --- /dev/null +++ lld/test/MachO/cspgo-use.ll @@ -0,0 +1,18 @@ +; REQUIRES: x86 + +; Create an empty profile +; RUN: echo > %t.proftext +; RUN: llvm-profdata merge %t.proftext -o %t.profdata + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: Running pass: PGOInstrumentationUse + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +define void @foo() { +entry: + ret void +} Index: lld/test/MachO/cspgo-gen.ll === --- /dev/null +++ lld/test/MachO/cspgo-gen.ll @@ -0,0 +1,16 @@ +; REQUIRES: x86 + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: PGOInstrumentationGen + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +@__llvm_profile_runtime = global i32 0, align 4 + +define void @foo() { +entry: + ret void +} Index: lld/MachO/Options.td === --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -126,6 +126,10 @@ Group; def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">, HelpText<"Debug new pass manager">, Group; +def cs_profile_generate: Flag<["--"], "cs-profile-generate">, +HelpText<"Perform context senstive PGO instrumentation">, Group; +def cs_profile_path: Joined<["--"], "cs-profile-path=">, +HelpText<"Context sensitive profile file path">, Group; // This is a complete Options.td compiled from Apple's ld(1) manpage // dated 2018-03-07 and cross checked with ld64 source code in repo Index: lld/MachO/LTO.cpp === --- lld/MachO/LTO.cpp +++ lld/MachO/LTO.cpp @@ -69,6 +69,8 @@ c.TimeTraceEnabled = config->timeTraceEnabled; c.TimeTraceGranularity = config->timeTraceGranularity; c.DebugPassManager = config->ltoDebugPassManager; + c.CSIRProfile = std::string(config->csProfilePath); + c.RunCSIRInstr = config->csProfileGenerate; c.OptLevel = config->ltoo; c.CGOptLevel = config->ltoCgo; if (config->saveTemps) Index: lld/MachO/Driver.cpp === --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -1637,6 +1637,8 @@ config->ignoreAutoLinkOptions.insert(arg->getValue()); config->strictAutoLink = args.hasArg(OPT_strict_auto_link); config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager); + config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); + config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( Index: lld/MachO/Config.h === --- lld/MachO/Config.h +++ lld/MachO/Config.h @@ -206,6 +206,8 @@ std::vector sectionAlignments; std::vector segmentProtections; bool ltoDebugPassManager = false; + bool csProfileGenerate = false; + llvm::StringRef csProfilePath; bool callGraphProfileSort = false; llvm::StringRef printSymbolOrder; Index: clang/test/Driver/cspgo-lto.c === --- clang/test/Driver/cspgo-lto.c +++ clang/test/Driver/cspgo-lto.c @@ -4,3 +4,17 @@ // RUN: -fprofile-use 2>&1 | FileCheck %s // CHECK: -plugin-opt=cs-profile-path=default.profdata + +// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1 +// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin
[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
ellis updated this revision to Diff 526825. ellis marked 3 inline comments as not done. ellis added a comment. Rename test function to `foo` since `_start` is not a necessary symbol Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151589/new/ https://reviews.llvm.org/D151589 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/cspgo-lto.c lld/MachO/Config.h lld/MachO/Driver.cpp lld/MachO/LTO.cpp lld/MachO/Options.td lld/test/MachO/cspgo-gen.ll lld/test/MachO/cspgo-use.ll lld/test/lit.cfg.py Index: lld/test/lit.cfg.py === --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -45,6 +45,7 @@ "llvm-objdump", "llvm-otool", "llvm-pdbutil", +"llvm-profdata", "llvm-dwarfdump", "llvm-readelf", "llvm-readobj", Index: lld/test/MachO/cspgo-use.ll === --- /dev/null +++ lld/test/MachO/cspgo-use.ll @@ -0,0 +1,18 @@ +; REQUIRES: x86 + +; Create an empty profile +; RUN: echo > %t.proftext +; RUN: llvm-profdata merge %t.proftext -o %t.profdata + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: Running pass: PGOInstrumentationUse + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +define void @foo() { +entry: + ret void +} Index: lld/test/MachO/cspgo-gen.ll === --- /dev/null +++ lld/test/MachO/cspgo-gen.ll @@ -0,0 +1,16 @@ +; REQUIRES: x86 + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: PGOInstrumentationGen + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +@__llvm_profile_runtime = global i32 0, align 4 + +define void @foo() { +entry: + ret void +} Index: lld/MachO/Options.td === --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -126,6 +126,10 @@ Group; def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">, HelpText<"Debug new pass manager">, Group; +def cs_profile_generate: Flag<["--"], "cs-profile-generate">, +HelpText<"Perform context senstive PGO instrumentation">, Group; +def cs_profile_path: Joined<["--"], "cs-profile-path=">, +HelpText<"Context sensitive profile file path">, Group; // This is a complete Options.td compiled from Apple's ld(1) manpage // dated 2018-03-07 and cross checked with ld64 source code in repo Index: lld/MachO/LTO.cpp === --- lld/MachO/LTO.cpp +++ lld/MachO/LTO.cpp @@ -69,6 +69,8 @@ c.TimeTraceEnabled = config->timeTraceEnabled; c.TimeTraceGranularity = config->timeTraceGranularity; c.DebugPassManager = config->ltoDebugPassManager; + c.CSIRProfile = std::string(config->csProfilePath); + c.RunCSIRInstr = config->csProfileGenerate; c.OptLevel = config->ltoo; c.CGOptLevel = config->ltoCgo; if (config->saveTemps) Index: lld/MachO/Driver.cpp === --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -1638,6 +1638,8 @@ config->ignoreAutoLinkOptions.insert(arg->getValue()); config->strictAutoLink = args.hasArg(OPT_strict_auto_link); config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager); + config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); + config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( Index: lld/MachO/Config.h === --- lld/MachO/Config.h +++ lld/MachO/Config.h @@ -207,6 +207,8 @@ std::vector sectionAlignments; std::vector segmentProtections; bool ltoDebugPassManager = false; + bool csProfileGenerate = false; + llvm::StringRef csProfilePath; bool callGraphProfileSort = false; llvm::StringRef printSymbolOrder; Index: clang/test/Driver/cspgo-lto.c === --- clang/test/Driver/cspgo-lto.c +++ clang/test/Driver/cspgo-lto.c @@ -4,3 +4,17 @@ // RUN: -fprofile-use 2>&1 | FileCheck %s // CHECK: -plugin-opt=cs-profile-path=default.profdata + +// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s
[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
int3 added inline comments. Comment at: lld/test/MachO/cspgo-gen.ll:13 + +define void @_start() { +entry: doesn't *really* matter since you are creating a dylib, but `lld-macho` doesn't actually treat `_start` as a special symbol (only `main`). maybe rename to `foo` to be less misleading? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151589/new/ https://reviews.llvm.org/D151589 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
ellis updated this revision to Diff 526751. ellis marked 3 inline comments as done. ellis added a comment. Add test to check that `PGOInstrumentationGen`(`Use`) are run Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151589/new/ https://reviews.llvm.org/D151589 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/cspgo-lto.c lld/MachO/Config.h lld/MachO/Driver.cpp lld/MachO/LTO.cpp lld/MachO/Options.td lld/test/MachO/cspgo-gen.ll lld/test/MachO/cspgo-use.ll lld/test/lit.cfg.py Index: lld/test/lit.cfg.py === --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -45,6 +45,7 @@ "llvm-objdump", "llvm-otool", "llvm-pdbutil", +"llvm-profdata", "llvm-dwarfdump", "llvm-readelf", "llvm-readobj", Index: lld/test/MachO/cspgo-use.ll === --- /dev/null +++ lld/test/MachO/cspgo-use.ll @@ -0,0 +1,18 @@ +; REQUIRES: x86 + +; Create an empty profile +; RUN: echo > %t.proftext +; RUN: llvm-profdata merge %t.proftext -o %t.profdata + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: Running pass: PGOInstrumentationUse + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +define void @_start() { +entry: + ret void +} Index: lld/test/MachO/cspgo-gen.ll === --- /dev/null +++ lld/test/MachO/cspgo-gen.ll @@ -0,0 +1,16 @@ +; REQUIRES: x86 + +; RUN: llvm-as %s -o %t.o +; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation + +; CHECK: PGOInstrumentationGen + +target triple = "x86_64-apple-darwin" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +@__llvm_profile_runtime = global i32 0, align 4 + +define void @_start() { +entry: + ret void +} Index: lld/MachO/Options.td === --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -126,6 +126,10 @@ Group; def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">, HelpText<"Debug new pass manager">, Group; +def cs_profile_generate: Flag<["--"], "cs-profile-generate">, +HelpText<"Perform context senstive PGO instrumentation">, Group; +def cs_profile_path: Joined<["--"], "cs-profile-path=">, +HelpText<"Context sensitive profile file path">, Group; // This is a complete Options.td compiled from Apple's ld(1) manpage // dated 2018-03-07 and cross checked with ld64 source code in repo Index: lld/MachO/LTO.cpp === --- lld/MachO/LTO.cpp +++ lld/MachO/LTO.cpp @@ -69,6 +69,8 @@ c.TimeTraceEnabled = config->timeTraceEnabled; c.TimeTraceGranularity = config->timeTraceGranularity; c.DebugPassManager = config->ltoDebugPassManager; + c.CSIRProfile = std::string(config->csProfilePath); + c.RunCSIRInstr = config->csProfileGenerate; c.OptLevel = config->ltoo; c.CGOptLevel = config->ltoCgo; if (config->saveTemps) Index: lld/MachO/Driver.cpp === --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -1638,6 +1638,8 @@ config->ignoreAutoLinkOptions.insert(arg->getValue()); config->strictAutoLink = args.hasArg(OPT_strict_auto_link); config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager); + config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); + config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( Index: lld/MachO/Config.h === --- lld/MachO/Config.h +++ lld/MachO/Config.h @@ -207,6 +207,8 @@ std::vector sectionAlignments; std::vector segmentProtections; bool ltoDebugPassManager = false; + bool csProfileGenerate = false; + llvm::StringRef csProfilePath; bool callGraphProfileSort = false; llvm::StringRef printSymbolOrder; Index: clang/test/Driver/cspgo-lto.c === --- clang/test/Driver/cspgo-lto.c +++ clang/test/Driver/cspgo-lto.c @@ -4,3 +4,17 @@ // RUN: -fprofile-use 2>&1 | FileCheck %s // CHECK: -plugin-opt=cs-profile-path=default.profdata + +// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1
[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
MaskRay accepted this revision as: MaskRay. MaskRay added inline comments. This revision is now accepted and ready to land. Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1356 +Arg *tools::getLastCSProfileGenerateArg(const ArgList ) { + auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate, Similar code in Clang.cpp `addPGOAndCoverageFlags` can be replaced by this function. Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:459 + llvm::sys::path::append(Path, "default_%m.profraw"); + CmdArgs.push_back(Args.MakeArgString("--cs-profile-generate")); + CmdArgs.push_back(Args.MakeArgString(Twine("--cs-profile-path=") + Path)); String literal doesn't need `MakeArgString` Comment at: clang/test/Driver/cspgo-lto.c:8 + +// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1 +// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use=a.profdata 2>&1 | FileCheck %s --check-prefix=DARWIN-USE2 Prefer `--target=` to deprecated/legacy (since clang 3.x) `-target ` Comment at: lld/MachO/Driver.cpp:1640 config->strictAutoLink = args.hasArg(OPT_strict_auto_link); + config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); + config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); This needs a `lld/test/MachO` test. The ELF patch unfortunately doesn't add a test and I failed to notice it. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151589/new/ https://reviews.llvm.org/D151589 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D151589: [lld] add context-sensitive PGO options for MachO
ellis created this revision. Herald added subscribers: wlei, ormris, wenlei, steven_wu, hiraditya. Herald added projects: lld-macho, All. Herald added a reviewer: lld-macho. ellis added reviewers: int3, tejohnson, xur. ellis updated this revision to Diff 526199. ellis added a comment. ellis edited the summary of this revision. ellis edited the summary of this revision. ellis edited the summary of this revision. ellis published this revision for review. Herald added subscribers: cfe-commits, MaskRay. Herald added a project: clang. Only pass flags when using lld Enable support for CSPGO for lld MachO targets. Since lld MachO does not support `-plugin-opt=`, we need to create the `--cs-profile-generate` and `--cs-profile-path=` options and propagate them in `Darwin.cpp`. These flags are not supported by ld64. Also outline code into `getLastCSProfileGenerateArg()` to share between `CommonArgs.cpp` and `Darwin.cpp`. CSPGO is already implemented for ELF (https://reviews.llvm.org/D56675) and COFF (https://reviews.llvm.org/D98763). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D151589 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/cspgo-lto.c lld/MachO/Config.h lld/MachO/Driver.cpp lld/MachO/LTO.cpp lld/MachO/Options.td Index: lld/MachO/Options.td === --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -124,6 +124,10 @@ def check_category_conflicts : Flag<["--"], "check-category-conflicts">, HelpText<"Check for conflicts between category & class methods">, Group; +def cs_profile_generate: Flag<["--"], "cs-profile-generate">, +HelpText<"Perform context senstive PGO instrumentation">, Group; +def cs_profile_path: Joined<["--"], "cs-profile-path=">, +HelpText<"Context sensitive profile file path">, Group; // This is a complete Options.td compiled from Apple's ld(1) manpage // dated 2018-03-07 and cross checked with ld64 source code in repo Index: lld/MachO/LTO.cpp === --- lld/MachO/LTO.cpp +++ lld/MachO/LTO.cpp @@ -68,6 +68,8 @@ c.TimeTraceEnabled = config->timeTraceEnabled; c.TimeTraceGranularity = config->timeTraceGranularity; + c.CSIRProfile = std::string(config->csProfilePath); + c.RunCSIRInstr = config->csProfileGenerate; c.OptLevel = config->ltoo; c.CGOptLevel = config->ltoCgo; if (config->saveTemps) Index: lld/MachO/Driver.cpp === --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -1637,6 +1637,8 @@ for (const Arg *arg : args.filtered(OPT_ignore_auto_link_option)) config->ignoreAutoLinkOptions.insert(arg->getValue()); config->strictAutoLink = args.hasArg(OPT_strict_auto_link); + config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); + config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( Index: lld/MachO/Config.h === --- lld/MachO/Config.h +++ lld/MachO/Config.h @@ -206,6 +206,8 @@ // so use a vector instead of a map. std::vector sectionAlignments; std::vector segmentProtections; + bool csProfileGenerate = false; + llvm::StringRef csProfilePath; bool callGraphProfileSort = false; llvm::StringRef printSymbolOrder; Index: clang/test/Driver/cspgo-lto.c === --- clang/test/Driver/cspgo-lto.c +++ clang/test/Driver/cspgo-lto.c @@ -4,3 +4,17 @@ // RUN: -fprofile-use 2>&1 | FileCheck %s // CHECK: -plugin-opt=cs-profile-path=default.profdata + +// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1 +// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use=a.profdata 2>&1 | FileCheck %s --check-prefix=DARWIN-USE2 + +// DARWIN-USE1: "--cs-profile-path=default.profdata" +// DARWIN-USE2: "--cs-profile-path=a.profdata" + +// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fcs-profile-generate 2>&1 | FileCheck %s --check-prefix=DARWIN-GEN1 +// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fcs-profile-generate=/dump/here 2>&1 | FileCheck %s --check-prefix=DARWIN-GEN2 + +// DARWIN-GEN1: "--cs-profile-generate" +// DARWIN-GEN1-SAME: "--cs-profile-path=default_%m.profraw" +// DARWIN-GEN2: "--cs-profile-generate" +// DARWIN-GEN2-SAME: "--cs-profile-path=/dump/here/default_%m.profraw" Index: clang/lib/Driver/ToolChains/Darwin.cpp === --- clang/lib/Driver/ToolChains/Darwin.cpp +++ clang/lib/Driver/ToolChains/Darwin.cpp @@ -449,6 +449,23 @@