Skip to content

Commit 7eadf83

Browse files
committed
Auto merge of #150456 - dianqk:codegen-llvm-serde, r=mati865
Removes the serde dependency in rustc_codegen_llvm
2 parents 23d01cd + fe075ad commit 7eadf83

5 files changed

Lines changed: 7 additions & 30 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,8 +3638,6 @@ dependencies = [
36383638
"rustc_span",
36393639
"rustc_symbol_mangling",
36403640
"rustc_target",
3641-
"serde",
3642-
"serde_json",
36433641
"smallvec",
36443642
"tracing",
36453643
]

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ rustc_session = { path = "../rustc_session" }
3838
rustc_span = { path = "../rustc_span" }
3939
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
4040
rustc_target = { path = "../rustc_target" }
41-
serde = { version = "1", features = ["derive"] }
42-
serde_json = "1"
4341
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4442
tracing = "0.1"
4543
# tidy-alphabetical-end

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ pub(crate) fn codegen(
11361136
EmitObj::None => {}
11371137
}
11381138

1139-
record_llvm_cgu_instructions_stats(&cgcx.prof, llmod);
1139+
record_llvm_cgu_instructions_stats(&cgcx.prof, &module.name, llmod);
11401140
}
11411141

11421142
// `.dwo` files are only emitted if:
@@ -1343,22 +1343,11 @@ fn record_artifact_size(
13431343
}
13441344
}
13451345

1346-
fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Module) {
1346+
fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, name: &str, llmod: &llvm::Module) {
13471347
if !prof.enabled() {
13481348
return;
13491349
}
13501350

1351-
let raw_stats =
1352-
llvm::build_string(|s| unsafe { llvm::LLVMRustModuleInstructionStats(llmod, s) })
1353-
.expect("cannot get module instruction stats");
1354-
1355-
#[derive(serde::Deserialize)]
1356-
struct InstructionsStats {
1357-
module: String,
1358-
total: u64,
1359-
}
1360-
1361-
let InstructionsStats { module, total } =
1362-
serde_json::from_str(&raw_stats).expect("cannot parse llvm cgu instructions stats");
1363-
prof.artifact_size("cgu_instructions", module, total);
1351+
let total = unsafe { llvm::LLVMRustModuleInstructionStats(llmod) };
1352+
prof.artifact_size("cgu_instructions", name, total);
13641353
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ unsafe extern "C" {
24542454
pub(crate) fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
24552455
pub(crate) fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
24562456
pub(crate) fn LLVMRustModuleCost(M: &Module) -> u64;
2457-
pub(crate) fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
2457+
pub(crate) fn LLVMRustModuleInstructionStats(M: &Module) -> u64;
24582458

24592459
pub(crate) fn LLVMRustThinLTOBufferCreate(
24602460
M: &Module,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,16 +1572,8 @@ extern "C" uint64_t LLVMRustModuleCost(LLVMModuleRef M) {
15721572
return std::distance(std::begin(f), std::end(f));
15731573
}
15741574

1575-
extern "C" void LLVMRustModuleInstructionStats(LLVMModuleRef M,
1576-
RustStringRef Str) {
1577-
auto OS = RawRustStringOstream(Str);
1578-
auto JOS = llvm::json::OStream(OS);
1579-
auto Module = unwrap(M);
1580-
1581-
JOS.object([&] {
1582-
JOS.attribute("module", Module->getName());
1583-
JOS.attribute("total", Module->getInstructionCount());
1584-
});
1575+
extern "C" uint64_t LLVMRustModuleInstructionStats(LLVMModuleRef M) {
1576+
return unwrap(M)->getInstructionCount();
15851577
}
15861578

15871579
// Transfers ownership of DiagnosticHandler unique_ptr to the caller.

0 commit comments

Comments
 (0)