Remove MiscMethods::instances

This commit is contained in:
bjorn3 2019-10-13 12:05:40 +02:00
parent dad8ddbfdd
commit bcb01bca86
8 changed files with 21 additions and 22 deletions

View file

@ -33,7 +33,7 @@ pub fn get_fn(
assert!(!instance.substs.has_param_types()); assert!(!instance.substs.has_param_types());
let sig = instance.fn_sig(cx.tcx()); let sig = instance.fn_sig(cx.tcx());
if let Some(&llfn) = cx.instances().borrow().get(&instance) { if let Some(&llfn) = cx.instances.borrow().get(&instance) {
return llfn; return llfn;
} }

View file

@ -305,7 +305,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
} }
} }
Some(GlobalAlloc::Function(fn_instance)) => { Some(GlobalAlloc::Function(fn_instance)) => {
self.get_fn(fn_instance) self.get_fn_addr(fn_instance)
} }
Some(GlobalAlloc::Static(def_id)) => { Some(GlobalAlloc::Static(def_id)) => {
assert!(self.tcx.is_static(def_id)); assert!(self.tcx.is_static(def_id));

View file

@ -326,11 +326,11 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
&self.vtables &self.vtables
} }
fn instances(&self) -> &RefCell<FxHashMap<Instance<'tcx>, &'ll Value>> { fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
&self.instances get_fn(self, instance)
} }
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value { fn get_fn_addr(&self, instance: Instance<'tcx>) -> &'ll Value {
get_fn(self, instance) get_fn(self, instance)
} }
@ -361,7 +361,7 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let llfn = match tcx.lang_items().eh_personality() { let llfn = match tcx.lang_items().eh_personality() {
Some(def_id) if !wants_msvc_seh(self.sess()) => { Some(def_id) if !wants_msvc_seh(self.sess()) => {
self.get_fn( self.get_fn_addr(
ty::Instance::resolve( ty::Instance::resolve(
tcx, tcx,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
@ -396,7 +396,7 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
assert!(self.sess().target.target.options.custom_unwind_resume); assert!(self.sess().target.target.options.custom_unwind_resume);
if let Some(def_id) = tcx.lang_items().eh_unwind_resume() { if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
let llfn = self.get_fn( let llfn = self.get_fn_addr(
ty::Instance::resolve( ty::Instance::resolve(
tcx, tcx,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),

View file

@ -376,8 +376,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
let sig = instance.fn_sig(cx.tcx()); let sig = instance.fn_sig(cx.tcx());
let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
let lldecl = cx.instances().borrow().get(&instance).cloned().unwrap_or_else(|| let lldecl = cx.get_fn(instance);
bug!("Instance `{:?}` not already declared", instance));
let mir = cx.tcx().instance_mir(instance.def); let mir = cx.tcx().instance_mir(instance.def);
mir::codegen_mir::<Bx>(cx, lldecl, &mir, instance, sig); mir::codegen_mir::<Bx>(cx, lldecl, &mir, instance, sig);
@ -399,7 +398,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
return; return;
} }
let main_llfn = cx.get_fn(instance); let main_llfn = cx.get_fn_addr(instance);
let et = cx.tcx().entry_fn(LOCAL_CRATE).map(|e| e.1); let et = cx.tcx().entry_fn(LOCAL_CRATE).map(|e| e.1);
match et { match et {
@ -454,7 +453,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
let (start_fn, args) = if use_start_lang_item { let (start_fn, args) = if use_start_lang_item {
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None); let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None);
let start_fn = cx.get_fn( let start_fn = cx.get_fn_addr(
ty::Instance::resolve( ty::Instance::resolve(
cx.tcx(), cx.tcx(),
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),

View file

@ -91,7 +91,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
let methods = methods.cloned().map(|opt_mth| { let methods = methods.cloned().map(|opt_mth| {
opt_mth.map_or(nullptr, |(def_id, substs)| { opt_mth.map_or(nullptr, |(def_id, substs)| {
cx.get_fn( cx.get_fn_addr(
ty::Instance::resolve_for_vtable( ty::Instance::resolve_for_vtable(
cx.tcx(), cx.tcx(),
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
@ -108,7 +108,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
// `get_vtable` in rust_mir/interpret/traits.rs // `get_vtable` in rust_mir/interpret/traits.rs
// ///////////////////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////////////////////
let components: Vec<_> = [ let components: Vec<_> = [
cx.get_fn(Instance::resolve_drop_in_place(cx.tcx(), ty)), cx.get_fn_addr(Instance::resolve_drop_in_place(cx.tcx(), ty)),
cx.const_usize(layout.size.bytes()), cx.const_usize(layout.size.bytes()),
cx.const_usize(layout.align.abi.bytes()) cx.const_usize(layout.align.abi.bytes())
].iter().cloned().chain(methods).collect(); ].iter().cloned().chain(methods).collect();

View file

@ -358,7 +358,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty) (meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty)
} }
_ => { _ => {
(bx.get_fn(drop_fn), (bx.get_fn_addr(drop_fn),
FnType::of_instance(&bx, drop_fn)) FnType::of_instance(&bx, drop_fn))
} }
}; };
@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item); let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item);
let instance = ty::Instance::mono(bx.tcx(), def_id); let instance = ty::Instance::mono(bx.tcx(), def_id);
let fn_ty = FnType::of_instance(&bx, instance); let fn_ty = FnType::of_instance(&bx, instance);
let llfn = bx.get_fn(instance); let llfn = bx.get_fn_addr(instance);
// Codegen the actual panic invoke/call. // Codegen the actual panic invoke/call.
helper.do_call(self, &mut bx, fn_ty, llfn, &args, None, cleanup); helper.do_call(self, &mut bx, fn_ty, llfn, &args, None, cleanup);
@ -576,7 +576,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem); common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem);
let instance = ty::Instance::mono(bx.tcx(), def_id); let instance = ty::Instance::mono(bx.tcx(), def_id);
let fn_ty = FnType::of_instance(&bx, instance); let fn_ty = FnType::of_instance(&bx, instance);
let llfn = bx.get_fn(instance); let llfn = bx.get_fn_addr(instance);
if let Some((_, target)) = destination.as_ref() { if let Some((_, target)) = destination.as_ref() {
helper.maybe_sideeffect(self.mir, &mut bx, &[*target]); helper.maybe_sideeffect(self.mir, &mut bx, &[*target]);
@ -793,7 +793,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let fn_ptr = match (llfn, instance) { let fn_ptr = match (llfn, instance) {
(Some(llfn), _) => llfn, (Some(llfn), _) => llfn,
(None, Some(instance)) => bx.get_fn(instance), (None, Some(instance)) => bx.get_fn_addr(instance),
_ => span_bug!(span, "no llfn for call"), _ => span_bug!(span, "no llfn for call"),
}; };

View file

@ -189,7 +189,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bug!("reifying a fn ptr that requires const arguments"); bug!("reifying a fn ptr that requires const arguments");
} }
OperandValue::Immediate( OperandValue::Immediate(
bx.get_fn( bx.get_fn_addr(
ty::Instance::resolve_for_fn_ptr( ty::Instance::resolve_for_fn_ptr(
bx.tcx(), bx.tcx(),
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
@ -212,7 +212,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
def_id, def_id,
substs, substs,
ty::ClosureKind::FnOnce); ty::ClosureKind::FnOnce);
OperandValue::Immediate(bx.cx().get_fn(instance)) OperandValue::Immediate(bx.cx().get_fn_addr(instance))
} }
_ => { _ => {
bug!("{} cannot be cast to a fn ptr", operand.layout.ty) bug!("{} cannot be cast to a fn ptr", operand.layout.ty)
@ -495,7 +495,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} }
}; };
let instance = ty::Instance::mono(bx.tcx(), def_id); let instance = ty::Instance::mono(bx.tcx(), def_id);
let r = bx.cx().get_fn(instance); let r = bx.cx().get_fn_addr(instance);
let call = bx.call(r, &[llsize, llalign], None); let call = bx.call(r, &[llsize, llalign], None);
let val = bx.pointercast(call, llty_ptr); let val = bx.pointercast(call, llty_ptr);

View file

@ -11,8 +11,8 @@ pub trait MiscMethods<'tcx>: BackendTypes {
&self, &self,
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), Self::Value>>; ) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), Self::Value>>;
fn check_overflow(&self) -> bool; fn check_overflow(&self) -> bool;
fn instances(&self) -> &RefCell<FxHashMap<Instance<'tcx>, Self::Function>>; fn get_fn(&self, instance: Instance<'tcx>) -> Self::Function;
fn get_fn(&self, instance: Instance<'tcx>) -> Self::Value; fn get_fn_addr(&self, instance: Instance<'tcx>) -> Self::Value;
fn eh_personality(&self) -> Self::Value; fn eh_personality(&self) -> Self::Value;
fn eh_unwind_resume(&self) -> Self::Value; fn eh_unwind_resume(&self) -> Self::Value;
fn sess(&self) -> &Session; fn sess(&self) -> &Session;