Skip to content

Commit e9ea578

Browse files
committed
Move vcall_visibility_metadata optimization hint out of a debuginfo generation method
1 parent 5ced3da commit e9ea578

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;
@@ -522,6 +523,15 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
522523
&self.vtables
523524
}
524525

526+
fn apply_vcall_visibility_metadata(
527+
&self,
528+
ty: Ty<'tcx>,
529+
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
530+
vtable: &'ll Value,
531+
) {
532+
apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable);
533+
}
534+
525535
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
526536
get_fn(self, instance)
527537
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

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

1452-
fn vcall_visibility_metadata<'ll, 'tcx>(
1452+
pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
14531453
cx: &CodegenCx<'ll, 'tcx>,
14541454
ty: Ty<'tcx>,
14551455
trait_ref: Option<PolyExistentialTraitRef<'tcx>>,
14561456
vtable: &'ll Value,
14571457
) {
1458+
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
1459+
// LLVM at the moment.
1460+
if !cx.sess().opts.unstable_opts.virtual_function_elimination || cx.sess().lto() != Lto::Fat {
1461+
return;
1462+
}
1463+
14581464
enum VCallVisibility {
14591465
Public = 0,
14601466
LinkageUnit = 1,
@@ -1531,12 +1537,6 @@ pub fn create_vtable_di_node<'ll, 'tcx>(
15311537
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
15321538
vtable: &'ll Value,
15331539
) {
1534-
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
1535-
// LLVM at the moment.
1536-
if cx.sess().opts.unstable_opts.virtual_function_elimination && cx.sess().lto() == Lto::Fat {
1537-
vcall_visibility_metadata(cx, ty, poly_trait_ref, vtable);
1538-
}
1539-
15401540
if cx.dbg_cx.is_none() {
15411541
return;
15421542
}

compiler/rustc_codegen_ssa/src/meth.rs

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

136+
cx.apply_vcall_visibility_metadata(ty, trait_ref, vtable);
136137
cx.create_vtable_debuginfo(ty, trait_ref, vtable);
137138
cx.vtables().borrow_mut().insert((ty, trait_ref), vtable);
138139
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)