Skip to content

Commit 98d80bd

Browse files
authored
Rollup merge of #79662 - bjorn3:move_more_code_out_of_codegen_backend, r=oli-obk
Move some more code out of CodegenBackend::{codegen_crate,link} Kind of a follow up to #77795
2 parents aef92d4 + 3a3a23f commit 98d80bd

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,19 @@ impl CodegenBackend for LlvmCodegenBackend {
298298
codegen_results: CodegenResults,
299299
outputs: &OutputFilenames,
300300
) -> Result<(), ErrorReported> {
301+
use crate::back::archive::LlvmArchiveBuilder;
302+
use rustc_codegen_ssa::back::link::link_binary;
303+
301304
// Run the linker on any artifacts that resulted from the LLVM run.
302305
// This should produce either a finished executable or library.
303-
sess.time("link_crate", || {
304-
use crate::back::archive::LlvmArchiveBuilder;
305-
use rustc_codegen_ssa::back::link::link_binary;
306-
307-
let target_cpu = crate::llvm_util::target_cpu(sess);
308-
link_binary::<LlvmArchiveBuilder<'_>>(
309-
sess,
310-
&codegen_results,
311-
outputs,
312-
&codegen_results.crate_name.as_str(),
313-
target_cpu,
314-
);
315-
});
306+
let target_cpu = crate::llvm_util::target_cpu(sess);
307+
link_binary::<LlvmArchiveBuilder<'_>>(
308+
sess,
309+
&codegen_results,
310+
outputs,
311+
&codegen_results.crate_name.as_str(),
312+
target_cpu,
313+
);
316314

317315
Ok(())
318316
}

compiler/rustc_codegen_ssa/src/base.rs

-21
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use rustc_session::cgu_reuse_tracker::CguReuse;
4646
use rustc_session::config::{self, EntryFnType};
4747
use rustc_session::utils::NativeLibKind;
4848
use rustc_session::Session;
49-
use rustc_symbol_mangling::test as symbol_names_test;
5049
use rustc_target::abi::{Align, LayoutOf, VariantIdx};
5150

5251
use std::cmp;
@@ -486,8 +485,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
486485

487486
ongoing_codegen.codegen_finished(tcx);
488487

489-
finalize_tcx(tcx);
490-
491488
ongoing_codegen.check_for_errors(tcx.sess);
492489

493490
return ongoing_codegen;
@@ -688,14 +685,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
688685
total_codegen_time.into_inner(),
689686
);
690687

691-
rustc_incremental::assert_module_sources::assert_module_sources(tcx);
692-
693-
symbol_names_test::report_symbol_names(tcx);
694-
695688
ongoing_codegen.check_for_errors(tcx.sess);
696689

697-
finalize_tcx(tcx);
698-
699690
ongoing_codegen.into_inner()
700691
}
701692

@@ -746,18 +737,6 @@ impl<B: ExtraBackendMethods> Drop for AbortCodegenOnDrop<B> {
746737
}
747738
}
748739

749-
fn finalize_tcx(tcx: TyCtxt<'_>) {
750-
tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx));
751-
tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx));
752-
753-
// We assume that no queries are run past here. If there are new queries
754-
// after this point, they'll show up as "<unknown>" in self-profiling data.
755-
{
756-
let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings");
757-
tcx.alloc_self_profile_query_strings();
758-
}
759-
}
760-
761740
impl CrateInfo {
762741
pub fn new(tcx: TyCtxt<'_>) -> CrateInfo {
763742
let mut info = CrateInfo {

compiler/rustc_interface/src/passes.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,23 @@ pub fn start_codegen<'tcx>(
10131013
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
10141014
});
10151015

1016+
// Don't run these test assertions when not doing codegen. Compiletest tries to build
1017+
// build-fail tests in check mode first and expects it to not give an error in that case.
1018+
if tcx.sess.opts.output_types.should_codegen() {
1019+
rustc_incremental::assert_module_sources::assert_module_sources(tcx);
1020+
rustc_symbol_mangling::test::report_symbol_names(tcx);
1021+
}
1022+
1023+
tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx));
1024+
tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx));
1025+
1026+
// We assume that no queries are run past here. If there are new queries
1027+
// after this point, they'll show up as "<unknown>" in self-profiling data.
1028+
{
1029+
let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings");
1030+
tcx.alloc_self_profile_query_strings();
1031+
}
1032+
10161033
info!("Post-codegen\n{:?}", tcx.debug_stats());
10171034

10181035
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {

compiler/rustc_interface/src/queries.rs

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ impl Linker {
403403
return Ok(());
404404
}
405405

406+
let _timer = sess.prof.verbose_generic_activity("link_crate");
406407
self.codegen_backend.link(&self.sess, codegen_results, &self.prepare_outputs)
407408
}
408409
}

0 commit comments

Comments
 (0)