Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4101,6 +4101,7 @@ dependencies = [
name = "rustc_interface"
version = "0.0.0"
dependencies = [
"rand 0.9.2",
"rustc_abi",
"rustc_ast",
"rustc_ast_lowering",
Expand Down Expand Up @@ -4602,7 +4603,6 @@ version = "0.0.0"
dependencies = [
"getopts",
"libc",
"rand 0.9.2",
"rustc_abi",
"rustc_ast",
"rustc_data_structures",
Expand Down
22 changes: 4 additions & 18 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {

fn emit_cgu(
output_filenames: &OutputFilenames,
invocation_temp: Option<&str>,
prof: &SelfProfilerRef,
name: String,
module: UnwindModule<ObjectModule>,
Expand All @@ -166,7 +165,6 @@ fn emit_cgu(

let module_regular = emit_module(
output_filenames,
invocation_temp,
prof,
product.object,
ModuleKind::Regular,
Expand All @@ -192,7 +190,6 @@ fn emit_cgu(

fn emit_module(
output_filenames: &OutputFilenames,
invocation_temp: Option<&str>,
prof: &SelfProfilerRef,
mut object: cranelift_object::object::write::Object<'_>,
kind: ModuleKind,
Expand All @@ -211,7 +208,7 @@ fn emit_module(
object.set_section_data(comment_section, producer, 1);
}

let tmp_file = output_filenames.temp_path_for_cgu(OutputType::Object, &name, invocation_temp);
let tmp_file = output_filenames.temp_path_for_cgu(OutputType::Object, &name);
let file = match File::create(&tmp_file) {
Ok(file) => file,
Err(err) => return Err(format!("error creating object file: {}", err)),
Expand Down Expand Up @@ -251,11 +248,8 @@ fn reuse_workproduct_for_cgu(
cgu: &CodegenUnit<'_>,
) -> Result<ModuleCodegenResult, String> {
let work_product = cgu.previous_work_product(tcx);
let obj_out_regular = tcx.output_filenames(()).temp_path_for_cgu(
OutputType::Object,
cgu.name().as_str(),
tcx.sess.invocation_temp.as_deref(),
);
let obj_out_regular =
tcx.output_filenames(()).temp_path_for_cgu(OutputType::Object, cgu.name().as_str());
let source_file_regular = rustc_incremental::in_incr_comp_dir_sess(
tcx.sess,
work_product.saved_files.get("o").expect("no saved object file in work product"),
Expand Down Expand Up @@ -394,7 +388,6 @@ fn module_codegen(
let producer = crate::debuginfo::producer(tcx.sess);

let profiler = tcx.prof.clone();
let invocation_temp = tcx.sess.invocation_temp.clone();
let output_filenames = tcx.output_filenames(()).clone();
let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess);

Expand All @@ -421,19 +414,13 @@ fn module_codegen(

let global_asm_object_file =
profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
crate::global_asm::compile_global_asm(
&global_asm_config,
&cgu_name,
global_asm,
invocation_temp.as_deref(),
)
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, global_asm)
})?;

let codegen_result =
profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
emit_cgu(
&global_asm_config.output_filenames,
invocation_temp.as_deref(),
&profiler,
cgu_name,
module,
Expand All @@ -456,7 +443,6 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {

match emit_module(
tcx.output_filenames(()),
tcx.sess.invocation_temp.as_deref(),
&tcx.sess.prof,
product.object,
ModuleKind::Allocator,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_cranelift/src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ fn create_jit_module(
(jit_module, cx)
}

pub(crate) fn run_jit(tcx: TyCtxt<'_>, crate_info: &CrateInfo, jit_args: Vec<String>) -> ! {
pub(crate) fn run_jit(tcx: TyCtxt<'_>, target_cpu: String, jit_args: Vec<String>) -> ! {
if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
tcx.dcx().fatal("can't jit non-executable crate");
}

let output_filenames = tcx.output_filenames(());
let crate_info = CrateInfo::new(tcx, target_cpu);
let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess);
let (mut jit_module, mut debug_context) = create_jit_module(tcx, crate_info);
let (mut jit_module, mut debug_context) = create_jit_module(tcx, &crate_info);
let mut cached_context = Context::new();

let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_cranelift/src/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ pub(crate) fn compile_global_asm(
config: &GlobalAsmConfig,
cgu_name: &str,
global_asm: String,
invocation_temp: Option<&str>,
) -> Result<Option<PathBuf>, String> {
if global_asm.is_empty() {
return Ok(None);
Expand All @@ -200,7 +199,7 @@ pub(crate) fn compile_global_asm(
global_asm.push('\n');

let global_asm_object_file = add_file_stem_postfix(
config.output_filenames.temp_path_for_cgu(OutputType::Object, cgu_name, invocation_temp),
config.output_filenames.temp_path_for_cgu(OutputType::Object, cgu_name),
".asm",
);

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ impl CodegenBackend for CraneliftCodegenBackend {
.to_owned()
}

fn codegen_crate(&self, tcx: TyCtxt<'_>, _crate_info: &CrateInfo) -> Box<dyn Any> {
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
info!("codegen crate {}", tcx.crate_name(LOCAL_CRATE));
let config = self.config.get().unwrap();
if config.jit_mode {
#[cfg(feature = "jit")]
driver::jit::run_jit(tcx, _crate_info, config.jit_args.clone());
driver::jit::run_jit(tcx, self.target_cpu(tcx.sess), config.jit_args.clone());

#[cfg(not(feature = "jit"))]
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
Expand All @@ -228,6 +228,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
_crate_info: &CrateInfo,
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(sess, outputs)
}
Expand Down
26 changes: 5 additions & 21 deletions compiler/rustc_codegen_gcc/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ pub(crate) fn codegen(
let lto_mode = module.module_llvm.lto_mode;
let lto_supported = module.module_llvm.lto_supported;

let bc_out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::Bitcode,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let obj_out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::Object,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let bc_out = cgcx.output_filenames.temp_path_for_cgu(OutputType::Bitcode, &module.name);
let obj_out = cgcx.output_filenames.temp_path_for_cgu(OutputType::Object, &module.name);

if config.bitcode_needed() {
let _timer =
Expand Down Expand Up @@ -82,22 +74,15 @@ pub(crate) fn codegen(
}

if config.emit_ir {
let out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::LlvmAssembly,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let out =
cgcx.output_filenames.temp_path_for_cgu(OutputType::LlvmAssembly, &module.name);
std::fs::write(out, "").expect("write file");
}

if config.emit_asm {
let _timer =
prof.generic_activity_with_arg("GCC_module_codegen_emit_asm", &*module.name);
let path = cgcx.output_filenames.temp_path_for_cgu(
OutputType::Assembly,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let path = cgcx.output_filenames.temp_path_for_cgu(OutputType::Assembly, &module.name);
context.compile_to_file(OutputKind::Assembler, path.to_str().expect("path to str"));
}

Expand Down Expand Up @@ -215,7 +200,6 @@ pub(crate) fn codegen(
config.emit_asm,
config.emit_ir,
&cgcx.output_filenames,
cgcx.invocation_temp.as_deref(),
)
}

Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,21 @@ impl CodegenBackend for GccCodegenBackend {
target_cpu(sess).to_owned()
}

fn codegen_crate(&self, tcx: TyCtxt<'_>, crate_info: &CrateInfo) -> Box<dyn Any> {
Box::new(codegen_crate(self.clone(), tcx, crate_info))
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
Box::new(codegen_crate(self.clone(), tcx))
}

fn join_codegen(
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
_outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>()
.expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>")
.join(sess)
.join(sess, crate_info)
}

fn target_config(&self, sess: &Session) -> TargetConfig {
Expand Down
51 changes: 11 additions & 40 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,13 @@ pub(crate) fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTar
tcx.sess.split_debuginfo(),
tcx.sess.opts.unstable_opts.split_dwarf_kind,
mod_name,
tcx.sess.invocation_temp.as_deref(),
)
} else {
None
};

let output_obj_file = Some(tcx.output_filenames(()).temp_path_for_cgu(
OutputType::Object,
mod_name,
tcx.sess.invocation_temp.as_deref(),
));
let output_obj_file =
Some(tcx.output_filenames(()).temp_path_for_cgu(OutputType::Object, mod_name));
let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file };

target_machine_factory(
Expand Down Expand Up @@ -322,11 +318,7 @@ pub(crate) fn save_temp_bitcode(
return;
}
let ext = format!("{name}.bc");
let path = cgcx.output_filenames.temp_path_ext_for_cgu(
&ext,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let path = cgcx.output_filenames.temp_path_ext_for_cgu(&ext, &module.name);
write_bitcode_to_file(&module.module_llvm, &path)
}

Expand Down Expand Up @@ -949,11 +941,8 @@ pub(crate) fn optimize(
if let Some(thin_lto_buffer) = thin_lto_buffer {
let thin_lto_buffer = thin_lto_buffer.unwrap();
module.thin_lto_buffer = Some(thin_lto_buffer.data().to_vec());
let bc_summary_out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::ThinLinkBitcode,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let bc_summary_out =
cgcx.output_filenames.temp_path_for_cgu(OutputType::ThinLinkBitcode, &module.name);
if let Some(thin_lto_summary_buffer) = thin_lto_summary_buffer
&& let Some(thin_link_bitcode_filename) = bc_summary_out.file_name()
{
Expand Down Expand Up @@ -1008,16 +997,8 @@ pub(crate) fn codegen(
// copy it to the .o file, and delete the bitcode if it wasn't
// otherwise requested.

let bc_out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::Bitcode,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let obj_out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::Object,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let bc_out = cgcx.output_filenames.temp_path_for_cgu(OutputType::Bitcode, &module.name);
let obj_out = cgcx.output_filenames.temp_path_for_cgu(OutputType::Object, &module.name);

if config.bitcode_needed() {
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
Expand Down Expand Up @@ -1055,11 +1036,8 @@ pub(crate) fn codegen(
if config.emit_ir {
let _timer =
prof.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &*module.name);
let out = cgcx.output_filenames.temp_path_for_cgu(
OutputType::LlvmAssembly,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let out =
cgcx.output_filenames.temp_path_for_cgu(OutputType::LlvmAssembly, &module.name);
let out_c = path_to_c_string(&out);

extern "C" fn demangle_callback(
Expand Down Expand Up @@ -1103,11 +1081,7 @@ pub(crate) fn codegen(
if config.emit_asm {
let _timer =
prof.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &*module.name);
let path = cgcx.output_filenames.temp_path_for_cgu(
OutputType::Assembly,
&module.name,
cgcx.invocation_temp.as_deref(),
);
let path = cgcx.output_filenames.temp_path_for_cgu(OutputType::Assembly, &module.name);

// We can't use the same module for asm and object code output,
// because that triggers various errors like invalid IR or broken
Expand Down Expand Up @@ -1136,9 +1110,7 @@ pub(crate) fn codegen(
let _timer =
prof.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &*module.name);

let dwo_out = cgcx
.output_filenames
.temp_path_dwo_for_cgu(&module.name, cgcx.invocation_temp.as_deref());
let dwo_out = cgcx.output_filenames.temp_path_dwo_for_cgu(&module.name);
let dwo_out = match (cgcx.split_debuginfo, cgcx.split_dwarf_kind) {
// Don't change how DWARF is emitted when disabled.
(SplitDebuginfo::Off, _) => None,
Expand Down Expand Up @@ -1203,7 +1175,6 @@ pub(crate) fn codegen(
config.emit_asm,
config.emit_ir,
&cgcx.output_filenames,
cgcx.invocation_temp.as_deref(),
)
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
tcx.sess.split_debuginfo(),
tcx.sess.opts.unstable_opts.split_dwarf_kind,
codegen_unit_name,
tcx.sess.invocation_temp.as_deref(),
) {
// We get a path relative to the working directory from split_dwarf_path
Some(tcx.sess.source_map().path_mapping().to_real_filename(work_dir, f))
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,21 @@ impl CodegenBackend for LlvmCodegenBackend {
crate::llvm_util::target_cpu(sess).to_string()
}

fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>, crate_info: &CrateInfo) -> Box<dyn Any> {
Box::new(rustc_codegen_ssa::base::codegen_crate(LlvmCodegenBackend(()), tcx, crate_info))
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any> {
Box::new(rustc_codegen_ssa::base::codegen_crate(LlvmCodegenBackend(()), tcx))
}

fn join_codegen(
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
let (compiled_modules, work_products) = ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>()
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")
.join(sess);
.join(sess, crate_info);

if sess.opts.unstable_opts.llvm_time_trace {
sess.time("llvm_dump_timing_file", || {
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ pub fn link_binary(
let path = MaybeTempDir::new(tmpdir, sess.opts.cg.save_temps);

let crate_name = format!("{}", crate_info.local_crate_name);
let out_filename = output.file_for_writing(
outputs,
OutputType::Exe,
&crate_name,
sess.invocation_temp.as_deref(),
);
let out_filename = output.file_for_writing(outputs, OutputType::Exe, &crate_name);
match crate_type {
CrateType::Rlib => {
let _timer = sess.timer("link_rlib");
Expand Down
Loading
Loading