Don't deduplicate vtables between functions
This commit is contained in:
parent
b6f7e71c1d
commit
f3b0f425c5
@ -18,9 +18,9 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
|
||||
let mir = tcx.instance_mir(instance.def);
|
||||
|
||||
// Declare function
|
||||
let name = tcx.symbol_name(instance).name.to_string();
|
||||
let symbol_name = tcx.symbol_name(instance);
|
||||
let sig = get_function_sig(tcx, cx.module.isa().triple(), instance);
|
||||
let func_id = cx.module.declare_function(&name, Linkage::Local, &sig).unwrap();
|
||||
let func_id = cx.module.declare_function(symbol_name.name, Linkage::Local, &sig).unwrap();
|
||||
|
||||
cx.cached_context.clear();
|
||||
|
||||
@ -46,8 +46,10 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
|
||||
cx,
|
||||
tcx,
|
||||
pointer_type,
|
||||
vtables: FxHashMap::default(),
|
||||
|
||||
instance,
|
||||
symbol_name,
|
||||
mir,
|
||||
fn_abi: Some(FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])),
|
||||
|
||||
@ -151,7 +153,7 @@ pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: In
|
||||
debug_context.define_function(
|
||||
instance,
|
||||
func_id,
|
||||
&name,
|
||||
symbol_name.name,
|
||||
isa,
|
||||
context,
|
||||
&source_info_set,
|
||||
|
@ -1,4 +1,5 @@
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::ty::SymbolName;
|
||||
use rustc_target::abi::call::FnAbi;
|
||||
use rustc_target::abi::{Integer, Primitive};
|
||||
use rustc_target::spec::{HasTargetSpec, Target};
|
||||
@ -230,8 +231,10 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx> {
|
||||
pub(crate) cx: &'clif mut crate::CodegenCx<'m, 'tcx>,
|
||||
pub(crate) tcx: TyCtxt<'tcx>,
|
||||
pub(crate) pointer_type: Type, // Cached from module
|
||||
pub(crate) vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
|
||||
|
||||
pub(crate) instance: Instance<'tcx>,
|
||||
pub(crate) symbol_name: SymbolName<'tcx>,
|
||||
pub(crate) mir: &'tcx Body<'tcx>,
|
||||
pub(crate) fn_abi: Option<FnAbi<'tcx, Ty<'tcx>>>,
|
||||
|
||||
|
@ -92,8 +92,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||
|
||||
let inline_asm_index = fx.inline_asm_index;
|
||||
fx.inline_asm_index += 1;
|
||||
let asm_name =
|
||||
format!("{}__inline_asm_{}", fx.tcx.symbol_name(fx.instance).name, inline_asm_index);
|
||||
let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index);
|
||||
|
||||
let generated_asm = generate_asm_wrapper(
|
||||
&asm_name,
|
||||
|
@ -125,7 +125,6 @@ struct CodegenCx<'m, 'tcx: 'm> {
|
||||
global_asm: String,
|
||||
constants_cx: ConstantCx,
|
||||
cached_context: Context,
|
||||
vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
|
||||
debug_context: Option<DebugContext<'tcx>>,
|
||||
unwind_context: UnwindContext<'tcx>,
|
||||
}
|
||||
@ -150,7 +149,6 @@ fn new(
|
||||
global_asm: String::new(),
|
||||
constants_cx: ConstantCx::default(),
|
||||
cached_context: Context::new(),
|
||||
vtables: FxHashMap::default(),
|
||||
debug_context,
|
||||
unwind_context,
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) {
|
||||
fx.add_comment(puts, "puts");
|
||||
}
|
||||
|
||||
let symbol_name = fx.tcx.symbol_name(fx.instance);
|
||||
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
|
||||
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, fx.symbol_name, msg);
|
||||
let msg_ptr = fx.anonymous_str("trap", &real_msg);
|
||||
fx.bcx.ins().call(puts, &[msg_ptr]);
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ pub(crate) fn get_vtable<'tcx>(
|
||||
layout: TyAndLayout<'tcx>,
|
||||
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||
) -> Value {
|
||||
let data_id = if let Some(data_id) = fx.cx.vtables.get(&(layout.ty, trait_ref)) {
|
||||
let data_id = if let Some(data_id) = fx.vtables.get(&(layout.ty, trait_ref)) {
|
||||
*data_id
|
||||
} else {
|
||||
let data_id = build_vtable(fx, layout, trait_ref);
|
||||
fx.cx.vtables.insert((layout.ty, trait_ref), data_id);
|
||||
fx.vtables.insert((layout.ty, trait_ref), data_id);
|
||||
data_id
|
||||
};
|
||||
|
||||
@ -139,27 +139,9 @@ fn build_vtable<'tcx>(
|
||||
|
||||
data_ctx.set_align(fx.tcx.data_layout.pointer_align.pref.bytes());
|
||||
|
||||
let data_id = fx
|
||||
.cx
|
||||
.module
|
||||
.declare_data(
|
||||
&format!(
|
||||
"__vtable.{}.for.{:?}.{}",
|
||||
trait_ref
|
||||
.as_ref()
|
||||
.map(|trait_ref| format!("{:?}", trait_ref.skip_binder()).into())
|
||||
.unwrap_or(std::borrow::Cow::Borrowed("???")),
|
||||
layout.ty,
|
||||
fx.cx.vtables.len(),
|
||||
),
|
||||
Linkage::Local,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
let data_id = fx.cx.module.declare_anonymous_data(false, false).unwrap();
|
||||
|
||||
// FIXME don't duplicate definitions in lazy jit mode
|
||||
let _ = fx.cx.module.define_data(data_id, &data_ctx);
|
||||
fx.cx.module.define_data(data_id, &data_ctx).unwrap();
|
||||
|
||||
data_id
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user