1 //! Drivers are responsible for calling [`codegen_fn`] or [`codegen_static`] for each mono item and
2 //! performing any further actions like JIT executing or writing object files.
4 //! [`codegen_fn`]: crate::base::codegen_fn
5 //! [`codegen_static`]: crate::constant::codegen_static
7 use rustc_data_structures
::profiling
::SelfProfilerRef
;
8 use rustc_middle
::middle
::codegen_fn_attrs
::CodegenFnAttrFlags
;
9 use rustc_middle
::mir
::mono
::{MonoItem, MonoItemData}
;
11 use crate::prelude
::*;
14 #[cfg(feature = "jit")]
17 fn predefine_mono_items
<'tcx
>(
19 module
: &mut dyn Module
,
20 mono_items
: &[(MonoItem
<'tcx
>, MonoItemData
)],
22 tcx
.prof
.generic_activity("predefine functions").run(|| {
23 let is_compiler_builtins
= tcx
.is_compiler_builtins(LOCAL_CRATE
);
24 for &(mono_item
, data
) in mono_items
{
26 MonoItem
::Fn(instance
) => {
27 let name
= tcx
.symbol_name(instance
).name
;
28 let _inst_guard
= crate::PrintOnPanic(|| format
!("{:?} {}", instance
, name
));
30 get_function_sig(tcx
, module
.target_config().default_call_conv
, instance
);
31 let linkage
= crate::linkage
::get_clif_linkage(
38 .codegen_fn_attrs(instance
.def_id())
40 .contains(CodegenFnAttrFlags
::NAKED
);
44 // Naked functions are defined in a separate object
45 // file from the codegen unit rustc expects them to
47 if is_naked { Linkage::Import }
else { linkage }
,
52 MonoItem
::Static(_
) | MonoItem
::GlobalAsm(_
) => {}
58 struct MeasuremeProfiler(SelfProfilerRef
);
61 profiler
: std
::mem
::ManuallyDrop
<SelfProfilerRef
>,
62 inner
: Option
<rustc_data_structures
::profiling
::TimingGuard
<'
static>>,
65 impl Drop
for TimingGuard
{
69 std
::mem
::ManuallyDrop
::drop(&mut self.profiler
);
74 impl cranelift_codegen
::timing
::Profiler
for MeasuremeProfiler
{
75 fn start_pass(&self, pass
: cranelift_codegen
::timing
::Pass
) -> Box
<dyn std
::any
::Any
> {
76 let mut timing_guard
=
77 TimingGuard { profiler: std::mem::ManuallyDrop::new(self.0.clone()), inner: None }
;
78 timing_guard
.inner
= Some(
79 unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
80 .generic_activity(pass
.description()),
82 Box
::new(timing_guard
)