Auto merge of #114439 - Kobzol:remark-pgo-hotness, r=tmiasko
Add hotness data to LLVM remarks Slight improvement of https://github.com/rust-lang/rust/pull/113040. This makes sure that if PGO is used, remarks generated using `-Zremark-dir` will include the `Hotness` attribute. r? `@tmiasko`
This commit is contained in:
commit
f525bb4e2a
5 changed files with 36 additions and 1 deletions
|
@ -320,6 +320,7 @@ impl<'a> DiagnosticHandlers<'a> {
|
||||||
})
|
})
|
||||||
.and_then(|dir| dir.to_str().and_then(|p| CString::new(p).ok()));
|
.and_then(|dir| dir.to_str().and_then(|p| CString::new(p).ok()));
|
||||||
|
|
||||||
|
let pgo_available = cgcx.opts.cg.profile_use.is_some();
|
||||||
let data = Box::into_raw(Box::new((cgcx, handler)));
|
let data = Box::into_raw(Box::new((cgcx, handler)));
|
||||||
unsafe {
|
unsafe {
|
||||||
let old_handler = llvm::LLVMRustContextGetDiagnosticHandler(llcx);
|
let old_handler = llvm::LLVMRustContextGetDiagnosticHandler(llcx);
|
||||||
|
@ -333,6 +334,7 @@ impl<'a> DiagnosticHandlers<'a> {
|
||||||
// The `as_ref()` is important here, otherwise the `CString` will be dropped
|
// The `as_ref()` is important here, otherwise the `CString` will be dropped
|
||||||
// too soon!
|
// too soon!
|
||||||
remark_file.as_ref().map(|dir| dir.as_ptr()).unwrap_or(std::ptr::null()),
|
remark_file.as_ref().map(|dir| dir.as_ptr()).unwrap_or(std::ptr::null()),
|
||||||
|
pgo_available,
|
||||||
);
|
);
|
||||||
DiagnosticHandlers { data, llcx, old_handler }
|
DiagnosticHandlers { data, llcx, old_handler }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2332,6 +2332,7 @@ extern "C" {
|
||||||
remark_passes: *const *const c_char,
|
remark_passes: *const *const c_char,
|
||||||
remark_passes_len: usize,
|
remark_passes_len: usize,
|
||||||
remark_file: *const c_char,
|
remark_file: *const c_char,
|
||||||
|
pgo_available: bool,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
|
|
|
@ -1869,7 +1869,8 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
|
||||||
LLVMContextRef C, LLVMDiagnosticHandlerTy DiagnosticHandlerCallback,
|
LLVMContextRef C, LLVMDiagnosticHandlerTy DiagnosticHandlerCallback,
|
||||||
void *DiagnosticHandlerContext, bool RemarkAllPasses,
|
void *DiagnosticHandlerContext, bool RemarkAllPasses,
|
||||||
const char * const * RemarkPasses, size_t RemarkPassesLen,
|
const char * const * RemarkPasses, size_t RemarkPassesLen,
|
||||||
const char * RemarkFilePath
|
const char * RemarkFilePath,
|
||||||
|
bool PGOAvailable
|
||||||
) {
|
) {
|
||||||
|
|
||||||
class RustDiagnosticHandler final : public DiagnosticHandler {
|
class RustDiagnosticHandler final : public DiagnosticHandler {
|
||||||
|
@ -1967,6 +1968,11 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
|
||||||
std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer;
|
std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer;
|
||||||
|
|
||||||
if (RemarkFilePath != nullptr) {
|
if (RemarkFilePath != nullptr) {
|
||||||
|
if (PGOAvailable) {
|
||||||
|
// Enable PGO hotness data for remarks, if available
|
||||||
|
unwrap(C)->setDiagnosticsHotnessRequested(true);
|
||||||
|
}
|
||||||
|
|
||||||
std::error_code EC;
|
std::error_code EC;
|
||||||
RemarkFile = std::make_unique<ToolOutputFile>(
|
RemarkFile = std::make_unique<ToolOutputFile>(
|
||||||
RemarkFilePath,
|
RemarkFilePath,
|
||||||
|
|
20
tests/run-make/optimization-remarks-dir-pgo/Makefile
Normal file
20
tests/run-make/optimization-remarks-dir-pgo/Makefile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# needs-profiler-support
|
||||||
|
# ignore-windows-gnu
|
||||||
|
|
||||||
|
# FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works
|
||||||
|
# properly. Since we only have GCC on the CI ignore the test for now.
|
||||||
|
|
||||||
|
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"
|
6
tests/run-make/optimization-remarks-dir-pgo/foo.rs
Normal file
6
tests/run-make/optimization-remarks-dir-pgo/foo.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#[inline(never)]
|
||||||
|
pub fn bar() {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
bar();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue