Skip to content

Commit 93bdc01

Browse files
committed
Add hotness data to LLVM remarks
This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute.
1 parent 2e6ac7f commit 93bdc01

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,9 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
19671967
std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer;
19681968

19691969
if (RemarkFilePath != nullptr) {
1970+
// Enable PGO hotness data for remarks, if available
1971+
unwrap(C)->setDiagnosticsHotnessRequested(true);
1972+
19701973
std::error_code EC;
19711974
RemarkFile = std::make_unique<ToolOutputFile>(
19721975
RemarkFilePath,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# needs-profiler-support
2+
3+
include ../tools.mk
4+
5+
PROFILE_DIR=$(TMPDIR)/profiles
6+
7+
check_hotness:
8+
$(RUSTC) -Cprofile-generate="$(TMPDIR)"/profdata -O foo.rs -o$(TMPDIR)/foo
9+
$(TMPDIR)/foo
10+
"$(LLVM_BIN_DIR)"/llvm-profdata merge \
11+
-o "$(TMPDIR)"/merged.profdata \
12+
"$(TMPDIR)"/profdata/*.profraw
13+
$(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata -O foo.rs -Cremark=all -Zremark-dir=$(PROFILE_DIR)
14+
15+
# Check that PGO hotness is included in the remark files
16+
cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "Hotness"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[inline(never)]
2+
pub fn bar() {}
3+
4+
fn main() {
5+
bar();
6+
}

0 commit comments

Comments
 (0)