Skip to content

Commit 4ba09ab

Browse files
denismerigouxeddyb
authored andcommitted
Added compile codegen to backend trait
1 parent 6819e6e commit 4ba09ab

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use rustc_mir::monomorphize::item::DefPathBasedNames;
5656
use common::{self, IntPredicate, RealPredicate, TypeKind};
5757
use meth;
5858
use mir;
59+
use context::CodegenCx;
5960
use monomorphize::Instance;
6061
use monomorphize::partitioning::{CodegenUnit, CodegenUnitExt};
6162
use rustc_codegen_utils::symbol_names_test;
@@ -712,7 +713,7 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
712713
}
713714
}
714715

715-
pub fn codegen_crate<'a, 'tcx, B: BackendMethods>(
716+
pub fn codegen_crate<B: BackendMethods>(
716717
backend: B,
717718
tcx: TyCtxt<'a, 'tcx, 'tcx>,
718719
rx: mpsc::Receiver<Box<dyn Any + Send>>
@@ -858,7 +859,7 @@ pub fn codegen_crate<'a, 'tcx, B: BackendMethods>(
858859
&format!("codegen {}", cgu.name()))
859860
});
860861
let start_time = Instant::now();
861-
let stats = compile_codegen_unit(tcx, *cgu.name());
862+
let stats = backend.compile_codegen_unit(tcx, *cgu.name());
862863
all_stats.extend(stats);
863864
total_codegen_time += start_time.elapsed();
864865
false
@@ -1066,7 +1067,7 @@ impl CrateInfo {
10661067
}
10671068
}
10681069

1069-
fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
1070+
pub fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
10701071
cgu_name: InternedString)
10711072
-> Stats {
10721073
let start_time = Instant::now();
@@ -1098,7 +1099,7 @@ fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
10981099
// Instantiate monomorphizations without filling out definitions yet...
10991100
let llvm_module = backend.new_metadata(tcx.sess, &cgu_name.as_str());
11001101
let stats = {
1101-
let cx = backend.new_codegen_context(tcx, cgu, &llvm_module);
1102+
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
11021103
let mono_items = cx.codegen_unit
11031104
.items_in_deterministic_order(cx.tcx);
11041105
for &(mono_item, (linkage, visibility)) in &mono_items {

src/librustc_codegen_llvm/interfaces/backend.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
1212
use rustc::ty::Ty;
1313

14-
use super::{CodegenMethods, CodegenObject};
15-
use monomorphize::partitioning::CodegenUnit;
14+
use super::CodegenObject;
1615
use rustc::middle::allocator::AllocatorKind;
1716
use rustc::middle::cstore::EncodedMetadata;
17+
use rustc::mir::mono::Stats;
1818
use rustc::session::Session;
1919
use rustc::ty::TyCtxt;
2020
use std::any::Any;
2121
use std::sync::mpsc::Receiver;
22-
use std::sync::Arc;
22+
use syntax_pos::symbol::InternedString;
2323
use time_graph::TimeGraph;
2424
use ModuleCodegen;
2525

@@ -71,15 +71,9 @@ pub trait BackendMethods {
7171
fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
7272
fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
7373
fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
74-
}
75-
76-
pub trait BackendCodegenCxMethods<'a, 'tcx: 'a>: BackendMethods {
77-
type CodegenCx: CodegenMethods<'tcx>;
78-
79-
fn new_codegen_context(
74+
fn compile_codegen_unit<'a, 'tcx: 'a>(
8075
&self,
8176
tcx: TyCtxt<'a, 'tcx, 'tcx>,
82-
codegen_unit: Arc<CodegenUnit<'tcx>>,
83-
llvm_module: &'a Self::Module,
84-
) -> Self::CodegenCx;
77+
cgu_name: InternedString,
78+
) -> Stats;
8579
}

src/librustc_codegen_llvm/interfaces/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod type_;
2222

2323
pub use self::abi::{AbiBuilderMethods, AbiMethods};
2424
pub use self::asm::{AsmBuilderMethods, AsmMethods};
25-
pub use self::backend::{Backend, BackendCodegenCxMethods, BackendMethods, BackendTypes};
25+
pub use self::backend::{Backend, BackendMethods, BackendTypes};
2626
pub use self::builder::BuilderMethods;
2727
pub use self::consts::ConstMethods;
2828
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};

src/librustc_codegen_llvm/lib.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ use interfaces::*;
7272
use time_graph::TimeGraph;
7373
use std::sync::mpsc::Receiver;
7474
use back::write::{self, OngoingCodegen};
75-
use context::CodegenCx;
76-
use monomorphize::partitioning::CodegenUnit;
75+
use syntax_pos::symbol::InternedString;
76+
use rustc::mir::mono::Stats;
7777

7878
pub use llvm_util::target_features;
7979
use std::any::Any;
80-
use std::sync::Arc;
8180
use std::sync::mpsc;
8281
use rustc_data_structures::sync::Lrc;
8382

@@ -188,18 +187,12 @@ impl BackendMethods for LlvmCodegenBackend {
188187
fn wait_for_signal_to_codegen_item(&self, codegen: &OngoingCodegen) {
189188
codegen.wait_for_signal_to_codegen_item()
190189
}
191-
}
192-
193-
impl<'a, 'tcx: 'a> BackendCodegenCxMethods<'a, 'tcx> for LlvmCodegenBackend {
194-
type CodegenCx = CodegenCx<'a, 'tcx>;
195-
196-
fn new_codegen_context(
190+
fn compile_codegen_unit<'a, 'tcx: 'a>(
197191
&self,
198192
tcx: TyCtxt<'a, 'tcx, 'tcx>,
199-
codegen_unit: Arc<CodegenUnit<'tcx>>,
200-
llvm_module: &'a ModuleLlvm
201-
) -> CodegenCx<'a, 'tcx> {
202-
CodegenCx::new(tcx, codegen_unit, llvm_module)
193+
cgu_name: InternedString,
194+
) -> Stats {
195+
base::compile_codegen_unit(tcx, cgu_name)
203196
}
204197
}
205198

0 commit comments

Comments
 (0)