From d6e72c48dd7dacebe08b44e7ee6ce0f052797f55 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 23 Feb 2016 22:00:59 +0200 Subject: [PATCH] trans: Don't store extra copies of intrinsics ID/substs. --- src/librustc_trans/trans/callee.rs | 13 ++++++------- src/librustc_trans/trans/intrinsic.rs | 27 ++++++++++++++------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 5e412baa9ce..06e3cba6be1 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -58,21 +58,21 @@ use syntax::codemap::DUMMY_SP; use syntax::errors; use syntax::ptr::P; -pub enum CalleeData<'tcx> { +pub enum CalleeData { /// Constructor for enum variant/tuple-like-struct. NamedTupleConstructor(Disr), /// Function pointer. Fn(ValueRef), - Intrinsic(ast::NodeId, &'tcx subst::Substs<'tcx>), + Intrinsic, /// Trait object found in the vtable at that index. Virtual(usize) } pub struct Callee<'tcx> { - pub data: CalleeData<'tcx>, + pub data: CalleeData, pub ty: Ty<'tcx> } @@ -245,7 +245,7 @@ impl<'tcx> Callee<'tcx> { } _ => unreachable!("expected fn item type, found {}", self.ty) }, - Intrinsic(..) => unreachable!("intrinsic {} getting reified", self.ty) + Intrinsic => unreachable!("intrinsic {} getting reified", self.ty) } } } @@ -545,7 +545,7 @@ fn trans_call_inner<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, }; match callee.data { - Intrinsic(node, substs) => { + Intrinsic => { assert!(abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic); assert!(dest.is_some()); @@ -557,10 +557,9 @@ fn trans_call_inner<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, }; let arg_cleanup_scope = fcx.push_custom_cleanup_scope(); - return intrinsic::trans_intrinsic_call(bcx, node, callee.ty, + return intrinsic::trans_intrinsic_call(bcx, callee.ty, arg_cleanup_scope, args, dest.unwrap(), - substs, call_info); } NamedTupleConstructor(disr) => { diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 7494cf2975a..707d60e18a9 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -51,8 +51,8 @@ use syntax::codemap::Span; use std::cmp::Ordering; -pub fn get_simple_intrinsic(ccx: &CrateContext, item: &hir::ForeignItem) -> Option { - let name = match &*item.name.as_str() { +fn get_simple_intrinsic(ccx: &CrateContext, name: &str) -> Option { + let llvm_name = match name { "sqrtf32" => "llvm.sqrt.f32", "sqrtf64" => "llvm.sqrt.f64", "powif32" => "llvm.powi.f32", @@ -94,7 +94,7 @@ pub fn get_simple_intrinsic(ccx: &CrateContext, item: &hir::ForeignItem) -> Opti "assume" => "llvm.assume", _ => return None }; - Some(ccx.get_intrinsic(&name)) + Some(ccx.get_intrinsic(&llvm_name)) } pub fn span_transmute_size_error(a: &Session, b: Span, msg: &str) { @@ -171,12 +171,10 @@ pub fn check_intrinsics(ccx: &CrateContext) { /// and in libcore/intrinsics.rs; if you need access to any llvm intrinsics, /// add them to librustc_trans/trans/context.rs pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - node: ast::NodeId, callee_ty: Ty<'tcx>, cleanup_scope: cleanup::CustomScopeIndex, args: callee::CallArgs<'a, 'tcx>, dest: expr::Dest, - substs: &'tcx subst::Substs<'tcx>, call_info: NodeIdAndSpan) -> Result<'blk, 'tcx> { let fcx = bcx.fcx; @@ -185,12 +183,16 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, let _icx = push_ctxt("trans_intrinsic_call"); - let sig = ccx.tcx().erase_late_bound_regions(callee_ty.fn_sig()); - let sig = infer::normalize_associated_type(ccx.tcx(), &sig); + let (def_id, substs, sig) = match callee_ty.sty { + ty::TyFnDef(def_id, substs, fty) => { + let sig = tcx.erase_late_bound_regions(&fty.sig); + (def_id, substs, infer::normalize_associated_type(tcx, &sig)) + } + _ => unreachable!("expected fn item type, found {}", callee_ty) + }; let arg_tys = sig.inputs; let ret_ty = sig.output; - let foreign_item = tcx.map.expect_foreign_item(node); - let name = foreign_item.name.as_str(); + let name = tcx.item_name(def_id).as_str(); let call_debug_location = DebugLoc::At(call_info.id, call_info.span); @@ -437,8 +439,8 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } }; - let simple = get_simple_intrinsic(ccx, &foreign_item); - let llval = match (simple, &*name) { + let simple = get_simple_intrinsic(ccx, &name); + let llval = match (simple, &name[..]) { (Some(llfn), _) => { Call(bcx, llfn, &llargs, None, call_debug_location) } @@ -815,8 +817,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, (_, _) => { let intr = match Intrinsic::find(tcx, &name) { Some(intr) => intr, - None => ccx.sess().span_bug(foreign_item.span, - &format!("unknown intrinsic '{}'", name)), + None => unreachable!("unknown intrinsic '{}'", name), }; fn one(x: Vec) -> T { assert_eq!(x.len(), 1);