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
|
|
|
|
2023-04-29 12:00:43 +00:00
|
|
|
use rustc_data_structures::profiling::SelfProfilerRef;
|
2023-07-14 16:32:10 +10:00
|
|
|
use rustc_middle::mir::mono::{MonoItem, MonoItemData};
|
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,
|
2023-07-14 16:32:10 +10:00
|
|
|
mono_items: &[(MonoItem<'tcx>, MonoItemData)],
|
2019-05-04 16:54:25 +02:00
|
|
|
) {
|
2023-02-09 12:38:16 +01:00
|
|
|
tcx.prof.generic_activity("predefine functions").run(|| {
|
2021-04-30 14:49:58 +02:00
|
|
|
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
|
2023-07-14 16:32:10 +10:00
|
|
|
for &(mono_item, data) 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,
|
2023-07-14 16:32:10 +10:00
|
|
|
data.linkage,
|
|
|
|
data.visibility,
|
2021-03-29 10:45:09 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-04-29 12:00:43 +00:00
|
|
|
|
|
|
|
struct MeasuremeProfiler(SelfProfilerRef);
|
|
|
|
|
|
|
|
struct TimingGuard {
|
|
|
|
profiler: std::mem::ManuallyDrop<SelfProfilerRef>,
|
|
|
|
inner: Option<rustc_data_structures::profiling::TimingGuard<'static>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for TimingGuard {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.inner.take();
|
|
|
|
unsafe {
|
|
|
|
std::mem::ManuallyDrop::drop(&mut self.profiler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl cranelift_codegen::timing::Profiler for MeasuremeProfiler {
|
|
|
|
fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
|
|
|
|
let mut timing_guard =
|
|
|
|
TimingGuard { profiler: std::mem::ManuallyDrop::new(self.0.clone()), inner: None };
|
|
|
|
timing_guard.inner = Some(
|
|
|
|
unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
|
|
|
|
.generic_activity(pass.description()),
|
|
|
|
);
|
|
|
|
Box::new(timing_guard)
|
|
|
|
}
|
|
|
|
}
|