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