Rollup merge of #113723 - khei4:khei4/llvm-stats, r=oli-obk,nikic
Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics. This resurrects PR https://github.com/rust-lang/rust/pull/104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :). I have applied the changes requested by `@oli-obk` and `@nagisa` https://github.com/rust-lang/rust/pull/104000#discussion_r1014625377 and https://github.com/rust-lang/rust/pull/104000#discussion_r1014642482 in the latest commits. r? `@oli-obk` ----- LLVM has a neat [statistics](https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option) feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too. ----- (Edit: fix broken link (Edit2: fix segmentation fault and use malloc If `rustc` is built with ```toml [llvm] assertions = true ``` Then you can see like ``` rustc +stage1 -Z print-codegen-stats -C opt-level=3 tmp.rs ===-------------------------------------------------------------------------=== ... Statistics Collected ... ===-------------------------------------------------------------------------=== 3 aa - Number of MayAlias results 193 aa - Number of MustAlias results 531 aa - Number of NoAlias results ... ``` And the current default build emits only ``` $ rustc +stage1 -Z print-codegen-stats -C opt-level=3 tmp.rs ===-------------------------------------------------------------------------=== ... Statistics Collected ... ===-------------------------------------------------------------------------=== $ ``` This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...
This commit is contained in:
commit
2734b5ada9
10 changed files with 69 additions and 5 deletions
|
@ -46,6 +46,7 @@ use rustc_span::symbol::Symbol;
|
|||
|
||||
use std::any::Any;
|
||||
use std::ffi::CStr;
|
||||
use std::io::Write;
|
||||
|
||||
mod back {
|
||||
pub mod archive;
|
||||
|
@ -178,7 +179,28 @@ impl WriteBackendMethods for LlvmCodegenBackend {
|
|||
type ThinBuffer = back::lto::ThinBuffer;
|
||||
fn print_pass_timings(&self) {
|
||||
unsafe {
|
||||
llvm::LLVMRustPrintPassTimings();
|
||||
let mut size = 0;
|
||||
let cstr = llvm::LLVMRustPrintPassTimings(&mut size as *mut usize);
|
||||
if cstr.is_null() {
|
||||
println!("failed to get pass timings");
|
||||
} else {
|
||||
let timings = std::slice::from_raw_parts(cstr as *const u8, size);
|
||||
std::io::stdout().write_all(timings).unwrap();
|
||||
libc::free(cstr as *mut _);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn print_statistics(&self) {
|
||||
unsafe {
|
||||
let mut size = 0;
|
||||
let cstr = llvm::LLVMRustPrintStatistics(&mut size as *mut usize);
|
||||
if cstr.is_null() {
|
||||
println!("failed to get pass stats");
|
||||
} else {
|
||||
let stats = std::slice::from_raw_parts(cstr as *const u8, size);
|
||||
std::io::stdout().write_all(stats).unwrap();
|
||||
libc::free(cstr as *mut _);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn run_link(
|
||||
|
|
|
@ -1868,7 +1868,10 @@ extern "C" {
|
|||
pub fn LLVMRustGetLastError() -> *const c_char;
|
||||
|
||||
/// Print the pass timings since static dtors aren't picking them up.
|
||||
pub fn LLVMRustPrintPassTimings();
|
||||
pub fn LLVMRustPrintPassTimings(size: *const size_t) -> *const c_char;
|
||||
|
||||
/// Print the statistics since static dtors aren't picking them up.
|
||||
pub fn LLVMRustPrintStatistics(size: *const size_t) -> *const c_char;
|
||||
|
||||
pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
|
||||
|
||||
|
|
|
@ -110,6 +110,10 @@ unsafe fn configure_llvm(sess: &Session) {
|
|||
// Use non-zero `import-instr-limit` multiplier for cold callsites.
|
||||
add("-import-cold-multiplier=0.1", false);
|
||||
|
||||
if sess.print_llvm_stats() {
|
||||
add("-stats", false);
|
||||
}
|
||||
|
||||
for arg in sess_args {
|
||||
add(&(*arg), true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue