Skip to content

Commit 7896906

Browse files
committed
Remove codegen_unit from MiscCodegenMethods
1 parent 52bf0cf commit 7896906

File tree

7 files changed

+29
-42
lines changed

7 files changed

+29
-42
lines changed

compiler/rustc_codegen_gcc/src/base.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,22 @@ pub fn compile_codegen_unit(
219219

220220
let mono_items = cgu.items_in_deterministic_order(tcx);
221221
for &(mono_item, data) in &mono_items {
222-
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
222+
mono_item.predefine::<Builder<'_, '_, '_>>(
223+
&cx,
224+
cgu_name.as_str(),
225+
data.linkage,
226+
data.visibility,
227+
);
223228
}
224229

225230
// ... and now that we have everything pre-defined, fill out those definitions.
226231
for &(mono_item, item_data) in &mono_items {
227-
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, item_data);
232+
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, cgu_name.as_str(), item_data);
228233
}
229234

230235
// If this codegen unit contains the main function, also create the
231236
// wrapper here
232-
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx);
237+
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx, cx.codegen_unit);
233238

234239
// Finalize debuginfo
235240
if cx.sess().opts.debuginfo != DebugInfo::None {

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,6 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
470470
self.tcx.sess
471471
}
472472

473-
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
474-
self.codegen_unit
475-
}
476-
477473
fn set_frame_pointer_type(&self, _llfn: RValue<'gcc>) {
478474
// TODO(antoyo)
479475
}

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,24 @@ pub(crate) fn compile_codegen_unit(
8686
let mut cx = CodegenCx::new(tcx, cgu, &llvm_module);
8787
let mono_items = cx.codegen_unit.items_in_deterministic_order(cx.tcx);
8888
for &(mono_item, data) in &mono_items {
89-
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
89+
mono_item.predefine::<Builder<'_, '_, '_>>(
90+
&cx,
91+
cgu_name.as_str(),
92+
data.linkage,
93+
data.visibility,
94+
);
9095
}
9196

9297
// ... and now that we have everything pre-defined, fill out those definitions.
9398
for &(mono_item, item_data) in &mono_items {
94-
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, item_data);
99+
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, cgu_name.as_str(), item_data);
95100
}
96101

97102
// If this codegen unit contains the main function, also create the
98103
// wrapper here
99-
if let Some(entry) = maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx) {
104+
if let Some(entry) =
105+
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx, cx.codegen_unit)
106+
{
100107
let attrs = attributes::sanitize_attrs(&cx, SanitizerSet::empty());
101108
attributes::apply_to_llfn(entry, llvm::AttributePlace::Function, &attrs);
102109
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,6 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
801801
self.tcx.sess
802802
}
803803

804-
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
805-
self.codegen_unit
806-
}
807-
808804
fn set_frame_pointer_type(&self, llfn: &'ll Value) {
809805
if let Some(attr) = attributes::frame_pointer_type_attr(self) {
810806
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[attr]);

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ where
492492
/// users main function.
493493
pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
494494
cx: &'a Bx::CodegenCx,
495+
cgu: &CodegenUnit<'tcx>,
495496
) -> Option<Bx::Function> {
496497
let (main_def_id, entry_type) = cx.tcx().entry_fn(())?;
497498
let main_is_local = main_def_id.is_local();
@@ -500,10 +501,10 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
500501
if main_is_local {
501502
// We want to create the wrapper in the same codegen unit as Rust's main
502503
// function.
503-
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
504+
if !cgu.contains_item(&MonoItem::Fn(instance)) {
504505
return None;
505506
}
506-
} else if !cx.codegen_unit().is_primary() {
507+
} else if !cgu.is_primary() {
507508
// We want to create the wrapper only when the codegen unit is the primary one
508509
return None;
509510
}

compiler/rustc_codegen_ssa/src/mono_item.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ pub trait MonoItemExt<'a, 'tcx> {
1111
fn define<Bx: BuilderMethods<'a, 'tcx>>(
1212
&self,
1313
cx: &'a mut Bx::CodegenCx,
14+
cgu_name: &str,
1415
item_data: MonoItemData,
1516
);
1617
fn predefine<Bx: BuilderMethods<'a, 'tcx>>(
1718
&self,
1819
cx: &'a Bx::CodegenCx,
20+
cgu_name: &str,
1921
linkage: Linkage,
2022
visibility: Visibility,
2123
);
@@ -26,14 +28,10 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
2628
fn define<Bx: BuilderMethods<'a, 'tcx>>(
2729
&self,
2830
cx: &'a mut Bx::CodegenCx,
31+
cgu_name: &str,
2932
item_data: MonoItemData,
3033
) {
31-
debug!(
32-
"BEGIN IMPLEMENTING '{} ({})' in cgu {}",
33-
self,
34-
self.to_raw_string(),
35-
cx.codegen_unit().name()
36-
);
34+
debug!("BEGIN IMPLEMENTING '{} ({})' in cgu {}", self, self.to_raw_string(), cgu_name,);
3735

3836
match *self {
3937
MonoItem::Static(def_id) => {
@@ -56,26 +54,17 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
5654
}
5755
}
5856

59-
debug!(
60-
"END IMPLEMENTING '{} ({})' in cgu {}",
61-
self,
62-
self.to_raw_string(),
63-
cx.codegen_unit().name()
64-
);
57+
debug!("END IMPLEMENTING '{} ({})' in cgu {}", self, self.to_raw_string(), cgu_name);
6558
}
6659

6760
fn predefine<Bx: BuilderMethods<'a, 'tcx>>(
6861
&self,
6962
cx: &'a Bx::CodegenCx,
63+
cgu_name: &str,
7064
linkage: Linkage,
7165
visibility: Visibility,
7266
) {
73-
debug!(
74-
"BEGIN PREDEFINING '{} ({})' in cgu {}",
75-
self,
76-
self.to_raw_string(),
77-
cx.codegen_unit().name()
78-
);
67+
debug!("BEGIN PREDEFINING '{} ({})' in cgu {}", self, self.to_raw_string(), cgu_name);
7968

8069
let symbol_name = self.symbol_name(cx.tcx()).name;
8170

@@ -97,12 +86,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
9786
MonoItem::GlobalAsm(..) => {}
9887
}
9988

100-
debug!(
101-
"END PREDEFINING '{} ({})' in cgu {}",
102-
self,
103-
self.to_raw_string(),
104-
cx.codegen_unit().name()
105-
);
89+
debug!("END PREDEFINING '{} ({})' in cgu {}", self, self.to_raw_string(), cgu_name);
10690
}
10791

10892
fn to_raw_string(&self) -> String {

compiler/rustc_codegen_ssa/src/traits/misc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::cell::RefCell;
22

33
use rustc_data_structures::fx::FxHashMap;
4-
use rustc_middle::mir::mono::CodegenUnit;
54
use rustc_middle::ty::{self, Instance, Ty};
65
use rustc_session::Session;
76

@@ -22,7 +21,6 @@ pub trait MiscCodegenMethods<'tcx>: BackendTypes {
2221
fn get_fn_addr(&self, instance: Instance<'tcx>) -> Self::Value;
2322
fn eh_personality(&self) -> Self::Value;
2423
fn sess(&self) -> &Session;
25-
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx>;
2624
fn set_frame_pointer_type(&self, llfn: Self::Function);
2725
fn apply_target_cpu_attr(&self, llfn: Self::Function);
2826
/// Declares the extern "C" main function for the entry point. Returns None if the symbol

0 commit comments

Comments
 (0)