Rollup merge of #108400 - csmoe:cgu-instr-perf, r=bjorn3

add llvm cgu instructions stats to perf

r? ```@bjorn3```
This commit is contained in:
Matthias Krüger 2023-03-01 01:21:56 +01:00 committed by GitHub
commit 32d7024100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 0 deletions

View file

@ -761,6 +761,7 @@ pub(crate) unsafe fn codegen(
EmitObj::None => {}
}
record_llvm_cgu_instructions_stats(&cgcx.prof, llmod);
drop(handlers);
}
@ -974,3 +975,23 @@ fn record_artifact_size(
self_profiler_ref.artifact_size(artifact_kind, artifact_name.to_string_lossy(), file_size);
}
}
fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Module) {
if !prof.enabled() {
return;
}
let raw_stats =
llvm::build_string(|s| unsafe { llvm::LLVMRustModuleInstructionStats(&llmod, s) })
.expect("cannot get module instruction stats");
#[derive(serde::Deserialize)]
struct InstructionsStats {
module: String,
total: u64,
}
let InstructionsStats { module, total } =
serde_json::from_str(&raw_stats).expect("cannot parse llvm cgu instructions stats");
prof.artifact_size("cgu_instructions", module, total);
}

View file

@ -2410,6 +2410,8 @@ extern "C" {
pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
pub fn LLVMRustModuleCost(M: &Module) -> u64;
#[allow(improper_ctypes)]
pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
pub fn LLVMRustThinLTOBufferCreate(M: &Module, is_thin: bool) -> &'static mut ThinLTOBuffer;
pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);