rust/compiler/rustc_codegen_llvm/src
flip1995 e96e6e2c89
Add metadata generation for vtables when using VFE
This adds the typeid and `vcall_visibility` metadata to vtables when the
-Cvirtual-function-elimination flag is set.

The typeid is generated in the same way as for the
`llvm.type.checked.load` intrinsic from the trait_ref.

The offset that is added to the typeid is always 0. This is because LLVM
assumes that vtables are constructed according to the definition in the
Itanium ABI. This includes an "address point" of the vtable. In C++ this
is the offset in the vtable where information for RTTI is placed. Since
there is no RTTI information in Rust's vtables, this "address point" is
always 0. This "address point" in combination with the offset passed to
the `llvm.type.checked.load` intrinsic determines the final function
that should be loaded from the vtable in the
`WholeProgramDevirtualization` pass in LLVM. That's why the
`llvm.type.checked.load` intrinsics are generated with the typeid of the
trait, rather than with that of the function that is called. This
matches what `clang` does for C++.

The vcall_visibility metadata depends on three factors:

1. LTO level: Currently this is always fat LTO, because LLVM only
   supports this optimization with fat LTO.
2. Visibility of the trait: If the trait is publicly visible, VFE
   can only act on its vtables after linking.
3. Number of CGUs: if there is more than one CGU, also vtables with
   restricted visibility could be seen outside of the CGU, so VFE can
   only act on them after linking.

To reflect this, there are three visibility levels: Public, LinkageUnit,
and TranslationUnit.
2022-06-14 14:50:52 +02:00
..
back Add LLVM module flags required for the VFE opt 2022-06-14 14:50:52 +02:00
coverageinfo add #[rustc_pass_by_value] to more types 2022-03-08 15:39:52 +01:00
debuginfo Add metadata generation for vtables when using VFE 2022-06-14 14:50:52 +02:00
llvm Add metadata generation for vtables when using VFE 2022-06-14 14:50:52 +02:00
abi.rs Add support for emitting functions with coldcc in LLVM 2022-05-30 00:19:23 -07:00
allocator.rs Auto merge of #88098 - Amanieu:oom_panic, r=nagisa 2022-03-18 03:01:46 +00:00
asm.rs Add tmm_reg clobbers 2022-05-16 20:15:06 -04:00
attributes.rs only_local: always check for misuse 2022-05-10 12:07:35 +02:00
base.rs Auto merge of #95689 - lqd:self-profiler, r=wesleywiser 2022-04-16 11:43:28 +00:00
builder.rs Don't use global initializer if type does not match 2022-05-25 17:28:58 +02:00
callee.rs Remove in_band_lifetimes from rustc_codegen_llvm 2021-12-16 14:43:32 -05:00
common.rs Mark scalar layout unions so that backends that do not support partially initialized scalars can special case them. 2022-04-05 13:18:21 +00:00
consts.rs Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
context.rs Add llvm.type.checked.load intrinsic 2022-06-14 14:50:52 +02:00
declare.rs Remove LLVM attribute removal 2022-02-28 00:02:11 -05:00
intrinsic.rs Add llvm.type.checked.load intrinsic 2022-06-14 14:50:52 +02:00
lib.rs Fully stabilize NLL 2022-06-03 17:16:41 -04:00
llvm_util.rs Avoid creating SmallVecs in global_llvm_features 2022-06-06 18:05:07 +08:00
mono_item.rs Remove in_band_lifetimes from rustc_codegen_llvm 2021-12-16 14:43:32 -05:00
type_.rs Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
type_of.rs Mark scalar layout unions so that backends that do not support partially initialized scalars can special case them. 2022-04-05 13:18:21 +00:00
va_arg.rs Introduce Bx::switch_to_block 2022-02-24 12:18:21 +01:00
value.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00