Skip to content

Commit 3f6f753

Browse files
committed
Added compile codegen to backend trait
1 parent 0c10974 commit 3f6f753

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
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::{self, PartitioningStrategy, 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>>
@@ -877,7 +878,7 @@ pub fn codegen_crate<'a, 'll: 'a, 'tcx: 'll, B : BackendMethods<'a, 'll, 'tcx>>(
877878
&format!("codegen {}", cgu.name()))
878879
});
879880
let start_time = Instant::now();
880-
let stats = compile_codegen_unit(tcx, *cgu.name());
881+
let stats = backend.compile_codegen_unit(tcx, *cgu.name());
881882
all_stats.extend(stats);
882883
total_codegen_time += start_time.elapsed();
883884
false
@@ -1166,7 +1167,7 @@ fn is_codegened_item(tcx: TyCtxt, id: DefId) -> bool {
11661167
all_mono_items.contains(&id)
11671168
}
11681169

1169-
fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
1170+
pub fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
11701171
cgu_name: InternedString)
11711172
-> Stats {
11721173
let start_time = Instant::now();
@@ -1198,7 +1199,7 @@ fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
11981199
// Instantiate monomorphizations without filling out definitions yet...
11991200
let llvm_module = backend.new_metadata(tcx.sess, &cgu_name.as_str());
12001201
let stats = {
1201-
let cx = backend.new_codegen_context(tcx, cgu, &llvm_module);
1202+
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
12021203
let mono_items = cx.codegen_unit
12031204
.items_in_deterministic_order(cx.tcx);
12041205
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@ 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;
82-
use std::sync::Arc;
8380
use std::path::{PathBuf};
8481
use std::sync::mpsc;
8582
use rustc_data_structures::sync::Lrc;
@@ -147,10 +144,9 @@ mod value;
147144

148145
pub struct LlvmCodegenBackend(());
149146

150-
impl<'a, 'll: 'a, 'tcx: 'll> BackendMethods<'a, 'll, 'tcx> for LlvmCodegenBackend {
147+
impl BackendMethods for LlvmCodegenBackend {
151148
type Metadata = ModuleLlvm;
152149
type OngoingCodegen = OngoingCodegen;
153-
type Builder = Builder<'a, 'll, 'tcx, &'ll Value>;
154150

155151
fn thin_lto_available(&self) -> bool {
156152
unsafe { !llvm::LLVMRustThinLTOAvailable() }
@@ -198,13 +194,12 @@ impl<'a, 'll: 'a, 'tcx: 'll> BackendMethods<'a, 'll, 'tcx> for LlvmCodegenBacken
198194
fn wait_for_signal_to_codegen_item(&self, codegen: &OngoingCodegen) {
199195
codegen.wait_for_signal_to_codegen_item()
200196
}
201-
fn new_codegen_context(
197+
fn compile_codegen_unit<'ll, 'tcx: 'll>(
202198
&self,
203199
tcx: TyCtxt<'ll, 'tcx, 'tcx>,
204-
codegen_unit: Arc<CodegenUnit<'tcx>>,
205-
llvm_module: &'ll ModuleLlvm
206-
) -> CodegenCx<'ll, 'tcx, &'ll Value> {
207-
CodegenCx::new(tcx, codegen_unit, llvm_module)
200+
cgu_name: InternedString
201+
) -> Stats {
202+
base::compile_codegen_unit(tcx, cgu_name)
208203
}
209204
}
210205

0 commit comments

Comments
 (0)