diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2025-02-19 14:53:31 -0800 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2025-02-20 19:55:29 -0800 |
| commit | 79f41c773aaad6a10c2c752d223bd5aba0371f9b (patch) | |
| tree | fe6175752d39902f306b559394e52b4ece26b041 | |
| parent | 5c474fd99b97b0d86d410dfe25b876b374b436fa (diff) | |
| download | rust-79f41c773aaad6a10c2c752d223bd5aba0371f9b.tar.gz rust-79f41c773aaad6a10c2c752d223bd5aba0371f9b.zip | |
compiler: split vector_align into cabi and llvmlike
Introduce a pair of functions that actually describe what they do, because it wasn't clear the alignment is sometimes a forgery.
| -rw-r--r-- | compiler/rustc_abi/src/callconv/reg.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_abi/src/lib.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/layout.rs | 7 |
3 files changed, 20 insertions, 12 deletions
diff --git a/compiler/rustc_abi/src/callconv/reg.rs b/compiler/rustc_abi/src/callconv/reg.rs index 66f47c52c15..8cf140dbaad 100644 --- a/compiler/rustc_abi/src/callconv/reg.rs +++ b/compiler/rustc_abi/src/callconv/reg.rs @@ -57,7 +57,7 @@ impl Reg { 128 => dl.f128_align.abi, _ => panic!("unsupported float: {self:?}"), }, - RegKind::Vector => dl.vector_align(self.size).abi, + RegKind::Vector => dl.llvmlike_vector_align(self.size).abi, } } } diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 43a7141472c..094a25129ae 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -408,16 +408,21 @@ impl TargetDataLayout { } } + /// psABI-mandated alignment for a vector type, if any #[inline] - pub fn vector_align(&self, vec_size: Size) -> AbiAndPrefAlign { - for &(size, align) in &self.vector_align { - if size == vec_size { - return align; - } - } - // Default to natural alignment, which is what LLVM does. - // That is, use the size, rounded up to a power of 2. - AbiAndPrefAlign::new(Align::from_bytes(vec_size.bytes().next_power_of_two()).unwrap()) + fn cabi_vector_align(&self, vec_size: Size) -> Option<AbiAndPrefAlign> { + self.vector_align + .iter() + .find(|(size, _align)| *size == vec_size) + .map(|(_size, align)| *align) + } + + /// an alignment resembling the one LLVM would pick for a vector + #[inline] + pub fn llvmlike_vector_align(&self, vec_size: Size) -> AbiAndPrefAlign { + self.cabi_vector_align(vec_size).unwrap_or(AbiAndPrefAlign::new( + Align::from_bytes(vec_size.bytes().next_power_of_two()).unwrap(), + )) } } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index e95c95ed6c5..0b5683bb84b 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -535,11 +535,14 @@ fn layout_of_uncached<'tcx>( BackendRepr::Memory { sized: true }, AbiAndPrefAlign { abi: Align::max_aligned_factor(size), - pref: dl.vector_align(size).pref, + pref: dl.llvmlike_vector_align(size).pref, }, ) } else { - (BackendRepr::Vector { element: e_abi, count: e_len }, dl.vector_align(size)) + ( + BackendRepr::Vector { element: e_abi, count: e_len }, + dl.llvmlike_vector_align(size), + ) }; let size = size.align_to(align.abi); |
