Merge commit 'ef07e8e60f994ec014d049a95591426fb92ebb79' into sync_cg_clif-2023-04-29
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
//! [`codegen_fn`]: crate::base::codegen_fn
|
||||
//! [`codegen_static`]: crate::constant::codegen_static
|
||||
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
|
||||
|
||||
use crate::prelude::*;
|
||||
@@ -39,3 +40,31 @@ fn predefine_mono_items<'tcx>(
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user