Auto merge of #96285 - flip1995:pk-vfe, r=nagisa
Introduce `-Zvirtual-function-elimination` codegen flag Fixes #68262 This PR adds a codegen flag `-Zvirtual-function-elimination` to enable the VFE optimization in LLVM. To make this work, additonal information has to be added to vtables ([`!vcall_visibility` metadata](https://llvm.org/docs/TypeMetadata.html#vcall-visibility-metadata) and a `typeid` of the trait). Furthermore, instead of just `load`ing functions, the [`llvm.type.checked.load` intrinsic](https://llvm.org/docs/LangRef.html#llvm-type-checked-load-intrinsic) has to be used to map functions to vtables. For technical details of the changes, see the commit messages. I also tested this flag on https://github.com/tock/tock on different boards to verify that this fixes the issue https://github.com/tock/tock/issues/2594. This flag is able to improve the size of the resulting binary by about 8k-9k bytes by removing the unused debug print functions. [Rendered documentation update](https://github.com/flip1995/rust/blob/pk-vfe/src/doc/rustc/src/codegen-options/index.md#virtual-function-elimination)
This commit is contained in:
commit
2d1e075079
20 changed files with 431 additions and 32 deletions
|
@ -401,7 +401,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
args = &args[..1];
|
||||
(
|
||||
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
|
||||
.get_fn(&mut bx, vtable, &fn_abi),
|
||||
.get_fn(&mut bx, vtable, ty, &fn_abi),
|
||||
fn_abi,
|
||||
)
|
||||
}
|
||||
|
@ -819,9 +819,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
// the data pointer as the first argument
|
||||
match op.val {
|
||||
Pair(data_ptr, meta) => {
|
||||
llfn = Some(
|
||||
meth::VirtualIndex::from_index(idx).get_fn(&mut bx, meta, &fn_abi),
|
||||
);
|
||||
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
|
||||
&mut bx,
|
||||
meta,
|
||||
op.layout.ty,
|
||||
&fn_abi,
|
||||
));
|
||||
llargs.push(data_ptr);
|
||||
continue 'make_args;
|
||||
}
|
||||
|
@ -829,7 +832,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
}
|
||||
} else if let Ref(data_ptr, Some(meta), _) = op.val {
|
||||
// by-value dynamic dispatch
|
||||
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(&mut bx, meta, &fn_abi));
|
||||
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
|
||||
&mut bx,
|
||||
meta,
|
||||
op.layout.ty,
|
||||
&fn_abi,
|
||||
));
|
||||
llargs.push(data_ptr);
|
||||
continue;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue