PGO: switch to using compiler-rt profile library. (#2527)

Also makes sure that the PGO runtime is available when doing the PGO tests.
This commit is contained in:
Johan Engelen 2018-01-30 20:36:58 +01:00 committed by Martin Kinkelin
parent 6dc59c78e0
commit 80fc2a2f08
18 changed files with 71 additions and 12 deletions

View file

@ -53,6 +53,7 @@ private:
virtual void addASanLinkFlags(const llvm::Triple &triple);
virtual void addFuzzLinkFlags(const llvm::Triple &triple);
virtual void addCppStdlibLinkFlags(const llvm::Triple &triple);
virtual void addProfileRuntimeLinkFlags(const llvm::Triple &triple);
virtual void addXRayLinkFlags(const llvm::Triple &triple);
virtual void addLinker();
@ -368,6 +369,33 @@ void ArgsBuilder::addCppStdlibLinkFlags(const llvm::Triple &triple) {
}
}
// Adds all required link flags for PGO.
void ArgsBuilder::addProfileRuntimeLinkFlags(const llvm::Triple &triple) {
std::string searchPaths[] = {
getFullCompilerRTLibPath(triple, "libldc_rt.profile"),
getFullCompilerRTLibPath(triple, "libclang_rt.profile"),
getFullClangCompilerRTLibPath(triple, "libclang_rt.profile"),
};
#if LDC_LLVM_VER >= 308
if (global.params.targetTriple->isOSLinux()) {
// For Linux, explicitly define __llvm_profile_runtime as undefined
// symbol, so that the initialization part of profile-rt is linked in.
addLdFlag("-u", llvm::getInstrProfRuntimeHookVarName());
}
#endif
for (const auto &filepath : searchPaths) {
IF_LOG Logger::println("Searching profile runtime: %s", filepath.c_str());
if (llvm::sys::fs::exists(filepath)) {
IF_LOG Logger::println("Found, linking with %s", filepath.c_str());
args.push_back(filepath);
return;
}
}
}
void ArgsBuilder::addSanitizers(const llvm::Triple &triple) {
if (opts::isSanitizerEnabled(opts::AddressSanitizer)) {
addASanLinkFlags(triple);
@ -401,14 +429,7 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
// Link with profile-rt library when generating an instrumented binary.
if (opts::isInstrumentingForPGO()) {
#if LDC_LLVM_VER >= 308
if (global.params.targetTriple->isOSLinux()) {
// For Linux, explicitly define __llvm_profile_runtime as undefined
// symbol, so that the initialization part of profile-rt is linked in.
addLdFlag("-u", llvm::getInstrProfRuntimeHookVarName());
}
#endif
args.push_back("-lldc-profile-rt");
addProfileRuntimeLinkFlags(*global.params.targetTriple);
}
if (opts::enableDynamicCompile) {