Skip to content

Commit

Permalink
Rollup merge of #79662 - bjorn3:move_more_code_out_of_codegen_backend…
Browse files Browse the repository at this point in the history
…, r=oli-obk

Move some more code out of CodegenBackend::{codegen_crate,link}

Kind of a follow up to #77795
  • Loading branch information
Dylan-DPC authored Dec 28, 2020
2 parents aef92d4 + 3a3a23f commit 98d80bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
24 changes: 11 additions & 13 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,19 @@ impl CodegenBackend for LlvmCodegenBackend {
codegen_results: CodegenResults,
outputs: &OutputFilenames,
) -> Result<(), ErrorReported> {
use crate::back::archive::LlvmArchiveBuilder;
use rustc_codegen_ssa::back::link::link_binary;

// Run the linker on any artifacts that resulted from the LLVM run.
// This should produce either a finished executable or library.
sess.time("link_crate", || {
use crate::back::archive::LlvmArchiveBuilder;
use rustc_codegen_ssa::back::link::link_binary;

let target_cpu = crate::llvm_util::target_cpu(sess);
link_binary::<LlvmArchiveBuilder<'_>>(
sess,
&codegen_results,
outputs,
&codegen_results.crate_name.as_str(),
target_cpu,
);
});
let target_cpu = crate::llvm_util::target_cpu(sess);
link_binary::<LlvmArchiveBuilder<'_>>(
sess,
&codegen_results,
outputs,
&codegen_results.crate_name.as_str(),
target_cpu,
);

Ok(())
}
Expand Down
21 changes: 0 additions & 21 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{self, EntryFnType};
use rustc_session::utils::NativeLibKind;
use rustc_session::Session;
use rustc_symbol_mangling::test as symbol_names_test;
use rustc_target::abi::{Align, LayoutOf, VariantIdx};

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

ongoing_codegen.codegen_finished(tcx);

finalize_tcx(tcx);

ongoing_codegen.check_for_errors(tcx.sess);

return ongoing_codegen;
Expand Down Expand Up @@ -688,14 +685,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
total_codegen_time.into_inner(),
);

rustc_incremental::assert_module_sources::assert_module_sources(tcx);

symbol_names_test::report_symbol_names(tcx);

ongoing_codegen.check_for_errors(tcx.sess);

finalize_tcx(tcx);

ongoing_codegen.into_inner()
}

Expand Down Expand Up @@ -746,18 +737,6 @@ impl<B: ExtraBackendMethods> Drop for AbortCodegenOnDrop<B> {
}
}

fn finalize_tcx(tcx: TyCtxt<'_>) {
tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx));
tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx));

// We assume that no queries are run past here. If there are new queries
// after this point, they'll show up as "<unknown>" in self-profiling data.
{
let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings");
tcx.alloc_self_profile_query_strings();
}
}

impl CrateInfo {
pub fn new(tcx: TyCtxt<'_>) -> CrateInfo {
let mut info = CrateInfo {
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,23 @@ pub fn start_codegen<'tcx>(
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
});

// Don't run these test assertions when not doing codegen. Compiletest tries to build
// build-fail tests in check mode first and expects it to not give an error in that case.
if tcx.sess.opts.output_types.should_codegen() {
rustc_incremental::assert_module_sources::assert_module_sources(tcx);
rustc_symbol_mangling::test::report_symbol_names(tcx);
}

tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx));
tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx));

// We assume that no queries are run past here. If there are new queries
// after this point, they'll show up as "<unknown>" in self-profiling data.
{
let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings");
tcx.alloc_self_profile_query_strings();
}

info!("Post-codegen\n{:?}", tcx.debug_stats());

if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ impl Linker {
return Ok(());
}

let _timer = sess.prof.verbose_generic_activity("link_crate");
self.codegen_backend.link(&self.sess, codegen_results, &self.prepare_outputs)
}
}
Expand Down

0 comments on commit 98d80bd

Please sign in to comment.