2021-04-30 14:49:58 +02:00
|
|
|
//! 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
|
2020-09-23 15:13:49 +02:00
|
|
|
|
2020-03-31 13:20:19 +02:00
|
|
|
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
|
2019-05-04 16:54:25 +02:00
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2021-04-30 14:49:58 +02:00
|
|
|
pub(crate) mod aot;
|
2020-07-09 14:23:00 +02:00
|
|
|
#[cfg(feature = "jit")]
|
2021-04-30 14:49:58 +02:00
|
|
|
pub(crate) mod jit;
|
2019-05-04 16:54:25 +02:00
|
|
|
|
2020-11-27 20:48:53 +01:00
|
|
|
fn predefine_mono_items<'tcx>(
|
2021-04-30 14:49:58 +02:00
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
module: &mut dyn Module,
|
2020-11-27 20:48:53 +01:00
|
|
|
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
|
2019-05-04 16:54:25 +02:00
|
|
|
) {
|
2021-04-30 14:49:58 +02:00
|
|
|
tcx.sess.time("predefine functions", || {
|
|
|
|
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
|
2020-11-27 20:48:53 +01:00
|
|
|
for &(mono_item, (linkage, visibility)) in mono_items {
|
2020-03-07 12:16:32 +01:00
|
|
|
match mono_item {
|
|
|
|
MonoItem::Fn(instance) => {
|
2021-04-30 14:49:58 +02:00
|
|
|
let name = tcx.symbol_name(instance).name;
|
2021-02-01 10:11:46 +01:00
|
|
|
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
|
2022-12-14 19:30:46 +01:00
|
|
|
let sig =
|
|
|
|
get_function_sig(tcx, module.target_config().default_call_conv, instance);
|
2021-03-29 10:45:09 +02:00
|
|
|
let linkage = crate::linkage::get_clif_linkage(
|
|
|
|
mono_item,
|
|
|
|
linkage,
|
|
|
|
visibility,
|
|
|
|
is_compiler_builtins,
|
|
|
|
);
|
2021-04-30 14:49:58 +02:00
|
|
|
module.declare_function(name, linkage, &sig).unwrap();
|
2019-10-04 14:39:14 +02:00
|
|
|
}
|
2020-03-07 12:16:32 +01:00
|
|
|
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
|
2019-10-04 14:39:14 +02:00
|
|
|
}
|
2019-05-04 16:54:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:49:58 +02:00
|
|
|
fn time<R>(tcx: TyCtxt<'_>, display: bool, name: &'static str, f: impl FnOnce() -> R) -> R {
|
|
|
|
if display {
|
2020-03-12 11:40:42 +01:00
|
|
|
println!("[{:<30}: {}] start", tcx.crate_name(LOCAL_CRATE), name);
|
2020-03-12 11:17:19 +01:00
|
|
|
let before = std::time::Instant::now();
|
2020-03-12 11:40:42 +01:00
|
|
|
let res = tcx.sess.time(name, f);
|
2020-03-12 11:17:19 +01:00
|
|
|
let after = std::time::Instant::now();
|
2021-03-05 19:12:59 +01:00
|
|
|
println!("[{:<30}: {}] end time: {:?}", tcx.crate_name(LOCAL_CRATE), name, after - before);
|
2020-03-12 11:17:19 +01:00
|
|
|
res
|
|
|
|
} else {
|
2020-03-12 11:40:42 +01:00
|
|
|
tcx.sess.time(name, f)
|
2020-03-12 11:17:19 +01:00
|
|
|
}
|
2019-05-04 16:54:25 +02:00
|
|
|
}
|