Skip to content

Commit ccfc22b

Browse files
authored
Rollup merge of #91868 - tmiasko:llvm-time-trace-out, r=oli-obk
Use `OutputFilenames` to generate output file for `-Zllvm-time-trace` The resulting profile will include the crate name and will be stored in the `--out-dir` directory. This implementation makes it convenient to use LLVM time trace together with cargo, in the contrast to the previous implementation which would overwrite profiles or store them in `.cargo/registry/..`.
2 parents d6c802e + 3f2a1c9 commit ccfc22b

File tree

7 files changed

+16
-6
lines changed

7 files changed

+16
-6
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
205205
&self,
206206
ongoing_codegen: Box<dyn Any>,
207207
_sess: &Session,
208+
_outputs: &OutputFilenames,
208209
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
209210
Ok(*ongoing_codegen
210211
.downcast::<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>)>()

compiler/rustc_codegen_gcc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl CodegenBackend for GccCodegenBackend {
9696
Box::new(res)
9797
}
9898

99-
fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
99+
fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
100100
let (codegen_results, work_products) = ongoing_codegen
101101
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>()
102102
.expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>")

compiler/rustc_codegen_llvm/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ impl CodegenBackend for LlvmCodegenBackend {
339339
&self,
340340
ongoing_codegen: Box<dyn Any>,
341341
sess: &Session,
342+
outputs: &OutputFilenames,
342343
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
343344
let (codegen_results, work_products) = ongoing_codegen
344345
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>()
@@ -347,7 +348,8 @@ impl CodegenBackend for LlvmCodegenBackend {
347348

348349
sess.time("llvm_dump_timing_file", || {
349350
if sess.opts.debugging_opts.llvm_time_trace {
350-
llvm_util::time_trace_profiler_finish("llvm_timings.json");
351+
let file_name = outputs.with_extension("llvm_timings.json");
352+
llvm_util::time_trace_profiler_finish(&file_name);
351353
}
352354
});
353355

compiler/rustc_codegen_llvm/src/llvm_util.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use libc::c_int;
44
use libloading::Library;
55
use rustc_codegen_ssa::target_features::supported_target_features;
66
use rustc_data_structures::fx::FxHashSet;
7+
use rustc_fs_util::path_to_c_string;
78
use rustc_middle::bug;
89
use rustc_session::config::PrintRequest;
910
use rustc_session::Session;
@@ -13,6 +14,7 @@ use std::ffi::{CStr, CString};
1314
use tracing::debug;
1415

1516
use std::mem;
17+
use std::path::Path;
1618
use std::ptr;
1719
use std::slice;
1820
use std::str;
@@ -134,9 +136,9 @@ unsafe fn configure_llvm(sess: &Session) {
134136
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr());
135137
}
136138

137-
pub fn time_trace_profiler_finish(file_name: &str) {
139+
pub fn time_trace_profiler_finish(file_name: &Path) {
138140
unsafe {
139-
let file_name = CString::new(file_name).unwrap();
141+
let file_name = path_to_c_string(file_name);
140142
llvm::LLVMTimeTraceProfilerFinish(file_name.as_ptr());
141143
}
142144
}

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub trait CodegenBackend {
9797
&self,
9898
ongoing_codegen: Box<dyn Any>,
9999
sess: &Session,
100+
outputs: &OutputFilenames,
100101
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported>;
101102

102103
/// This is called on the returned `Box<dyn Any>` from `join_codegen`

compiler/rustc_interface/src/queries.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,11 @@ pub struct Linker {
335335

336336
impl Linker {
337337
pub fn link(self) -> Result<()> {
338-
let (codegen_results, work_products) =
339-
self.codegen_backend.join_codegen(self.ongoing_codegen, &self.sess)?;
338+
let (codegen_results, work_products) = self.codegen_backend.join_codegen(
339+
self.ongoing_codegen,
340+
&self.sess,
341+
&self.prepare_outputs,
342+
)?;
340343

341344
self.sess.compile_status()?;
342345

src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl CodegenBackend for TheBackend {
4646
&self,
4747
ongoing_codegen: Box<dyn Any>,
4848
_sess: &Session,
49+
_outputs: &OutputFilenames,
4950
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
5051
let codegen_results = ongoing_codegen
5152
.downcast::<CodegenResults>()

0 commit comments

Comments
 (0)