about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2023-08-03 23:24:58 +0200
committerJakub Beránek <berykubik@gmail.com>2023-08-04 10:31:00 +0200
commit93bdc01adf7091e473e36620d3f748ce0481f880 (patch)
treebaa9159f649f10625a40aea5f033a8a186f5afe3
parent2e6ac7fe5bb96bcc2d8c0b3e20db7cf7d2baa241 (diff)
downloadrust-93bdc01adf7091e473e36620d3f748ce0481f880.tar.gz
rust-93bdc01adf7091e473e36620d3f748ce0481f880.zip
Add hotness data to LLVM remarks
This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute.
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp3
-rw-r--r--tests/run-make/optimization-remarks-dir-pgo/Makefile16
-rw-r--r--tests/run-make/optimization-remarks-dir-pgo/foo.rs6
3 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index 8ef39a6c866..8c04a430573 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -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,
diff --git a/tests/run-make/optimization-remarks-dir-pgo/Makefile b/tests/run-make/optimization-remarks-dir-pgo/Makefile
new file mode 100644
index 00000000000..93be1472037
--- /dev/null
+++ b/tests/run-make/optimization-remarks-dir-pgo/Makefile
@@ -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"
diff --git a/tests/run-make/optimization-remarks-dir-pgo/foo.rs b/tests/run-make/optimization-remarks-dir-pgo/foo.rs
new file mode 100644
index 00000000000..f7ca1826338
--- /dev/null
+++ b/tests/run-make/optimization-remarks-dir-pgo/foo.rs
@@ -0,0 +1,6 @@
+#[inline(never)]
+pub fn bar() {}
+
+fn main() {
+    bar();
+}