Skip to content

Commit a9b5c63

Browse files
Move eh_unwind_resume into CrateContext
Also improves cache quality.
1 parent a811f60 commit a9b5c63

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

src/librustc_trans/cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'tcx> DropValue<'tcx> {
8383
bcx.resume(llretval);
8484
} else {
8585
let exc_ptr = bcx.extract_value(llretval, 0);
86-
bcx.call(fcx.eh_unwind_resume().reify(fcx.ccx), &[exc_ptr], None);
86+
bcx.call(bcx.ccx.eh_unwind_resume(), &[exc_ptr], None);
8787
bcx.unreachable();
8888
}
8989
}

src/librustc_trans/common.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ use rustc::hir::def_id::DefId;
2121
use rustc::hir::map::DefPathData;
2222
use rustc::util::common::MemoizationMap;
2323
use middle::lang_items::LangItem;
24-
use abi::Abi;
2524
use base;
2625
use builder::Builder;
27-
use callee::Callee;
2826
use consts;
2927
use declare;
3028
use machine;
@@ -285,37 +283,6 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
285283
BlockAndBuilder::new(self.new_block(name), self)
286284
}
287285

288-
// Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
289-
// otherwise declares it as an external function.
290-
pub fn eh_unwind_resume(&self) -> Callee<'tcx> {
291-
use attributes;
292-
let ccx = self.ccx;
293-
let tcx = ccx.tcx();
294-
assert!(ccx.sess().target.target.options.custom_unwind_resume);
295-
if let Some(def_id) = tcx.lang_items.eh_unwind_resume() {
296-
return Callee::def(ccx, def_id, tcx.intern_substs(&[]));
297-
}
298-
299-
let ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
300-
unsafety: hir::Unsafety::Unsafe,
301-
abi: Abi::C,
302-
sig: ty::Binder(tcx.mk_fn_sig(
303-
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
304-
tcx.types.never,
305-
false
306-
)),
307-
}));
308-
309-
let unwresume = ccx.eh_unwind_resume();
310-
if let Some(llfn) = unwresume.get() {
311-
return Callee::ptr(llfn, ty);
312-
}
313-
let llfn = declare::declare_fn(ccx, "rust_eh_unwind_resume", ty);
314-
attributes::unwind(llfn, true);
315-
unwresume.set(Some(llfn));
316-
Callee::ptr(llfn, ty)
317-
}
318-
319286
pub fn alloca(&self, ty: Type, name: &str) -> ValueRef {
320287
self.alloca_builder.dynamic_alloca(ty, name)
321288
}

src/librustc_trans/context.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use llvm;
1212
use llvm::{ContextRef, ModuleRef, ValueRef};
1313
use rustc::dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig, WorkProduct};
1414
use middle::cstore::LinkMeta;
15+
use rustc::hir;
1516
use rustc::hir::def::ExportMap;
1617
use rustc::hir::def_id::DefId;
1718
use rustc::traits;
@@ -38,12 +39,13 @@ use std::ffi::{CStr, CString};
3839
use std::cell::{Cell, RefCell};
3940
use std::marker::PhantomData;
4041
use std::ptr;
42+
use std::iter;
4143
use std::rc::Rc;
4244
use std::str;
4345
use syntax::ast;
4446
use syntax::symbol::InternedString;
4547
use syntax_pos::DUMMY_SP;
46-
use abi::FnType;
48+
use abi::{Abi, FnType};
4749

4850
pub struct Stats {
4951
pub n_glues_created: Cell<usize>,
@@ -827,10 +829,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
827829
&self.local().dbg_cx
828830
}
829831

830-
pub fn eh_unwind_resume<'a>(&'a self) -> &'a Cell<Option<ValueRef>> {
831-
&self.local().eh_unwind_resume
832-
}
833-
834832
pub fn rust_try_fn<'a>(&'a self) -> &'a Cell<Option<ValueRef>> {
835833
&self.local().rust_try_fn
836834
}
@@ -951,6 +949,38 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
951949
}
952950
}
953951

952+
// Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
953+
// otherwise declares it as an external function.
954+
pub fn eh_unwind_resume(&self) -> ValueRef {
955+
use attributes;
956+
let unwresume = &self.local().eh_unwind_resume;
957+
if let Some(llfn) = unwresume.get() {
958+
return llfn;
959+
}
960+
961+
let tcx = self.tcx();
962+
assert!(self.sess().target.target.options.custom_unwind_resume);
963+
if let Some(def_id) = tcx.lang_items.eh_unwind_resume() {
964+
let llfn = Callee::def(self, def_id, tcx.intern_substs(&[])).reify(self);
965+
unwresume.set(Some(llfn));
966+
return llfn;
967+
}
968+
969+
let ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
970+
unsafety: hir::Unsafety::Unsafe,
971+
abi: Abi::C,
972+
sig: ty::Binder(tcx.mk_fn_sig(
973+
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
974+
tcx.types.never,
975+
false
976+
)),
977+
}));
978+
979+
let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty);
980+
attributes::unwind(llfn, true);
981+
unwresume.set(Some(llfn));
982+
llfn
983+
}
954984
}
955985

956986
pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'tcx>);

src/librustc_trans/mir/block.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
125125
bcx.resume(lp);
126126
} else {
127127
let exc_ptr = bcx.extract_value(lp, 0);
128-
bcx.call(
129-
bcx.fcx().eh_unwind_resume().reify(bcx.ccx),
130-
&[exc_ptr],
131-
cleanup_bundle,
132-
);
128+
bcx.call(bcx.ccx.eh_unwind_resume(), &[exc_ptr], cleanup_bundle);
133129
bcx.unreachable();
134130
}
135131
}

0 commit comments

Comments
 (0)