Add hotness data to LLVM remarks

This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute.
This commit is contained in:
Jakub Beránek 2023-08-03 23:24:58 +02:00
parent 2e6ac7fe5b
commit 93bdc01adf
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
3 changed files with 25 additions and 0 deletions

View File

@ -1967,6 +1967,9 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer;
if (RemarkFilePath != nullptr) {
// Enable PGO hotness data for remarks, if available
unwrap(C)->setDiagnosticsHotnessRequested(true);
std::error_code EC;
RemarkFile = std::make_unique<ToolOutputFile>(
RemarkFilePath,

View File

@ -0,0 +1,16 @@
# needs-profiler-support
include ../tools.mk
PROFILE_DIR=$(TMPDIR)/profiles
check_hotness:
$(RUSTC) -Cprofile-generate="$(TMPDIR)"/profdata -O foo.rs -o$(TMPDIR)/foo
$(TMPDIR)/foo
"$(LLVM_BIN_DIR)"/llvm-profdata merge \
-o "$(TMPDIR)"/merged.profdata \
"$(TMPDIR)"/profdata/*.profraw
$(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata -O foo.rs -Cremark=all -Zremark-dir=$(PROFILE_DIR)
# Check that PGO hotness is included in the remark files
cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "Hotness"

View File

@ -0,0 +1,6 @@
#[inline(never)]
pub fn bar() {}
fn main() {
bar();
}