[clang] [Clang] [PGO] Provide default value for -fprofile-sample-use (PR #112750)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 10:23:29 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang
Author: Mikołaj Piróg (mikolaj-pirog)
<details>
<summary>Changes</summary>
As in title. This matches the behavior of `-fprofile-use`, which when used without a path to the file, looks for `default.profdata` file in the current/supplied dir. Fixes #<!-- -->112391
---
Full diff: https://github.com/llvm/llvm-project/pull/112750.diff
1 Files Affected:
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+21)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fc39296f44281..2da8b604ebff62 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -594,6 +594,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
<< PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
auto *ProfileUseArg = getLastProfileUseArg(Args);
+ auto *ProfileSampleUseArg = Args.getLastArg(
+ options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ);
if (PGOGenerateArg && ProfileUseArg)
D.Diag(diag::err_drv_argument_not_allowed_with)
@@ -677,6 +679,25 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
}
}
+ if (ProfileSampleUseArg) {
+ if ((ProfileSampleUseArg->getOption().matches(
+ options::OPT_fprofile_sample_use) ||
+ ProfileSampleUseArg->getOption().matches(
+ options::OPT_fprofile_sample_use_EQ))) {
+ SmallString<128> Path(ProfileSampleUseArg->getNumValues() == 0
+ ? ""
+ : ProfileSampleUseArg->getValue());
+ if (Path.empty() || llvm::sys::fs::is_directory(Path))
+ llvm::sys::path::append(Path, "default.profdata");
+
+ if (!llvm::sys::fs::exists(Path))
+ D.Diag(diag::err_drv_no_such_file) << Path;
+
+ CmdArgs.push_back(
+ Args.MakeArgString(Twine("-fprofile-sample-use=") + Path));
+ }
+ }
+
bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
options::OPT_fno_test_coverage, false) ||
Args.hasArg(options::OPT_coverage);
``````````
</details>
https://github.com/llvm/llvm-project/pull/112750
More information about the cfe-commits
mailing list