Skip to content

Commit 9f69cf4

Browse files
committed
Move vcall_visibility_metadata optimization hint out of a debuginfo generation method
1 parent 7e0ed43 commit 9f69cf4

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::back::write::to_llvm_code_model;
33
use crate::callee::get_fn;
44
use crate::coverageinfo;
55
use crate::debuginfo;
6+
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
67
use crate::llvm;
78
use crate::llvm_util;
89
use crate::type_::Type;
@@ -488,6 +489,15 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
488489
&self.vtables
489490
}
490491

492+
fn apply_vcall_visibility_metadata(
493+
&self,
494+
ty: Ty<'tcx>,
495+
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
496+
vtable: &'ll Value,
497+
) {
498+
apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable);
499+
}
500+
491501
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
492502
get_fn(self, instance)
493503
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,12 +1447,18 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14471447
.di_node
14481448
}
14491449

1450-
fn vcall_visibility_metadata<'ll, 'tcx>(
1450+
pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
14511451
cx: &CodegenCx<'ll, 'tcx>,
14521452
ty: Ty<'tcx>,
14531453
trait_ref: Option<PolyExistentialTraitRef<'tcx>>,
14541454
vtable: &'ll Value,
14551455
) {
1456+
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
1457+
// LLVM at the moment.
1458+
if !cx.sess().opts.unstable_opts.virtual_function_elimination || cx.sess().lto() != Lto::Fat {
1459+
return;
1460+
}
1461+
14561462
enum VCallVisibility {
14571463
Public = 0,
14581464
LinkageUnit = 1,
@@ -1529,12 +1535,6 @@ pub fn create_vtable_di_node<'ll, 'tcx>(
15291535
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
15301536
vtable: &'ll Value,
15311537
) {
1532-
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
1533-
// LLVM at the moment.
1534-
if cx.sess().opts.unstable_opts.virtual_function_elimination && cx.sess().lto() == Lto::Fat {
1535-
vcall_visibility_metadata(cx, ty, poly_trait_ref, vtable);
1536-
}
1537-
15381538
if cx.dbg_cx.is_none() {
15391539
return;
15401540
}

compiler/rustc_codegen_ssa/src/meth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
108108
let align = cx.data_layout().pointer_align.abi;
109109
let vtable = cx.static_addr_of(vtable_const, align, Some("vtable"));
110110

111+
cx.apply_vcall_visibility_metadata(ty, trait_ref, vtable);
111112
cx.create_vtable_debuginfo(ty, trait_ref, vtable);
112113
cx.vtables().borrow_mut().insert((ty, trait_ref), vtable);
113114
vtable

compiler/rustc_codegen_ssa/src/traits/misc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ pub trait MiscMethods<'tcx>: BackendTypes {
99
fn vtables(
1010
&self,
1111
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), Self::Value>>;
12+
fn apply_vcall_visibility_metadata(
13+
&self,
14+
_ty: Ty<'tcx>,
15+
_poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
16+
_vtable: Self::Value,
17+
) {
18+
}
1219
fn check_overflow(&self) -> bool;
1320
fn get_fn(&self, instance: Instance<'tcx>) -> Self::Function;
1421
fn get_fn_addr(&self, instance: Instance<'tcx>) -> Self::Value;

0 commit comments

Comments
 (0)