Skip to content

Commit b7ca331

Browse files
committed
Added compile codegen to backend trait
1 parent a478ce6 commit b7ca331

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use rustc_mir::monomorphize::item::DefPathBasedNames;
5757
use common::{self, IntPredicate, RealPredicate, TypeKind};
5858
use meth;
5959
use mir;
60+
use context::CodegenCx;
6061
use monomorphize::Instance;
6162
use monomorphize::partitioning::{CodegenUnit, CodegenUnitExt};
6263
use rustc_codegen_utils::symbol_names_test;
@@ -719,7 +720,7 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
719720
}
720721
}
721722

722-
pub fn codegen_crate<'a, 'll: 'a, 'tcx: 'll, B : BackendMethods<'a, 'll, 'tcx>>(
723+
pub fn codegen_crate<B : BackendMethods>(
723724
backend: B,
724725
tcx: TyCtxt<'ll, 'tcx, 'tcx>,
725726
rx: mpsc::Receiver<Box<dyn Any + Send>>
@@ -878,7 +879,7 @@ pub fn codegen_crate<'a, 'll: 'a, 'tcx: 'll, B : BackendMethods<'a, 'll, 'tcx>>(
878879
&format!("codegen {}", cgu.name()))
879880
});
880881
let start_time = Instant::now();
881-
let stats = compile_codegen_unit(tcx, *cgu.name());
882+
let stats = backend.compile_codegen_unit(tcx, *cgu.name());
882883
all_stats.extend(stats);
883884
total_codegen_time += start_time.elapsed();
884885
false
@@ -1170,7 +1171,7 @@ fn is_codegened_item(tcx: TyCtxt, id: DefId) -> bool {
11701171
all_mono_items.contains(&id)
11711172
}
11721173

1173-
fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
1174+
pub fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
11741175
cgu_name: InternedString)
11751176
-> Stats {
11761177
let start_time = Instant::now();
@@ -1202,7 +1203,7 @@ fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
12021203
// Instantiate monomorphizations without filling out definitions yet...
12031204
let llvm_module = backend.new_metadata(tcx.sess, &cgu_name.as_str());
12041205
let stats = {
1205-
let cx = backend.new_codegen_context(tcx, cgu, &llvm_module);
1206+
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
12061207
let mono_items = cx.codegen_unit
12071208
.items_in_deterministic_order(cx.tcx);
12081209
for &(mono_item, (linkage, visibility)) in &mono_items {

src/librustc_codegen_llvm/interfaces/backend.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
// except according to those terms.
1010

1111
use super::CodegenObject;
12-
use super::builder::{HasCodegen, BuilderMethods};
1312
use ModuleCodegen;
1413
use rustc::session::Session;
1514
use rustc::middle::cstore::EncodedMetadata;
1615
use rustc::middle::allocator::AllocatorKind;
17-
use monomorphize::partitioning::CodegenUnit;
1816
use rustc::ty::TyCtxt;
17+
use rustc::mir::mono::Stats;
18+
use syntax_pos::symbol::InternedString;
1919
use time_graph::TimeGraph;
2020
use std::sync::mpsc::Receiver;
2121
use std::any::Any;
22-
use std::sync::Arc;
2322

2423
pub trait Backend<'ll> {
2524
type Value : 'll + CodegenObject;
@@ -28,10 +27,9 @@ pub trait Backend<'ll> {
2827
type Context;
2928
}
3029

31-
pub trait BackendMethods<'a, 'll: 'a, 'tcx: 'll> {
30+
pub trait BackendMethods {
3231
type Metadata;
3332
type OngoingCodegen;
34-
type Builder : BuilderMethods<'a, 'll, 'tcx>;
3533

3634
fn thin_lto_available(&self) -> bool;
3735
fn pgo_available(&self) -> bool;
@@ -60,10 +58,9 @@ pub trait BackendMethods<'a, 'll: 'a, 'tcx: 'll> {
6058
fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
6159
fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
6260
fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
63-
fn new_codegen_context(
61+
fn compile_codegen_unit<'ll, 'tcx: 'll>(
6462
&self,
6563
tcx: TyCtxt<'ll, 'tcx, 'tcx>,
66-
codegen_unit: Arc<CodegenUnit<'tcx>>,
67-
llvm_module: &'ll Self::Metadata
68-
) -> <Self::Builder as HasCodegen<'a, 'll, 'tcx>>::CodegenCx;
64+
cgu_name: InternedString
65+
) -> Stats ;
6966
}

src/librustc_codegen_llvm/lib.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ use interfaces::*;
7272
use time_graph::TimeGraph;
7373
use std::sync::mpsc::Receiver;
7474
use back::write::{self, OngoingCodegen};
75-
use builder::Builder;
76-
use value::Value;
77-
use context::CodegenCx;
78-
use monomorphize::partitioning::CodegenUnit;
75+
use syntax_pos::symbol::InternedString;
76+
use rustc::mir::mono::Stats;
7977

8078
pub use llvm_util::target_features;
8179
use std::any::Any;
@@ -142,10 +140,9 @@ mod value;
142140

143141
pub struct LlvmCodegenBackend(());
144142

145-
impl<'a, 'll: 'a, 'tcx: 'll> BackendMethods<'a, 'll, 'tcx> for LlvmCodegenBackend {
143+
impl BackendMethods for LlvmCodegenBackend {
146144
type Metadata = ModuleLlvm;
147145
type OngoingCodegen = OngoingCodegen;
148-
type Builder = Builder<'a, 'll, 'tcx, &'ll Value>;
149146

150147
fn thin_lto_available(&self) -> bool {
151148
unsafe { !llvm::LLVMRustThinLTOAvailable() }
@@ -193,13 +190,12 @@ impl<'a, 'll: 'a, 'tcx: 'll> BackendMethods<'a, 'll, 'tcx> for LlvmCodegenBacken
193190
fn wait_for_signal_to_codegen_item(&self, codegen: &OngoingCodegen) {
194191
codegen.wait_for_signal_to_codegen_item()
195192
}
196-
fn new_codegen_context(
193+
fn compile_codegen_unit<'ll, 'tcx: 'll>(
197194
&self,
198195
tcx: TyCtxt<'ll, 'tcx, 'tcx>,
199-
codegen_unit: Arc<CodegenUnit<'tcx>>,
200-
llvm_module: &'ll ModuleLlvm
201-
) -> CodegenCx<'ll, 'tcx, &'ll Value> {
202-
CodegenCx::new(tcx, codegen_unit, llvm_module)
196+
cgu_name: InternedString
197+
) -> Stats {
198+
base::compile_codegen_unit(tcx, cgu_name)
203199
}
204200
}
205201

0 commit comments

Comments
 (0)