Sync rustc_codegen_cranelift 'ddd4ce25535cf71203ba3700896131ce55fde795'
This commit is contained in:
@@ -1,63 +1,37 @@
|
||||
//! Drivers are responsible for calling [`codegen_mono_item`] and performing any further actions
|
||||
//! like JIT executing or writing object files.
|
||||
//! Drivers are responsible for calling [`codegen_fn`] or [`codegen_static`] for each mono item and
|
||||
//! performing any further actions like JIT executing or writing object files.
|
||||
//!
|
||||
//! [`codegen_fn`]: crate::base::codegen_fn
|
||||
//! [`codegen_static`]: crate::constant::codegen_static
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::CodegenMode;
|
||||
|
||||
mod aot;
|
||||
pub(crate) mod aot;
|
||||
#[cfg(feature = "jit")]
|
||||
mod jit;
|
||||
|
||||
pub(crate) fn codegen_crate(
|
||||
tcx: TyCtxt<'_>,
|
||||
metadata: EncodedMetadata,
|
||||
need_metadata_module: bool,
|
||||
backend_config: crate::BackendConfig,
|
||||
) -> Box<dyn Any> {
|
||||
tcx.sess.abort_if_errors();
|
||||
|
||||
match backend_config.codegen_mode {
|
||||
CodegenMode::Aot => aot::run_aot(tcx, backend_config, metadata, need_metadata_module),
|
||||
CodegenMode::Jit | CodegenMode::JitLazy => {
|
||||
let is_executable =
|
||||
tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable);
|
||||
if !is_executable {
|
||||
tcx.sess.fatal("can't jit non-executable crate");
|
||||
}
|
||||
|
||||
#[cfg(feature = "jit")]
|
||||
let _: ! = jit::run_jit(tcx, backend_config);
|
||||
|
||||
#[cfg(not(feature = "jit"))]
|
||||
tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift");
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) mod jit;
|
||||
|
||||
fn predefine_mono_items<'tcx>(
|
||||
cx: &mut crate::CodegenCx<'_, 'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
module: &mut dyn Module,
|
||||
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
|
||||
) {
|
||||
cx.tcx.sess.time("predefine functions", || {
|
||||
let is_compiler_builtins = cx.tcx.is_compiler_builtins(LOCAL_CRATE);
|
||||
tcx.sess.time("predefine functions", || {
|
||||
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
|
||||
for &(mono_item, (linkage, visibility)) in mono_items {
|
||||
match mono_item {
|
||||
MonoItem::Fn(instance) => {
|
||||
let name = cx.tcx.symbol_name(instance).name.to_string();
|
||||
let name = tcx.symbol_name(instance).name;
|
||||
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
|
||||
let sig = get_function_sig(cx.tcx, cx.module.isa().triple(), instance);
|
||||
let sig = get_function_sig(tcx, module.isa().triple(), instance);
|
||||
let linkage = crate::linkage::get_clif_linkage(
|
||||
mono_item,
|
||||
linkage,
|
||||
visibility,
|
||||
is_compiler_builtins,
|
||||
);
|
||||
cx.module.declare_function(&name, linkage, &sig).unwrap();
|
||||
module.declare_function(name, linkage, &sig).unwrap();
|
||||
}
|
||||
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
|
||||
}
|
||||
@@ -65,8 +39,8 @@ fn predefine_mono_items<'tcx>(
|
||||
});
|
||||
}
|
||||
|
||||
fn time<R>(tcx: TyCtxt<'_>, name: &'static str, f: impl FnOnce() -> R) -> R {
|
||||
if std::env::var("CG_CLIF_DISPLAY_CG_TIME").as_ref().map(|val| &**val) == Ok("1") {
|
||||
fn time<R>(tcx: TyCtxt<'_>, display: bool, name: &'static str, f: impl FnOnce() -> R) -> R {
|
||||
if display {
|
||||
println!("[{:<30}: {}] start", tcx.crate_name(LOCAL_CRATE), name);
|
||||
let before = std::time::Instant::now();
|
||||
let res = tcx.sess.time(name, f);
|
||||
|
||||
Reference in New Issue
Block a user