Removes the serde dependency in rustc_codegen_llvm

This commit is contained in:
dianqk 2025-12-28 15:51:10 +08:00
parent 23d01cd241
commit fe075ad212
No known key found for this signature in database
5 changed files with 7 additions and 30 deletions

View file

@ -3638,8 +3638,6 @@ dependencies = [
"rustc_span",
"rustc_symbol_mangling",
"rustc_target",
"serde",
"serde_json",
"smallvec",
"tracing",
]

View file

@ -38,8 +38,6 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
rustc_target = { path = "../rustc_target" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
# tidy-alphabetical-end

View file

@ -1136,7 +1136,7 @@ pub(crate) fn codegen(
EmitObj::None => {}
}
record_llvm_cgu_instructions_stats(&cgcx.prof, llmod);
record_llvm_cgu_instructions_stats(&cgcx.prof, &module.name, llmod);
}
// `.dwo` files are only emitted if:
@ -1343,22 +1343,11 @@ fn record_artifact_size(
}
}
fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Module) {
fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, name: &str, 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);
let total = unsafe { llvm::LLVMRustModuleInstructionStats(llmod) };
prof.artifact_size("cgu_instructions", name, total);
}

View file

@ -2454,7 +2454,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
pub(crate) fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
pub(crate) fn LLVMRustModuleCost(M: &Module) -> u64;
pub(crate) fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
pub(crate) fn LLVMRustModuleInstructionStats(M: &Module) -> u64;
pub(crate) fn LLVMRustThinLTOBufferCreate(
M: &Module,

View file

@ -1572,16 +1572,8 @@ extern "C" uint64_t LLVMRustModuleCost(LLVMModuleRef M) {
return std::distance(std::begin(f), std::end(f));
}
extern "C" void LLVMRustModuleInstructionStats(LLVMModuleRef M,
RustStringRef Str) {
auto OS = RawRustStringOstream(Str);
auto JOS = llvm::json::OStream(OS);
auto Module = unwrap(M);
JOS.object([&] {
JOS.attribute("module", Module->getName());
JOS.attribute("total", Module->getInstructionCount());
});
extern "C" uint64_t LLVMRustModuleInstructionStats(LLVMModuleRef M) {
return unwrap(M)->getInstructionCount();
}
// Transfers ownership of DiagnosticHandler unique_ptr to the caller.