mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 17:33:07 +00:00
Remove all non-tcx references from CodegenCx
This commit is contained in:
parent
ba7cdf21be
commit
16b5dac463
@ -3,8 +3,8 @@ use rustc_index::vec::IndexVec;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
|
||||
cx: &mut crate::CodegenCx<'clif, 'tcx, B>,
|
||||
pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||
cx: &mut crate::CodegenCx<'tcx, B>,
|
||||
instance: Instance<'tcx>,
|
||||
linkage: Linkage,
|
||||
) {
|
||||
@ -39,7 +39,7 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
|
||||
|
||||
let mut fx = FunctionCx {
|
||||
tcx,
|
||||
module: cx.module,
|
||||
module: &mut cx.module,
|
||||
pointer_type,
|
||||
|
||||
instance,
|
||||
|
@ -15,12 +15,12 @@ pub(crate) struct UnwindContext<'tcx> {
|
||||
impl<'tcx> UnwindContext<'tcx> {
|
||||
pub(crate) fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module: &mut Module<impl Backend>,
|
||||
isa: &dyn TargetIsa,
|
||||
) -> Self {
|
||||
let mut frame_table = FrameTable::default();
|
||||
|
||||
|
||||
let cie_id = if let Some(cie) = module.isa().create_systemv_cie() {
|
||||
let cie_id = if let Some(cie) = isa.create_systemv_cie() {
|
||||
Some(frame_table.add_cie(cie))
|
||||
} else {
|
||||
None
|
||||
|
@ -108,21 +108,11 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
|
||||
let cgu = tcx.codegen_unit(cgu_name);
|
||||
let mono_items = cgu.items_in_deterministic_order(tcx);
|
||||
|
||||
let mut module = new_module(tcx, cgu_name.as_str().to_string());
|
||||
let module = new_module(tcx, cgu_name.as_str().to_string());
|
||||
|
||||
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None {
|
||||
let debug = DebugContext::new(
|
||||
tcx,
|
||||
module.isa(),
|
||||
);
|
||||
Some(debug)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut unwind_context = UnwindContext::new(tcx, &mut module);
|
||||
|
||||
super::codegen_mono_items(tcx, &mut module, debug.as_mut(), &mut unwind_context, mono_items);
|
||||
let mut cx = CodegenCx::new(tcx, module, tcx.sess.opts.debuginfo != DebugInfo::None);
|
||||
super::codegen_mono_items(&mut cx, mono_items);
|
||||
let (mut module, debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize());
|
||||
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);
|
||||
|
||||
emit_module(
|
||||
@ -185,7 +175,7 @@ pub(super) fn run_aot(
|
||||
tcx.sess.abort_if_errors();
|
||||
|
||||
let mut allocator_module = new_module(tcx, "allocator_shim".to_string());
|
||||
let mut allocator_unwind_context = UnwindContext::new(tcx, &mut allocator_module);
|
||||
let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa());
|
||||
let created_alloc_shim = crate::allocator::codegen(
|
||||
tcx,
|
||||
&mut allocator_module,
|
||||
|
@ -52,10 +52,11 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
|
||||
.into_iter()
|
||||
.collect::<Vec<(_, (_, _))>>();
|
||||
|
||||
let mut unwind_context = UnwindContext::new(tcx, &mut jit_module);
|
||||
let mut cx = CodegenCx::new(tcx, jit_module, false);
|
||||
|
||||
super::time(tcx, "codegen mono items", || {
|
||||
super::codegen_mono_items(tcx, &mut jit_module, None, &mut unwind_context, mono_items);
|
||||
let (mut jit_module, _debug, mut unwind_context) = super::time(tcx, "codegen mono items", || {
|
||||
super::codegen_mono_items(&mut cx, mono_items);
|
||||
tcx.sess.time("finalize CodegenCx", || cx.finalize())
|
||||
});
|
||||
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context);
|
||||
crate::allocator::codegen(tcx, &mut jit_module, &mut unwind_context);
|
||||
|
@ -30,20 +30,15 @@ pub(crate) fn codegen_crate(
|
||||
}
|
||||
|
||||
fn codegen_mono_items<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module: &mut Module<impl Backend + 'static>,
|
||||
debug_context: Option<&mut DebugContext<'tcx>>,
|
||||
unwind_context: &mut UnwindContext<'tcx>,
|
||||
cx: &mut CodegenCx<'tcx, impl Backend + 'static>,
|
||||
mono_items: Vec<(MonoItem<'tcx>, (RLinkage, Visibility))>,
|
||||
) {
|
||||
let mut cx = CodegenCx::new(tcx, module, debug_context, unwind_context);
|
||||
|
||||
tcx.sess.time("predefine functions", || {
|
||||
cx.tcx.sess.time("predefine functions", || {
|
||||
for &(mono_item, (linkage, visibility)) in &mono_items {
|
||||
match mono_item {
|
||||
MonoItem::Fn(instance) => {
|
||||
let (name, sig) =
|
||||
get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
|
||||
get_function_name_and_sig(cx.tcx, cx.module.isa().triple(), instance, false);
|
||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||
cx.module.declare_function(&name, linkage, &sig).unwrap();
|
||||
}
|
||||
@ -54,14 +49,12 @@ fn codegen_mono_items<'tcx>(
|
||||
|
||||
for (mono_item, (linkage, visibility)) in mono_items {
|
||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||
trans_mono_item(&mut cx, mono_item, linkage);
|
||||
trans_mono_item(cx, mono_item, linkage);
|
||||
}
|
||||
|
||||
tcx.sess.time("finalize CodegenCx", || cx.finalize());
|
||||
}
|
||||
|
||||
fn trans_mono_item<'clif, 'tcx, B: Backend + 'static>(
|
||||
cx: &mut crate::CodegenCx<'clif, 'tcx, B>,
|
||||
fn trans_mono_item<'tcx, B: Backend + 'static>(
|
||||
cx: &mut crate::CodegenCx<'tcx, B>,
|
||||
mono_item: MonoItem<'tcx>,
|
||||
linkage: Linkage,
|
||||
) {
|
||||
|
29
src/lib.rs
29
src/lib.rs
@ -126,23 +126,31 @@ mod prelude {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct CodegenCx<'clif, 'tcx, B: Backend + 'static> {
|
||||
pub(crate) struct CodegenCx<'tcx, B: Backend + 'static> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module: &'clif mut Module<B>,
|
||||
module: Module<B>,
|
||||
constants_cx: ConstantCx,
|
||||
cached_context: Context,
|
||||
vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
|
||||
debug_context: Option<&'clif mut DebugContext<'tcx>>,
|
||||
unwind_context: &'clif mut UnwindContext<'tcx>,
|
||||
debug_context: Option<DebugContext<'tcx>>,
|
||||
unwind_context: UnwindContext<'tcx>,
|
||||
}
|
||||
|
||||
impl<'clif, 'tcx, B: Backend + 'static> CodegenCx<'clif, 'tcx, B> {
|
||||
impl<'tcx, B: Backend + 'static> CodegenCx<'tcx, B> {
|
||||
fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module: &'clif mut Module<B>,
|
||||
debug_context: Option<&'clif mut DebugContext<'tcx>>,
|
||||
unwind_context: &'clif mut UnwindContext<'tcx>,
|
||||
module: Module<B>,
|
||||
debug_info: bool,
|
||||
) -> Self {
|
||||
let unwind_context = UnwindContext::new(tcx, module.isa());
|
||||
let debug_context = if debug_info {
|
||||
Some(DebugContext::new(
|
||||
tcx,
|
||||
module.isa(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
CodegenCx {
|
||||
tcx,
|
||||
module,
|
||||
@ -154,8 +162,9 @@ impl<'clif, 'tcx, B: Backend + 'static> CodegenCx<'clif, 'tcx, B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn finalize(self) {
|
||||
self.constants_cx.finalize(self.tcx, self.module);
|
||||
fn finalize(mut self) -> (Module<B>, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) {
|
||||
self.constants_cx.finalize(self.tcx, &mut self.module);
|
||||
(self.module, self.debug_context, self.unwind_context)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user