Cleanup instruction counting
This commit is contained in:
parent
449c6d82a7
commit
88b2024a28
3 changed files with 6 additions and 94 deletions
|
@ -89,40 +89,6 @@ use rustc::hir;
|
|||
use rustc::ty::layout::{self, Layout};
|
||||
use syntax::ast;
|
||||
|
||||
thread_local! {
|
||||
static TASK_LOCAL_INSN_KEY: RefCell<Option<Vec<&'static str>>> = {
|
||||
RefCell::new(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_insn_ctxt<F>(blk: F)
|
||||
where F: FnOnce(&[&'static str])
|
||||
{
|
||||
TASK_LOCAL_INSN_KEY.with(move |slot| {
|
||||
slot.borrow().as_ref().map(move |s| blk(s));
|
||||
})
|
||||
}
|
||||
|
||||
pub fn init_insn_ctxt() {
|
||||
TASK_LOCAL_INSN_KEY.with(|slot| {
|
||||
*slot.borrow_mut() = Some(Vec::new());
|
||||
});
|
||||
}
|
||||
|
||||
pub struct _InsnCtxt {
|
||||
_cannot_construct_outside_of_this_module: (),
|
||||
}
|
||||
|
||||
impl Drop for _InsnCtxt {
|
||||
fn drop(&mut self) {
|
||||
TASK_LOCAL_INSN_KEY.with(|slot| {
|
||||
if let Some(ctx) = slot.borrow_mut().as_mut() {
|
||||
ctx.pop();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StatRecorder<'a, 'tcx: 'a> {
|
||||
ccx: &'a CrateContext<'a, 'tcx>,
|
||||
name: Option<String>,
|
||||
|
@ -144,10 +110,7 @@ impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> {
|
|||
fn drop(&mut self) {
|
||||
if self.ccx.sess().trans_stats() {
|
||||
let iend = self.ccx.stats().n_llvm_insns.get();
|
||||
self.ccx
|
||||
.stats()
|
||||
.fn_stats
|
||||
.borrow_mut()
|
||||
self.ccx.stats().fn_stats.borrow_mut()
|
||||
.push((self.name.take().unwrap(), iend - self.istart));
|
||||
self.ccx.stats().n_fns.set(self.ccx.stats().n_fns.get() + 1);
|
||||
// Reset LLVM insn count to avoid compound costs.
|
||||
|
|
|
@ -42,7 +42,7 @@ impl<'blk, 'tcx> Drop for Builder<'blk, 'tcx> {
|
|||
|
||||
// This is a really awful way to get a zero-length c-string, but better (and a
|
||||
// lot more efficient) than doing str::as_c_str("", ...) every time.
|
||||
pub fn noname() -> *const c_char {
|
||||
fn noname() -> *const c_char {
|
||||
static CNULL: c_char = 0;
|
||||
&CNULL
|
||||
}
|
||||
|
@ -59,50 +59,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn count_insn(&self, category: &str) {
|
||||
fn count_insn(&self, category: &str) {
|
||||
if self.ccx.sess().trans_stats() {
|
||||
self.ccx.stats().n_llvm_insns.set(self.ccx
|
||||
.stats()
|
||||
.n_llvm_insns
|
||||
.get() + 1);
|
||||
self.ccx.stats().n_llvm_insns.set(self.ccx.stats().n_llvm_insns.get() + 1);
|
||||
}
|
||||
self.ccx.count_llvm_insn();
|
||||
if self.ccx.sess().count_llvm_insns() {
|
||||
base::with_insn_ctxt(|v| {
|
||||
let mut h = self.ccx.stats().llvm_insns.borrow_mut();
|
||||
|
||||
// Build version of path with cycles removed.
|
||||
|
||||
// Pass 1: scan table mapping str -> rightmost pos.
|
||||
let mut mm = FxHashMap();
|
||||
let len = v.len();
|
||||
let mut i = 0;
|
||||
while i < len {
|
||||
mm.insert(v[i], i);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// Pass 2: concat strings for each elt, skipping
|
||||
// forwards over any cycles by advancing to rightmost
|
||||
// occurrence of each element in path.
|
||||
let mut s = String::from(".");
|
||||
i = 0;
|
||||
while i < len {
|
||||
i = mm[v[i]];
|
||||
s.push('/');
|
||||
s.push_str(v[i]);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
s.push('/');
|
||||
s.push_str(category);
|
||||
|
||||
let n = match h.get(&s) {
|
||||
Some(&n) => n,
|
||||
_ => 0
|
||||
};
|
||||
h.insert(s, n+1);
|
||||
})
|
||||
*h.entry(category.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,11 +149,6 @@ pub struct LocalCrateContext<'tcx> {
|
|||
|
||||
intrinsics: RefCell<FxHashMap<&'static str, ValueRef>>,
|
||||
|
||||
/// Number of LLVM instructions translated into this `LocalCrateContext`.
|
||||
/// This is used to perform some basic load-balancing to keep all LLVM
|
||||
/// contexts around the same size.
|
||||
n_llvm_insns: Cell<usize>,
|
||||
|
||||
/// Depth of the current type-of computation - used to bail out
|
||||
type_of_depth: Cell<usize>,
|
||||
|
||||
|
@ -608,7 +603,6 @@ impl<'tcx> LocalCrateContext<'tcx> {
|
|||
eh_unwind_resume: Cell::new(None),
|
||||
rust_try_fn: Cell::new(None),
|
||||
intrinsics: RefCell::new(FxHashMap()),
|
||||
n_llvm_insns: Cell::new(0),
|
||||
type_of_depth: Cell::new(0),
|
||||
symbol_map: symbol_map,
|
||||
local_gen_sym_counter: Cell::new(0),
|
||||
|
@ -634,10 +628,6 @@ impl<'tcx> LocalCrateContext<'tcx> {
|
|||
local_ccx.opaque_vec_type = opaque_vec_type;
|
||||
local_ccx.str_slice_type = str_slice_ty;
|
||||
|
||||
if shared.tcx.sess.count_llvm_insns() {
|
||||
base::init_insn_ctxt()
|
||||
}
|
||||
|
||||
local_ccx
|
||||
}
|
||||
}
|
||||
|
@ -841,10 +831,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
|
|||
&self.local().intrinsics
|
||||
}
|
||||
|
||||
pub fn count_llvm_insn(&self) {
|
||||
self.local().n_llvm_insns.set(self.local().n_llvm_insns.get() + 1);
|
||||
}
|
||||
|
||||
pub fn obj_size_bound(&self) -> u64 {
|
||||
self.tcx().data_layout.obj_size_bound()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue