Pass around BackendConfig
This commit is contained in:
parent
c5dff34ae9
commit
94aac0af59
@ -14,7 +14,7 @@ use rustc_session::config::{DebugInfo, OutputType};
|
|||||||
|
|
||||||
use cranelift_object::{ObjectModule, ObjectProduct};
|
use cranelift_object::{ObjectModule, ObjectProduct};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::{prelude::*, BackendConfig};
|
||||||
|
|
||||||
use crate::backend::AddConstructor;
|
use crate::backend::AddConstructor;
|
||||||
|
|
||||||
@ -117,7 +117,10 @@ fn reuse_workproduct_for_cgu(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodegenResult {
|
fn module_codegen(
|
||||||
|
tcx: TyCtxt<'_>,
|
||||||
|
(backend_config, cgu_name): (BackendConfig, rustc_span::Symbol),
|
||||||
|
) -> ModuleCodegenResult {
|
||||||
let cgu = tcx.codegen_unit(cgu_name);
|
let cgu = tcx.codegen_unit(cgu_name);
|
||||||
let mono_items = cgu.items_in_deterministic_order(tcx);
|
let mono_items = cgu.items_in_deterministic_order(tcx);
|
||||||
|
|
||||||
@ -148,9 +151,9 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
|
|||||||
|
|
||||||
let mut cx = crate::CodegenCx::new(
|
let mut cx = crate::CodegenCx::new(
|
||||||
tcx,
|
tcx,
|
||||||
|
backend_config,
|
||||||
module,
|
module,
|
||||||
tcx.sess.opts.debuginfo != DebugInfo::None,
|
tcx.sess.opts.debuginfo != DebugInfo::None,
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
super::predefine_mono_items(&mut cx, &mono_items);
|
super::predefine_mono_items(&mut cx, &mono_items);
|
||||||
for (mono_item, (linkage, visibility)) in mono_items {
|
for (mono_item, (linkage, visibility)) in mono_items {
|
||||||
@ -202,6 +205,7 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
|
|||||||
|
|
||||||
pub(super) fn run_aot(
|
pub(super) fn run_aot(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
|
backend_config: BackendConfig,
|
||||||
metadata: EncodedMetadata,
|
metadata: EncodedMetadata,
|
||||||
need_metadata_module: bool,
|
need_metadata_module: bool,
|
||||||
) -> Box<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>)> {
|
) -> Box<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>)> {
|
||||||
@ -242,7 +246,7 @@ pub(super) fn run_aot(
|
|||||||
let (ModuleCodegenResult(module, work_product), _) = tcx.dep_graph.with_task(
|
let (ModuleCodegenResult(module, work_product), _) = tcx.dep_graph.with_task(
|
||||||
dep_node,
|
dep_node,
|
||||||
tcx,
|
tcx,
|
||||||
cgu.name(),
|
(backend_config, cgu.name()),
|
||||||
module_codegen,
|
module_codegen,
|
||||||
rustc_middle::dep_graph::hash_result,
|
rustc_middle::dep_graph::hash_result,
|
||||||
);
|
);
|
||||||
|
@ -10,14 +10,15 @@ use rustc_middle::mir::mono::MonoItem;
|
|||||||
|
|
||||||
use cranelift_jit::{JITBuilder, JITModule};
|
use cranelift_jit::{JITBuilder, JITModule};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::{prelude::*, BackendConfig};
|
||||||
use crate::{CodegenCx, CodegenMode};
|
use crate::{CodegenCx, CodegenMode};
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
pub static BACKEND_CONFIG: RefCell<Option<BackendConfig>> = RefCell::new(None);
|
||||||
pub static CURRENT_MODULE: RefCell<Option<JITModule>> = RefCell::new(None);
|
pub static CURRENT_MODULE: RefCell<Option<JITModule>> = RefCell::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
|
pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||||
if !tcx.sess.opts.output_types.should_codegen() {
|
if !tcx.sess.opts.output_types.should_codegen() {
|
||||||
tcx.sess.fatal("JIT mode doesn't work with `cargo check`.");
|
tcx.sess.fatal("JIT mode doesn't work with `cargo check`.");
|
||||||
}
|
}
|
||||||
@ -46,7 +47,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
|
|||||||
crate::build_isa(tcx.sess),
|
crate::build_isa(tcx.sess),
|
||||||
cranelift_module::default_libcall_names(),
|
cranelift_module::default_libcall_names(),
|
||||||
);
|
);
|
||||||
jit_builder.hotswap(matches!(codegen_mode, CodegenMode::JitLazy));
|
jit_builder.hotswap(matches!(backend_config.codegen_mode, CodegenMode::JitLazy));
|
||||||
jit_builder.symbols(imported_symbols);
|
jit_builder.symbols(imported_symbols);
|
||||||
let mut jit_module = JITModule::new(jit_builder);
|
let mut jit_module = JITModule::new(jit_builder);
|
||||||
assert_eq!(pointer_ty(tcx), jit_module.target_config().pointer_type());
|
assert_eq!(pointer_ty(tcx), jit_module.target_config().pointer_type());
|
||||||
@ -74,14 +75,14 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<Vec<(_, (_, _))>>();
|
.collect::<Vec<(_, (_, _))>>();
|
||||||
|
|
||||||
let mut cx = crate::CodegenCx::new(tcx, jit_module, false, false);
|
let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
|
||||||
|
|
||||||
super::time(tcx, "codegen mono items", || {
|
super::time(tcx, "codegen mono items", || {
|
||||||
super::predefine_mono_items(&mut cx, &mono_items);
|
super::predefine_mono_items(&mut cx, &mono_items);
|
||||||
for (mono_item, (linkage, visibility)) in mono_items {
|
for (mono_item, (linkage, visibility)) in mono_items {
|
||||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => match codegen_mode {
|
MonoItem::Fn(inst) => match backend_config.codegen_mode {
|
||||||
CodegenMode::Aot => unreachable!(),
|
CodegenMode::Aot => unreachable!(),
|
||||||
CodegenMode::Jit => {
|
CodegenMode::Jit => {
|
||||||
cx.tcx.sess.time("codegen fn", || {
|
cx.tcx.sess.time("codegen fn", || {
|
||||||
@ -137,6 +138,12 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
|
|||||||
// useful as some dynamic linkers use it as a marker to jump over.
|
// useful as some dynamic linkers use it as a marker to jump over.
|
||||||
argv.push(std::ptr::null());
|
argv.push(std::ptr::null());
|
||||||
|
|
||||||
|
BACKEND_CONFIG.with(|tls_backend_config| {
|
||||||
|
assert!(tls_backend_config
|
||||||
|
.borrow_mut()
|
||||||
|
.replace(backend_config)
|
||||||
|
.is_none())
|
||||||
|
});
|
||||||
CURRENT_MODULE
|
CURRENT_MODULE
|
||||||
.with(|current_module| assert!(current_module.borrow_mut().replace(jit_module).is_none()));
|
.with(|current_module| assert!(current_module.borrow_mut().replace(jit_module).is_none()));
|
||||||
|
|
||||||
@ -154,7 +161,9 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8
|
|||||||
CURRENT_MODULE.with(|jit_module| {
|
CURRENT_MODULE.with(|jit_module| {
|
||||||
let mut jit_module = jit_module.borrow_mut();
|
let mut jit_module = jit_module.borrow_mut();
|
||||||
let jit_module = jit_module.as_mut().unwrap();
|
let jit_module = jit_module.as_mut().unwrap();
|
||||||
let mut cx = crate::CodegenCx::new(tcx, jit_module, false, false);
|
let backend_config =
|
||||||
|
BACKEND_CONFIG.with(|backend_config| backend_config.borrow().clone().unwrap());
|
||||||
|
let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
|
||||||
|
|
||||||
let name = tcx.symbol_name(instance).name.to_string();
|
let name = tcx.symbol_name(instance).name.to_string();
|
||||||
let sig = crate::abi::get_function_sig(tcx, cx.module.isa().triple(), instance);
|
let sig = crate::abi::get_function_sig(tcx, cx.module.isa().triple(), instance);
|
||||||
|
@ -17,12 +17,12 @@ pub(crate) fn codegen_crate(
|
|||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
metadata: EncodedMetadata,
|
metadata: EncodedMetadata,
|
||||||
need_metadata_module: bool,
|
need_metadata_module: bool,
|
||||||
config: crate::BackendConfig,
|
backend_config: crate::BackendConfig,
|
||||||
) -> Box<dyn Any> {
|
) -> Box<dyn Any> {
|
||||||
tcx.sess.abort_if_errors();
|
tcx.sess.abort_if_errors();
|
||||||
|
|
||||||
match config.codegen_mode {
|
match backend_config.codegen_mode {
|
||||||
CodegenMode::Aot => aot::run_aot(tcx, metadata, need_metadata_module),
|
CodegenMode::Aot => aot::run_aot(tcx, backend_config, metadata, need_metadata_module),
|
||||||
CodegenMode::Jit | CodegenMode::JitLazy => {
|
CodegenMode::Jit | CodegenMode::JitLazy => {
|
||||||
let is_executable = tcx
|
let is_executable = tcx
|
||||||
.sess
|
.sess
|
||||||
@ -33,7 +33,7 @@ pub(crate) fn codegen_crate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "jit")]
|
#[cfg(feature = "jit")]
|
||||||
let _: ! = jit::run_jit(tcx, config.codegen_mode);
|
let _: ! = jit::run_jit(tcx, backend_config);
|
||||||
|
|
||||||
#[cfg(not(feature = "jit"))]
|
#[cfg(not(feature = "jit"))]
|
||||||
tcx.sess
|
tcx.sess
|
||||||
|
@ -142,8 +142,12 @@ struct CodegenCx<'tcx, M: Module> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, M: Module> CodegenCx<'tcx, M> {
|
impl<'tcx, M: Module> CodegenCx<'tcx, M> {
|
||||||
fn new(tcx: TyCtxt<'tcx>, module: M, debug_info: bool, pic_eh_frame: bool) -> Self {
|
fn new(tcx: TyCtxt<'tcx>, backend_config: BackendConfig, module: M, debug_info: bool) -> Self {
|
||||||
let unwind_context = UnwindContext::new(tcx, module.isa(), pic_eh_frame);
|
let unwind_context = UnwindContext::new(
|
||||||
|
tcx,
|
||||||
|
module.isa(),
|
||||||
|
matches!(backend_config.codegen_mode, CodegenMode::Aot),
|
||||||
|
);
|
||||||
let debug_context = if debug_info {
|
let debug_context = if debug_info {
|
||||||
Some(DebugContext::new(tcx, module.isa()))
|
Some(DebugContext::new(tcx, module.isa()))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user