Files
rust/compiler/rustc_codegen_cranelift/src/driver/mod.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
2.0 KiB
Rust
Raw Normal View History

2021-04-09 11:34: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
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
2019-05-04 16:54:25 +02:00
use crate::prelude::*;
2021-04-08 21:26:20 +02:00
pub(crate) mod aot;
2020-07-09 14:23:00 +02:00
#[cfg(feature = "jit")]
2021-04-08 21:26:20 +02:00
pub(crate) mod jit;
2019-05-04 16:54:25 +02:00
fn predefine_mono_items<'tcx>(
tcx: TyCtxt<'tcx>,
module: &mut dyn Module,
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
2019-05-04 16:54:25 +02:00
) {
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 = tcx.symbol_name(instance).name;
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
let sig = get_function_sig(tcx, module.isa().triple(), instance);
let linkage = crate::linkage::get_clif_linkage(
mono_item,
linkage,
visibility,
is_compiler_builtins,
);
module.declare_function(name, linkage, &sig).unwrap();
}
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
}
2019-05-04 16:54:25 +02:00
}
});
}
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);
2020-03-12 11:17:19 +01:00
let before = std::time::Instant::now();
let res = tcx.sess.time(name, f);
2020-03-12 11:17:19 +01:00
let after = std::time::Instant::now();
2021-03-05 11:21:44 +01:00
println!("[{:<30}: {}] end time: {:?}", tcx.crate_name(LOCAL_CRATE), name, after - before);
2020-03-12 11:17:19 +01:00
res
} else {
tcx.sess.time(name, f)
2020-03-12 11:17:19 +01:00
}
2019-05-04 16:54:25 +02:00
}